orchard

package
v0.0.0-...-133031b Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: Apache-2.0 Imports: 10 Imported by: 1

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unsafe

func Unsafe(o *Orchard)

Unsafe uses the unsafe codec, meaning nodes do not get validated. For testing purposes only.

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

func (Bucket) String

func (b Bucket) String() string

type ByteCursor

type ByteCursor interface {
	First() ([]byte, []byte)
	Next() ([]byte, []byte)
}

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 Errors

type Errors []error

Errors wraps multiple errors into a single return value.

func (Errors) Error

func (e Errors) Error() string

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 Option

type Option func(*Orchard)

Option specifies an option on the Orchard.

type Orchard

type Orchard struct {
	*bolt.DB
	// contains filtered or unexported fields
}

Orchard is a database-backed node store for `forest.Node`. Nodes are persisted as schema entities and can be queried as such.

func Open

func Open(path string, opts ...Option) (*Orchard, error)

Open a database file at the given path using the standard OS filesystem.

func Using

func Using(db *bolt.DB, opts ...Option) (*Orchard, error)

Using allocates an Orchard using the provided database handle.

func (*Orchard) Add

func (o *Orchard) Add(node forest.Node) error

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

func (o *Orchard) CopyInto(other forest.Store) error

CopyInto copies all nodes from the store into the provided store.

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

func (o *Orchard) Recent(nt fields.NodeType, n int) (nodes []forest.Node, err error)

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

func (o *Orchard) RecentReplies(
	ts fields.Timestamp,
	q int,
) (replies []forest.Reply, err error)

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.

func (*Orchard) RepliesAfter

func (o *Orchard) RepliesAfter(
	ts fields.Timestamp,
	q int,
) (replies []forest.Reply, err error)

RepliesAfter returns up to `q` (quantity) replies newer than the timestamp.

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.

Directories

Path Synopsis
internal
mock
Package mock uses mocked structures to filter out non-essential data to clarify testing.
Package mock uses mocked structures to filter out non-essential data to clarify testing.

Jump to

Keyboard shortcuts

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