-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Do not expose hard-deleted docs in Lucene history #32333
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
10d2fdd
Do not expose hard-deleted docs in Lucene history
dnhatn 6cb9044
Revert "AwaitsFix: forbid completion without contexts test"
dnhatn 5405c6e
remove unused imports
dnhatn 1af3e9c
Merge branch 'ccr' into exclude-hard-deletes
dnhatn 5a7251b
Use hardLiveDocs
dnhatn ee8524a
Adrien’s feedback
dnhatn 996ad36
Add todo
dnhatn 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 |
---|---|---|
|
@@ -33,18 +33,24 @@ | |
import org.apache.lucene.index.NoMergePolicy; | ||
import org.apache.lucene.index.RandomIndexWriter; | ||
import org.apache.lucene.index.SegmentInfos; | ||
import org.apache.lucene.index.SoftDeletesRetentionMergePolicy; | ||
import org.apache.lucene.index.Term; | ||
import org.apache.lucene.search.IndexSearcher; | ||
import org.apache.lucene.search.MatchAllDocsQuery; | ||
import org.apache.lucene.search.ScoreDoc; | ||
import org.apache.lucene.search.TermQuery; | ||
import org.apache.lucene.search.TopDocs; | ||
import org.apache.lucene.search.Weight; | ||
import org.apache.lucene.store.Directory; | ||
import org.apache.lucene.store.MMapDirectory; | ||
import org.apache.lucene.store.MockDirectoryWrapper; | ||
import org.apache.lucene.util.Bits; | ||
import org.elasticsearch.common.UUIDs; | ||
import org.elasticsearch.core.internal.io.IOUtils; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import java.io.IOException; | ||
import java.io.StringReader; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
|
@@ -53,6 +59,8 @@ | |
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class LuceneTests extends ESTestCase { | ||
public void testWaitForIndex() throws Exception { | ||
final MockDirectoryWrapper dir = newMockDirectory(); | ||
|
@@ -406,4 +414,56 @@ public void testMMapHackSupported() throws Exception { | |
// add assume's here if needed for certain platforms, but we should know if it does not work. | ||
assertTrue("MMapDirectory does not support unmapping: " + MMapDirectory.UNMAP_NOT_SUPPORTED_REASON, MMapDirectory.UNMAP_SUPPORTED); | ||
} | ||
|
||
public void testWrapAllDocsLive() throws Exception { | ||
Directory dir = newDirectory(); | ||
IndexWriterConfig config = newIndexWriterConfig().setSoftDeletesField(Lucene.SOFT_DELETE_FIELD) | ||
.setMergePolicy(new SoftDeletesRetentionMergePolicy(Lucene.SOFT_DELETE_FIELD, MatchAllDocsQuery::new, newMergePolicy())); | ||
IndexWriter writer = new IndexWriter(dir, config); | ||
int numDocs = between(10, 100); | ||
Set<String> liveDocs = new HashSet<>(); | ||
for (int i = 0; i < numDocs; i++) { | ||
String id = Integer.toString(i); | ||
Document doc = new Document(); | ||
doc.add(new StringField("id", id, Store.YES)); | ||
writer.addDocument(doc); | ||
liveDocs.add(id); | ||
} | ||
for (int i = 0; i < numDocs; i++) { | ||
if (randomBoolean()) { | ||
String id = Integer.toString(i); | ||
Document doc = new Document(); | ||
doc.add(new StringField("id", "v2-" + id, Store.YES)); | ||
if (randomBoolean()) { | ||
writer.softUpdateDocument(new Term("id", id), doc, Lucene.newSoftDeleteField()); | ||
liveDocs.add("v2-" + id); | ||
} | ||
} | ||
// aborted document should never be exposed | ||
if (randomBoolean()) { | ||
try { | ||
Document doc = new Document(); | ||
doc.add(new StringField("aborted", UUIDs.randomBase64UUID(), Store.YES)); | ||
StringReader reader = new StringReader(""); | ||
doc.add(new TextField("other", reader)); | ||
reader.close(); // mark the indexing hit non-aborting error | ||
writer.addDocument(doc); | ||
fail("index should have failed"); | ||
} catch (Exception ignored) { } | ||
} | ||
// TODO: add rolled back docs | ||
} | ||
try (DirectoryReader unwrapped = DirectoryReader.open(writer)) { | ||
DirectoryReader reader = Lucene.wrapAllDocsLive(unwrapped); | ||
assertThat(reader.numDocs(), equalTo(liveDocs.size())); | ||
IndexSearcher searcher = new IndexSearcher(reader); | ||
Set<String> actualDocs = new HashSet<>(); | ||
TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), Integer.MAX_VALUE); | ||
for (ScoreDoc scoreDoc : topDocs.scoreDocs) { | ||
actualDocs.add(reader.document(scoreDoc.doc).get("id")); | ||
} | ||
assertThat(actualDocs, equalTo(liveDocs)); | ||
} | ||
IOUtils.close(writer, dir); | ||
} | ||
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 make it two tests? one that never inserts a document that fails indexing, and another one that always inserts one? 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. done |
||
} |
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
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.
I tried to think this through and we might be subject to concurrent deletes if we do it this way. Can't we instead do something like this:
note I didn't try this out.. just to provide an idea