sashapolo commented on code in PR #769:
URL: https://github.com/apache/ignite-3/pull/769#discussion_r851104622


##########
modules/raft/src/main/java/org/apache/ignite/raft/jraft/storage/impl/DefaultLogStorageProvider.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.raft.jraft.storage.impl;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.rocksdb.RocksDB.DEFAULT_COLUMN_FAMILY;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.ignite.raft.jraft.option.RaftOptions;
+import org.apache.ignite.raft.jraft.storage.LogStorage;
+import org.apache.ignite.raft.jraft.storage.LogStorageProvider;
+import org.apache.ignite.raft.jraft.util.Platform;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.ColumnFamilyOptions;
+import org.rocksdb.CompactionStyle;
+import org.rocksdb.CompressionType;
+import org.rocksdb.DBOptions;
+import org.rocksdb.Env;
+import org.rocksdb.Priority;
+import org.rocksdb.RocksDB;
+import org.rocksdb.util.SizeUnit;
+
+public class DefaultLogStorageProvider implements LogStorageProvider {
+    /** Database path. */
+    private final Path path;
+
+    /** Database instance shared across log storages. */
+    private RocksDB db;
+
+    /** Database options. */
+    private DBOptions dbOptions;
+
+    /** Configuration column family handle. */
+    private ColumnFamilyHandle confHandle;
+
+    /** Data column family handle. */
+    private ColumnFamilyHandle dataHandle;
+
+    public DefaultLogStorageProvider(Path path) {
+        this.path = path;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void start() {
+        if (Files.notExists(path)) {
+            try {
+                Files.createDirectories(path);
+            }
+            catch (IOException e) {
+                throw new IllegalStateException("Failed to create file: " + 
this.path, e);
+            }
+        }
+
+        if (Files.exists(path) && !Files.isDirectory(path)) {
+            throw new IllegalStateException("Invalid log path, it's a regular 
file: " + this.path);
+        }
+
+        final List<ColumnFamilyHandle> columnFamilyHandles = new ArrayList<>();
+
+        this.dbOptions = createDBOptions();
+
+        final List<ColumnFamilyDescriptor> columnFamilyDescriptors = new 
ArrayList<>();
+        final ColumnFamilyOptions cfOption = createColumnFamilyOptions();
+
+        // Column family to store configuration log entry.
+        columnFamilyDescriptors.add(new 
ColumnFamilyDescriptor("Configuration".getBytes(UTF_8), cfOption));
+        // Default column family to store user data log entry.
+        columnFamilyDescriptors.add(new 
ColumnFamilyDescriptor(DEFAULT_COLUMN_FAMILY, cfOption));
+
+        try {
+            this.db = RocksDB.open(this.dbOptions, this.path.toString(), 
columnFamilyDescriptors, columnFamilyHandles);
+
+            // Setup rocks thread pools
+            Env env = db.getEnv();
+            
env.setBackgroundThreads(Runtime.getRuntime().availableProcessors(), 
Priority.HIGH);
+            
env.setBackgroundThreads(Runtime.getRuntime().availableProcessors(), 
Priority.LOW);
+
+            assert (columnFamilyHandles.size() == 2);
+            this.confHandle = columnFamilyHandles.get(0);
+            this.dataHandle = columnFamilyHandles.get(1);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void shutdown() {
+        confHandle.close();

Review Comment:
   you should use `IgniteUtils.closeAll`



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