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);
}
});
}
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);
}
Aggregations