Skip to content

Commit

Permalink
[bugfix](schema change) fix multi clauses calculate column unique id
Browse files Browse the repository at this point in the history
error.
  • Loading branch information
SWJTU-ZhangLei committed Jun 22, 2022
1 parent 92fed3f commit ea0dff9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public class SchemaChangeHandler extends AlterHandler {

public int cycleCount = 0;

public int maxColUniqueId = Column.COLUMN_UNIQUE_ID_INIT_VALUE;

public SchemaChangeHandler() {
super("schema change", Config.default_schema_change_scheduler_interval_millisecond);
}
Expand All @@ -143,7 +145,8 @@ private boolean processAddColumn(AddColumnClause alterClause, OlapTable olapTabl

//only new table generate ColUniqueId, exist table do not.
if (olapTable.getMaxColUniqueId() > Column.COLUMN_UNIQUE_ID_INIT_VALUE) {
column.setUniqueId(olapTable.getMaxColUniqueId() + 1);
maxColUniqueId++;
column.setUniqueId(maxColUniqueId);
}

return addColumnInternal(olapTable, column, columnPos, targetIndexId, baseIndexId,
Expand Down Expand Up @@ -201,10 +204,9 @@ public boolean processAddColumns(AddColumnsClause alterClause, OlapTable olapTab

//for new table calculate column unique id
if (olapTable.getMaxColUniqueId() > Column.COLUMN_UNIQUE_ID_INIT_VALUE) {
int maxColUniqueId = olapTable.getMaxColUniqueId();
for (Column column : columns) {
column.setUniqueId(maxColUniqueId + 1);
maxColUniqueId++;
column.setUniqueId(maxColUniqueId);
}
}

Expand Down Expand Up @@ -1542,13 +1544,19 @@ private void getAlterJobV2Infos(Database db, List<List<Comparable>> schemaChange
getAlterJobV2Infos(db, ImmutableList.copyOf(alterJobsV2.values()), schemaChangeJobInfos);
}

public void setMaxColUniqueId(int maxColUniqueId) {
maxColUniqueId = maxColUniqueId;
}

@Override
public void process(List<AlterClause> alterClauses, String clusterName, Database db, OlapTable olapTable)
throws UserException {
olapTable.writeLockOrDdlException();
try {
//alterClauses can or cannot light schema change
boolean ligthSchemaChange = true;
//for multi add colmuns clauses
this.setMaxColUniqueId(olapTable.getMaxColUniqueId());
// index id -> index schema
Map<Long, List<Column>> indexSchemaMap = new HashMap<>();
for (Map.Entry<Long, List<Column>> entry : olapTable.getIndexIdToSchema(true).entrySet()) {
Expand Down Expand Up @@ -1655,8 +1663,8 @@ public void process(List<AlterClause> alterClauses, String clusterName, Database
}
} // end for alter clauses

LOG.debug("processAddColumns, table: {}({}), getMaxColUniqueId(): {}, ligthSchemaChange: {}", olapTable.getName(),
olapTable.getId(), olapTable.getMaxColUniqueId(), ligthSchemaChange);
LOG.debug("processAddColumns, table: {}({}), maxColUniqueId: {}, ligthSchemaChange: {}", olapTable.getName(),
olapTable.getId(), maxColUniqueId, ligthSchemaChange);

if (ligthSchemaChange) {
//for schema change add/drop value column optimize, direct modify table meta.
Expand All @@ -1666,6 +1674,8 @@ public void process(List<AlterClause> alterClauses, String clusterName, Database
createJob(db.getId(), olapTable, indexSchemaMap, propertyMap, newIndexes);
}
} finally {
//reset schema change max col unique id
maxColUniqueId = Column.COLUMN_UNIQUE_ID_INIT_VALUE;
olapTable.writeUnlock();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ private void onFinished(OlapTable tbl) {
maxColUniqueId = column.getUniqueId();
}
}
tbl.setMaxtColUniqueId(maxColUniqueId);
tbl.setMaxColUniqueId(maxColUniqueId);
LOG.debug("fullSchema:{}, maxColUniqueId:{}", tbl.getFullSchema(), maxColUniqueId);

tbl.setState(OlapTableState.NORMAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5036,7 +5036,7 @@ public void modifyTableAddOrDropColumns(Database db, OlapTable olapTable, Map<Lo
maxColUniqueId = column.getUniqueId();
}
}
olapTable.setMaxtColUniqueId(maxColUniqueId);
olapTable.setMaxColUniqueId(maxColUniqueId);

if (!isReplay) {
TableAddOrDropColumnsInfo info = new TableAddOrDropColumnsInfo(db.getId(), olapTable.getId(), indexSchemaMap, indexes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public int getMaxColUniqueId() {
return this.maxColUniqueId;
}

public void setMaxtColUniqueId(int maxColUniqueId) {
public void setMaxColUniqueId(int maxColUniqueId) {
this.maxColUniqueId = maxColUniqueId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,8 @@ public TAddColumnsResult addColumns(TAddColumnsRequest request) throws TExceptio
indexSchemaMap.put(entry.getKey(), new ArrayList<>(entry.getValue()));
}
//4. call schame change function, only for dynamic table feature.
SchemaChangeHandler schemaChangeHandler = new SchemaChangeHandler();
SchemaChangeHandler schemaChangeHandler = new SchemaChangeHandler();
schemaChangeHandler.setMaxColUniqueId(olapTable.getMaxColUniqueId());
boolean ligthSchemaChange = schemaChangeHandler.processAddColumns(addColumnsClause, olapTable, indexSchemaMap, true);
if (ligthSchemaChange) {
//for schema change add column optimize, direct modify table meta.
Expand Down

0 comments on commit ea0dff9

Please sign in to comment.