diff options
author | Daniel Gottlieb <daniel.gottlieb@mongodb.com> | 2020-08-27 11:09:08 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-08-27 18:26:55 +0000 |
commit | 9ced0d1888b2ab1e738b87b01a5454686e97811e (patch) | |
tree | 56601177259b68e85cbdab7e492a5c0f4e45a89a /jstests | |
parent | 18f397e322dbc7cc1d6272bfb6df5279a0ab6337 (diff) | |
download | mongo-9ced0d1888b2ab1e738b87b01a5454686e97811e.tar.gz |
SERVER-49890: Create resharding oplog view on startup.
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/libs/check_unique_indexes.js | 4 | ||||
-rw-r--r-- | jstests/libs/check_uuids.js | 4 | ||||
-rw-r--r-- | jstests/multiVersion/genericSetFCVUsage/do_upgrade_downgrade.js | 4 | ||||
-rw-r--r-- | jstests/noPassthrough/slim_oplog_test.js | 90 |
4 files changed, 102 insertions, 0 deletions
diff --git a/jstests/libs/check_unique_indexes.js b/jstests/libs/check_unique_indexes.js index 0dbaedf2d53..9decdbded64 100644 --- a/jstests/libs/check_unique_indexes.js +++ b/jstests/libs/check_unique_indexes.js @@ -23,6 +23,10 @@ function checkUniqueIndexFormatVersion(adminDB) { currentDatabase.runCommand("listCollections", {includePendingDrops: true}) .cursor.firstBatch; collectionsWithPending.forEach(function(c) { + if (c.type == "view") { + return; + } + let currentCollection = currentDatabase.getCollection(c.name); currentCollection.getIndexes().forEach(function(index) { if (index.unique) { diff --git a/jstests/libs/check_uuids.js b/jstests/libs/check_uuids.js index 54cf9bd2f90..69c4adfc06a 100644 --- a/jstests/libs/check_uuids.js +++ b/jstests/libs/check_uuids.js @@ -13,6 +13,10 @@ function checkCollectionUUIDs(adminDB) { let currentDatabase = adminDB.getSiblingDB(database.name); let collectionInfos = currentDatabase.getCollectionInfos(); for (let i = 0; i < collectionInfos.length; i++) { + if (collectionInfos[i].type == "view") { + continue; + } + assert(collectionInfos[i].info.uuid, "Expect uuid for collection: " + tojson(collectionInfos[i])); } diff --git a/jstests/multiVersion/genericSetFCVUsage/do_upgrade_downgrade.js b/jstests/multiVersion/genericSetFCVUsage/do_upgrade_downgrade.js index 686932593c8..e5888c67565 100644 --- a/jstests/multiVersion/genericSetFCVUsage/do_upgrade_downgrade.js +++ b/jstests/multiVersion/genericSetFCVUsage/do_upgrade_downgrade.js @@ -62,6 +62,10 @@ let recreateUniqueIndexes = function(db, secondary) { let mdb = db.getSiblingDB(d.name); mdb.getCollectionInfos().forEach(function(c) { let currentCollection = mdb.getCollection(c.name); + if (c.type == "view") { + return; + } + currentCollection.getIndexes().forEach(function(spec) { if (!spec.unique) { return; diff --git a/jstests/noPassthrough/slim_oplog_test.js b/jstests/noPassthrough/slim_oplog_test.js new file mode 100644 index 00000000000..f049e9d2a55 --- /dev/null +++ b/jstests/noPassthrough/slim_oplog_test.js @@ -0,0 +1,90 @@ +/** + * The slim oplog is a view on the oplog to support efficient lookup queries for resharding. + * + * @tags: [ + * requires_replication, + * requires_majority_read_concern, + * uses_transactions, + * uses_prepare_transaction + * ] + */ +(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; +} + +load("jstests/core/txns/libs/prepare_helpers.js"); + +const rst = new ReplSetTest({nodes: 2}); +rst.startSet(); +rst.initiate(); + +const rsConn = new Mongo(rst.getURL()); +const oplog = rst.getPrimary().getDB("local")["oplog.rs"]; +const slimOplog = rst.getPrimary().getDB("local")["system.resharding.slimOplogForGraphLookup"]; +const session = rsConn.startSession({retryWrites: true}); +const collection = session.getDatabase("test")["collection"]; + +{ + // Assert an oplog entry representing a retryable write projects a `prevOpTime.ts` of the null + // timestamp. + assert.commandWorked(collection.insert({_id: "slim"})); + + const oplogEntry = oplog.find({"o._id": "slim"}).next(); + jsTestLog({"slim entry": oplogEntry, "slim": slimOplog.exists()}); + assert(oplogEntry.hasOwnProperty("txnNumber")); + assert(oplogEntry.hasOwnProperty("stmtId")); + assert.eq(Timestamp(0, 0), slimOplog.find({ts: oplogEntry["ts"]}).next()["prevOpTime"]["ts"]); +} + +{ + // Assert an oplog entry that commits a prepared transaction projects a `prevOpTime.ts` equal to + // the timestamp of the preparing oplog entry. + session.startTransaction(); + assert.commandWorked(collection.insert({_id: "slim_1"})); + assert.commandWorked(collection.insert({_id: "slim_2"})); + let prepTs = PrepareHelpers.prepareTransaction(session); + assert.commandWorked(PrepareHelpers.commitTransaction(session, prepTs)); + + const commitEntry = oplog.find({"prevOpTime.ts": prepTs}).next(); + assert.eq(prepTs, commitEntry["prevOpTime"]["ts"]); + jsTestLog({ + PrepEntry: oplog.find({ts: prepTs}).next(), + CommitEntry: commitEntry, + SlimEntry: slimOplog.find({ts: commitEntry["ts"]}).next() + }); + + // Perform a $graphLookup connecting non-trivial slim oplog entries to the associated applyOps + // operations. Assert the history is as expected. + let oplogDocsWithHistory = oplog.aggregate([ + {$match: {ts: commitEntry["ts"]}}, + {$graphLookup: {from: "system.resharding.slimOplogForGraphLookup", + startWith: "$ts", + connectFromField: "prevOpTime.ts", + connectToField: "ts", + depthField: "depthForResharding", + as: "history"}}, + // For the purposes of this test, unwind the history to give a predictable order of items + // that graphLookup accumulates. + {$unwind: "$history"}, + {$sort: {"history.ts": 1}} + ]).toArray(); + + jsTestLog({"Unwound history": oplogDocsWithHistory}); + assert.eq(2, oplogDocsWithHistory.length); + assert.eq(1, oplogDocsWithHistory[0]["history"]["depthForResharding"]); + assert.eq(Timestamp(0, 0), oplogDocsWithHistory[0]["history"]["prevOpTime"]["ts"]); + assert.eq(2, oplogDocsWithHistory[0]["history"]["o"]["applyOps"].length); + + assert.eq(0, oplogDocsWithHistory[1]["history"].depthForResharding); + assert.eq(prepTs, oplogDocsWithHistory[1]["history"]["prevOpTime"]["ts"]); + assert.eq({}, oplogDocsWithHistory[1]["history"]["o"]); +} + +rst.stopSet(); +})(); |