Documentation ¶
Overview ¶
Package orchard implements a boltdb backed on-disk node store, satisfying the forest.Store interface.
This database is a single file that serializes nodes into buckets. Various indexes are used to accelerate important queries.
As a result of using boltdb, Orchard prefers read heavy workloads.
Index ¶
- func Unsafe(o *Orchard)
- type Bucket
- type ByteCursor
- type CommunityCursor
- type Errors
- type IdentityCursor
- type Option
- type Orchard
- func (o *Orchard) Add(node forest.Node) error
- func (o *Orchard) Children(parent *fields.QualifiedHash) (ch []*fields.QualifiedHash, err error)
- func (o *Orchard) ChildrenBatched(parent *fields.QualifiedHash, q, offset int) (ch []*fields.QualifiedHash, total int, err error)
- func (o *Orchard) CopyInto(other forest.Store) error
- func (o *Orchard) Get(nodeID *fields.QualifiedHash) (node forest.Node, present bool, err error)
- func (o *Orchard) GetCommunity(id *fields.QualifiedHash) (forest.Node, bool, error)
- func (o *Orchard) GetConversation(community *fields.QualifiedHash, id *fields.QualifiedHash) (forest.Node, bool, error)
- func (o *Orchard) GetIdentity(id *fields.QualifiedHash) (forest.Node, bool, error)
- func (o *Orchard) GetReply(community *fields.QualifiedHash, conversation *fields.QualifiedHash, ...) (forest.Node, bool, error)
- func (o *Orchard) Recent(nt fields.NodeType, n int) (nodes []forest.Node, err error)
- func (o *Orchard) RecentCommunities(ts fields.Timestamp, q int) (communities []forest.Community, err error)
- func (o *Orchard) RecentFrom(nt fields.NodeType, ts time.Time, q int) (nodes []forest.Node, err error)
- func (o *Orchard) RecentIdentities(ts fields.Timestamp, q int) (identities []forest.Identity, err error)
- func (o *Orchard) RecentReplies(ts fields.Timestamp, q int) (replies []forest.Reply, err error)
- func (o *Orchard) RemoveSubtree(id *fields.QualifiedHash) error
- func (o *Orchard) RepliesAfter(ts fields.Timestamp, q int) (replies []forest.Reply, err error)
- type ReplyCursor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Bucket ¶
type Bucket []byte
Bucket contains the name of a bucket in bytes.
var ( // Buckets are the storage primitive used by bolt, that contain a sorted // list of key-value pairs. Each bucket is homogeneous. BucketReply Bucket = Bucket("Reply") BucketIdentity Bucket = Bucket("Identity") BucketCommunity Bucket = Bucket("Community") // Indexes are used to speed up queries. IndexAge Bucket = Bucket("Age") IndexType Bucket = Bucket("Type") IndexChildren Bucket = Bucket("Children") Buckets []Bucket = []Bucket{ BucketReply, BucketIdentity, BucketCommunity, } Indexes []Bucket = []Bucket{ IndexAge, IndexType, IndexChildren, } )
type ByteCursor ¶
ByteCursor is a cursor that iterates over []byte kv pairs.
type CommunityCursor ¶
type CommunityCursor struct { Inner ByteCursor Codec *codec.Default }
CommunityCursor wraps byte cursor and decodes into `forest.Community` values.
func (*CommunityCursor) First ¶
func (c *CommunityCursor) First() (r forest.Community, err error)
First returns the first community or EOF if there are no.
func (*CommunityCursor) Next ¶
func (c *CommunityCursor) Next() (r forest.Community, err error)
Next returns the next community or EOF if there are no more.
type IdentityCursor ¶
type IdentityCursor struct { Inner ByteCursor Codec *codec.Default }
IdentityCursor wraps byte cursor and decodes into `forest.Identity` values.
func (*IdentityCursor) First ¶
func (c *IdentityCursor) First() (r forest.Identity, err error)
First returns the first identity or EOF if there are no.
func (*IdentityCursor) Next ¶
func (c *IdentityCursor) Next() (r forest.Identity, err error)
Next returns the next identity or EOF if there are no more.
type Orchard ¶
Orchard is a database-backed node store for `forest.Node`. Nodes are persisted as schema entities and can be queried as such.
func (*Orchard) Add ¶
Add inserts the node into the orchard. If the given node is already in the orchard, Add will do nothing. It is not an error to insert a node more than once.
func (*Orchard) Children ¶
func (o *Orchard) Children( parent *fields.QualifiedHash, ) (ch []*fields.QualifiedHash, err error)
Children returns the IDs of all known child nodes of the specified ID.
func (*Orchard) ChildrenBatched ¶
func (o *Orchard) ChildrenBatched( parent *fields.QualifiedHash, q, offset int, ) (ch []*fields.QualifiedHash, total int, err error)
ChildrenBatched traverses the children of a node in fixed-sized batches by age, youngest first.
func (*Orchard) Get ¶
func (o *Orchard) Get(nodeID *fields.QualifiedHash) (node forest.Node, present bool, err error)
Get searches for a node with the given id. Present indicates whether the node exists, err indicates a failure to load it.
func (*Orchard) GetCommunity ¶
func (o *Orchard) GetCommunity(id *fields.QualifiedHash) (forest.Node, bool, error)
func (*Orchard) GetConversation ¶
func (o *Orchard) GetConversation( community *fields.QualifiedHash, id *fields.QualifiedHash, ) (forest.Node, bool, error)
func (*Orchard) GetIdentity ¶
func (o *Orchard) GetIdentity(id *fields.QualifiedHash) (forest.Node, bool, error)
func (*Orchard) GetReply ¶
func (o *Orchard) GetReply( community *fields.QualifiedHash, conversation *fields.QualifiedHash, id *fields.QualifiedHash, ) (forest.Node, bool, error)
func (*Orchard) Recent ¶
Recent returns a slice of nodes of a given type ordered by recency, youngest first.
NOTE: this function may return both a valid slice of nodes and an error in the case that some nodes failed to be unmarshaled from disk, but others were successful. Calling code should always check whether the node list is empty before throwing it away.
func (*Orchard) RecentCommunities ¶
func (o *Orchard) RecentCommunities( ts fields.Timestamp, q int, ) (communities []forest.Community, err error)
RecentCommunities returns up to `q` (quantity) communities older than the timestamp.
func (*Orchard) RecentFrom ¶
func (o *Orchard) RecentFrom( nt fields.NodeType, ts time.Time, q int, ) (nodes []forest.Node, err error)
RecentFrom queries up to `q` (quantity) nodes of type `nt` that occur after specified timestamp. To page through, pass in the next oldest timestamp from the returned nodes.
NOTE(jfm): There's semantic edge cases around what it means to pass in timestamp of 0. Theoretically, that would mean "iterate from 0 at the earliest", which should always return no nodes.
PERF(jfm): Performance analysis pending.
func (*Orchard) RecentIdentities ¶
func (o *Orchard) RecentIdentities( ts fields.Timestamp, q int, ) (identities []forest.Identity, err error)
RecentIdentities returns up to `q` (quantity) identities older than the timestamp.
func (*Orchard) RecentReplies ¶
RecentReplies returns up to `q` (quantity) replies older than the timestamp.
func (*Orchard) RemoveSubtree ¶
func (o *Orchard) RemoveSubtree(id *fields.QualifiedHash) error
RemoveSubtree removes the subtree rooted at the node with the provided ID from the orchard.
type ReplyCursor ¶
type ReplyCursor struct { Inner ByteCursor Codec *codec.Default }
ReplyCursor wraps byte cursor and decodes into `forest.Reply` values.
func (*ReplyCursor) First ¶
func (c *ReplyCursor) First() (r forest.Reply, err error)
First returns the first reply or EOF if there are no.
func (*ReplyCursor) Next ¶
func (c *ReplyCursor) Next() (r forest.Reply, err error)
Next returns the next reply or EOF if there are no more replies.