Documentation
¶
Index ¶
- type DBOp
- type DeferredBlockPersist
- func (d *DeferredBlockPersist) AddNextOperation(nextOperation DBOp)
- func (d *DeferredBlockPersist) AddSucceedCallback(callback func())
- func (d *DeferredBlockPersist) Chain(deferred *DeferredBlockPersist)
- func (d *DeferredBlockPersist) Execute(lctx lockctx.Proof, blockID flow.Identifier, rw storage.ReaderBatchWriter) error
- func (d *DeferredBlockPersist) IsEmpty() bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DBOp ¶
type DBOp = func(lctx lockctx.Proof, blockID flow.Identifier, rw storage.ReaderBatchWriter) error
DBOp is a shorthand for a deferred database operation that works within a lock-protected context. It accepts a lock proof, a block ID, and a reader/writer interface to perform its task. This pattern allows chaining database updates for atomic execution in one batch updates.
type DeferredBlockPersist ¶
type DeferredBlockPersist struct {
// contains filtered or unexported fields
}
DeferredBlockPersist accumulates deferred database operations to be executed later in a single atomic batch update. Specifically, we defer appending writes and success-callbacks to a storage.ReaderBatchWriter. Operations for appending writes and success-callbacks are executed in the order in which they were queued. Since Pebble does not provide serializable snapshot isolation, callers MUST ensure that the necessary locks are acquired before executing the set of deferred operations.
This construct accomplishes two distinct goals:
- Deferring block indexing write operations when the block ID is not yet known.
- Deferring lock-requiring read-then-write operations to minimize time spent holding a lock.
NOT CONCURRENCY SAFE
func NewDeferredBlockPersist ¶
func NewDeferredBlockPersist() *DeferredBlockPersist
NewDeferredBlockPersist instantiates a DeferredBlockPersist instance. Initially, it behaves as a no-op until operations are added.
func (*DeferredBlockPersist) AddNextOperation ¶
func (d *DeferredBlockPersist) AddNextOperation(nextOperation DBOp)
AddNextOperation adds a new deferred database operation to the queue of pending operations. If there are already pending operations, this new operation will be composed to run after them. This method ensures the operations execute sequentially and abort on the first error.
If `nil` is passed, it is ignored — this might happen if chaining with an empty DeferredBlockPersist.
func (*DeferredBlockPersist) AddSucceedCallback ¶
func (d *DeferredBlockPersist) AddSucceedCallback(callback func())
AddSucceedCallback adds a callback to be executed **after** the pending database operations succeed. This is useful for registering indexing tasks or post-commit hooks. The callback is only invoked if no error occurred during batch updates execution.
func (*DeferredBlockPersist) Chain ¶
func (d *DeferredBlockPersist) Chain(deferred *DeferredBlockPersist)
Chain merges the deferred operations from another DeferredBlockPersist into this one. The resulting order of operations is: 1. execute the operations in the receiver in the order they were added 2. execute the operations from the input in the order they were added
func (*DeferredBlockPersist) Execute ¶
func (d *DeferredBlockPersist) Execute(lctx lockctx.Proof, blockID flow.Identifier, rw storage.ReaderBatchWriter) error
Execute runs all the accumulated deferred database operations in-order. If no operations were added, it is effectively a no-op. This method should be called exactly once per batch updates context.
func (*DeferredBlockPersist) IsEmpty ¶
func (d *DeferredBlockPersist) IsEmpty() bool
IsEmpty returns true if no operations have been enqueued.