File: transactions.yml

package info (click to toggle)
golang-mongodb-mongo-driver 1.8.4%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-backports
  • size: 18,520 kB
  • sloc: perl: 533; ansic: 491; python: 432; makefile: 187; sh: 72
file content (598 lines) | stat: -rw-r--r-- 19,393 bytes parent folder | download | duplicates (3)
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
description: transactions are correctly pinned to connections for load-balanced clusters

schemaVersion: '1.3'

runOnRequirements:
  - topologies: [ load-balanced ]

createEntities:
  - client:
      id: &client0 client0
      useMultipleMongoses: true
      observeEvents:
        # Do not observe commandSucceededEvent or commandFailedEvent because we cannot guarantee success or failure of
        # commands like commitTransaction and abortTransaction in a multi-mongos load-balanced setup.
        - commandStartedEvent
        - connectionReadyEvent
        - connectionClosedEvent
        - connectionCheckedOutEvent
        - connectionCheckedInEvent
  - session:
      id: &session0 session0
      client: *client0
  - database:
      id: &database0 database0
      client: *client0
      databaseName: &database0Name database0Name
  - collection:
      id: &collection0 collection0
      database: *database0
      collectionName: &collection0Name coll0

initialData:
  - collectionName: *collection0Name
    databaseName: *database0Name
    documents:
      - { _id: 1 }
      - { _id: 2 }
      - { _id: 3 }

_yamlAnchors:
  documents:
    - &insertDocument
      _id: 4

tests:
  - description: sessions are reused in LB mode
    operations:
      - &nonTransactionalInsert
        name: insertOne
        object: *collection0
        arguments:
          document: { x: 1 }
      - *nonTransactionalInsert
      - name: assertSameLsidOnLastTwoCommands
        object: testRunner
        arguments:
          client: *client0

  - description: all operations go to the same mongos
    operations:
      - &startTransaction
        name: startTransaction
        object: *session0
      - &transactionalInsert
        name: insertOne
        object: *collection0
        arguments:
          document: { x: 1 }
          session: *session0
      - &assertConnectionPinned
        name: assertNumberConnectionsCheckedOut
        object: testRunner
        arguments:
          client: *client0
          connections: 1
      - *transactionalInsert
      - *transactionalInsert
      - *transactionalInsert
      - *transactionalInsert
      - *transactionalInsert
      - *assertConnectionPinned
      - &commitTransaction
        name: commitTransaction
        object: *session0
    expectEvents:
      - client: *client0
        events:
          - &insertStarted
            commandStartedEvent:
              commandName: insert
          - *insertStarted
          - *insertStarted
          - *insertStarted
          - *insertStarted
          - *insertStarted
          - &commitStarted
            commandStartedEvent:
              commandName: commitTransaction
      - client: *client0
        eventType: cmap
        events:
          # The connection is never checked back in.
          - connectionReadyEvent: {}
          - connectionCheckedOutEvent: {}

  - description: transaction can be committed multiple times
    operations:
      - *startTransaction
      - *transactionalInsert
      - *assertConnectionPinned
      - *commitTransaction
      - *assertConnectionPinned
      - *commitTransaction
      - *commitTransaction
      - *commitTransaction
      - *assertConnectionPinned
    expectEvents:
      - client: *client0
        events:
          - *insertStarted
          - *commitStarted
          - *commitStarted
          - *commitStarted
          - *commitStarted
      - client: *client0
        eventType: cmap
        events:
          - connectionReadyEvent: {}
          - connectionCheckedOutEvent: {}

  - description: pinned connection is not released after a non-transient CRUD error
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *client0
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [ insert ]
              errorCode: &nonTransientErrorCode 51 # ManualInterventionRequired
      - *startTransaction
      - name: insertOne
        object: *collection0
        arguments:
          document: { x: 1 }
          session: *session0
        expectError: &nonTransientExpectedError
          errorCode: *nonTransientErrorCode
          errorLabelsOmit: [ TransientTransactionError ]
      - *assertConnectionPinned
    expectEvents:
      - client: *client0
        events:
          - *insertStarted
      - client: *client0
        eventType: cmap
        events:
          # Events for setting the fail point.
          - connectionReadyEvent: {}
          - connectionCheckedOutEvent: {}
          - connectionCheckedInEvent: {}
          # Events for the transactional insert.
          - connectionCheckedOutEvent: {}

  - description: pinned connection is not released after a non-transient commit error
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *client0
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [ commitTransaction ]
              errorCode: *nonTransientErrorCode
      - *startTransaction
      - *transactionalInsert
      - name: commitTransaction
        object: *session0
        expectError: *nonTransientExpectedError
      - *assertConnectionPinned
    expectEvents:
      - client: *client0
        events:
          - *insertStarted
          - *commitStarted
      - client: *client0
        eventType: cmap
        events:
          # Events for setting the fail point.
          - connectionReadyEvent: {}
          - connectionCheckedOutEvent: {}
          - connectionCheckedInEvent: {}
          # Events for the transactional insert and commit.
          - connectionCheckedOutEvent: {}

  # Errors during abort are different than errors during commit and CRUD operations because the pinned connection is
  # always released after abort.
  - description: pinned connection is released after a non-transient abort error
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *client0
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [ abortTransaction ]
              errorCode: &nonTransientErrorCode 51 # ManualInterventionRequired
      - *startTransaction
      - *transactionalInsert
      - name: abortTransaction
        object: *session0
      - &assertConnectionNotPinned
        name: assertNumberConnectionsCheckedOut
        object: testRunner
        arguments:
          client: *client0
          connections: 0
    expectEvents:
      - client: *client0
        events:
          - *insertStarted
          - &abortStarted
            commandStartedEvent:
              commandName: abortTransaction
      - client: *client0
        eventType: cmap
        events:
          # Events for setting the fail point.
          - connectionReadyEvent: {}
          - connectionCheckedOutEvent: {}
          - connectionCheckedInEvent: {}
          # Events for the transactional insert and abort.
          - connectionCheckedOutEvent: {}
          - connectionCheckedInEvent: {}

  - description: pinned connection is released after a transient non-network CRUD error
    runOnRequirements:
      - serverless: forbid # (CLOUDP-88216) Serverless does not append error labels to errors triggered by failpoints.
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *client0
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [ insert ]
              errorCode: &transientErrorCode 24 # LockTimeout
      - *startTransaction
      - <<: *transactionalInsert
        expectError: &transientExpectedServerError
          errorCode: *transientErrorCode
          errorLabelsContain: [ TransientTransactionError ]
      - *assertConnectionNotPinned
      - name: abortTransaction
        object: *session0
      - *assertConnectionNotPinned
    expectEvents:
      - client: *client0
        events:
          - *insertStarted
          - *abortStarted
      - client: *client0
        eventType: cmap
        events:
          # Events for setting the failpoint.
          - connectionReadyEvent: {}
          - connectionCheckedOutEvent: {}
          - connectionCheckedInEvent: {}
          # Events for the insert.
          - connectionCheckedOutEvent: {}
          - connectionCheckedInEvent: {}
          # Events for abortTransction.
          - connectionCheckedOutEvent: {}
          - connectionCheckedInEvent: {}

  - description: pinned connection is released after a transient network CRUD error
    runOnRequirements:
      - serverless: forbid # (CLOUDP-88216) Serverless does not append error labels to errors triggered by failpoints.
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *client0
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [ insert ]
              closeConnection: true
      - *startTransaction
      - <<: *transactionalInsert
        expectError: &transientExpectedNetworkError
          isClientError: true
          errorLabelsContain: [ TransientTransactionError ]
      - *assertConnectionNotPinned
      - name: abortTransaction
        object: *session0
      - *assertConnectionNotPinned
    expectEvents:
      - client: *client0
        events:
          - *insertStarted
          - *abortStarted
      - client: *client0
        eventType: cmap
        events:
          # Events for setting the failpoint.
          - connectionReadyEvent: {}
          - connectionCheckedOutEvent: {}
          - connectionCheckedInEvent: {}
          # Events for the insert.
          - connectionCheckedOutEvent: {}
          - connectionCheckedInEvent: {}
          - connectionClosedEvent:
              reason: error
          # Events for abortTransaction
          - connectionReadyEvent: {}
          - connectionCheckedOutEvent: {}
          - connectionCheckedInEvent: {}

  - description: pinned connection is released after a transient non-network commit error
    runOnRequirements:
      - serverless: forbid # (CLOUDP-88216) Serverless does not append error labels to errors triggered by failpoints.
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *client0
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [ commitTransaction ]
              errorCode: *transientErrorCode
      - *startTransaction
      - *transactionalInsert
      - <<: *commitTransaction
        expectError: *transientExpectedServerError
      - *assertConnectionNotPinned
    expectEvents:
      - client: *client0
        events:
          - *insertStarted
          - *commitStarted
      - client: *client0
        eventType: cmap
        events:
          # Events for setting the failpoint.
          - connectionReadyEvent: {}
          - connectionCheckedOutEvent: {}
          - connectionCheckedInEvent: {}
          # Events for the insert.
          - connectionCheckedOutEvent: {}
          # Events for commitTransaction.
          - connectionCheckedInEvent: {}

  - description: pinned connection is released after a transient network commit error
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *client0
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [ commitTransaction ]
              closeConnection: true
      - *startTransaction
      - *transactionalInsert
      - <<: *commitTransaction
        # Ignore the result and error because the operation might fail if it targets a new mongos that isn't aware of
        # the transaction or the server-side reaper thread closes the transaction first. We only want to assert that
        # the operation is retried, which is done via monitoring expectations, so the exact result/error is not
        # necessary.
        ignoreResultAndError: true
      - *assertConnectionNotPinned
    expectEvents:
      - client: *client0
        events:
          - *insertStarted
          - *commitStarted
          # The commit will be automatically retried.
          - *commitStarted
      - client: *client0
        eventType: cmap
        events:
          # Events for setting the failpoint.
          - connectionReadyEvent: {}
          - connectionCheckedOutEvent: {}
          - connectionCheckedInEvent: {}
          # Events for the insert.
          - connectionCheckedOutEvent: {}
          # Events for the first commitTransaction.
          - connectionCheckedInEvent: {}
          - connectionClosedEvent:
              reason: error
          # Events for the commitTransaction retry.
          - connectionReadyEvent: {}
          - connectionCheckedOutEvent: {}
          - connectionCheckedInEvent: {}

  - description: pinned connection is released after a transient non-network abort error
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *client0
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [ abortTransaction ]
              errorCode: *transientErrorCode
      - *startTransaction
      - *transactionalInsert
      - name: abortTransaction
        object: *session0
      - *assertConnectionNotPinned
    expectEvents:
      - client: *client0
        events:
          - *insertStarted
          - *abortStarted
      - client: *client0
        eventType: cmap
        events:
          # Events for setting the failpoint.
          - connectionReadyEvent: {}
          - connectionCheckedOutEvent: {}
          - connectionCheckedInEvent: {}
          # Events for the insert.
          - connectionCheckedOutEvent: {}
          # Events for abortTransaction.
          - connectionCheckedInEvent: {}

  - description: pinned connection is released after a transient network abort error
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *client0
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [ abortTransaction ]
              closeConnection: true
      - *startTransaction
      - *transactionalInsert
      - name: abortTransaction
        object: *session0
      - *assertConnectionNotPinned
    expectEvents:
      - client: *client0
        events:
          - *insertStarted
          - *abortStarted
          # The abort will be automatically retried.
          - *abortStarted
      - client: *client0
        eventType: cmap
        events:
          # Events for setting the failpoint.
          - connectionReadyEvent: {}
          - connectionCheckedOutEvent: {}
          - connectionCheckedInEvent: {}
          # Events for the insert.
          - connectionCheckedOutEvent: {}
          # Events for the first abortTransaction.
          - connectionCheckedInEvent: {}
          - connectionClosedEvent:
              reason: error
          # Events for the abortTransaction retry.
          - connectionReadyEvent: {}
          - connectionCheckedOutEvent: {}
          - connectionCheckedInEvent: {}

  - description: pinned connection is released on successful abort
    operations:
      - *startTransaction
      - *transactionalInsert
      - name: abortTransaction
        object: *session0
      - *assertConnectionNotPinned
    expectEvents:
      - client: *client0
        events:
          - *insertStarted
          - *abortStarted
      - client: *client0
        eventType: cmap
        events:
          # The insert will create and pin a connection. The abort will use it and then unpin.
          - connectionReadyEvent: {}
          - connectionCheckedOutEvent: {}
          - connectionCheckedInEvent: {}

  - description: pinned connection is returned when a new transaction is started
    operations:
      - *startTransaction
      - *transactionalInsert
      - *commitTransaction
      - *assertConnectionPinned
      - *startTransaction
      - *assertConnectionNotPinned # startTransaction will unpin the connection.
      - *transactionalInsert
      - *assertConnectionPinned # The first operation in the new transaction will pin the connection again.
      - *commitTransaction
    expectEvents:
      - client: *client0
        events:
          - *insertStarted
          - *commitStarted
          - *insertStarted
          - *commitStarted
      - client: *client0
        eventType: cmap
        events:
          # Events for the first insert and commit.
          - connectionReadyEvent: {}
          - connectionCheckedOutEvent: {}
          # Events for startTransaction.
          - connectionCheckedInEvent: {}
          # Events for the second insert and commit.
          - connectionCheckedOutEvent: {}

  - description: pinned connection is returned when a non-transaction operation uses the session
    operations:
      - *startTransaction
      - *transactionalInsert
      - *commitTransaction
      - *assertConnectionPinned
      - *transactionalInsert
      # The insert is a non-transactional operation that uses the session, so it unpins the connection.
      - *assertConnectionNotPinned
    expectEvents:
      - client: *client0
        events:
          - *insertStarted
          - *commitStarted
          - *insertStarted
      - client: *client0
        eventType: cmap
        events:
          # Events for the first insert and commit.
          - connectionReadyEvent: {}
          - connectionCheckedOutEvent: {}
          # Events for the second insert.
          - connectionCheckedInEvent: {}
          - connectionCheckedOutEvent: {}
          - connectionCheckedInEvent: {}

  - description: a connection can be shared by a transaction and a cursor
    operations:
      - *startTransaction
      - *transactionalInsert
      - *assertConnectionPinned
      - name: createFindCursor
        object: *collection0
        arguments:
          filter: {}
          batchSize: 2
          session: *session0
        saveResultAsEntity: &cursor0 cursor0
      - *assertConnectionPinned
      - name: close
        object: *cursor0
      - *assertConnectionPinned
      # Abort the transaction to ensure that the connection is unpinned.
      - name: abortTransaction
        object: *session0
      - *assertConnectionNotPinned
    expectEvents:
      - client: *client0
        events:
          - *insertStarted
          - commandStartedEvent:
              commandName: find
          - commandStartedEvent:
              commandName: killCursors
          - *abortStarted
      - client: *client0
        eventType: cmap
        events:
          # Events for the insert, find, and killCursors.
          - connectionReadyEvent: {}
          - connectionCheckedOutEvent: {}
          # Events for abortTransaction.
          - connectionCheckedInEvent: {}