mongo-driver: go.mongodb.org/mongo-driver/x/mongo/driver/session Index | Files

package session

import "go.mongodb.org/mongo-driver/x/mongo/driver/session"

Index

Package Files

client_session.go cluster_clock.go options.go server_session.go session_pool.go

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.

func MaxClusterTime Uses

func MaxClusterTime(ct1, ct2 bson.Raw) bson.Raw

MaxClusterTime compares 2 clusterTime documents and returns the document representing the highest cluster time.

type Client Uses

type Client struct {
    *Server
    ClientID       uuid.UUID
    ClusterTime    bson.Raw
    Consistent     bool // causal consistency
    OperationTime  *primitive.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

    PinnedSelector description.ServerSelector
    // contains filtered or unexported fields
}

Client is a session for clients to run commands.

func NewClientSession Uses

func NewClientSession(pool *Pool, clientID uuid.UUID, sessionType Type, opts ...*ClientOptions) (*Client, error)

NewClientSession creates a Client.

func (*Client) AbortTransaction Uses

func (c *Client) AbortTransaction() error

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 Uses

func (c *Client) AdvanceClusterTime(clusterTime bson.Raw) error

AdvanceClusterTime updates the session's cluster time.

func (*Client) AdvanceOperationTime Uses

func (c *Client) AdvanceOperationTime(opTime *primitive.Timestamp) error

AdvanceOperationTime updates the session's operation time.

func (*Client) ApplyCommand Uses

func (c *Client) ApplyCommand(desc description.Server)

ApplyCommand advances the state machine upon command execution.

func (*Client) CheckAbortTransaction Uses

func (c *Client) CheckAbortTransaction() error

CheckAbortTransaction checks to see if allowed to abort transaction and returns an error if not allowed.

func (*Client) CheckCommitTransaction Uses

func (c *Client) CheckCommitTransaction() error

CheckCommitTransaction checks to see if allowed to commit transaction and returns an error if not allowed.

func (*Client) CheckStartTransaction Uses

func (c *Client) CheckStartTransaction() error

CheckStartTransaction checks to see if allowed to start transaction and returns an error if not allowed

func (*Client) CommitTransaction Uses

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 (*Client) EndSession Uses

func (c *Client) EndSession()

EndSession ends the session.

func (*Client) StartTransaction Uses

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 (*Client) TransactionCommitted Uses

func (c *Client) TransactionCommitted() bool

TransactionCommitted returns true of the client session just committed a transaciton.

func (*Client) TransactionInProgress Uses

func (c *Client) TransactionInProgress() bool

TransactionInProgress returns true if the client session is in an active transaction.

func (*Client) TransactionRunning Uses

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 (*Client) TransactionStarting Uses

func (c *Client) TransactionStarting() bool

TransactionStarting returns true if the client session is starting a transaction.

func (*Client) UpdateUseTime Uses

func (c *Client) UpdateUseTime() error

UpdateUseTime updates the session's last used time. Must be called whenver this session is used to send a command to the server.

type ClientOptions Uses

type ClientOptions struct {
    CausalConsistency     *bool
    DefaultReadConcern    *readconcern.ReadConcern
    DefaultWriteConcern   *writeconcern.WriteConcern
    DefaultReadPreference *readpref.ReadPref
}

ClientOptions represents all possible options for creating a client session.

type ClusterClock Uses

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

ClusterClock represents a logical clock for keeping track of cluster time.

func (*ClusterClock) AdvanceClusterTime Uses

func (cc *ClusterClock) AdvanceClusterTime(clusterTime bson.Raw)

AdvanceClusterTime updates the cluster's current time.

func (*ClusterClock) GetClusterTime Uses

func (cc *ClusterClock) GetClusterTime() bson.Raw

GetClusterTime returns the cluster's current time.

type Node Uses

type Node struct {
    *Server
    // contains filtered or unexported fields
}

Node represents a server session in a linked list

type Pool Uses

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

Pool is a pool of server sessions that can be reused.

func NewPool Uses

func NewPool(descChan <-chan description.Topology) *Pool

NewPool creates a new server session pool

func (*Pool) CheckedOut Uses

func (p *Pool) CheckedOut() int

CheckedOut returns number of sessions checked out from pool.

func (*Pool) GetSession Uses

func (p *Pool) GetSession() (*Server, error)

GetSession retrieves an unexpired session from the pool.

func (*Pool) IDSlice Uses

func (p *Pool) IDSlice() []bsonx.Doc

IDSlice returns a slice of session IDs for each session in the pool

func (*Pool) ReturnSession Uses

func (p *Pool) ReturnSession(ss *Server)

ReturnSession returns a session to the pool if it has not expired.

func (*Pool) String Uses

func (p *Pool) String() string

String implements the Stringer interface

type Server Uses

type Server struct {
    SessionID bsonx.Doc
    TxnNumber int64
    LastUsed  time.Time
}

Server is an open session with the server.

func (*Server) IncrementTxnNumber Uses

func (ss *Server) IncrementTxnNumber()

IncrementTxnNumber increments the transaction number.

type TransactionOptions Uses

type TransactionOptions struct {
    ReadConcern    *readconcern.ReadConcern
    WriteConcern   *writeconcern.WriteConcern
    ReadPreference *readpref.ReadPref
}

TransactionOptions represents all possible options for starting a transaction in a session.

type Type Uses

type Type uint8

Type describes the type of the session

const (
    Explicit Type = iota
    Implicit
)

These constants are the valid types for a client session.

Package session imports 12 packages (graph) and is imported by 7 packages. Updated 2019-03-24. Refresh now. Tools for package owners.