-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Inline TransportReplAct#createReplicatedOperation #41197
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 4 commits
667cfd8
fb1f7eb
1350c0f
a26a986
c5dc9f9
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 |
|---|---|---|
|
|
@@ -357,37 +357,37 @@ public void handleException(TransportException exp) { | |
| }); | ||
| } else { | ||
| setPhase(replicationTask, "primary"); | ||
| createReplicatedOperation(primaryRequest.getRequest(), | ||
| ActionListener.wrap(result -> result.respond( | ||
| new ActionListener<>() { | ||
| @Override | ||
| public void onResponse(Response response) { | ||
| if (syncGlobalCheckpointAfterOperation) { | ||
| final IndexShard shard = primaryShardReference.indexShard; | ||
| try { | ||
| shard.maybeSyncGlobalCheckpoint("post-operation"); | ||
| } catch (final Exception e) { | ||
| // only log non-closed exceptions | ||
| if (ExceptionsHelper.unwrap( | ||
| e, AlreadyClosedException.class, IndexShardClosedException.class) == null) { | ||
| // intentionally swallow, a missed global checkpoint sync should not fail this operation | ||
| logger.info( | ||
| new ParameterizedMessage( | ||
| "{} failed to execute post-operation global checkpoint sync", shard.shardId()), e); | ||
| } | ||
| } | ||
| } | ||
| primaryShardReference.close(); // release shard operation lock before responding to caller | ||
| setPhase(replicationTask, "finished"); | ||
| onCompletionListener.onResponse(response); | ||
| } | ||
|
|
||
| @Override | ||
| public void onFailure(Exception e) { | ||
| handleException(primaryShardReference, e); | ||
| final ActionListener<Response> referenceClosingListener = ActionListener.wrap(response -> { | ||
| primaryShardReference.close(); // release shard operation lock before responding to caller | ||
| setPhase(replicationTask, "finished"); | ||
| onCompletionListener.onResponse(response); | ||
| }, e -> handleException(primaryShardReference, e)); | ||
|
|
||
| final IndexShard shard = primaryShardReference.indexShard; | ||
|
|
||
| final ActionListener<Response> globalCheckpointSyncingListener = ActionListener.wrap(response -> { | ||
| if (syncGlobalCheckpointAfterOperation) { | ||
| try { | ||
| shard.maybeSyncGlobalCheckpoint("post-operation"); | ||
| } catch (final Exception e) { | ||
| // only log non-closed exceptions | ||
| if (ExceptionsHelper.unwrap( | ||
| e, AlreadyClosedException.class, IndexShardClosedException.class) == null) { | ||
| // intentionally swallow, a missed global checkpoint sync should not fail this operation | ||
| logger.info( | ||
| new ParameterizedMessage( | ||
| "{} failed to execute post-operation global checkpoint sync", | ||
| primaryShardReference.routingEntry().shardId()), e); | ||
|
||
| } | ||
| }), e -> handleException(primaryShardReference, e) | ||
| ), primaryShardReference).execute(); | ||
| } | ||
| } | ||
| referenceClosingListener.onResponse(response); | ||
| }, referenceClosingListener::onFailure); | ||
|
|
||
| new ReplicationOperation<>(primaryRequest.getRequest(), primaryShardReference, | ||
| ActionListener.wrap(result -> result.respond(globalCheckpointSyncingListener), referenceClosingListener::onFailure), | ||
| newReplicasProxy(), logger, actionName, primaryRequest.getPrimaryTerm()).execute(); | ||
| } | ||
| } catch (Exception e) { | ||
| handleException(primaryShardReference, e); | ||
|
|
@@ -405,12 +405,6 @@ public void onFailure(Exception e) { | |
| onCompletionListener.onFailure(e); | ||
| } | ||
|
|
||
| protected ReplicationOperation<Request, ReplicaRequest, PrimaryResult<ReplicaRequest, Response>> createReplicatedOperation( | ||
| Request request, ActionListener<PrimaryResult<ReplicaRequest, Response>> listener, | ||
| PrimaryShardReference primaryShardReference) { | ||
| return new ReplicationOperation<>(request, primaryShardReference, listener, | ||
| newReplicasProxy(), logger, actionName, primaryRequest.getPrimaryTerm()); | ||
| } | ||
| } | ||
|
|
||
| public static class PrimaryResult<ReplicaRequest extends ReplicationRequest<ReplicaRequest>, | ||
|
|
||
Uh 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.
I find the separation into two listeners artificial and a bit confusing. I suggest something like following instead:
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.
In isolation I agree, but this separation will be important in a followup so I hope it's ok to leave it like it is. The global checkpoint syncing is the responsibility of the primary, whereas the cleanup of the replication task and the
primaryShardReferenceis the responsibility of the reroute/delegation phase.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.
👍