-
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 5 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
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 |
---|---|---|
|
@@ -67,7 +67,6 @@ | |
import org.elasticsearch.index.seqno.LocalCheckpointTracker; | ||
import org.elasticsearch.index.seqno.SequenceNumbers; | ||
import org.elasticsearch.index.shard.ElasticsearchMergePolicy; | ||
import org.elasticsearch.index.shard.IndexingStats; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.index.translog.Translog; | ||
import org.elasticsearch.index.translog.TranslogConfig; | ||
|
@@ -138,6 +137,7 @@ public class InternalEngine extends Engine { | |
private final CounterMetric numDocDeletes = new CounterMetric(); | ||
private final CounterMetric numDocAppends = new CounterMetric(); | ||
private final CounterMetric numDocUpdates = new CounterMetric(); | ||
private final boolean softDeleteEnabled; | ||
|
||
/** | ||
* How many bytes we are currently moving to disk, via either IndexWriter.flush or refresh. IndexingMemoryController polls this | ||
|
@@ -161,6 +161,7 @@ public InternalEngine(EngineConfig engineConfig) { | |
if (engineConfig.isAutoGeneratedIDsOptimizationEnabled() == false) { | ||
maxUnsafeAutoIdTimestamp.set(Long.MAX_VALUE); | ||
} | ||
this.softDeleteEnabled = engineConfig.getIndexSettings().isSoftDeleteEnabled(); | ||
final TranslogDeletionPolicy translogDeletionPolicy = new TranslogDeletionPolicy( | ||
engineConfig.getIndexSettings().getTranslogRetentionSize().getBytes(), | ||
engineConfig.getIndexSettings().getTranslogRetentionAge().getMillis() | ||
|
@@ -768,6 +769,7 @@ public IndexResult index(Index index) throws IOException { | |
} else if (plan.indexIntoLucene) { | ||
indexResult = indexIntoLucene(index, plan); | ||
} else { | ||
// TODO: We need to index stale documents to have a full history in Lucene. | ||
indexResult = new IndexResult( | ||
plan.versionForIndexing, plan.seqNoForIndexing, plan.currentNotFoundOrDeleted); | ||
} | ||
|
@@ -1066,10 +1068,18 @@ 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 (docs.size() > 1) { | ||
indexWriter.updateDocuments(uid, docs); | ||
if (softDeleteEnabled) { | ||
if (docs.size() > 1) { | ||
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.newSoftDeleteField()); | ||
} | ||
} else { | ||
indexWriter.updateDocument(uid, docs.get(0)); | ||
if (docs.size() > 1) { | ||
indexWriter.updateDocuments(uid, docs); | ||
} else { | ||
indexWriter.updateDocument(uid, docs.get(0)); | ||
} | ||
} | ||
numDocUpdates.inc(docs.size()); | ||
} | ||
|
@@ -1927,11 +1937,14 @@ private IndexWriterConfig getIndexWriterConfig() { | |
} | ||
iwc.setInfoStream(verbose ? InfoStream.getDefault() : new LoggerInfoStream(logger)); | ||
iwc.setMergeScheduler(mergeScheduler); | ||
MergePolicy mergePolicy = config().getMergePolicy(); | ||
// Give us the opportunity to upgrade old segments while performing | ||
// background merges | ||
mergePolicy = new ElasticsearchMergePolicy(mergePolicy); | ||
iwc.setMergePolicy(mergePolicy); | ||
MergePolicy mergePolicy = config().getMergePolicy(); | ||
if (softDeleteEnabled) { | ||
// TODO: soft-delete retention policy | ||
iwc.setSoftDeletesField(Lucene.SOFT_DELETE_FIELD); | ||
} | ||
iwc.setMergePolicy(new ElasticsearchMergePolicy(mergePolicy)); | ||
iwc.setSimilarity(engineConfig.getSimilarity()); | ||
iwc.setRAMBufferSizeMB(engineConfig.getIndexingBufferSize().getMbFrac()); | ||
iwc.setCodec(engineConfig.getCodec()); | ||
|
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 |
---|---|---|
|
@@ -119,6 +119,7 @@ | |
import org.elasticsearch.index.translog.Translog; | ||
import org.elasticsearch.index.translog.TranslogConfig; | ||
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; | ||
import org.elasticsearch.test.IndexSettingsModule; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
|
||
|
@@ -2711,6 +2712,12 @@ private void maybeThrowFailure() throws IOException { | |
} | ||
} | ||
|
||
@Override | ||
public long softUpdateDocument(Term term, Iterable<? extends IndexableField> doc, Field... softDeletes) throws IOException { | ||
maybeThrowFailure(); | ||
return super.softUpdateDocument(term, doc, softDeletes); | ||
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. ++ |
||
} | ||
|
||
@Override | ||
public long deleteDocuments(Term... terms) throws IOException { | ||
maybeThrowFailure(); | ||
|
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.