store

package
v0.0.0-...-269d6e4 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StatusOpen is an open batch.
	StatusOpen = BatchStatus(db.BatchStatusOpen)
	// StatusReady is a ready to be created batch.
	StatusReady = BatchStatus(db.BatchStatusReady)
	// StatusExecuting is a batch being processed.
	StatusExecuting = BatchStatus(db.BatchStatusExecuting)
	// StatusDone is an batch that was correctly created.
	StatusDone = BatchStatus(db.BatchStatusDone)
)

Variables

View Source
var (

	// ErrOperationIDExists indicates that the storage request inclusion
	// in a batch already exists.
	ErrOperationIDExists = errors.New("operation-id already exists")
)

Functions

This section is empty.

Types

type BatchStatus

type BatchStatus db.BatchStatus

BatchStatus is the status of a batch.

type DoneBatchStats

type DoneBatchStats struct {
	Origin string
	Count  int64
	Bytes  int64
}

DoneBatchStats provides information for a done batch.

type OpenBatchStats

type OpenBatchStats struct {
	Origin   string
	CidCount int64
	Bytes    int64
	Count    int64
}

OpenBatchStats provides information for an open batch.

type StorageRequest

type StorageRequest = db.StorageRequest

StorageRequest is a storage request from a batch.

type Store

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

Store is a store for unprepared batches.

func New

func New(postgresURI string,
	batchMaxSize,
	batchMinSize int64,
	batchMinWaiting time.Duration,
	batchWaitScalingFactor int64) (*Store, error)

New returns a new Store.

func (*Store) AddStorageRequestToOpenBatch

func (s *Store) AddStorageRequestToOpenBatch(
	ctx context.Context,
	opID string,
	srID broker.StorageRequestID,
	dataCid cid.Cid,
	dataSize int64,
	origin string) error

AddStorageRequestToOpenBatch adds a storage request to an open batch if available, and creates one if that isn't the case.

func (*Store) Close

func (s *Store) Close() error

Close closes the store.

func (*Store) CtxWithTx

func (s *Store) CtxWithTx(ctx context.Context, opts ...storeutil.TxOptions) (context.Context, error)

CtxWithTx attach a database transaction to the context. It returns the context unchanged if there's error starting the transaction.

func (*Store) GetNextReadyBatch

func (s *Store) GetNextReadyBatch(
	ctx context.Context) (
	batchID broker.BatchID,
	totalSize int64,
	srs []StorageRequest,
	origin string,
	exists bool,
	err error)

GetNextReadyBatch returns the next ready batch to be processed batch and changes the status to Executing. The caller is responsible for updating the status later to Ready on error, or Done on success.

func (*Store) GetStats

func (s *Store) GetStats(ctx context.Context) ([]OpenBatchStats, []DoneBatchStats, error)

GetStats return stats about batches.

func (*Store) MoveBatchToStatus

func (s *Store) MoveBatchToStatus(
	ctx context.Context,
	batchID broker.BatchID,
	delay time.Duration,
	status BatchStatus) error

MoveBatchToStatus moves a batch to a specified status.

func (*Store) TimeBasedBatchClose

func (s *Store) TimeBasedBatchClose(ctx context.Context) error

TimeBasedBatchClose closes all batches that satisfy the time-based closing criteria.

Directories

Path Synopsis
internal
db
Package migrations generated by go-bindata.// sources: migrations/001_init.down.sql migrations/001_init.up.sql
Package migrations generated by go-bindata.// sources: migrations/001_init.down.sql migrations/001_init.up.sql

Jump to

Keyboard shortcuts

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