[SERVER-13657] split with find doesn't work if chunk has only 1 document Created: 18/Apr/14  Updated: 20/Jan/20  Resolved: 20/Jan/20

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

Type: Bug Priority: Major - P3
Reporter: Randolph Tan Assignee: Marcos José Grillo Ramirez
Resolution: Won't Fix Votes: 0
Labels: ShardingRoughEdges, neweng, sharding-wfbf-day
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Sprint: Sharding 2019-12-30, Sharding 2020-01-13, Sharding 2020-01-27
Participants:

 Description   

db.adminCommand({ enableSharding: 'test' });
db.adminCommand({ shardCollection: 'test.user', key: { x: 1 }});
db.adminCommand({ split: 'test.user', middle: { x: 0 }})
db.adminCommand({ split: 'test.user', middle: { x: 100 }})
db.user.insert({ x: 1 })
db.adminCommand({ split: 'test.user', find: { x: 1 }})

returns:

{ "cause" : { }, "ok" : 0, "errmsg" : "split failed" }

Note: if the collection was not presplit, the split command will run fine because of special case handling on chunks with MinKey or MaxKey as boundaries.



 Comments   
Comment by Marcos José Grillo Ramirez [ 20/Jan/20 ]

According to the documentation of split with find, it tries to find a median point for the intersecting chunk (which is similar to how the auto splitter works).

With only 1 shard key element there is no way to calculate the median of the chunk, this is reported on the shard logs:

d35993| 2020-01-20T17:05:47.231+0100 W  SHARDING [conn20] possible low cardinality key detected in test.user - range { : 0.0 } -->> { : 100.0 } contains only the key { x: 1.0 }

And also on the router:

s35995| 2020-01-20T17:05:47.241+0100 I  COMMAND  [conn6] command test.user appName: "MongoDB Shell" command: split { split: "test.user", find: { x: 1.0 }, lsid: { id: UUID("3b658803-7baf-4438-a103-23c828711b2b") }, $clusterTime: { clusterTime: Timestamp(1579536337, 1), signature: { hash: BinData(0, 0000000000000000000000000000000000000000), keyId: 0 } }, $db: "admin" } numYields:0 ok:0 errMsg:"Unable to find median in chunk, possibly because chunk is empty."

Closing this ticket as won't fix because it is not possible to calculate the median with only one shard key on the chunk range. In case a specific split is needed, splitAt should be used.

Comment by Randolph Tan [ 18/Apr/14 ]

I suspect this is the culprit:

https://github.com/mongodb/mongo/blob/r2.6.0/src/mongo/s/d_split.cpp#L459-460

                // Remove the sentinel at the beginning before returning
                splitKeys.erase( splitKeys.begin() );

this is because the sentinel is actually the first key and if the chunk has only 1 document then it will be the same as the sentinel.

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