(This issue may be related to SERVER-10987)
Normally it's not possible to create a key which includes a $ symbol but the following somewhat bizarre (and admittedly contrived) command is accepted and generates really odd chunks:
sh.updateZoneKeyRange("foo.bar", { "key": { "$maxKey": 1 } }, { "key": { "$minKey": 1 } }, "zone")
What was meant of course was the following:
sh.updateZoneKeyRange("foo.bar", { "key": MaxKey }, { "key": MinKey }, "zone")
This second form fails as expected as MaxKey is greater than MinKey, but the first form matches more closely how chunks referencing MinKey and MaxKey are shown in, for example, the output of sh.status()
Running the commands in the 'steps to reproduce' section results in the following 3 chunks being created:
mongos> db.chunks.find({},{_id:0,lastmod:0,lastmodEpoch:0}) { "ns" : "foo.bar", "min" : { "key" : { "$minKey" : 1 } }, "max" : { "key" : { "$maxKey" : 1 } }, "shard" : "shard01" } { "ns" : "foo.bar", "min" : { "key" : { "$maxKey" : 1 } }, "max" : { "key" : { "$minKey" : 1 } }, "shard" : "shard01" } { "ns" : "foo.bar", "min" : { "key" : { "$minKey" : 1 } }, "max" : { "key" : { "$maxKey" : 1 } }, "shard" : "shard01" }
And the output of sh.status() is as follows:
[...] databases: { "_id" : "foo", "primary" : "shard01", "partitioned" : true } foo.bar shard key: { "key" : 1 } unique: false balancing: true chunks: shard01 3 { "key" : { "$minKey" : 1 } } -->> { "key" : { "$maxKey" : 1 } } on : shard01 Timestamp(1, 1) { "key" : { "$maxKey" : 1 } } -->> { "key" : { "$minKey" : 1 } } on : shard01 Timestamp(1, 2) { "key" : { "$minKey" : 1 } } -->> { "key" : { "$maxKey" : 1 } } on : shard01 Timestamp(1, 3) tag: zone { "key" : { "$maxKey" : 1 } } -->> { "key" : { "$minKey" : 1 } }
I have no idea how the balancer will react if it sees these chunk ranges...
Another interesting aspect is the following:
mongos> sh.updateZoneKeyRange("foo.bar", { "key": { "$minKey": 1 } }, { "key": { "$maxKey": 1 } }, "zone") { "code" : 9, "ok" : 0, "errmsg" : "min: { key: { $minKey: 1.0 } } should be less than max: { key: { $maxKey: 1.0 } }" }
In this case we're trying to set the range to MinKey -->> MaxKey but the validator rejects it (presumably because the min and max values are documents which are being compared in a binary manner and $minKey is alphabetically greater than $maxKey??)
All of the above tested on MongoDB 3.4.9
- related to
-
SERVER-19171 Shell does not always use extended JSON Shell Syntax
- Closed
-
SERVER-66584 sh.updateZoneKeyRange() does not support $minKey or $maxKey
- Closed
-
SERVER-34644 Disable `DollarPrefixedFieldName` checks for moveChunk/mergeChunks
- Closed