Search in sources :

Example 1 with GroupInfoReply

use of org.apache.ratis.protocol.GroupInfoReply in project incubator-ratis by apache.

the class GroupManagementImpl method info.

@Override
public GroupInfoReply info(RaftGroupId groupId) throws IOException {
    final RaftGroupId gid = groupId != null ? groupId : client.getGroupId();
    final long callId = CallId.getAndIncrement();
    final RaftClientReply reply = client.io().sendRequestWithRetry(() -> new GroupInfoRequest(client.getId(), server, gid, callId));
    Preconditions.assertTrue(reply instanceof GroupInfoReply, () -> "Unexpected reply: " + reply);
    return (GroupInfoReply) reply;
}
Also used : GroupInfoRequest(org.apache.ratis.protocol.GroupInfoRequest) RaftClientReply(org.apache.ratis.protocol.RaftClientReply) RaftGroupId(org.apache.ratis.protocol.RaftGroupId) GroupInfoReply(org.apache.ratis.protocol.GroupInfoReply)

Example 2 with GroupInfoReply

use of org.apache.ratis.protocol.GroupInfoReply in project incubator-ratis by apache.

the class GroupInfoCommand method run.

@Override
public int run(CommandLine cl) throws IOException {
    super.run(cl);
    println("group id: " + getRaftGroup().getGroupId().getUuid());
    final GroupInfoReply reply = getGroupInfoReply();
    RaftProtos.RaftPeerProto leader = getLeader(reply.getRoleInfoProto());
    if (leader == null) {
        println("leader not found");
    } else {
        printf("leader info: %s(%s)%n%n", leader.getId().toStringUtf8(), leader.getAddress());
    }
    println(reply.getCommitInfos());
    return 0;
}
Also used : RaftProtos(org.apache.ratis.proto.RaftProtos) GroupInfoReply(org.apache.ratis.protocol.GroupInfoReply)

Example 3 with GroupInfoReply

use of org.apache.ratis.protocol.GroupInfoReply in project incubator-ratis by apache.

the class NettyRpcService method handle.

RaftNettyServerReplyProto handle(RaftNettyServerRequestProto proto) {
    RaftRpcRequestProto rpcRequest = null;
    try {
        switch(proto.getRaftNettyServerRequestCase()) {
            case REQUESTVOTEREQUEST:
                final RequestVoteRequestProto request = proto.getRequestVoteRequest();
                rpcRequest = request.getServerRequest();
                final RequestVoteReplyProto reply = server.requestVote(request);
                return RaftNettyServerReplyProto.newBuilder().setRequestVoteReply(reply).build();
            case TRANSFERLEADERSHIPREQUEST:
                final TransferLeadershipRequestProto transferLeadershipRequest = proto.getTransferLeadershipRequest();
                rpcRequest = transferLeadershipRequest.getRpcRequest();
                final RaftClientReply transferLeadershipReply = server.transferLeadership(ClientProtoUtils.toTransferLeadershipRequest(transferLeadershipRequest));
                return RaftNettyServerReplyProto.newBuilder().setRaftClientReply(ClientProtoUtils.toRaftClientReplyProto(transferLeadershipReply)).build();
            case STARTLEADERELECTIONREQUEST:
                final StartLeaderElectionRequestProto startLeaderElectionRequest = proto.getStartLeaderElectionRequest();
                rpcRequest = startLeaderElectionRequest.getServerRequest();
                final StartLeaderElectionReplyProto startLeaderElectionReply = server.startLeaderElection(startLeaderElectionRequest);
                return RaftNettyServerReplyProto.newBuilder().setStartLeaderElectionReply(startLeaderElectionReply).build();
            case SNAPSHOTMANAGEMENTREQUEST:
                final SnapshotManagementRequestProto snapshotManagementRequest = proto.getSnapshotManagementRequest();
                rpcRequest = snapshotManagementRequest.getRpcRequest();
                final RaftClientReply snapshotManagementReply = server.snapshotManagement(ClientProtoUtils.toSnapshotManagementRequest(snapshotManagementRequest));
                return RaftNettyServerReplyProto.newBuilder().setRaftClientReply(ClientProtoUtils.toRaftClientReplyProto(snapshotManagementReply)).build();
            case LEADERELECTIONMANAGEMENTREQUEST:
                final LeaderElectionManagementRequestProto leaderElectionManagementRequest = proto.getLeaderElectionManagementRequest();
                rpcRequest = leaderElectionManagementRequest.getRpcRequest();
                final RaftClientReply leaderElectionManagementReply = server.leaderElectionManagement(ClientProtoUtils.toLeaderElectionManagementRequest(leaderElectionManagementRequest));
                return RaftNettyServerReplyProto.newBuilder().setRaftClientReply(ClientProtoUtils.toRaftClientReplyProto(leaderElectionManagementReply)).build();
            case APPENDENTRIESREQUEST:
                final AppendEntriesRequestProto appendEntriesRequest = proto.getAppendEntriesRequest();
                rpcRequest = appendEntriesRequest.getServerRequest();
                final AppendEntriesReplyProto appendEntriesReply = server.appendEntries(appendEntriesRequest);
                return RaftNettyServerReplyProto.newBuilder().setAppendEntriesReply(appendEntriesReply).build();
            case INSTALLSNAPSHOTREQUEST:
                final InstallSnapshotRequestProto installSnapshotRequest = proto.getInstallSnapshotRequest();
                rpcRequest = installSnapshotRequest.getServerRequest();
                final InstallSnapshotReplyProto installSnapshotReply = server.installSnapshot(installSnapshotRequest);
                return RaftNettyServerReplyProto.newBuilder().setInstallSnapshotReply(installSnapshotReply).build();
            case RAFTCLIENTREQUEST:
                final RaftClientRequestProto raftClientRequest = proto.getRaftClientRequest();
                rpcRequest = raftClientRequest.getRpcRequest();
                final RaftClientReply raftClientReply = server.submitClientRequest(ClientProtoUtils.toRaftClientRequest(raftClientRequest));
                return RaftNettyServerReplyProto.newBuilder().setRaftClientReply(ClientProtoUtils.toRaftClientReplyProto(raftClientReply)).build();
            case SETCONFIGURATIONREQUEST:
                final SetConfigurationRequestProto configurationRequest = proto.getSetConfigurationRequest();
                rpcRequest = configurationRequest.getRpcRequest();
                final RaftClientReply configurationReply = server.setConfiguration(ClientProtoUtils.toSetConfigurationRequest(configurationRequest));
                return RaftNettyServerReplyProto.newBuilder().setRaftClientReply(ClientProtoUtils.toRaftClientReplyProto(configurationReply)).build();
            case GROUPMANAGEMENTREQUEST:
                final GroupManagementRequestProto groupManagementRequest = proto.getGroupManagementRequest();
                rpcRequest = groupManagementRequest.getRpcRequest();
                final RaftClientReply groupManagementReply = server.groupManagement(ClientProtoUtils.toGroupManagementRequest(groupManagementRequest));
                return RaftNettyServerReplyProto.newBuilder().setRaftClientReply(ClientProtoUtils.toRaftClientReplyProto(groupManagementReply)).build();
            case GROUPLISTREQUEST:
                final GroupListRequestProto groupListRequest = proto.getGroupListRequest();
                rpcRequest = groupListRequest.getRpcRequest();
                final GroupListReply groupListReply = server.getGroupList(ClientProtoUtils.toGroupListRequest(groupListRequest));
                return RaftNettyServerReplyProto.newBuilder().setGroupListReply(ClientProtoUtils.toGroupListReplyProto(groupListReply)).build();
            case GROUPINFOREQUEST:
                final GroupInfoRequestProto groupInfoRequest = proto.getGroupInfoRequest();
                rpcRequest = groupInfoRequest.getRpcRequest();
                final GroupInfoReply groupInfoReply = server.getGroupInfo(ClientProtoUtils.toGroupInfoRequest(groupInfoRequest));
                return RaftNettyServerReplyProto.newBuilder().setGroupInfoReply(ClientProtoUtils.toGroupInfoReplyProto(groupInfoReply)).build();
            case RAFTNETTYSERVERREQUEST_NOT_SET:
                throw new IllegalArgumentException("Request case not set in proto: " + proto.getRaftNettyServerRequestCase());
            default:
                throw new UnsupportedOperationException("Request case not supported: " + proto.getRaftNettyServerRequestCase());
        }
    } catch (IOException ioe) {
        return toRaftNettyServerReplyProto(Objects.requireNonNull(rpcRequest, "rpcRequest = null"), ioe);
    }
}
Also used : GroupListReply(org.apache.ratis.protocol.GroupListReply) IOException(java.io.IOException) RaftClientReply(org.apache.ratis.protocol.RaftClientReply) GroupInfoReply(org.apache.ratis.protocol.GroupInfoReply)

Example 4 with GroupInfoReply

use of org.apache.ratis.protocol.GroupInfoReply in project alluxio by Alluxio.

the class RaftJournalSystem method getQuorumServerInfoList.

/**
 * Used to get information of internal RAFT quorum.
 *
 * @return list of information for participating servers in RAFT quorum
 */
public synchronized List<QuorumServerInfo> getQuorumServerInfoList() throws IOException {
    List<QuorumServerInfo> quorumMemberStateList = new LinkedList<>();
    GroupInfoReply groupInfo = getGroupInfo();
    if (groupInfo == null) {
        throw new UnavailableException("Cannot get raft group info");
    }
    if (groupInfo.getException() != null) {
        throw groupInfo.getException();
    }
    RaftProtos.RoleInfoProto roleInfo = groupInfo.getRoleInfoProto();
    if (roleInfo == null) {
        throw new UnavailableException("Cannot get server role info");
    }
    RaftProtos.LeaderInfoProto leaderInfo = roleInfo.getLeaderInfo();
    if (leaderInfo == null) {
        throw new UnavailableException("Cannot get server leader info");
    }
    for (RaftProtos.ServerRpcProto member : leaderInfo.getFollowerInfoList()) {
        HostAndPort hp = HostAndPort.fromString(member.getId().getAddress());
        NetAddress memberAddress = NetAddress.newBuilder().setHost(hp.getHost()).setRpcPort(hp.getPort()).build();
        quorumMemberStateList.add(QuorumServerInfo.newBuilder().setIsLeader(false).setPriority(member.getId().getPriority()).setServerAddress(memberAddress).setServerState(member.getLastRpcElapsedTimeMs() > mConf.getMaxElectionTimeoutMs() ? QuorumServerState.UNAVAILABLE : QuorumServerState.AVAILABLE).build());
    }
    InetSocketAddress localAddress = mConf.getLocalAddress();
    NetAddress self = NetAddress.newBuilder().setHost(localAddress.getHostString()).setRpcPort(localAddress.getPort()).build();
    quorumMemberStateList.add(QuorumServerInfo.newBuilder().setIsLeader(true).setPriority(roleInfo.getSelf().getPriority()).setServerAddress(self).setServerState(QuorumServerState.AVAILABLE).build());
    quorumMemberStateList.sort(Comparator.comparing(info -> info.getServerAddress().toString()));
    return quorumMemberStateList;
}
Also used : Arrays(java.util.Arrays) GroupInfoReply(org.apache.ratis.protocol.GroupInfoReply) RaftGroup(org.apache.ratis.protocol.RaftGroup) LeaderNotReadyException(org.apache.ratis.protocol.exceptions.LeaderNotReadyException) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) PropertyKey(alluxio.conf.PropertyKey) GrpcService(alluxio.grpc.GrpcService) LogUtils(alluxio.util.LogUtils) NetUtils(org.apache.ratis.util.NetUtils) JournalQueryRequest(alluxio.grpc.JournalQueryRequest) MetricKey(alluxio.metrics.MetricKey) Map(java.util.Map) RaftConfigKeys(org.apache.ratis.RaftConfigKeys) CancelledException(alluxio.exception.status.CancelledException) UnsafeByteOperations(org.apache.ratis.thirdparty.com.google.protobuf.UnsafeByteOperations) QuorumServerInfo(alluxio.grpc.QuorumServerInfo) ServerConfiguration(alluxio.conf.ServerConfiguration) RaftPeer(org.apache.ratis.protocol.RaftPeer) RetryPolicy(org.apache.ratis.retry.RetryPolicy) Master(alluxio.master.Master) Collection(java.util.Collection) AbstractJournalSystem(alluxio.master.journal.AbstractJournalSystem) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) SupportedRpcType(org.apache.ratis.rpc.SupportedRpcType) CompletionException(java.util.concurrent.CompletionException) ThreadSafe(javax.annotation.concurrent.ThreadSafe) UUID(java.util.UUID) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) List(java.util.List) ClientId(org.apache.ratis.protocol.ClientId) RaftClientReply(org.apache.ratis.protocol.RaftClientReply) RaftProperties(org.apache.ratis.conf.RaftProperties) ServiceType(alluxio.grpc.ServiceType) ExponentialBackoffRetry(org.apache.ratis.retry.ExponentialBackoffRetry) Optional(java.util.Optional) PrimarySelector(alluxio.master.PrimarySelector) RatisDropwizardExports(alluxio.metrics.sink.RatisDropwizardExports) AccessDeniedException(java.nio.file.AccessDeniedException) RaftClientConfigKeys(org.apache.ratis.client.RaftClientConfigKeys) UnavailableException(alluxio.exception.status.UnavailableException) TimeDuration(org.apache.ratis.util.TimeDuration) AsyncJournalWriter(alluxio.master.journal.AsyncJournalWriter) GroupInfoRequest(org.apache.ratis.protocol.GroupInfoRequest) CatchupFuture(alluxio.master.journal.CatchupFuture) SetConfigurationRequest(org.apache.ratis.protocol.SetConfigurationRequest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) JournalEntry(alluxio.proto.journal.Journal.JournalEntry) WaitForOptions(alluxio.util.WaitForOptions) RaftGroupId(org.apache.ratis.protocol.RaftGroupId) AddQuorumServerRequest(alluxio.grpc.AddQuorumServerRequest) Message(org.apache.ratis.protocol.Message) OptionalLong(java.util.OptionalLong) Constants(alluxio.Constants) QuorumServerState(alluxio.grpc.QuorumServerState) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) MetricsSystem(alluxio.metrics.MetricsSystem) LinkedList(java.util.LinkedList) SizeInBytes(org.apache.ratis.util.SizeInBytes) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) NetAddress(alluxio.grpc.NetAddress) Iterator(java.util.Iterator) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) RaftServerConfigKeys(org.apache.ratis.server.RaftServerConfigKeys) ExceptionMessage(alluxio.exception.ExceptionMessage) RaftProtos(org.apache.ratis.proto.RaftProtos) FileUtils(org.apache.commons.io.FileUtils) GrpcConfigKeys(org.apache.ratis.grpc.GrpcConfigKeys) RaftClientRequest(org.apache.ratis.protocol.RaftClientRequest) IOException(java.io.IOException) TransferLeaderMessage(alluxio.grpc.TransferLeaderMessage) HostAndPort(com.google.common.net.HostAndPort) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Parameters(org.apache.ratis.conf.Parameters) AtomicLong(java.util.concurrent.atomic.AtomicLong) LifeCycle(org.apache.ratis.util.LifeCycle) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) RaftServer(org.apache.ratis.server.RaftServer) RaftClient(org.apache.ratis.client.RaftClient) Comparator(java.util.Comparator) Journal(alluxio.master.journal.Journal) Collections(java.util.Collections) CommonUtils(alluxio.util.CommonUtils) InetSocketAddress(java.net.InetSocketAddress) UnavailableException(alluxio.exception.status.UnavailableException) QuorumServerInfo(alluxio.grpc.QuorumServerInfo) LinkedList(java.util.LinkedList) NetAddress(alluxio.grpc.NetAddress) HostAndPort(com.google.common.net.HostAndPort) RaftProtos(org.apache.ratis.proto.RaftProtos) GroupInfoReply(org.apache.ratis.protocol.GroupInfoReply)

Aggregations

GroupInfoReply (org.apache.ratis.protocol.GroupInfoReply)3 IOException (java.io.IOException)2 RaftClientReply (org.apache.ratis.protocol.RaftClientReply)2 Constants (alluxio.Constants)1 PropertyKey (alluxio.conf.PropertyKey)1 ServerConfiguration (alluxio.conf.ServerConfiguration)1 ExceptionMessage (alluxio.exception.ExceptionMessage)1 CancelledException (alluxio.exception.status.CancelledException)1 UnavailableException (alluxio.exception.status.UnavailableException)1 AddQuorumServerRequest (alluxio.grpc.AddQuorumServerRequest)1 GrpcService (alluxio.grpc.GrpcService)1 JournalQueryRequest (alluxio.grpc.JournalQueryRequest)1 NetAddress (alluxio.grpc.NetAddress)1 QuorumServerInfo (alluxio.grpc.QuorumServerInfo)1 QuorumServerState (alluxio.grpc.QuorumServerState)1 ServiceType (alluxio.grpc.ServiceType)1 TransferLeaderMessage (alluxio.grpc.TransferLeaderMessage)1 Master (alluxio.master.Master)1 PrimarySelector (alluxio.master.PrimarySelector)1 AbstractJournalSystem (alluxio.master.journal.AbstractJournalSystem)1