red

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: GPL-3.0 Imports: 30 Imported by: 0

README

RedQueen

Go Report Card CodeQL build-docker build-release codecov Godoc Releases LICENSE

简体中文

Inspired by the supercomputer (Red Queen) in "Resident Evil", the distributed key-value store is close to it in the distributed system

This is a reliable distributed key-value store based on the raft algorithm, and internal provides advanced functions such as distributed-lock...

Client call

# go get github.com/RealFax/RedQueen@latest

Code example

Write & Read

RedQueen based on raft algorithm has the characteristics of single node write (Leader node) and multiple node read (Follower node).

Write-only call
  • Set
  • TrySet
  • Delete
  • Lock
  • Unlock
  • TryLock
Read-only call
  • Get
  • PrefixScan
  • Watch

About Internal Advanced Functions

internal advanced functions require long-term experiments to ensure its reliability

🧪 Distributed-lock (experimental functions)

RedQueen internal implements a mutex and provides grpc interface calls

🔍 Third-party

Documentation

Index

Constants

View Source
const (
	SingleLogPack uint32 = iota
	MultipleLogPack
)
View Source
const (
	StoreSuffix = "data"
)

Variables

View Source
var (
	ErrApplyLogTimeTravelDone = errors.New("raft apply log time-travel done")
	ErrApplyLogDone           = errors.New("raft apply log done")
)

Functions

func GetLogPackHeader added in v0.5.0

func GetLogPackHeader(r io.Reader) uint32

func LogPackHeader added in v0.5.0

func LogPackHeader(typ uint32) []byte

func NewFSMHandlers added in v0.5.0

func NewFSMHandlers(s store.Store) map[serverpb.RaftLogCommand]FSMHandleFunc

func NewLockerBackend

func NewLockerBackend(
	ns store.Namespace,
	raftApplyFunc func(context.Context, *serverpb.RaftLogPayload, time.Duration) error,
) locker.Backend

func RaftLogPayloadKey added in v0.5.0

func RaftLogPayloadKey(m *serverpb.RaftLogPayload) uint64

func UnpackLog added in v0.5.0

func UnpackLog(r io.Reader) ([]*serverpb.RaftLogPayload, error)

Types

type ApplyFunc added in v0.5.0

type ApplyFunc func(cmd []byte, timeout time.Duration) raft.ApplyFuture

type FSM

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

func NewFSM

func NewFSM(s store.Store, handlers map[serverpb.RaftLogCommand]FSMHandleFunc) *FSM

func (*FSM) Apply

func (f *FSM) Apply(log *raft.Log) any

func (*FSM) Restore

func (f *FSM) Restore(rc io.ReadCloser) error

func (*FSM) Snapshot

func (f *FSM) Snapshot() (raft.FSMSnapshot, error)

type FSMHandleFunc

type FSMHandleFunc func(*serverpb.RaftLogPayload) error

type FSMHandlers added in v0.5.0

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

func (*FSMHandlers) Del added in v0.5.0

func (h *FSMHandlers) Del(payload *serverpb.RaftLogPayload) error

func (*FSMHandlers) Set added in v0.5.0

func (h *FSMHandlers) Set(payload *serverpb.RaftLogPayload) error

func (*FSMHandlers) SetWithTTL added in v0.5.0

func (h *FSMHandlers) SetWithTTL(payload *serverpb.RaftLogPayload) error

func (*FSMHandlers) TrySet added in v0.5.0

func (h *FSMHandlers) TrySet(payload *serverpb.RaftLogPayload) error

func (*FSMHandlers) TrySetWithTTL added in v0.5.0

func (h *FSMHandlers) TrySetWithTTL(payload *serverpb.RaftLogPayload) error

type LockerBackendWrapper

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

func (LockerBackendWrapper) Del

func (w LockerBackendWrapper) Del(key []byte) error

func (LockerBackendWrapper) Get

func (w LockerBackendWrapper) Get(key []byte) (*store.Value, error)

func (LockerBackendWrapper) TrySetWithTTL

func (w LockerBackendWrapper) TrySetWithTTL(key, value []byte, ttl uint32) error

func (LockerBackendWrapper) Watch

type Raft

type Raft struct {
	*raft.Raft
	// contains filtered or unexported fields
}

func NewRaft

func NewRaft(cfg RaftConfig) (*Raft, error)

func NewRaftWithOptions

func NewRaftWithOptions(opts ...RaftServerOption) (*Raft, error)

func (*Raft) AddCluster

func (r *Raft) AddCluster(id raft.ServerID, addr raft.ServerAddress) error

type RaftApply added in v0.5.0

type RaftApply interface {
	Apply(ctx *context.Context, m *serverpb.RaftLogPayload, timeout time.Duration) error
}

func NewRaftMultipleLogApply added in v0.5.0

func NewRaftMultipleLogApply(ctx context.Context, maxLimit int32, deadline, applyTimeout time.Duration, af ApplyFunc) RaftApply

func NewRaftSingeLogApply added in v0.5.0

func NewRaftSingeLogApply(af ApplyFunc) RaftApply

type RaftConfig

type RaftConfig struct {
	Bootstrap               bool
	MaxSnapshots            int
	ServerID, Addr, DataDir string
	Store                   store.Store
	Clusters                []raft.Server
}

type RaftServerOption

type RaftServerOption func(*Raft) error

func RaftWithBoltLogStore

func RaftWithBoltLogStore(path string) RaftServerOption

func RaftWithBootstrap

func RaftWithBootstrap() RaftServerOption

func RaftWithClusters

func RaftWithClusters(clusters []raft.Server) RaftServerOption

func RaftWithConfig

func RaftWithConfig(cfg *raft.Config) RaftServerOption

func RaftWithEmpty

func RaftWithEmpty() RaftServerOption

func RaftWithFileSnapshotStore

func RaftWithFileSnapshotStore(path string, retain int, logOut io.Writer) RaftServerOption

func RaftWithStdFSM

func RaftWithStdFSM(store store.Store) RaftServerOption

func RaftWithStdStableStore

func RaftWithStdStableStore(store store.Store) RaftServerOption

func RaftWithTCPTransport

func RaftWithTCPTransport(addr string, maxPool int, timeout time.Duration, logOut io.Writer) RaftServerOption

type Server

type Server struct {
	serverpb.UnimplementedKVServer
	serverpb.UnimplementedLockerServer
	serverpb.UnimplementedRedQueenServer
	// contains filtered or unexported fields
}

func NewServer

func NewServer(cfg *config.Config) (*Server, error)

func (*Server) Close

func (s *Server) Close() (err error)

func (*Server) Delete

func (*Server) Get

func (*Server) LeaderMonitor

func (*Server) ListenAndServe added in v0.5.1

func (s *Server) ListenAndServe() error

func (*Server) Lock

func (*Server) PrefixScan

func (*Server) RaftState

func (*Server) Set

func (*Server) TryLock

func (*Server) TrySet

func (*Server) Unlock

func (*Server) Watch

func (s *Server) Watch(req *serverpb.WatchRequest, stream serverpb.KV_WatchServer) error

func (*Server) WatchPrefix added in v0.5.1

type Snapshot

type Snapshot struct {
	io.Reader
}

func (*Snapshot) Persist

func (s *Snapshot) Persist(sink raft.SnapshotSink) error

func (*Snapshot) Release

func (s *Snapshot) Release()

type StableStore

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

func NewStableStore

func NewStableStore(s store.Store) (*StableStore, error)

func (*StableStore) Get

func (s *StableStore) Get(key []byte) ([]byte, error)

Get returns the value for key, or an empty byte slice if key was not found.

func (*StableStore) GetUint64

func (s *StableStore) GetUint64(key []byte) (uint64, error)

GetUint64 returns the uint64 value for key, or 0 if key was not found.

func (*StableStore) Set

func (s *StableStore) Set(key []byte, val []byte) error

func (*StableStore) SetUint64

func (s *StableStore) SetUint64(key []byte, val uint64) error

Directories

Path Synopsis
api
cmd
RedQueenServer command
RedQueenUtil command
internal

Jump to

Keyboard shortcuts

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