Documentation ¶
Index ¶
- Constants
- Variables
- func RegisterRaftServer(s grpc.ServiceRegistrar, srv RaftServer)
- type AppendEntryRequest
- func (*AppendEntryRequest) Descriptor() ([]byte, []int)deprecated
- func (x *AppendEntryRequest) GetEntry() []*LogEntry
- func (x *AppendEntryRequest) GetLeaderAddress() string
- func (x *AppendEntryRequest) GetLeaderCommit() int32
- func (x *AppendEntryRequest) GetPrevLogIndex() int32
- func (x *AppendEntryRequest) GetPrevLogTerm() int32
- func (x *AppendEntryRequest) GetTerm() int32
- func (*AppendEntryRequest) ProtoMessage()
- func (x *AppendEntryRequest) ProtoReflect() protoreflect.Message
- func (x *AppendEntryRequest) Reset()
- func (x *AppendEntryRequest) String() string
- type AppendEntryResponse
- func (*AppendEntryResponse) Descriptor() ([]byte, []int)deprecated
- func (x *AppendEntryResponse) GetErrorCode() ErrorCode
- func (x *AppendEntryResponse) GetMatchIndex() int32
- func (x *AppendEntryResponse) GetSuccess() bool
- func (x *AppendEntryResponse) GetTerm() int32
- func (*AppendEntryResponse) ProtoMessage()
- func (x *AppendEntryResponse) ProtoReflect() protoreflect.Message
- func (x *AppendEntryResponse) Reset()
- func (x *AppendEntryResponse) String() string
- type ErrorCode
- type LogEntry
- func (*LogEntry) Descriptor() ([]byte, []int)deprecated
- func (x *LogEntry) GetData() []byte
- func (x *LogEntry) GetIndex() int32
- func (x *LogEntry) GetTerm() int32
- func (*LogEntry) ProtoMessage()
- func (x *LogEntry) ProtoReflect() protoreflect.Message
- func (x *LogEntry) Reset()
- func (x *LogEntry) String() string
- type RaftClient
- type RaftServer
- type UnimplementedRaftServer
- type UnsafeRaftServer
Constants ¶
const (
Raft_AppendEntry_FullMethodName = "/raft.Raft/AppendEntry"
)
Variables ¶
var ( ErrorCode_name = map[int32]string{ 0: "SUCCESS", 1: "TERM_MISMATCH", 2: "LOG_INCONSISTENCY", 3: "LOG_DUPLICATE", } ErrorCode_value = map[string]int32{ "SUCCESS": 0, "TERM_MISMATCH": 1, "LOG_INCONSISTENCY": 2, "LOG_DUPLICATE": 3, } )
Enum value maps for ErrorCode.
var File_raft_proto protoreflect.FileDescriptor
var Raft_ServiceDesc = grpc.ServiceDesc{ ServiceName: "raft.Raft", HandlerType: (*RaftServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "AppendEntry", Handler: _Raft_AppendEntry_Handler, }, }, Streams: []grpc.StreamDesc{}, Metadata: "raft.proto", }
Raft_ServiceDesc is the grpc.ServiceDesc for Raft service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)
Functions ¶
func RegisterRaftServer ¶
func RegisterRaftServer(s grpc.ServiceRegistrar, srv RaftServer)
Types ¶
type AppendEntryRequest ¶
type AppendEntryRequest struct { Term int32 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"` // 领导者的任期号 LeaderAddress string `protobuf:"bytes,2,opt,name=leaderAddress,proto3" json:"leaderAddress,omitempty"` // 领导者的地址,以便于跟随者重定向请求 Entry []*LogEntry `protobuf:"bytes,3,rep,name=entry,proto3" json:"entry,omitempty"` // 需要复制的日志条目(即将要发送给其他服务器的日志条目) PrevLogIndex int32 `protobuf:"varint,4,opt,name=prevLogIndex,proto3" json:"prevLogIndex,omitempty"` // 领导者的 prevLogIndex PrevLogTerm int32 `protobuf:"varint,5,opt,name=prevLogTerm,proto3" json:"prevLogTerm,omitempty"` // 领导者的 prevLogTerm LeaderCommit int32 `protobuf:"varint,6,opt,name=leaderCommit,proto3" json:"leaderCommit,omitempty"` // 领导者的 commitIndex // contains filtered or unexported fields }
func (*AppendEntryRequest) Descriptor
deprecated
func (*AppendEntryRequest) Descriptor() ([]byte, []int)
Deprecated: Use AppendEntryRequest.ProtoReflect.Descriptor instead.
func (*AppendEntryRequest) GetEntry ¶
func (x *AppendEntryRequest) GetEntry() []*LogEntry
func (*AppendEntryRequest) GetLeaderAddress ¶
func (x *AppendEntryRequest) GetLeaderAddress() string
func (*AppendEntryRequest) GetLeaderCommit ¶
func (x *AppendEntryRequest) GetLeaderCommit() int32
func (*AppendEntryRequest) GetPrevLogIndex ¶
func (x *AppendEntryRequest) GetPrevLogIndex() int32
func (*AppendEntryRequest) GetPrevLogTerm ¶
func (x *AppendEntryRequest) GetPrevLogTerm() int32
func (*AppendEntryRequest) GetTerm ¶
func (x *AppendEntryRequest) GetTerm() int32
func (*AppendEntryRequest) ProtoMessage ¶
func (*AppendEntryRequest) ProtoMessage()
func (*AppendEntryRequest) ProtoReflect ¶
func (x *AppendEntryRequest) ProtoReflect() protoreflect.Message
func (*AppendEntryRequest) Reset ¶
func (x *AppendEntryRequest) Reset()
func (*AppendEntryRequest) String ¶
func (x *AppendEntryRequest) String() string
type AppendEntryResponse ¶
type AppendEntryResponse struct { Term int32 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"` // 当前的任期号,用于领导者更新自己 Success bool `protobuf:"varint,2,opt,name=success,proto3" json:"success,omitempty"` // 跟随者包含了匹配上 prevLogIndex 和 prevLogTerm 的日志时为真 MatchIndex int32 `protobuf:"varint,3,opt,name=matchIndex,proto3" json:"matchIndex,omitempty"` // 跟随者日志中最后一个条目的索引 ErrorCode ErrorCode `protobuf:"varint,4,opt,name=errorCode,proto3,enum=raft.ErrorCode" json:"errorCode,omitempty"` // 错误码 // contains filtered or unexported fields }
func (*AppendEntryResponse) Descriptor
deprecated
func (*AppendEntryResponse) Descriptor() ([]byte, []int)
Deprecated: Use AppendEntryResponse.ProtoReflect.Descriptor instead.
func (*AppendEntryResponse) GetErrorCode ¶
func (x *AppendEntryResponse) GetErrorCode() ErrorCode
func (*AppendEntryResponse) GetMatchIndex ¶
func (x *AppendEntryResponse) GetMatchIndex() int32
func (*AppendEntryResponse) GetSuccess ¶
func (x *AppendEntryResponse) GetSuccess() bool
func (*AppendEntryResponse) GetTerm ¶
func (x *AppendEntryResponse) GetTerm() int32
func (*AppendEntryResponse) ProtoMessage ¶
func (*AppendEntryResponse) ProtoMessage()
func (*AppendEntryResponse) ProtoReflect ¶
func (x *AppendEntryResponse) ProtoReflect() protoreflect.Message
func (*AppendEntryResponse) Reset ¶
func (x *AppendEntryResponse) Reset()
func (*AppendEntryResponse) String ¶
func (x *AppendEntryResponse) String() string
type ErrorCode ¶
type ErrorCode int32
func (ErrorCode) Descriptor ¶
func (ErrorCode) Descriptor() protoreflect.EnumDescriptor
func (ErrorCode) EnumDescriptor
deprecated
func (ErrorCode) Number ¶
func (x ErrorCode) Number() protoreflect.EnumNumber
func (ErrorCode) Type ¶
func (ErrorCode) Type() protoreflect.EnumType
type LogEntry ¶
type LogEntry struct { Term int32 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"` // 当前日志条目对应的任期号 Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 日志条目的数据 Index int32 `protobuf:"varint,3,opt,name=index,proto3" json:"index,omitempty"` // 日志条目的索引 // contains filtered or unexported fields }
func (*LogEntry) Descriptor
deprecated
func (*LogEntry) ProtoMessage ¶
func (*LogEntry) ProtoMessage()
func (*LogEntry) ProtoReflect ¶
func (x *LogEntry) ProtoReflect() protoreflect.Message
type RaftClient ¶
type RaftClient interface {
AppendEntry(ctx context.Context, in *AppendEntryRequest, opts ...grpc.CallOption) (*AppendEntryResponse, error)
}
RaftClient is the client API for Raft service.
For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
func NewRaftClient ¶
func NewRaftClient(cc grpc.ClientConnInterface) RaftClient
type RaftServer ¶
type RaftServer interface { AppendEntry(context.Context, *AppendEntryRequest) (*AppendEntryResponse, error) // contains filtered or unexported methods }
RaftServer is the server API for Raft service. All implementations must embed UnimplementedRaftServer for forward compatibility
type UnimplementedRaftServer ¶
type UnimplementedRaftServer struct { }
UnimplementedRaftServer must be embedded to have forward compatible implementations.
func (UnimplementedRaftServer) AppendEntry ¶
func (UnimplementedRaftServer) AppendEntry(context.Context, *AppendEntryRequest) (*AppendEntryResponse, error)
type UnsafeRaftServer ¶
type UnsafeRaftServer interface {
// contains filtered or unexported methods
}
UnsafeRaftServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to RaftServer will result in compilation errors.