cutter

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: Apache-2.0 Imports: 4 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchCutter

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

BatchCutter implements batch cutting.

func New

func New(client protocol.Client, queue OperationQueue) *BatchCutter

New creates a Cutter implementation.

func (*BatchCutter) Add

func (r *BatchCutter) Add(op *operation.QueuedOperation, protocolGenesisTime uint64) (uint, error)

Add adds the given operation to pending batch queue and returns the total number of pending operations.

func (*BatchCutter) Cut

func (r *BatchCutter) Cut(force bool) (Result, error)

Cut returns the current batch along with number of items that should be remaining in the queue after the committer is called. If force is false then the batch will be cut only if it has reached the max batch size (as specified in the protocol) If force is true then the batch will be cut if there is at least one Data in the batch Note that the operations are removed from the queue when Result.Ack is invoked, otherwise Result.Nack should be called in order to place the operations back in the queue so that they be processed again.

type Committer added in v0.1.3

type Committer = func() (pending uint, err error)

Committer is invoked to commit a batch Cut. The new number of pending items in the queue is returned.

type OperationQueue added in v0.1.3

type OperationQueue interface {
	// Add adds the given operation to the tail of the queue and returns the new length of the queue.
	Add(data *operation.QueuedOperation, protocolGenesisTime uint64) (uint, error)
	// Remove removes (up to) the given number of items from the head of the queue and returns:
	// - The operations that are to be removed.
	// - The 'Ack' function that must be called to commit the remove.
	// - The 'Nack' function that must be called to roll back the remove.
	Remove(num uint) (ops operation.QueuedOperationsAtTime, ack func() uint, nack func(), err error)
	// Peek returns (up to) the given number of operations from the head of the queue but does not remove them.
	Peek(num uint) (operation.QueuedOperationsAtTime, error)
	// Len returns the number of operation in the queue.
	Len() uint
}

OperationQueue defines the functions for adding and removing operations from a queue.

type Result added in v0.1.5

type Result struct {
	// Operations holds the operations that were cut from the queue
	Operations []*operation.QueuedOperation
	// ProtocolGenesisTime is the genesis time of the protocol version that was used to add the operations to the queue
	ProtocolGenesisTime uint64
	// Pending is the number of operations remaining in the queue
	Pending uint
	// Ack commits the remove from the queue and returns the number of pending operations.
	Ack func() uint
	// Nack rolls back the remove so that a retry may occur.
	Nack func()
}

Result is the result of a batch 'Cut'.

Jump to

Keyboard shortcuts

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