storage

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2021 License: Apache-2.0, MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSchemaTooOld = errors.New("database schema is too old and requires migration")
	ErrSchemaTooNew = errors.New("database schema is too new for this version of visor")
)
View Source
var ErrLockNotAcquired = errors.New("lock not acquired")
View Source
var ErrLockNotReleased = errors.New("lock not released")

Functions

This section is empty.

Types

type AdvisoryLock

type AdvisoryLock int64

An AdvisoryLock is a lock that is managed by Postgres but is only enforced by the application. Advisory locks are automatically released at the end of a session. It is safe to hold both a shared and exclusive lock within a single session.

var (
	SchemaLock AdvisoryLock = 1
)

Advisory locks

func (AdvisoryLock) LockExclusive

func (l AdvisoryLock) LockExclusive(ctx context.Context, db *pg.DB) error

LockShared tries to acquire a session scoped exclusive advisory lock.

func (AdvisoryLock) LockShared

func (l AdvisoryLock) LockShared(ctx context.Context, db *pg.DB) error

LockShared tries to acquire a session scoped shared advisory lock.

func (AdvisoryLock) UnlockExclusive

func (l AdvisoryLock) UnlockExclusive(ctx context.Context, db *pg.DB) error

UnlockExclusive releases an exclusive advisory lock.

func (AdvisoryLock) UnlockShared

func (l AdvisoryLock) UnlockShared(ctx context.Context, db *pg.DB) error

UnlockShared releases a shared advisory lock.

type Database

type Database struct {
	DB *pg.DB

	Clock clock.Clock
	// contains filtered or unexported fields
}

func NewDatabase

func NewDatabase(ctx context.Context, url string, poolSize int, name string) (*Database, error)

func (*Database) Close

func (d *Database) Close(ctx context.Context) error

func (*Database) Connect

func (d *Database) Connect(ctx context.Context) error

Connect opens a connection to the database and checks that the schema is compatible the the version required by this version of visor. ErrSchemaTooOld is returned if the database schema is older than the current schema, ErrSchemaTooNew if it is newer.

func (*Database) FindActors added in v0.3.0

func (d *Database) FindActors(ctx context.Context, batchSize int, minHeight, maxHeight int64, codes []string) (visor.ProcessingActorList, error)

FindActors finds a set of actors to process but does not take a lease out. minHeight and maxHeight define an inclusive range of heights to process.

func (*Database) FindGasOutputsMessages added in v0.3.0

func (d *Database) FindGasOutputsMessages(ctx context.Context, batchSize int, minHeight, maxHeight int64) ([]*derived.ProcessingGasOutputs, error)

FindGasOutputsMessages finds a set of messages that have receipts for gas output processing but does not take a lease out. minHeight and maxHeight define an inclusive range of heights to process.

func (*Database) GetActorByHead

func (d *Database) GetActorByHead(ctx context.Context, head string) (*visor.ProcessingActor, error)

GetActorByHead returns an actor without a lease by its CID

func (*Database) GetSchemaVersions

func (d *Database) GetSchemaVersions(ctx context.Context) (int, int, error)

GetSchemaVersions returns the schema version in the database and the latest schema version defined by the available migrations.

func (*Database) LeaseActors

func (d *Database) LeaseActors(ctx context.Context, claimUntil time.Time, batchSize int, minHeight, maxHeight int64, codes []string) (visor.ProcessingActorList, error)

LeaseActors leases a set of actors to process. minHeight and maxHeight define an inclusive range of heights to process.

func (*Database) LeaseGasOutputsMessages

func (d *Database) LeaseGasOutputsMessages(ctx context.Context, claimUntil time.Time, batchSize int, minHeight, maxHeight int64) ([]*derived.ProcessingGasOutputs, error)

LeaseGasOutputsMessages leases a set of messages that have receipts for gas output processing. minHeight and maxHeight define an inclusive range of heights to process.

func (*Database) LeaseStateChanges

func (d *Database) LeaseStateChanges(ctx context.Context, claimUntil time.Time, batchSize int, minHeight, maxHeight int64) (visor.ProcessingTipSetList, error)

func (*Database) LeaseTipSetEconomics added in v0.3.0

func (d *Database) LeaseTipSetEconomics(ctx context.Context, claimUntil time.Time, batchSize int, minHeight, maxHeight int64) (visor.ProcessingTipSetList, error)

LeaseTipSetEconomics leases a set of tipsets containing chain economics to process. minHeight and maxHeight define an inclusive range of heights to process. TODO: refactor all the tipset leasing methods into a more general function

func (*Database) LeaseTipSetMessages

func (d *Database) LeaseTipSetMessages(ctx context.Context, claimUntil time.Time, batchSize int, minHeight, maxHeight int64) (visor.ProcessingTipSetList, error)

LeaseTipSetMessages leases a set of tipsets containing messages to process. minHeight and maxHeight define an inclusive range of heights to process.

func (*Database) MarkActorComplete

func (d *Database) MarkActorComplete(ctx context.Context, height int64, head string, code string, completedAt time.Time, errorsDetected string) error

func (*Database) MarkGasOutputsMessagesComplete

func (d *Database) MarkGasOutputsMessagesComplete(ctx context.Context, height int64, cid string, completedAt time.Time, errorsDetected string) error

func (*Database) MarkStateChangeComplete

func (d *Database) MarkStateChangeComplete(ctx context.Context, tsk string, height int64, completedAt time.Time, errorsDetected string) error

func (*Database) MarkTipSetEconomicsComplete added in v0.3.0

func (d *Database) MarkTipSetEconomicsComplete(ctx context.Context, tipset string, height int64, completedAt time.Time, errorsDetected string) error

func (*Database) MarkTipSetMessagesComplete

func (d *Database) MarkTipSetMessagesComplete(ctx context.Context, tipset string, height int64, completedAt time.Time, errorsDetected string) error

func (*Database) MigrateSchema

func (d *Database) MigrateSchema(ctx context.Context) error

MigrateSchema migrates the database schema to the latest version based on the list of migrations available

func (*Database) MigrateSchemaTo

func (d *Database) MigrateSchemaTo(ctx context.Context, target int) error

MigrateSchema migrates the database schema to a specific version. Note that downgrading a schema to an earlier version is destructive and may result in the loss of data.

func (*Database) MostRecentAddedTipSet

func (d *Database) MostRecentAddedTipSet(ctx context.Context) (*visor.ProcessingTipSet, error)

func (*Database) Persist added in v0.4.0

func (d *Database) Persist(ctx context.Context, p model.PersistableWithTx) error

func (*Database) UnprocessedIndexedTipSets

func (d *Database) UnprocessedIndexedTipSets(ctx context.Context, maxHeight, limit int) (visor.ProcessingTipSetList, error)

func (*Database) VerifyCurrentSchema

func (d *Database) VerifyCurrentSchema(ctx context.Context) error

VerifyCurrentSchema compares the schema present in the database with the models used by visor and returns an error if they are incompatible

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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