Skip to content

Commit 2d7938a

Browse files
authored
CDRIVER-3949, CDRIVER-3963, CDRIVER-3966 aborting txn unpins session (#783)
Replace manual assignment with _mongoc_client_session_unpin Ensures that session arg is appended to operation_find in unified test runner. Other operations will need to be addressed in CDRIVER-3964. Syncs transaction spec tests with mongodb/specifications@ec32686
1 parent b2ba4d5 commit 2d7938a

38 files changed

+543
-712
lines changed

src/libmongoc/src/mongoc/mongoc-client-session.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ _mongoc_client_session_handle_reply (mongoc_client_session_t *session,
627627
* fails with a TransientTransactionError". If the server reply included
628628
* a TransientTransactionError, we unpin here. If a network error caused
629629
* us to add a label client-side, we unpin in network_error_reply. */
630-
session->server_id = 0;
630+
_mongoc_client_session_unpin (session);
631631
}
632632

633633
while (bson_iter_next (&iter)) {
@@ -1266,13 +1266,19 @@ mongoc_client_session_abort_transaction (mongoc_client_session_t *session,
12661266
case MONGOC_INTERNAL_TRANSACTION_STARTING:
12671267
/* we sent no commands, not actually started on server */
12681268
session->txn.state = MONGOC_INTERNAL_TRANSACTION_ABORTED;
1269+
/* Transactions Spec: aborting a transaction MUST unpin the session.
1270+
* It's likely the transaction is already unpinned if TRANSACTION_STARTING
1271+
* was just assigned, but there is no harm in doing so again. */
1272+
_mongoc_client_session_unpin (session);
12691273
txn_opts_cleanup (&session->txn.opts);
12701274
RETURN (true);
12711275
case MONGOC_INTERNAL_TRANSACTION_IN_PROGRESS:
12721276
session->txn.state = MONGOC_INTERNAL_TRANSACTION_ENDING;
12731277
/* Transactions Spec: ignore errors from abortTransaction command */
12741278
txn_abort (session, NULL, NULL);
12751279
session->txn.state = MONGOC_INTERNAL_TRANSACTION_ABORTED;
1280+
/* Transactions Spec: aborting a transaction MUST unpin the session. */
1281+
_mongoc_client_session_unpin (session);
12761282
RETURN (true);
12771283
case MONGOC_INTERNAL_TRANSACTION_COMMITTED:
12781284
case MONGOC_INTERNAL_TRANSACTION_COMMITTED_EMPTY:

src/libmongoc/tests/json/transactions/abort.json renamed to src/libmongoc/tests/json/transactions/legacy/abort.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@
458458
"errorLabelsOmit": [
459459
"TransientTransactionError",
460460
"UnknownTransactionCommitResult"
461-
]
461+
],
462+
"errorContains": "E11000"
462463
}
463464
},
464465
{

src/libmongoc/tests/json/transactions/bulk.json renamed to src/libmongoc/tests/json/transactions/legacy/bulk.json

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,7 @@
304304
"$set": {
305305
"x": 1
306306
}
307-
},
308-
"multi": false,
309-
"upsert": false
307+
}
310308
},
311309
{
312310
"q": {
@@ -317,7 +315,6 @@
317315
"x": 2
318316
}
319317
},
320-
"multi": false,
321318
"upsert": true
322319
}
323320
],
@@ -379,19 +376,15 @@
379376
},
380377
"u": {
381378
"y": 1
382-
},
383-
"multi": false,
384-
"upsert": false
379+
}
385380
},
386381
{
387382
"q": {
388383
"_id": 2
389384
},
390385
"u": {
391386
"y": 2
392-
},
393-
"multi": false,
394-
"upsert": false
387+
}
395388
}
396389
],
397390
"ordered": true,
@@ -454,8 +447,7 @@
454447
"z": 1
455448
}
456449
},
457-
"multi": true,
458-
"upsert": false
450+
"multi": true
459451
}
460452
],
461453
"ordered": true,

src/libmongoc/tests/json/transactions/causal-consistency.json renamed to src/libmongoc/tests/json/transactions/legacy/causal-consistency.json

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
"$inc": {
4141
"count": 1
4242
}
43-
},
44-
"upsert": false
43+
}
4544
},
4645
"result": {
4746
"matchedCount": 1,
@@ -65,8 +64,7 @@
6564
"$inc": {
6665
"count": 1
6766
}
68-
},
69-
"upsert": false
67+
}
7068
},
7169
"result": {
7270
"matchedCount": 1,
@@ -93,9 +91,7 @@
9391
"$inc": {
9492
"count": 1
9593
}
96-
},
97-
"multi": false,
98-
"upsert": false
94+
}
9995
}
10096
],
10197
"ordered": true,
@@ -123,9 +119,7 @@
123119
"$inc": {
124120
"count": 1
125121
}
126-
},
127-
"multi": false,
128-
"upsert": false
122+
}
129123
}
130124
],
131125
"ordered": true,
@@ -212,8 +206,7 @@
212206
"$inc": {
213207
"count": 1
214208
}
215-
},
216-
"upsert": false
209+
}
217210
},
218211
"result": {
219212
"matchedCount": 1,
@@ -260,9 +253,7 @@
260253
"$inc": {
261254
"count": 1
262255
}
263-
},
264-
"multi": false,
265-
"upsert": false
256+
}
266257
}
267258
],
268259
"ordered": true,

0 commit comments

Comments
 (0)