Search in sources :

Example 1 with LearnersOpResponse

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;
    });
}
Also used : System.currentTimeMillis(java.lang.System.currentTimeMillis) IgniteException(org.apache.ignite.lang.IgniteException) AddPeerRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.AddPeerRequest) S(org.apache.ignite.internal.tostring.S) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) IgniteLogger(org.apache.ignite.lang.IgniteLogger) RaftMessagesFactory(org.apache.ignite.raft.jraft.RaftMessagesFactory) AddPeerResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.AddPeerResponse) TransferLeaderRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.TransferLeaderRequest) ArrayList(java.util.ArrayList) GetLeaderResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.GetLeaderResponse) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) RemoveLearnersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.RemoveLearnersRequest) ResetLearnersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.ResetLearnersRequest) RemovePeerRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.RemovePeerRequest) ActionResponse(org.apache.ignite.raft.jraft.rpc.ActionResponse) ChangePeersResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.ChangePeersResponse) ThreadLocalRandom.current(java.util.concurrent.ThreadLocalRandom.current) Collection(java.util.Collection) RpcRequests(org.apache.ignite.raft.jraft.rpc.RpcRequests) GetLeaderRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.GetLeaderRequest) NetworkMessage(org.apache.ignite.network.NetworkMessage) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Command(org.apache.ignite.raft.client.Command) ActionRequest(org.apache.ignite.raft.jraft.rpc.ActionRequest) GetPeersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.GetPeersRequest) NetworkAddress(org.apache.ignite.network.NetworkAddress) ReadCommand(org.apache.ignite.raft.client.ReadCommand) GetPeersResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.GetPeersResponse) TimeUnit(java.util.concurrent.TimeUnit) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) List(java.util.List) Peer(org.apache.ignite.raft.client.Peer) RemovePeerResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.RemovePeerResponse) SnapshotRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.SnapshotRequest) ClusterService(org.apache.ignite.network.ClusterService) LearnersOpResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) ChangePeersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.ChangePeersRequest) AddLearnersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.AddLearnersRequest) RaftError(org.apache.ignite.raft.jraft.error.RaftError) CompletableFuture(java.util.concurrent.CompletableFuture) LearnersOpResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse) Peer(org.apache.ignite.raft.client.Peer) AddLearnersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.AddLearnersRequest)

Example 2 with LearnersOpResponse

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);
    }
}
Also used : LearnersOpResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse) Configuration(org.apache.ignite.raft.jraft.conf.Configuration) PeerId(org.apache.ignite.raft.jraft.entity.PeerId)

Example 3 with LearnersOpResponse

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;
    });
}
Also used : System.currentTimeMillis(java.lang.System.currentTimeMillis) IgniteException(org.apache.ignite.lang.IgniteException) AddPeerRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.AddPeerRequest) S(org.apache.ignite.internal.tostring.S) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) IgniteLogger(org.apache.ignite.lang.IgniteLogger) RaftMessagesFactory(org.apache.ignite.raft.jraft.RaftMessagesFactory) AddPeerResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.AddPeerResponse) TransferLeaderRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.TransferLeaderRequest) ArrayList(java.util.ArrayList) GetLeaderResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.GetLeaderResponse) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) RemoveLearnersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.RemoveLearnersRequest) ResetLearnersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.ResetLearnersRequest) RemovePeerRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.RemovePeerRequest) ActionResponse(org.apache.ignite.raft.jraft.rpc.ActionResponse) ChangePeersResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.ChangePeersResponse) ThreadLocalRandom.current(java.util.concurrent.ThreadLocalRandom.current) Collection(java.util.Collection) RpcRequests(org.apache.ignite.raft.jraft.rpc.RpcRequests) GetLeaderRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.GetLeaderRequest) NetworkMessage(org.apache.ignite.network.NetworkMessage) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Command(org.apache.ignite.raft.client.Command) ActionRequest(org.apache.ignite.raft.jraft.rpc.ActionRequest) GetPeersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.GetPeersRequest) NetworkAddress(org.apache.ignite.network.NetworkAddress) ReadCommand(org.apache.ignite.raft.client.ReadCommand) GetPeersResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.GetPeersResponse) TimeUnit(java.util.concurrent.TimeUnit) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) List(java.util.List) Peer(org.apache.ignite.raft.client.Peer) RemovePeerResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.RemovePeerResponse) SnapshotRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.SnapshotRequest) ClusterService(org.apache.ignite.network.ClusterService) LearnersOpResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) ChangePeersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.ChangePeersRequest) AddLearnersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.AddLearnersRequest) RaftError(org.apache.ignite.raft.jraft.error.RaftError) RemoveLearnersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.RemoveLearnersRequest) CompletableFuture(java.util.concurrent.CompletableFuture) LearnersOpResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse) Peer(org.apache.ignite.raft.client.Peer)

Example 4 with LearnersOpResponse

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;
    });
}
Also used : System.currentTimeMillis(java.lang.System.currentTimeMillis) IgniteException(org.apache.ignite.lang.IgniteException) AddPeerRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.AddPeerRequest) S(org.apache.ignite.internal.tostring.S) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) IgniteLogger(org.apache.ignite.lang.IgniteLogger) RaftMessagesFactory(org.apache.ignite.raft.jraft.RaftMessagesFactory) AddPeerResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.AddPeerResponse) TransferLeaderRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.TransferLeaderRequest) ArrayList(java.util.ArrayList) GetLeaderResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.GetLeaderResponse) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) RemoveLearnersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.RemoveLearnersRequest) ResetLearnersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.ResetLearnersRequest) RemovePeerRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.RemovePeerRequest) ActionResponse(org.apache.ignite.raft.jraft.rpc.ActionResponse) ChangePeersResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.ChangePeersResponse) ThreadLocalRandom.current(java.util.concurrent.ThreadLocalRandom.current) Collection(java.util.Collection) RpcRequests(org.apache.ignite.raft.jraft.rpc.RpcRequests) GetLeaderRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.GetLeaderRequest) NetworkMessage(org.apache.ignite.network.NetworkMessage) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Command(org.apache.ignite.raft.client.Command) ActionRequest(org.apache.ignite.raft.jraft.rpc.ActionRequest) GetPeersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.GetPeersRequest) NetworkAddress(org.apache.ignite.network.NetworkAddress) ReadCommand(org.apache.ignite.raft.client.ReadCommand) GetPeersResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.GetPeersResponse) TimeUnit(java.util.concurrent.TimeUnit) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) List(java.util.List) Peer(org.apache.ignite.raft.client.Peer) RemovePeerResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.RemovePeerResponse) SnapshotRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.SnapshotRequest) ClusterService(org.apache.ignite.network.ClusterService) LearnersOpResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) ChangePeersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.ChangePeersRequest) AddLearnersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.AddLearnersRequest) RaftError(org.apache.ignite.raft.jraft.error.RaftError) CompletableFuture(java.util.concurrent.CompletableFuture) LearnersOpResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse) Peer(org.apache.ignite.raft.client.Peer) ResetLearnersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.ResetLearnersRequest)

Example 5 with LearnersOpResponse

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;
}
Also used : LearnersOpResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse) ArrayList(java.util.ArrayList) PeerId(org.apache.ignite.raft.jraft.entity.PeerId)

Aggregations

PeerId (org.apache.ignite.raft.jraft.entity.PeerId)7 LearnersOpResponse (org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse)7 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)3 System.currentTimeMillis (java.lang.System.currentTimeMillis)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 List (java.util.List)3 Objects.requireNonNull (java.util.Objects.requireNonNull)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 ThreadLocalRandom.current (java.util.concurrent.ThreadLocalRandom.current)3 TimeUnit (java.util.concurrent.TimeUnit)3 TimeoutException (java.util.concurrent.TimeoutException)3 BiConsumer (java.util.function.BiConsumer)3 Collectors (java.util.stream.Collectors)3 S (org.apache.ignite.internal.tostring.S)3 IgniteException (org.apache.ignite.lang.IgniteException)3 IgniteLogger (org.apache.ignite.lang.IgniteLogger)3 ClusterService (org.apache.ignite.network.ClusterService)3