Documentation ¶
Overview ¶
Package store provides a bolt distributed key-value store. The keys and associated values are changed via distributed consensus, meaning that the values are changed only when a majority of nodes in the cluster agree on the new value.
Distributed consensus is provided via the Raft algorithm.
Index ¶
- Variables
- type Cache
- func (c *Cache) Add(bucketName []byte, key []byte, value []byte) bool
- func (c *Cache) Contains(bucket, key []byte) (ok bool)
- func (c *Cache) Get(bucket, key []byte) (value []byte, ok bool)
- func (c *Cache) GetOldest() ([]byte, []byte, []byte, bool)
- func (c *Cache) Keys() []string
- func (c *Cache) Len() int
- func (c *Cache) Open()
- func (c *Cache) Peek(bucket, key []byte) (value []byte, ok bool)
- func (c *Cache) Purge()
- func (c *Cache) Remove(bucket, key []byte) bool
- func (c *Cache) RemoveBucket(bucket []byte) bool
- func (c *Cache) RemoveOldest() ([]byte, []byte, []byte, bool)
- func (c *Cache) Statistics(tags map[string]string) []model.Statistic
- type CacheStatistics
- type ClusterState
- type EvictCallback
- type LodaSession
- type Session
- type Store
- func (s *Store) APIPeers() (map[string]string, error)
- func (s *Store) Addr() string
- func (s *Store) Backup() ([]byte, error)
- func (s *Store) Batch(rows []model.Row) error
- func (s *Store) Close(wait bool) error
- func (s *Store) CreateBucket(name []byte) error
- func (s *Store) CreateBucketIfNotExist(name []byte) error
- func (s *Store) DelSession(k interface{}) error
- func (s *Store) GetSession(k interface{}) interface{}
- func (s *Store) IsLeader() bool
- func (s *Store) Join(addr string) error
- func (s *Store) Leader() string
- func (s *Store) Nodes() ([]string, error)
- func (s *Store) Open(enableSingle bool) error
- func (s *Store) Path() string
- func (s *Store) Peer(addr string) string
- func (s *Store) Remove(addr string) error
- func (s *Store) RemoveBucket(name []byte) error
- func (s *Store) RemoveKey(bucket, key []byte) error
- func (s *Store) Restore(backupfile string) error
- func (s *Store) SetSession(k, v interface{}) error
- func (s *Store) State() ClusterState
- func (s *Store) Statistics(tags map[string]string) []model.Statistic
- func (s *Store) Update(bucket []byte, key []byte, value []byte) error
- func (s *Store) UpdateAPIPeers(peers map[string]string) error
- func (s *Store) View(bucket, key []byte) ([]byte, error)
- func (s *Store) ViewPrefix(bucket, keyPrefix []byte) (map[string][]byte, error)
- func (s *Store) WaitForLeader(timeout time.Duration) (string, error)
- type Transport
Constants ¶
This section is empty.
Variables ¶
var ErrBucketNotFound = errors.New("bucket not found")
ErrBucketNotFound bucket not found error
var ErrNotLeader = raft.ErrNotLeader
ErrNotLeader not leader error
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache implements a non-thread safe fixed size LRU cache.
func NewCache ¶
func NewCache(maxSize uint64, onEvict EvictCallback, logger log.Logger) *Cache
NewCache constructs an LRU cache of the given size.
func (*Cache) Contains ¶
Contains checks if a key is in the cache, without updating the recent-ness or deleting it for being stale.
func (*Cache) Peek ¶
Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.
func (*Cache) Remove ¶
Remove removes the provided key from the cache, returning if the key was contained.
func (*Cache) RemoveBucket ¶
RemoveBucket remove Bucket removes the provided bucket from the cache, returning if the bucket was contained.
func (*Cache) RemoveOldest ¶
RemoveOldest removes the oldest item from the cache.
type CacheStatistics ¶
type CacheStatistics struct { MemSizeBytes int64 PurgeCount int64 AddCount int64 GetCount int64 HitCount int64 MissCount int64 RemoveCount int64 RemoveBucketCount int64 RemoveOldestCount int64 KeysCount int64 }
CacheStatistics hold statistics related to the cache.
type ClusterState ¶
type ClusterState int
ClusterState defines the possible Raft states the current node can be in
const ( Leader ClusterState = iota Follower Candidate Shutdown Unknown )
Represents the Raft cluster states
type EvictCallback ¶
EvictCallback is used to get a callback when a cache entry is evicted.
type LodaSession ¶
type LodaSession struct { //SessionMap store all client token SessionMap map[interface{}]interface{} // Mux locks SessionMap Mux sync.Mutex }
LodaSession struct
func (*LodaSession) Delete ¶
func (ls *LodaSession) Delete(k interface{})
Delete removes the session value associated to the given key.
func (*LodaSession) Get ¶
func (ls *LodaSession) Get(i interface{}) interface{}
Get returns the session value associated to the given key.
func (*LodaSession) Set ¶
func (ls *LodaSession) Set(k, v interface{})
Set sets the session value associated to the given key.
type Session ¶
type Session interface { // Get returns the session value associated to the given key. Get(key interface{}) interface{} // Set sets the session value associated to the given key. Set(key interface{}, val interface{}) // Delete removes the session value associated to the given key. Delete(key interface{}) }
Session interface key is user token, value is user id.
type Store ¶
type Store struct { Dir string // TODO: maybe need to config SnapshotThreshold uint64 HeartbeatTimeout time.Duration // contains filtered or unexported fields }
Store is a bolt key-value store, where all changes are made via Raft consensus.
func (*Store) APIPeers ¶
APIPeers return the map of Raft addresses to API addresses. Delete apiPeer record not in the cluster.
func (*Store) CreateBucket ¶
CreateBucket create a bucket.
func (*Store) CreateBucketIfNotExist ¶
CreateBucketIfNotExist create a bucket if not exist.
func (*Store) DelSession ¶
DelSession delete a session by given key.
func (*Store) GetSession ¶
func (s *Store) GetSession(k interface{}) interface{}
GetSession get a session.
func (*Store) Join ¶
Join joins a node, located at addr, to this store. The node must be ready to respond to Raft communications at that address.
func (*Store) Leader ¶
Leader returns the current leader. Returns a blank string if there is no leader.
func (*Store) Open ¶
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.
func (*Store) Peer ¶
Peer returns the API address for the given addr. If there is no peer for the address, it returns the empty string.
func (*Store) Remove ¶
Remove removes a node from the store, specified by addr. NOTE: raft Bug will cause the claster cannot add peer any more.
func (*Store) RemoveBucket ¶
RemoveBucket remove a bucket.
func (*Store) SetSession ¶
SetSession set a session.
func (*Store) State ¶
func (s *Store) State() ClusterState
State returns the current node's Raft state.
func (*Store) Statistics ¶
Statistics returns statistics for periodic monitoring.
func (*Store) UpdateAPIPeers ¶
UpdateAPIPeers updates the cluster-wide peer information.
func (*Store) ViewPrefix ¶
ViewPrefix views bucket by keyPerfix.