Copilot commented on code in PR #9505:
URL: https://github.com/apache/seatunnel/pull/9505#discussion_r2178853494


##########
seatunnel-connectors-v2/connector-fake/src/main/java/org/apache/seatunnel/connectors/seatunnel/fake/source/FakeSource.java:
##########
@@ -32,10 +32,13 @@
 import 
org.apache.seatunnel.connectors.seatunnel.fake.config.MultipleTableFakeSourceConfig;
 import org.apache.seatunnel.connectors.seatunnel.fake.state.FakeSourceState;
 
+import lombok.extern.slf4j.Slf4j;
+
 import java.util.Collections;
 import java.util.List;
 import java.util.stream.Collectors;
 
+@Slf4j

Review Comment:
   [nitpick] The `@Slf4j` annotation is added but no logging calls are used in 
this class; consider removing it or adding relevant log statements.



##########
seatunnel-connectors-v2/connector-fake/src/main/java/org/apache/seatunnel/connectors/seatunnel/fake/utils/IdGeneratorUtils.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.fake.utils;
+
+import org.apache.seatunnel.shade.com.google.common.cache.Cache;
+import org.apache.seatunnel.shade.com.google.common.cache.CacheBuilder;
+
+import org.apache.seatunnel.api.table.catalog.CatalogTable;
+import org.apache.seatunnel.api.table.catalog.PrimaryKey;
+import org.apache.seatunnel.connectors.seatunnel.fake.config.FakeConfig;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
+public class IdGeneratorUtils {
+
+    private static final Cache<String, AutoIncrementIdGenerator> idGenerators =
+            CacheBuilder.newBuilder()
+                    .maximumSize(1000)
+                    .expireAfterWrite(30, TimeUnit.MINUTES)
+                    .build();
+
+    public static synchronized Optional<AutoIncrementIdGenerator> 
getIdGenerator(

Review Comment:
   The method is declared `synchronized`, which may become a bottleneck under 
high concurrency; consider relying on Guava's thread-safe cache instead of 
external synchronization.
   ```suggestion
       public static Optional<AutoIncrementIdGenerator> getIdGenerator(
   ```



##########
seatunnel-connectors-v2/connector-fake/src/main/java/org/apache/seatunnel/connectors/seatunnel/fake/utils/FakeDataRandomUtils.java:
##########
@@ -101,6 +119,15 @@ public Integer randomInt(Column column) {
     }
 
     public Long randomBigint(Column column) {
+        if (fakeConfig.getAutoIncrementEnabled()
+                && IdGeneratorUtils.isPrimaryColumn(fakeConfig, 
column.getName())) {

Review Comment:
   There's no overflow check for `auto.increment.start + parallelism * rowNum` 
when generating bigints; this could exceed `Long.MAX_VALUE`.
   ```suggestion
                   && IdGeneratorUtils.isPrimaryColumn(fakeConfig, 
column.getName())) {
               long autoIncrementStart = fakeConfig.getAutoIncrementStart();
               long parallelism = fakeConfig.getParallelism();
               long rowNum = fakeConfig.getRowNum();
               if (autoIncrementStart > 0 && parallelism > 0 && rowNum > 0) {
                   if (autoIncrementStart > Long.MAX_VALUE - (parallelism * 
rowNum)) {
                       throw new IllegalArgumentException(
                               "The auto increment start value is too large, or 
the combination of parallelism and rowNum causes an overflow. Please check your 
configuration.");
                   }
               }
   ```



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