summaryrefslogtreecommitdiff
path: root/jstests/disk/repair_failure_is_recoverable.js
blob: cbfc12e5b4b92420ca3e2c8cb8d27fbf16bc28ae (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
59
60
61
62
/**
 * This test ensures that a failure during repair does not allow MongoDB to start normally and
 * requires it to be restarted with --repair again.
 *
 * This is not storage-engine specific.
 */

(function() {

    load('jstests/disk/libs/wt_file_helper.js');

    const exitBeforeRepairParameter = "exitBeforeDataRepair";
    const exitBeforeRepairInvalidatesConfigParameter = "exitBeforeRepairInvalidatesConfig";

    const baseName = "repair_failure_is_recoverable";
    const dbName = "repair_failure_is_recoverable";
    const collName = "test";

    const dbpath = MongoRunner.dataPath + baseName + "/";
    resetDbpath(dbpath);

    let mongod = MongoRunner.runMongod({dbpath: dbpath});
    const port = mongod.port;

    let testColl = mongod.getDB(dbName)[collName];

    assert.commandWorked(testColl.insert({_id: 0, foo: "bar"}));

    MongoRunner.stopMongod(mongod);

    /**
     * Test 1. Cause an exit before repairing data. MongoDB should not be able to restart without
     * --repair.
     */
    assertRepairFailsWithFailpoint(dbpath, port, exitBeforeRepairParameter);

    assertErrorOnStartupAfterIncompleteRepair(dbpath, port);

    assertRepairSucceeds(dbpath, port);

    assertStartAndStopStandaloneOnExistingDbpath(dbpath, port, function(node) {
        let nodeDB = node.getDB(dbName);
        assert(nodeDB[collName].exists());
        assert.eq(nodeDB[collName].find().itcount(), 1);
    });

    /**
     * Test 2. Fail after repairing data, before invalidating the replica set config. MongoDB should
     * not be able to restart without --repair.
     */
    assertRepairFailsWithFailpoint(dbpath, port, exitBeforeRepairInvalidatesConfigParameter);

    assertErrorOnStartupAfterIncompleteRepair(dbpath, port);

    assertRepairSucceeds(dbpath, port);

    assertStartAndStopStandaloneOnExistingDbpath(dbpath, port, function(node) {
        let nodeDB = node.getDB(dbName);
        assert(nodeDB[collName].exists());
        assert.eq(nodeDB[collName].find().itcount(), 1);
    });
})();