raft

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CmdSet   = "set"
	CmdSetEx = "setex"
	CmdDel   = "del"
)

Variables

View Source
var (
	// ErrKeyNotFound is an error indicating a given key does not exist
	ErrKeyNotFound = errors.New("not found")
)

Functions

func RedirectKeyRequest

func RedirectKeyRequest(rs *raft.Raft, cmd, k, v string, exp int64) error

RedirectKeyRequest redirect the request to leader node

func RedirectRaftRequest

func RedirectRaftRequest(rs *raft.Raft, nodeId, addr string) error

RedirectRaftRequest redirect raft operation to leader node

Types

type BadgerStore

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

func (*BadgerStore) Close

func (b *BadgerStore) Close() error

Close is used to gracefully close the DB connection.

func (*BadgerStore) DeleteRange

func (b *BadgerStore) DeleteRange(min, max uint64) error

DeleteRange deletes logs within a given range inclusively.

func (*BadgerStore) FirstIndex

func (b *BadgerStore) FirstIndex() (uint64, error)

FirstIndex returns the first known index from the Raft log.

func (*BadgerStore) Get

func (b *BadgerStore) Get(key []byte) ([]byte, error)

Get is used to retrieve a value from the k/v store by key

func (*BadgerStore) GetLog

func (b *BadgerStore) GetLog(index uint64, log *raft.Log) error

GetLog gets a log entry from Badger at a given index.

func (*BadgerStore) GetUint64

func (b *BadgerStore) GetUint64(key []byte) (uint64, error)

GetUint64 is like Get, but handles uint64 values

func (*BadgerStore) LastIndex

func (b *BadgerStore) LastIndex() (uint64, error)

LastIndex returns the last known index from the Raft log.

func (*BadgerStore) Set

func (b *BadgerStore) Set(key []byte, val []byte) error

Set is used to set a key/value set outside the raft log.

func (*BadgerStore) SetUint64

func (b *BadgerStore) SetUint64(key []byte, val uint64) error

SetUint64 is like Set, but handles uint64 values

func (*BadgerStore) StoreLog

func (b *BadgerStore) StoreLog(log *raft.Log) error

StoreLog stores a single raft log.

func (*BadgerStore) StoreLogs

func (b *BadgerStore) StoreLogs(logs []*raft.Log) error

StoreLogs stores a set of raft logs.

type ClusterState

type ClusterState struct {
	LeaderId   string      `json:"leaderId,omitempty"`
	LeaderAddr string      `json:"leaderAddr,omitempty"`
	Peers      []PeerState `json:"peers,omitempty"`
}

func NewClusterInfo

func NewClusterInfo(rs *raft.Raft) *ClusterState

func (*ClusterState) String

func (c *ClusterState) String() string

type CustomLogger

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

func NewCustomLogger

func NewCustomLogger(l *logrus.Logger, name string) *CustomLogger

func (*CustomLogger) Debug

func (c *CustomLogger) Debug(msg string, args ...interface{})

func (*CustomLogger) Error

func (c *CustomLogger) Error(msg string, args ...interface{})

func (*CustomLogger) GetLevel

func (c *CustomLogger) GetLevel() hclog.Level

func (*CustomLogger) ImpliedArgs

func (c *CustomLogger) ImpliedArgs() []interface{}

func (*CustomLogger) Info

func (c *CustomLogger) Info(msg string, args ...interface{})

func (*CustomLogger) IsDebug

func (c *CustomLogger) IsDebug() bool

func (*CustomLogger) IsError

func (c *CustomLogger) IsError() bool

func (*CustomLogger) IsInfo

func (c *CustomLogger) IsInfo() bool

func (*CustomLogger) IsTrace

func (c *CustomLogger) IsTrace() bool

func (*CustomLogger) IsWarn

func (c *CustomLogger) IsWarn() bool

func (*CustomLogger) Log

func (c *CustomLogger) Log(level hclog.Level, msg string, args ...interface{})

func (*CustomLogger) Name

func (c *CustomLogger) Name() string

func (*CustomLogger) Named

func (c *CustomLogger) Named(name string) hclog.Logger

func (*CustomLogger) ResetNamed

func (c *CustomLogger) ResetNamed(name string) hclog.Logger

func (*CustomLogger) SetLevel

func (c *CustomLogger) SetLevel(level hclog.Level)

func (*CustomLogger) StandardLogger

func (c *CustomLogger) StandardLogger(opts *hclog.StandardLoggerOptions) *log.Logger

func (*CustomLogger) StandardWriter

func (c *CustomLogger) StandardWriter(opts *hclog.StandardLoggerOptions) io.Writer

func (*CustomLogger) Trace

func (c *CustomLogger) Trace(msg string, args ...interface{})

func (*CustomLogger) Warn

func (c *CustomLogger) Warn(msg string, args ...interface{})

func (*CustomLogger) With

func (c *CustomLogger) With(args ...interface{}) hclog.Logger

type Options

type Options struct {
	// Path is the directory path to the Badger db to use.
	Path string

	// BadgerOptions contains any specific Badger options you might
	// want to specify.
	BadgerOptions *badger.Options

	// NoSync causes the database to skip fsync calls after each
	// write to the log. This is unsafe, so it should be used
	// with caution.
	NoSync bool
}

Options contains all the configuration used to open the Badger db

type PeerState

type PeerState struct {
	Id    string `json:"id,omitempty"`
	Addr  string `json:"addr,omitempty"`
	Role  string `json:"role,omitempty"`
	State string `json:"state,omitempty"`
}

type Store

type Store struct {
	DataDir      string
	RaftDir      string
	RaftBindAddr string
	// contains filtered or unexported fields
}

func (*Store) Delete

func (s *Store) Delete(key string) error

Delete deletes the given key.

func (*Store) Get

func (s *Store) Get(key string) (string, error)

Get returns the value for the given key.

func (*Store) Join

func (s *Store) Join(nodeID, addr string) error

Join joins a node, identified by nodeID and located at addr, to this store. The node must be ready to respond to Raft communications at that address.

func (*Store) Open

func (s *Store) Open(enableSingle bool, localID string) error

Open opens the store. If enableSingle is set, and there are no existing peers, then this node becomes the first node, and therefore leader, of the cluster. localID should be the server identifier for this node.

func (*Store) Raft

func (s *Store) Raft() *raft.Raft

func (*Store) Remove

func (s *Store) Remove(nodeId, addr string) error

func (*Store) ScanKeys

func (s *Store) ScanKeys(p string) []string

ScanKeys scan Keys 要快一个数量级, 可以先找到key然后在进行稀疏的值读取 大部分key都在内存中

func (*Store) ScanKvs

func (s *Store) ScanKvs(p string) map[string]string

ScanKvs is a prefix related pattern

func (*Store) Set

func (s *Store) Set(key, value string, exp int64) error

Set sets the value for the given key.

Jump to

Keyboard shortcuts

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