use of org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse in project ignite-3 by apache.
the class RaftGroupServiceImpl method addLearners.
/**
* {@inheritDoc}
*/
@Override
public CompletableFuture<Void> addLearners(List<Peer> learners) {
Peer leader = this.leader;
if (leader == null)
return refreshLeader().thenCompose(res -> addLearners(learners));
List<String> lrns = learners.stream().map(p -> PeerId.fromPeer(p).toString()).collect(Collectors.toList());
AddLearnersRequest req = factory.addLearnersRequest().groupId(groupId).learnersList(lrns).build();
CompletableFuture<LearnersOpResponse> fut = new CompletableFuture<>();
sendWithRetry(leader, req, currentTimeMillis() + timeout, fut);
return fut.thenApply(resp -> {
this.learners = parsePeerList(resp.newLearnersList());
return null;
});
}
use of org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse in project ignite-3 by apache.
the class CliServiceImpl method processLearnersOpResponse.
private Status processLearnersOpResponse(final String groupId, final Message result, final String fmt, final Object... formatArgs) {
if (result instanceof LearnersOpResponse) {
final LearnersOpResponse resp = (LearnersOpResponse) result;
final Configuration oldConf = new Configuration();
for (final String peerIdStr : resp.oldLearnersList()) {
final PeerId oldPeer = new PeerId();
oldPeer.parse(peerIdStr);
oldConf.addLearner(oldPeer);
}
final Configuration newConf = new Configuration();
for (final String peerIdStr : resp.newLearnersList()) {
final PeerId newPeer = new PeerId();
newPeer.parse(peerIdStr);
newConf.addLearner(newPeer);
}
LOG.info("Learners of replication group {} changed from {} to {} after {}.", groupId, oldConf, newConf, String.format(fmt, formatArgs));
return Status.OK();
} else {
return statusFromResponse(result);
}
}
use of org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse in project ignite-3 by apache.
the class RaftGroupServiceImpl method removeLearners.
/**
* {@inheritDoc}
*/
@Override
public CompletableFuture<Void> removeLearners(List<Peer> learners) {
Peer leader = this.leader;
if (leader == null)
return refreshLeader().thenCompose(res -> removeLearners(learners));
List<String> lrns = learners.stream().map(p -> PeerId.fromPeer(p).toString()).collect(Collectors.toList());
RemoveLearnersRequest req = factory.removeLearnersRequest().groupId(groupId).learnersList(lrns).build();
CompletableFuture<LearnersOpResponse> fut = new CompletableFuture<>();
sendWithRetry(leader, req, currentTimeMillis() + timeout, fut);
return fut.thenApply(resp -> {
this.learners = parsePeerList(resp.newLearnersList());
return null;
});
}
use of org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse in project ignite-3 by apache.
the class RaftGroupServiceImpl method resetLearners.
/**
* {@inheritDoc}
*/
@Override
public CompletableFuture<Void> resetLearners(List<Peer> learners) {
Peer leader = this.leader;
if (leader == null)
return refreshLeader().thenCompose(res -> resetLearners(learners));
List<String> lrns = learners.stream().map(p -> PeerId.fromPeer(p).toString()).collect(Collectors.toList());
ResetLearnersRequest req = factory.resetLearnersRequest().groupId(groupId).learnersList(lrns).build();
CompletableFuture<LearnersOpResponse> fut = new CompletableFuture<>();
sendWithRetry(leader, req, currentTimeMillis() + timeout, fut);
return fut.thenApply(resp -> {
this.learners = parsePeerList(resp.newLearnersList());
return null;
});
}
use of org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse in project ignite-3 by apache.
the class AddLearnersRequestProcessor method processRequest0.
@Override
protected Message processRequest0(final CliRequestContext ctx, final AddLearnersRequest request, final IgniteCliRpcRequestClosure done) {
final List<PeerId> oldLearners = ctx.node.listLearners();
final List<PeerId> addingLearners = new ArrayList<>();
for (final String peerStr : request.learnersList()) {
final PeerId peer = new PeerId();
if (!peer.parse(peerStr)) {
return //
RaftRpcFactory.DEFAULT.newResponse(msgFactory(), RaftError.EINVAL, "Fail to parse peer id %s", peerStr);
}
addingLearners.add(peer);
}
LOG.info("Receive AddLearnersRequest to {} from {}, adding {}.", ctx.node.getNodeId(), done.getRpcCtx().getRemoteAddress(), addingLearners);
ctx.node.addLearners(addingLearners, status -> {
if (!status.isOk()) {
done.run(status);
} else {
List<String> oldLearnersList = new ArrayList<>();
List<String> newLearnersList = new ArrayList<>();
for (final PeerId peer : oldLearners) {
oldLearnersList.add(peer.toString());
newLearnersList.add(peer.toString());
}
for (final PeerId peer : addingLearners) {
if (!oldLearners.contains(peer)) {
newLearnersList.add(peer.toString());
}
}
LearnersOpResponse req = msgFactory().learnersOpResponse().oldLearnersList(oldLearnersList).newLearnersList(newLearnersList).build();
done.sendResponse(req);
}
});
return null;
}
Aggregations