Debian Codegraph @

testdata/transactions/legacy/pin-mongos.yml

raw symbols SCIP
1 # Test that all the operations go to the same mongos.
2 #
3 # In tests that don't include command-started events the assertion is implicit:
4 # that all the read operations succeed. If the driver does not properly pin to
5 # a single mongos then one of the operations in a transaction will eventually
6 # be sent to a different mongos, which is unaware of the transaction, and the
7 # mongos will return a command error. An example of such an error is:
8 # {
9 # 'ok': 0.0,
10 # 'errmsg': 'cannot continue txnId -1 for session 28938f50-9d29-4ca5-8de5-ddaf261267c4 - 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU= with txnId 1',
11 # 'code': 251,
12 # 'codeName': 'NoSuchTransaction',
13 # 'errorLabels': ['TransientTransactionError']
14 # }
15 runOn:
16 -
17 minServerVersion: "4.1.8"
18 topology: ["sharded"]
19 # serverless proxy doesn't append error labels to errors in transactions
20 # caused by failpoints (CLOUDP-88216)
21 serverless: "forbid"
22
23 database_name: &database_name "transaction-tests"
24 collection_name: &collection_name "test"
25
26 data: &data
27 - {_id: 1}
28 - {_id: 2}
29
30 tests:
31 - description: countDocuments
32 useMultipleMongoses: true
33 operations:
34 - &startTransaction
35 name: startTransaction
36 object: session0
37 - &countDocuments
38 name: countDocuments
39 object: collection
40 arguments:
41 filter:
42 _id: 2
43 session: session0
44 result: 1
45 - *countDocuments
46 - *countDocuments
47 - *countDocuments
48 - *countDocuments
49 - *countDocuments
50 - *countDocuments
51 - *countDocuments
52 - &commitTransaction
53 name: commitTransaction
54 object: session0
55
56 outcome:
57 collection:
58 data: *data
59
60 - description: distinct
61 useMultipleMongoses: true
62 operations:
63 - *startTransaction
64 - &distinct
65 name: distinct
66 object: collection
67 arguments:
68 fieldName: _id
69 session: session0
70 result: [1, 2]
71 - *distinct
72 - *distinct
73 - *distinct
74 - *distinct
75 - *distinct
76 - *distinct
77 - *distinct
78 - *commitTransaction
79
80 outcome:
81 collection:
82 data: *data
83
84 - description: find
85 useMultipleMongoses: true
86 operations:
87 - name: startTransaction
88 object: session0
89 - &find
90 name: find
91 object: collection
92 arguments:
93 filter:
94 _id: 2
95 session: session0
96 result:
97 - {_id: 2}
98 - *find
99 - *find
100 - *find
101 - *find
102 - *find
103 - *find
104 - *find
105 - *commitTransaction
106
107 outcome:
108 collection:
109 data: *data
110
111 - description: insertOne
112 useMultipleMongoses: true
113 operations:
114 - name: startTransaction
115 object: session0
116 - name: insertOne
117 object: collection
118 arguments:
119 document:
120 _id: 3
121 session: session0
122 result:
123 insertedId: 3
124 - name: insertOne
125 object: collection
126 arguments:
127 document:
128 _id: 4
129 session: session0
130 result:
131 insertedId: 4
132 - name: insertOne
133 object: collection
134 arguments:
135 document:
136 _id: 5
137 session: session0
138 result:
139 insertedId: 5
140 - name: insertOne
141 object: collection
142 arguments:
143 document:
144 _id: 6
145 session: session0
146 result:
147 insertedId: 6
148 - name: insertOne
149 object: collection
150 arguments:
151 document:
152 _id: 7
153 session: session0
154 result:
155 insertedId: 7
156 - name: insertOne
157 object: collection
158 arguments:
159 document:
160 _id: 8
161 session: session0
162 result:
163 insertedId: 8
164 - name: insertOne
165 object: collection
166 arguments:
167 document:
168 _id: 9
169 session: session0
170 result:
171 insertedId: 9
172 - name: insertOne
173 object: collection
174 arguments:
175 document:
176 _id: 10
177 session: session0
178 result:
179 insertedId: 10
180 - *commitTransaction
181
182 outcome:
183 collection:
184 data:
185 - {_id: 1}
186 - {_id: 2}
187 - {_id: 3}
188 - {_id: 4}
189 - {_id: 5}
190 - {_id: 6}
191 - {_id: 7}
192 - {_id: 8}
193 - {_id: 9}
194 - {_id: 10}
195
196 - description: mixed read write operations
197 useMultipleMongoses: true
198 operations:
199 - name: startTransaction
200 object: session0
201 - name: insertOne
202 object: collection
203 arguments:
204 document:
205 _id: 3
206 session: session0
207 result:
208 insertedId: 3
209 - &countDocuments
210 name: countDocuments
211 object: collection
212 arguments:
213 filter:
214 _id: 3
215 session: session0
216 result: 1
217 - *countDocuments
218 - *countDocuments
219 - *countDocuments
220 - *countDocuments
221 - name: insertOne
222 object: collection
223 arguments:
224 document:
225 _id: 4
226 session: session0
227 result:
228 insertedId: 4
229 - name: insertOne
230 object: collection
231 arguments:
232 document:
233 _id: 5
234 session: session0
235 result:
236 insertedId: 5
237 - name: insertOne
238 object: collection
239 arguments:
240 document:
241 _id: 6
242 session: session0
243 result:
244 insertedId: 6
245 - name: insertOne
246 object: collection
247 arguments:
248 document:
249 _id: 7
250 session: session0
251 result:
252 insertedId: 7
253 - *commitTransaction
254
255 outcome:
256 collection:
257 data:
258 - {_id: 1}
259 - {_id: 2}
260 - {_id: 3}
261 - {_id: 4}
262 - {_id: 5}
263 - {_id: 6}
264 - {_id: 7}
265
266 - description: multiple commits
267 useMultipleMongoses: true
268 operations:
269 - name: startTransaction
270 object: session0
271 - name: insertMany
272 object: collection
273 arguments:
274 documents:
275 - _id: 3
276 - _id: 4
277 session: session0
278 result:
279 insertedIds: {0: 3, 1: 4}
280 # Session is pinned and remains pinned after successful commits.
281 - &assertSessionPinned
282 name: assertSessionPinned
283 object: testRunner
284 arguments:
285 session: session0
286 - *commitTransaction
287 - *assertSessionPinned
288 - *commitTransaction
289 - *commitTransaction
290 - *commitTransaction
291 - *commitTransaction
292 - *commitTransaction
293 - *commitTransaction
294 - *commitTransaction
295 - *commitTransaction
296 - *commitTransaction
297 - *assertSessionPinned
298
299 outcome:
300 collection:
301 data:
302 - {_id: 1}
303 - {_id: 2}
304 - {_id: 3}
305 - {_id: 4}
306
307 - description: remain pinned after non-transient error on commit
308 useMultipleMongoses: true
309 operations:
310 - name: startTransaction
311 object: session0
312 - name: insertMany
313 object: collection
314 arguments:
315 documents:
316 - _id: 3
317 - _id: 4
318 session: session0
319 result:
320 insertedIds: {0: 3, 1: 4}
321 # Session is pinned.
322 - *assertSessionPinned
323 # Fail the commit with a non-transient error.
324 - name: targetedFailPoint
325 object: testRunner
326 arguments:
327 session: session0
328 failPoint:
329 configureFailPoint: failCommand
330 mode: { times: 1 }
331 data:
332 failCommands: ["commitTransaction"]
333 errorCode: 51 # ManualInterventionRequired
334 - name: commitTransaction
335 object: session0
336 result:
337 errorLabelsOmit: ["TransientTransactionError"]
338 errorCode: 51
339 - *assertSessionPinned
340 # The next commit should succeed.
341 - name: commitTransaction
342 object: session0
343 - *assertSessionPinned
344
345 outcome:
346 collection:
347 data:
348 - {_id: 1}
349 - {_id: 2}
350 - {_id: 3}
351 - {_id: 4}
352
353 - description: unpin after transient error within a transaction
354 useMultipleMongoses: true
355 operations:
356 - name: startTransaction
357 object: session0
358 - name: insertOne
359 object: collection
360 arguments:
361 session: session0
362 document:
363 _id: 3
364 result:
365 insertedId: 3
366 # Enable the fail point only on the Mongos that session0 is pinned to.
367 - name: targetedFailPoint
368 object: testRunner
369 arguments:
370 session: session0
371 failPoint:
372 configureFailPoint: failCommand
373 mode: { times: 1 }
374 data:
375 failCommands: ["insert"]
376 closeConnection: true
377 - name: insertOne
378 object: collection
379 arguments:
380 session: session0
381 document:
382 _id: 4
383 result:
384 errorLabelsContain: ["TransientTransactionError"]
385 errorLabelsOmit: ["UnknownTransactionCommitResult"]
386 # Session unpins from the first mongos after the insert error and
387 # abortTransaction succeeds immediately on any mongos.
388 - name: abortTransaction
389 object: session0
390
391 expectations:
392 - command_started_event:
393 command:
394 insert: *collection_name
395 documents:
396 - _id: 3
397 ordered: true
398 readConcern:
399 lsid: session0
400 txnNumber:
401 $numberLong: "1"
402 startTransaction: true
403 autocommit: false
404 writeConcern:
405 command_name: insert
406 database_name: *database_name
407 - command_started_event:
408 command:
409 insert: *collection_name
410 documents:
411 - _id: 4
412 ordered: true
413 readConcern:
414 lsid: session0
415 txnNumber:
416 $numberLong: "1"
417 startTransaction:
418 autocommit: false
419 writeConcern:
420 command_name: insert
421 database_name: *database_name
422 - command_started_event:
423 command:
424 abortTransaction: 1
425 lsid: session0
426 txnNumber:
427 $numberLong: "1"
428 startTransaction:
429 autocommit: false
430 writeConcern:
431 recoveryToken: 42
432 command_name: abortTransaction
433 database_name: admin
434
435 outcome:
436 collection:
437 data:
438 - _id: 1
439 - _id: 2
440
441 # Applications should not run commitTransaction after transient errors but
442 # the transactions API allows it and this test confirms unpinning behavior.
443 # In a sharded cluster, a transient error within a transaction unpins the
444 # session. This way a subsequent abort can "succeed" immediately instead of
445 # blocking for serverSelectionTimeoutMS in the case the mongos went down.
446 # However since the abortTransaction helper ignores errors, this test uses
447 # commitTransaction to prove the session was unpinned.
448 - description: unpin after transient error within a transaction and commit
449 useMultipleMongoses: true
450 clientOptions:
451 # Increase heartbeatFrequencyMS to avoid the race condition where an in
452 # flight heartbeat refreshes the first mongoes' SDAM state in between
453 # the insert connection error and the single commit attempt.
454 heartbeatFrequencyMS: 30000
455 operations:
456 - name: startTransaction
457 object: session0
458 - name: insertOne
459 object: collection
460 arguments:
461 session: session0
462 document:
463 _id: 3
464 result:
465 insertedId: 3
466 # Enable the fail point only on the Mongos that session0 is pinned to.
467 # Fail hello/legacy hello to prevent the heartbeat requested directly after the
468 # insert error from racing with server selection for the commit.
469 # Note: times: 7 is slightly artbitrary but it accounts for one failed
470 # insert and some SDAM heartbeats. A test runner will have multiple
471 # clients connected to this server so this fail point configuration
472 # is also racy.
473 - name: targetedFailPoint
474 object: testRunner
475 arguments:
476 session: session0
477 failPoint:
478 configureFailPoint: failCommand
479 mode: { times: 7 }
480 data:
481 failCommands: ["insert", "isMaster", "hello"]
482 closeConnection: true
483 - name: insertOne
484 object: collection
485 arguments:
486 session: session0
487 document:
488 _id: 4
489 result:
490 errorLabelsContain: ["TransientTransactionError"]
491 errorLabelsOmit: ["UnknownTransactionCommitResult"]
492 # Session unpins from the first mongos after the insert error and
493 # commitTransaction selects the second mongos which is unaware of the
494 # transaction and therefore fails with NoSuchTransaction error. If this
495 # commit succeeds it indicates a bug, either:
496 # - the driver mistakenly remained pinned even after the insert error, or
497 # - the test client was initialized with a single mongos seed
498 #
499 # Note that the commit attempt should not select the original mongos
500 # because that server's SDAM state is reset by the connection error,
501 # heartbeatFrequencyMS is high, and subsequent heartbeats
502 # should fail.
503 - name: commitTransaction
504 object: session0
505 result:
506 errorLabelsContain: ["TransientTransactionError"]
507 errorLabelsOmit: ["UnknownTransactionCommitResult"]
508 errorCodeName: NoSuchTransaction
509
510
511 expectations:
512 - command_started_event:
513 command:
514 insert: *collection_name
515 documents:
516 - _id: 3
517 ordered: true
518 readConcern:
519 lsid: session0
520 txnNumber:
521 $numberLong: "1"
522 startTransaction: true
523 autocommit: false
524 writeConcern:
525 command_name: insert
526 database_name: *database_name
527 - command_started_event:
528 command:
529 insert: *collection_name
530 documents:
531 - _id: 4
532 ordered: true
533 readConcern:
534 lsid: session0
535 txnNumber:
536 $numberLong: "1"
537 startTransaction:
538 autocommit: false
539 writeConcern:
540 command_name: insert
541 database_name: *database_name
542 - command_started_event:
543 command:
544 commitTransaction: 1
545 lsid: session0
546 txnNumber:
547 $numberLong: "1"
548 startTransaction:
549 autocommit: false
550 writeConcern:
551 recoveryToken: 42
552 command_name: commitTransaction
553 database_name: admin
554
555 outcome:
556 collection:
557 data:
558 - _id: 1
559 - _id: 2