Documentation
¶
Overview ¶
Package data pkg/cxo/data/cxds.go c2-net-cxo
Package data pkg/cxo/data/data.go c2-net-cxo
Package data pkg/cxo/data/idxdb.go c2-net-cxo
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrStopIteration = errors.New("stop iteration") ErrNoSuchFeed = errors.New("no such feed") ErrNoSuchHead = errors.New("no such head") ErrInvalidSize = errors.New("invalid size of encoded data") )
common errors
Functions ¶
This section is empty.
Types ¶
type CXDS ¶
type CXDS interface {
// Get and change references counter (rc). If the
// inc argument is zero then the rc will be leaved
// as is. If value with given key doesn't exist, then
// the Get method returns (nil, 0, data.ErrNotFound).
// Use negative inc argument to reduce the rc and
// positive to increase it
Get(key cipher.SHA256, inc int) (val []byte, rc uint32, err error)
// Set and change references counter (rc). If the inc
// argument is negative or zero, then the Set method
// panics. Other words, the Set method used to create
// and increase the rc (increase at least by one). E.g.
// it's impossible to set vlaue with zero-rc
Set(key cipher.SHA256, val []byte, inc int) (rc uint32, err error)
// Inc increments or decrements (if given inc is negative)
// references count for value with given key. If given
// inc argument is zero, then the Inc method checks
// presence of the value. E.g. if it returns ErrNotFound
// then value doesn't exist. The Inc returns new rc
Inc(key cipher.SHA256, inc int) (rc uint32, err error)
// Iterate all keys in CXDS. The rc is refs count.
// Use ErrStopIteration to stop an iteration.
Iterate(iterateFunc IterateObjectsFunc) (err error)
// IterateDel used to remove objects
IterateDel(iterateFunc IterateObjectsDelFunc) (err error)
// Del removes object with given key unconditionally.
// The Del method doesn't return an error if object
// doesn't exist
Del(key cipher.SHA256) (err error)
// RunBatch invokes fn with a CXDS handle that performs all of its
// Set/Get/Inc/Del calls inside a single underlying transaction. On
// bbolt-backed stores this collapses N writer transactions (and N
// commits) into one, which is the dominant cost on publisher
// tree-walks. The scoped handle is only valid for the duration of
// fn; using it after fn returns is undefined.
//
// fn returning nil commits the batch; a non-nil return rolls it
// back. RunBatch on stores without transaction semantics (in-memory
// CXDS) is a passthrough: fn is invoked with the receiver.
RunBatch(fn func(scoped CXDS) error) (err error)
// Amount of objects
Amount() (all, used int)
// Volume of objects
Volume() (all, used int)
// Close the CXDS
Close() (err error)
}
A CXDS is interface of CX data store. The CXDS is key-value store with references counters. There is data/cxds implementation that contains boltdb based and in-memory (golang map based) implementations of the CXDS. The CXDS returns ErrNotFound from this package if any value has not been found. The references counters is number of objects that points to an object. E.g. schema of the CXDS is
key -> {rc, val}
The CXDS keeps elements with rc == 0. End-user should track size of the DB and remove objects that doesn't used to free up space
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
A DB represents joiner of IdxDB and CXDS
type Feeds ¶
type Feeds interface {
// Add feed. Adding a feed twice or
// more times does nothing
Add(pk cipher.PubKey) (err error)
// Del feed with all heads and Root objects
// unconditionally. If feed doesn't exist
// then the Del returns ErrNoSuchFeed
Del(pk cipher.PubKey) (err error)
// Iterate all feeds. Use ErrStopRange to break
// it iteration. The Iterate passes any error
// returned from given function through. Except
// ErrStopIteration that turns nil. It's possible
// to mutate the IdxDB inside the Iterate
Iterate(iterateFunc IterateFeedsFunc) (err error)
// Has returns true if the IdxDB contains
// feed with given public key
Has(pk cipher.PubKey) (ok bool, err error)
// Heads of feed. It returns ErrNoSuchFeed
// if given feed doesn't exist
Heads(pk cipher.PubKey) (hs Heads, err error)
// Len is number of feeds stroed
Len() (length int)
}
A Feeds represents bucket of feeds
type Heads ¶
type Heads interface {
// Roots of head with given nonce. If given
// head doesn't exists then, this method
// returns ErrNoSuchHead
Roots(nonce uint64) (rs Roots, err error)
// Add new head with given nonce.
// If a head with given nonce already
// exists, then this method does nothing
Add(nonce uint64) (rs Roots, err error)
// Del deletes head with given nonce and
// all its Root objects. The method returns
// ErrNoSuchHead if a head with given nonce
// doesn't exist
Del(nonce uint64) (err error)
// Has returns true if a head with given
// nonce exits in the CXDS
Has(nonce uint64) (ok bool, err error)
// Iterate over all heads
Iterate(iterateFunc IterateHeadsFunc) (err error)
// Len is number of heads stored
Len() (length int)
}
A Heads represents all heads of a feed
type IdxDB ¶
type IdxDB interface {
Tx(func(Feeds) error) error // transaction
Close() error // close the IdxDB
}
An IdxDB repesents database that contains meta information: feeds meta information about Root objects. There is data/idxdb package that implements the IdxDB. The IdxDB returns and uses errors ErrNotFound, ErrNoSuchFeed, ErrNoSuchHead, and ErrStopIteration, and from this package.
type IterateFeedsFunc ¶
An IterateFeedsFunc represents function for iterating over all feeds IdxDB contains
type IterateHeadsFunc ¶
An IterateHeadsFunc used to iterate over heads of a feed
type IterateObjectsDelFunc ¶
type IterateObjectsDelFunc func( key cipher.SHA256, rc uint32, val []byte, ) ( del bool, err error, )
An IterateObjectsDelFunc used to iterate over objects deleting them by choose. All arguments are read only and must not be modified.
type IterateObjectsFunc ¶
An IterateObjectsFunc used to iterate over objects of the CXDS. All arguments are read only and must not be modified.
type IterateRootsFunc ¶
An IterateRootsFunc represents function for iterating over all Root objects of a feed
type Root ¶
type Root struct {
Create int64 // received or saved at
Access int64 // last access time
Time int64 // timestamp of the Root
Seq uint64 // seq number of this Root
Prev cipher.SHA256 // previous Root or empty if seq == 0
Hash cipher.SHA256 // hash of the Root
Sig cipher.Sig // signature of the Root
}
A Root represents meta information of a saved skyobject.Root
type Roots ¶
type Roots interface {
// Ascend iterates all Root object ascending order.
// Use ErrStopIteration to stop iteration. Any error
// (except the ErrStopIteration) returned by given
// IterateRootsFunc will be passed through. The
// Ascend doesn't update access time
Ascend(iterateFunc IterateRootsFunc) (err error)
// Descend is the same as the Ascend, but it iterates
// decending order. Use ErrStopIteration to stop
// iteration. The Descend doesn't update access time
Descend(iterateFunc IterateRootsFunc) (err error)
// Set adds new Root object to the DB. If an
// object already exists, then the Set touch
// it updating acess time. In this case, the
// set changes Access field of the given Root.
// If Root doesn't exist, then the Set sets
// Create field too. Thus, the method modifies
// given Root in any case. E.g. if Root exists
// then fields Create and Access of given Root
// will be changed to saved. But Access field
// of saved Root will be changed to now
Set(r *Root) (err error)
// Del Root by seq number. The Del never returns
// ErrNotFound if Root doesn't exist
Del(seq uint64) (err error)
// Get Root by seq number
Get(seq uint64) (r *Root, err error)
// Has the Roots Root with given seq?
Has(seq uint64) (ok bool, err error)
// Len is number of Root objects stored
Len() (length int)
}
A Roots represents bucket of Root objects. All Root objects ordered by seq number from small to big
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cxds pkg/cxo/data/cxds/cxds.go c2-net-cxo interface.
|
Package cxds pkg/cxo/data/cxds/cxds.go c2-net-cxo interface. |
|
Package idxdb pkg/cxo/data/idxdb/drive.go c2-net-cxo The bbolt-backed on-disk index DB.
|
Package idxdb pkg/cxo/data/idxdb/drive.go c2-net-cxo The bbolt-backed on-disk index DB. |
|
Package tests pkg/cxo/data/tests/cxds.go c2-net-cxo
|
Package tests pkg/cxo/data/tests/cxds.go c2-net-cxo |