summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/abandon_snapshot_for_each_collection_from_db.js
blob: 432ee93eaa7ff573a153b1581a33da4fe324a3de (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
/**
 * The 'forEachCollectionFromDb' CollectionCatalog helper should abandon its snapshot before it
 * performs the user provided callback on each collection.
 * Any newly added collections have the chance to be seen as 'forEachCollectionFromDb' iterates over
 * the remaining collections. This could lead to inconsistencies, such as seeing indexes in the
 * IndexCatalog of the new collection but not seeing them on-disk due to using an older snapshot
 * (BF-13133).
 *
 * @tags: [requires_replication]
 */
(function() {
    "use strict";

    const dbName = "test";
    const collName = "coll";

    const rst = new ReplSetTest({nodes: 2});
    rst.startSet();
    rst.initiate();

    const db = rst.getPrimary().getDB(dbName);
    assert.commandWorked(db.createCollection(collName));

    const failpoint = 'hangBeforeGettingNextCollection';

    // Hang 'forEachCollectionFromDb' after iterating through the first collection.
    assert.commandWorked(db.adminCommand({configureFailPoint: failpoint, mode: "alwaysOn"}));

    TestData.failpoint = failpoint;
    const awaitCreateCollections = startParallelShell(() => {
        // The 'forEachCollectionFromDb' helper doesn't iterate in collection name order, so we need
        // to insert multiple collections to have at least one next collection when the
        // CollectionCatalog iterator is incremented.
        for (let i = 0; i < 25; i++) {
            const collName = "a".repeat(i + 1);
            assert.commandWorked(db.createCollection(collName));
        }

        // Let 'forEachCollectionFromDb' iterate to the next collection.
        assert.commandWorked(
            db.adminCommand({configureFailPoint: TestData.failpoint, mode: "off"}));
    }, rst.getPrimary().port);

    assert.commandWorked(db.stats());
    awaitCreateCollections();

    rst.stopSet();
}());