[fix](DatabaseTransactionMgr) Fix clean label bug which may cause inconsitent editlog operation (#29198)

This commit is contained in:
caiconghui
2023-12-28 14:17:35 +08:00
committed by GitHub
parent f816d13c56
commit 4f2d54d462
3 changed files with 12 additions and 14 deletions

View File

@ -786,22 +786,16 @@ public class LoadManager implements Writable {
} finally {
writeUnlock();
}
LOG.info("clean {} labels on db {} with label '{}' in load mgr.", counter, dbId, label);
// 2. Remove from DatabaseTransactionMgr
try {
Env.getCurrentGlobalTransactionMgr().cleanLabel(dbId, label);
Env.getCurrentGlobalTransactionMgr().cleanLabel(dbId, label, isReplay);
} catch (AnalysisException e) {
// just ignore, because we don't want to throw any exception here.
LOG.warn("Exception:", e);
}
// 3. Log
if (!isReplay) {
CleanLabelOperationLog log = new CleanLabelOperationLog(dbId, label);
Env.getCurrentEnv().getEditLog().logCleanLabel(log);
}
LOG.info("finished to clean label on db {} with label {}. is replay: {}", dbId, label, isReplay);
LOG.info("finished to clean {} labels on db {} with label '{}' in load mgr. is replay: {}",
counter, dbId, label, isReplay);
}
private void readLock() {

View File

@ -50,6 +50,7 @@ import org.apache.doris.common.util.TimeUtils;
import org.apache.doris.metric.MetricRepo;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.persist.BatchRemoveTransactionsOperationV2;
import org.apache.doris.persist.CleanLabelOperationLog;
import org.apache.doris.persist.EditLog;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.statistics.AnalysisManager;
@ -2072,7 +2073,7 @@ public class DatabaseTransactionMgr {
}
}
protected void cleanLabel(String label) {
protected void cleanLabel(String label, boolean isReplay) {
Set<Long> removedTxnIds = Sets.newHashSet();
writeLock();
try {
@ -2113,11 +2114,14 @@ public class DatabaseTransactionMgr {
// So that we can keep consistency in meta image
finalStatusTransactionStateDequeShort.removeIf(txn -> removedTxnIds.contains(txn.getTransactionId()));
finalStatusTransactionStateDequeLong.removeIf(txn -> removedTxnIds.contains(txn.getTransactionId()));
if (!isReplay) {
CleanLabelOperationLog log = new CleanLabelOperationLog(dbId, label);
Env.getCurrentEnv().getEditLog().logCleanLabel(log);
}
} finally {
writeUnlock();
}
LOG.info("clean {} labels on db {} with label '{}' in database transaction mgr.", removedTxnIds.size(), dbId,
label);
}
public long getTxnNumByStatus(TransactionStatus status) {

View File

@ -754,8 +754,8 @@ public class GlobalTransactionMgr implements Writable {
return getDatabaseTransactionMgr(dbId).getPreCommittedTxnList();
}
public void cleanLabel(Long dbId, String label) throws AnalysisException {
getDatabaseTransactionMgr(dbId).cleanLabel(label);
public void cleanLabel(Long dbId, String label, boolean isReplay) throws AnalysisException {
getDatabaseTransactionMgr(dbId).cleanLabel(label, isReplay);
}
public Long getTransactionIdByLabel(Long dbId, String label, List<TransactionStatus> statusList)