UUIDSubtype is the BSON binary subtype that a UUID should be encoded as
const UUIDSubtype byte = 4
ErrAbortAfterCommit is returned when abort is called after a commit.
var ErrAbortAfterCommit = errors.New("cannot call abortTransaction after calling commitTransaction")
ErrAbortTwice is returned if abort is called after transaction is already aborted.
var ErrAbortTwice = errors.New("cannot call abortTransaction twice")
ErrCommitAfterAbort is returned if commit is called after an abort.
var ErrCommitAfterAbort = errors.New("cannot call commitTransaction after calling abortTransaction")
ErrNoTransactStarted is returned if a transaction operation is called when no transaction has started.
var ErrNoTransactStarted = errors.New("no transaction started")
ErrSessionEnded is returned when a client session is used after a call to endSession().
var ErrSessionEnded = errors.New("ended session was used")
ErrSnapshotTransaction is returned if an transaction is started on a snapshot session.
var ErrSnapshotTransaction = errors.New("transactions are not supported in snapshot sessions")
ErrTransactInProgress is returned if startTransaction() is called when a transaction is in progress.
var ErrTransactInProgress = errors.New("transaction already in progress")
ErrUnackWCUnsupported is returned if an unacknowledged write concern is supported for a transaction.
var ErrUnackWCUnsupported = errors.New("transactions do not support unacknowledged write concerns")
func MaxClusterTime(ct1, ct2 bson.Raw) bson.Raw
MaxClusterTime compares 2 clusterTime documents and returns the document representing the highest cluster time.
Client is a session for clients to run commands.
type Client struct { *Server ClientID uuid.UUID ClusterTime bson.Raw Consistent bool // causal consistency OperationTime *primitive.Timestamp IsImplicit bool Terminated bool RetryingCommit bool Committing bool Aborting bool RetryWrite bool RetryRead bool Snapshot bool // options for the current transaction // most recently set by transactionopt CurrentRc *readconcern.ReadConcern CurrentRp *readpref.ReadPref CurrentWc *writeconcern.WriteConcern CurrentMct *time.Duration TransactionState TransactionState PinnedServer *description.Server RecoveryToken bson.Raw PinnedConnection LoadBalancedTransactionConnection SnapshotTime *primitive.Timestamp // contains filtered or unexported fields }
func NewClientSession(pool *Pool, clientID uuid.UUID, opts ...*ClientOptions) (*Client, error)
NewClientSession creates a new explicit client-side session.
func NewImplicitClientSession(pool *Pool, clientID uuid.UUID) *Client
NewImplicitClientSession creates a new implicit client-side session.
func (c *Client) AbortTransaction() error
AbortTransaction updates the state for a successfully aborted transaction and returns an error if not permissible. It does not actually perform the abort.
func (c *Client) AdvanceClusterTime(clusterTime bson.Raw) error
AdvanceClusterTime updates the session's cluster time.
func (c *Client) AdvanceOperationTime(opTime *primitive.Timestamp) error
AdvanceOperationTime updates the session's operation time.
func (c *Client) ApplyCommand(desc description.Server) error
ApplyCommand advances the state machine upon command execution. This must be called after server selection is complete.
func (c *Client) CheckAbortTransaction() error
CheckAbortTransaction checks to see if allowed to abort transaction and returns an error if not allowed.
func (c *Client) CheckCommitTransaction() error
CheckCommitTransaction checks to see if allowed to commit transaction and returns an error if not allowed.
func (c *Client) CheckStartTransaction() error
CheckStartTransaction checks to see if allowed to start transaction and returns an error if not allowed
func (c *Client) ClearPinnedResources() error
ClearPinnedResources clears the pinned server and/or connection associated with the session.
func (c *Client) CommitTransaction() error
CommitTransaction updates the state for a successfully committed transaction and returns an error if not permissible. It does not actually perform the commit.
func (c *Client) EndSession()
EndSession ends the session.
func (c *Client) SetServer() error
SetServer will check out a session from the client session pool.
func (c *Client) StartCommand() error
StartCommand updates the session's internal state at the beginning of an operation. This must be called before server selection is done for the operation as the session's state can impact the result of that process.
func (c *Client) StartTransaction(opts *TransactionOptions) error
StartTransaction initializes the transaction options and advances the state machine. It does not contact the server to start the transaction.
func (c *Client) TransactionCommitted() bool
TransactionCommitted returns true of the client session just committed a transaction.
func (c *Client) TransactionInProgress() bool
TransactionInProgress returns true if the client session is in an active transaction.
func (c *Client) TransactionRunning() bool
TransactionRunning returns true if the client session has started the transaction and it hasn't been committed or aborted
func (c *Client) TransactionStarting() bool
TransactionStarting returns true if the client session is starting a transaction.
func (c *Client) UpdateCommitTransactionWriteConcern()
UpdateCommitTransactionWriteConcern will set the write concern to majority and potentially set a w timeout of 10 seconds. This should be called after a commit transaction operation fails with a retryable error or after a successful commit transaction operation.
func (c *Client) UpdateRecoveryToken(response bson.Raw)
UpdateRecoveryToken updates the session's recovery token from the server response.
func (c *Client) UpdateSnapshotTime(response bsoncore.Document)
UpdateSnapshotTime updates the session's value for the atClusterTime field of ReadConcern.
func (c *Client) UpdateUseTime() error
UpdateUseTime sets the session's last used time to the current time. This must be called whenever the session is used to send a command to the server to ensure that the session is not prematurely marked expired in the driver's session pool. If the session has already been ended, this method will return ErrSessionEnded.
ClientOptions represents all possible options for creating a client session.
type ClientOptions struct { CausalConsistency *bool DefaultReadConcern *readconcern.ReadConcern DefaultWriteConcern *writeconcern.WriteConcern DefaultReadPreference *readpref.ReadPref DefaultMaxCommitTime *time.Duration Snapshot *bool }
ClusterClock represents a logical clock for keeping track of cluster time.
type ClusterClock struct {
// contains filtered or unexported fields
}
func (cc *ClusterClock) AdvanceClusterTime(clusterTime bson.Raw)
AdvanceClusterTime updates the cluster's current time.
func (cc *ClusterClock) GetClusterTime() bson.Raw
GetClusterTime returns the cluster's current time.
LoadBalancedTransactionConnection represents a connection that's pinned by a ClientSession because it's being used to execute a transaction when running against a load balancer. This interface is a copy of driver.PinnedConnection and exists to be able to pin transactions to a connection without causing an import cycle.
type LoadBalancedTransactionConnection interface { // Functions copied over from driver.Connection. WriteWireMessage(context.Context, []byte) error ReadWireMessage(ctx context.Context) ([]byte, error) Description() description.Server Close() error ID() string ServerConnectionID() *int64 DriverConnectionID() uint64 // TODO(GODRIVER-2824): change type to int64. Address() address.Address Stale() bool // Functions copied over from driver.PinnedConnection that are not part of Connection or Expirable. PinToCursor() error PinToTransaction() error UnpinFromCursor() error UnpinFromTransaction() error }
Node represents a server session in a linked list
type Node struct { *Server // contains filtered or unexported fields }
Pool is a pool of server sessions that can be reused.
type Pool struct {
// contains filtered or unexported fields
}
func NewPool(descChan <-chan description.Topology) *Pool
NewPool creates a new server session pool
func (p *Pool) CheckedOut() int64
CheckedOut returns number of sessions checked out from pool.
func (p *Pool) GetSession() (*Server, error)
GetSession retrieves an unexpired session from the pool.
func (p *Pool) IDSlice() []bsoncore.Document
IDSlice returns a slice of session IDs for each session in the pool
func (p *Pool) ReturnSession(ss *Server)
ReturnSession returns a session to the pool if it has not expired.
func (p *Pool) String() string
String implements the Stringer interface
Server is an open session with the server.
type Server struct { SessionID bsoncore.Document TxnNumber int64 LastUsed time.Time Dirty bool }
func (ss *Server) IncrementTxnNumber()
IncrementTxnNumber increments the transaction number.
func (ss *Server) MarkDirty()
MarkDirty marks the session as dirty.
TransactionOptions represents all possible options for starting a transaction in a session.
type TransactionOptions struct { ReadConcern *readconcern.ReadConcern WriteConcern *writeconcern.WriteConcern ReadPreference *readpref.ReadPref MaxCommitTime *time.Duration }
TransactionState indicates the state of the transactions FSM.
type TransactionState uint8
Client Session states
const ( None TransactionState = iota Starting InProgress Committed Aborted )
func (s TransactionState) String() string
String implements the fmt.Stringer interface.