Documentation
¶
Index ¶
- Variables
- type DataStoreOp
- type LazyDatastore
- func (d *LazyDatastore) Activate() error
- func (d *LazyDatastore) Close() error
- func (d *LazyDatastore) Deactivate() error
- func (d *LazyDatastore) Delete(ctx context.Context, key key.Key) (err error)
- func (d *LazyDatastore) EnsureActive(op DataStoreOp) error
- func (d *LazyDatastore) Get(ctx context.Context, key key.Key) (value []byte, err error)
- func (d *LazyDatastore) GetSize(ctx context.Context, key key.Key) (size int, err error)
- func (d *LazyDatastore) Has(ctx context.Context, key key.Key) (exists bool, err error)
- func (d *LazyDatastore) Put(ctx context.Context, key key.Key, value []byte) (err error)
- func (d *LazyDatastore) Query(ctx context.Context, q query.Query) (rs query.Results, err error)
- func (d *LazyDatastore) Sync(ctx context.Context, prefix key.Key) error
- type StateChangeFunc
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("Datastore is closed")
Functions ¶
This section is empty.
Types ¶
type LazyDatastore ¶
type LazyDatastore struct {
// contains filtered or unexported fields
}
LazyDatastore wraps a datastore with three states: active, inactive and closed. State can be changed by three StateChangeFuncs: activateFn, deactivateFn and closeFn. The relationship between states and StateChangeFuncs is as follows:
----------(deactivateFn)---------- | | -(ensureActive)- V | | |
inactive -----(activateFn)------> active <------------
| | --(closeFn)-> closed <-(closeFn)--
Every datastore operation will check that the datastore is in the `active` state or try to activate it with the `activateFn` StateChangeFunc, an error will occur if it fails.
func NewLazyDataStore ¶
func NewLazyDataStore(wrapped datastore.Datastore, activateFn, deactivateFn, closeFn StateChangeFunc, ) (*LazyDatastore, error)
NewLazyDataStore creates a LazyStore.
func (*LazyDatastore) Activate ¶
func (d *LazyDatastore) Activate() error
Activate the LazyDatastore. It doesn't ensure that LazyDatastore will be kept in `active` state, use EnsureActive for that.
func (*LazyDatastore) Close ¶
func (d *LazyDatastore) Close() error
Close the LazyDatastore. Return `ErrClosed` if already closed. Close will NOT call `wrapped`'s closer, `closeFn` should do it.
func (*LazyDatastore) Deactivate ¶
func (d *LazyDatastore) Deactivate() error
Deactivate the LazyDatastore.
func (*LazyDatastore) EnsureActive ¶
func (d *LazyDatastore) EnsureActive(op DataStoreOp) error
EnsureActive makes sure that LazyDatastore is in active state and runs a DataStoreOp. It returns an error if it fails to activate the wrapped Datastore or `op` returns an error.
type StateChangeFunc ¶
type StateChangeFunc func(ds datastore.Datastore) error
StateChangeFunc is a function that change a LazyStore's state