一、 总览
Raft的提供了三种类型的RPC。分别如下:
- RaftClientProtocolService:client与server之间的交互RPC,分为ordered和unordered,一种是有序的异步请求流、一种是无序的异步请求流。
- RaftServerProtocolService:ratis server之间的rpc操作。请求选票requestVote(论文里有详细定义)、开始leader选举、appendEntries(论文里有详细定义)、install snapshot、readIndex(论文里跟安全性相关的操作)。
- AdminProtocolService:用于ratis集群的管理操作。例如设置配置、转换leader、snapshot管理、group的列举&查询&管理等。
二、 Grpc.proto 文件源码
这个proto文件里定义了ratis里用的RPC。
// client与server交互的rpc
service RaftClientProtocolService {// A client-to-server stream RPC to ordered async requestsrpc ordered(stream ratis.common.RaftClientRequestProto)returns (stream ratis.common.RaftClientReplyProto) {}// A client-to-server stream RPC for unordered async requestsrpc unordered(stream ratis.common.RaftClientRequestProto)returns (stream ratis.common.RaftClientReplyProto) {}
}// server之间交互的rpc
service RaftServerProtocolService {rpc requestVote(ratis.common.RequestVoteRequestProto)returns(ratis.common.RequestVoteReplyProto) {}rpc startLeaderElection(ratis.common.StartLeaderElectionRequestProto)returns(ratis.common.StartLeaderElectionReplyProto) {}rpc appendEntries(stream ratis.common.AppendEntriesRequestProto)returns(stream ratis.common.AppendEntriesReplyProto) {}rpc installSnapshot(stream ratis.common.InstallSnapshotRequestProto)returns(stream ratis.common.InstallSnapshotReplyProto) {}rpc readIndex(ratis.common.ReadIndexRequestProto)returns(ratis.common.ReadIndexReplyProto) {}
}// 管理ratis集群的rpc
service AdminProtocolService {// A client-to-server RPC to set new raft configurationrpc setConfiguration(ratis.common.SetConfigurationRequestProto)returns(ratis.common.RaftClientReplyProto) {}rpc transferLeadership(ratis.common.TransferLeadershipRequestProto)returns(ratis.common.RaftClientReplyProto) {}// A client-to-server RPC to add a new grouprpc groupManagement(ratis.common.GroupManagementRequestProto)returns(ratis.common.RaftClientReplyProto) {}rpc snapshotManagement(ratis.common.SnapshotManagementRequestProto)returns(ratis.common.RaftClientReplyProto) {}rpc leaderElectionManagement(ratis.common.LeaderElectionManagementRequestProto)returns(ratis.common.RaftClientReplyProto) {}rpc groupList(ratis.common.GroupListRequestProto)returns(ratis.common.GroupListReplyProto) {}rpc groupInfo(ratis.common.GroupInfoRequestProto)returns(ratis.common.GroupInfoReplyProto) {}
}