Search in sources :

Example 1 with FailoverClosureImpl

use of com.alibaba.nacos.core.distributed.raft.utils.FailoverClosureImpl in project nacos by alibaba.

the class JRaftServer method commit.

public CompletableFuture<Response> commit(final String group, final Message data, final CompletableFuture<Response> future) {
    LoggerUtils.printIfDebugEnabled(Loggers.RAFT, "data requested this time : {}", data);
    final RaftGroupTuple tuple = findTupleByGroup(group);
    if (tuple == null) {
        future.completeExceptionally(new IllegalArgumentException("No corresponding Raft Group found : " + group));
        return future;
    }
    FailoverClosureImpl closure = new FailoverClosureImpl(future);
    final Node node = tuple.node;
    if (node.isLeader()) {
        // The leader node directly applies this request
        applyOperation(node, data, closure);
    } else {
        // Forward to Leader for request processing
        invokeToLeader(group, data, rpcRequestTimeoutMs, closure);
    }
    return future;
}
Also used : FailoverClosureImpl(com.alibaba.nacos.core.distributed.raft.utils.FailoverClosureImpl) Node(com.alipay.sofa.jraft.Node)

Aggregations

FailoverClosureImpl (com.alibaba.nacos.core.distributed.raft.utils.FailoverClosureImpl)1 Node (com.alipay.sofa.jraft.Node)1