use of org.neo4j.causalclustering.core.replication.session.OperationContext in project neo4j by neo4j.
the class RaftReplicator method replicate.
@Override
public Future<Object> replicate(ReplicatedContent command, boolean trackResult) throws InterruptedException, NoLeaderFoundException {
OperationContext session = sessionPool.acquireSession();
DistributedOperation operation = new DistributedOperation(command, session.globalSession(), session.localOperationId());
Progress progress = progressTracker.start(operation);
RetryStrategy.Timeout timeout = retryStrategy.newTimeout();
do {
assertDatabaseNotShutdown();
try {
outbound.send(leaderLocator.getLeader(), new RaftMessages.NewEntry.Request(me, operation));
progress.awaitReplication(timeout.getMillis());
timeout.increment();
} catch (InterruptedException e) {
progressTracker.abort(operation);
throw e;
} catch (NoLeaderFoundException e) {
log.debug("Could not replicate operation " + operation + " because no leader was found. Retrying.", e);
}
} while (!progress.isReplicated());
BiConsumer<Object, Throwable> cleanup = (ignored1, ignored2) -> sessionPool.releaseSession(session);
if (trackResult) {
progress.futureResult().whenComplete(cleanup);
} else {
cleanup.accept(null, null);
}
return progress.futureResult();
}
Aggregations