use of io.atomix.protocols.backup.protocol.ExecuteRequest in project atomix by atomix.
the class PrimaryBackupProxy method execute.
private void execute(PrimitiveOperation operation, ComposableFuture<byte[]> future) {
ExecuteRequest request = ExecuteRequest.request(descriptor, sessionId.id(), clusterService.getLocalNode().id(), operation);
log.trace("Sending {} to {}", request, term.primary());
PrimaryTerm term = this.term;
if (term.primary() != null) {
protocol.execute(term.primary().nodeId(), request).whenCompleteAsync((response, error) -> {
if (error == null) {
log.trace("Received {}", response);
if (response.status() == Status.OK) {
future.complete(response.result());
} else {
if (this.term.term() > term.term()) {
execute(operation).whenComplete(future);
} else {
primaryElection.getTerm().whenComplete((newTerm, termError) -> {
if (termError == null) {
if (newTerm.term() > term.term() && newTerm.primary() != null) {
execute(operation).whenComplete(future);
} else {
future.completeExceptionally(new PrimitiveException.Unavailable());
}
} else {
future.completeExceptionally(new PrimitiveException.Unavailable());
}
});
}
}
} else {
future.completeExceptionally(error);
}
}, threadContext);
} else {
future.completeExceptionally(new ConnectException());
}
}
Aggregations