summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Mulrow <jack.mulrow@mongodb.com>2019-10-21 16:03:14 +0000
committerevergreen <evergreen@mongodb.com>2019-10-21 16:03:14 +0000
commit23ce0082bdb2cac0df95cacf013a5272a5d95942 (patch)
tree2efec7872090bc346c6d2265839f0d8370e5592c
parent6daa36018a6bd26c1353a49fd6cd42fd3aa1add1 (diff)
downloadmongo-23ce0082bdb2cac0df95cacf013a5272a5d95942.tar.gz
SERVER-44113 Refresh metadata for correct namespace in transactions_reject_writes_for_moved_chunks.js hashed case
(cherry picked from commit 713f6dd0dd90a000cb624c8d10ed2dfbdcd15772)
-rw-r--r--jstests/sharding/transactions_reject_writes_for_moved_chunks.js53
1 files changed, 34 insertions, 19 deletions
diff --git a/jstests/sharding/transactions_reject_writes_for_moved_chunks.js b/jstests/sharding/transactions_reject_writes_for_moved_chunks.js
index e6ff51cce97..b5eb4f59cb3 100644
--- a/jstests/sharding/transactions_reject_writes_for_moved_chunks.js
+++ b/jstests/sharding/transactions_reject_writes_for_moved_chunks.js
@@ -19,31 +19,38 @@ function expectChunks(st, ns, chunks) {
}
const dbName = "test";
-const collName = "not_hashed";
-const ns = dbName + '.' + collName;
const st = new ShardingTest({shards: 3, mongos: 1, config: 1});
+//////////////////////////////////////////////////////////////////////////////////////////////////
+//
+// Ranged Sharding Test
+
// Set up one sharded collection with 2 chunks, both on the primary shard.
+const rangedCollName = "not_hashed";
+const rangedNs = dbName + '.' + rangedCollName;
-assert.writeOK(st.s.getDB(dbName)[collName].insert({_id: -3}, {writeConcern: {w: "majority"}}));
-assert.writeOK(st.s.getDB(dbName)[collName].insert({_id: 11}, {writeConcern: {w: "majority"}}));
+assert.commandWorked(
+ st.s.getDB(dbName)[rangedCollName].insert({_id: -3}, {writeConcern: {w: "majority"}}));
+assert.commandWorked(
+ st.s.getDB(dbName)[rangedCollName].insert({_id: 11}, {writeConcern: {w: "majority"}}));
assert.commandWorked(st.s.adminCommand({enableSharding: dbName}));
st.ensurePrimaryShard(dbName, st.shard0.shardName);
-assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: {_id: 1}}));
-assert.commandWorked(st.s.adminCommand({split: ns, middle: {_id: 0}}));
+assert.commandWorked(st.s.adminCommand({shardCollection: rangedNs, key: {_id: 1}}));
+assert.commandWorked(st.s.adminCommand({split: rangedNs, middle: {_id: 0}}));
-expectChunks(st, ns, [2, 0, 0]);
+expectChunks(st, rangedNs, [2, 0, 0]);
// Force a routing table refresh on Shard2, to avoid picking a global read timestamp before the
// sharding metadata cache collections are created.
-assert.commandWorked(st.rs2.getPrimary().adminCommand({_flushRoutingTableCacheUpdates: ns}));
+assert.commandWorked(st.rs2.getPrimary().adminCommand({_flushRoutingTableCacheUpdates: rangedNs}));
-assert.commandWorked(st.s.adminCommand({moveChunk: ns, find: {_id: 11}, to: st.shard1.shardName}));
+assert.commandWorked(
+ st.s.adminCommand({moveChunk: rangedNs, find: {_id: 11}, to: st.shard1.shardName}));
-expectChunks(st, ns, [1, 1, 0]);
+expectChunks(st, rangedNs, [1, 1, 0]);
// The command should target only the second chunk.
let commandTestCases = function(collName) {
@@ -75,13 +82,17 @@ let commandTestCases = function(collName) {
];
};
-function runTest(testCase, collName, moveChunkToFunc, moveChunkBack) {
+function runTest(testCase, ns, collName, moveChunkToFunc, moveChunkBack) {
const testCaseName = testCase.name;
const cmdTargetChunk2 = testCase.command;
jsTestLog("Testing " + testCaseName + ", moveChunkBack: " + moveChunkBack);
- expectChunks(st, ns, [1, 1, 0]);
+ if (ns === rangedNs) {
+ expectChunks(st, ns, [1, 1, 0]);
+ } else { // hashed ns
+ expectChunks(st, ns, [2, 2, 2]);
+ }
const session = st.s.startSession();
const sessionDB = session.getDatabase(dbName);
@@ -160,13 +171,15 @@ function runTest(testCase, collName, moveChunkToFunc, moveChunkBack) {
}
let moveNotHashed = function(toShard) {
- return st.s.adminCommand({moveChunk: ns, find: {_id: 11}, to: toShard});
+ return st.s.adminCommand({moveChunk: rangedNs, find: {_id: 11}, to: toShard});
};
-commandTestCases(collName).forEach(
- testCase => runTest(testCase, collName, moveNotHashed, false /*moveChunkBack*/));
-commandTestCases(collName).forEach(
- testCase => runTest(testCase, collName, moveNotHashed, true /*moveChunkBack*/));
+commandTestCases(rangedCollName)
+ .forEach(testCase => runTest(
+ testCase, rangedNs, rangedCollName, moveNotHashed, false /*moveChunkBack*/));
+commandTestCases(rangedCollName)
+ .forEach(testCase => runTest(
+ testCase, rangedNs, rangedCollName, moveNotHashed, true /*moveChunkBack*/));
//////////////////////////////////////////////////////////////////////////////////////////////////
//
@@ -198,9 +211,11 @@ let moveHashed = function(toShard) {
};
commandTestCases(hashedCollName)
- .forEach(testCase => runTest(testCase, hashedCollName, moveHashed, false /*moveChunkBack*/));
+ .forEach(testCase =>
+ runTest(testCase, hashedNs, hashedCollName, moveHashed, false /*moveChunkBack*/));
commandTestCases(hashedCollName)
- .forEach(testCase => runTest(testCase, hashedCollName, moveHashed, true /*moveChunkBack*/));
+ .forEach(testCase =>
+ runTest(testCase, hashedNs, hashedCollName, moveHashed, true /*moveChunkBack*/));
st.stop();
})();