summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2020-02-26 05:20:35 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-02-26 12:15:07 +0000
commitb41cd4b2c416e965fc3541c97cd0b51563d90c40 (patch)
treeae733156e4785a7e523369faa8a2a2c4607454ce /jstests
parent9e69da32cea83fc45724213215a8de40d2635f45 (diff)
downloadmongo-b41cd4b2c416e965fc3541c97cd0b51563d90c40.tar.gz
SERVER-45599 Backport of SERVER-32198: Split CollectionShardingState::getMetadata into three methods
o getCurrentMetadataIfKnown - which returns the current filtering metadata if any is available o getMetadataForOperation - which returns the metadata which is required by the current opertion, based on the OperationShardingState o getCurrentMetadata - which returns the currently available filtering metadata (or UNSHARDED if not known) This is in preparation for making getMetadataForOperation/getCurrentMetadata throw StaleShardVersion exception if the metadata has not been loaded yet. This is a partial cherry-pick from dcf7e0dd89d34f58b592f1adb3d41e5edd6e2012, adapted for the 4.0 branch.
Diffstat (limited to 'jstests')
-rw-r--r--jstests/sharding/cursor_valid_after_shard_stepdown.js3
-rw-r--r--jstests/sharding/dump_coll_metadata.js10
-rw-r--r--jstests/sharding/features1.js124
3 files changed, 57 insertions, 80 deletions
diff --git a/jstests/sharding/cursor_valid_after_shard_stepdown.js b/jstests/sharding/cursor_valid_after_shard_stepdown.js
index ea0dd72338f..01e7ee57c30 100644
--- a/jstests/sharding/cursor_valid_after_shard_stepdown.js
+++ b/jstests/sharding/cursor_valid_after_shard_stepdown.js
@@ -38,10 +38,11 @@ TestData.skipCheckingUUIDsConsistentAcrossCluster = true;
assert.eq(0, getMoreCursor.id);
assert.eq(2, getMoreCursor.nextBatch[0].x);
+ // After stepdown, the shard version will be reset
var shardVersionAfterStepdown =
assert.commandWorked(st.rs0.getPrimary().adminCommand({getShardVersion: 'TestDB.TestColl'}))
.global;
- assert.eq(Timestamp(0, 0), shardVersionAfterStepdown);
+ assert.eq("UNKNOWN", shardVersionAfterStepdown);
st.stop();
})();
diff --git a/jstests/sharding/dump_coll_metadata.js b/jstests/sharding/dump_coll_metadata.js
index 30726f4746d..c1254985dd6 100644
--- a/jstests/sharding/dump_coll_metadata.js
+++ b/jstests/sharding/dump_coll_metadata.js
@@ -25,13 +25,13 @@
assert.eq(metadata.chunks.length, 1);
assert.eq(metadata.pending.length, 0);
- assert(metadata.chunks[0][0]._id + "" == MinKey + "");
- assert(metadata.chunks[0][1]._id + "" == MaxKey + "");
- assert(metadata.shardVersion + "" == result.global + "");
+ assert.eq(metadata.chunks[0][0]._id, MinKey);
+ assert.eq(metadata.chunks[0][1]._id, MaxKey);
+ assert.eq(metadata.shardVersion, result.global);
// Make sure a collection with no metadata still returns the metadata field
- assert(shardAdmin.runCommand({getShardVersion: coll + "xyz", fullMetadata: true}).metadata !=
- undefined);
+ assert.neq(shardAdmin.runCommand({getShardVersion: coll + "xyz", fullMetadata: true}).metadata,
+ undefined);
// Make sure we get multiple chunks after a split and refresh -- splits by themselves do not
// cause the shard to refresh.
diff --git a/jstests/sharding/features1.js b/jstests/sharding/features1.js
index 4f36d5675d6..2fabc5a514b 100644
--- a/jstests/sharding/features1.js
+++ b/jstests/sharding/features1.js
@@ -1,81 +1,63 @@
(function() {
+ 'use strict';
var s = new ShardingTest({name: "features1", shards: 2, mongos: 1});
-
- s.adminCommand({enablesharding: "test"});
+ assert.commandWorked(s.s0.adminCommand({enablesharding: "test"}));
s.ensurePrimaryShard('test', s.shard1.shardName);
// ---- can't shard system namespaces ----
-
- assert(!s.admin.runCommand({shardcollection: "test.system.blah", key: {num: 1}}).ok,
- "shard system namespace");
+ assert.commandFailed(s.s0.adminCommand({shardcollection: "test.system.blah", key: {num: 1}}),
+ "shard system namespace");
// ---- setup test.foo -----
+ assert.commandWorked(s.s0.adminCommand({shardcollection: "test.foo", key: {num: 1}}));
+ let db = s.s0.getDB("test");
- s.adminCommand({shardcollection: "test.foo", key: {num: 1}});
-
- db = s.getDB("test");
-
- a = s._connections[0].getDB("test");
- b = s._connections[1].getDB("test");
+ assert.commandWorked(db.foo.createIndex({y: 1}));
- db.foo.ensureIndex({y: 1});
+ assert.commandWorked(s.s0.adminCommand({split: "test.foo", middle: {num: 10}}));
+ assert.commandWorked(s.s0.adminCommand(
+ {movechunk: "test.foo", find: {num: 20}, to: s.getOther(s.getPrimaryShard("test")).name}));
- s.adminCommand({split: "test.foo", middle: {num: 10}});
- s.adminCommand(
- {movechunk: "test.foo", find: {num: 20}, to: s.getOther(s.getPrimaryShard("test")).name});
+ assert.writeOK(db.foo.insert({num: 5}));
+ assert.writeOK(db.foo.save({num: 15}));
- db.foo.save({num: 5});
- db.foo.save({num: 15});
-
- s.sync();
+ let a = s.rs0.getPrimary().getDB("test");
+ let b = s.rs1.getPrimary().getDB("test");
// ---- make sure shard key index is everywhere ----
-
assert.eq(3, a.foo.getIndexKeys().length, "a index 1");
assert.eq(3, b.foo.getIndexKeys().length, "b index 1");
// ---- make sure if you add an index it goes everywhere ------
-
- db.foo.ensureIndex({x: 1});
-
- s.sync();
-
+ assert.commandWorked(db.foo.createIndex({x: 1}));
assert.eq(4, a.foo.getIndexKeys().length, "a index 2");
assert.eq(4, b.foo.getIndexKeys().length, "b index 2");
- // ---- no unique indexes ------
-
- db.foo.ensureIndex({z: 1}, true);
-
- s.sync();
-
+ // ---- no unique indexes allowed that do not include the shard key ------
+ assert.commandFailed(db.foo.createIndex({z: 1}, true));
assert.eq(4, a.foo.getIndexKeys().length, "a index 3");
assert.eq(4, b.foo.getIndexKeys().length, "b index 3");
- db.foo.ensureIndex({num: 1, bar: 1}, true);
- s.sync();
+ // ---- unique indexes that include the shard key are allowed ------
+ assert.commandWorked(db.foo.createIndex({num: 1, bar: 1}, true));
assert.eq(5, b.foo.getIndexKeys().length, "c index 3");
- // ---- can't shard thing with unique indexes
-
- db.foo2.ensureIndex({a: 1});
- s.sync();
+ // ---- can't shard thing with unique indexes ------
+ assert.commandWorked(db.foo2.createIndex({a: 1}));
printjson(db.foo2.getIndexes());
- assert(s.admin.runCommand({shardcollection: "test.foo2", key: {num: 1}}).ok,
- "shard with index");
+ assert.commandWorked(s.s0.adminCommand({shardcollection: "test.foo2", key: {num: 1}}),
+ "shard with index");
- db.foo3.ensureIndex({a: 1}, true);
- s.sync();
+ assert.commandWorked(db.foo3.createIndex({a: 1}, true));
printjson(db.foo3.getIndexes());
- assert(!s.admin.runCommand({shardcollection: "test.foo3", key: {num: 1}}).ok,
- "shard with unique index");
+ assert.commandFailed(s.s0.adminCommand({shardcollection: "test.foo3", key: {num: 1}}),
+ "shard with unique index");
- db.foo7.ensureIndex({num: 1, a: 1}, true);
- s.sync();
+ assert.commandWorked(db.foo7.createIndex({num: 1, a: 1}, true));
printjson(db.foo7.getIndexes());
- assert(s.admin.runCommand({shardcollection: "test.foo7", key: {num: 1}}).ok,
- "shard with ok unique index");
+ assert.commandWorked(s.s0.adminCommand({shardcollection: "test.foo7", key: {num: 1}}),
+ "shard with ok unique index");
// ----- eval -----
@@ -124,17 +106,16 @@
assert.eq(0, result.ok, "eval should not work for sharded collection in cluster");
// ---- unique shard key ----
+ assert.commandWorked(
+ s.s0.adminCommand({shardcollection: "test.foo4", key: {num: 1}, unique: true}),
+ "shard with index and unique");
+ assert.commandWorked(s.s0.adminCommand({split: "test.foo4", middle: {num: 10}}));
+ assert.commandWorked(s.s0.adminCommand(
+ {movechunk: "test.foo4", find: {num: 20}, to: s.getOther(s.getPrimaryShard("test")).name}));
- assert(s.admin.runCommand({shardcollection: "test.foo4", key: {num: 1}, unique: true}).ok,
- "shard with index and unique");
- s.adminCommand({split: "test.foo4", middle: {num: 10}});
-
- s.admin.runCommand(
- {movechunk: "test.foo4", find: {num: 20}, to: s.getOther(s.getPrimaryShard("test")).name});
+ assert.writeOK(db.foo4.insert({num: 5}));
+ assert.writeOK(db.foo4.insert({num: 15}));
- assert.writeOK(db.foo4.save({num: 5}));
- assert.writeOK(db.foo4.save({num: 15}));
- s.sync();
assert.eq(1, a.foo4.count(), "ua1");
assert.eq(1, b.foo4.count(), "ub1");
@@ -145,16 +126,17 @@
assert(b.foo4.getIndexes()[1].unique, "ub3");
assert.eq(2, db.foo4.count(), "uc1");
- db.foo4.save({num: 7});
+ assert.writeOK(db.foo4.insert({num: 7}));
assert.eq(3, db.foo4.count(), "uc2");
- assert.writeError(db.foo4.save({num: 7}));
+ assert.writeError(db.foo4.insert({num: 7}));
assert.eq(3, db.foo4.count(), "uc4");
// --- don't let you convertToCapped ----
assert(!db.foo4.isCapped(), "ca1");
assert(!a.foo4.isCapped(), "ca2");
assert(!b.foo4.isCapped(), "ca3");
- assert(!db.foo4.convertToCapped(30000).ok, "ca30");
+
+ assert.commandFailed(db.foo4.convertToCapped(30000), "ca30");
assert(!db.foo4.isCapped(), "ca4");
assert(!a.foo4.isCapped(), "ca5");
assert(!b.foo4.isCapped(), "ca6");
@@ -166,11 +148,9 @@
assert(db.foo4a.isCapped(), "ca8");
// --- don't let you shard a capped collection
-
db.createCollection("foo5", {capped: true, size: 30000});
assert(db.foo5.isCapped(), "cb1");
- var res = s.admin.runCommand({shardcollection: "test.foo5", key: {num: 1}});
- assert(!res.ok, "shard capped: " + tojson(res));
+ assert.commandFailed(s.s0.adminCommand({shardcollection: "test.foo5", key: {num: 1}}));
// ----- group ----
@@ -220,21 +200,18 @@
});
// ---- can't shard non-empty collection without index -----
-
- assert.writeOK(db.foo8.save({a: 1}));
- assert(!s.admin.runCommand({shardcollection: "test.foo8", key: {a: 1}}).ok,
- "non-empty collection");
+ assert.writeOK(db.foo8.insert({a: 1}));
+ assert.commandFailed(s.s0.adminCommand({shardcollection: "test.foo8", key: {a: 1}}),
+ "non-empty collection");
// ---- can't shard non-empty collection with null values in shard key ----
-
- assert.writeOK(db.foo9.save({b: 1}));
- db.foo9.ensureIndex({a: 1});
- assert(!s.admin.runCommand({shardcollection: "test.foo9", key: {a: 1}}).ok,
- "entry with null value");
+ assert.writeOK(db.foo9.insert({b: 1}));
+ assert.commandWorked(db.foo9.createIndex({a: 1}));
+ assert.commandFailed(s.s0.adminCommand({shardcollection: "test.foo9", key: {a: 1}}),
+ "entry with null value");
// --- listDatabases ---
-
- r = db.getMongo().getDBs();
+ var r = db.getMongo().getDBs();
assert.eq(3, r.databases.length, tojson(r));
assert.eq("number", typeof(r.totalSize), "listDatabases 3 : " + tojson(r));
@@ -245,5 +222,4 @@
assert.commandWorked(s.s0.adminCommand({flushRouterConfig: 'TestDB.TestColl'}));
s.stop();
-
})();