transaction

package
v1.0.0-alpha.12 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSessionIsNotStarted is returned when the session is not started but is getting used
	ErrSessionIsNotStarted = status.Errorf(codes.Internal, "session not started")

	// ErrSessionIsGone is returned when the session is gone but getting used
	ErrSessionIsGone = status.Errorf(codes.Internal, "session is gone")

	// ErrTxCtxMissing is returned when the caller needs an existing transaction but passed a nil tx ctx object
	ErrTxCtxMissing = status.Errorf(codes.Internal, "tx ctx is missing")
)

Functions

This section is empty.

Types

type Manager

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

Manager is used to track all the sessions and provide all the functionality related to transactions. Once created this will create a session tracker for tracking the sessions.

func NewManager

func NewManager(kvStore kv.KeyValueStore) *Manager

func (*Manager) GetInherited

func (m *Manager) GetInherited(txCtx *api.TransactionCtx) (Tx, error)

GetInherited will return only inherited transaction i.e. return only if it is tracked and caller only wants to execute some operation inside the existing session.

func (*Manager) GetInheritedOrStartTx

func (m *Manager) GetInheritedOrStartTx(ctx context.Context, txCtx *api.TransactionCtx, enableTracking bool) (Tx, error)

GetInheritedOrStartTx will return either TxInherited if txCtx is not nil and the session is still with the tracker Or it will simply create a new explicit transaction.

func (*Manager) GetKV

func (m *Manager) GetKV() kv.KV

func (*Manager) GetTx

func (m *Manager) GetTx(txCtx *api.TransactionCtx) (Tx, error)

GetTx will return an explicit transaction that is getting tracked. It is called mainly when the caller wants to change the state of existing session like in case of Commit/Rollback.

func (*Manager) StartTx

func (m *Manager) StartTx(ctx context.Context, enableTracking bool) (Tx, *api.TransactionCtx, error)

StartTx always starts a new session and tracks the session based on the input parameter.

func (*Manager) StartTxWithoutTracking

func (m *Manager) StartTxWithoutTracking(ctx context.Context) (Tx, error)

StartTxWithoutTracking always starts a new session and disables the tracking

type SessionCtx

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

SessionCtx is used to store any baggage for the lifetime of the transaction. We use it to stage the database inside a transaction when the transaction is performing any DDLs.

func (*SessionCtx) AttachStagedDB

func (c *SessionCtx) AttachStagedDB(db StagedDB, cb func() error)

func (*SessionCtx) ExecuteCB

func (c *SessionCtx) ExecuteCB() error

func (*SessionCtx) GetStagedDB

func (c *SessionCtx) GetStagedDB() StagedDB

type StagedDB

type StagedDB interface {
	Name() string
	GetCollection(string) *schema.DefaultCollection
}

type Tx

type Tx interface {
	Insert(ctx context.Context, key keys.Key, data *internal.TableData) error
	Replace(ctx context.Context, key keys.Key, data *internal.TableData) error
	Update(ctx context.Context, key keys.Key, apply func(*internal.TableData) (*internal.TableData, error)) (int32, error)
	Delete(ctx context.Context, key keys.Key) error
	Read(ctx context.Context, key keys.Key) (kv.Iterator, error)
	Commit(ctx context.Context) error
	Rollback(ctx context.Context) error
	SetVersionstampedValue(ctx context.Context, key []byte, value []byte) error
	Get(ctx context.Context, key []byte) ([]byte, error)
	Context() *SessionCtx
}

Tx interface exposes a method to execute and then other method to end the transaction. When Tx is returned at that point transaction is already started so no need for explicit start.

type TxExplicit

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

TxExplicit is used to start an explicit transaction. Caller can control whether this transaction's session needs to be tracked inside session tracker. Tracker a session is useful if the object is shared across the requests otherwise it is not useful in the same request flow.

func NewTxExplicit

func NewTxExplicit(session *session, tracker *sessionTracker, trackingEnabled bool) *TxExplicit

NewTxExplicit creates TxExplicit object

func (*TxExplicit) Commit

func (tx *TxExplicit) Commit(ctx context.Context) error

Commit the transaction by calling commit and is also responsible for removing the session from the tracker

func (TxExplicit) Context

func (b TxExplicit) Context() *SessionCtx

func (TxExplicit) Delete

func (b TxExplicit) Delete(ctx context.Context, key keys.Key) error

func (TxExplicit) Get

func (b TxExplicit) Get(ctx context.Context, key []byte) ([]byte, error)

func (TxExplicit) Insert

func (b TxExplicit) Insert(ctx context.Context, key keys.Key, data *internal.TableData) error

func (TxExplicit) Read

func (b TxExplicit) Read(ctx context.Context, key keys.Key) (kv.Iterator, error)

func (TxExplicit) Replace

func (b TxExplicit) Replace(ctx context.Context, key keys.Key, data *internal.TableData) error

func (*TxExplicit) Rollback

func (tx *TxExplicit) Rollback(ctx context.Context) error

Rollback the transaction by calling rollback and is also responsible for removing the session from the tracker

func (TxExplicit) SetVersionstampedValue

func (b TxExplicit) SetVersionstampedValue(ctx context.Context, key []byte, value []byte) error

func (TxExplicit) Update

func (b TxExplicit) Update(ctx context.Context, key keys.Key, apply func(*internal.TableData) (*internal.TableData, error)) (int32, error)

type TxInherited

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

TxInherited is a transaction that doesn't own the state of the session and is only used to execute operation in the context of a transaction which is started by some other thread.

func NewTxInherited

func NewTxInherited(session *session) *TxInherited

NewTxInherited create TxInherited object

func (*TxInherited) Commit

func (tx *TxInherited) Commit(_ context.Context) error

Commit is noop for TxInherited, because this object doesn't own "session" so it should not modify session's state and let the owner decide the outcome of the session.

func (TxInherited) Context

func (b TxInherited) Context() *SessionCtx

func (TxInherited) Delete

func (b TxInherited) Delete(ctx context.Context, key keys.Key) error

func (TxInherited) Get

func (b TxInherited) Get(ctx context.Context, key []byte) ([]byte, error)

func (TxInherited) Insert

func (b TxInherited) Insert(ctx context.Context, key keys.Key, data *internal.TableData) error

func (TxInherited) Read

func (b TxInherited) Read(ctx context.Context, key keys.Key) (kv.Iterator, error)

func (TxInherited) Replace

func (b TxInherited) Replace(ctx context.Context, key keys.Key, data *internal.TableData) error

func (*TxInherited) Rollback

func (tx *TxInherited) Rollback(_ context.Context) error

func (TxInherited) SetVersionstampedValue

func (b TxInherited) SetVersionstampedValue(ctx context.Context, key []byte, value []byte) error

func (TxInherited) Update

func (b TxInherited) Update(ctx context.Context, key keys.Key, apply func(*internal.TableData) (*internal.TableData, error)) (int32, error)

Jump to

Keyboard shortcuts

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