summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorTess Avitabile <tess.avitabile@mongodb.com>2016-10-12 15:11:47 -0400
committerTess Avitabile <tess.avitabile@mongodb.com>2016-10-18 09:48:06 -0400
commit5053052fdafc16e7027cb246ce58c300bb6f45b5 (patch)
tree33f121cb5519537297554e7c9b0652807c7fe6c6 /jstests
parent7862cc37887855dc763975d77a00d8bd89f40eb4 (diff)
downloadmongo-5053052fdafc16e7027cb246ce58c300bb6f45b5.tar.gz
SERVER-26599 Master-slave initial sync should use the exact _id index spec from master
Diffstat (limited to 'jstests')
-rw-r--r--jstests/noPassthrough/index_version_autoupgrade.js31
-rw-r--r--jstests/repl/initial_sync_id_index.js46
2 files changed, 74 insertions, 3 deletions
diff --git a/jstests/noPassthrough/index_version_autoupgrade.js b/jstests/noPassthrough/index_version_autoupgrade.js
index 6895304217a..b7dcd5c7f35 100644
--- a/jstests/noPassthrough/index_version_autoupgrade.js
+++ b/jstests/noPassthrough/index_version_autoupgrade.js
@@ -42,9 +42,18 @@
testDB.dropDatabase();
var coll = testDB.index_version_autoupgrade;
- assert.commandWorked(coll.createIndex({withoutAnyOptions: 1}));
+ // Create a v=1 _id index. This requires setting featureCompatibilityVersion to 3.2.
+ assert.commandWorked(conn.adminCommand({setFeatureCompatibilityVersion: "3.2"}));
+ assert.commandWorked(testDB.createCollection("index_version_autoupgrade"));
+ assert.commandWorked(conn.adminCommand({setFeatureCompatibilityVersion: "3.4"}));
var allIndexes = coll.getIndexes();
- var spec = GetIndexHelpers.findByKeyPattern(allIndexes, {withoutAnyOptions: 1});
+ var spec = GetIndexHelpers.findByKeyPattern(allIndexes, {_id: 1});
+ assert.neq(null, spec, "Index with key pattern {_id: 1} not found: " + tojson(allIndexes));
+ assert.eq(1, spec.v, "Expected a v=1 index to be built: " + tojson(spec));
+
+ assert.commandWorked(coll.createIndex({withoutAnyOptions: 1}));
+ allIndexes = coll.getIndexes();
+ spec = GetIndexHelpers.findByKeyPattern(allIndexes, {withoutAnyOptions: 1});
assert.neq(
null,
spec,
@@ -72,6 +81,7 @@
if (doesAutoUpgrade) {
expectedResults = [
+ {keyPattern: {_id: 1}, version: defaultIndexVersion},
{keyPattern: {withoutAnyOptions: 1}, version: defaultIndexVersion},
{keyPattern: {withV1: 1}, version: defaultIndexVersion},
{keyPattern: {withV2: 1}, version: defaultIndexVersion},
@@ -79,6 +89,7 @@
} else {
expectedResults = [
+ {keyPattern: {_id: 1}, version: 1},
{keyPattern: {withoutAnyOptions: 1}, version: defaultIndexVersion},
{keyPattern: {withV1: 1}, version: 1},
{keyPattern: {withV2: 1}, version: 2},
@@ -86,7 +97,7 @@
}
expectedResults.forEach(function(expected) {
- var allIndexes = coll.getIndexes();
+ var allIndexes = collToVerify.getIndexes();
var spec = GetIndexHelpers.findByKeyPattern(allIndexes, expected.keyPattern);
assert.neq(null,
spec,
@@ -151,5 +162,19 @@
}, false);
MongoRunner.stopMongod(cloneConn);
+ // Test that the "clone" command doesn't upgrade existing indexes to the latest version.
+ cloneConn = MongoRunner.runMongod({});
+ assert.neq(null, cloneConn, "mongod was unable to start up");
+ assert.eq("3.4", getFeatureCompatibilityVersion(cloneConn));
+ testIndexVersionAutoUpgrades(function(coll) {
+ var cloneDB = cloneConn.getDB(coll.getDB().getName());
+ assert.commandWorked(cloneDB.runCommand({
+ clone: conn.host,
+ fromDB: coll.getDB().getName(),
+ }));
+ return cloneDB[coll.getName()];
+ }, false);
+ MongoRunner.stopMongod(cloneConn);
+
MongoRunner.stopMongod(conn);
})();
diff --git a/jstests/repl/initial_sync_id_index.js b/jstests/repl/initial_sync_id_index.js
new file mode 100644
index 00000000000..5871f68f323
--- /dev/null
+++ b/jstests/repl/initial_sync_id_index.js
@@ -0,0 +1,46 @@
+// Tests that the _id index spec is copied exactly during initial sync.
+(function() {
+ "use strict";
+
+ load("jstests/libs/get_index_helpers.js");
+
+ const rt = new ReplTest();
+ const master = rt.start(true);
+ const masterDB = master.getDB("test");
+
+ // Initially, featureCompatibilityVersion is 3.4, so we will create v=2 indexes.
+ let res = master.adminCommand({getParameter: 1, featureCompatibilityVersion: 1});
+ assert.commandWorked(res);
+ assert.eq(res.featureCompatibilityVersion, "3.4");
+ assert.commandWorked(masterDB.createCollection("collV2"));
+ let spec = GetIndexHelpers.findByName(masterDB.collV2.getIndexes(), "_id_");
+ assert.neq(spec, null);
+ assert.eq(spec.v, 2);
+
+ // Set featureCompatibilityVersion to 3.2, so we create v=1 indexes.
+ assert.commandWorked(master.adminCommand({setFeatureCompatibilityVersion: "3.2"}));
+ res = master.adminCommand({getParameter: 1, featureCompatibilityVersion: 1});
+ assert.commandWorked(res);
+ assert.eq(res.featureCompatibilityVersion, "3.2");
+ assert.commandWorked(masterDB.createCollection("collV1"));
+ spec = GetIndexHelpers.findByName(masterDB.collV1.getIndexes(), "_id_");
+ assert.neq(spec, null);
+ assert.eq(spec.v, 1);
+
+ // Initial sync a slave.
+ const slave = rt.start(false);
+ const slaveDB = slave.getDB("test");
+
+ // Perform a w=2 write to ensure that slave can be read from, and initial sync is complete.
+ assert.writeOK(masterDB.coll.insert({}, {writeConcern: {w: 2}}));
+
+ // Check _id index versions on slave.
+ spec = GetIndexHelpers.findByName(slaveDB.collV2.getIndexes(), "_id_");
+ assert.neq(spec, null);
+ assert.eq(spec.v, 2);
+ spec = GetIndexHelpers.findByName(slaveDB.collV1.getIndexes(), "_id_");
+ assert.neq(spec, null);
+ assert.eq(spec.v, 1);
+
+ rt.stop();
+})(); \ No newline at end of file