Documentation ¶
Index ¶
- Constants
- Variables
- func DiskUsage(ctx context.Context, d Datastore) (uint64, error)
- func GetBackedHas(ctx context.Context, ds Read, key Key) (bool, error)
- func GetBackedSize(ctx context.Context, ds Read, key Key) (int, error)
- func NamespaceType(namespace string) string
- func NamespaceValue(namespace string) string
- type Batch
- type Batching
- type BatchingFeature
- type CheckedDatastore
- type CheckedFeature
- type Datastore
- type Feature
- type GCDatastore
- type GCFeature
- type Key
- func (k Key) BaseNamespace() string
- func (k Key) Bytes() []byte
- func (k Key) Child(k2 Key) Key
- func (k Key) ChildString(s string) Key
- func (k *Key) Clean()
- func (k Key) Equal(k2 Key) bool
- func (k Key) Instance(s string) Key
- func (k Key) IsAncestorOf(other Key) bool
- func (k Key) IsDescendantOf(other Key) bool
- func (k Key) IsTopLevel() bool
- func (k Key) Less(k2 Key) bool
- func (k Key) List() []string
- func (k Key) MarshalJSON() ([]byte, error)
- func (k Key) Name() string
- func (k Key) Namespaces() []string
- func (k Key) Parent() Key
- func (k Key) Path() Key
- func (k Key) Reverse() Key
- func (k Key) String() string
- func (k Key) Type() string
- func (k *Key) UnmarshalJSON(data []byte) error
- type KeySlice
- type LogBatch
- type LogDatastore
- func (d *LogDatastore) Batch(ctx context.Context) (Batch, error)
- func (d *LogDatastore) Check(ctx context.Context) error
- func (d *LogDatastore) Children() []Datastore
- func (d *LogDatastore) Close() error
- func (d *LogDatastore) CollectGarbage(ctx context.Context) error
- func (d *LogDatastore) Delete(ctx context.Context, key Key) (err error)
- func (d *LogDatastore) DiskUsage(ctx context.Context) (uint64, error)
- func (d *LogDatastore) Get(ctx context.Context, key Key) (value []byte, err error)
- func (d *LogDatastore) GetSize(ctx context.Context, key Key) (size int, err error)
- func (d *LogDatastore) Has(ctx context.Context, key Key) (exists bool, err error)
- func (d *LogDatastore) Put(ctx context.Context, key Key, value []byte) (err error)
- func (d *LogDatastore) Query(ctx context.Context, q dsq.Query) (dsq.Results, error)
- func (d *LogDatastore) Scrub(ctx context.Context) error
- func (d *LogDatastore) Sync(ctx context.Context, prefix Key) error
- type MapDatastore
- func (d *MapDatastore) Batch(ctx context.Context) (Batch, error)
- func (d *MapDatastore) Close() error
- func (d *MapDatastore) Delete(ctx context.Context, key Key) (err error)
- func (d *MapDatastore) Get(ctx context.Context, key Key) (value []byte, err error)
- func (d *MapDatastore) GetSize(ctx context.Context, key Key) (size int, err error)
- func (d *MapDatastore) Has(ctx context.Context, key Key) (exists bool, err error)
- func (d *MapDatastore) Put(ctx context.Context, key Key, value []byte) (err error)
- func (d *MapDatastore) Query(ctx context.Context, q dsq.Query) (dsq.Results, error)
- func (d *MapDatastore) Sync(ctx context.Context, prefix Key) error
- type NullDatastore
- func (d *NullDatastore) Batch(ctx context.Context) (Batch, error)
- func (d *NullDatastore) Check(ctx context.Context) error
- func (d *NullDatastore) Close() error
- func (d *NullDatastore) CollectGarbage(ctx context.Context) error
- func (d *NullDatastore) Delete(ctx context.Context, key Key) (err error)
- func (d *NullDatastore) DiskUsage(ctx context.Context) (uint64, error)
- func (d *NullDatastore) Get(ctx context.Context, key Key) (value []byte, err error)
- func (d *NullDatastore) GetSize(ctx context.Context, key Key) (size int, err error)
- func (d *NullDatastore) Has(ctx context.Context, key Key) (exists bool, err error)
- func (d *NullDatastore) NewTransaction(ctx context.Context, readOnly bool) (Txn, error)
- func (d *NullDatastore) Put(ctx context.Context, key Key, value []byte) (err error)
- func (d *NullDatastore) Query(ctx context.Context, q dsq.Query) (dsq.Results, error)
- func (d *NullDatastore) Scrub(ctx context.Context) error
- func (d *NullDatastore) Sync(ctx context.Context, prefix Key) error
- type PersistentDatastore
- type PersistentFeature
- type Read
- type ScrubbedDatastore
- type ScrubbedFeature
- type Shim
- type TTL
- type TTLDatastore
- type Txn
- type TxnDatastore
- type TxnFeature
- type Write
Constants ¶
const ( FeatureNameBatching = "Batching" FeatureNameChecked = "Checked" FeatureNameGC = "GC" FeatureNamePersistent = "Persistent" FeatureNameScrubbed = "Scrubbed" FeatureNameTTL = "TTL" FeatureNameTransaction = "Transaction" )
Variables ¶
var ErrBatchUnsupported = errors.New("this datastore does not support batching")
ErrBatchUnsupported is returned if the by Batch if the Datastore doesn't actually support batching.
var ErrNotFound error = &dsError{error: errors.New("datastore: key not found"), isNotFound: true}
ErrNotFound is returned by Get and GetSize when a datastore does not map the given key to a value.
Functions ¶
func DiskUsage ¶
DiskUsage checks if a Datastore is a PersistentDatastore and returns its DiskUsage(), otherwise returns 0.
func GetBackedHas ¶
GetBackedHas provides a default Datastore.Has implementation. It exists so Datastore.Has implementations can use it, like so:
func (*d SomeDatastore) Has(key Key) (exists bool, err error) { return GetBackedHas(d, key) }
func GetBackedSize ¶
GetBackedSize provides a default Datastore.GetSize implementation. It exists so Datastore.GetSize implementations can use it, like so:
func (*d SomeDatastore) GetSize(key Key) (size int, err error) { return GetBackedSize(d, key) }
func NamespaceType ¶
NamespaceType is the first component of a namespace. `foo` in `foo:bar`
func NamespaceValue ¶
NamespaceValue returns the last component of a namespace. `baz` in `f:b:baz`
Types ¶
type Batch ¶
func NewBasicBatch ¶
type Batching ¶
type Batching interface { Datastore BatchingFeature }
Batching datastores support deferred, grouped updates to the database. `Batch`es do NOT have transactional semantics: updates to the underlying datastore are not guaranteed to occur in the same iota of time. Similarly, batched updates will not be flushed to the underlying datastore until `Commit` has been called. `Txn`s from a `TxnDatastore` have all the capabilities of a `Batch`, but the reverse is NOT true.
type BatchingFeature ¶ added in v0.6.0
type CheckedDatastore ¶
type CheckedDatastore interface { Datastore CheckedFeature }
CheckedDatastore is an interface that should be implemented by datastores which may need checking on-disk data integrity.
type CheckedFeature ¶ added in v0.6.0
type Datastore ¶
type Datastore interface { Read Write // Sync guarantees that any Put or Delete calls under prefix that returned // before Sync(prefix) was called will be observed after Sync(prefix) // returns, even if the program crashes. If Put/Delete operations already // satisfy these requirements then Sync may be a no-op. // // If the prefix fails to Sync this method returns an error. Sync(ctx context.Context, prefix Key) error io.Closer }
Datastore represents storage for any key-value pair.
Datastores are general enough to be backed by all kinds of different storage: in-memory caches, databases, a remote datastore, flat files on disk, etc.
The general idea is to wrap a more complicated storage facility in a simple, uniform interface, keeping the freedom of using the right tools for the job. In particular, a Datastore can aggregate other datastores in interesting ways, like sharded (to distribute load) or tiered access (caches before databases).
While Datastores should be written general enough to accept all sorts of values, some implementations will undoubtedly have to be specific (e.g. SQL databases where fields should be decomposed into columns), particularly to support queries efficiently. Moreover, certain datastores may enforce certain types of values (e.g. requiring an io.Reader, a specific struct, etc) or serialization formats (JSON, Protobufs, etc).
IMPORTANT: No Datastore should ever Panic! This is a cross-module interface, and thus it should behave predictably and handle exceptional conditions with proper error reporting. Thus, all Datastore calls may return errors, which should be checked by callers.
type Feature ¶ added in v0.6.0
type Feature struct { Name string // Interface is the nil interface of the feature. Interface interface{} // DatastoreInterface is the nil interface of the feature's corresponding datastore interface. DatastoreInterface interface{} }
Feature contains metadata about a datastore Feature.
func FeatureByName ¶ added in v0.6.0
FeatureByName returns the feature with the given name, if known.
func Features ¶ added in v0.6.0
func Features() []Feature
Features returns a list of all known datastore features. This serves both to provide an authoritative list of features, and to define a canonical ordering of features.
func FeaturesForDatastore ¶ added in v0.6.0
FeaturesForDatastore returns the features supported by the given datastore.
type GCDatastore ¶
GCDatastore is an interface that should be implemented by datastores which don't free disk space by just removing data from them.
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
A Key represents the unique identifier of an object. Our Key scheme is inspired by file systems and Google App Engine key model.
Keys are meant to be unique across a system. Keys are hierarchical, incorporating more and more specific namespaces. Thus keys can be deemed 'children' or 'ancestors' of other keys::
Key("/Comedy") Key("/Comedy/MontyPython")
Also, every namespace can be parametrized to embed relevant object information. For example, the Key `name` (most specific namespace) could include the object type::
Key("/Comedy/MontyPython/Actor:JohnCleese") Key("/Comedy/MontyPython/Sketch:CheeseShop") Key("/Comedy/MontyPython/Sketch:CheeseShop/Character:Mousebender")
func KeyWithNamespaces ¶
KeyWithNamespaces constructs a key out of a namespace slice.
func RandomKey ¶
func RandomKey() Key
RandomKey returns a randomly (uuid) generated key.
RandomKey() NewKey("/f98719ea086343f7b71f32ea9d9d521d")
func (Key) BaseNamespace ¶
BaseNamespace returns the "base" namespace of this key (path.Base(filename))
NewKey("/Comedy/MontyPython/Actor:JohnCleese").BaseNamespace() "Actor:JohnCleese"
func (Key) Child ¶
Child returns the `child` Key of this Key.
NewKey("/Comedy/MontyPython").Child(NewKey("Actor:JohnCleese")) NewKey("/Comedy/MontyPython/Actor:JohnCleese")
func (Key) ChildString ¶
ChildString returns the `child` Key of this Key -- string helper.
NewKey("/Comedy/MontyPython").ChildString("Actor:JohnCleese") NewKey("/Comedy/MontyPython/Actor:JohnCleese")
func (Key) Instance ¶
Instance returns an "instance" of this type key (appends value to namespace).
NewKey("/Comedy/MontyPython/Actor").Instance("JohnClesse") NewKey("/Comedy/MontyPython/Actor:JohnCleese")
func (Key) IsAncestorOf ¶
IsAncestorOf returns whether this key is a prefix of `other`
NewKey("/Comedy").IsAncestorOf("/Comedy/MontyPython") true
func (Key) IsDescendantOf ¶
IsDescendantOf returns whether this key contains another as a prefix.
NewKey("/Comedy/MontyPython").IsDescendantOf("/Comedy") true
func (Key) IsTopLevel ¶
IsTopLevel returns whether this key has only one namespace.
func (Key) List ¶
List returns the `list` representation of this Key.
NewKey("/Comedy/MontyPython/Actor:JohnCleese").List() ["Comedy", "MontyPythong", "Actor:JohnCleese"]
func (Key) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface, keys are represented as JSON strings
func (Key) Name ¶
Name returns the "name" of this key (field of last namespace).
NewKey("/Comedy/MontyPython/Actor:JohnCleese").Name() "JohnCleese"
func (Key) Namespaces ¶
Namespaces returns the `namespaces` making up this Key.
NewKey("/Comedy/MontyPython/Actor:JohnCleese").Namespaces() ["Comedy", "MontyPython", "Actor:JohnCleese"]
func (Key) Parent ¶
Parent returns the `parent` Key of this Key.
NewKey("/Comedy/MontyPython/Actor:JohnCleese").Parent() NewKey("/Comedy/MontyPython")
func (Key) Path ¶
Path returns the "path" of this key (parent + type).
NewKey("/Comedy/MontyPython/Actor:JohnCleese").Path() NewKey("/Comedy/MontyPython/Actor")
func (Key) Reverse ¶
Reverse returns the reverse of this Key.
NewKey("/Comedy/MontyPython/Actor:JohnCleese").Reverse() NewKey("/Actor:JohnCleese/MontyPython/Comedy")
func (Key) Type ¶
Type returns the "type" of this key (value of last namespace).
NewKey("/Comedy/MontyPython/Actor:JohnCleese").Type() "Actor"
func (*Key) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface, keys will parse any value specified as a key to a string
type KeySlice ¶
type KeySlice []Key
KeySlice attaches the methods of sort.Interface to []Key, sorting in increasing order.
type LogBatch ¶
type LogBatch struct { Name string // contains filtered or unexported fields }
LogBatch logs all accesses through the batch.
type LogDatastore ¶
type LogDatastore struct { Name string // contains filtered or unexported fields }
LogDatastore logs all accesses through the datastore.
func NewLogDatastore ¶
func NewLogDatastore(ds Datastore, name string) *LogDatastore
NewLogDatastore constructs a log datastore.
func (*LogDatastore) Children ¶
func (d *LogDatastore) Children() []Datastore
Children implements Shim
func (*LogDatastore) Close ¶
func (d *LogDatastore) Close() error
func (*LogDatastore) CollectGarbage ¶
func (d *LogDatastore) CollectGarbage(ctx context.Context) error
func (*LogDatastore) Delete ¶
func (d *LogDatastore) Delete(ctx context.Context, key Key) (err error)
Delete implements Datastore.Delete
func (*LogDatastore) DiskUsage ¶
func (d *LogDatastore) DiskUsage(ctx context.Context) (uint64, error)
DiskUsage implements the PersistentDatastore interface.
type MapDatastore ¶
type MapDatastore struct {
// contains filtered or unexported fields
}
MapDatastore uses a standard Go map for internal storage.
func NewMapDatastore ¶
func NewMapDatastore() (d *MapDatastore)
NewMapDatastore constructs a MapDatastore. It is _not_ thread-safe by default, wrap using sync.MutexWrap if you need thread safety (the answer here is usually yes).
func (*MapDatastore) Close ¶
func (d *MapDatastore) Close() error
func (*MapDatastore) Delete ¶
func (d *MapDatastore) Delete(ctx context.Context, key Key) (err error)
Delete implements Datastore.Delete
type NullDatastore ¶
type NullDatastore struct { }
NullDatastore stores nothing, but conforms to the API. Useful to test with.
func NewNullDatastore ¶
func NewNullDatastore() *NullDatastore
NewNullDatastore constructs a null datastoe
func (*NullDatastore) Check ¶ added in v0.6.0
func (d *NullDatastore) Check(ctx context.Context) error
func (*NullDatastore) Close ¶
func (d *NullDatastore) Close() error
func (*NullDatastore) CollectGarbage ¶ added in v0.6.0
func (d *NullDatastore) CollectGarbage(ctx context.Context) error
func (*NullDatastore) Delete ¶
func (d *NullDatastore) Delete(ctx context.Context, key Key) (err error)
Delete implements Datastore.Delete
func (*NullDatastore) DiskUsage ¶ added in v0.6.0
func (d *NullDatastore) DiskUsage(ctx context.Context) (uint64, error)
func (*NullDatastore) NewTransaction ¶ added in v0.6.0
type PersistentDatastore ¶
type PersistentDatastore interface { Datastore PersistentFeature }
PersistentDatastore is an interface that should be implemented by datastores which can report disk usage.
type PersistentFeature ¶ added in v0.6.0
type Read ¶
type Read interface { // Get retrieves the object `value` named by `key`. // Get will return ErrNotFound if the key is not mapped to a value. Get(ctx context.Context, key Key) (value []byte, err error) // Has returns whether the `key` is mapped to a `value`. // In some contexts, it may be much cheaper only to check for existence of // a value, rather than retrieving the value itself. (e.g. HTTP HEAD). // The default implementation is found in `GetBackedHas`. Has(ctx context.Context, key Key) (exists bool, err error) // GetSize returns the size of the `value` named by `key`. // In some contexts, it may be much cheaper to only get the size of the // value rather than retrieving the value itself. GetSize(ctx context.Context, key Key) (size int, err error) // Query searches the datastore and returns a query result. This function // may return before the query actually runs. To wait for the query: // // result, _ := ds.Query(q) // // // use the channel interface; result may come in at different times // for entry := range result.Next() { ... } // // // or wait for the query to be completely done // entries, _ := result.Rest() // for entry := range entries { ... } // Query(ctx context.Context, q query.Query) (query.Results, error) }
Read is the read-side of the Datastore interface.
type ScrubbedDatastore ¶
type ScrubbedDatastore interface { Datastore ScrubbedFeature }
ScrubbedDatastore is an interface that should be implemented by datastores which want to provide a mechanism to check data integrity and/or error correction.
type ScrubbedFeature ¶ added in v0.6.0
type TTL ¶
type TTL interface { PutWithTTL(ctx context.Context, key Key, value []byte, ttl time.Duration) error SetTTL(ctx context.Context, key Key, ttl time.Duration) error GetExpiration(ctx context.Context, key Key) (time.Time, error) }
TTL encapulates the methods that deal with entries with time-to-live.
type TTLDatastore ¶
TTLDatastore is an interface that should be implemented by datastores that support expiring entries.
type Txn ¶
type Txn interface { Read Write // Commit finalizes a transaction, attempting to commit it to the Datastore. // May return an error if the transaction has gone stale. The presence of an // error is an indication that the data was not committed to the Datastore. Commit(ctx context.Context) error // Discard throws away changes recorded in a transaction without committing // them to the underlying Datastore. Any calls made to Discard after Commit // has been successfully called will have no effect on the transaction and // state of the Datastore, making it safe to defer. Discard(ctx context.Context) }
Txn extends the Datastore type. Txns allow users to batch queries and mutations to the Datastore into atomic groups, or transactions. Actions performed on a transaction will not take hold until a successful call to Commit has been made. Likewise, transactions can be aborted by calling Discard before a successful Commit has been made.
type TxnDatastore ¶
type TxnDatastore interface { Datastore TxnFeature }
TxnDatastore is an interface that should be implemented by datastores that support transactions.
type TxnFeature ¶ added in v0.6.0
type Write ¶
type Write interface { // Put stores the object `value` named by `key`. // // The generalized Datastore interface does not impose a value type, // allowing various datastore middleware implementations (which do not // handle the values directly) to be composed together. // // Ultimately, the lowest-level datastore will need to do some value checking // or risk getting incorrect values. It may also be useful to expose a more // type-safe interface to your application, and do the checking up-front. Put(ctx context.Context, key Key, value []byte) error // Delete removes the value for given `key`. If the key is not in the // datastore, this method returns no error. Delete(ctx context.Context, key Key) error }
Write is the write-side of the Datastore interface.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package autobatch provides a go-datastore implementation that automatically batches together writes by holding puts in memory until a certain threshold is met.
|
Package autobatch provides a go-datastore implementation that automatically batches together writes by holding puts in memory until a certain threshold is met. |
Package delayed wraps a datastore allowing to artificially delay all operations.
|
Package delayed wraps a datastore allowing to artificially delay all operations. |
Package fs is a simple Datastore implementation that stores keys as directories and files, mirroring the key.
|
Package fs is a simple Datastore implementation that stores keys as directories and files, mirroring the key. |
Package failstore implements a datastore which can produce custom failures on operations by calling a user-provided error function.
|
Package failstore implements a datastore which can produce custom failures on operations by calling a user-provided error function. |
fuzz
module
|
|
Package keytransform introduces a Datastore Shim that transforms keys before passing them to its child.
|
Package keytransform introduces a Datastore Shim that transforms keys before passing them to its child. |
Package mount provides a Datastore that has other Datastores mounted at various key prefixes and is threadsafe
|
Package mount provides a Datastore that has other Datastores mounted at various key prefixes and is threadsafe |
Package namespace introduces a namespace Datastore Shim, which basically mounts the entire child datastore under a prefix.
|
Package namespace introduces a namespace Datastore Shim, which basically mounts the entire child datastore under a prefix. |
Package retrystore provides a datastore wrapper which allows to retry operations.
|
Package retrystore provides a datastore wrapper which allows to retry operations. |