-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
ICoreSession.cs
210 lines (184 loc) · 6.59 KB
/
ICoreSession.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* Copyright 2017-present MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Threading;
using System.Threading.Tasks;
using MongoDB.Bson;
namespace MongoDB.Driver.Core.Bindings
{
/// <summary>
/// The interface for a session in Core.
/// </summary>
public interface ICoreSession : IDisposable
{
// properties
/// <summary>
/// Gets the cluster time.
/// </summary>
/// <value>
/// The cluster time.
/// </value>
BsonDocument ClusterTime { get; }
/// <summary>
/// Gets the current transaction.
/// </summary>
/// <value>
/// The current transaction.
/// </value>
CoreTransaction CurrentTransaction { get; }
/// <summary>
/// Gets the session Id.
/// </summary>
/// <value>
/// The session Id.
/// </value>
BsonDocument Id { get; }
/// <summary>
/// Gets a value indicate whether this instance is causally consistent.
/// </summary>
/// <value>
/// <c>true</c> if the session is causally consistent.
/// </value>
bool IsCausallyConsistent { get; }
/// <summary>
/// Gets a value indicate whether this session is dirty.
/// </summary>
/// <value>
/// <c>true</c> if the session is dirty.
/// </value>
bool IsDirty { get; }
/// <summary>
/// Gets a value indicating whether this instance is implicit session.
/// </summary>
/// <value>
/// <c>true</c> if this instance is implicit session; otherwise, <c>false</c>.
/// </value>
bool IsImplicit { get; }
/// <summary>
/// Gets a value indicating whether this instance is in a transaction.
/// </summary>
/// <value>
/// <c>true</c> if this instance is in a transaction; otherwise, <c>false</c>.
/// </value>
bool IsInTransaction { get; }
/// <summary>
/// Gets a value indicate whether this instance is a snapshot session.
/// </summary>
/// <value>
/// <c>true</c> if the session is a snapshot session.
/// </value>
bool IsSnapshot { get; }
/// <summary>
/// Gets the operation time.
/// </summary>
/// <value>
/// The operation time.
/// </value>
BsonTimestamp OperationTime { get; }
/// <summary>
/// Gets the session options.
/// </summary>
/// <value>
/// The session options.
/// </value>
CoreSessionOptions Options { get; }
/// <summary>
/// Gets the server session.
/// </summary>
/// <value>
/// The server session.
/// </value>
ICoreServerSession ServerSession { get; }
/// <summary>
/// Gets the snapshot time.
/// </summary>
/// <value>
/// The snapshot time.
/// </value>
BsonTimestamp SnapshotTime { get; }
// methods
/// <summary>
/// Aborts the transaction.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
void AbortTransaction(CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Aborts the transaction.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A Task.</returns>
Task AbortTransactionAsync(CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// The driver is about to send a command on this session. Called to track session state.
/// </summary>
void AboutToSendCommand();
/// <summary>
/// Advances the cluster time.
/// </summary>
/// <param name="newClusterTime">The new cluster time.</param>
void AdvanceClusterTime(BsonDocument newClusterTime);
/// <summary>
/// Advances the operation time.
/// </summary>
/// <param name="newOperationTime">The new operation time.</param>
void AdvanceOperationTime(BsonTimestamp newOperationTime);
/// <summary>
/// Advances the transaction id.
/// </summary>
/// <returns>The transaction id.</returns>
long AdvanceTransactionNumber();
/// <summary>
/// Commits the transaction.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
void CommitTransaction(CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Commits the transaction.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A Task.</returns>
Task CommitTransactionAsync(CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Marks the session as dirty.
/// </summary>
void MarkDirty();
/// <summary>
/// Starts a transaction.
/// </summary>
/// <param name="transactionOptions">The transaction options.</param>
void StartTransaction(TransactionOptions transactionOptions = null);
/// <summary>
/// Sets the snapshot time if not set.
/// </summary>
/// <param name="snapshotTime">The snapshot time.</param>
void SetSnapshotTimeIfNeeded(BsonTimestamp snapshotTime);
/// <summary>
/// Called by the driver when the session is used (i.e. sent to the server).
/// </summary>
void WasUsed();
}
/// <summary>
/// A handle to a reference counted core session.
/// </summary>
/// <seealso cref="MongoDB.Driver.Core.Bindings.ICoreSession" />
public interface ICoreSessionHandle : ICoreSession
{
/// <summary>
/// Increments the reference count of the underlying session and returns a new handle to it.
/// </summary>
/// <returns>A new handle.</returns>
ICoreSessionHandle Fork();
}
}