store

package
v0.0.0-...-90db793 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SET = "set"
	GET = "get"
	DEL = "del"
)

Variables

View Source
var (

	// An error indicating a given key does not exist
	ErrKeyNotFound    = errors.New("not found")
	ErrBucketNotFound = errors.New("bucket is not exist")
)

buckets

View Source
var (
	Timeout = 10 * time.Second

	DataName = "raft.db"
)
View Source
var (
	ErrUnknownCommand = errors.New("unknown command")
)

Functions

This section is empty.

Types

type BoltDB

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

func NewBoltDB

func NewBoltDB(path string) (*BoltDB, error)

func (*BoltDB) Bucket

func (b *BoltDB) Bucket(name []byte) *Bucket

func (*BoltDB) Close

func (b *BoltDB) Close() error

func (*BoltDB) DeleteRange

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

DeleteRange deletes a range of log entries. The range is inclusive.

func (*BoltDB) FirstIndex

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

FirstIndex returns the first index written. 0 for no entries.

func (*BoltDB) Get

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

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

func (*BoltDB) GetLog

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

GetLog gets a log entry at a given index.

func (*BoltDB) GetUint64

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

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

func (*BoltDB) LastIndex

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

LastIndex returns the last index written. 0 for no entries.

func (*BoltDB) Set

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

func (*BoltDB) SetUint64

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

func (*BoltDB) StoreLog

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

StoreLog stores a log entry.

func (*BoltDB) StoreLogs

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

StoreLogs stores multiple log entries.

type Bucket

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

func (*Bucket) AllData

func (b *Bucket) AllData() (<-chan *Item, error)

func (*Bucket) Del

func (b *Bucket) Del(key []byte) error

func (*Bucket) Get

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

func (*Bucket) Set

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

type Command

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

type FSM

type FSM struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

FSM provides an interface that can be implemented by clients to make use of the replicated log.

func NewFSM

func NewFSM(rb *BoltDB) (*FSM, error)

func (*FSM) Apply

func (f *FSM) Apply(log *raft.Log) interface{}

Apply log is invoked once a log entry is committed. It returns a value which will be made available in the ApplyFuture returned by Raft.Apply method if that method was called on the same Raft node as the FSM.

func (*FSM) Restore

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

Restore is used to restore an FSM from a snapshot. It is not called concurrently with any other command. The FSM must discard all previous state.

func (*FSM) Snapshot

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

Snapshot is used to support log compaction. This call should return an FSMSnapshot which can be used to save a point-in-time snapshot of the FSM. Apply and Snapshot are not called in multiple threads, but Apply will be called concurrently with Persist. This means the FSM should be implemented in a fashion that allows for concurrent updates while a snapshot is happening.

type FSMSnapshot

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

FSMSnapshot is returned by an FSM in response to a Snapshot It must be safe to invoke FSMSnapshot methods with concurrent calls to Apply.

func (*FSMSnapshot) Persist

func (f *FSMSnapshot) Persist(sink raft.SnapshotSink) error

Persist should dump all necessary state to the WriteCloser 'sink', and call sink.Close() when finished or call sink.Cancel() on error.

func (*FSMSnapshot) Release

func (f *FSMSnapshot) Release()

Release is invoked when we are finished with the snapshot.

type Item

type Item struct {
	Err   error  `json:"-"`
	Key   []byte `json:"key"`
	Value []byte `json:"value"`
}

type Logger

type Logger struct {
}

func (*Logger) Write

func (l *Logger) Write(bs []byte) (int, error)

type Options

type Options struct {
	// store path
	Path string
}

boltdb option

func NewOptions

func NewOptions(path string) (*Options, error)

type Store

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

func NewStore

func NewStore(path, localId string, localAddr string) (*Store, error)

local addr: addr:port

func (*Store) Get

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

func (*Store) Set

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

Jump to

Keyboard shortcuts

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