Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ public static void renamePartitionTableMeta(Connection metaDbConn, String schema
String tableListDataId = MetaDbDataIdBuilder.getTableListDataId(schemaName);
String tableDataId = MetaDbDataIdBuilder.getTableDataId(schemaName, logicalTableName);
String newTableDataId = MetaDbDataIdBuilder.getTableDataId(schemaName, newLogicalTableName);
boolean renamePhyTable = executionContext.needToRenamePhyTables();

// Rename sequence if exists.
SequenceBaseRecord sequenceRecord = null;
Expand All @@ -365,9 +366,13 @@ public static void renamePartitionTableMeta(Connection metaDbConn, String schema
TableInfoManager tableInfoManager = new TableInfoManager();
tableInfoManager.setConnection(metaDbConn);

// Replace with new physical table name
if (renamePhyTable) {
tableInfoManager.renamePartitionTablePhyTable(schemaName, logicalTableName, newLogicalTableName);
}

// Replace with new table name
tableInfoManager
.renamePartitionTable(schemaName, logicalTableName, newLogicalTableName, sequenceRecord);
tableInfoManager.renamePartitionTable(schemaName, logicalTableName, newLogicalTableName, sequenceRecord);

// Unregister the old table data id.
CONFIG_MANAGER.unregister(tableDataId, metaDbConn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
import com.alibaba.polardbx.gms.partition.TableLocalPartitionRecord;
import com.alibaba.polardbx.gms.partition.TablePartRecordInfoContext;
import com.alibaba.polardbx.gms.partition.TablePartitionAccessor;
import com.alibaba.polardbx.gms.partition.TablePartitionConfig;
import com.alibaba.polardbx.gms.partition.TablePartitionRecord;
import com.alibaba.polardbx.gms.partition.TablePartitionSpecConfig;
import com.alibaba.polardbx.gms.scheduler.FiredScheduledJobsAccessor;
import com.alibaba.polardbx.gms.scheduler.ScheduledJobsAccessor;
import com.alibaba.polardbx.gms.scheduler.ScheduledJobsRecord;
Expand Down Expand Up @@ -729,6 +731,16 @@ public void renamePartitionTable(String tableSchema, String tableName, String ne
}
}

public void renamePartitionTablePhyTable(String tableSchema, String tableName, String newTableName) {
TablePartitionConfig tablePartitionConfig =
tablePartitionAccessor.getTablePartitionConfig(tableSchema, tableName, false);
for (TablePartitionSpecConfig item : tablePartitionConfig.getPartitionSpecConfigs()) {
String phyTableName = item.getSpecConfigInfo().phyTable;
String newPhyTableName = TStringUtil.replaceWithIgnoreCase(phyTableName, tableName, newTableName);
tablePartitionAccessor.renamePhyTableName(item.getSpecConfigInfo().id, newPhyTableName);
}
}

public void setMultiWriteSourceColumn(String tableSchema, String tableName, String columnsName) {
columnsAccessor.updateStatus(tableSchema, tableName, ImmutableList.of(columnsName),
ColumnStatus.MULTI_WRITE_SOURCE.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ public class TablePartitionAccessor extends AbstractAccessor {
private static final String UPDATE_TABLES_RENAME =
"update table_partitions set `table_name` = ? where table_schema=? and table_name=? ";

private static final String UPDATE_RENAME_PHYSICAL_TABLE =
"update table_partitions set `phy_table` = ? where id = ? ";

private static final String GET_TABLE_PARTITIONS_BY_GID_AND_PART_FROM_DELTA_TABLE =
"select " + ALL_COLUMNS + " from " + GmsSystemTables.TABLE_PARTITIONS_DELTA
+ " where table_schema=? and group_id=? and part_name=? and part_level<>0";
Expand Down Expand Up @@ -1182,6 +1185,20 @@ public void rename(String tableSchema, String tableName, String newTableName) {
}
}

public void renamePhyTableName(Long id, String newPhyTableName) {
try {
Map<Integer, ParameterContext> params = new HashMap<>();
MetaDbUtil.setParameter(1, params, ParameterMethod.setString, newPhyTableName);
MetaDbUtil.setParameter(2, params, ParameterMethod.setLong, id);
MetaDbUtil.update(UPDATE_RENAME_PHYSICAL_TABLE, params, connection);
return;
} catch (Exception e) {
logger.error("Failed to query the system table 'table_partitions'", e);
throw new TddlRuntimeException(ErrorCode.ERR_GMS_ACCESS_TO_SYSTEM_TABLE, e,
e.getMessage());
}
}

private TablePartitionConfig getTablePartitionConfigInner(String dbName, String tbName, Connection metaDbConn,
boolean fromDeltaTable, boolean publicOnly) {

Expand Down