jt2594838 commented on code in PR #17079:
URL: https://github.com/apache/iotdb/pull/17079#discussion_r2943914970


##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/schema/table/RenameTableProcedure.java:
##########
@@ -134,7 +155,95 @@ private void renameTable(final ConfigNodeProcedureEnv env) 
{
     if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
       setFailure(new ProcedureException(new IoTDBException(status)));
     } else {
-      setNextState(RenameTableState.COMMIT_RELEASE);
+      setNextState(RenameTableState.EXECUTE_ON_REGIONS);
+    }
+  }
+
+  private void executeOnRegions(final ConfigNodeProcedureEnv env) {
+    final Map<TConsensusGroupId, TRegionReplicaSet> relatedDataRegionGroup =
+        env.getConfigManager().getRelatedDataRegionGroup4TableModel(database);
+
+    if (!relatedDataRegionGroup.isEmpty()) {
+      List<SchemaEvolution> schemaEvolutions =
+          Collections.singletonList(new TableRename(tableName, newName));
+      PublicBAOS publicBAOS = new PublicBAOS();
+      try {
+        SchemaEvolution.serializeList(schemaEvolutions, publicBAOS);
+      } catch (IOException ignored) {
+      }
+      ByteBuffer byteBuffer = ByteBuffer.wrap(publicBAOS.getBuf(), 0, 
publicBAOS.size());
+      new TableRegionTaskExecutor<>(
+              "evolve data region schema",
+              env,
+              relatedDataRegionGroup,
+              CnToDnAsyncRequestType.EVOLVE_DATA_REGION_SCHEMA,
+              ((dataNodeLocation, consensusGroupIdList) ->
+                  new TDataRegionEvolveSchemaReq(
+                      new ArrayList<>(consensusGroupIdList), byteBuffer)))
+          .execute();
+    }
+
+    final Map<TConsensusGroupId, TRegionReplicaSet> relatedSchemaRegionGroup =
+        
env.getConfigManager().getRelatedSchemaRegionGroup4TableModel(database);
+
+    if (!relatedSchemaRegionGroup.isEmpty()) {
+      List<SchemaEvolution> schemaEvolutions =
+          Collections.singletonList(new TableRename(tableName, newName));
+      PublicBAOS publicBAOS = new PublicBAOS();
+      try {
+        SchemaEvolution.serializeList(schemaEvolutions, publicBAOS);
+      } catch (IOException ignored) {
+      }
+      ByteBuffer byteBuffer = ByteBuffer.wrap(publicBAOS.getBuf(), 0, 
publicBAOS.size());
+      new TableRegionTaskExecutor<>(
+              "evolve schema region schema",
+              env,
+              relatedSchemaRegionGroup,
+              CnToDnAsyncRequestType.EVOLVE_SCHEMA_REGION_SCHEMA,
+              ((dataNodeLocation, consensusGroupIdList) ->
+                  new TSchemaRegionEvolveSchemaReq(
+                      new ArrayList<>(consensusGroupIdList), byteBuffer)))
+          .execute();
+    }
+
+    invalidateAuthCache(env);
+
+    setNextState(RenameTableState.COMMIT_RELEASE);
+  }
+
+  private void invalidateAuthCache(final ConfigNodeProcedureEnv env) {
+    TInvalidatePermissionCacheReq req = new TInvalidatePermissionCacheReq();
+    // use all empty to invalidate all cache
+    req.setUsername("");
+    req.setRoleName("");
+    TSStatus status;
+    List<TDataNodeConfiguration> allDataNodes =
+        env.getConfigManager().getNodeManager().getRegisteredDataNodes();
+    List<Pair<TDataNodeConfiguration, Long>> dataNodesToInvalid = new 
ArrayList<>();
+    for (TDataNodeConfiguration item : allDataNodes) {
+      dataNodesToInvalid.add(new Pair<>(item, System.currentTimeMillis()));
+    }
+    Iterator<Pair<TDataNodeConfiguration, Long>> it = 
dataNodesToInvalid.iterator();
+    long timeoutMS = 10 * 60 * 1000; // 10 minutes
+    while (it.hasNext()) {

Review Comment:
   Since the operation is critical and low-frequency, I hope the user can 
acknowledge which node is problematic and may need a manual restart.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to