Documentation
¶
Index ¶
- Variables
- type Manager
- func (m *Manager) GetInherited(txCtx *api.TransactionCtx) (Tx, error)
- func (m *Manager) GetInheritedOrStartTx(ctx context.Context, txCtx *api.TransactionCtx, enableTracking bool) (Tx, error)
- func (m *Manager) GetKV() kv.KV
- func (m *Manager) GetTx(txCtx *api.TransactionCtx) (Tx, error)
- func (m *Manager) StartTx(ctx context.Context, enableTracking bool) (Tx, *api.TransactionCtx, error)
- func (m *Manager) StartTxWithoutTracking(ctx context.Context) (Tx, error)
- type Tx
- type TxExplicit
- func (tx *TxExplicit) Commit(ctx context.Context) error
- func (b TxExplicit) Delete(ctx context.Context, key keys.Key) error
- func (b TxExplicit) Get(ctx context.Context, key []byte) ([]byte, error)
- func (b TxExplicit) Insert(ctx context.Context, key keys.Key, data *internal.TableData) error
- func (b TxExplicit) Read(ctx context.Context, key keys.Key) (kv.Iterator, error)
- func (b TxExplicit) Replace(ctx context.Context, key keys.Key, data *internal.TableData) error
- func (tx *TxExplicit) Rollback(ctx context.Context) error
- func (b TxExplicit) SetVersionstampedValue(ctx context.Context, key []byte, value []byte) error
- func (b TxExplicit) Update(ctx context.Context, key keys.Key, ...) (int32, error)
- type TxInherited
- func (tx *TxInherited) Commit(_ context.Context) error
- func (b TxInherited) Delete(ctx context.Context, key keys.Key) error
- func (b TxInherited) Get(ctx context.Context, key []byte) ([]byte, error)
- func (b TxInherited) Insert(ctx context.Context, key keys.Key, data *internal.TableData) error
- func (b TxInherited) Read(ctx context.Context, key keys.Key) (kv.Iterator, error)
- func (b TxInherited) Replace(ctx context.Context, key keys.Key, data *internal.TableData) error
- func (tx *TxInherited) Rollback(_ context.Context) error
- func (b TxInherited) SetVersionstampedValue(ctx context.Context, key []byte, value []byte) error
- func (b TxInherited) Update(ctx context.Context, key keys.Key, ...) (int32, error)
Constants ¶
This section is empty.
Variables ¶
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) 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.
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) }
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) 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 ¶
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.