raft

package
v0.0.0-...-110c355 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ADD                  string = "add"
	ADD_OBSERVER         string = "addobserver"
	ADD_WITNESS          string = "addwitness"
	REMOVE               string = "remove"
	TRANSFER             string = "transfer"
	GET_LEADER           string = "getleader"
	GET_NODEHOST_INFO    string = "getnodehostinfo"
	GET_CLUSTER_MEM_SHIP string = "getclustermembership"
	REMOVE_DATA          string = "removedata"
	OK                   string = "ok"
	FULLSYNC             string = "fullsync"
	STAT_INFO            string = "statinfo"
	DERAFT               string = "deraft"
	RERAFT               string = "reraft"
	LOGCOMPACT           string = "logcompact"
)
View Source
const (
	DefaultWorkNum     = 32
	DefaultQueueLength = 8 << 10
)

Variables

View Source
var DefaultLogger = &DLog{}
View Source
var UpdateOtherNodeDoing = []byte("&OtherNode*")
View Source
var UpdateSelfNodeDoing = []byte("&SelfNode*")

Functions

func GetClusterNodeOK

func GetClusterNodeOK(nCluster uint64) bool

func Init

func Init()

func NewDiskKV

func NewDiskKV(clusterID uint64, nodeID uint64, s *server.Server, p *StartRun) sm.IOnDiskStateMachine

func ReraftInit

func ReraftInit(s *server.Server, port string) error

Types

type ClusterInfo

type ClusterInfo struct {
	ClusterID         uint64            `json:"clusterID"`
	NodeID            uint64            `json:"nodeID"`
	Nodes             map[uint64]string `json:"nodes"`
	ConfigChangeIndex uint64            `json:"configChangeIndex"`
	StateMachineType  uint64            `json:"stateMachineType"`
	IsLeader          bool              `json:"isLeader"`
	IsObserver        bool              `json:"isObserver"`
	IsWitness         bool              `json:"isWitness "`
	Pending           bool              `json:"pending"`
}

type DLog

type DLog struct {
}

func (*DLog) Debugf

func (l *DLog) Debugf(format string, args ...interface{})

func (*DLog) Errorf

func (l *DLog) Errorf(format string, args ...interface{})

func (*DLog) Infof

func (l *DLog) Infof(format string, args ...interface{})

func (*DLog) Panicf

func (l *DLog) Panicf(format string, args ...interface{})

func (*DLog) SetLevel

func (l *DLog) SetLevel(logger.LogLevel)

func (*DLog) Warningf

func (l *DLog) Warningf(format string, args ...interface{})

type DiskKV

type DiskKV struct {
	// contains filtered or unexported fields
}

func (*DiskKV) Close

func (pD *DiskKV) Close() error

func (*DiskKV) GetHash

func (pD *DiskKV) GetHash() (uint64, error)

func (*DiskKV) Lookup

func (pD *DiskKV) Lookup(key interface{}) (interface{}, error)

func (*DiskKV) OnDisk

func (pD *DiskKV) OnDisk() bool

func (*DiskKV) Open

func (pD *DiskKV) Open(stopc <-chan struct{}) (uint64, uint64, error)

func (*DiskKV) PrepareSnapshot

func (pD *DiskKV) PrepareSnapshot() (interface{}, error)

func (*DiskKV) RecoverFromSnapshot

func (pD *DiskKV) RecoverFromSnapshot(r io.Reader, done <-chan struct{}) error

func (*DiskKV) SaveSnapshot

func (pD *DiskKV) SaveSnapshot(ctx interface{}, w io.Writer, done <-chan struct{}) error

func (*DiskKV) Sync

func (pD *DiskKV) Sync() error

func (*DiskKV) Update

func (pD *DiskKV) Update(es []sm.Entry) ([]sm.Entry, error)

type Membership

type Membership struct {
	ConfigChangeID uint64              `json:"config_changeid"`
	Nodes          map[uint64]string   `json:"nodes"`
	Observers      map[uint64]string   `json:"observers"`
	NonVotings     map[uint64]string   `json:"nonvotings"`
	Witnesses      map[uint64]string   `json:"witnesses"`
	Removed        map[uint64]struct{} `json:"removed"`
}

type MembershipV2

type MembershipV2 struct {
	Info Membership `json:"info"`
}

func (*MembershipV2) InitByDragonboatMembership

func (m *MembershipV2) InitByDragonboatMembership(ms *braft.Membership)

func (*MembershipV2) Marshal

func (m *MembershipV2) Marshal() (string, error)

type NodeHostInfo

type NodeHostInfo struct {
	RaftAddress     string        `json:"raftAddress"`
	ClusterInfoList []ClusterInfo `json:"clusterInfoList"`
	LogInfo         []NodeInfo    `json:"LogInfo"`
}

type NodeHostInfoV2

type NodeHostInfoV2 struct {
	Info braft.NodeHostInfo `json:"info"`
}

type NodeInfo

type NodeInfo struct {
	ClusterID uint64 `json:"clusterID"`
	NodeID    uint64 `json:"nodeID"`
}

type QData

type QData struct {
	// contains filtered or unexported fields
}

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue(worknum, length int, pD *DiskKV) *Queue

func (*Queue) Close

func (q *Queue) Close()

func (*Queue) QLength

func (q *Queue) QLength() int

type RetType

type RetType int
const (
	R_UNKNOWN_ERROR RetType = -1
	R_SUCCESS       RetType = 0
	R_SHUT_DOWN     RetType = 1
	R_NIL_POINTER   RetType = 2
	R_ERROR         RetType = 3
	R_PARA_ERR      RetType = 4
	R_RETRY_EXHAUST RetType = 5
	R_REJECTED      RetType = 6
	R_ABORTED       RetType = 7
	R_RET_ERROR     RetType = 8
	R_JOSON_ERR     RetType = 9
)

type StartRun

type StartRun struct {
	ClusterId       uint64
	NodeID          uint64
	Addr            string
	Join            bool
	IsObserver      bool
	IsWitness       bool
	TimeOut         time.Duration
	RetryTimes      int
	SnapshotTimeOut int
	AsyncPropose    bool
	RaftReady       bool
	Mu              sync.Mutex
	ClusterStatOnce sync.Once
	AddrList        map[uint64]string
	WalDir          string
	NodeHostDir     string
	HostName        string
	Nhc             dconfig.NodeHostConfig
	Nh              *braft.NodeHost
	Rc              dconfig.Config
	// contains filtered or unexported fields
}

func (*StartRun) AddNode

func (p *StartRun) AddNode(nodeId uint64, address string, retryTime int) (RetType, error)

func (*StartRun) AddObserver

func (p *StartRun) AddObserver(nodeId uint64, address string) (RetType, error)

func (*StartRun) AddWitness

func (p *StartRun) AddWitness(nodeId uint64, address string) (RetType, error)

func (*StartRun) Clean

func (p *StartRun) Clean() error

func (*StartRun) DelNode

func (p *StartRun) DelNode(nodeId uint64, retryTime int) (RetType, error)

func (*StartRun) FullSync

func (p *StartRun) FullSync() error

func (*StartRun) GetClusterMembership

func (p *StartRun) GetClusterMembership() (string, RetType, error)

func (*StartRun) GetLeaderId

func (p *StartRun) GetLeaderId() (uint64, RetType, error)

func (*StartRun) GetNodeHostInfo

func (p *StartRun) GetNodeHostInfo() (string, RetType, error)

func (*StartRun) GetOK

func (p *StartRun) GetOK() (bool, RetType, error)

func (*StartRun) LeaderTransfer

func (p *StartRun) LeaderTransfer(targetNodeID uint64) (RetType, error)

func (*StartRun) LoadConfig

func (p *StartRun) LoadConfig(s *server.Server)

func (*StartRun) Propose

func (p *StartRun) Propose(msg []byte, retryTime int) (RetType, error)

func (*StartRun) RemoveData

func (p *StartRun) RemoveData(nNodeID uint64) (RetType, error)

func (*StartRun) StatInfo

func (p *StartRun) StatInfo() (string, RetType, error)

func (*StartRun) StopNodeHost

func (p *StartRun) StopNodeHost() (RetType, error)

func (*StartRun) SyncPropose

func (p *StartRun) SyncPropose(msg []byte) (statemachine.Result, error)

Jump to

Keyboard shortcuts

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