Documentation ¶
Overview ¶
Package storage contains objects for storing decided value and consensus state to disk, or in memory if desired.
Index ¶
- type ConsDiskstore
- func (cs *ConsDiskstore) Clear() error
- func (cs *ConsDiskstore) Close() error
- func (cs *ConsDiskstore) Contains(key interface{}) bool
- func (cs *ConsDiskstore) DeleteFile() error
- func (cs *ConsDiskstore) Range(f func(key interface{}, state, decision []byte) bool)
- func (cs *ConsDiskstore) Read(key interface{}) ([]byte, []byte, error)
- func (cs *ConsDiskstore) Write(key interface{}, state []byte, decision []byte) error
- type ConsMemstore
- func (cs *ConsMemstore) Clear() error
- func (cs *ConsMemstore) Close() error
- func (cs *ConsMemstore) Contains(key interface{}) bool
- func (cs *ConsMemstore) DeleteFile() error
- func (cs *ConsMemstore) Range(f func(key interface{}, state, decision []byte) bool)
- func (cs *ConsMemstore) Read(key interface{}) ([]byte, []byte, error)
- func (cs *ConsMemstore) Write(key interface{}, state []byte, decision []byte) error
- type ConsensusIDType
- type DiskStoreHash
- type DiskStoreUint64
- type Diskstore
- func (ds *Diskstore) Clear() error
- func (ds *Diskstore) Close() error
- func (ds *Diskstore) Contains(key interface{}) bool
- func (ds *Diskstore) Init(unmarshalFunc func([]byte) (interface{}, error), keySize int, name string, ...) error
- func (ds *Diskstore) InitClear(unmarshalFunc func([]byte) (interface{}, error), keySize int, name string, ...) error
- func (ds *Diskstore) Range(f func(key interface{}, value []byte) bool)
- func (ds *Diskstore) Read(key interface{}) ([]byte, error)
- func (ds *Diskstore) Write(key encoding.BinaryMarshaler, val []byte) error
- type StoreInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConsDiskstore ¶
type ConsDiskstore struct {
// contains filtered or unexported fields
}
ConsDiskstore is the interface to store decided values on disk.
func NewConsDiskStore ¶
func NewConsDiskStore(name string, keyType ConsensusIDType, bufferSize int) (*ConsDiskstore, error)
NewConsDiskStore creates a new disk storage, at the file name in the current directory, for the give key type and buffer size in bytes.
func (*ConsDiskstore) Clear ¶
func (cs *ConsDiskstore) Clear() error
Clear deletes all stored keys and values.
func (*ConsDiskstore) Contains ¶
func (cs *ConsDiskstore) Contains(key interface{}) bool
Contains returns true is the key is contained in the map.
func (*ConsDiskstore) DeleteFile ¶
func (cs *ConsDiskstore) DeleteFile() error
DeleteFile removes the storage file used for this item.
func (*ConsDiskstore) Range ¶
func (cs *ConsDiskstore) Range(f func(key interface{}, state, decision []byte) bool)
func (*ConsDiskstore) Read ¶
func (cs *ConsDiskstore) Read(key interface{}) ([]byte, []byte, error)
Read returns the values stored for the consensus decision at index key. See Write for the description of what the values represent.
func (*ConsDiskstore) Write ¶
func (cs *ConsDiskstore) Write(key interface{}, state []byte, decision []byte) error
Write stores for consensus index key the state of the consensus and the decided value. The state should be all the messages needed to reply the consensus and decide the same value. Writing the same key twice overwrites the old value.
type ConsMemstore ¶
type ConsMemstore struct {
// contains filtered or unexported fields
}
ConsMemstore represnets consensus storage in memory.
func NewConsMemStore ¶
func NewConsMemStore(keyType ConsensusIDType) *ConsMemstore
NewConsMemStore creates a new
func (*ConsMemstore) Clear ¶
func (cs *ConsMemstore) Clear() error
Clear deletes all stored keys and values.
func (*ConsMemstore) Close ¶
func (cs *ConsMemstore) Close() error
Close does nothing for the memstore.
func (*ConsMemstore) Contains ¶
func (cs *ConsMemstore) Contains(key interface{}) bool
Contains returns true if key is stored in the map.
func (*ConsMemstore) DeleteFile ¶
func (cs *ConsMemstore) DeleteFile() error
DeleteFile returns nil.
func (*ConsMemstore) Range ¶
func (cs *ConsMemstore) Range(f func(key interface{}, state, decision []byte) bool)
Range go through the keys in the order they were written, calling f on them. It stops if f returns false.
func (*ConsMemstore) Read ¶
func (cs *ConsMemstore) Read(key interface{}) ([]byte, []byte, error)
Read returns the values stored for the consensus decision at index key. See Write for the description of what the values represent.
func (*ConsMemstore) Write ¶
func (cs *ConsMemstore) Write(key interface{}, state []byte, decision []byte) error
Write stores for consensus index key the state of the consensus and the decided value. The state should be all the messages needed to reply the consensus and decide the same value. Writing the same key twice overwrites the old value.
type ConsensusIDType ¶
type ConsensusIDType int
const ( ConsensusIndexKey ConsensusIDType = iota HashKey )
type DiskStoreHash ¶
type DiskStoreHash struct {
Diskstore
}
func InitDiskStoreHash ¶
func InitDiskStoreHash(name string, useSnappy bool, bufferSize int) (*DiskStoreHash, error)
func (*DiskStoreHash) ContainsKey ¶
func (ds *DiskStoreHash) ContainsKey(key interface{}) bool
func (*DiskStoreHash) ReadKey ¶
func (ds *DiskStoreHash) ReadKey(key interface{}) ([]byte, error)
func (*DiskStoreHash) WriteKey ¶
func (ds *DiskStoreHash) WriteKey(key interface{}, val []byte) error
type DiskStoreUint64 ¶
type DiskStoreUint64 struct {
Diskstore
}
func InitDiskStoreUint64 ¶
func InitDiskStoreUint64(name string, useSnappy bool, bufferSize int) (*DiskStoreUint64, error)
func (*DiskStoreUint64) ContainsKey ¶
func (ds *DiskStoreUint64) ContainsKey(key interface{}) bool
func (*DiskStoreUint64) ReadKey ¶
func (ds *DiskStoreUint64) ReadKey(key interface{}) ([]byte, error)
func (*DiskStoreUint64) WriteKey ¶
func (ds *DiskStoreUint64) WriteKey(key interface{}, val []byte) error
type Diskstore ¶
type Diskstore struct {
// contains filtered or unexported fields
}
Diskstore represents a simple key/value disk storage. It works using an append only file. Writing a key twice will append the new value to the end of the file, the old value will still exist, but be unaccessble. The keys and a pointer to where the value is stored on disk is kept in memory. Values are stored with their hashes and the hash is verified when the value is read. Writes can be buffered in memory if a bufferSize > 0 is used as input to the Init function. It is meant to be efficient for storing consensus decisions for example, where we store something once and keep it forever. TODO fix the error types.
func (*Diskstore) Contains ¶
Contains returns true is the key is contained in the map. It returns false if a 0 length value has been stored for the key.
func (*Diskstore) Init ¶
func (ds *Diskstore) Init(unmarshalFunc func([]byte) (interface{}, error), keySize int, name string, useSnappy bool, bufferSize int) error
Initialized the diskstore for file name, if to use snappy compression, and the size of the write buffer (use 0 for unbuffered). If the file exists, it checks the stored values are valid and loads meta-data into memory.
func (*Diskstore) InitClear ¶
func (ds *Diskstore) InitClear(unmarshalFunc func([]byte) (interface{}, error), keySize int, name string, useSnappy bool, bufferSize int) error
InitClear is the same as Init, expect it deletes any stored keys and values.
func (*Diskstore) Range ¶
Range go through the keys in the order they were written, calling f on them. It stops if f returns false.
type StoreInterface ¶
type StoreInterface interface { // Range go through the keys in the order they were written, calling f on them. // It stops if f returns false. Range(f func(key interface{}, state, decision []byte) bool) Read(key interface{}) (state, decision []byte, err error) // Read returns the values stored for the consensus decision at index key. See Write for the description of what the values represent. Contains(key interface{}) bool // Contains returns true if key is stored in the map. Close() error // Close closes the storage. Clear() error // Clear deletes all keys and values from the storage. Write(key interface{}, state []byte, decision []byte) error // Write stores for consensus index key the state of the consensus and the decided value. The state should be all the messages needed to reply the consensus and decide the same value. Writing the same key twice overwrites the old value. DeleteFile() error // DeleteFile removes the storage file used for this item. }
StoreInterface is the interface used by the consensus to store decidede values and consensus state to disk (or memory).