summaryrefslogtreecommitdiff
path: root/jstests/sharding/move_chunk_update_with_write_retryability.js
blob: b7d0ddae5d36e1a3d180dea696db8c4c9ed845b3 (plain)
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
load("jstests/sharding/move_chunk_with_session_helper.js");

(function() {
"use strict";

load("jstests/libs/retryable_writes_util.js");

if (!RetryableWritesUtil.storageEngineSupportsRetryableWrites(jsTest.options().storageEngine)) {
    jsTestLog("Retryable writes are not supported, skipping test");
    return;
}

// Prevent unnecessary elections in the first shard replica set. Shard 'rs1' shard will need its
// secondary to get elected, so we don't give it a zero priority.
var st = new ShardingTest({
    mongos: 2,
    shards: {
        rs0: {nodes: [{rsConfig: {}}, {rsConfig: {priority: 0}}]},
        rs1: {nodes: [{rsConfig: {}}, {rsConfig: {}}]}
    }
});
assert.commandWorked(st.s.adminCommand({enableSharding: 'test'}));
st.ensurePrimaryShard('test', st.shard0.shardName);

var coll = 'update';
var cmd = {
    update: 'update',
    updates: [
        {q: {x: 10}, u: {$inc: {a: 1}}},  // in place
        {q: {x: 20}, u: {$inc: {b: 1}}, upsert: true},
        {q: {x: 30}, u: {x: 30, z: 1}}  // replacement
    ],
    ordered: false,
    lsid: {id: UUID()},
    txnNumber: NumberLong(35),
};
var setup = function(coll) {
    coll.insert({x: 10});
    coll.insert({x: 30});
};
var checkRetryResult = function(result, retryResult) {
    assert.eq(result.ok, retryResult.ok);
    assert.eq(result.n, retryResult.n);
    assert.eq(result.nModified, retryResult.nModified);
    assert.eq(result.upserted, retryResult.upserted);
    assert.eq(result.writeErrors, retryResult.writeErrors);
    assert.eq(result.writeConcernErrors, retryResult.writeConcernErrors);
};
var checkDocuments = function(coll) {
    assert.eq(1, coll.findOne({x: 10}).a);
    assert.eq(1, coll.findOne({x: 20}).b);
    assert.eq(1, coll.findOne({x: 30}).z);
};

testMoveChunkWithSession(st, coll, cmd, setup, checkRetryResult, checkDocuments);

st.stop();
})();