-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Added timing data and more granular stages to SegmentReplicationState #4222
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -64,7 +64,7 @@ public SegmentReplicationTarget( | |
| super("replication_target", indexShard, new ReplicationLuceneIndex(), listener); | ||
| this.checkpoint = checkpoint; | ||
| this.source = source; | ||
| this.state = new SegmentReplicationState(stateIndex); | ||
| this.state = new SegmentReplicationState(stateIndex, getId()); | ||
| this.multiFileWriter = new MultiFileWriter(indexShard.store(), stateIndex, getPrefix(), logger, this::ensureRefCount); | ||
| } | ||
|
|
||
|
|
@@ -139,7 +139,9 @@ public void startReplication(ActionListener<Void> listener) { | |
| final StepListener<GetSegmentFilesResponse> getFilesListener = new StepListener<>(); | ||
| final StepListener<Void> finalizeListener = new StepListener<>(); | ||
|
|
||
| logger.trace("[shardId {}] Replica starting replication [id {}]", shardId().getId(), getId()); | ||
| // Get list of files to copy from this checkpoint. | ||
| state.setStage(SegmentReplicationState.Stage.GET_CHECKPOINT_INFO); | ||
| source.getCheckpointMetadata(getId(), checkpoint, checkpointInfoListener); | ||
|
|
||
| checkpointInfoListener.whenComplete(checkpointInfo -> getFiles(checkpointInfo, getFilesListener), listener::onFailure); | ||
|
|
@@ -152,14 +154,16 @@ public void startReplication(ActionListener<Void> listener) { | |
|
|
||
| private void getFiles(CheckpointInfoResponse checkpointInfo, StepListener<GetSegmentFilesResponse> getFilesListener) | ||
| throws IOException { | ||
| state.setStage(SegmentReplicationState.Stage.FILE_DIFF); | ||
| final Store.MetadataSnapshot snapshot = checkpointInfo.getSnapshot(); | ||
| Store.MetadataSnapshot localMetadata = getMetadataSnapshot(); | ||
| final Store.RecoveryDiff diff = snapshot.segmentReplicationDiff(localMetadata); | ||
| logger.debug("Replication diff {}", diff); | ||
| // Segments are immutable. So if the replica has any segments with the same name that differ from the one in the incoming snapshot | ||
| // from | ||
| // source that means the local copy of the segment has been corrupted/changed in some way and we throw an IllegalStateException to | ||
| // fail the shard | ||
| logger.trace("Replication diff {}", diff); | ||
|
kartg marked this conversation as resolved.
Outdated
|
||
| /* | ||
| * Segments are immutable. So if the replica has any segments with the same name that differ from the one in the incoming | ||
| * snapshot from source that means the local copy of the segment has been corrupted/changed in some way and we throw an | ||
| * IllegalStateException to fail the shard | ||
| */ | ||
| if (diff.different.isEmpty() == false) { | ||
| getFilesListener.onFailure( | ||
|
Contributor
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. Certainly an existing code, but it seems like there is a bug here: we don't thrown an exception but call the listener direclty and move on ... @kartg wdyt?
Member
Author
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. @reta Good catch! We shouldn't be proceeding if the failure listener is invoked. Would you mind if i incorporated the fix for this as a follow-up PR? I'd like to keep the scope of this PR focused on the seg-rep stages and timing data. |
||
| new IllegalStateException( | ||
|
|
@@ -177,15 +181,18 @@ private void getFiles(CheckpointInfoResponse checkpointInfo, StepListener<GetSeg | |
| .collect(Collectors.toSet()); | ||
|
|
||
| filesToFetch.addAll(pendingDeleteFiles); | ||
| logger.trace("Files to fetch {}", filesToFetch); | ||
|
kartg marked this conversation as resolved.
Outdated
|
||
|
|
||
| for (StoreFileMetadata file : filesToFetch) { | ||
| state.getIndex().addFileDetail(file.name(), file.length(), false); | ||
| } | ||
| // always send a req even if not fetching files so the primary can clear the copyState for this shard. | ||
| state.setStage(SegmentReplicationState.Stage.GET_FILES); | ||
| source.getSegmentFiles(getId(), checkpointInfo.getCheckpoint(), filesToFetch, store, getFilesListener); | ||
| } | ||
|
|
||
| private void finalizeReplication(CheckpointInfoResponse checkpointInfoResponse, ActionListener<Void> listener) { | ||
| state.setStage(SegmentReplicationState.Stage.FINALIZE_REPLICATION); | ||
| ActionListener.completeWith(listener, () -> { | ||
| multiFileWriter.renameAllTempFiles(); | ||
| final Store store = store(); | ||
|
|
||
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 there is an issue between stage demarcation and handlng the unhappy path. @kartg please correct me if I am wrong but in case of failure
checkpointInfoListener(and others) would delegate tolistener::onFailurewithout marking the current stage as "finished", correct?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.
Yes, that's a conscious choice. We're treating the
DONEstage as a successful replication run. I opted to avoid an explicitFAILEDstage since the target and state objects are local to each replication, and the replication stages are currently only relevant when tracking timing dataUh oh!
There was an error while loading. Please reload this page.
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.
That's fine (I think), the dangling stage is what concerns me: since we publish timing on success only, we do nothing on failure (we don't even know if stage was run, which could be even more important than success for troubleshooting). In any case, leaving the decision up to you.