sashapolo commented on code in PR #7101:
URL: https://github.com/apache/ignite-3/pull/7101#discussion_r2597383417


##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileMetaArray.java:
##########
@@ -106,10 +114,50 @@ IndexFileMeta find(long logIndex) {
             } else if (logIndex >= midValue.lastLogIndexExclusive()) {
                 lowArrayIndex = middleArrayIndex + 1;
             } else {
-                return midValue;
+                return middleArrayIndex;
             }
         }
 
-        return null;
+        return -1;
+    }
+
+    IndexFileMetaArray truncateIndicesSmallerThan(long firstLogIndexKept) {
+        int firstLogIndexKeptArrayIndex = findArrayIndex(firstLogIndexKept);
+
+        assert firstLogIndexKeptArrayIndex >= 0 : String.format(
+                "Missing entry for log index %d in range [%d:%d).",
+                firstLogIndexKept, firstLogIndexInclusive(), 
lastLogIndexExclusive()
+        );
+
+        IndexFileMeta metaToUpdate = array[firstLogIndexKeptArrayIndex];
+
+        int numEntriesToSkip = toIntExact(firstLogIndexKept - 
metaToUpdate.firstLogIndexInclusive());
+
+        assert numEntriesToSkip >= 0 : String.format(
+                "Trying to do a no-op prefix truncate from index %d in range 
[%d:%d).",
+                firstLogIndexKept, firstLogIndexInclusive(), 
lastLogIndexExclusive()
+        );
+
+        // Move the payload offset pointer to skip truncated entries (each 
entry is 4 bytes).
+        int adjustedPayloadOffset = metaToUpdate.indexFilePayloadOffset() + 
numEntriesToSkip * Integer.BYTES;

Review Comment:
   > Are those 4 bytes the same 4 bytes used in IndexFileManager?
   
   yes



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to