[SERVER-39180] Wrong initial chunk owner shard can be selected when sharding non-empty collection with pre-created zones Created: 24/Jan/19  Updated: 29/Oct/23  Resolved: 25/Jan/19

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 4.0.5
Fix Version/s: 4.0.6, 4.1.8

Type: Bug Priority: Critical - P2
Reporter: Kaloian Manassiev Assignee: Kaloian Manassiev
Resolution: Fixed Votes: 0
Labels: SWNA
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Related
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.0
Sprint: Sharding 2019-01-28, Sharding 2019-02-11
Participants:

 Description   
Issue Status as of Jan 30, 2019

ISSUE DESCRIPTION AND IMPACT
If a user specifies zones for a non-empty collection prior to sharding it, there is a chance that the initial chunk will be placed onto an incorrect shard, thus effectively losing all the documents in the sharded collection. This will occur if there is more than one shard (e.g. shard01, shard02) and the database's primary is not the first alphabetically-sorted shard (e.g. shard02 in the example above).

DIAGNOSIS AND AFFECTED VERSIONS
Only MongoDB 4.0.5 is affected. Prior to MongoDB 4.0.5, it was not possible to shard a non-empty collection with zones preset.

REMEDIATION AND WORKAROUNDS
Users running MongoDB 4.0.5 are strongly encouraged to upgrade to 4.0.6 or later immediately. If an immediate upgrade is not possible, users should ensure that no zones are set for a non-empty collection before sharding it. After sharding a non-empty collection, the zones can be safely set.

FIXED VERSIONS
The fix is included in MongoDB 4.0.6.

Original description

When sharding a non-empty collection, whose primary is not the first alphabetically-sorted shard, the Fast Initial Split logic can select wrong shard for the lone initial chunk.

These are the conditions for this issue to occur:

  • There is more than one shard (e.g., shard01, shard02)
  • The database's primary is not the first alphabetically-sorted shard (shard02 in the example above)
  • There are some zones defined for the collection (so the Fast Initial Split optimization is attempted)
  • The unsharded collection contains some documents (so that the Fast Initial Split optimization won't kick-in)

In this case, attempting to shard such a collection will wrongly place the only chunk on the first alphabetically-sorted shard, which means none of the documents for that collection will be visible anymore.



 Comments   
Comment by Githook User [ 25/Jan/19 ]

Author:

{'username': 'kaloianm', 'email': 'kaloian.manassiev@mongodb.com', 'name': 'Kaloian Manassiev'}

Message: SERVER-39180 Don't distribute chunks on `shardCollection` if the collection is not empty

(cherry picked from commit ec3a2060a3fbdd8808a39533b25e6b270ea95b28)
Branch: v4.0
https://github.com/mongodb/mongo/commit/88216373b7f1ba0ee16db972b81010efeee3022a

Comment by Kaloian Manassiev [ 25/Jan/19 ]

Author:

{'email': 'kaloian.manassiev@mongodb.com', 'name': 'Kaloian Manassiev', 'username': 'kaloianm'}

Message: SERVER-39180 Don't distribute chunks on `shardCollection` if the collection is not empty
Branch: master
https://github.com/mongodb/mongo/commit/ec3a2060a3fbdd8808a39533b25e6b270ea95b28

Generated at Thu Feb 08 04:51:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.