[SERVER-81293] Get rid of `ensurePrimaryShard` helper Created: 21/Sep/23  Updated: 29/Oct/23  Resolved: 28/Sep/23

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

Type: Task Priority: Major - P3
Reporter: Pierlauro Sciarelli Assignee: Pierlauro Sciarelli
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-81461 Change tests that uses movePrimary to... In Code Review
Problem/Incident
Backwards Compatibility: Fully Compatible
Sprint: Sharding EMEA 2023-10-02
Participants:
Linked BF Score: 160

 Description   

The ensurePrimaryShard helper function is currently used to create a database on a specific primary shard (if not existing) or changing a db's primary shard (if existing).

Inspecting a sample of tests invoking it, it turns out that this function is used in the following ways:

  • 83% of current usages: calling enableSharding + ensurePrimaryShard to simply create the db on a primary shard. This is technically equivalent to calling enableSharding (creating an empty database on a random primary shard) + movePrimary (in this case, moving an empty database).
    • This can be avoided by just calling enableSharding with the primaryShard argument.
  • 10% of current usages: calling ensurePrimaryShard to create a db on a specific primary shard.
    • Also this can be avoided by just calling enableSharding with the primaryShard argument.
  • 7% of current usages: used to actually change the primary shard of a non-empty database.
    • This can be avoided by directly calling movePrimary.

Purpose of this ticket is to get rid of ensurePrimaryShard for the following reasons:

  • Bring to an end the unnecessary pattern of creating an empty database and then moving it.
  • Mark all the points in the code that really need movePrimary.

This is a precondition to deprecate the movePrimary command once moveCollection will be available, so there will not be too many tests to adapt in the future.



 Comments   
Comment by Githook User [ 28/Sep/23 ]

Author:

{'name': 'Pierlauro Sciarelli', 'email': 'pierlauro.sciarelli@mongodb.com', 'username': 'pierlauro'}

Message: SERVER-81293 remove unnecessary enableSharding from shard_keycount.js
Branch: master
https://github.com/mongodb/mongo/commit/b6a5ab8a989dc2846c8b00322c92d91da7aa9f15

Comment by Githook User [ 28/Sep/23 ]

Author:

{'name': 'Pierlauro Sciarelli', 'email': 'pierlauro.sciarelli@mongodb.com', 'username': 'pierlauro'}

Message: SERVER-81293 Get rid of `ensurePrimaryShard` helper
Branch: master
https://github.com/mongodb/mongo/commit/ce28e79ede00c7f837cf3a9bfbe8e7ee1958ed26

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