@@ -84,53 +84,58 @@ func SessionFromContext(ctx context.Context) Session {
84
84
// https://www.mongodb.com/docs/manual/core/transactions/.
85
85
//
86
86
// Implementations of Session are not safe for concurrent use by multiple goroutines.
87
- //
88
- // StartTransaction starts a new transaction, configured with the given options, on this session. This method will
89
- // return an error if there is already a transaction in-progress for this session.
90
- //
91
- // CommitTransaction commits the active transaction for this session. This method will return an error if there is no
92
- // active transaction for this session or the transaction has been aborted.
93
- //
94
- // AbortTransaction aborts the active transaction for this session. This method will return an error if there is no
95
- // active transaction for this session or the transaction has been committed or aborted.
96
- //
97
- // WithTransaction starts a transaction on this session and runs the fn callback. Errors with the
98
- // TransientTransactionError and UnknownTransactionCommitResult labels are retried for up to 120 seconds. Inside the
99
- // callback, sessCtx must be used as the Context parameter for any operations that should be part of the transaction. If
100
- // the ctx parameter already has a Session attached to it, it will be replaced by this session. The fn callback may be
101
- // run multiple times during WithTransaction due to retry attempts, so it must be idempotent. Non-retryable operation
102
- // errors or any operation errors that occur after the timeout expires will be returned without retrying. If the
103
- // callback fails, the driver will call AbortTransaction. Because this method must succeed to ensure that server-side
104
- // resources are properly cleaned up, context deadlines and cancellations will not be respected during this call. For a
105
- // usage example, see the Client.StartSession method documentation.
106
- //
107
- // ClusterTime, OperationTime, Client, and ID return the session's current cluster time, the session's current operation
108
- // time, the Client associated with the session, and the ID document associated with the session, respectively. The ID
109
- // document for a session is in the form {"id": <BSON binary value>}.
110
- //
111
- // EndSession method should abort any existing transactions and close the session.
112
- //
113
- // AdvanceClusterTime advances the cluster time for a session. This method will return an error if the session has ended.
114
- //
115
- // AdvanceOperationTime advances the operation time for a session. This method will return an error if the session has
116
- // ended.
117
87
type Session interface {
118
- // Functions to modify session state.
88
+ // StartTransaction starts a new transaction, configured with the given options, on this
89
+ // session. This method returns an error if there is already a transaction in-progress for this
90
+ // session.
119
91
StartTransaction (... * options.TransactionOptions ) error
92
+
93
+ // AbortTransaction aborts the active transaction for this session. This method returns an error
94
+ // if there is no active transaction for this session or if the transaction has been committed
95
+ // or aborted.
120
96
AbortTransaction (context.Context ) error
97
+
98
+ // CommitTransaction commits the active transaction for this session. This method returns an
99
+ // error if there is no active transaction for this session or if the transaction has been
100
+ // aborted.
121
101
CommitTransaction (context.Context ) error
122
- WithTransaction (ctx context.Context , fn func (sessCtx SessionContext ) (interface {}, error ),
102
+
103
+ // WithTransaction starts a transaction on this session and runs the fn callback. Errors with
104
+ // the TransientTransactionError and UnknownTransactionCommitResult labels are retried for up to
105
+ // 120 seconds. Inside the callback, the SessionContext must be used as the Context parameter
106
+ // for any operations that should be part of the transaction. If the ctx parameter already has a
107
+ // Session attached to it, it will be replaced by this session. The fn callback may be run
108
+ // multiple times during WithTransaction due to retry attempts, so it must be idempotent.
109
+ // Non-retryable operation errors or any operation errors that occur after the timeout expires
110
+ // will be returned without retrying. If the callback fails, the driver will call
111
+ // AbortTransaction. Because this method must succeed to ensure that server-side resources are
112
+ // properly cleaned up, context deadlines and cancellations will not be respected during this
113
+ // call. For a usage example, see the Client.StartSession method documentation.
114
+ WithTransaction (ctx context.Context , fn func (ctx SessionContext ) (interface {}, error ),
123
115
opts ... * options.TransactionOptions ) (interface {}, error )
116
+
117
+ // EndSession aborts any existing transactions and close the session.
124
118
EndSession (context.Context )
125
119
126
- // Functions to retrieve session properties .
120
+ // ClusterTime returns the current cluster time document associated with the session .
127
121
ClusterTime () bson.Raw
122
+
123
+ // OperationTime returns the current operation time document associated with the session.
128
124
OperationTime () * primitive.Timestamp
125
+
126
+ // Client the Client associated with the session.
129
127
Client () * Client
128
+
129
+ // ID returns the current ID document associated with the session. The ID document is in the
130
+ // form {"id": <BSON binary value>}.
130
131
ID () bson.Raw
131
132
132
- // Functions to modify mutable session properties.
133
+ // AdvanceClusterTime advances the cluster time for a session. This method returns an error if
134
+ // the session has ended.
133
135
AdvanceClusterTime (bson.Raw ) error
136
+
137
+ // AdvanceOperationTime advances the operation time for a session. This method returns an error
138
+ // if the session has ended.
134
139
AdvanceOperationTime (* primitive.Timestamp ) error
135
140
136
141
session ()
@@ -175,7 +180,7 @@ func (s *sessionImpl) EndSession(ctx context.Context) {
175
180
}
176
181
177
182
// WithTransaction implements the Session interface.
178
- func (s * sessionImpl ) WithTransaction (ctx context.Context , fn func (sessCtx SessionContext ) (interface {}, error ),
183
+ func (s * sessionImpl ) WithTransaction (ctx context.Context , fn func (ctx SessionContext ) (interface {}, error ),
179
184
opts ... * options.TransactionOptions ) (interface {}, error ) {
180
185
timeout := time .NewTimer (withTransactionTimeout )
181
186
defer timeout .Stop ()
0 commit comments