sashapolo commented on code in PR #7101:
URL: https://github.com/apache/ignite-3/pull/7101#discussion_r2597671175
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexMemTable.java:
##########
@@ -63,23 +69,40 @@ public void appendSegmentFileOffset(long groupId, long
logIndex, int segmentFile
@Override
public SegmentInfo segmentInfo(long groupId) {
- return stripe(groupId).memTable.get(groupId);
+ return memtable(groupId).get(groupId);
}
@Override
public void truncateSuffix(long groupId, long lastLogIndexKept) {
- ConcurrentMap<Long, SegmentInfo> memtable = stripe(groupId).memTable;
-
- SegmentInfo segmentInfo = memtable.get(groupId);
+ ConcurrentMap<Long, SegmentInfo> memtable = memtable(groupId);
+
+ memtable.compute(groupId, (id, segmentInfo) -> {
+ if (segmentInfo == null || lastLogIndexKept <
segmentInfo.firstLogIndexInclusive()) {
+ // If the current memtable does not have information for the
given group or if we are truncating everything currently
+ // present in the memtable, we need to write a special "empty"
SegmentInfo into the memtable to override existing persisted
+ // data during search.
+ return new SegmentInfo(lastLogIndexKept + 1);
Review Comment:
Because if we are in this branch, then "lastLogIndexKept" entry is located
somewhere in index files, not in the current memtable. Therefore we replace the
existing entries, if any (they are all truncated), and add a new "empty" entry
with a base log index of "lastLogIndexKept + 1", since this is the index that
must come next, when a new log entry will be added. This allows us to simply
call `segmentInfo.addOffset` later in `appendSegmentFileOffset`.
--
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]