gotkv

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: GPL-3.0 Imports: 9 Imported by: 8

README

GotKV

GotKV is a copy-on-write, encrypted, deterministic, key value store built on top of content-addressed storage.

Example: Put/Get

package main

import "github.com/gotvc/got/pkg/gotkv"

func main() {
    // create operator
    avgSize := 1 << 13
    maxSize := 1 << 16
    kvop := gotkv.NewOperator(avgSize, maxSize)

    // create store
    s := cadata.NewMem(cadata.DefaultHash, maxSize)

    // ignoring errors for brevity
    x, _ := op.NewEmpty(ctx, s)
    x, _ = op.Put(ctx, s, *x, []byte("my key"), []byte("my value"))
    value, _ := op.Get(ctx, s, *x, []byte("my key"))
    // value == []byte("my value")
} 

Example: Builder

package main

import "github.com/gotvc/got/pkg/gotkv"

func main() {
    ctx := context.Background()
    // create operator
    avgSize := 1 << 13
    maxSize := 1 << 16
    kvop := gotkv.NewOperator(avgSize, maxSize)

    // create store
    s := cadata.NewMem(cadata.DefaultHash, maxSize)

    // ignoring errors for brevity
    b := kvop.NewBuilder(s)
    for i := 0; i < 10; i++ { 
        b.Put(ctx, []byte("key-" + strconv.Itoa(i)), []byte("my value"))
    }
    root, _ := b.Finish(ctx)
    // the instance rooted at root contains key-0 through key-10
}

Documentation

Index

Constants

View Source
const (
	MaxKeySize = ptree.MaxKeySize
)

Variables

View Source
var (
	ErrKeyNotFound = errors.Errorf("key not found")
	EOS            = kvstreams.EOS
)

Functions

func CopyAll

func CopyAll(ctx context.Context, b *Builder, it kvstreams.Iterator) error

CopyAll copies all the entries from iterator to builder.

func Get

func Get(ctx context.Context, s Store, x Root, key []byte) ([]byte, error)

Get is a convenience function for performing Get without creating an Operator.

func GetF

func GetF(ctx context.Context, s Store, x Root, key []byte, fn func([]byte) error) error

GetF is a convenience function for performing GetF without creating an Operator

func KeyAfter

func KeyAfter(x []byte) []byte

func PrefixEnd

func PrefixEnd(prefix []byte) []byte

Types

type Builder

type Builder = ptree.Builder

Builder is used to construct GotKV instances by adding keys in lexicographical order.

type Entry

type Entry = kvstreams.Entry

type ID

type ID = cadata.ID

type Iterator

type Iterator = ptree.Iterator

Iterator is used to iterate through entries in GotKV instances.

type Mutation added in v0.0.2

type Mutation struct {
	Span    Span
	Entries []Entry
}

Mutation represents a declarative change to a Span of entries. The result of applying mutation is that

type Operator

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

Operator holds common configuration for operations on gotkv instances. It has nothing to do with the state of a particular gotkv instance. It is NOT analagous to a collection object. It is safe for use by multiple goroutines.

func NewOperator

func NewOperator(avgSize, maxSize int, opts ...Option) Operator

NewOperator returns an operator which will create nodes with average size `avgSize` and maximum size `maxSize`.

func (*Operator) AddPrefix

func (o *Operator) AddPrefix(x Root, prefix []byte) Root

AddPrefix prepends prefix to all the keys in instance x. This is a O(1) operation.

func (*Operator) Concat added in v0.0.2

func (o *Operator) Concat(ctx context.Context, s cadata.Store, iters ...kvstreams.Iterator) (*Root, error)

Concat copies data from the iterators in order. If the iterators produce out of order keys concat errors.

func (*Operator) Delete

func (o *Operator) Delete(ctx context.Context, s cadata.Store, x Root, key []byte) (*Root, error)

Delete returns a new version of the instance x where there is no entry for key. If key does not exist no error is returned.

func (*Operator) DeleteSpan

func (o *Operator) DeleteSpan(ctx context.Context, s cadata.Store, x Root, span Span) (*Root, error)

DeleteSpan returns a new version of the instance x where there are no entries contained in span.

func (*Operator) ForEach

func (o *Operator) ForEach(ctx context.Context, s Store, root Root, span Span, fn func(Entry) error) error

ForEach calls fn with every entry, in the GotKV instance rooted at root, contained in span, in lexicographical order. If fn returns an error, ForEach immediately returns that error.

func (*Operator) Get

func (o *Operator) Get(ctx context.Context, s cadata.Store, x Root, key []byte) ([]byte, error)

Get returns the value corresponding to key in the instance x.

func (*Operator) GetF

func (o *Operator) GetF(ctx context.Context, s cadata.Store, x Root, key []byte, fn func([]byte) error) error

GetF calls fn with the value corresponding to key in the instance x. The value must not be used outside the callback.

func (*Operator) MaxEntry added in v0.0.2

func (o *Operator) MaxEntry(ctx context.Context, s cadata.Store, x Root, span Span) (*Entry, error)

MaxEntry returns the entry in the instance x, within span, with the greatest lexicographic value.

func (*Operator) MaxSize added in v0.0.4

func (o *Operator) MaxSize() int

func (*Operator) MeanSize added in v0.0.4

func (o *Operator) MeanSize() int

func (*Operator) Mutate added in v0.0.2

func (o *Operator) Mutate(ctx context.Context, s cadata.Store, x Root, mutations ...Mutation) (*Root, error)

Mutate applies a batch of mutations to the tree x.

func (*Operator) NewBuilder

func (o *Operator) NewBuilder(s Store) *Builder

NewBuilder returns a Builder for constructing a GotKV instance. Data will be persisted to s.

func (*Operator) NewEmpty

func (o *Operator) NewEmpty(ctx context.Context, s cadata.Store) (*Root, error)

NewEmpty returns a new GotKV instance with no entries.

func (*Operator) NewIterator

func (o *Operator) NewIterator(s Store, root Root, span Span) *Iterator

NewIterator returns an iterator for the instance rooted at x, which will emit all keys within span in the instance.

func (*Operator) Populate added in v0.0.4

func (o *Operator) Populate(ctx context.Context, s Store, x Root, set cadata.Set, entryFn func(ent Entry) error) error

Populate adds all blobs reachable from x to set. If an item is in set all of the blobs reachable from it are also assumed to also be in set.

func (*Operator) Put

func (o *Operator) Put(ctx context.Context, s cadata.Store, x Root, key, value []byte) (*Root, error)

Put returns a new version of the instance x with the entry at key corresponding to value. If an entry at key already exists it is overwritten, otherwise it will be created.

func (*Operator) RemovePrefix

func (o *Operator) RemovePrefix(ctx context.Context, s cadata.Store, x Root, prefix []byte) (*Root, error)

RemovePrefix removes a prefix from all the keys in instance x. RemotePrefix errors if all the entries in x do not share a common prefix. This is a O(1) operation.

func (*Operator) Sync added in v0.0.4

func (o *Operator) Sync(ctx context.Context, src, dst Store, x Root, entryFn func(Entry) error) error

Sync ensures dst has all the data reachable from x.

type Option

type Option func(op *Operator)

Option is used to configure an Operator

func WithCompare added in v0.0.4

func WithCompare(fn func(a, b []byte) int) Option

func WithDataOperator

func WithDataOperator(ro gdat.Operator) Option

func WithSeed

func WithSeed(seed *[16]byte) Option

WithSeed returns an Option which sets the seed for an Operator. Seed affects node boundaries.

type Ref

type Ref = gdat.Ref

type Root

type Root = ptree.Root

type Span

type Span = kvstreams.Span

func PrefixSpan

func PrefixSpan(prefix []byte) Span

func SingleKeySpan

func SingleKeySpan(k []byte) Span

func TotalSpan

func TotalSpan() Span

type Store

type Store = cadata.Store

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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