gyang94 commented on code in PR #2273:
URL: https://github.com/apache/fluss/pull/2273#discussion_r2867007422


##########
fluss-server/src/main/java/org/apache/fluss/server/log/remote/RemoteLogManifest.java:
##########


Review Comment:
   should add `remoteLogDir` in `hashCode()`



##########
fluss-common/src/main/java/org/apache/fluss/remote/RemoteLogSegment.java:
##########
@@ -115,6 +120,10 @@ public int segmentSizeInBytes() {
         return segmentSizeInBytes;
     }
 
+    public FsPath remoteLogDir() {
+        return remoteLogDir;
+    }
+
     @Override
     public boolean equals(Object o) {

Review Comment:
   should check `remoteLogDir` in `equals()`



##########
fluss-server/src/main/java/org/apache/fluss/server/utils/ServerRpcMessageUtils.java:
##########
@@ -588,6 +589,7 @@ private static TableMetadata 
toTableMetaData(PbTableMetadata pbTableMetadata) {
                         tableId,
                         pbTableMetadata.getSchemaId(),
                         
TableDescriptor.fromJsonBytes(pbTableMetadata.getTableJson()),
+                        new FsPath(pbTableMetadata.getRemoteDataDir()),

Review Comment:
   potential NPE



##########
fluss-server/src/main/java/org/apache/fluss/server/log/remote/RemoteLogManifest.java:
##########
@@ -120,11 +125,36 @@ public TableBucket getTableBucket() {
         return tableBucket;
     }
 
+    public FsPath getRemoteLogDir() {
+        return remoteLogDir;
+    }
+
     @VisibleForTesting
     public List<RemoteLogSegment> getRemoteLogSegmentList() {
         return remoteLogSegmentList;
     }
 
+    public RemoteLogManifest newManifest(FsPath remoteLogDir) {
+        List<RemoteLogSegment> newRemoteLogSegments = new 
ArrayList<>(remoteLogSegmentList.size());
+        for (RemoteLogSegment remoteLogSegment : remoteLogSegmentList) {
+            newRemoteLogSegments.add(
+                    RemoteLogSegment.Builder.builder()
+                            
.physicalTablePath(remoteLogSegment.physicalTablePath())
+                            .tableBucket(remoteLogSegment.tableBucket())
+                            
.remoteLogSegmentId(remoteLogSegment.remoteLogSegmentId())
+                            
.remoteLogStartOffset(remoteLogSegment.remoteLogStartOffset())
+                            
.remoteLogEndOffset(remoteLogSegment.remoteLogEndOffset())
+                            .maxTimestamp(remoteLogSegment.maxTimestamp())
+                            
.segmentSizeInBytes(remoteLogSegment.segmentSizeInBytes())
+                            // We set remoteLogDir manually here, so 
subsequent usage will be safe
+                            // to directly use it.
+                            .remoteLogDir(remoteLogDir)
+                            .build());
+        }
+        return new RemoteLogManifest(
+                physicalTablePath, tableBucket, newRemoteLogSegments, 
remoteLogDir);
+    }
+
     @Override
     public boolean equals(Object o) {

Review Comment:
   should check `remoteLogDir` in `equals()`



##########
fluss-server/src/main/java/org/apache/fluss/server/coordinator/remote/RoundRobinRemoteDirSelector.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.remote;
+
+import org.apache.fluss.fs.FsPath;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Round-robin remote data dir selector.
+ *
+ * <p>This implementation cycles through the available remote data directories 
in order, ensuring
+ * each directory is selected once before repeating.
+ *
+ * <p>Example: For directories [A, B, C], the selection sequence would be: A, 
B, C, A, B, C, ...
+ */
+public class RoundRobinRemoteDirSelector implements RemoteDirSelector {
+
+    private final FsPath defaultRemoteDataDir;
+    private final List<FsPath> remoteDataDirs;
+
+    // Current position in the round-robin cycle.
+    private int position;
+
+    // Lock object for thread safety
+    private final Object lock = new Object();
+
+    public RoundRobinRemoteDirSelector(FsPath defaultRemoteDataDir, 
List<FsPath> remoteDataDirs) {
+        this.defaultRemoteDataDir = defaultRemoteDataDir;
+        this.remoteDataDirs = Collections.unmodifiableList(remoteDataDirs);
+        this.position = 0;
+    }
+
+    @Override
+    public FsPath nextDataDir() {
+        if (remoteDataDirs.isEmpty()) {
+            return defaultRemoteDataDir;
+        }
+
+        synchronized (lock) {

Review Comment:
   Will it be better to use `AutomicInteger` for `position`, to avoid 
synchronized lock.



##########
fluss-server/src/main/java/org/apache/fluss/server/coordinator/CoordinatorRequestBatch.java:
##########
@@ -83,6 +84,7 @@ public class CoordinatorRequestBatch {
     private static final Schema EMPTY_SCHEMA = Schema.newBuilder().build();
     private static final TableDescriptor EMPTY_TABLE_DESCRIPTOR =
             
TableDescriptor.builder().schema(EMPTY_SCHEMA).distributedBy(0).build();
+    private static final FsPath EMPTY_REMOTE_DATA_DIR = new FsPath("/");

Review Comment:
   It is confusing about "empty" data dir. Can we set `null` for deleted tables?



##########
fluss-common/src/main/java/org/apache/fluss/config/FlussConfigUtils.java:
##########
@@ -77,4 +81,109 @@ static Map<String, ConfigOption<?>> 
extractConfigOptions(String prefix) {
         }
         return options;
     }
+
+    public static void validateCoordinatorConfigs(Configuration conf) {
+        validServerConfigs(conf);
+
+        validMinValue(conf, ConfigOptions.DEFAULT_REPLICATION_FACTOR, 1);
+        validMinValue(conf, ConfigOptions.KV_MAX_RETAINED_SNAPSHOTS, 1);
+        validMinValue(conf, ConfigOptions.SERVER_IO_POOL_SIZE, 1);
+
+        // Validate remote.data.dirs
+        List<String> remoteDataDirs = conf.get(ConfigOptions.REMOTE_DATA_DIRS);
+        for (int i = 0; i < remoteDataDirs.size(); i++) {
+            String remoteDataDir = remoteDataDirs.get(i);
+            try {
+                new FsPath(remoteDataDir);
+            } catch (Exception e) {
+                throw new IllegalConfigurationException(
+                        String.format(
+                                "Invalid remote path for %s at index %d.",
+                                ConfigOptions.REMOTE_DATA_DIRS.key(), i),
+                        e);
+            }
+        }
+
+        // Validate remote.data.dirs.strategy
+        ConfigOptions.RemoteDataDirStrategy remoteDataDirStrategy =
+                conf.get(ConfigOptions.REMOTE_DATA_DIRS_STRATEGY);
+        if (remoteDataDirStrategy == 
ConfigOptions.RemoteDataDirStrategy.WEIGHTED_ROUND_ROBIN) {
+            List<Integer> weights = 
conf.get(ConfigOptions.REMOTE_DATA_DIRS_WEIGHTS);
+            if (!remoteDataDirs.isEmpty() && !weights.isEmpty()) {
+                if (remoteDataDirs.size() != weights.size()) {
+                    throw new IllegalConfigurationException(
+                            String.format(
+                                    "The size of '%s' (%d) must match the size 
of '%s' (%d) when using WEIGHTED_ROUND_ROBIN strategy.",
+                                    ConfigOptions.REMOTE_DATA_DIRS.key(),
+                                    remoteDataDirs.size(),
+                                    
ConfigOptions.REMOTE_DATA_DIRS_WEIGHTS.key(),
+                                    weights.size()));
+                }
+                // Validate all weights are positive
+                for (int i = 0; i < weights.size(); i++) {
+                    if (weights.get(i) < 0) {

Review Comment:
   should we allow the `weight` be `0`? 
   The remote dir won't be selected if the weight is 0



##########
fluss-common/src/main/java/org/apache/fluss/remote/RemoteLogSegment.java:
##########


Review Comment:
   should add `remoteLogDir` in `hashCode()`



##########
fluss-server/src/main/java/org/apache/fluss/server/coordinator/remote/RoundRobinRemoteDirSelector.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.remote;
+
+import org.apache.fluss.fs.FsPath;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Round-robin remote data dir selector.
+ *
+ * <p>This implementation cycles through the available remote data directories 
in order, ensuring
+ * each directory is selected once before repeating.
+ *
+ * <p>Example: For directories [A, B, C], the selection sequence would be: A, 
B, C, A, B, C, ...
+ */
+public class RoundRobinRemoteDirSelector implements RemoteDirSelector {
+
+    private final FsPath defaultRemoteDataDir;
+    private final List<FsPath> remoteDataDirs;
+
+    // Current position in the round-robin cycle.
+    private int position;
+
+    // Lock object for thread safety
+    private final Object lock = new Object();
+
+    public RoundRobinRemoteDirSelector(FsPath defaultRemoteDataDir, 
List<FsPath> remoteDataDirs) {
+        this.defaultRemoteDataDir = defaultRemoteDataDir;
+        this.remoteDataDirs = Collections.unmodifiableList(remoteDataDirs);
+        this.position = 0;
+    }
+
+    @Override
+    public FsPath nextDataDir() {
+        if (remoteDataDirs.isEmpty()) {
+            return defaultRemoteDataDir;
+        }
+
+        synchronized (lock) {
+            int selectedIndex = position++;
+            if (position == remoteDataDirs.size()) {

Review Comment:
   position = (position + 1) % remoteDataDirs.size()



##########
fluss-server/src/main/java/org/apache/fluss/server/utils/ServerRpcMessageUtils.java:
##########
@@ -530,6 +530,7 @@ private static PbTableMetadata 
toPbTableMetadata(TableMetadata tableMetadata) {
                         .setTableId(tableInfo.getTableId())
                         .setSchemaId(tableInfo.getSchemaId())
                         
.setTableJson(tableInfo.toTableDescriptor().toJsonBytes())
+                        
.setRemoteDataDir(tableInfo.getRemoteDataDir().toString())

Review Comment:
   Will `tableInfo.getRemoteDataDir()` return `null` if remote dir is not set?
   If yes, there will be a NPE.



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