badger

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: May 18, 2021 License: AGPL-3.0 Imports: 16 Imported by: 21

Documentation

Index

Constants

View Source
const JobQueueChunksQueue = "JobQueueChunksQueue"

Variables

This section is empty.

Functions

func InitAll added in v0.12.0

func InitAll(metrics module.CacheMetrics, db *badger.DB) *storage.All

func KeyFromBlockIDTransactionID added in v0.15.1

func KeyFromBlockIDTransactionID(blockID flow.Identifier, txID flow.Identifier) string

func KeyToBlockIDTransactionID added in v0.15.1

func KeyToBlockIDTransactionID(key string) (flow.Identifier, flow.Identifier, error)

Types

type Batch added in v0.15.1

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

func NewBatch added in v0.15.1

func NewBatch(db *badger.DB) *Batch

func (*Batch) Flush added in v0.15.1

func (b *Batch) Flush() error

Flush will call the badger Batch's Flush method, in addition, it will call the callbacks added by OnSucceed

func (*Batch) GetWriter added in v0.15.1

func (b *Batch) GetWriter() *badger.WriteBatch

func (*Batch) OnSucceed added in v0.15.1

func (b *Batch) OnSucceed(callback func())

OnSucceed adds a callback to execute after the batch has been successfully flushed. useful for implementing the cache where we will only cache after the batch has been successfully flushed

type Blocks

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

Blocks implements a simple block storage around a badger DB.

func NewBlocks

func NewBlocks(db *badger.DB, headers *Headers, payloads *Payloads) *Blocks

NewBlocks ...

func (*Blocks) ByCollectionID

func (b *Blocks) ByCollectionID(collID flow.Identifier) (*flow.Block, error)

ByCollectionID ...

func (*Blocks) ByHeight

func (b *Blocks) ByHeight(height uint64) (*flow.Block, error)

ByHeight ...

func (*Blocks) ByID

func (b *Blocks) ByID(blockID flow.Identifier) (*flow.Block, error)

ByID ...

func (*Blocks) GetLastFullBlockHeight

func (b *Blocks) GetLastFullBlockHeight() (uint64, error)

GetLastFullBlockHeight ...

func (*Blocks) IndexBlockForCollections

func (b *Blocks) IndexBlockForCollections(blockID flow.Identifier, collIDs []flow.Identifier) error

IndexBlockForCollections ...

func (*Blocks) Store

func (b *Blocks) Store(block *flow.Block) error

Store ...

func (*Blocks) StoreTx

func (b *Blocks) StoreTx(block *flow.Block) func(*transaction.Tx) error

func (*Blocks) UpdateLastFullBlockHeight

func (b *Blocks) UpdateLastFullBlockHeight(height uint64) error

UpdateLastFullBlockHeight upsert (update or insert) the last full block height

type Cache

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

func (*Cache) Get

func (c *Cache) Get(key interface{}) func(*badger.Txn) (interface{}, error)

Get will try to retrieve the resource from cache first, and then from the injected

func (*Cache) Insert added in v0.16.1

func (c *Cache) Insert(key interface{}, resource interface{})

Insert will add an resource directly to the cache with the given ID

func (*Cache) PutTx added in v0.17.1

func (c *Cache) PutTx(key interface{}, resource interface{}) func(*transaction.Tx) error

PutTx will return tx which adds an resource to the cache with the given ID.

func (*Cache) Remove added in v0.16.1

func (c *Cache) Remove(key interface{})

type ChunkDataPacks

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

func NewChunkDataPacks

func NewChunkDataPacks(collector module.CacheMetrics, db *badger.DB, byChunkIDCacheSize uint) *ChunkDataPacks

func (*ChunkDataPacks) BatchStore added in v0.15.0

func (ch *ChunkDataPacks) BatchStore(c *flow.ChunkDataPack, batch storage.BatchStorage) error

func (*ChunkDataPacks) ByChunkID

func (ch *ChunkDataPacks) ByChunkID(chunkID flow.Identifier) (*flow.ChunkDataPack, error)

func (*ChunkDataPacks) Remove

func (ch *ChunkDataPacks) Remove(chunkID flow.Identifier) error

func (*ChunkDataPacks) Store

func (ch *ChunkDataPacks) Store(c *flow.ChunkDataPack) error

type ChunksQueue added in v0.15.0

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

ChunksQueue stores a queue of chunk locators that assigned to me to verify. Job consumers can read the locators as job from the queue by index. Chunk locators stored in this queue are unique.

func NewChunkQueue added in v0.15.0

func NewChunkQueue(db *badger.DB) *ChunksQueue

NewChunkQueue will initialize the underlying badger database of chunk locator queue.

func (*ChunksQueue) AtIndex added in v0.15.0

func (q *ChunksQueue) AtIndex(index uint64) (*chunks.Locator, error)

AtIndex returns the chunk locator stored at the given index in the queue.

func (*ChunksQueue) Init added in v0.15.0

func (q *ChunksQueue) Init(defaultIndex uint64) (bool, error)

Init initializes chunk queue's latest index with the given default index.

func (*ChunksQueue) LatestIndex added in v0.15.0

func (q *ChunksQueue) LatestIndex() (uint64, error)

LatestIndex returns the index of the latest chunk locator stored in the queue.

func (*ChunksQueue) StoreChunkLocator added in v0.15.0

func (q *ChunksQueue) StoreChunkLocator(locator *chunks.Locator) (bool, error)

StoreChunkLocator stores a new chunk locator that assigned to me to the job queue. A true will be returned, if the locator was new. A false will be returned, if the locator was duplicate.

type Cleaner

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

func NewCleaner

func NewCleaner(log zerolog.Logger, db *badger.DB, metrics module.CleanerMetrics, frequency int) *Cleaner

NewCleaner returns a cleaner that runs the badger value log garbage collection once every `frequency` calls if a frequency of zero is passed in, we will not run the GC at all

func (*Cleaner) RunGC

func (c *Cleaner) RunGC()

type ClusterBlocks

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

ClusterBlocks implements a simple block storage around a badger DB.

func NewClusterBlocks

func NewClusterBlocks(db *badger.DB, chainID flow.ChainID, headers *Headers, payloads *ClusterPayloads) *ClusterBlocks

func (*ClusterBlocks) ByHeight

func (b *ClusterBlocks) ByHeight(height uint64) (*cluster.Block, error)

func (*ClusterBlocks) ByID

func (b *ClusterBlocks) ByID(blockID flow.Identifier) (*cluster.Block, error)

func (*ClusterBlocks) Store

func (b *ClusterBlocks) Store(block *cluster.Block) error

type ClusterPayloads

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

ClusterPayloads implements storage of block payloads for collection node cluster consensus.

func NewClusterPayloads

func NewClusterPayloads(cacheMetrics module.CacheMetrics, db *badger.DB) *ClusterPayloads

func (*ClusterPayloads) ByBlockID

func (cp *ClusterPayloads) ByBlockID(blockID flow.Identifier) (*cluster.Payload, error)

func (*ClusterPayloads) Store

func (cp *ClusterPayloads) Store(blockID flow.Identifier, payload *cluster.Payload) error

type Collections

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

func NewCollections

func NewCollections(db *badger.DB, transactions *Transactions) *Collections

func (*Collections) ByID

func (c *Collections) ByID(colID flow.Identifier) (*flow.Collection, error)

func (*Collections) LightByID

func (c *Collections) LightByID(colID flow.Identifier) (*flow.LightCollection, error)

func (*Collections) LightByTransactionID

func (c *Collections) LightByTransactionID(txID flow.Identifier) (*flow.LightCollection, error)

func (*Collections) Remove

func (c *Collections) Remove(colID flow.Identifier) error

func (*Collections) Store

func (c *Collections) Store(collection *flow.Collection) error

func (*Collections) StoreLight

func (c *Collections) StoreLight(collection *flow.LightCollection) error

func (*Collections) StoreLightAndIndexByTransaction

func (c *Collections) StoreLightAndIndexByTransaction(collection *flow.LightCollection) error

type Commits

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

func NewCommits

func NewCommits(collector module.CacheMetrics, db *badger.DB) *Commits

func (*Commits) BatchStore added in v0.15.0

func (c *Commits) BatchStore(blockID flow.Identifier, commit flow.StateCommitment, batch storage.BatchStorage) error

func (*Commits) ByBlockID

func (c *Commits) ByBlockID(blockID flow.Identifier) (flow.StateCommitment, error)

func (*Commits) Store

func (c *Commits) Store(blockID flow.Identifier, commit flow.StateCommitment) error

type ConsumerProgress added in v0.15.0

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

func NewConsumerProgress added in v0.15.0

func NewConsumerProgress(db *badger.DB, consumer string) *ConsumerProgress

func (*ConsumerProgress) InitProcessedIndex added in v0.15.0

func (cp *ConsumerProgress) InitProcessedIndex(defaultIndex uint64) error

InitProcessedIndex insert the default processed index to the storage layer, can only be done once. initialize for the second time will return storage.ErrAlreadyExists

func (*ConsumerProgress) ProcessedIndex added in v0.15.0

func (cp *ConsumerProgress) ProcessedIndex() (uint64, error)

func (*ConsumerProgress) SetProcessedIndex added in v0.15.0

func (cp *ConsumerProgress) SetProcessedIndex(processed uint64) error

type EpochCommits

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

func NewEpochCommits

func NewEpochCommits(collector module.CacheMetrics, db *badger.DB) *EpochCommits

func (*EpochCommits) ByID

func (ec *EpochCommits) ByID(commitID flow.Identifier) (*flow.EpochCommit, error)

func (*EpochCommits) Store

func (ec *EpochCommits) Store(commit *flow.EpochCommit) error

TODO: can we remove this method? Its not contained in the interface.

func (*EpochCommits) StoreTx

func (ec *EpochCommits) StoreTx(commit *flow.EpochCommit) func(*transaction.Tx) error

type EpochSetups

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

func NewEpochSetups

func NewEpochSetups(collector module.CacheMetrics, db *badger.DB) *EpochSetups

func (*EpochSetups) ByID

func (es *EpochSetups) ByID(setupID flow.Identifier) (*flow.EpochSetup, error)

func (*EpochSetups) StoreTx

func (es *EpochSetups) StoreTx(setup *flow.EpochSetup) func(tx *transaction.Tx) error

type EpochStatuses

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

func NewEpochStatuses

func NewEpochStatuses(collector module.CacheMetrics, db *badger.DB) *EpochStatuses

NewEpochStatuses ...

func (*EpochStatuses) ByBlockID

func (es *EpochStatuses) ByBlockID(blockID flow.Identifier) (*flow.EpochStatus, error)

func (*EpochStatuses) StoreTx

func (es *EpochStatuses) StoreTx(blockID flow.Identifier, status *flow.EpochStatus) func(tx *transaction.Tx) error

type Events

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

func NewEvents

func NewEvents(collector module.CacheMetrics, db *badger.DB) *Events

func (*Events) BatchStore added in v0.15.0

func (e *Events) BatchStore(blockID flow.Identifier, events []flow.Event, batch storage.BatchStorage) error

func (*Events) ByBlockID

func (e *Events) ByBlockID(blockID flow.Identifier) ([]flow.Event, error)

ByBlockID returns the events for the given block ID

func (*Events) ByBlockIDEventType

func (e *Events) ByBlockIDEventType(blockID flow.Identifier, eventType flow.EventType) ([]flow.Event, error)

ByBlockIDEventType returns the events for the given block ID and event type

func (*Events) ByBlockIDTransactionID

func (e *Events) ByBlockIDTransactionID(blockID flow.Identifier, txID flow.Identifier) ([]flow.Event, error)

ByBlockIDTransactionID returns the events for the given block ID and transaction ID

type ExecutionReceipts

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

ExecutionReceipts implements storage for execution receipts.

func NewExecutionReceipts

func NewExecutionReceipts(collector module.CacheMetrics, db *badger.DB, results *ExecutionResults) *ExecutionReceipts

NewExecutionReceipts Creates ExecutionReceipts instance which is a database of receipts which supports storing and indexing receipts by receipt ID and block ID.

func (*ExecutionReceipts) BatchStore added in v0.15.1

func (r *ExecutionReceipts) BatchStore(receipt *flow.ExecutionReceipt, batch storage.BatchStorage) error

func (*ExecutionReceipts) ByBlockID

func (*ExecutionReceipts) ByID

func (*ExecutionReceipts) Store

func (r *ExecutionReceipts) Store(receipt *flow.ExecutionReceipt) error

type ExecutionResults

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

ExecutionResults implements persistent storage for execution results.

func NewExecutionResults

func NewExecutionResults(collector module.CacheMetrics, db *badger.DB) *ExecutionResults

func (*ExecutionResults) BatchIndex added in v0.15.0

func (r *ExecutionResults) BatchIndex(blockID flow.Identifier, resultID flow.Identifier, batch storage.BatchStorage) error

func (*ExecutionResults) BatchStore added in v0.15.0

func (r *ExecutionResults) BatchStore(result *flow.ExecutionResult, batch storage.BatchStorage) error

func (*ExecutionResults) ByBlockID

func (r *ExecutionResults) ByBlockID(blockID flow.Identifier) (*flow.ExecutionResult, error)

func (*ExecutionResults) ByID

func (r *ExecutionResults) ByID(resultID flow.Identifier) (*flow.ExecutionResult, error)

func (*ExecutionResults) Index

func (r *ExecutionResults) Index(blockID flow.Identifier, resultID flow.Identifier) error

func (*ExecutionResults) Store

func (r *ExecutionResults) Store(result *flow.ExecutionResult) error

type Guarantees

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

Guarantees implements persistent storage for collection guarantees.

func NewGuarantees

func NewGuarantees(collector module.CacheMetrics, db *badger.DB) *Guarantees

func (*Guarantees) ByCollectionID

func (g *Guarantees) ByCollectionID(collID flow.Identifier) (*flow.CollectionGuarantee, error)

func (*Guarantees) Store

func (g *Guarantees) Store(guarantee *flow.CollectionGuarantee) error

type Headers

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

Headers implements a simple read-only header storage around a badger DB.

func NewHeaders

func NewHeaders(collector module.CacheMetrics, db *badger.DB) *Headers

func (*Headers) BatchIndexByChunkID added in v0.15.0

func (h *Headers) BatchIndexByChunkID(headerID, chunkID flow.Identifier, batch storage.BatchStorage) error

func (*Headers) ByBlockID

func (h *Headers) ByBlockID(blockID flow.Identifier) (*flow.Header, error)

func (*Headers) ByHeight

func (h *Headers) ByHeight(height uint64) (*flow.Header, error)

func (*Headers) ByParentID

func (h *Headers) ByParentID(parentID flow.Identifier) ([]*flow.Header, error)

func (*Headers) FindHeaders

func (h *Headers) FindHeaders(filter func(header *flow.Header) bool) ([]flow.Header, error)

func (*Headers) IDByChunkID added in v0.15.0

func (h *Headers) IDByChunkID(chunkID flow.Identifier) (flow.Identifier, error)

func (*Headers) IndexByChunkID added in v0.15.0

func (h *Headers) IndexByChunkID(headerID, chunkID flow.Identifier) error

func (*Headers) Store

func (h *Headers) Store(header *flow.Header) error

type Index

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

Index implements a simple read-only payload storage around a badger DB.

func NewIndex

func NewIndex(collector module.CacheMetrics, db *badger.DB) *Index

func (*Index) ByBlockID

func (i *Index) ByBlockID(blockID flow.Identifier) (*flow.Index, error)

func (*Index) Store

func (i *Index) Store(blockID flow.Identifier, index *flow.Index) error

type MyExecutionReceipts added in v0.15.0

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

MyExecutionReceipts holds and indexes Execution Receipts. MyExecutionReceipts is implemented as a wrapper around badger.ExecutionReceipts The wrapper adds the ability to "MY execution receipt", from the viewpoint of an individual Execution Node.

func NewMyExecutionReceipts added in v0.15.0

func NewMyExecutionReceipts(collector module.CacheMetrics, db *badger.DB, receipts *ExecutionReceipts) *MyExecutionReceipts

NewMyExecutionReceipts creates instance of MyExecutionReceipts which is a wrapper wrapper around badger.ExecutionReceipts It's useful for execution nodes to keep track of produced execution receipts.

func (*MyExecutionReceipts) BatchStoreMyReceipt added in v0.15.1

func (m *MyExecutionReceipts) BatchStoreMyReceipt(receipt *flow.ExecutionReceipt, batch storage.BatchStorage) error

func (*MyExecutionReceipts) MyReceipt added in v0.15.0

func (m *MyExecutionReceipts) MyReceipt(blockID flow.Identifier) (*flow.ExecutionReceipt, error)

MyReceipt retrieves my receipt for the given block. Returns storage.ErrNotFound if no receipt was persisted for the block.

func (*MyExecutionReceipts) StoreMyReceipt added in v0.15.0

func (m *MyExecutionReceipts) StoreMyReceipt(receipt *flow.ExecutionReceipt) error

StoreMyReceipt stores the receipt and marks it as mine (trusted). My receipts are indexed by the block whose result they compute. Currently, we only support indexing a _single_ receipt per block. Attempting to store conflicting receipts for the same block will error.

type Payloads

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

func NewPayloads

func NewPayloads(db *badger.DB, index *Index, guarantees *Guarantees, seals *Seals, receipts *ExecutionReceipts,
	results *ExecutionResults) *Payloads

func (*Payloads) ByBlockID

func (p *Payloads) ByBlockID(blockID flow.Identifier) (*flow.Payload, error)

func (*Payloads) Store

func (p *Payloads) Store(blockID flow.Identifier, payload *flow.Payload) error

type ResultApprovals added in v0.14.0

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

ResultApprovals implements persistent storage for result approvals.

func NewResultApprovals added in v0.14.0

func NewResultApprovals(collector module.CacheMetrics, db *badger.DB) *ResultApprovals

func (*ResultApprovals) ByChunk added in v0.14.0

func (r *ResultApprovals) ByChunk(resultID flow.Identifier, chunkIndex uint64) (*flow.ResultApproval, error)

ByChunk retrieves a ResultApproval by result ID and chunk index. The ResultApprovals store is only used within a verification node, where it is assumed that there is never more than one approval per chunk.

func (*ResultApprovals) ByID added in v0.14.0

func (r *ResultApprovals) ByID(approvalID flow.Identifier) (*flow.ResultApproval, error)

ByID retrieves a ResultApproval by its ID

func (*ResultApprovals) Index added in v0.14.0

func (r *ResultApprovals) Index(resultID flow.Identifier, chunkIndex uint64, approvalID flow.Identifier) error

Index indexes a ResultApproval by chunk (ResultID + chunk index). operation is idempotent (repeated calls with the same value are equivalent to just calling the method once; still the method succeeds on each call).

func (*ResultApprovals) Store added in v0.14.0

func (r *ResultApprovals) Store(approval *flow.ResultApproval) error

Store stores a ResultApproval

type Seals

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

func NewSeals

func NewSeals(collector module.CacheMetrics, db *badger.DB) *Seals

func (*Seals) ByBlockID

func (s *Seals) ByBlockID(blockID flow.Identifier) (*flow.Seal, error)

func (*Seals) ByID

func (s *Seals) ByID(sealID flow.Identifier) (*flow.Seal, error)

func (*Seals) Store

func (s *Seals) Store(seal *flow.Seal) error

type ServiceEvents added in v0.14.0

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

func NewServiceEvents added in v0.14.0

func NewServiceEvents(collector module.CacheMetrics, db *badger.DB) *ServiceEvents

func (*ServiceEvents) BatchStore added in v0.15.0

func (e *ServiceEvents) BatchStore(blockID flow.Identifier, events []flow.Event, batch storage.BatchStorage) error

func (*ServiceEvents) ByBlockID added in v0.14.0

func (e *ServiceEvents) ByBlockID(blockID flow.Identifier) ([]flow.Event, error)

ByBlockID returns the events for the given block ID

type TransactionResults

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

func NewTransactionResults

func NewTransactionResults(collector module.CacheMetrics, db *badger.DB, transactionResultsCacheSize uint) *TransactionResults

func (*TransactionResults) BatchStore

func (tr *TransactionResults) BatchStore(blockID flow.Identifier, transactionResults []flow.TransactionResult, batch storage.BatchStorage) error

BatchStore will store the transaction results for the given block ID in a batch

func (*TransactionResults) ByBlockIDTransactionID

func (tr *TransactionResults) ByBlockIDTransactionID(blockID flow.Identifier, txID flow.Identifier) (*flow.TransactionResult, error)

ByBlockIDTransactionID returns the runtime transaction result for the given block ID and transaction ID

type Transactions

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

Transactions ...

func NewTransactions

func NewTransactions(cacheMetrics module.CacheMetrics, db *badger.DB) *Transactions

NewTransactions ...

func (*Transactions) ByID

ByID ...

func (*Transactions) Store

func (t *Transactions) Store(flowTx *flow.TransactionBody) error

Store ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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