@@ -49,7 +49,7 @@ public abstract class Publication {
4949
5050 private Optional <ApplyCommitRequest > applyCommitRequest ; // set when state is committed
5151 private boolean isCompleted ; // set when publication is completed
52- private boolean timedOut ; // set when publication timed out
52+ private boolean cancelled ; // set when publication is cancelled
5353
5454 public Publication (PublishRequest publishRequest , AckListener ackListener , LongSupplier currentTimeSupplier ) {
5555 this .publishRequest = publishRequest ;
@@ -71,17 +71,17 @@ public void start(Set<DiscoveryNode> faultyNodes) {
7171 publicationTargets .forEach (PublicationTarget ::sendPublishRequest );
7272 }
7373
74- public void onTimeout ( ) {
74+ public void cancel ( String reason ) {
7575 if (isCompleted ) {
7676 return ;
7777 }
7878
79- assert timedOut == false ;
80- timedOut = true ;
79+ assert cancelled == false ;
80+ cancelled = true ;
8181 if (applyCommitRequest .isPresent () == false ) {
82- logger .debug ("onTimeout : [{}] timed out before committing" , this );
82+ logger .debug ("cancel : [{}] cancelled before committing (reason: {}) " , this , reason );
8383 // fail all current publications
84- final Exception e = new ElasticsearchException ("publication timed out before committing" );
84+ final Exception e = new ElasticsearchException ("publication cancelled before committing: " + reason );
8585 publicationTargets .stream ().filter (PublicationTarget ::isActive ).forEach (pt -> pt .setFailed (e ));
8686 }
8787 onPossibleCompletion ();
@@ -101,7 +101,7 @@ private void onPossibleCompletion() {
101101 return ;
102102 }
103103
104- if (timedOut == false ) {
104+ if (cancelled == false ) {
105105 for (final PublicationTarget target : publicationTargets ) {
106106 if (target .isActive ()) {
107107 return ;
@@ -125,8 +125,8 @@ private void onPossibleCompletion() {
125125 }
126126
127127 // For assertions only: verify that this invariant holds
128- private boolean publicationCompletedIffAllTargetsInactiveOrTimedOut () {
129- if (timedOut == false ) {
128+ private boolean publicationCompletedIffAllTargetsInactiveOrCancelled () {
129+ if (cancelled == false ) {
130130 for (final PublicationTarget target : publicationTargets ) {
131131 if (target .isActive ()) {
132132 return isCompleted == false ;
@@ -222,7 +222,7 @@ void sendPublishRequest() {
222222 state = PublicationTargetState .SENT_PUBLISH_REQUEST ;
223223 Publication .this .sendPublishRequest (discoveryNode , publishRequest , new PublishResponseHandler ());
224224 // TODO Can this ^ fail with an exception? Target should be failed if so.
225- assert publicationCompletedIffAllTargetsInactiveOrTimedOut ();
225+ assert publicationCompletedIffAllTargetsInactiveOrCancelled ();
226226 }
227227
228228 void handlePublishResponse (PublishResponse publishResponse ) {
@@ -245,7 +245,7 @@ void sendApplyCommit() {
245245 state = PublicationTargetState .SENT_APPLY_COMMIT ;
246246 assert applyCommitRequest .isPresent ();
247247 Publication .this .sendApplyCommit (discoveryNode , applyCommitRequest .get (), new ApplyCommitResponseHandler ());
248- assert publicationCompletedIffAllTargetsInactiveOrTimedOut ();
248+ assert publicationCompletedIffAllTargetsInactiveOrCancelled ();
249249 }
250250
251251 void setAppliedCommit () {
@@ -300,7 +300,7 @@ private class PublishResponseHandler implements ActionListener<PublishWithJoinRe
300300 public void onResponse (PublishWithJoinResponse response ) {
301301 if (isFailed ()) {
302302 logger .debug ("PublishResponseHandler.handleResponse: already failed, ignoring response from [{}]" , discoveryNode );
303- assert publicationCompletedIffAllTargetsInactiveOrTimedOut ();
303+ assert publicationCompletedIffAllTargetsInactiveOrCancelled ();
304304 return ;
305305 }
306306
@@ -319,7 +319,7 @@ public void onResponse(PublishWithJoinResponse response) {
319319 state = PublicationTargetState .WAITING_FOR_QUORUM ;
320320 handlePublishResponse (response .getPublishResponse ());
321321
322- assert publicationCompletedIffAllTargetsInactiveOrTimedOut ();
322+ assert publicationCompletedIffAllTargetsInactiveOrCancelled ();
323323 }
324324
325325 @ Override
@@ -330,7 +330,7 @@ public void onFailure(Exception e) {
330330 assert ((TransportException ) e ).getRootCause () instanceof Exception ;
331331 setFailed ((Exception ) exp .getRootCause ());
332332 onPossibleCommitFailure ();
333- assert publicationCompletedIffAllTargetsInactiveOrTimedOut ();
333+ assert publicationCompletedIffAllTargetsInactiveOrCancelled ();
334334 }
335335
336336 }
@@ -346,7 +346,7 @@ public void onResponse(TransportResponse.Empty ignored) {
346346 }
347347 setAppliedCommit ();
348348 onPossibleCompletion ();
349- assert publicationCompletedIffAllTargetsInactiveOrTimedOut ();
349+ assert publicationCompletedIffAllTargetsInactiveOrCancelled ();
350350 }
351351
352352 @ Override
@@ -357,7 +357,7 @@ public void onFailure(Exception e) {
357357 assert ((TransportException ) e ).getRootCause () instanceof Exception ;
358358 setFailed ((Exception ) exp .getRootCause ());
359359 onPossibleCompletion ();
360- assert publicationCompletedIffAllTargetsInactiveOrTimedOut ();
360+ assert publicationCompletedIffAllTargetsInactiveOrCancelled ();
361361 }
362362 }
363363 }
0 commit comments