badgerbs

package
v1.9.0-rc3 Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: Apache-2.0, MIT Imports: 19 Imported by: 9

Documentation

Index

Constants

View Source
const (
	// FileIO is equivalent to badger/options.FileIO.
	FileIO = options.FileIO
	// MemoryMap is equivalent to badger/options.MemoryMap.
	MemoryMap = options.MemoryMap
	// LoadToRAM is equivalent to badger/options.LoadToRAM.
	LoadToRAM = options.LoadToRAM
)

aliases to mask badger dependencies.

Variables

View Source
var (
	// ErrBlockstoreClosed is returned from blockstore operations after
	// the blockstore has been closed.
	ErrBlockstoreClosed = fmt.Errorf("badger blockstore closed")
)
View Source
var (
	// KeyPool is the buffer pool we use to compute storage keys.
	KeyPool *pool.BufferPool = pool.GlobalPool
)

Functions

This section is empty.

Types

type Blockstore

type Blockstore struct {
	DB *badger.DB
	// contains filtered or unexported fields
}

Blockstore is a badger-backed IPLD blockstore.

NOTE: once Close() is called, methods will try their best to return ErrBlockstoreClosed. This will guaranteed to happen for all subsequent operation calls after Close() has returned, but it may not happen for operations in progress. Those are likely to fail with a different error.

func Open

func Open(opts Options) (*Blockstore, error)

Open creates a new badger-backed blockstore, with the supplied options.

func (*Blockstore) AllKeysChan

func (b *Blockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error)

AllKeysChan implements Blockstore.AllKeysChan.

func (*Blockstore) Close

func (b *Blockstore) Close() error

Close closes the store. If the store has already been closed, this noops and returns an error, even if the first closure resulted in error.

func (*Blockstore) CollectGarbage

func (b *Blockstore) CollectGarbage() error

CollectGarbage runs garbage collection on the value log

func (*Blockstore) Compact added in v1.9.0

func (b *Blockstore) Compact() error

Compact runs a synchronous compaction

func (*Blockstore) DeleteBlock

func (b *Blockstore) DeleteBlock(cid cid.Cid) error

DeleteBlock implements Blockstore.DeleteBlock.

func (*Blockstore) DeleteMany

func (b *Blockstore) DeleteMany(cids []cid.Cid) error

func (*Blockstore) Get

func (b *Blockstore) Get(cid cid.Cid) (blocks.Block, error)

Get implements Blockstore.Get.

func (*Blockstore) GetSize

func (b *Blockstore) GetSize(cid cid.Cid) (int, error)

GetSize implements Blockstore.GetSize.

func (*Blockstore) Has

func (b *Blockstore) Has(cid cid.Cid) (bool, error)

Has implements Blockstore.Has.

func (*Blockstore) HashOnRead

func (b *Blockstore) HashOnRead(_ bool)

HashOnRead implements Blockstore.HashOnRead. It is not supported by this blockstore.

func (*Blockstore) PooledStorageKey

func (b *Blockstore) PooledStorageKey(cid cid.Cid) (key []byte, pooled bool)

PooledStorageKey returns the storage key under which this CID is stored.

The key is: prefix + base32_no_padding(cid.Hash)

This method may return pooled byte slice, which MUST be returned to the KeyPool if pooled=true, or a leak will occur.

func (*Blockstore) Put

func (b *Blockstore) Put(block blocks.Block) error

Put implements Blockstore.Put.

func (*Blockstore) PutMany

func (b *Blockstore) PutMany(blocks []blocks.Block) error

PutMany implements Blockstore.PutMany.

func (*Blockstore) StorageKey

func (b *Blockstore) StorageKey(dst []byte, cid cid.Cid) []byte

Storage acts like PooledStorageKey, but attempts to write the storage key into the provided slice. If the slice capacity is insufficient, it allocates a new byte slice with enough capacity to accommodate the result. This method returns the resulting slice.

func (*Blockstore) View

func (b *Blockstore) View(cid cid.Cid, fn func([]byte) error) error

View implements blockstore.Viewer, which leverages zero-copy read-only access to values.

type Options

type Options struct {
	badger.Options

	// Prefix is an optional prefix to prepend to keys. Default: "".
	Prefix string
}

Options embeds the badger options themselves, and augments them with blockstore-specific options.

func DefaultOptions

func DefaultOptions(path string) Options

type Suite

type Suite struct {
	NewBlockstore  func(tb testing.TB) (bs blockstore.BasicBlockstore, path string)
	OpenBlockstore func(tb testing.TB, path string) (bs blockstore.BasicBlockstore, err error)
}

TODO: move this to go-ipfs-blockstore.

func (*Suite) RunTests

func (s *Suite) RunTests(t *testing.T, prefix string)

func (*Suite) TestAllKeysRespectsContext

func (s *Suite) TestAllKeysRespectsContext(t *testing.T)

func (*Suite) TestAllKeysSimple

func (s *Suite) TestAllKeysSimple(t *testing.T)

func (*Suite) TestCidv0v1

func (s *Suite) TestCidv0v1(t *testing.T)

func (*Suite) TestDelete

func (s *Suite) TestDelete(t *testing.T)

func (*Suite) TestDoubleClose

func (s *Suite) TestDoubleClose(t *testing.T)

func (*Suite) TestGetWhenKeyIsNil

func (s *Suite) TestGetWhenKeyIsNil(t *testing.T)

func (*Suite) TestGetWhenKeyNotPresent

func (s *Suite) TestGetWhenKeyNotPresent(t *testing.T)

func (*Suite) TestHas

func (s *Suite) TestHas(t *testing.T)

func (*Suite) TestPutMany

func (s *Suite) TestPutMany(t *testing.T)

func (*Suite) TestPutThenGetBlock

func (s *Suite) TestPutThenGetBlock(t *testing.T)

func (*Suite) TestPutThenGetSizeBlock

func (s *Suite) TestPutThenGetSizeBlock(t *testing.T)

func (*Suite) TestReopenPutGet

func (s *Suite) TestReopenPutGet(t *testing.T)

Jump to

Keyboard shortcuts

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