Skip to content

Commit cc7a70f

Browse files
DOCSP-29669 resharding improvements (#5120) (#5544)
* DOCSP-29669 reshard improvements * Fixes per Ashley * Empty change to force rebuild * Empty change to force rebuild * Fixes per Ashley * Fixes per Ashley * Fixes spacing * Fixes per Ashley * Fixes per Matt * Fixes per Matt * Fixes per Matt * Fixes per Matt * Removes stray duplicate interlink * Fixes per Matt * Fixes per Matt * Fixes per Matt * Fixes per Matt * Fixes per Matt * Fixes per Ratika * Fixes per Ratika * Fixes per Matt --------- Co-authored-by: Ashley Brown <[email protected]>
1 parent a7987a6 commit cc7a70f

File tree

4 files changed

+109
-8
lines changed

4 files changed

+109
-8
lines changed

source/core/sharding-balancer-administration.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ shard immediately, it can take some time before the cluster balances.
9797
See the :ref:`Add Shards to a Cluster <sharding-procedure-add-shard>`
9898
tutorial for instructions on adding a shard to a cluster.
9999

100+
.. tip::
101+
102+
If your application meets the :ref:`reshard-requirements`, you can use the
103+
:dbcommand:`reshardCollection` command to redistribute data across the
104+
cluster to include the new shards. This process is much faster than the
105+
alternative :ref:`range-migration-procedure`.
106+
107+
For an example, see :ref:`reshardCollection-redistribute-data`.
108+
100109
Removing a shard from a cluster creates a similar imbalance, since data
101110
residing on that shard must be redistributed throughout the cluster.
102111
While MongoDB begins draining a removed shard immediately, it can take

source/core/sharding-reshard-a-collection.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ Reshard a Collection
1717
The ideal shard key allows MongoDB to distribute documents evenly
1818
throughout the cluster while facilitating common query patterns. A
1919
suboptimal shard key can lead to performance or scaling issues due to
20-
uneven data distribution. Starting in MongoDB 5.0, you can change the
21-
shard key for a collection to change the distribution of your data
22-
across a cluster.
20+
uneven data distribution.
21+
22+
Starting in MongoDB 5.0, you can change the shard key for a collection to
23+
change the distribution of your data across a cluster.
24+
25+
Starting in MongoDB 7.2, you can reshard a collection on the same shard key,
26+
allowing you to redistribute data to include new shards or to different zones
27+
without changing your shard key.
2328

2429
.. note::
2530

source/reference/command/reshardCollection.txt

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The command has the following syntax:
3131

3232
.. code-block:: javascript
3333

34-
db.runCommand(
34+
db.adminCommand(
3535
{
3636
reshardCollection: "<database>.<collection>",
3737
key: <shardkey>,
@@ -45,7 +45,8 @@ The command has the following syntax:
4545
zone: <string> | null
4646
},
4747
...
48-
]
48+
],
49+
forceDistribution: <bool>
4950
}
5051
)
5152

@@ -109,9 +110,15 @@ The command takes the following fields:
109110
- array
110111
- Optional. To maintain or add :ref:`zones <zone-sharding>`,
111112
specify the zones for your collection in an array.
112-
113-
The :binary:`~bin.mongosh` provides a wrapper method
114-
:method:`sh.reshardCollection()`.
113+
114+
* - ``forceRedistribution``
115+
- boolean
116+
- Optional. When set to ``true``, the operation executes even if the new
117+
shard key is the same as the old shard key. Use with the
118+
``zones`` option to move data to specific zones.
119+
120+
.. versionadded:: 7.2
121+
115122

116123
Resharding Process
117124
------------------
@@ -217,3 +224,54 @@ MongoDB returns the following:
217224
.. seealso::
218225

219226
:ref:`sharding-resharding`
227+
228+
.. _reshardCollection-redistribute-data:
229+
230+
Redistribute Data to New Shards
231+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
232+
233+
Starting in MongoDB 7.2, you can reshard a collection on the same key,
234+
which can be used to redistribute data onto new shards.
235+
236+
After adding a shard to the cluster, you use the ``reshardCollection`` command
237+
with the ``forceRedistribution`` option to redistribute data across the
238+
cluster:
239+
240+
.. code-block:: javascript
241+
242+
db.adminCommand({
243+
reshardCollection: "accounts.invoices",
244+
key: { store_id: "hashed" },
245+
forceRedistribution: true
246+
})
247+
248+
249+
Redistribute Data to Different Zones
250+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
251+
252+
Starting in MongoDB 7.2, you can use the ``reshardCollection`` command to
253+
move data into new zones without changing the shard key.
254+
255+
The following command redistributes data for the ``accounts.sales`` collection
256+
using the same shard key, moving data from zones ``zone01`` and ``zone02`` to
257+
``zone03`` and ``zone04``:
258+
259+
.. code-block:: javascript
260+
261+
db.adminCommand({
262+
reshardCollection: "accounts.sales",
263+
key: { region_id: "hashed" },
264+
forceRedistribution: true,
265+
zones: [
266+
{
267+
zone: "zone04",
268+
min: { region_id: MinKey() },
269+
max: { region_id: 10 }
270+
},
271+
{
272+
zone: "zone05",
273+
min: { region_id: 10 },
274+
max: { region_id: MaxKey() }
275+
}
276+
]
277+
})

source/release-notes/7.2.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,37 @@ Starting in MongoDB 7.2, when you :ref:`shard an empty collection
5858
creates one chunk per shard by default. Previously, the operation
5959
created two chunks by default.
6060

61+
Resharding Improvements
62+
-----------------------
63+
64+
MongoDB 7.2 introduces significant performance improvements in reshard
65+
collection operations, substantially reducing the amount of time the
66+
operation takes to run.
67+
68+
Additionally, if your application and cluster meet the necessary
69+
:ref:`requirements <reshard-requirements>` and :ref:`limitations
70+
<resharding-limitations>`, you can reshard the collection on the same key using
71+
the :dbcommand:`reshardCollection` command to redistribute your collection,
72+
which is much faster than alternative :ref:`range migration procedure
73+
<range-migration-procedure>`.
74+
75+
The following options are added to the command:
76+
77+
.. list-table::
78+
:header-rows: 1
79+
80+
* - Field
81+
- Description
82+
83+
* - ``forceRedistribution``
84+
- Enables same-key resharding.
85+
86+
For examples, see :ref:`reshardCollection-redistribute-data`.
87+
6188
.. toctree::
6289
:titlesonly:
6390
:hidden:
6491

6592
/release-notes/7.2-compatibility
93+
94+

0 commit comments

Comments
 (0)