Search in sources :

Example 1 with RaftError

use of org.apache.ignite.raft.jraft.error.RaftError in project ignite-3 by apache.

the class ItNodeTest method startChangePeersThread.

private Future<?> startChangePeersThread(ChangeArg arg) {
    Set<RaftError> expectedErrors = new HashSet<>();
    expectedErrors.add(RaftError.EBUSY);
    expectedErrors.add(RaftError.EPERM);
    expectedErrors.add(RaftError.ECATCHUP);
    ExecutorService executor = Executors.newSingleThreadExecutor();
    executors.add(executor);
    return Utils.runInThread(executor, () -> {
        try {
            while (!arg.stop) {
                arg.c.waitLeader();
                Node leader = arg.c.getLeader();
                if (leader == null)
                    continue;
                // select peers in random
                Configuration conf = new Configuration();
                if (arg.dontRemoveFirstPeer)
                    conf.addPeer(arg.peers.get(0));
                for (int i = 0; i < arg.peers.size(); i++) {
                    boolean select = ThreadLocalRandom.current().nextInt(64) < 32;
                    if (select && !conf.contains(arg.peers.get(i)))
                        conf.addPeer(arg.peers.get(i));
                }
                if (conf.isEmpty()) {
                    LOG.warn("No peer has been selected");
                    continue;
                }
                SynchronizedClosure done = new SynchronizedClosure();
                leader.changePeers(conf, done);
                done.await();
                assertTrue(done.getStatus().isOk() || expectedErrors.contains(done.getStatus().getRaftError()), done.getStatus().toString());
            }
        } catch (InterruptedException e) {
            LOG.error("ChangePeersThread is interrupted", e);
        }
    });
}
Also used : SynchronizedClosure(org.apache.ignite.raft.jraft.closure.SynchronizedClosure) Configuration(org.apache.ignite.raft.jraft.conf.Configuration) RaftError(org.apache.ignite.raft.jraft.error.RaftError) Node(org.apache.ignite.raft.jraft.Node) ExecutorService(java.util.concurrent.ExecutorService) Endpoint(org.apache.ignite.raft.jraft.util.Endpoint) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 2 with RaftError

use of org.apache.ignite.raft.jraft.error.RaftError in project ignite-3 by apache.

the class ActionRequestProcessor method sendRaftError.

/**
 * @param ctx    The context.
 * @param status The status.
 * @param node   Raft node.
 */
private void sendRaftError(RpcContext ctx, Status status, Node node) {
    RaftError raftError = status.getRaftError();
    Message response;
    if (raftError == RaftError.EPERM && node.getLeaderId() != null)
        response = RaftRpcFactory.DEFAULT.newResponse(node.getLeaderId().toString(), factory, RaftError.EPERM, status.getErrorMsg());
    else
        response = RaftRpcFactory.DEFAULT.newResponse(factory, raftError, status.getErrorMsg());
    ctx.sendResponse(response);
}
Also used : Message(org.apache.ignite.raft.jraft.rpc.Message) RaftError(org.apache.ignite.raft.jraft.error.RaftError)

Aggregations

RaftError (org.apache.ignite.raft.jraft.error.RaftError)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 ExecutorService (java.util.concurrent.ExecutorService)1 Node (org.apache.ignite.raft.jraft.Node)1 SynchronizedClosure (org.apache.ignite.raft.jraft.closure.SynchronizedClosure)1 Configuration (org.apache.ignite.raft.jraft.conf.Configuration)1 Message (org.apache.ignite.raft.jraft.rpc.Message)1 Endpoint (org.apache.ignite.raft.jraft.util.Endpoint)1