keyvalue

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2015 License: Apache-2.0 Imports: 9 Imported by: 10

Documentation

Overview

Package keyvalue implements a generic GraphStore for anything that implements the DB interface.

Index

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).

func Entry

func Entry(key []byte, val []byte) (*spb.Entry, error)

Entry decodes the key (assuming it was encoded by EncodeKey) into an Entry and populates its value field.

func KeyPrefix

func KeyPrefix(source *spb.VName, edgeKind string) ([]byte, error)

KeyPrefix returns a prefix to every encoded key for the given source VName and exact edgeKind. If edgeKind is "*", the prefix will match any edgeKind.

Types

type DB

type DB interface {
	io.Closer

	// ScanPrefix returns an Iterator for all key-values starting with the given
	// key prefix.  Options may be nil to use the defaults.
	ScanPrefix([]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(*Range, *Options) (Iterator, error)

	// Writer return a new write-access object
	Writer() (Writer, error)

	// NewSnapshot returns a new consistent view of the DB that can be passed as
	// an option to DB scan methods.
	NewSnapshot() Snapshot
}

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)
}

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

func (o *Options) GetSnapshot() Snapshot

GetSnapshot returns the Snapshot option or the default of nil when o==nil.

func (*Options) IsLargeRead

func (o *Options) IsLargeRead() bool

IsLargeRead returns the LargeRead option or the default of false when o==nil.

type Range

type Range struct {
	Start, End []byte
}

Range is section of contiguous keys, including Start and excluding End.

type Snapshot

type Snapshot io.Closer

Snapshot is a consistent view of the DB.

type Store

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

A Store implements the graphstore.Service interface for a keyvalue DB

func NewGraphStore

func NewGraphStore(db DB) *Store

NewGraphStore returns a graphstore.Service backed by the given keyvalue DB.

func (*Store) Close

func (s *Store) Close(ctx context.Context) error

Close implements part of the graphstore.Service interface.

func (*Store) Count

func (s *Store) Count(ctx context.Context, req *spb.CountRequest) (int64, error)

Count implements part of the graphstore.Sharded interface.

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.

func (*Store) Write

func (s *Store) Write(ctx context.Context, req *spb.WriteRequest) (err error)

Write implements part of the GraphStore interface.

type Writer

type Writer interface {
	io.Closer

	// Write writes a key-value entry to the DB. Writes may be batched until the
	// Writer is Closed.
	Write(key, val []byte) error
}

Writer provides write access to a DB. Writes must be Closed when no longer used to ensure that resources are not leaked.

Jump to

Keyboard shortcuts

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