Documentation ¶
Overview ¶
Package keyvalue implements a generic GraphStore for anything that implements the DB interface.
Index ¶
- func EncodeKey(source *spb.VName, factName string, edgeKind string, target *spb.VName) ([]byte, error)
- func Entry(key []byte, val []byte) (*spb.Entry, error)
- func KeyPrefix(source *spb.VName, edgeKind string) ([]byte, error)
- type DB
- type Iterator
- type Options
- type PoolOptions
- type Range
- type Snapshot
- type Store
- func (s *Store) Close(ctx context.Context) error
- func (s *Store) Count(ctx context.Context, req *spb.CountRequest) (int64, error)
- func (s *Store) Read(ctx context.Context, req *spb.ReadRequest, f graphstore.EntryFunc) error
- func (s *Store) Scan(ctx context.Context, req *spb.ScanRequest, f graphstore.EntryFunc) error
- func (s *Store) Shard(ctx context.Context, req *spb.ShardRequest, f graphstore.EntryFunc) error
- func (s *Store) Write(ctx context.Context, req *spb.WriteRequest) (err error)
- type WritePool
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeKey ¶
func EncodeKey(source *spb.VName, factName string, edgeKind string, target *spb.VName) ([]byte, error)
EncodeKey returns a canonical encoding of an Entry (minus its value).
Types ¶
type DB ¶
type DB interface { // Get returns the value associated with the given key. An io.EOF will be // returned if the key is not found. Get(context.Context, []byte, *Options) ([]byte, error) // ScanPrefix returns an Iterator for all key-values starting with the given // key prefix. Options may be nil to use the defaults. ScanPrefix(context.Context, []byte, *Options) (Iterator, error) // ScanRange returns an Iterator for all key-values starting with the given // key range. Options may be nil to use the defaults. ScanRange(context.Context, *Range, *Options) (Iterator, error) // Writer return a new write-access object Writer(context.Context) (Writer, error) // NewSnapshot returns a new consistent view of the DB that can be passed as // an option to DB scan methods. NewSnapshot(context.Context) Snapshot // Close release the underlying resources for the database. Close(context.Context) error }
A DB is a sorted key-value store with read/write access. DBs must be Closed when no longer used to ensure resources are not leaked.
type Iterator ¶
type Iterator interface { io.Closer // Next returns the currently positioned key-value entry and moves to the next // entry. If there is no key-value entry to return, an io.EOF error is // returned. Next() (key, val []byte, err error) // Seeks positions the Iterator to the given key. The key must be further // than the current Iterator's position. If the key does not exist, the // Iterator is positioned at the next existing key. If no such key exists, // io.EOF is returned. Seek(key []byte) error }
Iterator provides sequential access to a DB. Iterators must be Closed when no longer used to ensure that resources are not leaked.
type Options ¶
type Options struct { // LargeRead expresses the client's intent that the read will likely be // "large" and the implementation should usually avoid certain behaviors such // as caching the entire visited key-value range. Defaults to false. LargeRead bool // Snapshot causes the iterator to view the DB as it was at the Snapshot's // creation. Snapshot }
Options alters the behavior of an Iterator.
func (*Options) GetSnapshot ¶
GetSnapshot returns the Snapshot option or the default of nil when o==nil.
func (*Options) IsLargeRead ¶
IsLargeRead returns the LargeRead option or the default of false when o==nil.
type PoolOptions ¶ added in v0.0.16
type PoolOptions struct { // MaxWrites is the number of calls to Write before the WritePool // automatically flushes the underlying Writer. This defaults to 32000 // writes. MaxWrites int // MaxSize is the total size of the keys and values given to Write before the // WritePool automatically flushes the underlying Writer. This defaults to // 32MiB. MaxSize datasize.Size }
PoolOptions is a set of options used by WritePools.
type Range ¶
type Range struct {
Start, End []byte
}
Range is section of contiguous keys, including Start and excluding End.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
A Store implements the graphstore.Service interface for a keyvalue DB
func NewGraphStore ¶
NewGraphStore returns a graphstore.Service backed by the given keyvalue DB.
func (*Store) Read ¶
func (s *Store) Read(ctx context.Context, req *spb.ReadRequest, f graphstore.EntryFunc) error
Read implements part of the graphstore.Service interface.
func (*Store) Scan ¶
func (s *Store) Scan(ctx context.Context, req *spb.ScanRequest, f graphstore.EntryFunc) error
Scan implements part of the graphstore.Service interface.
func (*Store) Shard ¶
func (s *Store) Shard(ctx context.Context, req *spb.ShardRequest, f graphstore.EntryFunc) error
Shard implements part of the graphstore.Sharded interface.
type WritePool ¶ added in v0.0.16
type WritePool struct {
// contains filtered or unexported fields
}
WritePool is a wrapper around a DB that automatically creates and flushes Writers as data size is written, creating a simple buffered interface for writing to a DB. This interface is not thread-safe.
func NewPool ¶ added in v0.0.16
func NewPool(db DB, opts *PoolOptions) *WritePool
NewPool returns a new WritePool for the given DB. If opts==nil, its defaults are used.