kv

package
v0.0.0-...-d3bda19 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyKey = errors.New("an empty key")
View Source
var ErrNotFound = errors.New("not found")

Functions

This section is empty.

Types

type Command

type Command struct {
	Op    Op     `json:"op,omitempty"`
	Key   string `json:"key,omitempty"`
	Value string `json:"value,omitempty"`
}

type Op

type Op string
const (
	SetOp    Op = "set"
	DeleteOp Op = "delete"
)

type Server

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

Server behaves a Raft server.

func NewServer

func NewServer(store *Store, l hclog.Logger, config *config.Values) *Server

func (*Server) ApplyDeleteOp

func (s *Server) ApplyDeleteOp(key string) error

func (*Server) ApplyGetOp

func (s *Server) ApplyGetOp(key string) (string, error)

func (*Server) ApplySetOp

func (s *Server) ApplySetOp(key, value string) error

func (*Server) BootstrapCluster

func (s *Server) BootstrapCluster() error

BootstrapCluster bootstrap a new cluster. There are no existing peers, then this server becomes the first server, and therefore leader of the cluster.

func (*Server) Join

func (s *Server) Join(serverId, advertise string) error

Join register a server to a cluster, identified by serverId and located at advertise, to this server. The server must be ready to respond to Raft communications at that address.

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown is used to shutdown the server

func (*Server) Start

func (s *Server) Start() error

Start runs a finite-state machine.

type Store

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

Store stores key-values and behaves FSM.

func NewStore

func NewStore(logger hclog.Logger) *Store

NewStore initializes the store.

func (*Store) Apply

func (s *Store) Apply(rl *raft.Log) interface{}

func (*Store) Get

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

func (*Store) Persist

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

func (*Store) Release

func (s *Store) Release()

func (*Store) Restore

func (s *Store) Restore(rc io.ReadCloser) error

func (*Store) Snapshot

func (s *Store) Snapshot() (raft.FSMSnapshot, error)

Jump to

Keyboard shortcuts

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