-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Never block on key in LiveVersionMap#pruneTombstones
#28736
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9e51950
Never block on key in `LiveVersionMap#pruneTombstones`
s1monw f86962d
Merge branch 'master' into issues/28714
s1monw 0e847ec
apply feedback from @danielmitterdorfer
s1monw 42d785c
add engine test to reproduce the issue
s1monw 3edb7af
apply comments
s1monw 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 |
---|---|---|
|
@@ -4517,4 +4517,60 @@ public void testShouldPeriodicallyFlush() throws Exception { | |
assertThat(engine.getLastCommittedSegmentInfos(), not(sameInstance(lastCommitInfo))); | ||
assertThat(engine.getTranslog().uncommittedOperations(), equalTo(0)); | ||
} | ||
|
||
|
||
public void testStressUpdateSameDocWhileGettingIt() throws IOException, InterruptedException { | ||
final int iters = randomIntBetween(1, 15); | ||
for (int i = 0; i < iters; i++) { | ||
// this is a reproduction of https://github.com/elastic/elasticsearch/issues/28714 | ||
try (Store store = createStore(); final InternalEngine engine = createEngine(store, createTempDir())) { | ||
final IndexSettings indexSettings = engine.config().getIndexSettings(); | ||
final IndexMetaData indexMetaData = IndexMetaData.builder(indexSettings.getIndexMetaData()) | ||
.settings(Settings.builder().put(indexSettings.getSettings()) | ||
.put(IndexSettings.INDEX_GC_DELETES_SETTING.getKey(), TimeValue.timeValueMillis(1))).build(); | ||
engine.engineConfig.getIndexSettings().updateIndexMetaData(indexMetaData); | ||
engine.onSettingsChanged(); | ||
ParsedDocument document = testParsedDocument(Integer.toString(0), null, testDocumentWithTextField(), SOURCE, null); | ||
final Engine.Index doc = new Engine.Index(newUid(document), document, SequenceNumbers.UNASSIGNED_SEQ_NO, 0, | ||
Versions.MATCH_ANY, VersionType.INTERNAL, Engine.Operation.Origin.PRIMARY, System.nanoTime(), 0, false); | ||
// first index an append only document and then delete it. such that we have it in the tombstones | ||
engine.index(doc); | ||
engine.delete(new Engine.Delete(doc.type(), doc.id(), doc.uid())); | ||
|
||
// now index more append only docs and refresh so we re-enabel the optimization for unsafe version map | ||
ParsedDocument document1 = testParsedDocument(Integer.toString(1), null, testDocumentWithTextField(), SOURCE, null); | ||
engine.index(new Engine.Index(newUid(document1), document1, SequenceNumbers.UNASSIGNED_SEQ_NO, 0, | ||
Versions.MATCH_ANY, VersionType.INTERNAL, Engine.Operation.Origin.PRIMARY, System.nanoTime(), 0, false)); | ||
engine.refresh("test"); | ||
ParsedDocument document2 = testParsedDocument(Integer.toString(2), null, testDocumentWithTextField(), SOURCE, null); | ||
engine.index(new Engine.Index(newUid(document2), document2, SequenceNumbers.UNASSIGNED_SEQ_NO, 0, | ||
Versions.MATCH_ANY, VersionType.INTERNAL, Engine.Operation.Origin.PRIMARY, System.nanoTime(), 0, false)); | ||
engine.refresh("test"); | ||
ParsedDocument dummyDocument = testParsedDocument(Integer.toString(3), null, testDocumentWithTextField(), SOURCE, null); | ||
final Engine.Index dummy = new Engine.Index(newUid(dummyDocument), dummyDocument, SequenceNumbers.UNASSIGNED_SEQ_NO, 0, | ||
Versions.MATCH_ANY, VersionType.INTERNAL, Engine.Operation.Origin.PRIMARY, System.nanoTime(), 0, false); | ||
engine.index(dummy); | ||
engine.engineConfig.setEnableGcDeletes(true); | ||
// once we are here the version map is unsafe again and we need to do a refresh inside the get calls to ensure we | ||
// de-optimize. We also enabled GCDeletes which now causes pruning tombstones inside that refresh that is done internally | ||
// to ensure we de-optimize. One get call will purne and the other will try to lock the version map concurrently while | ||
// holding the lock that pruneTombstones needs and we have a deadlock | ||
CountDownLatch awaitStared = new CountDownLatch(1); | ||
Thread thread = new Thread(() -> { | ||
awaitStared.countDown(); | ||
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. Nit: |
||
try (Engine.GetResult getResult = engine.get(new Engine.Get(true, dummy.type(), dummy.id(), dummy.uid()), | ||
engine::acquireSearcher)) { | ||
assertTrue(getResult.exists()); | ||
} | ||
}); | ||
thread.start(); | ||
awaitStared.await(); | ||
try (Engine.GetResult getResult = engine.get(new Engine.Get(true, doc.type(), doc.id(), doc.uid()), | ||
engine::acquireSearcher)) { | ||
assertFalse(getResult.exists()); | ||
} | ||
thread.join(); | ||
} | ||
} | ||
} | ||
} |
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.
Nit: should be named
document3
for consistency?