[fix](tablet invert index) fix tablet invert index leaky caused by auto partition (#33973)

This commit is contained in:
yujun
2024-04-25 11:13:01 +08:00
committed by yiguolei
parent 789a16ec6b
commit c2e3defe56
3 changed files with 72 additions and 11 deletions

View File

@ -1415,8 +1415,10 @@ public class InternalCatalog implements CatalogIf<Database> {
// check partition name
if (olapTable.checkPartitionNameExist(partitionName)) {
if (singlePartitionDesc.isSetIfNotExists()) {
LOG.info("add partition[{}] which already exists", partitionName);
return;
LOG.info("table[{}] add partition[{}] which already exists", olapTable.getName(), partitionName);
if (!DebugPointUtil.isEnable("InternalCatalog.addPartition.noCheckExists")) {
return;
}
} else {
ErrorReport.reportDdlException(ErrorCode.ERR_SAME_NAME_PARTITION, partitionName);
}
@ -1573,6 +1575,11 @@ public class InternalCatalog implements CatalogIf<Database> {
if (!Strings.isNullOrEmpty(dataProperty.getStoragePolicy())) {
storagePolicy = dataProperty.getStoragePolicy();
}
Runnable failedCleanCallback = () -> {
for (Long tabletId : tabletIdSet) {
Env.getCurrentInvertedIndex().deleteTablet(tabletId);
}
};
try {
long partitionId = idGeneratorBuffer.getNextId();
Partition partition = createPartitionWithIndices(db.getId(), olapTable,
@ -1592,8 +1599,9 @@ public class InternalCatalog implements CatalogIf<Database> {
olapTable.checkNormalStateForAlter();
// check partition name
if (olapTable.checkPartitionNameExist(partitionName)) {
LOG.info("table[{}] add partition[{}] which already exists", olapTable.getName(), partitionName);
if (singlePartitionDesc.isSetIfNotExists()) {
LOG.info("add partition[{}] which already exists", partitionName);
failedCleanCallback.run();
return;
} else {
ErrorReport.reportDdlException(ErrorCode.ERR_SAME_NAME_PARTITION, partitionName);
@ -1642,8 +1650,6 @@ public class InternalCatalog implements CatalogIf<Database> {
}
}
if (metaChanged) {
throw new DdlException("Table[" + tableName + "]'s meta has been changed. try again.");
}
@ -1685,9 +1691,7 @@ public class InternalCatalog implements CatalogIf<Database> {
olapTable.writeUnlock();
}
} catch (DdlException e) {
for (Long tabletId : tabletIdSet) {
Env.getCurrentInvertedIndex().deleteTablet(tabletId);
}
failedCleanCallback.run();
throw e;
}
}
@ -2735,10 +2739,10 @@ public class InternalCatalog implements CatalogIf<Database> {
Env.getCurrentEnv().getEditLog().logColocateAddTable(info);
}
LOG.info("successfully create table[{};{}]", tableName, tableId);
// register or remove table from DynamicPartition after table created
DynamicPartitionUtil.registerOrRemoveDynamicPartitionTable(db.getId(), olapTable, false);
Env.getCurrentEnv().getDynamicPartitionScheduler()
.executeDynamicPartitionFirstTime(db.getId(), olapTable.getId());
// register or remove table from DynamicPartition after table created
DynamicPartitionUtil.registerOrRemoveDynamicPartitionTable(db.getId(), olapTable, false);
Env.getCurrentEnv().getDynamicPartitionScheduler()
.createOrUpdateRuntimeInfo(tableId, DynamicPartitionScheduler.LAST_UPDATE_TIME,
TimeUtils.getCurrentFormatTime());