Skip to content

Commit

Permalink
Complete user requests exceptionally
Browse files Browse the repository at this point in the history
* Complete user requests exceptionally if failed to add to the
  processing queue.

Closes jgroups-extras#308.
  • Loading branch information
jabolina committed Sep 24, 2024
1 parent f8904ab commit f7459b1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/org/jgroups/protocols/raft/RAFT.java
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,9 @@ public CompletableFuture<byte[]> setAsync(byte[] buf, int offset, int length, bo
}
if(synchronous) // set only for testing purposes
handleDownRequest(retval, buf, offset, length, internal, options);
else
else {
add(new DownRequest(retval, buf, offset, length, internal, options)); // will call handleDownRequest()
}
return retval; // 4. Return CompletableFuture
}

Expand All @@ -705,6 +706,7 @@ protected void add(Request r) {
}
catch(InterruptedException ex) {
log.error("%s: failed adding %s to processing queue: %s", local_addr, r, ex);
r.failed(ex);
}
}

Expand Down Expand Up @@ -1298,6 +1300,8 @@ protected void computeMajority() {

protected static class Request {

protected void failed(Throwable t) { }

}

/** Received by up(Message) or up(MessageBatch) */
Expand Down Expand Up @@ -1333,6 +1337,11 @@ public DownRequest(CompletableFuture<byte[]> f, byte[] buf, int offset, int leng
this.options=opts;
}

@Override
protected final void failed(Throwable t) {
f.completeExceptionally(t);
}

public String toString() {
return String.format("%s %d bytes", DownRequest.class.getSimpleName(), length);
}
Expand Down

0 comments on commit f7459b1

Please sign in to comment.