-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Advance max_seq_no before add operation to Lucene #38879
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5653,4 +5653,46 @@ public void testStoreHonorsLuceneVersion() throws IOException { | |
} | ||
} | ||
} | ||
|
||
public void testMaxSeqNoInCommitUserData() throws Exception { | ||
AtomicBoolean running = new AtomicBoolean(true); | ||
Thread rollTranslog = new Thread(() -> { | ||
while (running.get() && engine.getTranslog().currentFileGeneration() < 500) { | ||
engine.rollTranslogGeneration(); // make adding operations to translog slower | ||
} | ||
}); | ||
rollTranslog.start(); | ||
|
||
long maxNumDocs = 1000; | ||
Thread indexing = new Thread(() -> { | ||
long seqNo = 0; | ||
while (running.get() && seqNo <= maxNumDocs) { | ||
try { | ||
ParsedDocument doc = testParsedDocument(Long.toString(seqNo), null, testDocumentWithTextField(), SOURCE, null); | ||
engine.index(replicaIndexForDoc(doc, 1L, seqNo, false)); | ||
seqNo++; | ||
} catch (IOException e) { | ||
throw new AssertionError(e); | ||
} | ||
} | ||
}); | ||
indexing.start(); | ||
|
||
int numCommits = between(5, 20); | ||
for (int i = 0; i < numCommits; i++) { | ||
engine.flush(false, true); | ||
} | ||
running.set(false); | ||
indexing.join(); | ||
rollTranslog.join(); | ||
List<IndexCommit> commits = DirectoryReader.listCommits(store.directory()); | ||
for (IndexCommit commit : commits) { | ||
try (DirectoryReader reader = DirectoryReader.open(commit)) { | ||
AtomicLong maxSeqNoFromDocs = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED); | ||
Lucene.scanSeqNosInReader(reader, 0, maxNumDocs, n -> maxSeqNoFromDocs.set(Math.max(n, maxSeqNoFromDocs.get()))); | ||
assertThat(Long.parseLong(commit.getUserData().get(SequenceNumbers.MAX_SEQ_NO)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we check this property across all of our Engine tests? |
||
greaterThanOrEqualTo(maxSeqNoFromDocs.get())); | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Properly setting the max sequence number before indexing might not only be a useful property for Lucene-indexed stuff, but in general. I would prefer not to hide it in this sub-condition.
It bugs me that the planning process is mutating the state of the LocalCheckpointTracker in this way when being primary, but not when being replica. If we want the flow for the primary and replica to be the same, we could do this instead as part of the planning process in
planIndexingAsNonPrimary
. This will make it so that both primary and replica manage this property in the planning phase (will also require adaptation to FollowingEngine).As a follow-up, I think we should also investigate whether we can remove this state mutation from the planning process, i.e., not have the planning process assign a sequence number or change the max seq no, but do it as an explicit step here in the
index
method, given that it is such a fundamental step in processing a request.