Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-81293

Get rid of `ensurePrimaryShard` helper

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.2.0-rc0
    • Affects Version/s: None
    • Component/s: Sharding
    • Labels:
      None
    • Fully Compatible
    • Sharding EMEA 2023-10-02
    • 160

      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.

            Assignee:
            pierlauro.sciarelli@mongodb.com Pierlauro Sciarelli
            Reporter:
            pierlauro.sciarelli@mongodb.com Pierlauro Sciarelli
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: