You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by tk...@apache.org on 2025/07/04 10:02:43 UTC

(ignite-3) 01/01: IGNITE-25837 wip

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

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

commit 1710ccb01acd76994626d2a63db754274a57c161
Author: Kirill Tkalenko <tk...@yandex.ru>
AuthorDate: Fri Jul 4 13:02:22 2025 +0300

    IGNITE-25837 wip
---
 .../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();
             }