wardlican commented on code in PR #3927:
URL: https://github.com/apache/amoro/pull/3927#discussion_r2985267422


##########
amoro-ams/src/main/java/org/apache/amoro/server/table/DefaultTableService.java:
##########
@@ -495,7 +821,78 @@ private boolean triggerTableAdded(
     meta.setStatusCode(OptimizingStatus.IDLE.getCode());
     meta.setGroupName(configuration.getOptimizingConfig().getOptimizerGroup());
     meta.setTableSummary(new TableSummary());
-    doAs(TableRuntimeMapper.class, mapper -> mapper.insertRuntime(meta));
+
+    // In master-slave mode, assign bucketId to the table if it's not assigned 
yet.
+    // Only leader node should assign bucketIds; follower may still persist 
the table with null
+    // bucketId (e.g. onTableCreated on follower), and leader will assign 
later via exploration.
+    String assignedBucketId = null;
+    if (isMasterSlaveMode) {
+      if (haContainer != null && haContainer.hasLeadership()) {
+        TableRuntimeMeta existingMeta =
+            getAs(
+                TableRuntimeMapper.class,
+                mapper -> mapper.selectRuntime(serverTableIdentifier.getId()));
+        if (existingMeta != null) {
+          // Runtime already exists (e.g. inserted by follower with null 
bucketId)
+          if (existingMeta.getBucketId() != null) {
+            return true; // already assigned
+          }
+          assignedBucketId = assignBucketIdForTable();
+          if (assignedBucketId != null) {
+            existingMeta.setBucketId(assignedBucketId);
+            doAs(TableRuntimeMapper.class, mapper -> 
mapper.updateRuntime(existingMeta));

Review Comment:
   Okay, I will add an `updateBucketIdIfNull` method, specifically for updating 
the `bucketId`.



-- 
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