This is an automated email from the ASF dual-hosted git repository.

tkalkirill pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 1be2bb32f73 IGNITE-25837 Fix "end key comes before start key" error in 
RocksDbSharedLogStorage#truncateSuffix (#6190)
1be2bb32f73 is described below

commit 1be2bb32f734cdbb74c35810a16e5273476833a3
Author: Kirill Tkalenko <tkalkir...@yandex.ru>
AuthorDate: Fri Jul 4 14:42:06 2025 +0300

    IGNITE-25837 Fix "end key comes before start key" error in 
RocksDbSharedLogStorage#truncateSuffix (#6190)
---
 .../raft/storage/impl/RocksDbSharedLogStorage.java | 28 ++++++++++++++--------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git 
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/impl/RocksDbSharedLogStorage.java
 
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/impl/RocksDbSharedLogStorage.java
index ef025cc642e..0c92e0d6fc5 100644
--- 
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/impl/RocksDbSharedLogStorage.java
+++ 
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/impl/RocksDbSharedLogStorage.java
@@ -510,19 +510,27 @@ public class RocksDbSharedLogStorage implements 
LogStorage, Describer {
     /** {@inheritDoc} */
     @Override
     public boolean truncateSuffix(long lastIndexKept) {
+        Long lastLogIndex = null;
+
         this.useLock.lock();
         try {
-            try {
-                onTruncateSuffix(lastIndexKept);
-            } finally {
-                this.db.deleteRange(this.dataHandle, this.writeOptions, 
createKey(lastIndexKept + 1),
-                        createKey(getLastLogIndex() + 1));
-                this.db.deleteRange(this.confHandle, this.writeOptions, 
createKey(lastIndexKept + 1),
-                        createKey(getLastLogIndex() + 1));
+            onTruncateSuffix(lastIndexKept);
+
+            lastLogIndex = getLastLogIndex();
+
+            if (lastLogIndex > lastIndexKept) {
+                byte[] beginKey = createKey(lastIndexKept + 1);
+                byte[] endKey = createKey(lastLogIndex + 1);
+
+                this.db.deleteRange(this.dataHandle, this.writeOptions, 
beginKey, endKey);
+                this.db.deleteRange(this.confHandle, this.writeOptions, 
beginKey, endKey);
+
+                return true;
+            } else {
+                LOG.info("Skip truncateSuffix: [lastIndexKept={}, 
lastLogIndex={}]", lastIndexKept, lastLogIndex);
             }
-            return true;
         } catch (RocksDBException | IOException e) {
-            LOG.error("Fail to truncateSuffix {}.", e, lastIndexKept);
+            LOG.error("Fail to truncateSuffix: [lastIndexKept={}, 
lastLogIndex={}]", e, lastIndexKept, lastLogIndex);
         } finally {
             this.useLock.unlock();
         }
@@ -653,7 +661,7 @@ public class RocksDbSharedLogStorage implements LogStorage, 
Describer {
                 this.db.deleteRange(this.dataHandle, startKey, endKey);
                 this.db.deleteRange(this.confHandle, startKey, endKey);
             } catch (RocksDBException | IOException e) {
-                LOG.error("Fail to truncatePrefix {}.", e, firstIndexKept);
+                LOG.error("Fail to truncatePrefix: [startIndex={}, 
firstIndexKept={}].", e, startIndex, firstIndexKept);
             } finally {
                 this.useLock.unlock();
             }

Reply via email to