Search in sources :

Example 1 with OperationContext

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();
}
Also used : OperationContext(org.neo4j.causalclustering.core.replication.session.OperationContext) LifecycleAdapter(org.neo4j.kernel.lifecycle.LifecycleAdapter) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) Log(org.neo4j.logging.Log) Listener(org.neo4j.kernel.impl.util.Listener) LogProvider(org.neo4j.logging.LogProvider) LocalSessionPool(org.neo4j.causalclustering.core.replication.session.LocalSessionPool) Future(java.util.concurrent.Future) NoLeaderFoundException(org.neo4j.causalclustering.core.consensus.NoLeaderFoundException) BiConsumer(java.util.function.BiConsumer) MemberId(org.neo4j.causalclustering.identity.MemberId) Outbound(org.neo4j.causalclustering.messaging.Outbound) DatabaseShutdownException(org.neo4j.graphdb.DatabaseShutdownException) RaftMessages(org.neo4j.causalclustering.core.consensus.RaftMessages) OperationContext(org.neo4j.causalclustering.core.replication.session.OperationContext) LeaderLocator(org.neo4j.causalclustering.core.consensus.LeaderLocator) RetryStrategy(org.neo4j.causalclustering.helper.RetryStrategy) NoLeaderFoundException(org.neo4j.causalclustering.core.consensus.NoLeaderFoundException) RetryStrategy(org.neo4j.causalclustering.helper.RetryStrategy)

Aggregations

Future (java.util.concurrent.Future)1 BiConsumer (java.util.function.BiConsumer)1 LeaderLocator (org.neo4j.causalclustering.core.consensus.LeaderLocator)1 NoLeaderFoundException (org.neo4j.causalclustering.core.consensus.NoLeaderFoundException)1 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)1 LocalSessionPool (org.neo4j.causalclustering.core.replication.session.LocalSessionPool)1 OperationContext (org.neo4j.causalclustering.core.replication.session.OperationContext)1 RetryStrategy (org.neo4j.causalclustering.helper.RetryStrategy)1 MemberId (org.neo4j.causalclustering.identity.MemberId)1 Outbound (org.neo4j.causalclustering.messaging.Outbound)1 DatabaseShutdownException (org.neo4j.graphdb.DatabaseShutdownException)1 AvailabilityGuard (org.neo4j.kernel.AvailabilityGuard)1 Listener (org.neo4j.kernel.impl.util.Listener)1 LifecycleAdapter (org.neo4j.kernel.lifecycle.LifecycleAdapter)1 Log (org.neo4j.logging.Log)1 LogProvider (org.neo4j.logging.LogProvider)1