Skip to content

Commit 10919c9

Browse files
DRIVERS-716 Improved Bulk Write API (#1534)
1 parent ccfb65c commit 10919c9

File tree

48 files changed

+13062
-11
lines changed

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

+13062
-11
lines changed

source/client-side-operations-timeout/tests/README.md

+44-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ test MUST be unset using `internalClient` after the test has been executed. All
2424
MUST be configured with read/write concern `majority`, read preference `primary`, and command monitoring enabled to
2525
listen for `command_started` events.
2626

27-
### 1. Multi-batch writes
27+
### 1. Multi-batch inserts
2828

2929
This test MUST only run against standalones on server versions 4.4 and higher. The `insertMany` call takes an
3030
exceedingly long time on replicasets and sharded clusters. Drivers MAY adjust the timeouts used in this test to allow
@@ -598,6 +598,49 @@ Tests in this section MUST only run against replica sets and sharded clusters wi
598598
1. `command_started` and `command_failed` events for an `insert` command.
599599
2. `command_started` and `command_failed` events for an `abortTransaction` command.
600600

601+
### 11. Multi-batch bulkWrites
602+
603+
This test MUST only run against server versions 8.0+.
604+
605+
1. Using `internalClient`, drop the `db.coll` collection.
606+
607+
2. Using `internalClient`, set the following fail point:
608+
609+
```javascript
610+
{
611+
configureFailPoint: "failCommand",
612+
mode: {
613+
times: 2
614+
},
615+
data: {
616+
failCommands: ["bulkWrite"],
617+
blockConnection: true,
618+
blockTimeMS: 1010
619+
}
620+
}
621+
```
622+
623+
3. Using `internalClient`, perform a `hello` command and record the `maxBsonObjectSize` and `maxMessageSizeBytes` values
624+
in the response.
625+
626+
4. Create a new MongoClient (referred to as `client`) with `timeoutMS=2000`.
627+
628+
5. Create a list of write models (referred to as `models`) with the following write model repeated
629+
(`maxMessageSizeBytes / maxBsonObjectSize + 1`) times:
630+
631+
```json
632+
InsertOne {
633+
"namespace": "db.coll",
634+
"document": { "a": "b".repeat(maxBsonObjectSize - 500) }
635+
}
636+
```
637+
638+
6. Call `bulkWrite` on `client` with `models`.
639+
640+
- Expect this to fail with a timeout error.
641+
642+
7. Verify that two `bulkWrite` commands were executed as part of the `MongoClient.bulkWrite` call.
643+
601644
## Unit Tests
602645

603646
The tests enumerated in this section could not be expressed in either spec or prose format. Drivers SHOULD implement

source/command-logging-and-monitoring/tests/monitoring/unacknowledged-client-bulkWrite.json

+186
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
description: "unacknowledged-client-bulkWrite"
2+
3+
schemaVersion: "1.1"
4+
5+
createEntities:
6+
- client:
7+
id: &client client
8+
observeEvents:
9+
- commandStartedEvent
10+
- commandSucceededEvent
11+
- commandFailedEvent
12+
uriOptions:
13+
w: 0
14+
- database:
15+
id: &database database
16+
client: *client
17+
databaseName: &databaseName command-monitoring-tests
18+
- collection:
19+
id: &collection collection
20+
database: *database
21+
collectionName: &collectionName test
22+
23+
initialData:
24+
- collectionName: *collectionName
25+
databaseName: *databaseName
26+
documents:
27+
- { _id: 1, x: 11 }
28+
- { _id: 2, x: 22 }
29+
- { _id: 3, x: 33 }
30+
31+
_yamlAnchors:
32+
namespace: &namespace "command-monitoring-tests.test"
33+
34+
tests:
35+
- description: 'A successful mixed client bulkWrite'
36+
operations:
37+
- object: *client
38+
name: clientBulkWrite
39+
arguments:
40+
models:
41+
- insertOne:
42+
namespace: *namespace
43+
document: { _id: 4, x: 44 }
44+
- updateOne:
45+
namespace: *namespace
46+
filter: { _id: 3 }
47+
update: { $set: { x: 333 } }
48+
expectResult:
49+
insertedCount:
50+
$$unsetOrMatches: 0
51+
upsertedCount:
52+
$$unsetOrMatches: 0
53+
matchedCount:
54+
$$unsetOrMatches: 0
55+
modifiedCount:
56+
$$unsetOrMatches: 0
57+
deletedCount:
58+
$$unsetOrMatches: 0
59+
insertResults:
60+
$$unsetOrMatches: {}
61+
updateResults:
62+
$$unsetOrMatches: {}
63+
deleteResults:
64+
$$unsetOrMatches: {}
65+
expectEvents:
66+
-
67+
client: *client
68+
events:
69+
- commandStartedEvent:
70+
commandName: bulkWrite
71+
databaseName: admin
72+
command:
73+
bulkWrite: 1
74+
errorsOnly: true
75+
ordered: true
76+
ops:
77+
- insert: 0
78+
document: { _id: 4, x: 44 }
79+
- update: 0
80+
filter: { _id: 3 }
81+
updateMods: { $set: { x: 333 } }
82+
multi: false
83+
nsInfo:
84+
- ns: *namespace
85+
- commandSucceededEvent:
86+
commandName: bulkWrite
87+
reply:
88+
ok: 1
89+
nInserted: { $$exists: false }
90+
nMatched: { $$exists: false }
91+
nModified: { $$exists: false }
92+
nUpserted: { $$exists: false }
93+
nDeleted: { $$exists: false }

0 commit comments

Comments
 (0)