You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "ibessonov (via GitHub)" <gi...@apache.org> on 2024/01/05 12:34:35 UTC

[PR] IGNITE-21204 Implement shared rocksdb storage for transaction states [ignite-3]

ibessonov opened a new pull request, #3012:
URL: https://github.com/apache/ignite-3/pull/3012

   https://issues.apache.org/jira/browse/IGNITE-21204
   
   Thank you for submitting the pull request.
   
   To streamline the review process of the patch and ensure better code quality
   we ask both an author and a reviewer to verify the following:
   
   ### The Review Checklist
   - [ ] **Formal criteria:** TC status, codestyle, mandatory documentation. Also make sure to complete the following:  
   \- There is a single JIRA ticket related to the pull request.  
   \- The web-link to the pull request is attached to the JIRA ticket.  
   \- The JIRA ticket has the Patch Available state.  
   \- The description of the JIRA ticket explains WHAT was made, WHY and HOW.  
   \- The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
   - [ ] **Design:** new code conforms with the design principles of the components it is added to.
   - [ ] **Patch quality:** patch cannot be split into smaller pieces, its size must be reasonable.
   - [ ] **Code quality:** code is clean and readable, necessary developer documentation is added if needed.
   - [ ] **Tests code quality:** test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.
   
   ### Notes
   - [Apache Ignite Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide)


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21204 Implement shared rocksdb storage for transaction states [ignite-3]

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #3012:
URL: https://github.com/apache/ignite-3/pull/3012#discussion_r1444269209


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbSharedStorage.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.tx.storage.state.rocksdb;
+
+import static java.util.Collections.reverse;
+import static java.util.stream.Collectors.toList;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.IntSupplier;
+import org.apache.ignite.internal.close.ManuallyCloseable;
+import org.apache.ignite.internal.lang.IgniteInternalException;
+import org.apache.ignite.internal.rocksdb.flush.RocksDbFlusher;
+import org.apache.ignite.internal.tx.storage.state.TxStateTableStorage;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.ColumnFamilyOptions;
+import org.rocksdb.DBOptions;
+import org.rocksdb.Options;
+import org.rocksdb.ReadOptions;
+import org.rocksdb.RocksDB;
+import org.rocksdb.WriteOptions;
+
+/**
+ * RocksDb implementation of {@link TxStateTableStorage}.
+ */
+public class TxStateRocksDbSharedStorage implements ManuallyCloseable {
+    static {
+        RocksDB.loadLibrary();
+    }
+
+    /** Column family name for transaction states. */
+    private static final String TX_STATE_CF = new String(RocksDB.DEFAULT_COLUMN_FAMILY, StandardCharsets.UTF_8);
+
+    /** Rocks DB instance. */
+    private volatile RocksDB db;
+
+    /** RocksDb database options. */
+    private volatile DBOptions dbOptions;
+
+    /** Write options. */
+    final WriteOptions writeOptions = new WriteOptions().setDisableWAL(true);
+
+    /** Read options for regular reads. */
+    final ReadOptions readOptions = new ReadOptions();
+
+    /** Database path. */
+    private final Path dbPath;
+
+    /** RocksDB flusher instance. */
+    private volatile RocksDbFlusher flusher;
+
+    /** Prevents double stopping the storage. */
+    private final AtomicBoolean stopGuard = new AtomicBoolean();
+
+    /** Busy lock to stop synchronously. */
+    private final IgniteSpinBusyLock busyLock = new IgniteSpinBusyLock();
+
+    private final ScheduledExecutorService scheduledExecutor;
+
+    /** Thread pool to execute after-flush actions. */
+    private final ExecutorService threadPool;
+
+    /** Supplier for the value of delay for scheduled database flush. */
+    private final IntSupplier flushDelaySupplier;
+
+    /**
+     * Constructor.
+     *
+     * @param dbPath Database path.
+     * @param scheduledExecutor Scheduled executor.
+     */
+    public TxStateRocksDbSharedStorage(
+            Path dbPath,
+            ScheduledExecutorService scheduledExecutor,
+            ExecutorService threadPool,
+            IntSupplier flushDelaySupplier
+    ) {
+        this.dbPath = dbPath;
+        this.scheduledExecutor = scheduledExecutor;
+        this.threadPool = threadPool;
+        this.flushDelaySupplier = flushDelaySupplier;
+
+        try {
+            Files.createDirectories(dbPath);
+        } catch (IOException e) {
+            throw new IgniteInternalException("Failed to create transaction state storage directory", e);
+        }
+    }
+
+    /**
+     * Returns shared {@link RocksDB} instance.
+     */
+    RocksDB db() {
+        return db;
+    }
+
+    /**
+     * Returns a future to await flush.
+     */
+    CompletableFuture<Void> awaitFlush(boolean schedule) {
+        return flusher.awaitFlush(schedule);
+    }
+
+    /**
+     * Starts the storage.
+     */
+    public void start() {
+        try {
+            flusher = new RocksDbFlusher(
+                    busyLock,
+                    scheduledExecutor,
+                    threadPool,
+                    flushDelaySupplier,
+                    () -> {} // No-op.
+            );
+
+            this.dbOptions = new DBOptions()
+                    .setCreateIfMissing(true)
+                    .setAtomicFlush(true)
+                    .setListeners(List.of(flusher.listener()));
+
+            List<ColumnFamilyDescriptor> cfDescriptors;
+
+            try (Options opts = new Options()) {
+                cfDescriptors = RocksDB.listColumnFamilies(opts, dbPath.toAbsolutePath().toString())
+                        .stream()
+                        .map(nameBytes -> new ColumnFamilyDescriptor(nameBytes, new ColumnFamilyOptions()))
+                        .collect(toList());
+
+                cfDescriptors = cfDescriptors.isEmpty()
+                        ? List.of(new ColumnFamilyDescriptor(TX_STATE_CF.getBytes(StandardCharsets.UTF_8), new ColumnFamilyOptions()))
+                        : cfDescriptors;
+            }
+
+            List<ColumnFamilyHandle> cfHandles = new ArrayList<>(cfDescriptors.size());
+
+            this.db = RocksDB.open(dbOptions, dbPath.toString(), cfDescriptors, cfHandles);
+
+            flusher.init(db, cfHandles);
+        } catch (Exception e) {
+            throw new IgniteInternalException("Could not create transaction state storage", e);
+        }
+    }
+
+    @Override
+    public void close() {
+        if (!stopGuard.compareAndSet(false, true)) {
+            return;
+        }
+
+        busyLock.block();
+
+        try {
+            List<AutoCloseable> resources = new ArrayList<>();
+
+            resources.add(readOptions);
+            resources.add(writeOptions);
+            resources.add(dbOptions);
+            resources.add(db);
+
+            reverse(resources);
+            IgniteUtils.closeAll(resources);
+        } catch (Exception e) {
+            throw new IgniteInternalException("Failed to stop transaction state storage", e);

Review Comment:
   Then I would have to handle it in every invocation, and that code is not ready for checked exceptions unfortunately



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21204 Implement shared rocksdb storage for transaction states [ignite-3]

Posted by "tkalkirill (via GitHub)" <gi...@apache.org>.
tkalkirill merged PR #3012:
URL: https://github.com/apache/ignite-3/pull/3012


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21204 Implement shared rocksdb storage for transaction states [ignite-3]

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #3012:
URL: https://github.com/apache/ignite-3/pull/3012#discussion_r1444274634


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -398,28 +391,31 @@ public void destroy() {
     }
 
     private byte[] partitionStartPrefix() {
-        return ByteBuffer.allocate(Short.BYTES).order(ByteOrder.BIG_ENDIAN)
-            .putShort((short) (partitionId))
-            .array();
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES).order(ByteOrder.BIG_ENDIAN)
+                .putInt(tableId)
+                .putShort((short) (partitionId))
+                .array();
     }
 
     private byte[] partitionEndPrefix() {
-        return ByteBuffer.allocate(Short.BYTES).order(ByteOrder.BIG_ENDIAN)
-            .putShort((short) (partitionId + 1))
-            .array();
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES).order(ByteOrder.BIG_ENDIAN)
+                .putInt(tableId)
+                .putShort((short) (partitionId + 1))
+                .array();
     }
 
     private byte[] txIdToKey(UUID txId) {
-        return ByteBuffer.allocate(Short.BYTES + 2 * Long.BYTES).order(ByteOrder.BIG_ENDIAN)
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES + 2 * Long.BYTES).order(ByteOrder.BIG_ENDIAN)

Review Comment:
   How will it help? The size is self-evident from the code below, explaining it in the constant would only smear the information



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21204 Implement shared rocksdb storage for transaction states [ignite-3]

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #3012:
URL: https://github.com/apache/ignite-3/pull/3012#discussion_r1444334646


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbSharedStorage.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.tx.storage.state.rocksdb;
+
+import static java.util.Collections.reverse;
+import static java.util.stream.Collectors.toList;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.IntSupplier;
+import org.apache.ignite.internal.close.ManuallyCloseable;
+import org.apache.ignite.internal.lang.IgniteInternalException;
+import org.apache.ignite.internal.rocksdb.flush.RocksDbFlusher;
+import org.apache.ignite.internal.tx.storage.state.TxStateTableStorage;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.ColumnFamilyOptions;
+import org.rocksdb.DBOptions;
+import org.rocksdb.Options;
+import org.rocksdb.ReadOptions;
+import org.rocksdb.RocksDB;
+import org.rocksdb.WriteOptions;
+
+/**
+ * RocksDb implementation of {@link TxStateTableStorage}.
+ */
+public class TxStateRocksDbSharedStorage implements ManuallyCloseable {
+    static {
+        RocksDB.loadLibrary();
+    }
+
+    /** Column family name for transaction states. */
+    private static final String TX_STATE_CF = new String(RocksDB.DEFAULT_COLUMN_FAMILY, StandardCharsets.UTF_8);
+
+    /** Rocks DB instance. */
+    private volatile RocksDB db;
+
+    /** RocksDb database options. */
+    private volatile DBOptions dbOptions;
+
+    /** Write options. */
+    final WriteOptions writeOptions = new WriteOptions().setDisableWAL(true);
+
+    /** Read options for regular reads. */
+    final ReadOptions readOptions = new ReadOptions();
+
+    /** Database path. */
+    private final Path dbPath;
+
+    /** RocksDB flusher instance. */
+    private volatile RocksDbFlusher flusher;
+
+    /** Prevents double stopping the storage. */
+    private final AtomicBoolean stopGuard = new AtomicBoolean();
+
+    /** Busy lock to stop synchronously. */
+    private final IgniteSpinBusyLock busyLock = new IgniteSpinBusyLock();
+
+    private final ScheduledExecutorService scheduledExecutor;
+
+    /** Thread pool to execute after-flush actions. */
+    private final ExecutorService threadPool;
+
+    /** Supplier for the value of delay for scheduled database flush. */
+    private final IntSupplier flushDelaySupplier;
+
+    /**
+     * Constructor.
+     *
+     * @param dbPath Database path.
+     * @param scheduledExecutor Scheduled executor.
+     */
+    public TxStateRocksDbSharedStorage(
+            Path dbPath,
+            ScheduledExecutorService scheduledExecutor,
+            ExecutorService threadPool,
+            IntSupplier flushDelaySupplier
+    ) {
+        this.dbPath = dbPath;
+        this.scheduledExecutor = scheduledExecutor;
+        this.threadPool = threadPool;
+        this.flushDelaySupplier = flushDelaySupplier;
+
+        try {
+            Files.createDirectories(dbPath);
+        } catch (IOException e) {
+            throw new IgniteInternalException("Failed to create transaction state storage directory", e);
+        }
+    }
+
+    /**
+     * Returns shared {@link RocksDB} instance.
+     */
+    RocksDB db() {
+        return db;
+    }
+
+    /**
+     * Returns a future to await flush.
+     */
+    CompletableFuture<Void> awaitFlush(boolean schedule) {
+        return flusher.awaitFlush(schedule);
+    }
+
+    /**
+     * Starts the storage.
+     */
+    public void start() {
+        try {
+            flusher = new RocksDbFlusher(
+                    busyLock,
+                    scheduledExecutor,
+                    threadPool,
+                    flushDelaySupplier,
+                    () -> {} // No-op.
+            );
+
+            this.dbOptions = new DBOptions()
+                    .setCreateIfMissing(true)
+                    .setAtomicFlush(true)
+                    .setListeners(List.of(flusher.listener()));
+
+            List<ColumnFamilyDescriptor> cfDescriptors;
+
+            try (Options opts = new Options()) {
+                cfDescriptors = RocksDB.listColumnFamilies(opts, dbPath.toAbsolutePath().toString())
+                        .stream()
+                        .map(nameBytes -> new ColumnFamilyDescriptor(nameBytes, new ColumnFamilyOptions()))
+                        .collect(toList());
+
+                cfDescriptors = cfDescriptors.isEmpty()
+                        ? List.of(new ColumnFamilyDescriptor(TX_STATE_CF.getBytes(StandardCharsets.UTF_8), new ColumnFamilyOptions()))
+                        : cfDescriptors;
+            }
+
+            List<ColumnFamilyHandle> cfHandles = new ArrayList<>(cfDescriptors.size());
+
+            this.db = RocksDB.open(dbOptions, dbPath.toString(), cfDescriptors, cfHandles);
+
+            flusher.init(db, cfHandles);
+        } catch (Exception e) {
+            throw new IgniteInternalException("Could not create transaction state storage", e);
+        }
+    }
+
+    @Override
+    public void close() {
+        if (!stopGuard.compareAndSet(false, true)) {
+            return;
+        }
+
+        busyLock.block();
+
+        try {
+            List<AutoCloseable> resources = new ArrayList<>();
+
+            resources.add(readOptions);
+            resources.add(writeOptions);
+            resources.add(dbOptions);
+            resources.add(db);
+
+            reverse(resources);
+            IgniteUtils.closeAll(resources);
+        } catch (Exception e) {
+            throw new IgniteInternalException("Failed to stop transaction state storage", e);

Review Comment:
   My previous answer was not correct, I apologize. I'll remove this handling



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21204 Implement shared rocksdb storage for transaction states [ignite-3]

Posted by "tkalkirill (via GitHub)" <gi...@apache.org>.
tkalkirill commented on code in PR #3012:
URL: https://github.com/apache/ignite-3/pull/3012#discussion_r1444242624


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbSharedStorage.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.tx.storage.state.rocksdb;
+
+import static java.util.Collections.reverse;
+import static java.util.stream.Collectors.toList;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.IntSupplier;
+import org.apache.ignite.internal.close.ManuallyCloseable;
+import org.apache.ignite.internal.lang.IgniteInternalException;
+import org.apache.ignite.internal.rocksdb.flush.RocksDbFlusher;
+import org.apache.ignite.internal.tx.storage.state.TxStateTableStorage;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.ColumnFamilyOptions;
+import org.rocksdb.DBOptions;
+import org.rocksdb.Options;
+import org.rocksdb.ReadOptions;
+import org.rocksdb.RocksDB;
+import org.rocksdb.WriteOptions;
+
+/**
+ * RocksDb implementation of {@link TxStateTableStorage}.

Review Comment:
   There won’t be enough comments, please indicate a few words about why it’s shared and what it will bring.



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbSharedStorage.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.tx.storage.state.rocksdb;
+
+import static java.util.Collections.reverse;
+import static java.util.stream.Collectors.toList;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.IntSupplier;
+import org.apache.ignite.internal.close.ManuallyCloseable;
+import org.apache.ignite.internal.lang.IgniteInternalException;
+import org.apache.ignite.internal.rocksdb.flush.RocksDbFlusher;
+import org.apache.ignite.internal.tx.storage.state.TxStateTableStorage;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.ColumnFamilyOptions;
+import org.rocksdb.DBOptions;
+import org.rocksdb.Options;
+import org.rocksdb.ReadOptions;
+import org.rocksdb.RocksDB;
+import org.rocksdb.WriteOptions;
+
+/**
+ * RocksDb implementation of {@link TxStateTableStorage}.
+ */
+public class TxStateRocksDbSharedStorage implements ManuallyCloseable {
+    static {
+        RocksDB.loadLibrary();
+    }
+
+    /** Column family name for transaction states. */
+    private static final String TX_STATE_CF = new String(RocksDB.DEFAULT_COLUMN_FAMILY, StandardCharsets.UTF_8);
+
+    /** Rocks DB instance. */
+    private volatile RocksDB db;
+
+    /** RocksDb database options. */
+    private volatile DBOptions dbOptions;
+
+    /** Write options. */
+    final WriteOptions writeOptions = new WriteOptions().setDisableWAL(true);
+
+    /** Read options for regular reads. */
+    final ReadOptions readOptions = new ReadOptions();
+
+    /** Database path. */
+    private final Path dbPath;
+
+    /** RocksDB flusher instance. */
+    private volatile RocksDbFlusher flusher;
+
+    /** Prevents double stopping the storage. */
+    private final AtomicBoolean stopGuard = new AtomicBoolean();
+
+    /** Busy lock to stop synchronously. */
+    private final IgniteSpinBusyLock busyLock = new IgniteSpinBusyLock();
+
+    private final ScheduledExecutorService scheduledExecutor;
+
+    /** Thread pool to execute after-flush actions. */
+    private final ExecutorService threadPool;
+
+    /** Supplier for the value of delay for scheduled database flush. */
+    private final IntSupplier flushDelaySupplier;
+
+    /**
+     * Constructor.
+     *
+     * @param dbPath Database path.
+     * @param scheduledExecutor Scheduled executor.

Review Comment:
   Can you indicate in a few words what this executor is for?



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbSharedStorage.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.tx.storage.state.rocksdb;
+
+import static java.util.Collections.reverse;
+import static java.util.stream.Collectors.toList;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.IntSupplier;
+import org.apache.ignite.internal.close.ManuallyCloseable;
+import org.apache.ignite.internal.lang.IgniteInternalException;
+import org.apache.ignite.internal.rocksdb.flush.RocksDbFlusher;
+import org.apache.ignite.internal.tx.storage.state.TxStateTableStorage;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.ColumnFamilyOptions;
+import org.rocksdb.DBOptions;
+import org.rocksdb.Options;
+import org.rocksdb.ReadOptions;
+import org.rocksdb.RocksDB;
+import org.rocksdb.WriteOptions;
+
+/**
+ * RocksDb implementation of {@link TxStateTableStorage}.
+ */
+public class TxStateRocksDbSharedStorage implements ManuallyCloseable {
+    static {
+        RocksDB.loadLibrary();
+    }
+
+    /** Column family name for transaction states. */
+    private static final String TX_STATE_CF = new String(RocksDB.DEFAULT_COLUMN_FAMILY, StandardCharsets.UTF_8);
+
+    /** Rocks DB instance. */
+    private volatile RocksDB db;
+
+    /** RocksDb database options. */
+    private volatile DBOptions dbOptions;
+
+    /** Write options. */
+    final WriteOptions writeOptions = new WriteOptions().setDisableWAL(true);
+
+    /** Read options for regular reads. */
+    final ReadOptions readOptions = new ReadOptions();
+
+    /** Database path. */
+    private final Path dbPath;
+
+    /** RocksDB flusher instance. */
+    private volatile RocksDbFlusher flusher;
+
+    /** Prevents double stopping the storage. */
+    private final AtomicBoolean stopGuard = new AtomicBoolean();
+
+    /** Busy lock to stop synchronously. */
+    private final IgniteSpinBusyLock busyLock = new IgniteSpinBusyLock();
+
+    private final ScheduledExecutorService scheduledExecutor;

Review Comment:
   Please add comments to this field by analogy with others.



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbSharedStorage.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.tx.storage.state.rocksdb;
+
+import static java.util.Collections.reverse;
+import static java.util.stream.Collectors.toList;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.IntSupplier;
+import org.apache.ignite.internal.close.ManuallyCloseable;
+import org.apache.ignite.internal.lang.IgniteInternalException;
+import org.apache.ignite.internal.rocksdb.flush.RocksDbFlusher;
+import org.apache.ignite.internal.tx.storage.state.TxStateTableStorage;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.ColumnFamilyOptions;
+import org.rocksdb.DBOptions;
+import org.rocksdb.Options;
+import org.rocksdb.ReadOptions;
+import org.rocksdb.RocksDB;
+import org.rocksdb.WriteOptions;
+
+/**
+ * RocksDb implementation of {@link TxStateTableStorage}.
+ */
+public class TxStateRocksDbSharedStorage implements ManuallyCloseable {
+    static {
+        RocksDB.loadLibrary();
+    }
+
+    /** Column family name for transaction states. */
+    private static final String TX_STATE_CF = new String(RocksDB.DEFAULT_COLUMN_FAMILY, StandardCharsets.UTF_8);
+
+    /** Rocks DB instance. */
+    private volatile RocksDB db;
+
+    /** RocksDb database options. */
+    private volatile DBOptions dbOptions;
+
+    /** Write options. */
+    final WriteOptions writeOptions = new WriteOptions().setDisableWAL(true);
+
+    /** Read options for regular reads. */
+    final ReadOptions readOptions = new ReadOptions();
+
+    /** Database path. */
+    private final Path dbPath;
+
+    /** RocksDB flusher instance. */
+    private volatile RocksDbFlusher flusher;
+
+    /** Prevents double stopping the storage. */
+    private final AtomicBoolean stopGuard = new AtomicBoolean();
+
+    /** Busy lock to stop synchronously. */
+    private final IgniteSpinBusyLock busyLock = new IgniteSpinBusyLock();
+
+    private final ScheduledExecutorService scheduledExecutor;
+
+    /** Thread pool to execute after-flush actions. */
+    private final ExecutorService threadPool;
+
+    /** Supplier for the value of delay for scheduled database flush. */
+    private final IntSupplier flushDelaySupplier;
+
+    /**
+     * Constructor.
+     *
+     * @param dbPath Database path.
+     * @param scheduledExecutor Scheduled executor.
+     */
+    public TxStateRocksDbSharedStorage(

Review Comment:
   Not all parameters are listed in the documentation.
   And also what error there might be and why it might occur.



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbSharedStorage.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.tx.storage.state.rocksdb;
+
+import static java.util.Collections.reverse;
+import static java.util.stream.Collectors.toList;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.IntSupplier;
+import org.apache.ignite.internal.close.ManuallyCloseable;
+import org.apache.ignite.internal.lang.IgniteInternalException;
+import org.apache.ignite.internal.rocksdb.flush.RocksDbFlusher;
+import org.apache.ignite.internal.tx.storage.state.TxStateTableStorage;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.ColumnFamilyOptions;
+import org.rocksdb.DBOptions;
+import org.rocksdb.Options;
+import org.rocksdb.ReadOptions;
+import org.rocksdb.RocksDB;
+import org.rocksdb.WriteOptions;
+
+/**
+ * RocksDb implementation of {@link TxStateTableStorage}.
+ */
+public class TxStateRocksDbSharedStorage implements ManuallyCloseable {
+    static {
+        RocksDB.loadLibrary();
+    }
+
+    /** Column family name for transaction states. */
+    private static final String TX_STATE_CF = new String(RocksDB.DEFAULT_COLUMN_FAMILY, StandardCharsets.UTF_8);
+
+    /** Rocks DB instance. */
+    private volatile RocksDB db;
+
+    /** RocksDb database options. */
+    private volatile DBOptions dbOptions;
+
+    /** Write options. */
+    final WriteOptions writeOptions = new WriteOptions().setDisableWAL(true);
+
+    /** Read options for regular reads. */
+    final ReadOptions readOptions = new ReadOptions();
+
+    /** Database path. */
+    private final Path dbPath;
+
+    /** RocksDB flusher instance. */
+    private volatile RocksDbFlusher flusher;
+
+    /** Prevents double stopping the storage. */
+    private final AtomicBoolean stopGuard = new AtomicBoolean();
+
+    /** Busy lock to stop synchronously. */
+    private final IgniteSpinBusyLock busyLock = new IgniteSpinBusyLock();
+
+    private final ScheduledExecutorService scheduledExecutor;
+
+    /** Thread pool to execute after-flush actions. */
+    private final ExecutorService threadPool;
+
+    /** Supplier for the value of delay for scheduled database flush. */
+    private final IntSupplier flushDelaySupplier;
+
+    /**
+     * Constructor.
+     *
+     * @param dbPath Database path.
+     * @param scheduledExecutor Scheduled executor.
+     */
+    public TxStateRocksDbSharedStorage(
+            Path dbPath,
+            ScheduledExecutorService scheduledExecutor,
+            ExecutorService threadPool,
+            IntSupplier flushDelaySupplier
+    ) {
+        this.dbPath = dbPath;
+        this.scheduledExecutor = scheduledExecutor;
+        this.threadPool = threadPool;
+        this.flushDelaySupplier = flushDelaySupplier;
+
+        try {
+            Files.createDirectories(dbPath);
+        } catch (IOException e) {
+            throw new IgniteInternalException("Failed to create transaction state storage directory", e);
+        }
+    }
+
+    /**
+     * Returns shared {@link RocksDB} instance.
+     */
+    RocksDB db() {
+        return db;
+    }
+
+    /**
+     * Returns a future to await flush.
+     */
+    CompletableFuture<Void> awaitFlush(boolean schedule) {
+        return flusher.awaitFlush(schedule);
+    }
+
+    /**
+     * Starts the storage.
+     */
+    public void start() {

Review Comment:
   It would be great if you reported the error to the documentation.



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbSharedStorage.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.tx.storage.state.rocksdb;
+
+import static java.util.Collections.reverse;
+import static java.util.stream.Collectors.toList;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.IntSupplier;
+import org.apache.ignite.internal.close.ManuallyCloseable;
+import org.apache.ignite.internal.lang.IgniteInternalException;
+import org.apache.ignite.internal.rocksdb.flush.RocksDbFlusher;
+import org.apache.ignite.internal.tx.storage.state.TxStateTableStorage;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.ColumnFamilyOptions;
+import org.rocksdb.DBOptions;
+import org.rocksdb.Options;
+import org.rocksdb.ReadOptions;
+import org.rocksdb.RocksDB;
+import org.rocksdb.WriteOptions;
+
+/**
+ * RocksDb implementation of {@link TxStateTableStorage}.
+ */
+public class TxStateRocksDbSharedStorage implements ManuallyCloseable {
+    static {
+        RocksDB.loadLibrary();
+    }
+
+    /** Column family name for transaction states. */
+    private static final String TX_STATE_CF = new String(RocksDB.DEFAULT_COLUMN_FAMILY, StandardCharsets.UTF_8);
+
+    /** Rocks DB instance. */
+    private volatile RocksDB db;
+
+    /** RocksDb database options. */
+    private volatile DBOptions dbOptions;
+
+    /** Write options. */
+    final WriteOptions writeOptions = new WriteOptions().setDisableWAL(true);
+
+    /** Read options for regular reads. */
+    final ReadOptions readOptions = new ReadOptions();
+
+    /** Database path. */
+    private final Path dbPath;
+
+    /** RocksDB flusher instance. */
+    private volatile RocksDbFlusher flusher;
+
+    /** Prevents double stopping the storage. */
+    private final AtomicBoolean stopGuard = new AtomicBoolean();
+
+    /** Busy lock to stop synchronously. */
+    private final IgniteSpinBusyLock busyLock = new IgniteSpinBusyLock();
+
+    private final ScheduledExecutorService scheduledExecutor;
+
+    /** Thread pool to execute after-flush actions. */
+    private final ExecutorService threadPool;
+
+    /** Supplier for the value of delay for scheduled database flush. */
+    private final IntSupplier flushDelaySupplier;
+
+    /**
+     * Constructor.
+     *
+     * @param dbPath Database path.
+     * @param scheduledExecutor Scheduled executor.
+     */
+    public TxStateRocksDbSharedStorage(
+            Path dbPath,
+            ScheduledExecutorService scheduledExecutor,
+            ExecutorService threadPool,
+            IntSupplier flushDelaySupplier
+    ) {
+        this.dbPath = dbPath;
+        this.scheduledExecutor = scheduledExecutor;
+        this.threadPool = threadPool;
+        this.flushDelaySupplier = flushDelaySupplier;
+
+        try {
+            Files.createDirectories(dbPath);
+        } catch (IOException e) {
+            throw new IgniteInternalException("Failed to create transaction state storage directory", e);
+        }
+    }
+
+    /**
+     * Returns shared {@link RocksDB} instance.
+     */
+    RocksDB db() {
+        return db;
+    }
+
+    /**
+     * Returns a future to await flush.
+     */

Review Comment:
   ```suggestion
       /** Returns a future to await flush. */
   ```



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbSharedStorage.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.tx.storage.state.rocksdb;
+
+import static java.util.Collections.reverse;
+import static java.util.stream.Collectors.toList;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.IntSupplier;
+import org.apache.ignite.internal.close.ManuallyCloseable;
+import org.apache.ignite.internal.lang.IgniteInternalException;
+import org.apache.ignite.internal.rocksdb.flush.RocksDbFlusher;
+import org.apache.ignite.internal.tx.storage.state.TxStateTableStorage;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.ColumnFamilyOptions;
+import org.rocksdb.DBOptions;
+import org.rocksdb.Options;
+import org.rocksdb.ReadOptions;
+import org.rocksdb.RocksDB;
+import org.rocksdb.WriteOptions;
+
+/**
+ * RocksDb implementation of {@link TxStateTableStorage}.
+ */
+public class TxStateRocksDbSharedStorage implements ManuallyCloseable {
+    static {
+        RocksDB.loadLibrary();
+    }
+
+    /** Column family name for transaction states. */
+    private static final String TX_STATE_CF = new String(RocksDB.DEFAULT_COLUMN_FAMILY, StandardCharsets.UTF_8);
+
+    /** Rocks DB instance. */
+    private volatile RocksDB db;
+
+    /** RocksDb database options. */
+    private volatile DBOptions dbOptions;
+
+    /** Write options. */
+    final WriteOptions writeOptions = new WriteOptions().setDisableWAL(true);
+
+    /** Read options for regular reads. */
+    final ReadOptions readOptions = new ReadOptions();
+
+    /** Database path. */
+    private final Path dbPath;
+
+    /** RocksDB flusher instance. */
+    private volatile RocksDbFlusher flusher;
+
+    /** Prevents double stopping the storage. */
+    private final AtomicBoolean stopGuard = new AtomicBoolean();
+
+    /** Busy lock to stop synchronously. */
+    private final IgniteSpinBusyLock busyLock = new IgniteSpinBusyLock();
+
+    private final ScheduledExecutorService scheduledExecutor;
+
+    /** Thread pool to execute after-flush actions. */
+    private final ExecutorService threadPool;
+
+    /** Supplier for the value of delay for scheduled database flush. */
+    private final IntSupplier flushDelaySupplier;
+
+    /**
+     * Constructor.
+     *
+     * @param dbPath Database path.
+     * @param scheduledExecutor Scheduled executor.
+     */
+    public TxStateRocksDbSharedStorage(
+            Path dbPath,
+            ScheduledExecutorService scheduledExecutor,
+            ExecutorService threadPool,
+            IntSupplier flushDelaySupplier
+    ) {
+        this.dbPath = dbPath;
+        this.scheduledExecutor = scheduledExecutor;
+        this.threadPool = threadPool;
+        this.flushDelaySupplier = flushDelaySupplier;
+
+        try {
+            Files.createDirectories(dbPath);
+        } catch (IOException e) {
+            throw new IgniteInternalException("Failed to create transaction state storage directory", e);
+        }
+    }
+
+    /**
+     * Returns shared {@link RocksDB} instance.
+     */

Review Comment:
   ```suggestion
       /** Returns shared {@link RocksDB} instance. */
   ```



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbSharedStorage.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.tx.storage.state.rocksdb;
+
+import static java.util.Collections.reverse;
+import static java.util.stream.Collectors.toList;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.IntSupplier;
+import org.apache.ignite.internal.close.ManuallyCloseable;
+import org.apache.ignite.internal.lang.IgniteInternalException;
+import org.apache.ignite.internal.rocksdb.flush.RocksDbFlusher;
+import org.apache.ignite.internal.tx.storage.state.TxStateTableStorage;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.ColumnFamilyOptions;
+import org.rocksdb.DBOptions;
+import org.rocksdb.Options;
+import org.rocksdb.ReadOptions;
+import org.rocksdb.RocksDB;
+import org.rocksdb.WriteOptions;
+
+/**
+ * RocksDb implementation of {@link TxStateTableStorage}.
+ */
+public class TxStateRocksDbSharedStorage implements ManuallyCloseable {
+    static {
+        RocksDB.loadLibrary();
+    }
+
+    /** Column family name for transaction states. */
+    private static final String TX_STATE_CF = new String(RocksDB.DEFAULT_COLUMN_FAMILY, StandardCharsets.UTF_8);
+
+    /** Rocks DB instance. */
+    private volatile RocksDB db;
+
+    /** RocksDb database options. */
+    private volatile DBOptions dbOptions;
+
+    /** Write options. */
+    final WriteOptions writeOptions = new WriteOptions().setDisableWAL(true);
+
+    /** Read options for regular reads. */
+    final ReadOptions readOptions = new ReadOptions();
+
+    /** Database path. */
+    private final Path dbPath;
+
+    /** RocksDB flusher instance. */
+    private volatile RocksDbFlusher flusher;
+
+    /** Prevents double stopping the storage. */
+    private final AtomicBoolean stopGuard = new AtomicBoolean();
+
+    /** Busy lock to stop synchronously. */
+    private final IgniteSpinBusyLock busyLock = new IgniteSpinBusyLock();
+
+    private final ScheduledExecutorService scheduledExecutor;
+
+    /** Thread pool to execute after-flush actions. */
+    private final ExecutorService threadPool;
+
+    /** Supplier for the value of delay for scheduled database flush. */
+    private final IntSupplier flushDelaySupplier;
+
+    /**
+     * Constructor.
+     *
+     * @param dbPath Database path.
+     * @param scheduledExecutor Scheduled executor.
+     */
+    public TxStateRocksDbSharedStorage(
+            Path dbPath,
+            ScheduledExecutorService scheduledExecutor,
+            ExecutorService threadPool,
+            IntSupplier flushDelaySupplier
+    ) {
+        this.dbPath = dbPath;
+        this.scheduledExecutor = scheduledExecutor;
+        this.threadPool = threadPool;
+        this.flushDelaySupplier = flushDelaySupplier;
+
+        try {
+            Files.createDirectories(dbPath);
+        } catch (IOException e) {
+            throw new IgniteInternalException("Failed to create transaction state storage directory", e);
+        }
+    }
+
+    /**
+     * Returns shared {@link RocksDB} instance.
+     */
+    RocksDB db() {
+        return db;
+    }
+
+    /**
+     * Returns a future to await flush.
+     */
+    CompletableFuture<Void> awaitFlush(boolean schedule) {
+        return flusher.awaitFlush(schedule);
+    }
+
+    /**
+     * Starts the storage.
+     */

Review Comment:
   ```suggestion
       /** Starts the storage. */
   ```



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbSharedStorage.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.tx.storage.state.rocksdb;
+
+import static java.util.Collections.reverse;
+import static java.util.stream.Collectors.toList;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.IntSupplier;
+import org.apache.ignite.internal.close.ManuallyCloseable;
+import org.apache.ignite.internal.lang.IgniteInternalException;
+import org.apache.ignite.internal.rocksdb.flush.RocksDbFlusher;
+import org.apache.ignite.internal.tx.storage.state.TxStateTableStorage;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.ColumnFamilyOptions;
+import org.rocksdb.DBOptions;
+import org.rocksdb.Options;
+import org.rocksdb.ReadOptions;
+import org.rocksdb.RocksDB;
+import org.rocksdb.WriteOptions;
+
+/**
+ * RocksDb implementation of {@link TxStateTableStorage}.
+ */
+public class TxStateRocksDbSharedStorage implements ManuallyCloseable {
+    static {
+        RocksDB.loadLibrary();
+    }
+
+    /** Column family name for transaction states. */
+    private static final String TX_STATE_CF = new String(RocksDB.DEFAULT_COLUMN_FAMILY, StandardCharsets.UTF_8);
+
+    /** Rocks DB instance. */
+    private volatile RocksDB db;
+
+    /** RocksDb database options. */
+    private volatile DBOptions dbOptions;
+
+    /** Write options. */
+    final WriteOptions writeOptions = new WriteOptions().setDisableWAL(true);
+
+    /** Read options for regular reads. */
+    final ReadOptions readOptions = new ReadOptions();
+
+    /** Database path. */
+    private final Path dbPath;
+
+    /** RocksDB flusher instance. */
+    private volatile RocksDbFlusher flusher;
+
+    /** Prevents double stopping the storage. */
+    private final AtomicBoolean stopGuard = new AtomicBoolean();
+
+    /** Busy lock to stop synchronously. */
+    private final IgniteSpinBusyLock busyLock = new IgniteSpinBusyLock();
+
+    private final ScheduledExecutorService scheduledExecutor;
+
+    /** Thread pool to execute after-flush actions. */
+    private final ExecutorService threadPool;
+
+    /** Supplier for the value of delay for scheduled database flush. */
+    private final IntSupplier flushDelaySupplier;
+
+    /**
+     * Constructor.
+     *
+     * @param dbPath Database path.
+     * @param scheduledExecutor Scheduled executor.
+     */
+    public TxStateRocksDbSharedStorage(
+            Path dbPath,
+            ScheduledExecutorService scheduledExecutor,
+            ExecutorService threadPool,
+            IntSupplier flushDelaySupplier
+    ) {
+        this.dbPath = dbPath;
+        this.scheduledExecutor = scheduledExecutor;
+        this.threadPool = threadPool;
+        this.flushDelaySupplier = flushDelaySupplier;
+
+        try {
+            Files.createDirectories(dbPath);
+        } catch (IOException e) {
+            throw new IgniteInternalException("Failed to create transaction state storage directory", e);
+        }
+    }
+
+    /**
+     * Returns shared {@link RocksDB} instance.
+     */
+    RocksDB db() {
+        return db;
+    }
+
+    /**
+     * Returns a future to await flush.
+     */
+    CompletableFuture<Void> awaitFlush(boolean schedule) {
+        return flusher.awaitFlush(schedule);
+    }
+
+    /**
+     * Starts the storage.
+     */
+    public void start() {
+        try {
+            flusher = new RocksDbFlusher(
+                    busyLock,
+                    scheduledExecutor,
+                    threadPool,
+                    flushDelaySupplier,
+                    () -> {} // No-op.
+            );
+
+            this.dbOptions = new DBOptions()
+                    .setCreateIfMissing(true)
+                    .setAtomicFlush(true)
+                    .setListeners(List.of(flusher.listener()));
+
+            List<ColumnFamilyDescriptor> cfDescriptors;
+
+            try (Options opts = new Options()) {
+                cfDescriptors = RocksDB.listColumnFamilies(opts, dbPath.toAbsolutePath().toString())
+                        .stream()
+                        .map(nameBytes -> new ColumnFamilyDescriptor(nameBytes, new ColumnFamilyOptions()))
+                        .collect(toList());
+
+                cfDescriptors = cfDescriptors.isEmpty()
+                        ? List.of(new ColumnFamilyDescriptor(TX_STATE_CF.getBytes(StandardCharsets.UTF_8), new ColumnFamilyOptions()))
+                        : cfDescriptors;
+            }
+
+            List<ColumnFamilyHandle> cfHandles = new ArrayList<>(cfDescriptors.size());
+
+            this.db = RocksDB.open(dbOptions, dbPath.toString(), cfDescriptors, cfHandles);
+
+            flusher.init(db, cfHandles);
+        } catch (Exception e) {
+            throw new IgniteInternalException("Could not create transaction state storage", e);
+        }
+    }
+
+    @Override
+    public void close() {
+        if (!stopGuard.compareAndSet(false, true)) {
+            return;
+        }
+
+        busyLock.block();
+
+        try {
+            List<AutoCloseable> resources = new ArrayList<>();
+
+            resources.add(readOptions);
+            resources.add(writeOptions);
+            resources.add(dbOptions);
+            resources.add(db);
+
+            reverse(resources);
+            IgniteUtils.closeAll(resources);
+        } catch (Exception e) {
+            throw new IgniteInternalException("Failed to stop transaction state storage", e);

Review Comment:
   Suggestion: Maybe just leave the `Exception` in the signature and remove this code?



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -246,10 +232,16 @@ public Cursor<IgniteBiTuple<UUID, TxMeta>> scan() {
         return busy(() -> {
             throwExceptionIfStorageInProgressOfRebalance();
 
-            byte[] lowerBound = ByteBuffer.allocate(Short.BYTES + 1).putShort((short) partitionId).put((byte) 0).array();
+            byte[] lowerBound = ByteBuffer.allocate(PREFIX_SIZE_BYTES + 1).order(ByteOrder.BIG_ENDIAN)

Review Comment:
   I suggest putting the size into a constant with a description.



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbSharedStorage.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.tx.storage.state.rocksdb;
+
+import static java.util.Collections.reverse;
+import static java.util.stream.Collectors.toList;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.IntSupplier;
+import org.apache.ignite.internal.close.ManuallyCloseable;
+import org.apache.ignite.internal.lang.IgniteInternalException;
+import org.apache.ignite.internal.rocksdb.flush.RocksDbFlusher;
+import org.apache.ignite.internal.tx.storage.state.TxStateTableStorage;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.ColumnFamilyOptions;
+import org.rocksdb.DBOptions;
+import org.rocksdb.Options;
+import org.rocksdb.ReadOptions;
+import org.rocksdb.RocksDB;
+import org.rocksdb.WriteOptions;
+
+/**
+ * RocksDb implementation of {@link TxStateTableStorage}.
+ */
+public class TxStateRocksDbSharedStorage implements ManuallyCloseable {
+    static {
+        RocksDB.loadLibrary();
+    }
+
+    /** Column family name for transaction states. */
+    private static final String TX_STATE_CF = new String(RocksDB.DEFAULT_COLUMN_FAMILY, StandardCharsets.UTF_8);
+
+    /** Rocks DB instance. */
+    private volatile RocksDB db;
+
+    /** RocksDb database options. */
+    private volatile DBOptions dbOptions;
+
+    /** Write options. */
+    final WriteOptions writeOptions = new WriteOptions().setDisableWAL(true);
+
+    /** Read options for regular reads. */
+    final ReadOptions readOptions = new ReadOptions();
+
+    /** Database path. */
+    private final Path dbPath;
+
+    /** RocksDB flusher instance. */
+    private volatile RocksDbFlusher flusher;
+
+    /** Prevents double stopping the storage. */
+    private final AtomicBoolean stopGuard = new AtomicBoolean();
+
+    /** Busy lock to stop synchronously. */
+    private final IgniteSpinBusyLock busyLock = new IgniteSpinBusyLock();
+
+    private final ScheduledExecutorService scheduledExecutor;
+
+    /** Thread pool to execute after-flush actions. */
+    private final ExecutorService threadPool;
+
+    /** Supplier for the value of delay for scheduled database flush. */
+    private final IntSupplier flushDelaySupplier;
+
+    /**
+     * Constructor.
+     *
+     * @param dbPath Database path.
+     * @param scheduledExecutor Scheduled executor.
+     */
+    public TxStateRocksDbSharedStorage(
+            Path dbPath,
+            ScheduledExecutorService scheduledExecutor,
+            ExecutorService threadPool,
+            IntSupplier flushDelaySupplier
+    ) {
+        this.dbPath = dbPath;
+        this.scheduledExecutor = scheduledExecutor;
+        this.threadPool = threadPool;
+        this.flushDelaySupplier = flushDelaySupplier;
+
+        try {
+            Files.createDirectories(dbPath);
+        } catch (IOException e) {
+            throw new IgniteInternalException("Failed to create transaction state storage directory", e);
+        }
+    }
+
+    /**
+     * Returns shared {@link RocksDB} instance.
+     */
+    RocksDB db() {
+        return db;
+    }
+
+    /**
+     * Returns a future to await flush.
+     */
+    CompletableFuture<Void> awaitFlush(boolean schedule) {
+        return flusher.awaitFlush(schedule);
+    }
+
+    /**
+     * Starts the storage.
+     */
+    public void start() {
+        try {
+            flusher = new RocksDbFlusher(
+                    busyLock,
+                    scheduledExecutor,
+                    threadPool,
+                    flushDelaySupplier,
+                    () -> {} // No-op.
+            );
+
+            this.dbOptions = new DBOptions()
+                    .setCreateIfMissing(true)
+                    .setAtomicFlush(true)
+                    .setListeners(List.of(flusher.listener()));
+
+            List<ColumnFamilyDescriptor> cfDescriptors;
+
+            try (Options opts = new Options()) {
+                cfDescriptors = RocksDB.listColumnFamilies(opts, dbPath.toAbsolutePath().toString())
+                        .stream()
+                        .map(nameBytes -> new ColumnFamilyDescriptor(nameBytes, new ColumnFamilyOptions()))
+                        .collect(toList());
+
+                cfDescriptors = cfDescriptors.isEmpty()
+                        ? List.of(new ColumnFamilyDescriptor(TX_STATE_CF.getBytes(StandardCharsets.UTF_8), new ColumnFamilyOptions()))
+                        : cfDescriptors;
+            }
+
+            List<ColumnFamilyHandle> cfHandles = new ArrayList<>(cfDescriptors.size());
+
+            this.db = RocksDB.open(dbOptions, dbPath.toString(), cfDescriptors, cfHandles);
+
+            flusher.init(db, cfHandles);
+        } catch (Exception e) {
+            throw new IgniteInternalException("Could not create transaction state storage", e);
+        }
+    }
+
+    @Override
+    public void close() {
+        if (!stopGuard.compareAndSet(false, true)) {
+            return;
+        }
+
+        busyLock.block();
+
+        try {
+            List<AutoCloseable> resources = new ArrayList<>();
+
+            resources.add(readOptions);
+            resources.add(writeOptions);
+            resources.add(dbOptions);
+            resources.add(db);
+
+            reverse(resources);
+            IgniteUtils.closeAll(resources);

Review Comment:
   ```suggestion
               reverse(resources);
               
               IgniteUtils.closeAll(resources);
   ```



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -81,6 +71,8 @@ public class TxStateRocksDbStorage implements TxStateStorage {
 
     /** Database key for the last applied index+term. */
     private final byte[] lastAppliedIndexAndTermKey;
+    private final TxStateRocksDbSharedStorage sharedStorage;
+    private final int tableId;

Review Comment:
   ```suggestion
       private final TxStateRocksDbSharedStorage sharedStorage;
       
       private final int tableId;
   ```



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbSharedStorage.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.tx.storage.state.rocksdb;
+
+import static java.util.Collections.reverse;
+import static java.util.stream.Collectors.toList;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.IntSupplier;
+import org.apache.ignite.internal.close.ManuallyCloseable;
+import org.apache.ignite.internal.lang.IgniteInternalException;
+import org.apache.ignite.internal.rocksdb.flush.RocksDbFlusher;
+import org.apache.ignite.internal.tx.storage.state.TxStateTableStorage;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.ColumnFamilyOptions;
+import org.rocksdb.DBOptions;
+import org.rocksdb.Options;
+import org.rocksdb.ReadOptions;
+import org.rocksdb.RocksDB;
+import org.rocksdb.WriteOptions;
+
+/**
+ * RocksDb implementation of {@link TxStateTableStorage}.
+ */
+public class TxStateRocksDbSharedStorage implements ManuallyCloseable {
+    static {
+        RocksDB.loadLibrary();
+    }
+
+    /** Column family name for transaction states. */
+    private static final String TX_STATE_CF = new String(RocksDB.DEFAULT_COLUMN_FAMILY, StandardCharsets.UTF_8);
+
+    /** Rocks DB instance. */
+    private volatile RocksDB db;
+
+    /** RocksDb database options. */
+    private volatile DBOptions dbOptions;
+
+    /** Write options. */
+    final WriteOptions writeOptions = new WriteOptions().setDisableWAL(true);
+
+    /** Read options for regular reads. */
+    final ReadOptions readOptions = new ReadOptions();
+
+    /** Database path. */
+    private final Path dbPath;
+
+    /** RocksDB flusher instance. */
+    private volatile RocksDbFlusher flusher;
+
+    /** Prevents double stopping the storage. */
+    private final AtomicBoolean stopGuard = new AtomicBoolean();
+
+    /** Busy lock to stop synchronously. */
+    private final IgniteSpinBusyLock busyLock = new IgniteSpinBusyLock();
+
+    private final ScheduledExecutorService scheduledExecutor;
+
+    /** Thread pool to execute after-flush actions. */
+    private final ExecutorService threadPool;
+
+    /** Supplier for the value of delay for scheduled database flush. */
+    private final IntSupplier flushDelaySupplier;
+
+    /**
+     * Constructor.
+     *
+     * @param dbPath Database path.
+     * @param scheduledExecutor Scheduled executor.
+     */
+    public TxStateRocksDbSharedStorage(
+            Path dbPath,
+            ScheduledExecutorService scheduledExecutor,
+            ExecutorService threadPool,
+            IntSupplier flushDelaySupplier
+    ) {
+        this.dbPath = dbPath;
+        this.scheduledExecutor = scheduledExecutor;
+        this.threadPool = threadPool;
+        this.flushDelaySupplier = flushDelaySupplier;
+
+        try {
+            Files.createDirectories(dbPath);
+        } catch (IOException e) {
+            throw new IgniteInternalException("Failed to create transaction state storage directory", e);
+        }
+    }
+
+    /**
+     * Returns shared {@link RocksDB} instance.
+     */
+    RocksDB db() {
+        return db;
+    }
+
+    /**
+     * Returns a future to await flush.
+     */
+    CompletableFuture<Void> awaitFlush(boolean schedule) {
+        return flusher.awaitFlush(schedule);
+    }
+
+    /**
+     * Starts the storage.
+     */
+    public void start() {
+        try {
+            flusher = new RocksDbFlusher(
+                    busyLock,
+                    scheduledExecutor,
+                    threadPool,
+                    flushDelaySupplier,
+                    () -> {} // No-op.
+            );
+
+            this.dbOptions = new DBOptions()
+                    .setCreateIfMissing(true)
+                    .setAtomicFlush(true)
+                    .setListeners(List.of(flusher.listener()));
+
+            List<ColumnFamilyDescriptor> cfDescriptors;
+
+            try (Options opts = new Options()) {
+                cfDescriptors = RocksDB.listColumnFamilies(opts, dbPath.toAbsolutePath().toString())
+                        .stream()
+                        .map(nameBytes -> new ColumnFamilyDescriptor(nameBytes, new ColumnFamilyOptions()))
+                        .collect(toList());
+
+                cfDescriptors = cfDescriptors.isEmpty()
+                        ? List.of(new ColumnFamilyDescriptor(TX_STATE_CF.getBytes(StandardCharsets.UTF_8), new ColumnFamilyOptions()))

Review Comment:
   Maybe use static import for StandardCharsets.UTF_8 ?



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbTableStorage.java:
##########
@@ -248,12 +152,13 @@ public void stop() {
 
     @Override
     public void destroy() {
-        try (Options options = new Options()) {
-            close();
+        byte[] start = ByteBuffer.allocate(Integer.BYTES).order(ByteOrder.BIG_ENDIAN).putInt(id).array();

Review Comment:
   I suggest putting the size into a constant with a description.



##########
modules/transactions/src/test/java/org/apache/ignite/internal/tx/storage/state/rocksdb/RocksDbTxStateStorageTest.java:
##########
@@ -56,18 +59,25 @@ protected TxStateRocksDbTableStorage createTableStorage() {
         return new TxStateRocksDbTableStorage(
                 TABLE_ID,
                 3,
-                workDir,
-                scheduledExecutor,
-                executor,
-                () -> 1_000
+                sharedStorage
         );
     }
 
+    @Override
+    @BeforeEach
+    protected void beforeTest() {
+        sharedStorage = new TxStateRocksDbSharedStorage(workDir, scheduledExecutor, executor, () -> 0);
+        sharedStorage.start();
+
+        super.beforeTest();
+    }
+
     @Override
     @AfterEach
     protected void afterTest() {
         super.afterTest();
 
+        sharedStorage.close();
         IgniteUtils.shutdownAndAwaitTermination(scheduledExecutor, 10, TimeUnit.SECONDS);
         IgniteUtils.shutdownAndAwaitTermination(executor, 10, TimeUnit.SECONDS);

Review Comment:
   I would make all calls in this method in IgniteUtils#closeAll, if desired.



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -398,28 +391,31 @@ public void destroy() {
     }
 
     private byte[] partitionStartPrefix() {
-        return ByteBuffer.allocate(Short.BYTES).order(ByteOrder.BIG_ENDIAN)
-            .putShort((short) (partitionId))
-            .array();
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES).order(ByteOrder.BIG_ENDIAN)

Review Comment:
   Maybe byte order to constant or static import?



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -398,28 +391,31 @@ public void destroy() {
     }
 
     private byte[] partitionStartPrefix() {
-        return ByteBuffer.allocate(Short.BYTES).order(ByteOrder.BIG_ENDIAN)
-            .putShort((short) (partitionId))
-            .array();
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES).order(ByteOrder.BIG_ENDIAN)
+                .putInt(tableId)
+                .putShort((short) (partitionId))
+                .array();
     }
 
     private byte[] partitionEndPrefix() {
-        return ByteBuffer.allocate(Short.BYTES).order(ByteOrder.BIG_ENDIAN)
-            .putShort((short) (partitionId + 1))
-            .array();
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES).order(ByteOrder.BIG_ENDIAN)
+                .putInt(tableId)
+                .putShort((short) (partitionId + 1))
+                .array();
     }
 
     private byte[] txIdToKey(UUID txId) {
-        return ByteBuffer.allocate(Short.BYTES + 2 * Long.BYTES).order(ByteOrder.BIG_ENDIAN)
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES + 2 * Long.BYTES).order(ByteOrder.BIG_ENDIAN)

Review Comment:
   I suggest putting the size into a constant with a description.



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -47,26 +47,16 @@
 import org.apache.ignite.internal.util.IgniteSpinBusyLock;
 import org.jetbrains.annotations.Nullable;
 import org.rocksdb.ReadOptions;
-import org.rocksdb.RocksDB;
 import org.rocksdb.RocksDBException;
 import org.rocksdb.RocksIterator;
 import org.rocksdb.Slice;
 import org.rocksdb.WriteBatch;
-import org.rocksdb.WriteOptions;
 
 /**
  * Tx state storage implementation based on RocksDB.
  */
 public class TxStateRocksDbStorage implements TxStateStorage {
-    /** RocksDB database. */
-    private final RocksDB db;
-
-    /** Write options. */
-    private final WriteOptions writeOptions;
-
-    /** Read options for regular reads. */
-    private final ReadOptions readOptions;
-
+    private static final int PREFIX_SIZE_BYTES = Integer.BYTES + Short.BYTES;

Review Comment:
   Can you indicate what will be stored in the prefix? for example, table and partition ID.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21204 Implement shared rocksdb storage for transaction states [ignite-3]

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #3012:
URL: https://github.com/apache/ignite-3/pull/3012#discussion_r1444275073


##########
modules/transactions/src/test/java/org/apache/ignite/internal/tx/storage/state/rocksdb/RocksDbTxStateStorageTest.java:
##########
@@ -56,18 +59,25 @@ protected TxStateRocksDbTableStorage createTableStorage() {
         return new TxStateRocksDbTableStorage(
                 TABLE_ID,
                 3,
-                workDir,
-                scheduledExecutor,
-                executor,
-                () -> 1_000
+                sharedStorage
         );
     }
 
+    @Override
+    @BeforeEach
+    protected void beforeTest() {
+        sharedStorage = new TxStateRocksDbSharedStorage(workDir, scheduledExecutor, executor, () -> 0);
+        sharedStorage.start();
+
+        super.beforeTest();
+    }
+
     @Override
     @AfterEach
     protected void afterTest() {
         super.afterTest();
 
+        sharedStorage.close();
         IgniteUtils.shutdownAndAwaitTermination(scheduledExecutor, 10, TimeUnit.SECONDS);
         IgniteUtils.shutdownAndAwaitTermination(executor, 10, TimeUnit.SECONDS);

Review Comment:
   ok



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21204 Implement shared rocksdb storage for transaction states [ignite-3]

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #3012:
URL: https://github.com/apache/ignite-3/pull/3012#discussion_r1444273689


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -398,28 +391,31 @@ public void destroy() {
     }
 
     private byte[] partitionStartPrefix() {
-        return ByteBuffer.allocate(Short.BYTES).order(ByteOrder.BIG_ENDIAN)
-            .putShort((short) (partitionId))
-            .array();
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES).order(ByteOrder.BIG_ENDIAN)

Review Comment:
   I'll do a static import



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21204 Implement shared rocksdb storage for transaction states [ignite-3]

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #3012:
URL: https://github.com/apache/ignite-3/pull/3012#discussion_r1444270789


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -246,10 +232,16 @@ public Cursor<IgniteBiTuple<UUID, TxMeta>> scan() {
         return busy(() -> {
             throwExceptionIfStorageInProgressOfRebalance();
 
-            byte[] lowerBound = ByteBuffer.allocate(Short.BYTES + 1).putShort((short) partitionId).put((byte) 0).array();
+            byte[] lowerBound = ByteBuffer.allocate(PREFIX_SIZE_BYTES + 1).order(ByteOrder.BIG_ENDIAN)

Review Comment:
   I don't see how it would help, small comment right here would be better



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21204 Implement shared rocksdb storage for transaction states [ignite-3]

Posted by "tkalkirill (via GitHub)" <gi...@apache.org>.
tkalkirill commented on code in PR #3012:
URL: https://github.com/apache/ignite-3/pull/3012#discussion_r1444291759


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -398,28 +391,31 @@ public void destroy() {
     }
 
     private byte[] partitionStartPrefix() {
-        return ByteBuffer.allocate(Short.BYTES).order(ByteOrder.BIG_ENDIAN)
-            .putShort((short) (partitionId))
-            .array();
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES).order(ByteOrder.BIG_ENDIAN)
+                .putInt(tableId)
+                .putShort((short) (partitionId))
+                .array();
     }
 
     private byte[] partitionEndPrefix() {
-        return ByteBuffer.allocate(Short.BYTES).order(ByteOrder.BIG_ENDIAN)
-            .putShort((short) (partitionId + 1))
-            .array();
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES).order(ByteOrder.BIG_ENDIAN)
+                .putInt(tableId)
+                .putShort((short) (partitionId + 1))
+                .array();
     }
 
     private byte[] txIdToKey(UUID txId) {
-        return ByteBuffer.allocate(Short.BYTES + 2 * Long.BYTES).order(ByteOrder.BIG_ENDIAN)
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES + 2 * Long.BYTES).order(ByteOrder.BIG_ENDIAN)

Review Comment:
   I would be grateful (and a little persistent) if you still put the size into a separate constant with a description, it increases the readability and obviousness of the code. At your discretion of course.



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -391,21 +399,21 @@ public void destroy() {
     }
 
     private byte[] partitionStartPrefix() {
-        return ByteBuffer.allocate(PREFIX_SIZE_BYTES).order(ByteOrder.BIG_ENDIAN)
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES).order(BIG_ENDIAN)
                 .putInt(tableId)
                 .putShort((short) (partitionId))
                 .array();
     }
 
     private byte[] partitionEndPrefix() {
-        return ByteBuffer.allocate(PREFIX_SIZE_BYTES).order(ByteOrder.BIG_ENDIAN)
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES).order(BIG_ENDIAN)
                 .putInt(tableId)
                 .putShort((short) (partitionId + 1))
                 .array();
     }
 
     private byte[] txIdToKey(UUID txId) {
-        return ByteBuffer.allocate(PREFIX_SIZE_BYTES + 2 * Long.BYTES).order(ByteOrder.BIG_ENDIAN)
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES + 2 * Long.BYTES).order(BIG_ENDIAN)

Review Comment:
   I would be grateful (and a little persistent) if you still put the size into a separate constant with a description, it increases the readability and obviousness of the code. At your discretion of course.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21204 Implement shared rocksdb storage for transaction states [ignite-3]

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #3012:
URL: https://github.com/apache/ignite-3/pull/3012#discussion_r1444275073


##########
modules/transactions/src/test/java/org/apache/ignite/internal/tx/storage/state/rocksdb/RocksDbTxStateStorageTest.java:
##########
@@ -56,18 +59,25 @@ protected TxStateRocksDbTableStorage createTableStorage() {
         return new TxStateRocksDbTableStorage(
                 TABLE_ID,
                 3,
-                workDir,
-                scheduledExecutor,
-                executor,
-                () -> 1_000
+                sharedStorage
         );
     }
 
+    @Override
+    @BeforeEach
+    protected void beforeTest() {
+        sharedStorage = new TxStateRocksDbSharedStorage(workDir, scheduledExecutor, executor, () -> 0);
+        sharedStorage.start();
+
+        super.beforeTest();
+    }
+
     @Override
     @AfterEach
     protected void afterTest() {
         super.afterTest();
 
+        sharedStorage.close();
         IgniteUtils.shutdownAndAwaitTermination(scheduledExecutor, 10, TimeUnit.SECONDS);
         IgniteUtils.shutdownAndAwaitTermination(executor, 10, TimeUnit.SECONDS);

Review Comment:
   ok, but I'd have to add exception to the signature



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21204 Implement shared rocksdb storage for transaction states [ignite-3]

Posted by "tkalkirill (via GitHub)" <gi...@apache.org>.
tkalkirill commented on code in PR #3012:
URL: https://github.com/apache/ignite-3/pull/3012#discussion_r1444287231


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -391,21 +399,21 @@ public void destroy() {
     }
 
     private byte[] partitionStartPrefix() {
-        return ByteBuffer.allocate(PREFIX_SIZE_BYTES).order(ByteOrder.BIG_ENDIAN)
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES).order(BIG_ENDIAN)
                 .putInt(tableId)
                 .putShort((short) (partitionId))
                 .array();
     }
 
     private byte[] partitionEndPrefix() {
-        return ByteBuffer.allocate(PREFIX_SIZE_BYTES).order(ByteOrder.BIG_ENDIAN)
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES).order(BIG_ENDIAN)
                 .putInt(tableId)
                 .putShort((short) (partitionId + 1))
                 .array();
     }
 
     private byte[] txIdToKey(UUID txId) {
-        return ByteBuffer.allocate(PREFIX_SIZE_BYTES + 2 * Long.BYTES).order(ByteOrder.BIG_ENDIAN)
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES + 2 * Long.BYTES).order(BIG_ENDIAN)

Review Comment:
   I would be grateful (and a little persistent) if you still put the size into a separate constant with a description, it increases the readability and obviousness of the code. At your discretion of course.



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbSharedStorage.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.tx.storage.state.rocksdb;
+
+import static java.util.Collections.reverse;
+import static java.util.stream.Collectors.toList;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.IntSupplier;
+import org.apache.ignite.internal.close.ManuallyCloseable;
+import org.apache.ignite.internal.lang.IgniteInternalException;
+import org.apache.ignite.internal.rocksdb.flush.RocksDbFlusher;
+import org.apache.ignite.internal.tx.storage.state.TxStateTableStorage;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.ColumnFamilyOptions;
+import org.rocksdb.DBOptions;
+import org.rocksdb.Options;
+import org.rocksdb.ReadOptions;
+import org.rocksdb.RocksDB;
+import org.rocksdb.WriteOptions;
+
+/**
+ * RocksDb implementation of {@link TxStateTableStorage}.
+ */
+public class TxStateRocksDbSharedStorage implements ManuallyCloseable {
+    static {
+        RocksDB.loadLibrary();
+    }
+
+    /** Column family name for transaction states. */
+    private static final String TX_STATE_CF = new String(RocksDB.DEFAULT_COLUMN_FAMILY, StandardCharsets.UTF_8);
+
+    /** Rocks DB instance. */
+    private volatile RocksDB db;
+
+    /** RocksDb database options. */
+    private volatile DBOptions dbOptions;
+
+    /** Write options. */
+    final WriteOptions writeOptions = new WriteOptions().setDisableWAL(true);
+
+    /** Read options for regular reads. */
+    final ReadOptions readOptions = new ReadOptions();
+
+    /** Database path. */
+    private final Path dbPath;
+
+    /** RocksDB flusher instance. */
+    private volatile RocksDbFlusher flusher;
+
+    /** Prevents double stopping the storage. */
+    private final AtomicBoolean stopGuard = new AtomicBoolean();
+
+    /** Busy lock to stop synchronously. */
+    private final IgniteSpinBusyLock busyLock = new IgniteSpinBusyLock();
+
+    private final ScheduledExecutorService scheduledExecutor;
+
+    /** Thread pool to execute after-flush actions. */
+    private final ExecutorService threadPool;
+
+    /** Supplier for the value of delay for scheduled database flush. */
+    private final IntSupplier flushDelaySupplier;
+
+    /**
+     * Constructor.
+     *
+     * @param dbPath Database path.
+     * @param scheduledExecutor Scheduled executor.
+     */
+    public TxStateRocksDbSharedStorage(
+            Path dbPath,
+            ScheduledExecutorService scheduledExecutor,
+            ExecutorService threadPool,
+            IntSupplier flushDelaySupplier
+    ) {
+        this.dbPath = dbPath;
+        this.scheduledExecutor = scheduledExecutor;
+        this.threadPool = threadPool;
+        this.flushDelaySupplier = flushDelaySupplier;
+
+        try {
+            Files.createDirectories(dbPath);
+        } catch (IOException e) {
+            throw new IgniteInternalException("Failed to create transaction state storage directory", e);
+        }
+    }
+
+    /**
+     * Returns shared {@link RocksDB} instance.
+     */
+    RocksDB db() {
+        return db;
+    }
+
+    /**
+     * Returns a future to await flush.
+     */
+    CompletableFuture<Void> awaitFlush(boolean schedule) {
+        return flusher.awaitFlush(schedule);
+    }
+
+    /**
+     * Starts the storage.
+     */
+    public void start() {
+        try {
+            flusher = new RocksDbFlusher(
+                    busyLock,
+                    scheduledExecutor,
+                    threadPool,
+                    flushDelaySupplier,
+                    () -> {} // No-op.
+            );
+
+            this.dbOptions = new DBOptions()
+                    .setCreateIfMissing(true)
+                    .setAtomicFlush(true)
+                    .setListeners(List.of(flusher.listener()));
+
+            List<ColumnFamilyDescriptor> cfDescriptors;
+
+            try (Options opts = new Options()) {
+                cfDescriptors = RocksDB.listColumnFamilies(opts, dbPath.toAbsolutePath().toString())
+                        .stream()
+                        .map(nameBytes -> new ColumnFamilyDescriptor(nameBytes, new ColumnFamilyOptions()))
+                        .collect(toList());
+
+                cfDescriptors = cfDescriptors.isEmpty()
+                        ? List.of(new ColumnFamilyDescriptor(TX_STATE_CF.getBytes(StandardCharsets.UTF_8), new ColumnFamilyOptions()))
+                        : cfDescriptors;
+            }
+
+            List<ColumnFamilyHandle> cfHandles = new ArrayList<>(cfDescriptors.size());
+
+            this.db = RocksDB.open(dbOptions, dbPath.toString(), cfDescriptors, cfHandles);
+
+            flusher.init(db, cfHandles);
+        } catch (Exception e) {
+            throw new IgniteInternalException("Could not create transaction state storage", e);
+        }
+    }
+
+    @Override
+    public void close() {
+        if (!stopGuard.compareAndSet(false, true)) {
+            return;
+        }
+
+        busyLock.block();
+
+        try {
+            List<AutoCloseable> resources = new ArrayList<>();
+
+            resources.add(readOptions);
+            resources.add(writeOptions);
+            resources.add(dbOptions);
+            resources.add(db);
+
+            reverse(resources);
+            IgniteUtils.closeAll(resources);
+        } catch (Exception e) {
+            throw new IgniteInternalException("Failed to stop transaction state storage", e);

Review Comment:
   Your answer sounds like an excuse for laziness.
   I would correct it, but it's at your discretion.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21204 Implement shared rocksdb storage for transaction states [ignite-3]

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #3012:
URL: https://github.com/apache/ignite-3/pull/3012#discussion_r1444327296


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -398,28 +391,31 @@ public void destroy() {
     }
 
     private byte[] partitionStartPrefix() {
-        return ByteBuffer.allocate(Short.BYTES).order(ByteOrder.BIG_ENDIAN)
-            .putShort((short) (partitionId))
-            .array();
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES).order(ByteOrder.BIG_ENDIAN)
+                .putInt(tableId)
+                .putShort((short) (partitionId))
+                .array();
     }
 
     private byte[] partitionEndPrefix() {
-        return ByteBuffer.allocate(Short.BYTES).order(ByteOrder.BIG_ENDIAN)
-            .putShort((short) (partitionId + 1))
-            .array();
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES).order(ByteOrder.BIG_ENDIAN)
+                .putInt(tableId)
+                .putShort((short) (partitionId + 1))
+                .array();
     }
 
     private byte[] txIdToKey(UUID txId) {
-        return ByteBuffer.allocate(Short.BYTES + 2 * Long.BYTES).order(ByteOrder.BIG_ENDIAN)
+        return ByteBuffer.allocate(PREFIX_SIZE_BYTES + 2 * Long.BYTES).order(ByteOrder.BIG_ENDIAN)

Review Comment:
   Ok, I don't mind doing that if you persist



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org