SilverNarcissus commented on a change in pull request #5295:
URL: https://github.com/apache/iotdb/pull/5295#discussion_r840598244



##########
File path: 
server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/rocksdb/RSchemaReadWriteHandler.java
##########
@@ -0,0 +1,581 @@
+/*
+ * 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.iotdb.db.metadata.schemaregion.rocksdb;
+
+import org.apache.iotdb.commons.utils.TestOnly;
+import org.apache.iotdb.db.conf.IoTDBConfig;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.mnode.IMeasurementMNode;
+import org.apache.iotdb.db.metadata.mnode.MeasurementMNode;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.metadata.schemaregion.rocksdb.mnode.RMNodeType;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+import com.google.common.primitives.Bytes;
+import org.rocksdb.BlockBasedTableConfig;
+import org.rocksdb.BloomFilter;
+import org.rocksdb.Cache;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.ColumnFamilyOptions;
+import org.rocksdb.DBOptions;
+import org.rocksdb.Filter;
+import org.rocksdb.Holder;
+import org.rocksdb.InfoLogLevel;
+import org.rocksdb.LRUCache;
+import org.rocksdb.Options;
+import org.rocksdb.RocksDB;
+import org.rocksdb.RocksDBException;
+import org.rocksdb.RocksIterator;
+import org.rocksdb.Statistics;
+import org.rocksdb.WriteBatch;
+import org.rocksdb.WriteOptions;
+import org.rocksdb.util.SizeUnit;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
+
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.ALL_NODE_TYPE_ARRAY;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.DATA_BLOCK_TYPE_ORIGIN_KEY;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.DATA_BLOCK_TYPE_SCHEMA;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.DATA_VERSION;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.DEFAULT_FLAG;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.NODE_TYPE_ENTITY;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.NODE_TYPE_MEASUREMENT;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.NODE_TYPE_ROOT;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.PATH_SEPARATOR;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.ROOT;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.TABLE_NAME_TAGS;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.ZERO;
+
+public class RSchemaReadWriteHandler {
+
+  private static final Logger logger = 
LoggerFactory.getLogger(RSchemaReadWriteHandler.class);
+
+  protected static IoTDBConfig config = 
IoTDBDescriptor.getInstance().getConfig();
+
+  private static final String ROCKSDB_FOLDER = "rocksdb-schema";
+
+  private static final String[] INNER_TABLES =
+      new String[] {new String(RocksDB.DEFAULT_COLUMN_FAMILY), 
TABLE_NAME_TAGS};
+
+  public static final String ROCKSDB_PATH = config.getSystemDir() + 
File.separator + ROCKSDB_FOLDER;
+
+  private RocksDB rocksDB;
+
+  ConcurrentMap<String, ColumnFamilyHandle> columnFamilyHandleMap = new 
ConcurrentHashMap<>();
+  List<ColumnFamilyDescriptor> columnFamilyDescriptors = new ArrayList<>();
+  List<ColumnFamilyHandle> columnFamilyHandles = new ArrayList<>();
+
+  static {
+    RocksDB.loadLibrary();
+  }
+
+  public RSchemaReadWriteHandler(String path) throws RocksDBException {
+    initReadWriteHandler(path);
+  }
+
+  public RSchemaReadWriteHandler() throws RocksDBException {
+    initReadWriteHandler(ROCKSDB_PATH);
+  }
+
+  private void initReadWriteHandler(String path) throws RocksDBException {
+    try (Options options = new Options()) {
+      org.rocksdb.Logger rocksDBLogger = new RSchemaLogger(options, logger);
+      rocksDBLogger.setInfoLogLevel(InfoLogLevel.ERROR_LEVEL);
+
+      options
+          .setCreateIfMissing(true)
+          .setAllowMmapReads(true)
+          .setWriteBufferSize(64 * SizeUnit.KB)
+          .setMaxWriteBufferNumber(6)
+          .setMaxBackgroundJobs(10)
+          .setStatistics(new Statistics())
+          .setLogger(rocksDBLogger);
+
+      final Filter bloomFilter = new BloomFilter(64);
+
+      final BlockBasedTableConfig table_options = new BlockBasedTableConfig();
+      Cache cache = new LRUCache(20L * 1024 * 1024 * 1024, 6);

Review comment:
       This size can be a constant.

##########
File path: server/src/assembly/resources/conf/iotdb-engine.properties
##########
@@ -505,6 +505,14 @@ timestamp_precision=ms
 # Datatype: int
 # query_timeout_threshold=60000
 
+####################

Review comment:
       Please also update doc

##########
File path: 
server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/rocksdb/RSchemaReadWriteHandler.java
##########
@@ -0,0 +1,581 @@
+/*
+ * 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.iotdb.db.metadata.schemaregion.rocksdb;
+
+import org.apache.iotdb.commons.utils.TestOnly;
+import org.apache.iotdb.db.conf.IoTDBConfig;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.mnode.IMeasurementMNode;
+import org.apache.iotdb.db.metadata.mnode.MeasurementMNode;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.metadata.schemaregion.rocksdb.mnode.RMNodeType;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+import com.google.common.primitives.Bytes;
+import org.rocksdb.BlockBasedTableConfig;
+import org.rocksdb.BloomFilter;
+import org.rocksdb.Cache;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.ColumnFamilyOptions;
+import org.rocksdb.DBOptions;
+import org.rocksdb.Filter;
+import org.rocksdb.Holder;
+import org.rocksdb.InfoLogLevel;
+import org.rocksdb.LRUCache;
+import org.rocksdb.Options;
+import org.rocksdb.RocksDB;
+import org.rocksdb.RocksDBException;
+import org.rocksdb.RocksIterator;
+import org.rocksdb.Statistics;
+import org.rocksdb.WriteBatch;
+import org.rocksdb.WriteOptions;
+import org.rocksdb.util.SizeUnit;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
+
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.ALL_NODE_TYPE_ARRAY;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.DATA_BLOCK_TYPE_ORIGIN_KEY;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.DATA_BLOCK_TYPE_SCHEMA;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.DATA_VERSION;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.DEFAULT_FLAG;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.NODE_TYPE_ENTITY;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.NODE_TYPE_MEASUREMENT;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.NODE_TYPE_ROOT;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.PATH_SEPARATOR;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.ROOT;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.TABLE_NAME_TAGS;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.ZERO;
+
+public class RSchemaReadWriteHandler {
+
+  private static final Logger logger = 
LoggerFactory.getLogger(RSchemaReadWriteHandler.class);
+
+  protected static IoTDBConfig config = 
IoTDBDescriptor.getInstance().getConfig();
+
+  private static final String ROCKSDB_FOLDER = "rocksdb-schema";
+
+  private static final String[] INNER_TABLES =
+      new String[] {new String(RocksDB.DEFAULT_COLUMN_FAMILY), 
TABLE_NAME_TAGS};
+
+  public static final String ROCKSDB_PATH = config.getSystemDir() + 
File.separator + ROCKSDB_FOLDER;
+
+  private RocksDB rocksDB;
+
+  ConcurrentMap<String, ColumnFamilyHandle> columnFamilyHandleMap = new 
ConcurrentHashMap<>();
+  List<ColumnFamilyDescriptor> columnFamilyDescriptors = new ArrayList<>();
+  List<ColumnFamilyHandle> columnFamilyHandles = new ArrayList<>();
+
+  static {
+    RocksDB.loadLibrary();
+  }
+
+  public RSchemaReadWriteHandler(String path) throws RocksDBException {
+    initReadWriteHandler(path);
+  }
+
+  public RSchemaReadWriteHandler() throws RocksDBException {
+    initReadWriteHandler(ROCKSDB_PATH);
+  }
+
+  private void initReadWriteHandler(String path) throws RocksDBException {
+    try (Options options = new Options()) {
+      org.rocksdb.Logger rocksDBLogger = new RSchemaLogger(options, logger);
+      rocksDBLogger.setInfoLogLevel(InfoLogLevel.ERROR_LEVEL);
+
+      options
+          .setCreateIfMissing(true)
+          .setAllowMmapReads(true)
+          .setWriteBufferSize(64 * SizeUnit.KB)
+          .setMaxWriteBufferNumber(6)
+          .setMaxBackgroundJobs(10)
+          .setStatistics(new Statistics())
+          .setLogger(rocksDBLogger);
+
+      final Filter bloomFilter = new BloomFilter(64);
+
+      final BlockBasedTableConfig table_options = new BlockBasedTableConfig();
+      Cache cache = new LRUCache(20L * 1024 * 1024 * 1024, 6);
+      table_options
+          .setBlockCache(cache)
+          .setFilterPolicy(bloomFilter)
+          .setBlockSizeDeviation(5)
+          .setBlockRestartInterval(10)
+          .setCacheIndexAndFilterBlocks(true)
+          .setBlockCacheCompressed(new LRUCache(10L * 1024 * 1024 * 1024, 6));

Review comment:
       This size can be a constant.

##########
File path: 
server/src/test/java/org/apache/iotdb/db/metadata/schemaregion/rocksdb/MRocksDBBenchmark.java
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.iotdb.db.metadata.schemaregion.rocksdb;
+
+import org.apache.iotdb.db.conf.IoTDBConfig;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.mnode.IMNode;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.qp.physical.sys.CreateTimeSeriesPlan;
+
+import org.junit.Ignore;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+@Ignore
+public class MRocksDBBenchmark {
+  protected static IoTDBConfig config = 
IoTDBDescriptor.getInstance().getConfig();
+  private RSchemaRegion rocksDBManager;
+
+  public MRocksDBBenchmark(RSchemaRegion rocksDBManager) {
+    this.rocksDBManager = rocksDBManager;
+  }
+
+  public List<RocksDBBenchmarkTask.BenchmarkResult> benchmarkResults = new 
ArrayList<>();
+
+  //  public void testStorageGroupCreation(List<SetStorageGroupPlan> 
storageGroups) {

Review comment:
       This class has too many commented code. Please explain the main function 
of this class and remove these commented code.

##########
File path: 
server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/rocksdb/RSchemaReadWriteHandler.java
##########
@@ -0,0 +1,581 @@
+/*
+ * 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.iotdb.db.metadata.schemaregion.rocksdb;
+
+import org.apache.iotdb.commons.utils.TestOnly;
+import org.apache.iotdb.db.conf.IoTDBConfig;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.mnode.IMeasurementMNode;
+import org.apache.iotdb.db.metadata.mnode.MeasurementMNode;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.metadata.schemaregion.rocksdb.mnode.RMNodeType;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+import com.google.common.primitives.Bytes;
+import org.rocksdb.BlockBasedTableConfig;
+import org.rocksdb.BloomFilter;
+import org.rocksdb.Cache;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.ColumnFamilyOptions;
+import org.rocksdb.DBOptions;
+import org.rocksdb.Filter;
+import org.rocksdb.Holder;
+import org.rocksdb.InfoLogLevel;
+import org.rocksdb.LRUCache;
+import org.rocksdb.Options;
+import org.rocksdb.RocksDB;
+import org.rocksdb.RocksDBException;
+import org.rocksdb.RocksIterator;
+import org.rocksdb.Statistics;
+import org.rocksdb.WriteBatch;
+import org.rocksdb.WriteOptions;
+import org.rocksdb.util.SizeUnit;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
+
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.ALL_NODE_TYPE_ARRAY;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.DATA_BLOCK_TYPE_ORIGIN_KEY;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.DATA_BLOCK_TYPE_SCHEMA;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.DATA_VERSION;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.DEFAULT_FLAG;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.NODE_TYPE_ENTITY;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.NODE_TYPE_MEASUREMENT;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.NODE_TYPE_ROOT;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.PATH_SEPARATOR;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.ROOT;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.TABLE_NAME_TAGS;
+import static 
org.apache.iotdb.db.metadata.schemaregion.rocksdb.RSchemaConstants.ZERO;
+
+public class RSchemaReadWriteHandler {
+
+  private static final Logger logger = 
LoggerFactory.getLogger(RSchemaReadWriteHandler.class);
+
+  protected static IoTDBConfig config = 
IoTDBDescriptor.getInstance().getConfig();
+
+  private static final String ROCKSDB_FOLDER = "rocksdb-schema";
+
+  private static final String[] INNER_TABLES =
+      new String[] {new String(RocksDB.DEFAULT_COLUMN_FAMILY), 
TABLE_NAME_TAGS};
+
+  public static final String ROCKSDB_PATH = config.getSystemDir() + 
File.separator + ROCKSDB_FOLDER;
+
+  private RocksDB rocksDB;
+
+  ConcurrentMap<String, ColumnFamilyHandle> columnFamilyHandleMap = new 
ConcurrentHashMap<>();
+  List<ColumnFamilyDescriptor> columnFamilyDescriptors = new ArrayList<>();
+  List<ColumnFamilyHandle> columnFamilyHandles = new ArrayList<>();
+
+  static {
+    RocksDB.loadLibrary();
+  }
+
+  public RSchemaReadWriteHandler(String path) throws RocksDBException {
+    initReadWriteHandler(path);
+  }
+
+  public RSchemaReadWriteHandler() throws RocksDBException {
+    initReadWriteHandler(ROCKSDB_PATH);
+  }
+
+  private void initReadWriteHandler(String path) throws RocksDBException {
+    try (Options options = new Options()) {
+      org.rocksdb.Logger rocksDBLogger = new RSchemaLogger(options, logger);
+      rocksDBLogger.setInfoLogLevel(InfoLogLevel.ERROR_LEVEL);
+
+      options
+          .setCreateIfMissing(true)
+          .setAllowMmapReads(true)
+          .setWriteBufferSize(64 * SizeUnit.KB)
+          .setMaxWriteBufferNumber(6)
+          .setMaxBackgroundJobs(10)
+          .setStatistics(new Statistics())
+          .setLogger(rocksDBLogger);
+
+      final Filter bloomFilter = new BloomFilter(64);
+
+      final BlockBasedTableConfig table_options = new BlockBasedTableConfig();
+      Cache cache = new LRUCache(20L * 1024 * 1024 * 1024, 6);
+      table_options
+          .setBlockCache(cache)
+          .setFilterPolicy(bloomFilter)
+          .setBlockSizeDeviation(5)
+          .setBlockRestartInterval(10)
+          .setCacheIndexAndFilterBlocks(true)
+          .setBlockCacheCompressed(new LRUCache(10L * 1024 * 1024 * 1024, 6));
+
+      options.setTableFormatConfig(table_options);
+
+      try (DBOptions dbOptions = new DBOptions(options)) {
+
+        initColumnFamilyDescriptors(options, path);
+
+        rocksDB = RocksDB.open(dbOptions, path, columnFamilyDescriptors, 
columnFamilyHandles);
+
+        initInnerColumnFamilies();
+
+        initRootKey();
+      }
+    }
+  }
+
+  private void initColumnFamilyDescriptors(Options options, String path) 
throws RocksDBException {
+    List<byte[]> cfs = RocksDB.listColumnFamilies(options, path);
+    if (cfs.size() <= 0) {
+      cfs = new ArrayList<>();
+      cfs.add(RocksDB.DEFAULT_COLUMN_FAMILY);
+    }
+
+    for (byte[] tableBytes : cfs) {
+      columnFamilyDescriptors.add(
+          new ColumnFamilyDescriptor(tableBytes, new ColumnFamilyOptions()));
+    }
+  }
+
+  private void initInnerColumnFamilies() throws RocksDBException {
+    for (String tableNames : INNER_TABLES) {
+      boolean tableCreated = false;
+      for (ColumnFamilyHandle cfh : columnFamilyHandles) {
+        if (tableNames.equals(new String(cfh.getName()))) {
+          tableCreated = true;
+          break;
+        }
+      }
+      if (!tableCreated) {
+        createTable(tableNames);
+      }
+    }
+    for (ColumnFamilyHandle handle : columnFamilyHandles) {
+      columnFamilyHandleMap.put(new String(handle.getName()), handle);
+    }
+  }
+
+  private void initRootKey() throws RocksDBException {
+    byte[] rootKey = RSchemaUtils.toRocksDBKey(ROOT, NODE_TYPE_ROOT);
+    if (!keyExist(rootKey)) {
+      rocksDB.put(rootKey, new byte[] {DATA_VERSION, DEFAULT_FLAG});
+    }
+  }
+
+  private void createTable(String tableName) throws RocksDBException {
+    ColumnFamilyHandle columnFamilyHandle =
+        rocksDB.createColumnFamily(
+            new ColumnFamilyDescriptor(tableName.getBytes(), new 
ColumnFamilyOptions()));
+    columnFamilyDescriptors.add(
+        new ColumnFamilyDescriptor(tableName.getBytes(), new 
ColumnFamilyOptions()));
+    columnFamilyHandles.add(columnFamilyHandle);
+  }
+
+  public ColumnFamilyHandle getCFHByName(String columnFamilyName) {
+    return columnFamilyHandleMap.get(columnFamilyName);
+  }
+
+  public void updateNode(byte[] key, byte[] value) throws RocksDBException {
+    rocksDB.put(key, value);
+  }
+
+  public void createNode(String levelKey, RMNodeType type, byte[] value) 
throws RocksDBException {
+    byte[] nodeKey = RSchemaUtils.toRocksDBKey(levelKey, type.getValue());
+    rocksDB.put(nodeKey, value);
+  }
+
+  public void createNode(byte[] nodeKey, byte[] value) throws RocksDBException 
{
+    rocksDB.put(nodeKey, value);
+  }
+
+  public void convertToEntityNode(String levelPath, byte[] value) throws 
RocksDBException {
+    try (WriteBatch batch = new WriteBatch()) {
+      byte[] internalKey = RSchemaUtils.toInternalNodeKey(levelPath);
+      byte[] entityKey = RSchemaUtils.toEntityNodeKey(levelPath);
+      batch.delete(internalKey);
+      batch.put(entityKey, value);
+      executeBatch(batch);
+    }
+  }
+
+  public IMeasurementMNode getMeasurementMNode(PartialPath fullPath) throws 
MetadataException {
+    String[] nodes = fullPath.getNodes();
+    String key = RSchemaUtils.getLevelPath(nodes, nodes.length - 1);
+    try {
+      byte[] value = rocksDB.get(key.getBytes());
+      if (value == null) {
+        logger.warn("path not exist: {}", key);
+        throw new MetadataException("key not exist");
+      }
+      return new MeasurementMNode(null, fullPath.getFullPath(), null, null);
+    } catch (RocksDBException e) {
+      throw new MetadataException(e);
+    }
+  }
+
+  public boolean keyExistByType(String levelKey, RMNodeType type) throws 
RocksDBException {
+    return keyExistByType(levelKey, type, new Holder<>());
+  }
+
+  public boolean keyExistByType(String levelKey, RMNodeType type, 
Holder<byte[]> holder)
+      throws RocksDBException {
+    byte[] key = RSchemaUtils.toRocksDBKey(levelKey, type.getValue());
+    return keyExist(key, holder);
+  }
+
+  public CheckKeyResult keyExistByAllTypes(String levelKey) throws 
RocksDBException {
+    RMNodeType[] types =
+        new RMNodeType[] {
+          RMNodeType.ALISA,
+          RMNodeType.ENTITY,
+          RMNodeType.INTERNAL,
+          RMNodeType.MEASUREMENT,
+          RMNodeType.STORAGE_GROUP
+        };
+    return keyExistByTypes(levelKey, types);
+  }
+
+  public CheckKeyResult keyExistByTypes(String levelKey, RMNodeType... types)
+      throws RocksDBException {
+    CheckKeyResult result = new CheckKeyResult();
+    try {
+      Arrays.stream(types)
+          //          .parallel()

Review comment:
       Why this line is commented?




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