wuchong commented on code in PR #3482:
URL: https://github.com/apache/fluss/pull/3482#discussion_r3408248842


##########
fluss-server/src/main/java/org/apache/fluss/server/coordinator/event/CoordinatorEventManager.java:
##########
@@ -119,7 +120,19 @@ private void updateMetricsViaAccessContext() {
                         context -> {
                             int coordinatorServerCount = 
context.getLiveCoordinatorServers().size();
                             int tabletServerCount = 
context.getLiveTabletServers().size();
-                            int tableCount = context.allTables().size();
+                            // Exclude tables that have been queued for 
deletion (DropTable RPC
+                            // already acked, but completeDeleteTable has not 
yet removed them
+                            // from tablePathById). We dedup by tableId rather 
than subtracting
+                            // sizes so the result is robust even if 
tablesToBeDeleted ever
+                            // drifts out of sync with tablePathById -- it can 
never go negative
+                            // and only counts ids that are truly still in 
tablePathById.
+                            Set<Long> tablesToBeDeleted = 
context.getTablesToBeDeleted();
+                            int tableCount = 0;
+                            for (Long tableId : context.allTables().keySet()) {
+                                if (!tablesToBeDeleted.contains(tableId)) {
+                                    tableCount++;
+                                }

Review Comment:
   We should reverse the lookup by iterating over `tablesToBeDeleted` and 
checking for existence in `context.allTables()`. If a match is found, decrement 
`tableSize`. This approach significantly improves performance.
   
   ```java
   Set<Long> allTables = context.allTables().keySet();
   int tableCount = allTables.size();
   for (Long toDelete : context.getTablesToBeDeleted()) {
       if (allTables.contains(toDelete)) {
           tableCount--;
       }
   }
   ```



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