Documentation
¶
Index ¶
- func Get(key string) ([]byte, error)
- func Put(key string, value []byte) error
- func RaftStart(params *Params)
- func RegisterRaftServer(s *grpc.Server, srv RaftServer)
- type Data
- func (*Data) Descriptor() ([]byte, []int)
- func (m *Data) GetHash() string
- func (m *Data) GetKey() string
- func (m *Data) GetVersion() int32
- func (*Data) ProtoMessage()
- func (m *Data) Reset()
- func (m *Data) String() string
- func (m *Data) XXX_DiscardUnknown()
- func (m *Data) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Data) XXX_Merge(src proto.Message)
- func (m *Data) XXX_Size() int
- func (m *Data) XXX_Unmarshal(b []byte) error
- type Log
- type Node
- func (*Node) Descriptor() ([]byte, []int)
- func (m *Node) GetId() string
- func (m *Node) GetUnusualTimes() int32
- func (m *Node) GetUrl() string
- func (*Node) ProtoMessage()
- func (m *Node) Reset()
- func (m *Node) String() string
- func (m *Node) XXX_DiscardUnknown()
- func (m *Node) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Node) XXX_Merge(src proto.Message)
- func (m *Node) XXX_Size() int
- func (m *Node) XXX_Unmarshal(b []byte) error
- type Nodes
- type Params
- type Raft
- type RaftClient
- type RaftServer
- type ReqData
- func (*ReqData) Descriptor() ([]byte, []int)
- func (m *ReqData) GetKey() string
- func (*ReqData) ProtoMessage()
- func (m *ReqData) Reset()
- func (m *ReqData) String() string
- func (m *ReqData) XXX_DiscardUnknown()
- func (m *ReqData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *ReqData) XXX_Merge(src proto.Message)
- func (m *ReqData) XXX_Size() int
- func (m *ReqData) XXX_Unmarshal(b []byte) error
- type ReqDataList
- func (*ReqDataList) Descriptor() ([]byte, []int)
- func (*ReqDataList) ProtoMessage()
- func (m *ReqDataList) Reset()
- func (m *ReqDataList) String() string
- func (m *ReqDataList) XXX_DiscardUnknown()
- func (m *ReqDataList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *ReqDataList) XXX_Merge(src proto.Message)
- func (m *ReqDataList) XXX_Size() int
- func (m *ReqDataList) XXX_Unmarshal(b []byte) error
- type ReqHeartBeat
- func (*ReqHeartBeat) Descriptor() ([]byte, []int)
- func (m *ReqHeartBeat) GetHash() string
- func (m *ReqHeartBeat) GetId() string
- func (m *ReqHeartBeat) GetTerm() int32
- func (m *ReqHeartBeat) GetUrl() string
- func (*ReqHeartBeat) ProtoMessage()
- func (m *ReqHeartBeat) Reset()
- func (m *ReqHeartBeat) String() string
- func (m *ReqHeartBeat) XXX_DiscardUnknown()
- func (m *ReqHeartBeat) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *ReqHeartBeat) XXX_Merge(src proto.Message)
- func (m *ReqHeartBeat) XXX_Size() int
- func (m *ReqHeartBeat) XXX_Unmarshal(b []byte) error
- type ReqNodeList
- func (*ReqNodeList) Descriptor() ([]byte, []int)
- func (m *ReqNodeList) GetNodes() []*Node
- func (*ReqNodeList) ProtoMessage()
- func (m *ReqNodeList) Reset()
- func (m *ReqNodeList) String() string
- func (m *ReqNodeList) XXX_DiscardUnknown()
- func (m *ReqNodeList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *ReqNodeList) XXX_Merge(src proto.Message)
- func (m *ReqNodeList) XXX_Size() int
- func (m *ReqNodeList) XXX_Unmarshal(b []byte) error
- type ReqSyncData
- func (*ReqSyncData) Descriptor() ([]byte, []int)
- func (m *ReqSyncData) GetKey() string
- func (m *ReqSyncData) GetLeaderId() string
- func (m *ReqSyncData) GetLeaderUrl() string
- func (m *ReqSyncData) GetTerm() int32
- func (m *ReqSyncData) GetValue() []byte
- func (m *ReqSyncData) GetVersion() int32
- func (*ReqSyncData) ProtoMessage()
- func (m *ReqSyncData) Reset()
- func (m *ReqSyncData) String() string
- func (m *ReqSyncData) XXX_DiscardUnknown()
- func (m *ReqSyncData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *ReqSyncData) XXX_Merge(src proto.Message)
- func (m *ReqSyncData) XXX_Size() int
- func (m *ReqSyncData) XXX_Unmarshal(b []byte) error
- type ReqVote
- func (*ReqVote) Descriptor() ([]byte, []int)
- func (m *ReqVote) GetId() string
- func (m *ReqVote) GetTerm() int32
- func (m *ReqVote) GetTimestamp() int64
- func (m *ReqVote) GetUrl() string
- func (*ReqVote) ProtoMessage()
- func (m *ReqVote) Reset()
- func (m *ReqVote) String() string
- func (m *ReqVote) XXX_DiscardUnknown()
- func (m *ReqVote) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *ReqVote) XXX_Merge(src proto.Message)
- func (m *ReqVote) XXX_Size() int
- func (m *ReqVote) XXX_Unmarshal(b []byte) error
- type RespData
- func (*RespData) Descriptor() ([]byte, []int)
- func (m *RespData) GetValue() []byte
- func (*RespData) ProtoMessage()
- func (m *RespData) Reset()
- func (m *RespData) String() string
- func (m *RespData) XXX_DiscardUnknown()
- func (m *RespData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *RespData) XXX_Merge(src proto.Message)
- func (m *RespData) XXX_Size() int
- func (m *RespData) XXX_Unmarshal(b []byte) error
- type RespDataList
- func (*RespDataList) Descriptor() ([]byte, []int)
- func (m *RespDataList) GetDataArr() []*Data
- func (*RespDataList) ProtoMessage()
- func (m *RespDataList) Reset()
- func (m *RespDataList) String() string
- func (m *RespDataList) XXX_DiscardUnknown()
- func (m *RespDataList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *RespDataList) XXX_Merge(src proto.Message)
- func (m *RespDataList) XXX_Size() int
- func (m *RespDataList) XXX_Unmarshal(b []byte) error
- type RespHeartBeat
- func (*RespHeartBeat) Descriptor() ([]byte, []int)
- func (*RespHeartBeat) ProtoMessage()
- func (m *RespHeartBeat) Reset()
- func (m *RespHeartBeat) String() string
- func (m *RespHeartBeat) XXX_DiscardUnknown()
- func (m *RespHeartBeat) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *RespHeartBeat) XXX_Merge(src proto.Message)
- func (m *RespHeartBeat) XXX_Size() int
- func (m *RespHeartBeat) XXX_Unmarshal(b []byte) error
- type RespNodeList
- func (*RespNodeList) Descriptor() ([]byte, []int)
- func (m *RespNodeList) GetNodes() []*Node
- func (*RespNodeList) ProtoMessage()
- func (m *RespNodeList) Reset()
- func (m *RespNodeList) String() string
- func (m *RespNodeList) XXX_DiscardUnknown()
- func (m *RespNodeList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *RespNodeList) XXX_Merge(src proto.Message)
- func (m *RespNodeList) XXX_Size() int
- func (m *RespNodeList) XXX_Unmarshal(b []byte) error
- type RespSyncData
- func (*RespSyncData) Descriptor() ([]byte, []int)
- func (m *RespSyncData) GetSuccess() bool
- func (m *RespSyncData) GetTerm() int32
- func (*RespSyncData) ProtoMessage()
- func (m *RespSyncData) Reset()
- func (m *RespSyncData) String() string
- func (m *RespSyncData) XXX_DiscardUnknown()
- func (m *RespSyncData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *RespSyncData) XXX_Merge(src proto.Message)
- func (m *RespSyncData) XXX_Size() int
- func (m *RespSyncData) XXX_Unmarshal(b []byte) error
- type RespVote
- func (*RespVote) Descriptor() ([]byte, []int)
- func (m *RespVote) GetVoteGranted() bool
- func (*RespVote) ProtoMessage()
- func (m *RespVote) Reset()
- func (m *RespVote) String() string
- func (m *RespVote) XXX_DiscardUnknown()
- func (m *RespVote) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *RespVote) XXX_Merge(src proto.Message)
- func (m *RespVote) XXX_Size() int
- func (m *RespVote) XXX_Unmarshal(b []byte) error
- type RoleStatus
- type Server
- func (s *Server) Data(_ context.Context, req *ReqData) (resp *RespData, err error)
- func (s *Server) DataList(_ context.Context, _ *ReqDataList) (resp *RespDataList, err error)
- func (s *Server) Heartbeat(ctx context.Context, req *ReqHeartBeat) (resp *RespHeartBeat, err error)
- func (s *Server) NodeList(_ context.Context, req *ReqNodeList) (resp *RespNodeList, err error)
- func (s *Server) SyncData(_ context.Context, req *ReqSyncData) (resp *RespSyncData, err error)
- func (s *Server) Vote(_ context.Context, req *ReqVote) (resp *RespVote, err error)
- type UnimplementedRaftServer
- func (*UnimplementedRaftServer) Data(ctx context.Context, req *ReqData) (*RespData, error)
- func (*UnimplementedRaftServer) DataList(ctx context.Context, req *ReqDataList) (*RespDataList, error)
- func (*UnimplementedRaftServer) Heartbeat(ctx context.Context, req *ReqHeartBeat) (*RespHeartBeat, error)
- func (*UnimplementedRaftServer) NodeList(ctx context.Context, req *ReqNodeList) (*RespNodeList, error)
- func (*UnimplementedRaftServer) SyncData(ctx context.Context, req *ReqSyncData) (*RespSyncData, error)
- func (*UnimplementedRaftServer) Vote(ctx context.Context, req *ReqVote) (*RespVote, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RaftStart ¶
func RaftStart(params *Params)
RaftStart 启动且只能启动一次Raft服务
node 自身节点信息
nodes 集群节点信息
timeCheck raft心跳定时检查超时时间
timeout raft心跳定时/超时ms
func RegisterRaftServer ¶
func RegisterRaftServer(s *grpc.Server, srv RaftServer)
Types ¶
type Data ¶
type Data struct {
// 数据key
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
// 数据hash
Hash string `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"`
// 当前配置版本 index 递增
Version int32 `protobuf:"varint,3,opt,name=version,proto3" json:"version,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
data 匹配数据对象
func (*Data) Descriptor ¶
func (*Data) GetVersion ¶
func (*Data) ProtoMessage ¶
func (*Data) ProtoMessage()
func (*Data) XXX_DiscardUnknown ¶
func (m *Data) XXX_DiscardUnknown()
func (*Data) XXX_Unmarshal ¶
type Log ¶
type Log struct {
Dir string // 日志文件目录
FileMaxSize int // 每个日志文件保存的最大尺寸 单位:M
FileMaxAge int // 文件最多保存多少天
Utc bool // CST & UTC 时间
Level string // 日志级别(debug/info/warn/error/panic/fatal)
Production bool // 是否生产环境,在生产环境下控制台不会输出任何日志
}
Log 日志属性
type Node ¶
type Node struct {
// 节点ID
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
// 节点地址
Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"`
// 节点异常次数,异常次数到达或超过3次,则表示该节点异常
UnusualTimes int32 `protobuf:"varint,3,opt,name=unusualTimes,proto3" json:"unusualTimes,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
node 节点信息
func (*Node) Descriptor ¶
func (*Node) GetUnusualTimes ¶
func (*Node) ProtoMessage ¶
func (*Node) ProtoMessage()
func (*Node) XXX_DiscardUnknown ¶
func (m *Node) XXX_DiscardUnknown()
func (*Node) XXX_Unmarshal ¶
type Params ¶
type Params struct {
Node *Node // 自身节点信息
Nodes []*Node // 集群节点信息
TimeHeartbeat int64 // raft心跳定时ms
TimeCheckReq int64 // raft心跳定时检查超时时间ms
TimeoutReq int64 // raft心跳定时ms
PortReq string // raft服务开放端口号,默认19877
Log *Log // 日志
}
Params 启动参数
type Raft ¶
type Raft struct {
// contains filtered or unexported fields
}
Raft 接收客户端提交的同步内容,被封装在自定义的方法中
也返回客户端期望的同步结果及从其他节点同步过来的信息
type RaftClient ¶
type RaftClient interface {
// Heartbeat 发送心跳
Heartbeat(ctx context.Context, in *ReqHeartBeat, opts ...grpc.CallOption) (*RespHeartBeat, error)
// NodeList 请求集群节点集合
NodeList(ctx context.Context, in *ReqNodeList, opts ...grpc.CallOption) (*RespNodeList, error)
// Data 请求当前集群指定key数据
Data(ctx context.Context, in *ReqData, opts ...grpc.CallOption) (*RespData, error)
// DataList 请求集群数据集合
DataList(ctx context.Context, in *ReqDataList, opts ...grpc.CallOption) (*RespDataList, error)
// SyncData 同步数据
SyncData(ctx context.Context, in *ReqSyncData, opts ...grpc.CallOption) (*RespSyncData, error)
// Vote 发起选举,索要选票
Vote(ctx context.Context, in *ReqVote, opts ...grpc.CallOption) (*RespVote, error)
}
RaftClient is the client API for Raft service.
For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
func NewRaftClient ¶
func NewRaftClient(cc grpc.ClientConnInterface) RaftClient
type RaftServer ¶
type RaftServer interface {
// Heartbeat 发送心跳
Heartbeat(context.Context, *ReqHeartBeat) (*RespHeartBeat, error)
// NodeList 请求集群节点集合
NodeList(context.Context, *ReqNodeList) (*RespNodeList, error)
// Data 请求当前集群指定key数据
Data(context.Context, *ReqData) (*RespData, error)
// DataList 请求集群数据集合
DataList(context.Context, *ReqDataList) (*RespDataList, error)
// SyncData 同步数据
SyncData(context.Context, *ReqSyncData) (*RespSyncData, error)
// Vote 发起选举,索要选票
Vote(context.Context, *ReqVote) (*RespVote, error)
}
RaftServer is the server API for Raft service.
type ReqData ¶
type ReqData struct {
// 数据key
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
ReqData 请求当前集群指定key数据
func (*ReqData) Descriptor ¶
func (*ReqData) ProtoMessage ¶
func (*ReqData) ProtoMessage()
func (*ReqData) XXX_DiscardUnknown ¶
func (m *ReqData) XXX_DiscardUnknown()
func (*ReqData) XXX_Marshal ¶
func (*ReqData) XXX_Unmarshal ¶
type ReqDataList ¶
type ReqDataList struct {
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
ReqDataList 请求当前集群数据集合
func (*ReqDataList) Descriptor ¶
func (*ReqDataList) Descriptor() ([]byte, []int)
func (*ReqDataList) ProtoMessage ¶
func (*ReqDataList) ProtoMessage()
func (*ReqDataList) Reset ¶
func (m *ReqDataList) Reset()
func (*ReqDataList) String ¶
func (m *ReqDataList) String() string
func (*ReqDataList) XXX_DiscardUnknown ¶
func (m *ReqDataList) XXX_DiscardUnknown()
func (*ReqDataList) XXX_Marshal ¶
func (m *ReqDataList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*ReqDataList) XXX_Merge ¶
func (m *ReqDataList) XXX_Merge(src proto.Message)
func (*ReqDataList) XXX_Size ¶
func (m *ReqDataList) XXX_Size() int
func (*ReqDataList) XXX_Unmarshal ¶
func (m *ReqDataList) XXX_Unmarshal(b []byte) error
type ReqHeartBeat ¶
type ReqHeartBeat struct {
// 自身作为Leader节点的任期
Term int32 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"`
// 自身作为Leader节点的ID
Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
// 自身作为Leader节点的地址
Url string `protobuf:"bytes,3,opt,name=url,proto3" json:"url,omitempty"`
// 自身作为Leader节点所有数据集hash,用于比较彼此数据
Hash string `protobuf:"bytes,4,opt,name=hash,proto3" json:"hash,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
ReqHeartBeat 用于Leader节点复制日志给其他节点,也作为心跳
prevLogIndex和prevLogTerm表示上一次发送的日志的索引和任期,用于保证收到的日志是连续的
func (*ReqHeartBeat) Descriptor ¶
func (*ReqHeartBeat) Descriptor() ([]byte, []int)
func (*ReqHeartBeat) GetHash ¶
func (m *ReqHeartBeat) GetHash() string
func (*ReqHeartBeat) GetId ¶
func (m *ReqHeartBeat) GetId() string
func (*ReqHeartBeat) GetTerm ¶
func (m *ReqHeartBeat) GetTerm() int32
func (*ReqHeartBeat) GetUrl ¶
func (m *ReqHeartBeat) GetUrl() string
func (*ReqHeartBeat) ProtoMessage ¶
func (*ReqHeartBeat) ProtoMessage()
func (*ReqHeartBeat) Reset ¶
func (m *ReqHeartBeat) Reset()
func (*ReqHeartBeat) String ¶
func (m *ReqHeartBeat) String() string
func (*ReqHeartBeat) XXX_DiscardUnknown ¶
func (m *ReqHeartBeat) XXX_DiscardUnknown()
func (*ReqHeartBeat) XXX_Marshal ¶
func (m *ReqHeartBeat) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*ReqHeartBeat) XXX_Merge ¶
func (m *ReqHeartBeat) XXX_Merge(src proto.Message)
func (*ReqHeartBeat) XXX_Size ¶
func (m *ReqHeartBeat) XXX_Size() int
func (*ReqHeartBeat) XXX_Unmarshal ¶
func (m *ReqHeartBeat) XXX_Unmarshal(b []byte) error
type ReqNodeList ¶
type ReqNodeList struct {
Nodes []*Node `protobuf:"bytes,1,rep,name=nodes,proto3" json:"nodes,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
ReqNodeList 请求当前集群节点集合
func (*ReqNodeList) Descriptor ¶
func (*ReqNodeList) Descriptor() ([]byte, []int)
func (*ReqNodeList) GetNodes ¶
func (m *ReqNodeList) GetNodes() []*Node
func (*ReqNodeList) ProtoMessage ¶
func (*ReqNodeList) ProtoMessage()
func (*ReqNodeList) Reset ¶
func (m *ReqNodeList) Reset()
func (*ReqNodeList) String ¶
func (m *ReqNodeList) String() string
func (*ReqNodeList) XXX_DiscardUnknown ¶
func (m *ReqNodeList) XXX_DiscardUnknown()
func (*ReqNodeList) XXX_Marshal ¶
func (m *ReqNodeList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*ReqNodeList) XXX_Merge ¶
func (m *ReqNodeList) XXX_Merge(src proto.Message)
func (*ReqNodeList) XXX_Size ¶
func (m *ReqNodeList) XXX_Size() int
func (*ReqNodeList) XXX_Unmarshal ¶
func (m *ReqNodeList) XXX_Unmarshal(b []byte) error
type ReqSyncData ¶
type ReqSyncData struct {
// Leader节点的任期
Term int32 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"`
// Leader节点的ID
LeaderId string `protobuf:"bytes,2,opt,name=leaderId,proto3" json:"leaderId,omitempty"`
// Leader节点的地址
LeaderUrl string `protobuf:"bytes,3,opt,name=leaderUrl,proto3" json:"leaderUrl,omitempty"`
// 当前配置版本 index 递增
Version int32 `protobuf:"varint,4,opt,name=version,proto3" json:"version,omitempty"`
// 当前term同步配置信息的key
Key string `protobuf:"bytes,5,opt,name=key,proto3" json:"key,omitempty"`
// 当前term同步配置信息的值
Value []byte `protobuf:"bytes,6,opt,name=value,proto3" json:"value,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
ReqSyncData 用于Leader节点同步数据给其他节点
func (*ReqSyncData) Descriptor ¶
func (*ReqSyncData) Descriptor() ([]byte, []int)
func (*ReqSyncData) GetKey ¶
func (m *ReqSyncData) GetKey() string
func (*ReqSyncData) GetLeaderId ¶
func (m *ReqSyncData) GetLeaderId() string
func (*ReqSyncData) GetLeaderUrl ¶
func (m *ReqSyncData) GetLeaderUrl() string
func (*ReqSyncData) GetTerm ¶
func (m *ReqSyncData) GetTerm() int32
func (*ReqSyncData) GetValue ¶
func (m *ReqSyncData) GetValue() []byte
func (*ReqSyncData) GetVersion ¶
func (m *ReqSyncData) GetVersion() int32
func (*ReqSyncData) ProtoMessage ¶
func (*ReqSyncData) ProtoMessage()
func (*ReqSyncData) Reset ¶
func (m *ReqSyncData) Reset()
func (*ReqSyncData) String ¶
func (m *ReqSyncData) String() string
func (*ReqSyncData) XXX_DiscardUnknown ¶
func (m *ReqSyncData) XXX_DiscardUnknown()
func (*ReqSyncData) XXX_Marshal ¶
func (m *ReqSyncData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*ReqSyncData) XXX_Merge ¶
func (m *ReqSyncData) XXX_Merge(src proto.Message)
func (*ReqSyncData) XXX_Size ¶
func (m *ReqSyncData) XXX_Size() int
func (*ReqSyncData) XXX_Unmarshal ¶
func (m *ReqSyncData) XXX_Unmarshal(b []byte) error
type ReqVote ¶
type ReqVote struct {
// Candidate的ID
Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
// Candidate的URL
Url string `protobuf:"bytes,3,opt,name=url,proto3" json:"url,omitempty"`
// Candidate的任期
Term int32 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"`
// 时间戳ns
Timestamp int64 `protobuf:"varint,7,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
reqVote 用于Candidate获取选票
func (*ReqVote) Descriptor ¶
func (*ReqVote) GetTimestamp ¶
func (*ReqVote) ProtoMessage ¶
func (*ReqVote) ProtoMessage()
func (*ReqVote) XXX_DiscardUnknown ¶
func (m *ReqVote) XXX_DiscardUnknown()
func (*ReqVote) XXX_Marshal ¶
func (*ReqVote) XXX_Unmarshal ¶
type RespData ¶
type RespData struct {
// 当前集群指定key数据信息的值
Value []byte `protobuf:"bytes,6,opt,name=value,proto3" json:"value,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
RespData 应答当前集群指定key数据
func (*RespData) Descriptor ¶
func (*RespData) ProtoMessage ¶
func (*RespData) ProtoMessage()
func (*RespData) XXX_DiscardUnknown ¶
func (m *RespData) XXX_DiscardUnknown()
func (*RespData) XXX_Marshal ¶
func (*RespData) XXX_Unmarshal ¶
type RespDataList ¶
type RespDataList struct {
DataArr []*Data `protobuf:"bytes,1,rep,name=dataArr,proto3" json:"dataArr,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
RespDataList 应答当前集群数据集合
func (*RespDataList) Descriptor ¶
func (*RespDataList) Descriptor() ([]byte, []int)
func (*RespDataList) GetDataArr ¶
func (m *RespDataList) GetDataArr() []*Data
func (*RespDataList) ProtoMessage ¶
func (*RespDataList) ProtoMessage()
func (*RespDataList) Reset ¶
func (m *RespDataList) Reset()
func (*RespDataList) String ¶
func (m *RespDataList) String() string
func (*RespDataList) XXX_DiscardUnknown ¶
func (m *RespDataList) XXX_DiscardUnknown()
func (*RespDataList) XXX_Marshal ¶
func (m *RespDataList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*RespDataList) XXX_Merge ¶
func (m *RespDataList) XXX_Merge(src proto.Message)
func (*RespDataList) XXX_Size ¶
func (m *RespDataList) XXX_Size() int
func (*RespDataList) XXX_Unmarshal ¶
func (m *RespDataList) XXX_Unmarshal(b []byte) error
type RespHeartBeat ¶
type RespHeartBeat struct {
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
RespHeartBeat 接收者实现逻辑
返回false,如果收到的任期比当前任期小
返回false,如果不包含之前的日志条目(没有匹配prevLogIndex和prevLogTerm)
如果存在index相同但是term不相同的日志,删除从该位置开始所有的日志
追加所有不存在的日志
如果leaderCommit>commitIndex,将commitIndex设置为commitIndex = min(leaderCommit, index of last new entry)
func (*RespHeartBeat) Descriptor ¶
func (*RespHeartBeat) Descriptor() ([]byte, []int)
func (*RespHeartBeat) ProtoMessage ¶
func (*RespHeartBeat) ProtoMessage()
func (*RespHeartBeat) Reset ¶
func (m *RespHeartBeat) Reset()
func (*RespHeartBeat) String ¶
func (m *RespHeartBeat) String() string
func (*RespHeartBeat) XXX_DiscardUnknown ¶
func (m *RespHeartBeat) XXX_DiscardUnknown()
func (*RespHeartBeat) XXX_Marshal ¶
func (m *RespHeartBeat) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*RespHeartBeat) XXX_Merge ¶
func (m *RespHeartBeat) XXX_Merge(src proto.Message)
func (*RespHeartBeat) XXX_Size ¶
func (m *RespHeartBeat) XXX_Size() int
func (*RespHeartBeat) XXX_Unmarshal ¶
func (m *RespHeartBeat) XXX_Unmarshal(b []byte) error
type RespNodeList ¶
type RespNodeList struct {
Nodes []*Node `protobuf:"bytes,1,rep,name=nodes,proto3" json:"nodes,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
RespNodeList 应答当前集群节点集合
func (*RespNodeList) Descriptor ¶
func (*RespNodeList) Descriptor() ([]byte, []int)
func (*RespNodeList) GetNodes ¶
func (m *RespNodeList) GetNodes() []*Node
func (*RespNodeList) ProtoMessage ¶
func (*RespNodeList) ProtoMessage()
func (*RespNodeList) Reset ¶
func (m *RespNodeList) Reset()
func (*RespNodeList) String ¶
func (m *RespNodeList) String() string
func (*RespNodeList) XXX_DiscardUnknown ¶
func (m *RespNodeList) XXX_DiscardUnknown()
func (*RespNodeList) XXX_Marshal ¶
func (m *RespNodeList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*RespNodeList) XXX_Merge ¶
func (m *RespNodeList) XXX_Merge(src proto.Message)
func (*RespNodeList) XXX_Size ¶
func (m *RespNodeList) XXX_Size() int
func (*RespNodeList) XXX_Unmarshal ¶
func (m *RespNodeList) XXX_Unmarshal(b []byte) error
type RespSyncData ¶
type RespSyncData struct {
// 当前任期号,用于Leader节点更新自己的任期(应该说是如果这个返回值比Leader自身的任期大,那么Leader需要更新自己的任期)
Term int32 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"`
// 如果Follower节点匹配prevLogIndex和prevLogTerm,返回true
Success bool `protobuf:"varint,2,opt,name=success,proto3" json:"success,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
RespSyncData 接收者实现逻辑
返回false,如果收到的任期比当前任期小
返回false,如果不包含之前的日志条目(没有匹配prevLogIndex和prevLogTerm)
如果存在index相同但是term不相同的日志,删除从该位置开始所有的日志
追加所有不存在的日志
如果leaderCommit>commitIndex,将commitIndex设置为commitIndex = min(leaderCommit, index of last new entry)
func (*RespSyncData) Descriptor ¶
func (*RespSyncData) Descriptor() ([]byte, []int)
func (*RespSyncData) GetSuccess ¶
func (m *RespSyncData) GetSuccess() bool
func (*RespSyncData) GetTerm ¶
func (m *RespSyncData) GetTerm() int32
func (*RespSyncData) ProtoMessage ¶
func (*RespSyncData) ProtoMessage()
func (*RespSyncData) Reset ¶
func (m *RespSyncData) Reset()
func (*RespSyncData) String ¶
func (m *RespSyncData) String() string
func (*RespSyncData) XXX_DiscardUnknown ¶
func (m *RespSyncData) XXX_DiscardUnknown()
func (*RespSyncData) XXX_Marshal ¶
func (m *RespSyncData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*RespSyncData) XXX_Merge ¶
func (m *RespSyncData) XXX_Merge(src proto.Message)
func (*RespSyncData) XXX_Size ¶
func (m *RespSyncData) XXX_Size() int
func (*RespSyncData) XXX_Unmarshal ¶
func (m *RespSyncData) XXX_Unmarshal(b []byte) error
type RespVote ¶
type RespVote struct {
// true表示给Candidate投票
VoteGranted bool `protobuf:"varint,2,opt,name=voteGranted,proto3" json:"voteGranted,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
接收者的实现逻辑
返回false,如果收到的任期比当前任期小
如果本地状态中votedFor为null或者candidateId,且candidate的日志等于或多余(按照index判断)接收者的日志,则接收者投票给candidate,即返回true
func (*RespVote) Descriptor ¶
func (*RespVote) GetVoteGranted ¶
func (*RespVote) ProtoMessage ¶
func (*RespVote) ProtoMessage()
func (*RespVote) XXX_DiscardUnknown ¶
func (m *RespVote) XXX_DiscardUnknown()
func (*RespVote) XXX_Marshal ¶
func (*RespVote) XXX_Unmarshal ¶
type RoleStatus ¶
type RoleStatus int
RoleStatus 角色定义
const ( // RoleStatusLeader leader RoleStatusLeader RoleStatus = iota // RoleStatusCandidate candidate RoleStatusCandidate // RoleStatusFollower follower RoleStatusFollower )
func Status ¶
func Status() RoleStatus
Status 获取角色状态,0-leader、1-candidate、2-follower
RoleStatusLeader、RoleStatusCandidate、RoleStatusFollower
type Server ¶
type Server struct{}
Server gRPC服务
func (*Server) DataList ¶
func (s *Server) DataList(_ context.Context, _ *ReqDataList) (resp *RespDataList, err error)
DataList 接收请求集群数据集合
func (*Server) Heartbeat ¶
func (s *Server) Heartbeat(ctx context.Context, req *ReqHeartBeat) (resp *RespHeartBeat, err error)
Heartbeat 接收发送心跳
func (*Server) NodeList ¶
func (s *Server) NodeList(_ context.Context, req *ReqNodeList) (resp *RespNodeList, err error)
NodeList 接收请求集群节点集合
func (*Server) SyncData ¶
func (s *Server) SyncData(_ context.Context, req *ReqSyncData) (resp *RespSyncData, err error)
SyncData 接收同步数据
type UnimplementedRaftServer ¶
type UnimplementedRaftServer struct {
}
UnimplementedRaftServer can be embedded to have forward compatible implementations.
func (*UnimplementedRaftServer) DataList ¶
func (*UnimplementedRaftServer) DataList(ctx context.Context, req *ReqDataList) (*RespDataList, error)
func (*UnimplementedRaftServer) Heartbeat ¶
func (*UnimplementedRaftServer) Heartbeat(ctx context.Context, req *ReqHeartBeat) (*RespHeartBeat, error)
func (*UnimplementedRaftServer) NodeList ¶
func (*UnimplementedRaftServer) NodeList(ctx context.Context, req *ReqNodeList) (*RespNodeList, error)
func (*UnimplementedRaftServer) SyncData ¶
func (*UnimplementedRaftServer) SyncData(ctx context.Context, req *ReqSyncData) (*RespSyncData, error)