cluster

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = config.Options{
	DirPath:      DefaultDbDir,
	DataFileSize: 256 * 1024 * 1024,
	SyncWrite:    false,
	IndexType:    Btree,
	FIOType:      config.MmapIOType,
}

Functions

This section is empty.

Types

type Cluster

type Cluster struct {
	//Master List
	Master []Master
	//Slave List
	Slave []Slave
	//Master List Leader
	Leader string
}

Cluster define the cluster of db

func NewRaftCluster

func NewRaftCluster(masterList []string, slaveList []string) *Cluster

NewRaftCluster create a new raft db cluster

func (*Cluster) Apply

func (c *Cluster) Apply(log *raft.Log) interface{}

Apply applies a Raft log entry to the FSM.

func (*Cluster) Restore

func (c *Cluster) Restore(snapshot io.ReadCloser) error

Restore stores the FSM from a snapshot.

func (*Cluster) Snapshot

func (c *Cluster) Snapshot() (raft.FSMSnapshot, error)

Snapshot returns a snapshot of the FSM.

type FSMSnapshot

type FSMSnapshot struct {
}

FSMSnapshot use to store the snapshot of the FSM

func (*FSMSnapshot) Persist

func (F *FSMSnapshot) Persist(sink raft.SnapshotSink) error

func (*FSMSnapshot) Release

func (F *FSMSnapshot) Release()

type Impl

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

Impl is the interface that must be implemented by a raft server.

func (*Impl) AddServer

func (i *Impl) AddServer(addr string) error

func (*Impl) Apply

func (i *Impl) Apply(b []byte) error

func (*Impl) Close

func (i *Impl) Close() error

func (*Impl) Get

func (i *Impl) Get(key []byte) ([]byte, error)

func (*Impl) IsCandidate

func (i *Impl) IsCandidate() bool

func (*Impl) IsLeader

func (i *Impl) IsLeader() bool

func (*Impl) Leader

func (i *Impl) Leader() string

func (*Impl) Peers

func (i *Impl) Peers() ([]string, error)

func (*Impl) Put

func (i *Impl) Put(key, value []byte) error

func (*Impl) ShowDebugInfo

func (i *Impl) ShowDebugInfo(witch string) ([]byte, error)

func (*Impl) State

func (i *Impl) State() raft.RaftState

func (*Impl) UserSnapshot

func (i *Impl) UserSnapshot() error

type IndexerType

type IndexerType = int8
const (
	DefaultDbDir             = "/tmp/flydb"
	Btree        IndexerType = iota + 1
)

type Interface

type Interface interface {
	State() raft.RaftState
	Peers() ([]string, error)
	Close() error
	IsLeader() bool
	IsCandidate() bool
	Leader() string
	Apply(b []byte) error
	AddServer(addr string) error
	ShowDebugInfo(witch string) ([]byte, error)
	UserSnapshot() error
	Put(key, value []byte) error
	Get(key []byte) ([]byte, error)
}

Interface is the interface that must be implemented by a raft server.

type Master

type Master struct {
	//grpc server
	proto.MasterGrpcServiceServer
	//ID
	ID string
	//Addr
	Addr string
	//Master List
	Peers []string
	//Slave List
	Slave []Slave
	//Heartbeat
	Heartbeat map[string]time.Time
	//Filename to node,key is filename,value is node
	FilenameToNode map[string]string
	//Dir Tree
	DirTree *dirtree.DirTree
	//Raft
	Raft raft.Raft
	//Raft Log
	RaftLog *boltdb.BoltStore
	// contains filtered or unexported fields
}

func (*Master) Del

func (*Master) Expire

func (*Master) Get

func (*Master) Keys

func (*Master) ListenRequest

func (m *Master) ListenRequest()

func (*Master) ListenSlave

func (m *Master) ListenSlave()

func (*Master) NewRaft

func (m *Master) NewRaft()

func (*Master) Ping

func (*Master) ReceiveHeartbeat

func (*Master) Scan

func (*Master) Set

func (*Master) Shutdown

func (*Master) StartGrpcServer

func (m *Master) StartGrpcServer()

func (*Master) TTL

func (*Master) WaitForLeader

func (m *Master) WaitForLeader()

type Slave

type Slave struct {
	//grpc server
	proto.SlaveGrpcServiceServer
	//ID
	ID string
	//Addr
	Addr string
	//Master List Leader
	Leader string
	//Slave List
	Peers []string
	//DB
	DB *engine.DB
	//Slave Message
	SlaveMessage SlaveMessage
	//work pool
	WorkPool chan struct{}
}

func (*Slave) Del

func (*Slave) Exists

func (*Slave) Expire

func (*Slave) Get

func (*Slave) Heartbeat

func (*Slave) Keys

func (*Slave) ListenLeader

func (s *Slave) ListenLeader()

func (*Slave) RegisterToMaster

func (s *Slave) RegisterToMaster()

func (*Slave) SendHeartbeat

func (s *Slave) SendHeartbeat()

func (*Slave) Set

func (*Slave) StartGrpcServer

func (s *Slave) StartGrpcServer()

func (*Slave) TTL

func (*Slave) UpdateSlaveMessage

func (s *Slave) UpdateSlaveMessage()

type SlaveMessage

type SlaveMessage struct {
	UsedDisk   uint64
	UsedMem    uint64
	CpuPercent float32
	TotalMem   uint64
	TotalDisk  uint64
}

Jump to

Keyboard shortcuts

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