Copilot commented on code in PR #3614:
URL: https://github.com/apache/fluss/pull/3614#discussion_r3563041888


##########
fluss-server/src/main/java/org/apache/fluss/server/coordinator/KvLeaderReplicaCapacityManager.java:
##########
@@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.fluss.server.coordinator;
+
+import org.apache.fluss.annotation.VisibleForTesting;
+import org.apache.fluss.config.ConfigOptions;
+import org.apache.fluss.config.Configuration;
+import org.apache.fluss.config.cluster.ServerReconfigurable;
+import org.apache.fluss.exception.ConfigException;
+import org.apache.fluss.exception.DatabaseNotExistException;
+import org.apache.fluss.exception.FlussRuntimeException;
+import org.apache.fluss.exception.InsufficientKvLeaderReplicaCapacityException;
+import org.apache.fluss.exception.TableNotExistException;
+import org.apache.fluss.metadata.TableInfo;
+import org.apache.fluss.metadata.TablePath;
+import org.apache.fluss.server.metadata.CoordinatorMetadataCache;
+import org.apache.fluss.server.metadata.ServerInfo;
+
+import java.util.List;
+import java.util.Set;
+
+import static org.apache.fluss.utils.Preconditions.checkNotNull;
+
+/** Manages the in-memory cluster capacity for KV leader replicas. */
+public class KvLeaderReplicaCapacityManager implements ServerReconfigurable {
+
+    /** Negative capacity means the automatic capacity limit is disabled. */
+    public static final long CAPACITY_LIMIT_DISABLED = -1L;
+
+    private final Object lock = new Object();
+    private final CoordinatorMetadataCache metadataCache;
+
+    private long leaderReplicaMemoryReservedBytes;
+    private long currentKvLeaderReplicaCount;
+
+    public KvLeaderReplicaCapacityManager(
+            Configuration conf, CoordinatorMetadataCache metadataCache) {
+        this.metadataCache = checkNotNull(metadataCache, "metadataCache should 
not be null.");
+        this.leaderReplicaMemoryReservedBytes = 
getLeaderReplicaMemoryReservedBytes(conf);
+    }

Review Comment:
   `getKvLeaderReplicaCapacityLocked()` divides by 
`leaderReplicaMemoryReservedBytes`, but the constructor does not validate the 
initial configured value. If `kv.leader-replica.memory-reserved` is 
misconfigured as 0 (or negative), this can trigger a divide-by-zero at runtime. 
Validate the initial config in the constructor (consistent with `validate()`) 
before storing it.



##########
fluss-server/src/main/java/org/apache/fluss/server/coordinator/CoordinatorService.java:
##########
@@ -704,7 +778,22 @@ public CompletableFuture<DropTableResponse> 
dropTable(DropTableRequest request)
         authorizeTable(OperationType.DROP, tablePath);
 
         DropTableResponse response = new DropTableResponse();
-        metadataManager.dropTable(tablePath, request.isIgnoreIfNotExists());
+        if (!metadataManager.tableExists(tablePath)) {
+            metadataManager.dropTable(tablePath, 
request.isIgnoreIfNotExists());
+            return CompletableFuture.completedFuture(response);
+        }
+
+        long removedKvLeaderReplicaCount =
+                
getExistingKvLeaderReplicaCount(metadataManager.getTable(tablePath));
+        try {

Review Comment:
   `dropTable` calls `metadataManager.getTable(tablePath)` outside the 
`try`/`catch`, so if the table is deleted between the `tableExists` check and 
the `getTable` call, this method will throw `TableNotExistException` even when 
`ignoreIfNotExists` is true. Fetch the `TableInfo` in a `try`/`catch` and only 
compute/decrease the capacity when the table was actually found.



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