raft

package
v0.0.0-...-0effa93 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorCode

type ErrorCode int32
const (
	Success          ErrorCode = iota // 表示成功
	TermMismatch                      // 任期不匹配
	LogInconsistency                  // 日志不一致
	LogDuplicate                      // 日志重复
)

type RaftNode

type RaftNode struct {
	sync.Mutex                                // 保证某些情况下的并发安全
	pb.UnimplementedRaftServer                // 保证实现了 RaftServer 接口
	Address                    string         // 节点地址
	Role                       Role           // 当前节点的角色
	Term                       int32          // 当前任期
	CommitIndex                int32          // 已提交的日志索引
	Logs                       []*pb.LogEntry // 日志
	LogsBuffer                 []*pb.LogEntry // 日志缓冲区

	Peers   []string                 // 集群中的其他节点地址
	Clients map[string]pb.RaftClient // 与其他节点的gRPC客户端

	// debug
	Wg sync.WaitGroup
	// contains filtered or unexported fields
}

func NewRaftNode

func NewRaftNode(role Role, address string) *RaftNode

func (*RaftNode) AppendEntry

func (r *RaftNode) AppendEntry(ctx context.Context, req *pb.AppendEntryRequest) (*pb.AppendEntryResponse, error)

实现RaftServer接口,执行一致性操作

func (*RaftNode) HandleInConsistency

func (r *RaftNode) HandleInConsistency(peer string, matchIndex int32)

func (*RaftNode) SubmitData

func (r *RaftNode) SubmitData(data []byte) error

提供接口供外部调用,接收客户端的写请求

type Role

type Role int
const (
	Follower Role = iota
	Leader
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL