Skip to content

Commit

Permalink
[fix][dingo-executor] Delete autoIncrement while drop/truncate a table
Browse files Browse the repository at this point in the history
  • Loading branch information
guojn1 authored and githubgxll committed Nov 18, 2024
1 parent 7c1f931 commit 2e59936
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ private static synchronized void checkMdlVersion() {
if (maxVer > saveMaxSchemaVersion) {
saveMaxSchemaVersion = maxVer;
} else if (!jobNeedToSync) {
mdlCheckTableInfo.wUnlock();
if (DdlUtil.timeOutError.get()) {
LogUtils.info(log, "[ddl] mdl check not need to sync,max ver:{} saveMaxSchema ver:{}",
maxVer, saveMaxSchemaVersion);
Expand All @@ -83,8 +82,8 @@ private static synchronized void checkMdlVersion() {
int jobNeedToCheckCnt = mdlCheckTableInfo.getJobsVerMap().size();
if (jobNeedToCheckCnt == 0) {
jobNeedToSync = false;
LogUtils.info(log, "[ddl] mdl check job need to check cnt is 0,max ver:{} saveMaxSchema ver:{}",
maxVer, saveMaxSchemaVersion);
//LogUtils.info(log, "[ddl] mdl check job need to check cnt is 0,max ver:{} saveMaxSchema ver:{}",
// maxVer, saveMaxSchemaVersion);
mdlCheckTableInfo.wUnlock();
return;
}
Expand Down Expand Up @@ -117,12 +116,6 @@ private static synchronized void checkMdlVersion() {
if (jobCache.containsKey(entry.getKey())
&& jobCache.get(entry.getKey()) >= entry.getValue()
) {
if (DdlUtil.timeOutError.get()) {
//LogUtils.info(log, "[ddl] mdl check skip, max ver:{},"
// +" saveMaxSchema ver:{}, new ver:{}, jobs ver:{}", maxVer,
// saveMaxSchemaVersion, DdlContext.INSTANCE.getNewVer(), entry.getValue());
//DdlUtil.timeOutError.set(false);
}
continue;
}
LogUtils.info(log, "mdl gets lock, update to owner, jobId:{}, version:{}, save ver:{}, jobNeedSync:{}",
Expand All @@ -136,7 +129,7 @@ private static synchronized void checkMdlVersion() {
}
}
} catch (Exception e) {
LogUtils.error(log, "mdlCheckLoop error, error:" + e.getMessage());
LogUtils.error(log, "mdlCheckLoop error, error:" + e.getMessage(), e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import io.dingodb.common.util.Utils;
import io.dingodb.meta.DdlService;
import io.dingodb.meta.MetaServiceProvider;
import io.dingodb.meta.entity.Column;
import io.dingodb.meta.entity.IndexTable;
import io.dingodb.meta.entity.InfoSchema;
import io.dingodb.meta.entity.Table;
Expand Down Expand Up @@ -66,6 +67,7 @@
import io.dingodb.sdk.service.entity.coordinator.SplitRegionRequest;
import io.dingodb.sdk.service.entity.meta.CreateAutoIncrementRequest;
import io.dingodb.sdk.service.entity.meta.CreateTenantRequest;
import io.dingodb.sdk.service.entity.meta.DeleteAutoIncrementRequest;
import io.dingodb.sdk.service.entity.meta.DingoCommonId;
import io.dingodb.sdk.service.entity.meta.DropTenantRequest;
import io.dingodb.sdk.service.entity.meta.EntityType;
Expand Down Expand Up @@ -787,7 +789,11 @@ public long truncateTable(@NonNull String tableName, long tableEntityId) {

// Generate new table ids.
CoordinatorService coordinatorService = Services.coordinatorService(Configuration.coordinatorSet());

boolean autoInc = table.getTableDefinition().getColumns().stream()
.anyMatch(io.dingodb.sdk.service.entity.meta.ColumnDefinition::isAutoIncrement);
if (autoInc) {
delAutoInc(table.getTableId());
}
dropRegionByTable(table, coordinatorService);

for (TableDefinitionWithId index : indexes) {
Expand Down Expand Up @@ -982,6 +988,11 @@ public boolean dropTable(long tenantId, long schemaId, String tableName) {
if (table == null) {
return false;
}
boolean autoInc = table.getColumns().stream()
.anyMatch(Column::isAutoIncrement);
if (autoInc) {
delAutoInc(MAPPER.idTo(table.getTableId()));
}
List<IndexTable> indexes = table.getIndexes();

loadDistribution(table.tableId, tenantId, table).values().forEach(rangeDistribution -> {
Expand Down Expand Up @@ -1276,4 +1287,18 @@ public static RawEngine getRawEngine(Engine engine) {
return RawEngine.RAW_ENG_ROCKSDB;
}
}

public void delAutoInc(DingoCommonId tableId) {
DeleteAutoIncrementRequest req = DeleteAutoIncrementRequest.builder()
.tableId(tableId)
.build();
try {
io.dingodb.sdk.service.MetaService metaService
= Services.autoIncrementMetaService(Configuration.coordinatorSet());
metaService.deleteAutoIncrement(System.identityHashCode(req), req);
LogUtils.info(log, "delAutoInc success, tableId:{}", tableId);
} catch (Exception e) {
LogUtils.error(log, e.getMessage(), e);
}
}
}

0 comments on commit 2e59936

Please sign in to comment.