summaryrefslogtreecommitdiff
path: root/jstests/sharding/libs
diff options
context:
space:
mode:
authorCheahuychou Mao <cheahuychou.mao@mongodb.com>2019-12-18 04:05:28 +0000
committerevergreen <evergreen@mongodb.com>2019-12-18 04:05:28 +0000
commitb93d957a0fb564a8b4d30f6a571f608c6a310bfb (patch)
tree4540836ad98106c423399212250fc52d762133ae /jstests/sharding/libs
parent1b75fcdcaf9c320ef8b916204d1eb51c4bab8a5f (diff)
downloadmongo-b93d957a0fb564a8b4d30f6a571f608c6a310bfb.tar.gz
SERVER-45102 Sharded listIndexes should always target a shard that owns chunks
Diffstat (limited to 'jstests/sharding/libs')
-rw-r--r--jstests/sharding/libs/shard_versioning_util.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/jstests/sharding/libs/shard_versioning_util.js b/jstests/sharding/libs/shard_versioning_util.js
new file mode 100644
index 00000000000..3848fd2d57f
--- /dev/null
+++ b/jstests/sharding/libs/shard_versioning_util.js
@@ -0,0 +1,59 @@
+/*
+ * Utilities for shard versioning testing.
+ */
+let ShardVersioningUtil = (function() {
+ /*
+ * Returns the metadata for the collection in the shard's catalog cache.
+ */
+ let getMetadataOnShard = function(shard, ns) {
+ let res = shard.adminCommand({getShardVersion: ns, fullMetadata: true});
+ assert.commandWorked(res);
+ return res.metadata;
+ };
+
+ /*
+ * Asserts that the collection version for the collection in the shard's catalog cache
+ * is equal to the given collection version.
+ */
+ let assertCollectionVersionEquals = function(shard, ns, collectionVersion) {
+ assert.eq(getMetadataOnShard(shard, ns).collVersion, collectionVersion);
+ };
+
+ /*
+ * Asserts that the collection version for the collection in the shard's catalog cache
+ * is older than the given collection version.
+ */
+ let assertCollectionVersionOlderThan = function(shard, ns, collectionVersion) {
+ let shardCollectionVersion = getMetadataOnShard(shard, ns).collVersion;
+ if (shardCollectionVersion != undefined) {
+ assert.lt(shardCollectionVersion.t, collectionVersion.t);
+ }
+ };
+
+ /*
+ * Asserts that the shard version of the shard in its catalog cache is equal to the
+ * given shard version.
+ */
+ let assertShardVersionEquals = function(shard, ns, shardVersion) {
+ assert.eq(getMetadataOnShard(shard, ns).shardVersion, shardVersion);
+ };
+
+ /*
+ * Moves the chunk that matches the given query to toShard. Forces fromShard to skip the
+ * recipient metadata refresh post-migration commit.
+ */
+ let moveChunkNotRefreshRecipient = function(mongos, ns, fromShard, toShard, findQuery) {
+ let failPoint = configureFailPoint(fromShard, "doNotRefreshRecipientAfterCommit");
+ assert.commandWorked(mongos.adminCommand(
+ {moveChunk: ns, find: findQuery, to: toShard.shardName, _waitForDelete: true}));
+ failPoint.off();
+ };
+
+ return {
+ getMetadataOnShard,
+ assertCollectionVersionEquals,
+ assertCollectionVersionOlderThan,
+ assertShardVersionEquals,
+ moveChunkNotRefreshRecipient
+ };
+})();