badgerstorecredentials

package
v0.0.0-...-72fcfe4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package badgerstorecredentials provides the default credentials storage implementation using badger db.

Index

Constants

View Source
const DefaultOpsLimit = badgerbatch.DefaultOpsLimit

DefaultOpsLimit is the throughput limit a store takes when it is given none. It is what the calibration rule picked on the hardware measured, inside a plateau of about 100 to 1000 that every shape measured shared ([ADR-007](../decisions/adr-007-atomic-boundary-transaction-splitting.md) §3).

View Source
const (
	Prefix_Credentials = iota
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CredentialsStorage

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

func NewCredentialsStorage

func NewCredentialsStorage(db *badger.DB, opts ...StorageOption) *CredentialsStorage

NewCredentialsStorage accepts an instance of BadgerDB and returns a pointer to the instantiated CredentialsStorage. It is the responsibility of the caller to manage the db instance.

func (*CredentialsStorage) CredentialsByUserId

func (cs *CredentialsStorage) CredentialsByUserId(_ context.Context, userId ksuid.KSUID) (*register.Credentials, error)

CredentialsByUserId returns the credentials for the given user, provided it exists. On failure an error is returned.

func (*CredentialsStorage) DeleteBatchCredentials

func (cs *CredentialsStorage) DeleteBatchCredentials(
	_ context.Context,
	uids []ksuid.KSUID,
	batchFail bool,
) *register.BatchStatusBundle

DeleteBatchCredentials batches the deletion of multiple user credentials from storage. The batchFail flag indicates if the entire batch must succeed or fail as a single commit. If batchFail is false the txn will automatically be split and restart when the txn limit is exceeded. Failures are reported in a multierror error aggregate.

func (*CredentialsStorage) DeleteCredentials

func (cs *CredentialsStorage) DeleteCredentials(_ context.Context, userId ksuid.KSUID) error

DeleteCredentials deletes the credentials of the given user from storage. On failure an error is returned.

func (*CredentialsStorage) WriteBatchCredentials

func (cs *CredentialsStorage) WriteBatchCredentials(
	_ context.Context,
	batch map[ksuid.KSUID]register.Credentials,
	batchFail bool,
) *register.BatchStatusBundle

WriteBatchCredentials batches the writing of multiple user credentials to storage. The batchFail flag indicates if the entire batch must succeed or fail as a single commit. If batchFail is false the txn will automatically be split and restart when the txn limit is exceeded. Failures are reported in a multierror error aggregate.

The batch is processed with its keys sorted into ascending KSUID order, which the CredentialsStore contract requires: it is what gives the index half of an error key its meaning for a map-shaped batch, and it is creation order, so the range-scanned keyspace is walked with the locality KSUIDs are chosen for.

func (*CredentialsStorage) WriteCredentials

func (cs *CredentialsStorage) WriteCredentials(_ context.Context, userId ksuid.KSUID, credentials register.Credentials) error

WriteCredentials writes the credentials to storage for the given user. On failure an error is returned.

type StorageOption

type StorageOption func(*CredentialsStorage)

func WithOpsLimit

func WithOpsLimit(limit int) StorageOption

WithOpsLimit sets the throughput limit: the operation count at which a best-effort batch commits its transaction and starts another, even when the database's ceilings would take more. Smaller transactions measured faster, and the optimum is a property of the deployment's hardware rather than of this store, so a deployment that has measured its own sets it here. One that has not gets DefaultOpsLimit. TestCalibrateOpsLimit is how a deployment measures its own ([ADR-007](../decisions/adr-007-atomic-boundary-transaction-splitting.md) §3). A value below 1 is ignored and the default applies.

The limit is one of two bounds. A transaction also commits before the next item would carry it past the byte budget read from the database itself, so no limit set here can make a transaction the database refuses.

func WithStoragePrefix

func WithStoragePrefix(prefix byte) StorageOption

WithStoragePrefix may be used to change the store's byte prefix. This allows the underlying database instance to be shared with other stores without key conflicts.

Jump to

Keyboard shortcuts

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