blockstore

package
v0.4.10-rc1 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2017 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package blockstore implements a thin wrapper over a datastore, giving a clean interface for Getting and Putting block objects.

Index

Constants

This section is empty.

Variables

View Source
var BlockPrefix = ds.NewKey("blocks")

BlockPrefix namespaces blockstore datastores

View Source
var ErrHashMismatch = errors.New("block in storage has different hash than requested")

ErrHashMismatch is an error returned when the hash of a block is different than expected.

View Source
var ErrNotFound = errors.New("blockstore: block not found")

ErrNotFound is an error returned when a block is not found.

View Source
var ErrValueTypeMismatch = errors.New("the retrieved value is not a Block")

ErrValueTypeMismatch is an error returned when the item retrieved from the datatstore is not a block.

Functions

This section is empty.

Types

type Blockstore

type Blockstore interface {
	DeleteBlock(*cid.Cid) error
	Has(*cid.Cid) (bool, error)
	Get(*cid.Cid) (blocks.Block, error)
	Put(blocks.Block) error
	PutMany([]blocks.Block) error
	// AllKeysChan returns a channel from which
	// the CIDs in the Blockstore can be read. It should respect
	// the given context, closing the channel if it becomes Done.
	AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error)
	// HashOnRead specifies if every read block should be
	// rehashed to make sure it matches its CID.
	HashOnRead(enabled bool)
}

Blockstore wraps a Datastore block-centered methods and provides a layer of abstraction which allows to add different caching strategies.

func CachedBlockstore added in v0.4.3

func CachedBlockstore(
	ctx context.Context,
	bs Blockstore,
	opts CacheOpts) (cbs Blockstore, err error)

CachedBlockstore returns a blockstore wrapped in an ARCCache and then in a bloom filter cache, if the options indicate it.

func NewBlockstore

func NewBlockstore(d ds.Batching) Blockstore

NewBlockstore returns a default Blockstore implementation using the provided datastore.Batching backend.

type CacheOpts added in v0.4.3

type CacheOpts struct {
	HasBloomFilterSize   int // 1 byte
	HasBloomFilterHashes int // No size, 7 is usually best, consult bloom papers
	HasARCCacheSize      int // 32 bytes
}

CacheOpts wraps options for CachedBlockStore(). Next to each option is it aproximate memory usage per unit

func DefaultCacheOpts added in v0.4.3

func DefaultCacheOpts() CacheOpts

DefaultCacheOpts returns a CacheOpts initialized with default values.

type GCBlockstore added in v0.4.0

type GCBlockstore interface {
	Blockstore
	GCLocker
}

GCBlockstore is a blockstore that can safely run garbage-collection operations.

func NewGCBlockstore added in v0.4.5

func NewGCBlockstore(bs Blockstore, gcl GCLocker) GCBlockstore

NewGCBlockstore returns a default implementation of GCBlockstore using the given Blockstore and GCLocker.

type GCLocker added in v0.4.5

type GCLocker interface {
	// GCLock locks the blockstore for garbage collection. No operations
	// that expect to finish with a pin should ocurr simultaneously.
	// Reading during GC is safe, and requires no lock.
	GCLock() Unlocker

	// PinLock locks the blockstore for sequences of puts expected to finish
	// with a pin (before GC). Multiple put->pin sequences can write through
	// at the same time, but no GC should not happen simulatenously.
	// Reading during Pinning is safe, and requires no lock.
	PinLock() Unlocker

	// GcRequested returns true if GCLock has been called and is waiting to
	// take the lock
	GCRequested() bool
}

GCLocker abstract functionality to lock a blockstore when performing garbage-collection operations.

func NewGCLocker added in v0.4.5

func NewGCLocker() GCLocker

NewGCLocker returns a default implementation of GCLocker using standard [RW] mutexes.

type Unlocker added in v0.4.0

type Unlocker interface {
	Unlock()
}

Unlocker represents an object which can Unlock something.

Directories

Path Synopsis
Package blockstoreutil provides utility functions for Blockstores.
Package blockstoreutil provides utility functions for Blockstores.

Jump to

Keyboard shortcuts

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