mount

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2020 License: MIT Imports: 8 Imported by: 21

Documentation

Overview

Package mount provides a Datastore that has other Datastores mounted at various key prefixes and is threadsafe

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoMount = errors.New("no datastore mounted for this key")
)

Functions

This section is empty.

Types

type Datastore

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

Datastore is a mount datastore. In this datastore, keys live under the most specific mounted sub-datastore. That is, given sub-datastores mounted under:

* / * /foo * /foo/bar

Keys would be written as follows:

* /foo, /foobar, /baz would all live under /. * /foo/baz, /foo/bar, etc. would live under /foo. * /foo/bar/baz would live under /foo/bar.

Additionally, even if the datastore mounted at / contains the key /foo/thing, the datastore mounted at /foo would mask this value in get, deletes, and query results.

Finally, if no root (/) mount is provided, operations on keys living outside all of the provided mounts will behave as follows:

* Get - Returns datastore.ErrNotFound. * Query - Returns no results. * Put - Returns ErrNoMount.

func New

func New(mounts []Mount) *Datastore

New creates a new mount datstore from the given mounts. See the documentation on Datastore for details.

The order of the mounts does not matter, they will be applied most specific to least specific.

func (*Datastore) Batch

func (d *Datastore) Batch() (ds.Batch, error)

Batch returns a batch that operates over all mounted datastores.

func (*Datastore) Check

func (d *Datastore) Check() error

func (*Datastore) Close

func (d *Datastore) Close() error

Close closes all mounted datastores.

func (*Datastore) CollectGarbage

func (d *Datastore) CollectGarbage() error

func (*Datastore) Delete

func (d *Datastore) Delete(key ds.Key) error

Delete deletes the value associated with the key in the appropriate datastore.

Delete returns no error if there is no value associated with the given key.

func (*Datastore) DiskUsage

func (d *Datastore) DiskUsage() (uint64, error)

DiskUsage returns the sum of DiskUsages for the mounted datastores. Non PersistentDatastores will not be accounted.

func (*Datastore) Get

func (d *Datastore) Get(key ds.Key) (value []byte, err error)

Get returns the value associated with the key from the appropriate datastore.

func (*Datastore) GetSize

func (d *Datastore) GetSize(key ds.Key) (size int, err error)

Get returns the size of the value associated with the key in the appropriate datastore.

func (*Datastore) Has

func (d *Datastore) Has(key ds.Key) (exists bool, err error)

Has returns the true if there exists a value associated with key in the appropriate datastore.

func (*Datastore) Put

func (d *Datastore) Put(key ds.Key, value []byte) error

Put puts the given value into the datastore at the given key.

Returns ErrNoMount if there no datastores are mounted at the appropriate prefix for the given key.

func (*Datastore) Query

func (d *Datastore) Query(master query.Query) (query.Results, error)

Query queries the appropriate mounted datastores, merging the results according to the given orders.

If a query prefix is specified, Query will avoid querying datastores mounted outside that prefix.

func (*Datastore) Scrub

func (d *Datastore) Scrub() error

func (*Datastore) Sync added in v0.3.0

func (d *Datastore) Sync(prefix ds.Key) error

Sync implements Datastore.Sync

type Mount

type Mount struct {
	Prefix    ds.Key
	Datastore ds.Datastore
}

Mount defines a datastore mount. It mounts the given datastore at the given prefix.

Jump to

Keyboard shortcuts

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