Documentation ¶
Index ¶
- Constants
- Variables
- func MaxClusterTime(ct1 *bson.Document, ct2 *bson.Document) *bson.Document
- type Client
- func (c *Client) AbortTransaction() error
- func (c *Client) AdvanceClusterTime(clusterTime *bson.Document) error
- func (c *Client) AdvanceOperationTime(opTime *bson.Timestamp) error
- func (c *Client) ApplyCommand()
- func (c *Client) CheckAbortTransaction() error
- func (c *Client) CheckCommitTransaction() error
- func (c *Client) CheckStartTransaction() error
- func (c *Client) CommitTransaction() error
- func (c *Client) EndSession()
- func (c *Client) StartTransaction(opts ...ClientOptioner) error
- func (c *Client) TransactionCommitted() bool
- func (c *Client) TransactionInProgress() bool
- func (c *Client) TransactionRunning() bool
- func (c *Client) TransactionStarting() bool
- func (c *Client) UpdateUseTime() error
- type ClientOptioner
- type ClusterClock
- type Node
- type OptCausalConsistency
- type OptCurrentReadConcern
- type OptCurrentReadPreference
- type OptCurrentWriteConcern
- type OptDefaultReadConcern
- type OptDefaultReadPreference
- type OptDefaultWriteConcern
- type Pool
- type Server
- type Type
Constants ¶
const ( None state = iota Starting InProgress Committed Aborted )
Client Session states
const UUIDSubtype byte = 4
UUIDSubtype is the BSON binary subtype that a UUID should be encoded as
Variables ¶
var ErrAbortAfterCommit = errors.New("cannot call abortTransaction after calling commitTransaction")
ErrAbortAfterCommit is returned when abort is called after a commit.
var ErrAbortTwice = errors.New("cannot call abortTransaction twice")
ErrAbortTwice is returned if abort is called after transaction is already aborted.
var ErrCommitAfterAbort = errors.New("cannot call commitTransaction after calling abortTransaction")
ErrCommitAfterAbort is returned if commit is called after an abort.
var ErrNoTransactStarted = errors.New("no transaction started")
ErrNoTransactStarted is returned if a transaction operation is called when no transaction has started.
var ErrSessionEnded = errors.New("ended session was used")
ErrSessionEnded is returned when a client session is used after a call to endSession().
var ErrTransactInProgress = errors.New("transaction already in progress")
ErrTransactInProgress is returned if startTransaction() is called when a transaction is in progress.
var ErrUnackWCUnsupported = errors.New("transactions do not support unacknowledged write concerns")
ErrUnackWCUnsupported is returned if an unacknowledged write concern is supported for a transaciton.
Functions ¶
Types ¶
type Client ¶
type Client struct { *Server ClientID uuid.UUID ClusterTime *bson.Document Consistent bool // causal consistency OperationTime *bson.Timestamp SessionType Type Terminated bool RetryingCommit bool Committing bool Aborting bool RetryWrite bool // options for the current transaction // most recently set by transactionopt CurrentRc *readconcern.ReadConcern CurrentRp *readpref.ReadPref CurrentWc *writeconcern.WriteConcern // contains filtered or unexported fields }
Client is a session for clients to run commands.
func NewClientSession ¶
func NewClientSession(pool *Pool, clientID uuid.UUID, sessionType Type, opts ...ClientOptioner) (*Client, error)
NewClientSession creates a Client.
func (*Client) AbortTransaction ¶ added in v0.0.12
AbortTransaction updates the state for a successfully committed transaction and returns an error if not permissible. It does not actually perform the abort.
func (*Client) AdvanceClusterTime ¶
AdvanceClusterTime updates the session's cluster time.
func (*Client) AdvanceOperationTime ¶ added in v0.0.11
AdvanceOperationTime updates the session's operation time.
func (*Client) ApplyCommand ¶ added in v0.0.12
func (c *Client) ApplyCommand()
ApplyCommand advances the state machine upon command execution.
func (*Client) CheckAbortTransaction ¶ added in v0.0.12
CheckAbortTransaction checks to see if allowed to abort transaction and returns an error if not allowed.
func (*Client) CheckCommitTransaction ¶ added in v0.0.12
CheckCommitTransaction checks to see if allowed to commit transaction and returns an error if not allowed.
func (*Client) CheckStartTransaction ¶ added in v0.0.12
CheckStartTransaction checks to see if allowed to start transaction and returns an error if not allowed
func (*Client) CommitTransaction ¶ added in v0.0.12
CommitTransaction updates the state for a successfully committed transaction and returns an error if not permissible. It does not actually perform the commit.
func (*Client) StartTransaction ¶ added in v0.0.12
func (c *Client) StartTransaction(opts ...ClientOptioner) error
StartTransaction initializes the transaction options and advances the state machine. It does not contact the server to start the transaction.
func (*Client) TransactionCommitted ¶ added in v0.0.12
TransactionCommitted returns true of the client session just committed a transaciton.
func (*Client) TransactionInProgress ¶ added in v0.0.12
TransactionInProgress returns true if the client session is in an active transaction.
func (*Client) TransactionRunning ¶ added in v0.0.12
TransactionRunning returns true if the client session has started the transaction and it hasn't been committed or aborted
func (*Client) TransactionStarting ¶ added in v0.0.12
TransactionStarting returns true if the client session is starting a transaction.
func (*Client) UpdateUseTime ¶
UpdateUseTime updates the session's last used time. Must be called whenver this session is used to send a command to the server.
type ClientOptioner ¶ added in v0.0.11
ClientOptioner is the interface implemented by types that can be used as options for configuring a client session.
type ClusterClock ¶
type ClusterClock struct {
// contains filtered or unexported fields
}
ClusterClock represents a logical clock for keeping track of cluster time.
func (*ClusterClock) AdvanceClusterTime ¶
func (cc *ClusterClock) AdvanceClusterTime(clusterTime *bson.Document)
AdvanceClusterTime updates the cluster's current time.
func (*ClusterClock) GetClusterTime ¶
func (cc *ClusterClock) GetClusterTime() *bson.Document
GetClusterTime returns the cluster's current time.
type Node ¶
type Node struct { *Server // contains filtered or unexported fields }
Node represents a server session in a linked list
type OptCausalConsistency ¶ added in v0.0.11
type OptCausalConsistency bool
OptCausalConsistency specifies if a session should be causally consistent.
func (OptCausalConsistency) Option ¶ added in v0.0.11
func (opt OptCausalConsistency) Option(c *Client) error
Option implements the ClientOptioner interface.
type OptCurrentReadConcern ¶ added in v0.0.12
type OptCurrentReadConcern struct {
*readconcern.ReadConcern
}
OptCurrentReadConcern specifies the read concern to be used for the current transaction.
func (OptCurrentReadConcern) Option ¶ added in v0.0.12
func (opt OptCurrentReadConcern) Option(c *Client) error
Option implements the ClientOptioner interface.
type OptCurrentReadPreference ¶ added in v0.0.12
OptCurrentReadPreference specifies the read concern to be used for the current transaction.
func (OptCurrentReadPreference) Option ¶ added in v0.0.12
func (opt OptCurrentReadPreference) Option(c *Client) error
Option implements the ClientOptioner interface.
type OptCurrentWriteConcern ¶ added in v0.0.12
type OptCurrentWriteConcern struct {
*writeconcern.WriteConcern
}
OptCurrentWriteConcern specifies the read concern to be used for the current transaction.
func (OptCurrentWriteConcern) Option ¶ added in v0.0.12
func (opt OptCurrentWriteConcern) Option(c *Client) error
Option implements the ClientOptioner interface.
type OptDefaultReadConcern ¶ added in v0.0.12
type OptDefaultReadConcern struct {
*readconcern.ReadConcern
}
OptDefaultReadConcern specifies the read concern that should be used for transactions started from this session.
func (OptDefaultReadConcern) Option ¶ added in v0.0.12
func (opt OptDefaultReadConcern) Option(c *Client) error
Option implements the ClientOptioner interface.
type OptDefaultReadPreference ¶ added in v0.0.12
OptDefaultReadPreference specifies the read concern that should be used for transactions started from this session.
func (OptDefaultReadPreference) Option ¶ added in v0.0.12
func (opt OptDefaultReadPreference) Option(c *Client) error
Option implements the ClientOptioner interface.
type OptDefaultWriteConcern ¶ added in v0.0.12
type OptDefaultWriteConcern struct {
*writeconcern.WriteConcern
}
OptDefaultWriteConcern specifies the read concern that should be used for transactions started from this session.
func (OptDefaultWriteConcern) Option ¶ added in v0.0.12
func (opt OptDefaultWriteConcern) Option(c *Client) error
Option implements the ClientOptioner interface.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is a pool of server sessions that can be reused.
func NewPool ¶
func NewPool(descChan <-chan description.Topology) *Pool
NewPool creates a new server session pool
func (*Pool) CheckedOut ¶
CheckedOut returns number of sessions checked out from pool.
func (*Pool) GetSession ¶
GetSession retrieves an unexpired session from the pool.
func (*Pool) ReturnSession ¶
ReturnSession returns a session to the pool if it has not expired.
type Server ¶
Server is an open session with the server.
func (*Server) IncrementTxnNumber ¶ added in v0.0.12
func (ss *Server) IncrementTxnNumber()
IncrementTxnNumber increments the transaction number.