database

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2020 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package database implements a checksum database backed by an underlying transactional key-value store.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

A DB is a Go checksum database.

func Create

func Create(ctx context.Context, store storage.Storage) (*DB, error)

Create initializes a new checksum database in empty storage.

func Open

func Open(ctx context.Context, store storage.Storage) (*DB, error)

Open opens an existing checksum database in the storage.

func (*DB) Add

func (db *DB) Add(ctx context.Context, records []NewRecord) error

Add adds a new record with the given content and associated key. It returns the record id for the new record. If the key is the empty string, the new record has no key.

If a record already exists with the same content and key, Add returns the record id for the existing record instead of adding a new one.

If a record already exists with the same content but a different key, or the same key but different content, Add returns an error.

func (*DB) Config

func (db *DB) Config(ctx context.Context, key string) (string, error)

Config returns the database configuration value for the given key.

func (*DB) Lookup

func (db *DB) Lookup(ctx context.Context, key string) (int64, error)

Lookup looks up a record by its associated key ("module@version"), returning the record ID.

func (*DB) NumRecords

func (db *DB) NumRecords(ctx context.Context) (int64, error)

NumRecords returns the number of records in the database.

func (*DB) ProveRecord

func (db *DB) ProveRecord(ctx context.Context, t, n int64) (tlog.RecordProof, error)

ProveRecord returns the proof that the tree of size t contains the record with index n.

func (*DB) ProveTree

func (db *DB) ProveTree(ctx context.Context, t, n int64) (tlog.TreeProof, error)

ProveTree returns the proof that the tree of size t contains as a prefix all the records from the tree of smaller size n.

func (*DB) ReadHashes

func (db *DB) ReadHashes(ctx context.Context, indexes []int64) ([]tlog.Hash, error)

ReadHashes reads and returns the hashes with the given storage indexes.

func (*DB) ReadRecords

func (db *DB) ReadRecords(ctx context.Context, id, n int64) ([][]byte, error)

ReadRecords returns the content for the n records starting at id.

func (*DB) ReadTileData

func (db *DB) ReadTileData(ctx context.Context, t tlog.Tile) ([]byte, error)

ReadTileData reads the hashes for the tile t and returns the corresponding tile data.

func (*DB) SetConfig

func (db *DB) SetConfig(ctx context.Context, key, value string) error

SetConfig sets the database configuration value for the given key to the value.

func (*DB) TreeHash

func (db *DB) TreeHash(ctx context.Context, n int64) (tlog.Hash, error)

TreeHash returns the top-level tree hash for the tree with n records.

type NewRecord

type NewRecord struct {
	Key     string // record key ("module@version")
	Content []byte // record content
	ID      int64  // record log ID sequence number
	Err     error  // error inserting record, if any
}

A NewRecord tracks a new record to be added to the database. The caller initializes Key and Content, and Add sets ID and Err.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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