datastore

package
v0.0.0-...-cd7b07c Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2019 License: GPL-3.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultImplName = "badger"

DefaultImplName should be used when a datastore impl is not specified

View Source
const (

	// ProtocolDesc appears in StorageEpochs originating from this impl
	ProtocolDesc = "plan/storage/pdi-local/1"
)

Variables

This section is empty.

Functions

func NewStorageEpoch

func NewStorageEpoch(
	skiSession ski.Session,
	inCommunity *pdi.CommunityEpoch,
) (*pdi.StorageEpoch, error)

NewStorageEpoch generates a new StorageEpoch, needed when creating a new community.

func NewTxnDecoder

func NewTxnDecoder(
	inMakeThreadsafe bool,
) pdi.TxnDecoder

NewTxnDecoder creates a TxnDecoder for use with pdi-datastore

func NewTxnEncoder

func NewTxnEncoder(
	inMakeThreadsafe bool,
	inStorageEpoch pdi.StorageEpoch,
) pdi.TxnEncoder

NewTxnEncoder creates a new StorageProviderAgent for use with a pdi-datastore StorageProvider. If inSegmentMaxSz == 0, then a default size is chosen

Types

type CommitJob

type CommitJob struct {
	Txn pdi.DecodedTxn
}

CommitJob represents a pending CommitTxn() call to a StorageProvider

type ScanJob

type ScanJob struct {
	TxnScan *pdi.TxnScan
	Outlet  pdi.StorageProvider_ScanServer

	OnComplete chan error
	// contains filtered or unexported fields
}

ScanJob represents a pending Query() call to a StorageProvider

type SendJob

type SendJob struct {
	URIDs      [][]byte
	Outlet     pdi.StorageProvider_FetchTxnsServer
	OnComplete chan error
}

SendJob represents a pending SendTxns) calls to a StorageProvider

type StorageConfig

type StorageConfig struct {
	HomePath     string           `json:"home_path"`
	ImplName     string           `json:"impl_name"`
	StorageEpoch pdi.StorageEpoch `json:"storage_epoch"`
}

StorageConfig contains core info about a db/store

type Store

type Store struct {
	ctx.Context

	AgentDesc string
	Config    *StorageConfig
	AbsPath   string

	DecodedCommits chan CommitJob

	DefaultFileMode os.FileMode
	// contains filtered or unexported fields
}

Store wraps a PLAN community UUID and a datastore

func NewStore

func NewStore(
	inConfig *StorageConfig,
	inBasePath string,
) *Store

NewStore makes a new Datastore

func (*Store) DepositTransfers

func (St *Store) DepositTransfers(inTransfers []*pdi.Transfer) error

DepositTransfers deposits the given amount to

func (*Store) DoCommitJob

func (St *Store) DoCommitJob(job CommitJob) error

DoCommitJob queues the given CommitJob

func (*Store) DoScanJob

func (St *Store) DoScanJob(job ScanJob)

DoScanJob queues the given ScanJob

func (*Store) DoSendJob

func (St *Store) DoSendJob(job SendJob)

DoSendJob queues the given SendJob

func (*Store) Startup

func (St *Store) Startup(
	inFirstTime bool,
) error

Startup should be called once Datastore is preprared and ready to invoke the underlying implementation.

type TxnHelper

type TxnHelper struct {
	Txn *badger.Txn
	// contains filtered or unexported fields
}

TxnHelper wraps ds.Txn for easier Commit() reattempts

func NewTxnHelper

func NewTxnHelper(db *badger.DB) TxnHelper

NewTxnHelper returns a helper struct that wraps datastore.Txn for convenience. This makes life easier for reattempting txns if they go stale, etc.

func (*TxnHelper) FatalErr

func (h *TxnHelper) FatalErr() error

FatalErr returns the most recent error passed to Finish() *or* an error reflecting that the max number of retries was reached. If non-nil, this reflects that the txn was NOT committed.

func (*TxnHelper) Finish

func (h *TxnHelper) Finish(inFatalErr error)

Finish is called with inFatalErr == nil to denote that the ds.Txn should be committed. If the commit

succeeds, the next call to NextAttempt() will have no effect and return false.  If the commit
fails (b/c the txn got stale), NextAttempt() will return true until the max number of attempts has been reached.

If inFatalErr != nil, then the current ds.Txn.Discard() is called and the next call to NextAttempt() will return false.

func (*TxnHelper) NextAttempt

func (h *TxnHelper) NextAttempt() bool

NextAttempt is intended to be used to control a for loop and returns true only if:

  1. the max number of attempts has not been reached
  2. Finish() has not been called with a non-nil error
  3. the txn has not yet been committed successfully yet.

Jump to

Keyboard shortcuts

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