summaryrefslogtreecommitdiff
path: root/jstests/sharding/min_optime_recovery_on_failed_move_chunk_commit.js
blob: ab125e12e21b54160b50af1ba76a1404bb1ca8d6 (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
/**
 * Tests that the shard will update the min optime recovery document after startup.
 * @tags: [requires_persistence]
 */
(function() {
    "use strict";

    var st = new ShardingTest({shards: 1});

    // Insert a recovery doc with non-zero minOpTimeUpdaters to simulate a migration
    // process that crashed in the middle of the critical section.

    var recoveryDoc = {
        _id: 'minOpTimeRecovery',
        configsvrConnectionString: st.configRS.getURL(),
        shardName: st.shard0.shardName,
        minOpTime: {ts: Timestamp(0, 0), t: 0},
        minOpTimeUpdaters: 2
    };

    assert.writeOK(st.shard0.getDB('admin').system.version.insert(recoveryDoc));

    // Make sure test is setup correctly.
    var minOpTimeRecoveryDoc =
        st.shard0.getDB('admin').system.version.findOne({_id: 'minOpTimeRecovery'});

    assert.neq(null, minOpTimeRecoveryDoc);
    assert.eq(0, minOpTimeRecoveryDoc.minOpTime.ts.getTime());
    assert.eq(2, minOpTimeRecoveryDoc.minOpTimeUpdaters);

    st.restartShardRS(0);

    // After the restart, the shard should have updated the opTime and reset minOpTimeUpdaters.
    minOpTimeRecoveryDoc =
        st.shard0.getDB('admin').system.version.findOne({_id: 'minOpTimeRecovery'});

    assert.neq(null, minOpTimeRecoveryDoc);
    assert.gt(minOpTimeRecoveryDoc.minOpTime.ts.getTime(), 0);
    assert.eq(0, minOpTimeRecoveryDoc.minOpTimeUpdaters);

    st.stop();

})();