-
Notifications
You must be signed in to change notification settings - Fork 115
Handle multiple updates to the same record in a transaction #3722
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
Open
ohadzeliger
wants to merge
7
commits into
FoundationDB:main
Choose a base branch
from
ohadzeliger:lucene-multiple-updates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+115
−6
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7f9a93e
Implement a refresh getter for the DirectoryReader to be able to see …
ohadzeliger ee7eea9
Keep old readers and close all together, only refresh reader if fail …
ohadzeliger 1908913
Cleanup
ohadzeliger 7151358
Cleanup
ohadzeliger 1a60d94
Cleanup
ohadzeliger 5f87f43
Merge branch 'main' into lucene-multiple-updates
ohadzeliger de9955c
Merge branch 'main' into lucene-multiple-updates
ohadzeliger 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 hidden or 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 |
|---|---|---|
|
|
@@ -308,8 +308,7 @@ int deleteDocument(Tuple groupingKey, Integer partitionId, Tuple primaryKey) thr | |
| @Nullable final LucenePrimaryKeySegmentIndex segmentIndex = directoryManager.getDirectory(groupingKey, partitionId).getPrimaryKeySegmentIndex(); | ||
|
|
||
| if (segmentIndex != null) { | ||
| final DirectoryReader directoryReader = directoryManager.getWriterReader(groupingKey, partitionId); | ||
| final LucenePrimaryKeySegmentIndex.DocumentIndexEntry documentIndexEntry = segmentIndex.findDocument(directoryReader, primaryKey); | ||
| final LucenePrimaryKeySegmentIndex.DocumentIndexEntry documentIndexEntry = getDocumentIndexEntryWithRetry(segmentIndex, groupingKey, partitionId, primaryKey); | ||
| if (documentIndexEntry != null) { | ||
| state.context.ensureActive().clear(documentIndexEntry.entryKey); // TODO: Only if valid? | ||
| long valid = indexWriter.tryDeleteDocument(documentIndexEntry.indexReader, documentIndexEntry.docId); | ||
|
|
@@ -360,6 +359,33 @@ int deleteDocument(Tuple groupingKey, Integer partitionId, Tuple primaryKey) thr | |
| return 0; | ||
| } | ||
|
|
||
| /** | ||
| * Try to find the document for the given record in the segment index. | ||
| * This method would first try to find the document using teh existing reader. If it can't, it will refresh the reader | ||
| * and try again. The issue is that when the documents have been updated in memory (e.g. in the same transaction), the | ||
| * writer may cache the changes in NRT and the reader (created earlier) can't see them. Refreshing the reader from the | ||
| * writer can alleviate this. If the index can't find the document with the refresh reader, null is returned. | ||
| * Note that the refresh of the reader will do so at the {@link com.apple.foundationdb.record.lucene.directory.FDBDirectoryWrapper} | ||
| * and so has impact on the entire directory. | ||
|
Contributor
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. Please consider rewording. |
||
| * @param groupingKey the grouping key for the index | ||
| * @param partitionId the partition ID for the index | ||
| * @param primaryKey the record primary key to look for | ||
| * @return segment index entry if the record was found, null if none | ||
| * @throws IOException in case of error | ||
| */ | ||
| @SuppressWarnings("PMD.CloseResource") | ||
| private LucenePrimaryKeySegmentIndex.DocumentIndexEntry getDocumentIndexEntryWithRetry(LucenePrimaryKeySegmentIndex segmentIndex, final Tuple groupingKey, final Integer partitionId, final Tuple primaryKey) throws IOException { | ||
| DirectoryReader directoryReader = directoryManager.getWriterReader(groupingKey, partitionId, false); | ||
| LucenePrimaryKeySegmentIndex.DocumentIndexEntry documentIndexEntry = segmentIndex.findDocument(directoryReader, primaryKey); | ||
| if (documentIndexEntry != null) { | ||
| return documentIndexEntry; | ||
| } else { | ||
| // Use refresh to ensure the reader can see the latest deletes | ||
| directoryReader = directoryManager.getWriterReader(groupingKey, partitionId, true); | ||
| return segmentIndex.findDocument(directoryReader, primaryKey); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public CompletableFuture<Void> mergeIndex() { | ||
| return rebalancePartitions() | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.