Skip to content

Commit f4bf404

Browse files
committed
CSHARP-2221: Remove AutoStartTransaction.
1 parent ac83d02 commit f4bf404

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1445
-3095
lines changed

src/MongoDB.Driver.Core/Core/Bindings/CoreSession.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ private IReadOperation<BsonDocument> CreateCommitTransactionOperation()
319319

320320
private void EnsureIsInTransaction(string methodName)
321321
{
322-
this.AutoStartTransactionIfApplicable();
323322
if (_currentTransaction == null)
324323
{
325324
throw new InvalidOperationException("No transaction started.");

src/MongoDB.Driver.Core/Core/Bindings/CoreSessionOptions.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ namespace MongoDB.Driver.Core.Bindings
2121
public class CoreSessionOptions
2222
{
2323
// private fields
24-
private readonly bool _autoStartTransaction;
2524
private readonly TransactionOptions _defaultTransactionOptions;
2625
private readonly bool _isCausallyConsistent;
2726
private readonly bool _isImplicit;
@@ -32,29 +31,18 @@ public class CoreSessionOptions
3231
/// </summary>
3332
/// <param name="isCausallyConsistent">if set to <c>true</c> this session is causally consistent]</param>
3433
/// <param name="isImplicit">if set to <c>true</c> this session is an implicit session.</param>
35-
/// <param name="autoStartTransaction">if set to <c>true</c> [automatic start transaction].</param>
3634
/// <param name="defaultTransactionOptions">The default transaction options.</param>
3735
public CoreSessionOptions(
3836
bool isCausallyConsistent = false,
3937
bool isImplicit = false,
40-
bool autoStartTransaction = false,
4138
TransactionOptions defaultTransactionOptions = null)
4239
{
4340
_isCausallyConsistent = isCausallyConsistent;
4441
_isImplicit = isImplicit;
45-
_autoStartTransaction = autoStartTransaction;
4642
_defaultTransactionOptions = defaultTransactionOptions;
4743
}
4844

4945
// public properties
50-
/// <summary>
51-
/// Gets a value indicating whether to auto start a transaction.
52-
/// </summary>
53-
/// <value>
54-
/// <c>true</c> if driver should auto start a transaction; otherwise, <c>false</c>.
55-
/// </value>
56-
public bool AutoStartTransaction => _autoStartTransaction;
57-
5846
/// <summary>
5947
/// Gets the default transaction options.
6048
/// </summary>

src/MongoDB.Driver.Core/Core/Bindings/ICoreSession.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,4 @@ public interface ICoreSessionHandle : ICoreSession
168168
/// <returns>A new handle.</returns>
169169
ICoreSessionHandle Fork();
170170
}
171-
172-
internal static class ICoreSessionHandleExtensions
173-
{
174-
public static void AutoStartTransactionIfApplicable(this ICoreSession session)
175-
{
176-
if (!session.IsInTransaction && session.Options != null && session.Options.AutoStartTransaction)
177-
{
178-
session.StartTransaction();
179-
}
180-
}
181-
}
182171
}

src/MongoDB.Driver.Core/Core/WireProtocol/CommandUsingCommandMessageWireProtocol.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ private Type0CommandMessageSection<BsonDocument> CreateType0Section(ConnectionDe
186186
}
187187
Action<BsonWriterSettings> writerSettingsConfigurator = s => s.GuidRepresentation = GuidRepresentation.Unspecified;
188188

189-
_session.AutoStartTransactionIfApplicable();
190189
if (_session.IsInTransaction)
191190
{
192191
var transaction = _session.CurrentTransaction;

src/MongoDB.Driver/ClientSessionOptions.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ namespace MongoDB.Driver
2323
public class ClientSessionOptions
2424
{
2525
// public properties
26-
/// <summary>
27-
/// Gets or sets a value indicating whether to auto start a transaction.
28-
/// </summary>
29-
/// <value>
30-
/// <c>true</c> if the driver should auto start a transaction; otherwise, <c>false</c>.
31-
/// </value>
32-
public bool AutoStartTransaction { get; set; }
33-
3426
/// <summary>
3527
/// When true or unspecified, an application will read its own writes and subsequent
3628
/// reads will never observe an earlier version of the data.
@@ -51,7 +43,6 @@ internal CoreSessionOptions ToCore(bool isImplicit = false)
5143
return new CoreSessionOptions(
5244
isCausallyConsistent: CausalConsistency ?? true,
5345
isImplicit: isImplicit,
54-
autoStartTransaction: AutoStartTransaction,
5546
defaultTransactionOptions: DefaultTransactionOptions);
5647
}
5748
}

tests/MongoDB.Driver.Core.Tests/Core/Bindings/CoreSessionOptionsTests.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,17 @@ public class CoreSessionOptionsTests
2424
[Theory]
2525
[ParameterAttributeData]
2626
public void constructor_should_initialize_instance(
27-
[Values(false, true)] bool autoStartTransaction,
2827
[Values(false, true)] bool nullDefaultTransactionOptions,
2928
[Values(false, true)] bool isCausallyConsistent,
3029
[Values(false, true)] bool isImplicit)
3130
{
3231
var defaultTransactionOptions = nullDefaultTransactionOptions ? null : new TransactionOptions();
3332

3433
var result = new CoreSessionOptions(
35-
autoStartTransaction: autoStartTransaction,
3634
defaultTransactionOptions: defaultTransactionOptions,
3735
isCausallyConsistent: isCausallyConsistent,
3836
isImplicit: isImplicit);
3937

40-
result.AutoStartTransaction.Should().Be(autoStartTransaction);
4138
result.DefaultTransactionOptions.Should().BeSameAs(defaultTransactionOptions);
4239
result.IsCausallyConsistent.Should().Be(isCausallyConsistent);
4340
result.IsImplicit.Should().Be(isImplicit);
@@ -48,24 +45,11 @@ public void constructor_should_initialize_instance_with_default_values()
4845
{
4946
var result = new CoreSessionOptions();
5047

51-
result.AutoStartTransaction.Should().BeFalse();
5248
result.DefaultTransactionOptions.Should().BeNull();
5349
result.IsCausallyConsistent.Should().BeFalse();
5450
result.IsImplicit.Should().BeFalse();
5551
}
5652

57-
[Theory]
58-
[ParameterAttributeData]
59-
public void AutoStartTransaction_should_return_expected_result(
60-
[Values(false, true)] bool value)
61-
{
62-
var subject = new CoreSessionOptions(autoStartTransaction: value);
63-
64-
var result = subject.AutoStartTransaction;
65-
66-
result.Should().Be(value);
67-
}
68-
6953
[Theory]
7054
[ParameterAttributeData]
7155
public void DefaultTransactionOptions_should_return_expected_result(

tests/MongoDB.Driver.Tests.Dotnet/Specifications/transactions/tests/README.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ Test Format
2222

2323
Each YAML file has the following keys:
2424

25+
- ``database_name`` and ``collection_name``: The database and collection to use
26+
for testing.
27+
2528
- ``data``: The data that should exist in the collection under test before each
26-
test run. (TODO: not used yet.)
29+
test run.
2730

2831
- ``tests``: An array of tests that are to be run independently of each other.
2932
Each test will have some or all of the following fields:
@@ -73,6 +76,8 @@ For each YAML file, for each element in ``tests``:
7376
transactions from previous test failures. The command will fail with message
7477
"operation was interrupted", because it kills its own implicit session. Catch
7578
the exception and continue.
79+
#. Create a collection object from the MongoClient, using the ``database_name``
80+
and ``collection_name`` fields of the YAML file.
7681
#. Drop the test collection, using writeConcern "majority".
7782
#. Execute the "create" command to recreate the collection, using writeConcern
7883
"majority". (Creating the collection inside a transaction is prohibited, so
@@ -121,7 +126,9 @@ For each YAML file, for each element in ``tests``:
121126
#. For each element in ``outcome``:
122127

123128
- If ``name`` is "collection", verify that the test collection contains
124-
exactly the documents in the ``data`` array.
129+
exactly the documents in the ``data`` array. Ensure this find uses
130+
Primary read preference even when the MongoClient is configured with
131+
another read preference.
125132

126133
TODO:
127134

@@ -132,6 +139,9 @@ TODO:
132139
Command-Started Events
133140
``````````````````````
134141

142+
The event listener used for these tests MUST ignore the security commands
143+
listed in the Command Monitoring Spec.
144+
135145
Logical Session Id
136146
~~~~~~~~~~~~~~~~~~
137147

@@ -144,7 +154,7 @@ Null Values
144154
~~~~~~~~~~~
145155

146156
Some command-started events in ``expectations`` include ``null`` values for
147-
fields such as ``txnNumber``, ``autocommit``, ``writeConcern``, and ``stmtId``.
157+
fields such as ``txnNumber``, ``autocommit``, and ``writeConcern``.
148158
Tests MUST assert that the actual command **omits** any field that has a
149159
``null`` value in the expected command.
150160

tests/MongoDB.Driver.Tests.Dotnet/Specifications/transactions/tests/abort.json

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2+
"database_name": "transaction-tests",
3+
"collection_name": "test",
24
"data": [],
35
"tests": [
46
{
@@ -69,7 +71,6 @@
6971
"txnNumber": {
7072
"$numberLong": "1"
7173
},
72-
"stmtId": 0,
7374
"startTransaction": true,
7475
"autocommit": false,
7576
"writeConcern": null
@@ -86,7 +87,6 @@
8687
"txnNumber": {
8788
"$numberLong": "1"
8889
},
89-
"stmtId": 1,
9090
"startTransaction": null,
9191
"autocommit": false,
9292
"writeConcern": null
@@ -112,7 +112,6 @@
112112
"txnNumber": {
113113
"$numberLong": "2"
114114
},
115-
"stmtId": 0,
116115
"startTransaction": true,
117116
"autocommit": false,
118117
"writeConcern": null
@@ -129,7 +128,6 @@
129128
"txnNumber": {
130129
"$numberLong": "2"
131130
},
132-
"stmtId": 1,
133131
"startTransaction": null,
134132
"autocommit": false,
135133
"writeConcern": null
@@ -183,7 +181,6 @@
183181
"txnNumber": {
184182
"$numberLong": "1"
185183
},
186-
"stmtId": 0,
187184
"startTransaction": true,
188185
"autocommit": false,
189186
"writeConcern": null
@@ -200,7 +197,6 @@
200197
"txnNumber": {
201198
"$numberLong": "1"
202199
},
203-
"stmtId": 1,
204200
"startTransaction": null,
205201
"autocommit": false,
206202
"writeConcern": null
@@ -269,7 +265,6 @@
269265
"txnNumber": {
270266
"$numberLong": "1"
271267
},
272-
"stmtId": 0,
273268
"startTransaction": true,
274269
"autocommit": false,
275270
"writeConcern": null
@@ -286,7 +281,6 @@
286281
"txnNumber": {
287282
"$numberLong": "1"
288283
},
289-
"stmtId": 1,
290284
"startTransaction": null,
291285
"autocommit": false,
292286
"writeConcern": null
@@ -375,7 +369,6 @@
375369
"txnNumber": {
376370
"$numberLong": "1"
377371
},
378-
"stmtId": 0,
379372
"startTransaction": true,
380373
"autocommit": false,
381374
"writeConcern": null
@@ -392,7 +385,6 @@
392385
"txnNumber": {
393386
"$numberLong": "1"
394387
},
395-
"stmtId": 1,
396388
"startTransaction": null,
397389
"autocommit": false,
398390
"writeConcern": null
@@ -471,7 +463,6 @@
471463
"txnNumber": {
472464
"$numberLong": "1"
473465
},
474-
"stmtId": 0,
475466
"startTransaction": true,
476467
"autocommit": false,
477468
"writeConcern": null
@@ -495,7 +486,6 @@
495486
"txnNumber": {
496487
"$numberLong": "1"
497488
},
498-
"stmtId": 1,
499489
"startTransaction": null,
500490
"autocommit": false,
501491
"writeConcern": null
@@ -519,7 +509,6 @@
519509
"txnNumber": {
520510
"$numberLong": "1"
521511
},
522-
"stmtId": 2,
523512
"startTransaction": null,
524513
"autocommit": false,
525514
"writeConcern": null
@@ -536,7 +525,6 @@
536525
"txnNumber": {
537526
"$numberLong": "1"
538527
},
539-
"stmtId": 3,
540528
"startTransaction": null,
541529
"autocommit": false,
542530
"writeConcern": null
@@ -551,6 +539,45 @@
551539
"data": []
552540
}
553541
}
542+
},
543+
{
544+
"description": "abort does not apply writeConcern",
545+
"operations": [
546+
{
547+
"name": "startTransaction",
548+
"arguments": {
549+
"session": "session0",
550+
"options": {
551+
"writeConcern": {
552+
"w": 10
553+
}
554+
}
555+
}
556+
},
557+
{
558+
"name": "insertOne",
559+
"arguments": {
560+
"document": {
561+
"_id": 1
562+
},
563+
"session": "session0"
564+
},
565+
"result": {
566+
"insertedId": 1
567+
}
568+
},
569+
{
570+
"name": "abortTransaction",
571+
"arguments": {
572+
"session": "session0"
573+
}
574+
}
575+
],
576+
"outcome": {
577+
"collection": {
578+
"data": []
579+
}
580+
}
554581
}
555582
]
556583
}

0 commit comments

Comments
 (0)