store

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2022 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IndexSize      = 5 * 4              // ko+ks+vo+vs+ttl
	BlockIndexSize = 4 + 1024*IndexSize // currOffset + 1024*(ko+ks+vo+vs+ttl)
)
View Source
const (
	DefaultKVBucketName    = "impact-eintr"
	DefaultLeaseBucketName = "raftd-lease-system"
)
View Source
const (
	CREATE = iota
	ALIVE
	DEAD
)

Variables

View Source
var (
	ErrInvalidKV   = errors.New("Invalid Key Value Pair!")
	ErrEmptyBucket = errors.New("A empty Bucket!")
)
View Source
var (
	// ErrNotLeader is returned when a node attempts to execute a leader-only
	// operation.
	ErrNotLeader = errors.New("not leader")

	// ErrOpenTimeout is returned when the Store does not apply its initial
	// logs within the specified time.
	ErrOpenTimeout = errors.New("timeout waiting for initial logs application")

	ErrLeaseNotFound = errors.New("can not find this Lease")
	ErrLeaseExpire   = errors.New("this Lease has been expired")
)

Functions

func AssertTrue added in v0.2.0

func AssertTrue(p bool)

func EncodeMeta added in v0.2.0

func EncodeMeta(l *LeaseMeta) []byte

Types

type Bucket added in v0.2.0

type Bucket struct {
	Meta LeaseMeta
	KV   ValuePairs
}

func NewBucket added in v0.2.0

func NewBucket() *Bucket

func (*Bucket) AddKV added in v0.2.0

func (b *Bucket) AddKV(key, value []byte)

func (*Bucket) Decode added in v0.2.0

func (b *Bucket) Decode(src []byte) error

func (*Bucket) DelKV added in v0.2.0

func (v *Bucket) DelKV(key []byte)

func (*Bucket) Encode added in v0.2.0

func (b *Bucket) Encode() (out []byte, err error)

type ConsistencyLevel

type ConsistencyLevel int
const (
	Default ConsistencyLevel = iota
	Stale
	Consistent
)

type LeaseMeta added in v0.1.0

type LeaseMeta struct {
	Name   string `msgpack:"name"`
	TTL    int    `msgpack:"ttl"`
	Status int    `msgpack:"status"`
	Count  int    `msgpack:"count"`
}

func DecodeMeta added in v0.2.0

func DecodeMeta(b []byte) (*LeaseMeta, int)

type Store

type Store struct {
	RaftDir  string
	RaftBind string

	DBDir  string
	DB2Dir string
	// contains filtered or unexported fields
}

func New

func New(bindID int64) *Store

func (*Store) Close added in v0.2.0

func (s *Store) Close()

func (*Store) Delete

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

func (*Store) DeleteMeta

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

func (*Store) Get

func (s *Store) Get(key string, lvl ConsistencyLevel) ([]byte, error)

func (*Store) GetLeaseKV added in v0.1.0

func (s *Store) GetLeaseKV(prefix, key string) ([]string, error)

func (*Store) GetMeta

func (s *Store) GetMeta(key string) (m string, err error)

func (*Store) Join

func (s *Store) Join(nodeID, httpAddr string, 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) LeaderAPIAddr

func (s *Store) LeaderAPIAddr() string

func (*Store) LeaderAddr

func (s *Store) LeaderAddr() string

func (*Store) LeaderID

func (s *Store) LeaderID() (string, error)

func (*Store) LeaseGrant added in v0.1.0

func (s *Store) LeaseGrant(name string, ttl int) (uint64, error)

创建新的租约

func (*Store) LeaseKeepAlive added in v0.1.0

func (s *Store) LeaseKeepAlive(leaseId, key string, value []byte) error

func (*Store) LeaseRevoke added in v0.1.0

func (s *Store) LeaseRevoke(leaseId string) error

func (*Store) LeaseTimeToAlive added in v0.1.0

func (s *Store) LeaseTimeToAlive() error

func (*Store) Open

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

func (*Store) RecoverStatus added in v0.1.1

func (s *Store) RecoverStatus()

RecoverStatus 节点状态机恢复后 根据状态机最新状态恢复服务现场

func (*Store) Set

func (s *Store) Set(key string, value []byte) error

func (*Store) SetMeta

func (s *Store) SetMeta(key, value string) error

func (*Store) WaitForApplied

func (s *Store) WaitForApplied(timeout time.Duration) error

WaitForApplied waits for all Raft log entries to to be applied to the underlying database.

func (*Store) WaitForAppliedIndex

func (s *Store) WaitForAppliedIndex(idx uint64, timeout time.Duration) error

WaitForAppliedIndex blocks until a given log index has been applied, or the timeout expires.

func (*Store) WaitForLeader

func (s *Store) WaitForLeader(timeout time.Duration) (string, error)

WaitForLeader blocks until a leader is detected, or the timeout expires.

type ValuePair added in v0.2.0

type ValuePair struct {
	T uint32
	V []byte
}

type ValuePairs added in v0.2.0

type ValuePairs map[string]ValuePair

type WaitGroupWrapper added in v0.1.0

type WaitGroupWrapper struct {
	sync.WaitGroup
}

func (*WaitGroupWrapper) Wrap added in v0.1.0

func (w *WaitGroupWrapper) Wrap(cb func())

Jump to

Keyboard shortcuts

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