transactionenv

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthTransactionServer

type AuthTransactionServer interface {
	AuthorizeInTransaction(*TransactionContext, *auth.AuthorizeRequest) (*auth.AuthorizeResponse, error)

	GetScopeInTransaction(*TransactionContext, *auth.GetScopeRequest) (*auth.GetScopeResponse, error)
	SetScopeInTransaction(*TransactionContext, *auth.SetScopeRequest) (*auth.SetScopeResponse, error)

	GetACLInTransaction(*TransactionContext, *auth.GetACLRequest) (*auth.GetACLResponse, error)
	SetACLInTransaction(*TransactionContext, *auth.SetACLRequest) (*auth.SetACLResponse, error)
}

AuthTransactionServer is an interface for the transactionally-supported methods that can be called through the auth server.

type AuthWrites

type AuthWrites interface {
	SetScope(*auth.SetScopeRequest) (*auth.SetScopeResponse, error)
	SetACL(*auth.SetACLRequest) (*auth.SetACLResponse, error)
}

AuthWrites is an interface providing a wrapper for each operation that may be appended to a transaction through the Auth server. Each call may either directly run the request through Auth or append it to the active transaction, depending on if there is an active transaction in the client context.

type PfsPropagater

type PfsPropagater interface {
	PropagateCommit(branch *pfs.Branch, isNewCommit bool) error
	Run() error
}

PfsPropagater is the interface that PFS implements to propagate commits at the end of a transaction. It is defined here to avoid a circular dependency.

type PfsTransactionServer

type PfsTransactionServer interface {
	NewPropagater(col.STM) PfsPropagater

	CreateRepoInTransaction(*TransactionContext, *pfs.CreateRepoRequest) error
	InspectRepoInTransaction(*TransactionContext, *pfs.InspectRepoRequest) (*pfs.RepoInfo, error)
	DeleteRepoInTransaction(*TransactionContext, *pfs.DeleteRepoRequest) error

	StartCommitInTransaction(*TransactionContext, *pfs.StartCommitRequest, *pfs.Commit) (*pfs.Commit, error)
	FinishCommitInTransaction(*TransactionContext, *pfs.FinishCommitRequest) error
	DeleteCommitInTransaction(*TransactionContext, *pfs.DeleteCommitRequest) error

	CreateBranchInTransaction(*TransactionContext, *pfs.CreateBranchRequest) error
	DeleteBranchInTransaction(*TransactionContext, *pfs.DeleteBranchRequest) error
}

PfsTransactionServer is an interface for the transactionally-supported methods that can be called through the PFS server.

type PfsWrites

type PfsWrites interface {
	CreateRepo(*pfs.CreateRepoRequest) error
	DeleteRepo(*pfs.DeleteRepoRequest) error

	StartCommit(*pfs.StartCommitRequest, *pfs.Commit) (*pfs.Commit, error)
	FinishCommit(*pfs.FinishCommitRequest) error
	DeleteCommit(*pfs.DeleteCommitRequest) error

	CreateBranch(*pfs.CreateBranchRequest) error
	DeleteBranch(*pfs.DeleteBranchRequest) error
}

PfsWrites is an interface providing a wrapper for each operation that may be appended to a transaction through PFS. Each call may either directly run the request through PFS or append it to the active transaction, depending on if there is an active transaction in the client context.

type Transaction

type Transaction interface {
	PfsWrites
	AuthWrites
}

Transaction is an interface to unify the code that may either perform an action directly or append an action to an existing transaction (depending on if there is an active transaction in the client context metadata). There are two implementations of this interface:

directTransaction: all operations will be run directly through the relevant
  server, all inside the same STM.
appendTransaction: all operations will be appended to the active transaction
  which will then be dryrun so that the response for the operation can be
  returned.  Each operation that is appended will do a new dryrun, so this
  isn't as efficient as it could be.

func NewDirectTransaction

func NewDirectTransaction(txnCtx *TransactionContext) Transaction

NewDirectTransaction is a helper function to instantiate a directTransaction object. It is exposed so that the transaction API server can run a direct transaction even though there is an active transaction in the context (which is why it cannot use `WithTransaction`).

type TransactionContext

type TransactionContext struct {
	ClientContext context.Context
	Client        *client.APIClient
	Stm           col.STM
	// contains filtered or unexported fields
}

TransactionContext is a helper type to encapsulate the state for a given set of operations being performed in the Pachyderm API. When a new transaction is started, a context will be created for it containing these objects, which will be threaded through to every API call:

ctx: the client context which initiated the operations being performed
pachClient: the APIClient associated with the client context ctx
stm: the object that controls transactionality with etcd.  This is to ensure
  that all reads and writes are consistent until changes are committed.
txnEnv: a struct containing references to each API server, it can be used
  to make calls to other API servers (e.g. checking auth permissions)
pfsDefer: an interface for ensuring certain PFS cleanup tasks are performed
  properly (and deduped) at the end of the transaction.

func (*TransactionContext) Auth

Auth returns a reference to the Auth API Server so that transactionally- supported methods can be called across the API boundary without using RPCs (which will not maintain transactional guarantees)

func (*TransactionContext) Pfs

Pfs returns a reference to the PFS API Server so that transactionally- supported methods can be called across the API boundary without using RPCs (which will not maintain transactional guarantees)

func (*TransactionContext) PropagateCommit

func (t *TransactionContext) PropagateCommit(branch *pfs.Branch, isNewCommit bool) error

PropagateCommit saves a branch to be propagated at the end of the transaction (if all operations complete successfully). This is used to batch together propagations and dedupe downstream commits in PFS.

type TransactionEnv

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

TransactionEnv contains the APIServer instances for each subsystem that may be involved in running transactions so that they can make calls to each other without leaving the context of a transaction. This is a separate object because there are cyclic dependencies between APIServer instances.

func (*TransactionEnv) Initialize

func (env *TransactionEnv) Initialize(
	serviceEnv *serviceenv.ServiceEnv,
	txnServer TransactionServer,
	authServer AuthTransactionServer,
	pfsServer PfsTransactionServer,
)

Initialize stores the references to APIServer instances in the TransactionEnv

func (*TransactionEnv) WithReadContext

func (env *TransactionEnv) WithReadContext(ctx context.Context, cb func(*TransactionContext) error) error

WithReadContext will call the given callback with a TransactionContext which can be used to perform reads of the current cluster state. If the transaction is used to perform any writes, they will be silently discarded.

func (*TransactionEnv) WithTransaction

func (env *TransactionEnv) WithTransaction(ctx context.Context, cb func(Transaction) error) error

WithTransaction will call the given callback with a txnenv.Transaction object, which is instantiated differently based on if an active transaction is present in the RPC context. If an active transaction is present, any calls into the Transaction are first dry-run then appended to the transaction. If there is no active transaction, the request will be run directly through the selected server.

func (*TransactionEnv) WithWriteContext

func (env *TransactionEnv) WithWriteContext(ctx context.Context, cb func(*TransactionContext) error) error

WithWriteContext will call the given callback with a TransactionContext which can be used to perform reads and writes on the current cluster state.

type TransactionServer

type TransactionServer interface {
	AppendRequest(
		context.Context,
		*transaction.Transaction,
		*transaction.TransactionRequest,
	) (*transaction.TransactionResponse, error)
}

TransactionServer is an interface used by other servers to append a request to an existing transaction.

Jump to

Keyboard shortcuts

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