-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Use soft-update to maintain document history #29458
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f898440
Use soft-update to maintain document history
dnhatn c9d1fd1
only enable soft-delete in the latest version
dnhatn 6f3eb34
Merge branch 'ccr' into ccr-soft-updates
dnhatn 754b0e2
Merge branch 'ccr' into ccr-soft-updates
dnhatn 90ab934
apply simonw feedbacks
dnhatn 82ef84d
Merge branch 'ccr' into ccr-soft-updates
dnhatn 29cbece
Cache the soft-delete field
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 |
---|---|---|
|
@@ -31,10 +31,8 @@ | |
import org.apache.lucene.index.MergePolicy; | ||
import org.apache.lucene.index.SegmentCommitInfo; | ||
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.ReferenceManager; | ||
import org.apache.lucene.search.SearcherFactory; | ||
import org.apache.lucene.search.SearcherManager; | ||
|
@@ -163,7 +161,6 @@ public InternalEngine(EngineConfig engineConfig) { | |
if (engineConfig.isAutoGeneratedIDsOptimizationEnabled() == false) { | ||
maxUnsafeAutoIdTimestamp.set(Long.MAX_VALUE); | ||
} | ||
this.uidField = engineConfig.getIndexSettings().isSingleType() ? IdFieldMapper.NAME : UidFieldMapper.NAME; | ||
this.softDeleteEnabled = engineConfig.getIndexSettings().isSoftDeleteEnabled(); | ||
final TranslogDeletionPolicy translogDeletionPolicy = new TranslogDeletionPolicy( | ||
engineConfig.getIndexSettings().getTranslogRetentionSize().getBytes(), | ||
|
@@ -1073,9 +1070,9 @@ private boolean assertDocDoesNotExist(final Index index, final boolean allowDele | |
private void updateDocs(final Term uid, final List<ParseContext.Document> docs, final IndexWriter indexWriter) throws IOException { | ||
if (softDeleteEnabled) { | ||
if (docs.size() > 1) { | ||
indexWriter.softUpdateDocuments(uid, docs, Lucene.getSoftDeleteDVMarker()); | ||
indexWriter.softUpdateDocuments(uid, docs, Lucene.newSoftDeleteField()); | ||
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. I think we can cache this in here in a constant so we don't need to re-create a new one every time. |
||
} else { | ||
indexWriter.softUpdateDocument(uid, docs.get(0), Lucene.getSoftDeleteDVMarker()); | ||
indexWriter.softUpdateDocument(uid, docs.get(0), Lucene.newSoftDeleteField()); | ||
} | ||
} else { | ||
if (docs.size() > 1) { | ||
|
@@ -1927,7 +1924,6 @@ IndexWriter createWriter(Directory directory, IndexWriterConfig iwc) throws IOEx | |
return new IndexWriter(directory, iwc); | ||
} | ||
|
||
|
||
private IndexWriterConfig getIndexWriterConfig() { | ||
final IndexWriterConfig iwc = new IndexWriterConfig(engineConfig.getAnalyzer()); | ||
iwc.setCommitOnClose(false); // we by default don't commit on close | ||
|
@@ -1945,9 +1941,8 @@ private IndexWriterConfig getIndexWriterConfig() { | |
// background merges | ||
MergePolicy mergePolicy = config().getMergePolicy(); | ||
if (softDeleteEnabled) { | ||
iwc.setSoftDeletesField(Lucene.SOFT_DELETE_FIELD); | ||
// TODO: soft-delete retention policy | ||
mergePolicy = new SoftDeletesRetentionMergePolicy(Lucene.SOFT_DELETE_FIELD, () -> new MatchAllDocsQuery(), mergePolicy); | ||
iwc.setSoftDeletesField(Lucene.SOFT_DELETE_FIELD); | ||
} | ||
iwc.setMergePolicy(new ElasticsearchMergePolicy(mergePolicy)); | ||
iwc.setSimilarity(engineConfig.getSimilarity()); | ||
|
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
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 think in the delete case we should also use
indexWriter.updateDocValue(uid, Lucene.getSoftDeleteDVMarker())
; instead ofIndexWriter#deleteDocuments
and then override this in the test to maybe throw an exception.