Copilot commented on code in PR #7724:
URL: https://github.com/apache/ignite-3/pull/7724#discussion_r2895537312


##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/impl/RocksDbLogStorageOptions.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.ignite.internal.raft.storage.impl;
+
+import org.apache.ignite.internal.configuration.SystemLocalView;
+import org.apache.ignite.internal.configuration.SystemPropertyView;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.rocksdb.util.SizeUnit;
+
+/**
+ * RocksDB-specific options for RocksDB-based log storage.
+ */
+public class RocksDbLogStorageOptions {
+    private static final IgniteLogger LOG = 
Loggers.forClass(RocksDbLogStorageOptions.class);
+
+    private static final String 
PARTITIONS_RAFT_LOG_STORAGE_WRITE_BUFFER_SIZE_PROPERTY_NAME = 
"partitionsRaftLogStorageWriteBufferSize";
+
+    private static final long DEFAULT_WRITE_BUFFER_SIZE = 64 * SizeUnit.MB;
+
+    private final long writeBufferSize;
+
+    public static RocksDbLogStorageOptions forPartitions(SystemLocalView 
properties) {
+        return new 
RocksDbLogStorageOptions(partitionsRaftLogStorageWriteBufferSize(properties));
+    }
+
+    private static long 
partitionsRaftLogStorageWriteBufferSize(SystemLocalView properties) {
+        SystemPropertyView property = 
properties.properties().get(PARTITIONS_RAFT_LOG_STORAGE_WRITE_BUFFER_SIZE_PROPERTY_NAME);
+
+        if (property == null) {
+            return DEFAULT_WRITE_BUFFER_SIZE;
+        }
+
+        try {
+            return Long.parseLong(property.propertyValue());
+        } catch (NumberFormatException e) {
+            LOG.warn(
+                    "Failed to parse partitions writeBufferSize '{}', default 
value will be used ({})",
+                    e,
+                    property.propertyValue(),
+                    DEFAULT_WRITE_BUFFER_SIZE
+            );
+
+            return DEFAULT_WRITE_BUFFER_SIZE;
+        }

Review Comment:
   `writeBufferSize` is taken verbatim from config and can be <= 0 (or 
extremely large). RocksDB expects sensible positive sizes; with 0/negative 
here, the DB may fail to open or behave unexpectedly. Consider validating the 
parsed value (e.g., require > 0 and maybe enforce an upper bound) and falling 
back to the default (with a warning) when invalid.



##########
modules/raft/src/integrationTest/java/org/apache/ignite/internal/raftsnapshot/ItLogStorageConfigurationTest.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.ignite.internal.raftsnapshot;
+
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.ConfigOverride;
+import org.apache.ignite.internal.raft.storage.LogStorageManager;
+import org.apache.ignite.internal.raft.storage.impl.DefaultLogStorageManager;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.rocksdb.ColumnFamilyOptions;
+
+class ItLogStorageConfigurationTest extends ClusterPerTestIntegrationTest {
+    private Ignite node;
+
+    @Override
+    protected int initialNodes() {
+        return 1;
+    }
+
+    @BeforeEach
+    void prepare() {
+        node = cluster.node(0);
+    }
+
+    @Test
+    @ConfigOverride(name = 
"ignite.system.properties.partitionsRaftLogStorageWriteBufferSize", value = "" 
+ (99L * 1024 * 1024))
+    void partitionsLogStorageWriteBufferSizeIsTakenFromConfiguration() throws 
Exception {
+        LogStorageManager logStorageManager = 
unwrapIgniteImpl(node).partitionsLogStorageManager();
+        DefaultLogStorageManager defaultLogStorageManager = 
(DefaultLogStorageManager) logStorageManager;
+

Review Comment:
   This test assumes `SharedLogStorageManagerUtils.create(...)` returns 
`DefaultLogStorageManager` and force-casts. If the JVM/system property 
`LOGIT_STORAGE_ENABLED` is set, the factory will return 
`LogitLogStorageManager` and this will `ClassCastException`. Consider either 
forcing the property off for this test, or asserting the type and 
skipping/failing with a clear message when logit storage is enabled.



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/impl/DefaultLogStorageManager.java:
##########
@@ -383,16 +392,21 @@ private static ColumnFamilyOptions 
createColumnFamilyOptions() {
                     .optimizeLevelStyleCompaction();
         }
 
-        opts.setWriteBufferSize(64 * SizeUnit.MB);
+        long writeBufferSize = specificOptions.writeBufferSize();
+        int minWriteBufferNumberToMerge = 1;
+        int level0FileNumCompactionTrigger = 50;
+
+        opts.setWriteBufferSize(writeBufferSize);
         opts.setMaxWriteBufferNumber(5);
-        opts.setMinWriteBufferNumberToMerge(1);
-        opts.setLevel0FileNumCompactionTrigger(50);
+
+        opts.setMinWriteBufferNumberToMerge(minWriteBufferNumberToMerge);
+        opts.setLevel0FileNumCompactionTrigger(level0FileNumCompactionTrigger);
         opts.setLevel0SlowdownWritesTrigger(100);
         opts.setLevel0StopWritesTrigger(200);
         // Size of level 0 which is (in stable state) equal to
         // WriteBufferSize * MinWriteBufferNumberToMerge * 
Level0FileNumCompactionTrigger
-        opts.setMaxBytesForLevelBase(3200 * SizeUnit.MB);
-        opts.setTargetFileSizeBase(320 * SizeUnit.MB);
+        opts.setMaxBytesForLevelBase(writeBufferSize * 
minWriteBufferNumberToMerge * level0FileNumCompactionTrigger);
+        opts.setTargetFileSizeBase(writeBufferSize * 5);
 

Review Comment:
   `setMaxBytesForLevelBase` / `setTargetFileSizeBase` are computed via 
multiplications on a user-provided `writeBufferSize`. For large values this can 
overflow `long` and produce negative/incorrect sizes. Consider using 
`Math.multiplyExact` (and falling back/capping on `ArithmeticException`) or 
otherwise clamping values to a safe maximum before passing them to RocksDB.



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/impl/DefaultLogStorageManager.java:
##########
@@ -458,7 +472,7 @@ ColumnFamilyHandle confColumnFamilyHandle() {
     }
 
     @TestOnly
-    ColumnFamilyHandle dataColumnFamilyHandle() {
+    public ColumnFamilyHandle dataColumnFamilyHandle() {

Review Comment:
   Making `dataColumnFamilyHandle()` public increases the production API 
surface of `DefaultLogStorageManager` just to support a test. Prefer keeping it 
package-private (still @TestOnly) and moving the integration test into the same 
package (or using a test-only accessor/reflection) to avoid exposing RocksDB 
internals to non-test code.
   ```suggestion
       ColumnFamilyHandle dataColumnFamilyHandle() {
   ```



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