vc

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SnapshotDatabaseName added in v1.0.6

func SnapshotDatabaseName(ref *committerpb.TxRef) string

SnapshotDatabaseName returns the deterministic clone-database name for ref, so a test outside this package names the same clone the commit path would.

Types

type Config

type Config struct {
	Database       *statedb.Config       `mapstructure:"database" validate:"required"`
	ResourceLimits *ResourceLimitsConfig `mapstructure:"resource-limits" validate:"required"`
}

Config is the configuration for the validator-committer service.

type DatabaseTestEnv

type DatabaseTestEnv struct {
	DB     *database
	DBConf *statedb.Config
}

DatabaseTestEnv represents a database test environment.

func NewDatabaseTestEnv

func NewDatabaseTestEnv(t *testing.T) *DatabaseTestEnv

NewDatabaseTestEnv creates a new default database test environment.

func NewDatabaseTestEnvFromConnection added in v0.1.8

func NewDatabaseTestEnvFromConnection(t *testing.T, cs *testdb.Connection, loadBalance bool) *DatabaseTestEnv

NewDatabaseTestEnvFromConnection creates a new db test environment given a db connection without preparations.

func NewDatabaseTestEnvWithCustomConnection added in v0.1.7

func NewDatabaseTestEnvWithCustomConnection(t *testing.T, dbConnections *testdb.Connection) *DatabaseTestEnv

NewDatabaseTestEnvWithCustomConnection creates a new db test environment given a db connection.

func (*DatabaseTestEnv) ClearLatestSnapshotKey added in v1.0.6

func (env *DatabaseTestEnv) ClearLatestSnapshotKey(t *testing.T)

ClearLatestSnapshotKey clears the latest-snapshot pointer without deleting snapshot rows. Tests use it to simulate inconsistent metadata that normal commits cannot produce.

func (*DatabaseTestEnv) CountAlternateStatus

func (env *DatabaseTestEnv) CountAlternateStatus(t *testing.T, status committerpb.Status) int

CountAlternateStatus returns the number of transactions not with a given tx status.

func (*DatabaseTestEnv) CountStatus

func (env *DatabaseTestEnv) CountStatus(t *testing.T, status committerpb.Status) int

CountStatus returns the number of transactions with a given tx status.

func (*DatabaseTestEnv) CreateSnapshotClone added in v1.0.6

func (env *DatabaseTestEnv) CreateSnapshotClone(t *testing.T, name string)

CreateSnapshotClone creates the named clone database through the same path the commit uses, and registers its drop as cleanup so a parallel test run does not leak cluster-global databases.

func (*DatabaseTestEnv) FetchKeys

func (env *DatabaseTestEnv) FetchKeys(t *testing.T, nsID string, keys [][]byte) map[string]*ValueVersion

FetchKeys fetches a list of keys.

func (*DatabaseTestEnv) InsertRowDirectly added in v1.0.6

func (env *DatabaseTestEnv) InsertRowDirectly(t *testing.T, nsID string, row KeyValue)

InsertRowDirectly inserts a row into ns_<nsID> without registering the namespace in ns__meta, which is the only way to populate a system namespace (`_snapshot`, `_checkpoint`) whose table already exists but is deliberately never registered.

func (*DatabaseTestEnv) ReadSnapshotRecord added in v1.0.6

func (env *DatabaseTestEnv) ReadSnapshotRecord(ctx context.Context, txID string) (*SnapshotRecord, bool)

ReadSnapshotRecord reads a `_snapshot` record and its row version.

It goes through the retry profile rather than a bare query because creating a snapshot clone briefly severs this pool's connections on PostgreSQL, so an otherwise-correct read can fail purely because it raced a clone.

func (*DatabaseTestEnv) SeedSnapshotRecord added in v1.0.6

func (env *DatabaseTestEnv) SeedSnapshotRecord(t *testing.T, f SnapshotFixture)

SeedSnapshotRecord commits a `_snapshot` record for f.Ref directly at f.Status, bypassing the normal PENDING-then-hasher-advances flow.

Committing it through db.commit rather than a raw INSERT is what makes the fixture realistic: the txID lands in tx_status and the latest-snapshot pointer is written in the same transaction as the row, which is how a reader finds it.

func (*DatabaseTestEnv) SeedSnapshotRecordWithoutTxRef added in v1.0.6

func (env *DatabaseTestEnv) SeedSnapshotRecordWithoutTxRef(t *testing.T, txID, cloneDatabase string)

SeedSnapshotRecordWithoutTxRef commits a `_snapshot` record whose value carries no TxRef, which a reader cannot address. Only a bug or storage corruption produces one, so a fixture is the only way to cover how a reader reports it.

func (*DatabaseTestEnv) SeedState added in v1.0.6

func (env *DatabaseTestEnv) SeedState(t *testing.T, f StateFixture)

SeedState commits f through the normal commit path, so the resulting state is indistinguishable from state produced by real transactions.

func (*DatabaseTestEnv) StatusExistsForNonDuplicateTxID

func (env *DatabaseTestEnv) StatusExistsForNonDuplicateTxID(
	ctx context.Context,
	t *testing.T,
	expectedStatuses []*committerpb.TxStatus,
)

StatusExistsForNonDuplicateTxID ensures that the given statuses and height exist for the corresponding txIDs in the tx_status table, excluding any duplicate txID statuses.

func (*DatabaseTestEnv) StatusExistsWithDifferentHeightForDuplicateTxID

func (env *DatabaseTestEnv) StatusExistsWithDifferentHeightForDuplicateTxID(
	t *testing.T,
	expectedStatuses []*committerpb.TxStatus,
)

StatusExistsWithDifferentHeightForDuplicateTxID ensures that the given statuses and height do not exist for corresponding txIDs in the tx_status table for duplicate txID statuses.

type KeyValue added in v1.0.6

type KeyValue struct {
	Key   []byte
	Value []byte
}

KeyValue is one namespace row in a StateFixture.

type ResourceLimitsConfig

type ResourceLimitsConfig struct {
	MaxWorkersForPreparer             int           `mapstructure:"max-workers-for-preparer" default:"1" validate:"gt=0"`                //nolint:lll,revive
	MaxWorkersForValidator            int           `mapstructure:"max-workers-for-validator" default:"1" validate:"gt=0"`               //nolint:lll,revive
	MaxWorkersForCommitter            int           `mapstructure:"max-workers-for-committer" default:"20" validate:"gt=0"`              //nolint:lll,revive
	MinTransactionBatchSize           int           `mapstructure:"min-transaction-batch-size" default:"1" validate:"gt=0"`              //nolint:lll,revive
	TimeoutForMinTransactionBatchSize time.Duration `mapstructure:"timeout-for-min-transaction-batch-size" default:"5s" validate:"gt=0"` //nolint:lll,revive
}

ResourceLimitsConfig is the configuration for the resource limits.

type SnapshotFixture added in v1.0.6

type SnapshotFixture struct {
	Ref           *committerpb.TxRef
	Status        committerpb.SnapshotState_Status
	CloneDatabase string
}

SnapshotFixture describes a durable `_snapshot` record a test wants in place. It exists because the snapshot hasher and the integration tests both need the state the commit path leaves behind, without driving a whole block through the pipeline: the record, the committed txID, and the latest-snapshot pointer.

The clone database itself is not created here. A test that needs one calls CreateSnapshotClone, which keeps a record whose clone must be absent (asserting how a missing clone is reported) on the same footing as one whose clone exists.

type SnapshotRecord added in v1.0.6

type SnapshotRecord struct {
	State   *committerpb.SnapshotState
	Version int64
}

SnapshotRecord is a `_snapshot` record together with its row version, so a test can assert that a tick did NOT rewrite a record, not merely that its status is unchanged.

type StateFixture added in v1.0.6

type StateFixture struct {
	// NamespaceIDs are registered in ns__meta, which both creates their ns_<id>
	// tables and makes them part of the hashed table set.
	NamespaceIDs []string
	// Rows are the namespace rows to insert, keyed by namespace ID.
	Rows map[string][]KeyValue
	// TxStatuses are committed as COMMITTED tx_status rows, so a fixture can also
	// populate the tx_status table.
	TxStatuses []*committerpb.TxRef
}

StateFixture describes committed state a test wants in the database before it exercises something that reads the whole state, such as hashing a clone.

type TestEnvOpts added in v0.1.8

type TestEnvOpts struct {
	NumServices    int
	ServerCreds    connection.TLSConfig
	ResourceLimits *ResourceLimitsConfig
	DBEnv          *DatabaseTestEnv
}

TestEnvOpts contains options for creating a VC test environment.

type TxID

type TxID string

TxID is the type defining the transaction identifier.

type ValidatorAndCommitterServiceTestEnv

type ValidatorAndCommitterServiceTestEnv struct {
	VCServices    []*ValidatorCommitterService
	DBEnv         *DatabaseTestEnv
	Configs       []*Config
	ServerConfigs []*serve.Config
	Endpoints     []*connection.Endpoint
}

ValidatorAndCommitterServiceTestEnv denotes the test environment for vcservice.

func NewValidatorAndCommitServiceTestEnv

func NewValidatorAndCommitServiceTestEnv(t *testing.T, opts *TestEnvOpts) *ValidatorAndCommitterServiceTestEnv

NewValidatorAndCommitServiceTestEnv creates a new test environment with the given options.

func (*ValidatorAndCommitterServiceTestEnv) GetDBEnv

GetDBEnv returns the database test environment.

type ValidatorCommitterService

type ValidatorCommitterService struct {
	servicepb.UnimplementedValidationAndCommitServiceServer
	// contains filtered or unexported fields
}

ValidatorCommitterService is the service that receives transactions from the client, prepares them, validates them and commits them to the database. It is composed of a preparer, a validator and a committer. The preparer receives transactions from the client and prepares them for validation. The validator receives prepared transactions from the preparer and validates them. The committer receives validated transactions from the validator and commits them to the database. The service also sends the status of the transactions to the client. ValidatorCommitterService is a gRPC service that implements the ValidationAndCommitService interface.

func NewValidatorCommitterService

func NewValidatorCommitterService(
	ctx context.Context,
	config *Config,
) *ValidatorCommitterService

NewValidatorCommitterService creates a new ValidatorCommitterService. It creates the preparer, the validator and the committer. It also creates the channels that are used to communicate between the preparer, the validator and the committer. It also creates the database connection.

func (*ValidatorCommitterService) GetConfigTransaction

GetConfigTransaction retrieves the config block from the database.

func (*ValidatorCommitterService) GetNamespacePolicies

GetNamespacePolicies retrieves the policy data from the database.

func (*ValidatorCommitterService) GetNextBlockNumberToCommit added in v0.1.8

func (vc *ValidatorCommitterService) GetNextBlockNumberToCommit(
	ctx context.Context,
	_ *emptypb.Empty,
) (*servicepb.BlockRef, error)

GetNextBlockNumberToCommit get the last committed block number in the database/ledger.

func (*ValidatorCommitterService) GetTransactionsStatus

func (vc *ValidatorCommitterService) GetTransactionsStatus(
	ctx context.Context,
	query *committerpb.TxIDsBatch,
) (*servicepb.TxStatusBatch, error)

GetTransactionsStatus gets the status of a given set of transaction IDs.

func (*ValidatorCommitterService) RegisterService added in v0.1.5

func (vc *ValidatorCommitterService) RegisterService(s serve.Servers)

RegisterService registers the validator-committer's gRPC services and monitoring server.

func (*ValidatorCommitterService) Run

Run starts the validator and committer service.

func (*ValidatorCommitterService) SetLastCommittedBlockNumber

func (vc *ValidatorCommitterService) SetLastCommittedBlockNumber(
	ctx context.Context,
	lastCommittedBlock *servicepb.BlockRef,
) (*emptypb.Empty, error)

SetLastCommittedBlockNumber set the last committed block number in the database/ledger.

func (*ValidatorCommitterService) StartValidateAndCommitStream

StartValidateAndCommitStream is the function that starts the stream between the client and the service. It receives transactions from the client, prepares them, validates them and commits them to the database. It also sends the status of the transactions to the client.

func (*ValidatorCommitterService) WaitForReady

func (vc *ValidatorCommitterService) WaitForReady(ctx context.Context) bool

WaitForReady wait for the service to be ready to be exposed as gRPC service. If the context ended before the service is ready, returns false.

type ValueVersion

type ValueVersion struct {
	Value   []byte
	Version uint64
}

ValueVersion contains a list of values and their matching versions.

Jump to

Keyboard shortcuts

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