SammyVimes commented on a change in pull request #203:
URL: https://github.com/apache/ignite-3/pull/203#discussion_r668587337



##########
File path: 
modules/metastorage-server/src/main/java/org/apache/ignite/internal/metastorage/server/RocksDBKeyValueStorage.java
##########
@@ -0,0 +1,1249 @@
+/*
+ * 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.metastorage.server;
+
+import java.nio.ByteBuffer;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NavigableMap;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.function.Predicate;
+import org.apache.ignite.internal.util.ByteUtils;
+import org.apache.ignite.internal.util.Cursor;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.lang.IgniteInternalException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.rocksdb.EnvOptions;
+import org.rocksdb.IngestExternalFileOptions;
+import org.rocksdb.Options;
+import org.rocksdb.ReadOptions;
+import org.rocksdb.RocksDB;
+import org.rocksdb.RocksDBException;
+import org.rocksdb.RocksIterator;
+import org.rocksdb.Snapshot;
+import org.rocksdb.SstFileWriter;
+import org.rocksdb.StringAppendOperator;
+
+import static org.apache.ignite.internal.metastorage.server.Value.TOMBSTONE;
+
+/**
+ * Key-value storage based on RocksDB.
+ * Keys are stored with revision.
+ * Values are stored with update counter and a boolean flag which represenets 
whether this record is a tombstone.
+ * <br>
+ * Key: [8 bytes revision, N bytes key itself].
+ * <br>
+ * Value: [8 bytes update counter, 1 byte tombstone flag, N bytes value].
+ */
+public class RocksDBKeyValueStorage implements KeyValueStorage {
+    /** Database snapshot file name. */
+    private static final String SNAPSHOT_FILE_NAME = "db.snapshot";
+
+    /** Suffix for temporal snapshot folder */
+    private static final String TMP_SUFFIX = ".tmp";
+
+    /** Revision key. */
+    private static final byte[] REVISION_KEY = keyToRocksKey(-1, 
"SYSTEM_REVISION_KEY".getBytes());
+
+    /** Update counter key. */
+    private static final byte[] UPDATE_COUNTER_KEY = keyToRocksKey(-1, 
"SYSTEM_UPDATE_COUNTER_KEY".getBytes());
+
+    static {
+        RocksDB.loadLibrary();
+    }
+
+    /** RockDB options. */
+    private final Options options;
+
+    /** RocksDb instance. */
+    private final RocksDB db;
+
+    /** RW lock. */
+    private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
+
+    /** Thread-pool for a snapshot operation execution. */
+    private final Executor snapshotExecutor = 
Executors.newSingleThreadExecutor();
+    
+    /**
+     * Special value for revision number which means that operation should be 
applied
+     * to the latest revision of an entry.
+     */
+    private static final long LATEST_REV = -1;
+
+    /** Lexicographic order comparator. */
+    private final Comparator<byte[]> CMP = Arrays::compare;
+
+    /** Keys index. Value is the list of all revisions under which entry 
corresponding to the key was modified. */
+    private NavigableMap<byte[], List<Long>> keysIdx = new TreeMap<>(CMP);
+
+    /** Revision. Will be incremented for each single-entry or multi-entry 
update operation. */
+    private long rev;
+
+    /** Update counter. Will be incremented for each update of any particular 
entry. */
+    private long updCntr;
+
+    /**
+     * Constructor.
+     *
+     * @param dbPath RocksDB path.
+     */
+    public RocksDBKeyValueStorage(Path dbPath) {
+        try {
+            options = new Options();
+
+            options.setCreateIfMissing(true);
+
+            options.useFixedLengthPrefixExtractor(8);

Review comment:
       We have a simple prefix search (by equality), I'm not sure if that 
should be different. 




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