-
Notifications
You must be signed in to change notification settings - Fork 1.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
Delete Operations on Replicas when Segment Replication is enabled #2839
Changes from 2 commits
5ccdee8
1670ba1
abced8c
9da9d29
f9cf43e
5a0f68b
9948fa0
e7e3c31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ | |
import org.apache.lucene.index.ShuffleForcedMergePolicy; | ||
import org.apache.lucene.index.SoftDeletesRetentionMergePolicy; | ||
import org.apache.lucene.index.StandardDirectoryReader; | ||
import org.apache.lucene.index.SoftDeletesDirectoryReaderWrapper; | ||
import org.apache.lucene.index.Term; | ||
import org.apache.lucene.search.BooleanClause; | ||
import org.apache.lucene.search.BooleanQuery; | ||
|
@@ -716,11 +717,13 @@ private ExternalReaderManager createReaderManager(RefreshWarmerListener external | |
} | ||
|
||
private DirectoryReader getDirectoryReader() throws IOException { | ||
// for segment replication: replicas should create the reader from store, we don't want an open IW on replicas. | ||
// for segment replication: replicas should create the reader from store and, we don't want an open IW on replicas. | ||
/* We should always wrap replicas with a SoftDeletesDirectoryReaderWrapper as we use soft deletes when segment replication is on for | ||
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 - "We should always wrap the DirectoryReader used on replicas with |
||
deletions */ | ||
if (engineConfig.isReadOnly()) { | ||
return DirectoryReader.open(store.directory()); | ||
return new SoftDeletesDirectoryReaderWrapper(DirectoryReader.open(store.directory()), Lucene.SOFT_DELETES_FIELD); | ||
} | ||
return DirectoryReader.open(indexWriter); | ||
return DirectoryReader.open(indexWriter, true, true); | ||
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. is this required? does your test pass without this like with the first PR? I forgot this also impacts the reader with segrep off - if this isn't required with segrep on then we should remove it. Otherwise it needs to be gated by reading the setting. It is changing how the primary behaves with segrep off. 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. This isn't required with segrep on. I think we remove it |
||
} | ||
|
||
@Override | ||
|
@@ -1524,8 +1527,7 @@ public DeleteResult delete(Delete delete) throws IOException { | |
} | ||
} | ||
if (delete.origin().isFromTranslog() == false && deleteResult.getResultType() == Result.Type.SUCCESS) { | ||
final Translog.Location location = translog.add(new Translog.Delete(delete, deleteResult)); | ||
deleteResult.setTranslogLocation(location); | ||
addDeleteOperationToTranslog(delete, deleteResult); | ||
} | ||
localCheckpointTracker.markSeqNoAsProcessed(deleteResult.getSeqNo()); | ||
if (deleteResult.getTranslogLocation() == null) { | ||
|
@@ -1549,6 +1551,30 @@ public DeleteResult delete(Delete delete) throws IOException { | |
return deleteResult; | ||
} | ||
|
||
@Override | ||
public Engine.DeleteResult addDeleteOperationToTranslog(Delete delete) throws IOException { | ||
try (Releasable ignored = versionMap.acquireLock(delete.uid().bytes())) { | ||
DeletionStrategy plan = deletionStrategyForOperation(delete); | ||
DeleteResult deleteResult = new DeleteResult( | ||
plan.versionOfDeletion, | ||
delete.primaryTerm(), | ||
delete.seqNo(), | ||
plan.currentlyDeleted == false | ||
); | ||
addDeleteOperationToTranslog(delete, deleteResult); | ||
deleteResult.setTook(System.nanoTime() - delete.startTime()); | ||
deleteResult.freeze(); | ||
return deleteResult; | ||
} | ||
} | ||
|
||
private void addDeleteOperationToTranslog(Delete delete, DeleteResult deleteResult) throws IOException { | ||
if (deleteResult.getResultType() == Result.Type.SUCCESS) { | ||
final Translog.Location location = translog.add(new Translog.Delete(delete, deleteResult)); | ||
deleteResult.setTranslogLocation(location); | ||
} | ||
} | ||
|
||
private Exception tryAcquireInFlightDocs(Operation operation, int addingDocs) { | ||
assert operation.origin() == Operation.Origin.PRIMARY : operation; | ||
assert operation.seqNo() == SequenceNumbers.UNASSIGNED_SEQ_NO : operation; | ||
|
@@ -2286,6 +2312,12 @@ public SegmentInfos getLatestSegmentInfos() { | |
OpenSearchDirectoryReader reader = null; | ||
try { | ||
reader = externalReaderManager.internalReaderManager.acquire(); | ||
/* This is safe, as we always wrap Standard reader with a SoftDeletesDirectoryReaderWrapper for replicas when segment | ||
replication is enabled */ | ||
if (engineConfig.isReadOnly()) { | ||
return ((StandardDirectoryReader) ((SoftDeletesDirectoryReaderWrapper) reader.getDelegate()).getDelegate()) | ||
.getSegmentInfos(); | ||
} | ||
return ((StandardDirectoryReader) reader.getDelegate()).getSegmentInfos(); | ||
} catch (IOException e) { | ||
throw new EngineException(shardId, e.getMessage(), e); | ||
|
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.
Sorry I missed this on the last PR. You shouldn't need to set these settings here because we override the indexSettings() method at the top of this file.
Will create the index with the default settings we override.
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.
Yeah sorry I too missed it