You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "sashapolo (via GitHub)" <gi...@apache.org> on 2025/10/23 13:45:03 UTC
[PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
sashapolo opened a new pull request, #6839:
URL: https://github.com/apache/ignite-3/pull/6839
https://issues.apache.org/jira/browse/IGNITE-26283
Thank you for submitting the pull request.
To streamline the review process of the patch and ensure better code quality
we ask both an author and a reviewer to verify the following:
### The Review Checklist
- [ ] **Formal criteria:** TC status, codestyle, mandatory documentation. Also make sure to complete the following:
\- There is a single JIRA ticket related to the pull request.
\- The web-link to the pull request is attached to the JIRA ticket.
\- The JIRA ticket has the Patch Available state.
\- The description of the JIRA ticket explains WHAT was made, WHY and HOW.
\- The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
- [ ] **Design:** new code conforms with the design principles of the components it is added to.
- [ ] **Patch quality:** patch cannot be split into smaller pieces, its size must be reasonable.
- [ ] **Code quality:** code is clean and readable, necessary developer documentation is added if needed.
- [ ] **Tests code quality:** test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.
### Notes
- [Apache Ignite Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide)
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839#discussion_r2482056910
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/WriteBufferWithMemtable.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.raft.storage.segstore;
+
+import java.nio.ByteBuffer;
+import org.apache.ignite.internal.raft.storage.segstore.SegmentFile.WriteBuffer;
+
+class WriteBufferWithMemtable implements AutoCloseable {
Review Comment:
Note to reviewer: this class was simply extracted from an inner class.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "adityamukho (via GitHub)" <gi...@apache.org>.
adityamukho commented on code in PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839#discussion_r2480376280
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java:
##########
@@ -120,20 +129,36 @@ class IndexFileManager {
Files.createDirectories(indexFilesDir);
}
+ void start() throws IOException {
+ try (Stream<Path> indexFiles = Files.list(indexFilesDir)) {
+ Iterator<Path> it = indexFiles.sorted().iterator();
+
+ while (it.hasNext()) {
+ recoverIndexFileMetas(it.next());
+ }
+ }
+ }
+
Path indexFilesDir() {
return indexFilesDir;
}
/**
* Saves the given index memtable to a file.
+ *
+ * <p>Must only be called by the checkpoint thread.
*/
Path saveIndexMemtable(ReadModeIndexMemTable indexMemTable) throws IOException {
Review Comment:
What about `org.apache.ignite.internal.raft.storage.segstore.RaftLogCheckpointer.CheckpointTask#run`? I wasn't sure if there could be multiple instances of this.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "adityamukho (via GitHub)" <gi...@apache.org>.
adityamukho commented on code in PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839#discussion_r2480286421
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegmentFileManager.java:
##########
@@ -429,6 +479,100 @@ private long maxPossibleEntrySize() {
return segmentFile.buffer().position(segmentFilePointer.payloadOffset());
}
+ private WriteModeIndexMemTable recoverMemtable(SegmentFile segmentFile, Path segmentFilePath) {
+ ByteBuffer buffer = segmentFile.buffer();
+
+ validateSegmentFileHeader(buffer, segmentFilePath);
+
+ var memtable = new IndexMemTable(stripes);
+
+ while (buffer.remaining() > SWITCH_SEGMENT_RECORD.length) {
+ int segmentFilePayloadOffset = buffer.position();
+
+ long groupId = buffer.getLong();
+
+ int payloadLength = buffer.getInt();
+
+ int endOfRecordPosition = buffer.position() + payloadLength + HASH_SIZE_BYTES;
+
+ long index = VarlenEncoder.readLong(buffer);
+
+ memtable.appendSegmentFileOffset(groupId, index, segmentFilePayloadOffset);
+
+ buffer.position(endOfRecordPosition);
+ }
+
+ return memtable;
+ }
+
+ /**
+ * Creates an index memtable from the given segment file. Unlike {@link #recoverMemtable} which is expected to only be called on
+ * "complete" segment files (i.e. those that has experienced a rollover), this method is expected to be called on the most recent,
+ * possibly incomplete segment file.
+ */
+ private WriteModeIndexMemTable recoverLatestMemtable(SegmentFile segmentFile, Path segmentFilePath) {
+ ByteBuffer buffer = segmentFile.buffer();
+
+ validateSegmentFileHeader(buffer, segmentFilePath);
+
+ var memtable = new IndexMemTable(stripes);
+
+ while (buffer.remaining() > SWITCH_SEGMENT_RECORD.length) {
+ int segmentFilePayloadOffset = buffer.position();
+
+ long groupId = buffer.getLong();
+
+ int payloadLength = buffer.getInt();
+
+ int crcPosition = buffer.position() + payloadLength;
+
+ long index = VarlenEncoder.readLong(buffer);
+
+ int crc = buffer.getInt(crcPosition);
+
+ buffer.position(segmentFilePayloadOffset);
+
+ int expectedCrc = FastCrc.calcCrc(buffer, crcPosition - segmentFilePayloadOffset);
+
+ // CRC violation signals the end of meaningful data in the segment file.
+ if (crc != expectedCrc) {
+ break;
+ }
+
+ memtable.appendSegmentFileOffset(groupId, index, segmentFilePayloadOffset);
+ }
+
+ return memtable;
+ }
+
+ private static void validateSegmentFileHeader(ByteBuffer buffer, Path segmentFilePath) {
+ int magicNumber = buffer.getInt();
+
+ if (magicNumber != MAGIC_NUMBER) {
Review Comment:
What does this magic number signify?
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839#discussion_r2481026080
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java:
##########
@@ -120,20 +129,36 @@ class IndexFileManager {
Files.createDirectories(indexFilesDir);
}
+ void start() throws IOException {
+ try (Stream<Path> indexFiles = Files.list(indexFilesDir)) {
+ Iterator<Path> it = indexFiles.sorted().iterator();
+
+ while (it.hasNext()) {
+ recoverIndexFileMetas(it.next());
+ }
+ }
+ }
+
Path indexFilesDir() {
return indexFilesDir;
}
/**
* Saves the given index memtable to a file.
+ *
+ * <p>Must only be called by the checkpoint thread.
*/
Path saveIndexMemtable(ReadModeIndexMemTable indexMemTable) throws IOException {
Review Comment:
yes, it's this thread and it's only one
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839#discussion_r2481683950
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegmentFileManager.java:
##########
@@ -150,10 +157,44 @@ class SegmentFileManager implements ManuallyCloseable {
}
void start() throws IOException {
- checkpointer.start();
+ Path lastSegmentFilePath = null;
+
+ try (Stream<Path> segmentFiles = Files.list(segmentFilesDir)) {
Review Comment:
What tmp files are you talking here? We only have tmp files for index files.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839#discussion_r2480350597
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java:
##########
@@ -120,20 +129,36 @@ class IndexFileManager {
Files.createDirectories(indexFilesDir);
}
+ void start() throws IOException {
+ try (Stream<Path> indexFiles = Files.list(indexFilesDir)) {
+ Iterator<Path> it = indexFiles.sorted().iterator();
+
+ while (it.hasNext()) {
+ recoverIndexFileMetas(it.next());
+ }
Review Comment:
Just a question: why did you mix iterators and streams here? A simple `forEach` would do the job just as well, is there some important difference that I'm unaware of?
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexMemTable.java:
##########
@@ -114,6 +114,8 @@ public Iterator<Entry<Long, SegmentInfo>> iterator() {
private Stripe stripe(long groupId) {
int stripeIndex = Long.hashCode(groupId) % stripes.length;
+ assert stripeIndex >= 0 : String.format("Stripe index must not be negative [groupId=%d]", groupId);
Review Comment:
I don't trust this code, please add a little bit of `org.apache.ignite.internal.util.IgniteUtils#safeAbs(int)`. How does this not failing yet?
Another question - this striping method doesn't match the distribution of disruptors between groups. This will eventually lead to unnecessary contention. Could you please explain this choice, and maybe fix it? If it can't be fixed then please describe the reasons. Thank you!
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegmentFileManager.java:
##########
@@ -150,10 +157,44 @@ class SegmentFileManager implements ManuallyCloseable {
}
void start() throws IOException {
- checkpointer.start();
+ Path lastSegmentFilePath = null;
+
+ try (Stream<Path> segmentFiles = Files.list(segmentFilesDir)) {
Review Comment:
Same comment about `tmp` files, I don't see them being deleted. Maybe I'm looking at the wrong place
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java:
##########
@@ -120,20 +129,36 @@ class IndexFileManager {
Files.createDirectories(indexFilesDir);
}
+ void start() throws IOException {
+ try (Stream<Path> indexFiles = Files.list(indexFilesDir)) {
Review Comment:
Please delete all `tmp` files preemptively, I believe `start` is a right place for it. We should also have a test for restart with an incomplete index file in the folder.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839#discussion_r2481052765
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexMemTable.java:
##########
@@ -114,6 +114,8 @@ public Iterator<Entry<Long, SegmentInfo>> iterator() {
private Stripe stripe(long groupId) {
int stripeIndex = Long.hashCode(groupId) % stripes.length;
+ assert stripeIndex >= 0 : String.format("Stripe index must not be negative [groupId=%d]", groupId);
Review Comment:
> How does this not failing yet?
Because there are no tests that use negative `groupId`
> Another question - this striping method doesn't match the distribution of disruptors between groups.
I'll try to fix it in a separate ticket, `StripedDisruptor` mapping logic is not straightforward. The main reason I did it like this is because it was simpler (though I'd better have created a ticket then).
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "adityamukho (via GitHub)" <gi...@apache.org>.
adityamukho commented on code in PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839#discussion_r2480248147
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java:
##########
@@ -120,20 +129,36 @@ class IndexFileManager {
Files.createDirectories(indexFilesDir);
}
+ void start() throws IOException {
+ try (Stream<Path> indexFiles = Files.list(indexFilesDir)) {
+ Iterator<Path> it = indexFiles.sorted().iterator();
+
+ while (it.hasNext()) {
+ recoverIndexFileMetas(it.next());
+ }
+ }
+ }
+
Path indexFilesDir() {
return indexFilesDir;
}
/**
* Saves the given index memtable to a file.
+ *
+ * <p>Must only be called by the checkpoint thread.
*/
Path saveIndexMemtable(ReadModeIndexMemTable indexMemTable) throws IOException {
- String fileName = indexFileName(curFileOrdinal, 0);
+ return saveIndexMemtable(indexMemTable, ++curFileOrdinal);
+ }
+
+ Path saveIndexMemtable(ReadModeIndexMemTable indexMemTable, int fileOrdinal) throws IOException {
+ String fileName = indexFileName(fileOrdinal, 0);
Review Comment:
I know I had asked this in an earlier PR, but just to refresh my memory, why is the generation always set to 0?
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "adityamukho (via GitHub)" <gi...@apache.org>.
adityamukho commented on code in PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839#discussion_r2480248147
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java:
##########
@@ -120,20 +129,36 @@ class IndexFileManager {
Files.createDirectories(indexFilesDir);
}
+ void start() throws IOException {
+ try (Stream<Path> indexFiles = Files.list(indexFilesDir)) {
+ Iterator<Path> it = indexFiles.sorted().iterator();
+
+ while (it.hasNext()) {
+ recoverIndexFileMetas(it.next());
+ }
+ }
+ }
+
Path indexFilesDir() {
return indexFilesDir;
}
/**
* Saves the given index memtable to a file.
+ *
+ * <p>Must only be called by the checkpoint thread.
*/
Path saveIndexMemtable(ReadModeIndexMemTable indexMemTable) throws IOException {
- String fileName = indexFileName(curFileOrdinal, 0);
+ return saveIndexMemtable(indexMemTable, ++curFileOrdinal);
+ }
+
+ Path saveIndexMemtable(ReadModeIndexMemTable indexMemTable, int fileOrdinal) throws IOException {
+ String fileName = indexFileName(fileOrdinal, 0);
Review Comment:
I know I had asked this in an earlier PR, but just to refresh my memory, why is the generation always set to 0 here?
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839#discussion_r2481683950
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegmentFileManager.java:
##########
@@ -150,10 +157,44 @@ class SegmentFileManager implements ManuallyCloseable {
}
void start() throws IOException {
- checkpointer.start();
+ Path lastSegmentFilePath = null;
+
+ try (Stream<Path> segmentFiles = Files.list(segmentFilesDir)) {
Review Comment:
What tmp files are you talking about here? We only have tmp files for index files.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839#discussion_r2481027186
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java:
##########
@@ -120,20 +129,36 @@ class IndexFileManager {
Files.createDirectories(indexFilesDir);
}
+ void start() throws IOException {
+ try (Stream<Path> indexFiles = Files.list(indexFilesDir)) {
+ Iterator<Path> it = indexFiles.sorted().iterator();
+
+ while (it.hasNext()) {
+ recoverIndexFileMetas(it.next());
+ }
Review Comment:
because of checked exceptions
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839#discussion_r2485531874
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegmentFileManager.java:
##########
@@ -150,10 +157,44 @@ class SegmentFileManager implements ManuallyCloseable {
}
void start() throws IOException {
- checkpointer.start();
+ Path lastSegmentFilePath = null;
+
+ try (Stream<Path> segmentFiles = Files.list(segmentFilesDir)) {
Review Comment:
Ok, here it's my mistake, sorry
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839#discussion_r2481027699
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java:
##########
@@ -120,20 +129,36 @@ class IndexFileManager {
Files.createDirectories(indexFilesDir);
}
+ void start() throws IOException {
+ try (Stream<Path> indexFiles = Files.list(indexFilesDir)) {
Review Comment:
Nice catch, will do
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "adityamukho (via GitHub)" <gi...@apache.org>.
adityamukho commented on code in PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839#discussion_r2480303371
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java:
##########
@@ -120,20 +129,36 @@ class IndexFileManager {
Files.createDirectories(indexFilesDir);
}
+ void start() throws IOException {
+ try (Stream<Path> indexFiles = Files.list(indexFilesDir)) {
+ Iterator<Path> it = indexFiles.sorted().iterator();
+
+ while (it.hasNext()) {
+ recoverIndexFileMetas(it.next());
+ }
+ }
+ }
+
Path indexFilesDir() {
return indexFilesDir;
}
/**
* Saves the given index memtable to a file.
+ *
+ * <p>Must only be called by the checkpoint thread.
*/
Path saveIndexMemtable(ReadModeIndexMemTable indexMemTable) throws IOException {
Review Comment:
Is this potentially called from multiple threads concurrently?
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839#discussion_r2480321729
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegmentFileManager.java:
##########
@@ -429,6 +479,100 @@ private long maxPossibleEntrySize() {
return segmentFile.buffer().position(segmentFilePointer.payloadOffset());
}
+ private WriteModeIndexMemTable recoverMemtable(SegmentFile segmentFile, Path segmentFilePath) {
+ ByteBuffer buffer = segmentFile.buffer();
+
+ validateSegmentFileHeader(buffer, segmentFilePath);
+
+ var memtable = new IndexMemTable(stripes);
+
+ while (buffer.remaining() > SWITCH_SEGMENT_RECORD.length) {
+ int segmentFilePayloadOffset = buffer.position();
+
+ long groupId = buffer.getLong();
+
+ int payloadLength = buffer.getInt();
+
+ int endOfRecordPosition = buffer.position() + payloadLength + HASH_SIZE_BYTES;
+
+ long index = VarlenEncoder.readLong(buffer);
+
+ memtable.appendSegmentFileOffset(groupId, index, segmentFilePayloadOffset);
+
+ buffer.position(endOfRecordPosition);
+ }
+
+ return memtable;
+ }
+
+ /**
+ * Creates an index memtable from the given segment file. Unlike {@link #recoverMemtable} which is expected to only be called on
+ * "complete" segment files (i.e. those that has experienced a rollover), this method is expected to be called on the most recent,
+ * possibly incomplete segment file.
+ */
+ private WriteModeIndexMemTable recoverLatestMemtable(SegmentFile segmentFile, Path segmentFilePath) {
+ ByteBuffer buffer = segmentFile.buffer();
+
+ validateSegmentFileHeader(buffer, segmentFilePath);
+
+ var memtable = new IndexMemTable(stripes);
+
+ while (buffer.remaining() > SWITCH_SEGMENT_RECORD.length) {
+ int segmentFilePayloadOffset = buffer.position();
+
+ long groupId = buffer.getLong();
+
+ int payloadLength = buffer.getInt();
+
+ int crcPosition = buffer.position() + payloadLength;
+
+ long index = VarlenEncoder.readLong(buffer);
+
+ int crc = buffer.getInt(crcPosition);
+
+ buffer.position(segmentFilePayloadOffset);
+
+ int expectedCrc = FastCrc.calcCrc(buffer, crcPosition - segmentFilePayloadOffset);
+
+ // CRC violation signals the end of meaningful data in the segment file.
+ if (crc != expectedCrc) {
+ break;
+ }
+
+ memtable.appendSegmentFileOffset(groupId, index, segmentFilePayloadOffset);
+ }
+
+ return memtable;
+ }
+
+ private static void validateSegmentFileHeader(ByteBuffer buffer, Path segmentFilePath) {
+ int magicNumber = buffer.getInt();
+
+ if (magicNumber != MAGIC_NUMBER) {
Review Comment:
Just a sanity check that the file type is correct
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "adityamukho (via GitHub)" <gi...@apache.org>.
adityamukho commented on code in PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839#discussion_r2480380389
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java:
##########
@@ -120,20 +129,36 @@ class IndexFileManager {
Files.createDirectories(indexFilesDir);
}
+ void start() throws IOException {
+ try (Stream<Path> indexFiles = Files.list(indexFilesDir)) {
+ Iterator<Path> it = indexFiles.sorted().iterator();
+
+ while (it.hasNext()) {
+ recoverIndexFileMetas(it.next());
+ }
+ }
+ }
+
Path indexFilesDir() {
return indexFilesDir;
}
/**
* Saves the given index memtable to a file.
+ *
+ * <p>Must only be called by the checkpoint thread.
*/
Path saveIndexMemtable(ReadModeIndexMemTable indexMemTable) throws IOException {
Review Comment:
Ok, the javadoc comment above implies there is only one.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839#discussion_r2480321258
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java:
##########
@@ -120,20 +129,36 @@ class IndexFileManager {
Files.createDirectories(indexFilesDir);
}
+ void start() throws IOException {
+ try (Stream<Path> indexFiles = Files.list(indexFilesDir)) {
+ Iterator<Path> it = indexFiles.sorted().iterator();
+
+ while (it.hasNext()) {
+ recoverIndexFileMetas(it.next());
+ }
+ }
+ }
+
Path indexFilesDir() {
return indexFilesDir;
}
/**
* Saves the given index memtable to a file.
+ *
+ * <p>Must only be called by the checkpoint thread.
*/
Path saveIndexMemtable(ReadModeIndexMemTable indexMemTable) throws IOException {
- String fileName = indexFileName(curFileOrdinal, 0);
+ return saveIndexMemtable(indexMemTable, ++curFileOrdinal);
+ }
+
+ Path saveIndexMemtable(ReadModeIndexMemTable indexMemTable, int fileOrdinal) throws IOException {
+ String fileName = indexFileName(fileOrdinal, 0);
Review Comment:
The functionality regarding generations has not been implemented yet
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839#discussion_r2480320492
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java:
##########
@@ -120,20 +129,36 @@ class IndexFileManager {
Files.createDirectories(indexFilesDir);
}
+ void start() throws IOException {
+ try (Stream<Path> indexFiles = Files.list(indexFilesDir)) {
+ Iterator<Path> it = indexFiles.sorted().iterator();
+
+ while (it.hasNext()) {
+ recoverIndexFileMetas(it.next());
+ }
+ }
+ }
+
Path indexFilesDir() {
return indexFilesDir;
}
/**
* Saves the given index memtable to a file.
+ *
+ * <p>Must only be called by the checkpoint thread.
*/
Path saveIndexMemtable(ReadModeIndexMemTable indexMemTable) throws IOException {
Review Comment:
No, this is literally written right above =)
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839#discussion_r2481052765
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexMemTable.java:
##########
@@ -114,6 +114,8 @@ public Iterator<Entry<Long, SegmentInfo>> iterator() {
private Stripe stripe(long groupId) {
int stripeIndex = Long.hashCode(groupId) % stripes.length;
+ assert stripeIndex >= 0 : String.format("Stripe index must not be negative [groupId=%d]", groupId);
Review Comment:
> How does this not failing yet?
Because there are no tests that use `groupId` with negative hash code =)
> Another question - this striping method doesn't match the distribution of disruptors between groups.
I'll try to fix it in a separate ticket, `StripedDisruptor` mapping logic is not straightforward. The main reason I did it like this is because it was simpler (though I'd better have created a ticket then).
##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexMemTable.java:
##########
@@ -114,6 +114,8 @@ public Iterator<Entry<Long, SegmentInfo>> iterator() {
private Stripe stripe(long groupId) {
int stripeIndex = Long.hashCode(groupId) % stripes.length;
+ assert stripeIndex >= 0 : String.format("Stripe index must not be negative [groupId=%d]", groupId);
Review Comment:
> How does this not failing yet?
Because there are no tests that use `groupId` with a negative hash code =)
> Another question - this striping method doesn't match the distribution of disruptors between groups.
I'll try to fix it in a separate ticket, `StripedDisruptor` mapping logic is not straightforward. The main reason I did it like this is because it was simpler (though I'd better have created a ticket then).
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26283 Recover Log Storage on startup [ignite-3]
Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo merged PR #6839:
URL: https://github.com/apache/ignite-3/pull/6839
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org