sashapolo commented on code in PR #7101:
URL: https://github.com/apache/ignite-3/pull/7101#discussion_r2597380084
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java:
##########
@@ -293,33 +301,76 @@ private byte[]
serializeHeaderAndFillMetadata(ReadModeIndexMemTable indexMemTabl
long lastLogIndexExclusive = segmentInfo.lastLogIndexExclusive();
+ long firstIndexKept = segmentInfo.firstIndexKept();
+
// On recovery we are only creating missing index files, in-memory
meta will be created on Index File Manager start.
if (!onRecovery) {
- var indexFileMeta = new IndexFileMeta(firstLogIndexInclusive,
lastLogIndexExclusive, payloadOffset, fileOrdinal);
+ IndexFileMeta indexFileMeta = createIndexFileMeta(
+ firstLogIndexInclusive, lastLogIndexExclusive,
firstIndexKept, payloadOffset, fileOrdinal
+ );
- putIndexFileMeta(groupId, indexFileMeta);
+ putIndexFileMeta(groupId, indexFileMeta, firstIndexKept);
}
headerBuffer
.putLong(groupId)
.putInt(0) // Flags.
.putInt(payloadOffset)
.putLong(firstLogIndexInclusive)
- .putLong(lastLogIndexExclusive);
+ .putLong(lastLogIndexExclusive)
+ .putLong(firstIndexKept);
payloadOffset += payloadSize(segmentInfo);
}
return headerBuffer.array();
}
- private void putIndexFileMeta(Long groupId, IndexFileMeta indexFileMeta) {
+ private static @Nullable IndexFileMeta createIndexFileMeta(
+ long firstLogIndexInclusive,
+ long lastLogIndexExclusive,
+ long firstIndexKept,
+ int payloadOffset,
+ int fileOrdinal
+ ) {
+ if (firstLogIndexInclusive == -1) {
+ assert firstIndexKept != -1 : "Expected a prefix tombstone, but
firstIndexKept is not set.";
+
+ // This is a "prefix tombstone", no need to create any meta, we
will just truncate the prefix.
+ return null;
+ }
+
+ if (firstIndexKept == -1 || firstIndexKept <= firstLogIndexInclusive) {
+ // No prefix truncation required, simply create a new meta.
+ return new IndexFileMeta(firstLogIndexInclusive,
lastLogIndexExclusive, payloadOffset, fileOrdinal);
+ }
+
+ // Create a meta with a truncated prefix.
+ int numEntriesToSkip = toIntExact(firstIndexKept -
firstLogIndexInclusive);
+
+ int adjustedPayloadOffset = payloadOffset + numEntriesToSkip *
Integer.BYTES;
+
+ return new IndexFileMeta(firstIndexKept, lastLogIndexExclusive,
adjustedPayloadOffset, fileOrdinal);
+ }
+
+ private void putIndexFileMeta(Long groupId, @Nullable IndexFileMeta
indexFileMeta, long firstIndexKept) {
GroupIndexMeta existingGroupIndexMeta = groupIndexMetas.get(groupId);
if (existingGroupIndexMeta == null) {
- groupIndexMetas.put(groupId, new GroupIndexMeta(indexFileMeta));
+ if (indexFileMeta != null) {
+ groupIndexMetas.put(groupId, new
GroupIndexMeta(indexFileMeta));
+ }
} else {
- existingGroupIndexMeta.addIndexMeta(indexFileMeta);
+ if (firstIndexKept != -1) {
+ existingGroupIndexMeta.truncatePrefix(firstIndexKept);
+ }
+
+ if (indexFileMeta != null) {
+ // New index meta must have already been truncated according
to the prefix tombstone.
Review Comment:
I was trying to say that if there was a prefix tombstone, the provided index
meta must already be truncated accordingly
--
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]