[SERVER-5387] moveChunk find:{$minKey:1} matches incorrect chunk Created: 23/Mar/12  Updated: 06/Dec/22  Resolved: 31/Jan/17

Status: Closed
Project: Core Server
Component/s: Sharding, Shell
Affects Version/s: 2.0.3
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Y. Wayne Huang Assignee: [DO NOT USE] Backlog - Sharding Team
Resolution: Done Votes: 0
Labels: sharding
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Assigned Teams:
Sharding
Operating System: ALL
Participants:

 Description   

we have a sharded collection "x", with chunks:

{ "shard_id" : { $minKey : 1 } } -->> { "shard_id" : "0" } on : shard1 { "t" : 5000, "i" : 1 }
{ "shard_id" : "0" } -->> { "shard_id" : "d" } on : shard2 { "t" : 8000, "i" : 0 }
{ "shard_id" : "d" } -->> { "shard_id" : "k" } on : shard3 { "t" : 8000, "i" : 1 }
{ "shard_id" : "k" } -->> { "shard_id" : "z" } on : shard3 { "t" : 2000, "i" : 0 }
{ "shard_id" : "z" } -->> { "shard_id" : { $maxKey : 1 } } on : shard4 { "t" : 7000, "i" : 0 }

from mongos:

mongos> use admin;
mongos> db.runCommand({"moveChunk":"mydb.x","find":{"email":{"$minKey":1}},"to":"shard4"});
{ "ok" : 0, "errmsg" : "that chunk is already on that shard" }
mongos> db.runCommand({"moveChunk":"mydb.x","find":{"email":{"$lt":"0"}},"to":"shard4"});
{ "ok" : 0, "errmsg" : "that chunk is already on that shard" }

is it incorrectly "finding" the last chunk?



 Comments   
Comment by Y. Wayne Huang [ 05/Apr/12 ]

seems reasonable to me. obviously not a huge issue w/ a known workaround but it would be great to get this scheduled some time or see some sort of movement toward getting it fixed.

Comment by Antoine Girbal [ 28/Mar/12 ]

The general rule is that special objects get printed out as their own type.
It makes it non-JSON but it let's one copy paste without switching type, and less likely to mix up types in general.
We've seen several instance of ppl switching Timestamps to simple objects, etc..

For example the following are now printing correctly in 2.1:

mongos> doc = {a: ObjectId()}
{ "a" : ObjectId("4f72abc44bf1939beb844641") }
mongos> doc = {a: Timestamp()}
{ "a" : Timestamp(0, 0) }

So here it makes sense to fix to:

mongos> doc = {a: MinKey()}
{ "a" : MinKey() }

Comment by Y. Wayne Huang [ 26/Mar/12 ]

Hi Scott - thanks, using the constant worked although I would guess that most users' first inclination would be to use

{"$minKey":1}

because it's what is returned in db.printShardingStatus().

Comment by Scott Hernandez (Inactive) [ 26/Mar/12 ]

You want to the use the Min/MaxKey constant.

> MinKey
{ $minKey : 1 }
> MaxKey
{ $maxKey : 1 }

You do not want to use "

{ $maxKey : 1 }

" which is just a document, not a special thing like you want.

Also, '"email":

{"$lt":"0"}

' will find the lowest numeric value, not the lowest possible value which is why you want to use MinKey. http://www.mongodb.org/display/DOCS/What+is+the+Compare+Order+for+BSON+Types

Comment by Eliot Horowitz (Inactive) [ 26/Mar/12 ]

This is a display/parsing issue in the shell.
I don't think

{ $minKey : 1}

round trips right now.

Generated at Thu Feb 08 03:08:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.