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
|
'use strict';
/**
* agg_merge_when_matched_replace_with_new.js
*
* Tests $merge with whenMatched set to "replace" concurrently with moveChunk operations on
* the output collection.
*
* @tags: [
* requires_sharding,
* assumes_balancer_off,
* requires_non_retryable_writes,
* ]
*/
load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload
load('jstests/concurrency/fsm_workloads/agg_with_chunk_migrations.js'); // for $config
var $config = extendWorkload($config, function($config, $super) {
// Set the collection to run concurrent moveChunk operations as the output collection.
$config.data.collWithMigrations = "agg_merge_when_matched_replace_with_new";
$config.data.threadRunCount = 0;
$config.states.aggregate = function aggregate(db, collName, connCache) {
// This pipeline will perform an upsert on the first run, and replacement-style update on
// subsequent runs.
const res = db[collName].aggregate([
{$addFields: {_id: this.tid, count: this.threadRunCount}},
{
$merge: {
into: this.collWithMigrations,
whenMatched: "replace",
whenNotMatched: "insert"
}
},
]);
// $merge should always return 0 documents.
assert.eq(0, res.itcount());
// If running with causal consistency, the writes may not have propagated to the secondaries
// yet.
assert.soon(() => {
return db[this.collWithMigrations]
.find({_id: this.tid, count: this.threadRunCount})
.itcount() == 1;
});
this.threadRunCount += 1;
};
return $config;
});
|