Skip to content

Commit 42db732

Browse files
authored
backport to v6.0 (#6277)
1 parent 4d1f6fc commit 42db732

File tree

8 files changed

+140
-24
lines changed

8 files changed

+140
-24
lines changed

source/administration/sharded-cluster-administration.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Sharded Cluster Administration
2828
/tutorial/backup-sharded-cluster-metadata
2929
/tutorial/convert-sharded-cluster-to-replica-set
3030
/tutorial/convert-replica-set-to-replicated-shard-cluster
31+
/tutorial/drop-a-hashed-shard-key-index
3132

3233
:doc:`Config Server Administration </administration/sharded-cluster-config-servers>`
3334
This section contains articles and tutorials related to sharded
@@ -67,3 +68,6 @@ Sharded Cluster Administration
6768
Convert a replica set to a sharded cluster in which each shard is
6869
its own replica set.
6970

71+
:doc:`/tutorial/drop-a-hashed-shard-key-index`
72+
Drop a Hashed Shard Key Index.
73+

source/core/hashed-sharding.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ Sharding Empty Collection on Compound Hashed Shard Key with Non-Hashed Prefix
249249
:ref:`pre-define-zone-range-hashed-example`.
250250

251251

252+
Drop a Hashed Shard Key Index
253+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
254+
255+
.. include:: /includes/drop-hashed-shard-key-index.rst
252256

253257

254258
.. seealso::
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Starting in MongoDB 7.0.3 (and 6.0.12 and 5.0.22), you can drop the
2+
index for a hashed shard key.
3+
4+
This can speed up data insertion for collections sharded with a hashed
5+
shard key. It can also speed up data ingestion when using
6+
``mongosync``.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.. include:: /includes/drop-hashed-shard-key-index-main.rst
2+
3+
For details, see :ref:`drop-a-hashed-shard-key-index`.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.. code-block:: json
2+
3+
[
4+
{
5+
"ns": "test.names",
6+
"shards": [
7+
{
8+
"shardName": "shard-1",
9+
"numOrphanedDocs": 0,
10+
"numOwnedDocuments": 6,
11+
"ownedSizeBytes": 366,
12+
"orphanedSizeBytes": 0
13+
},
14+
{
15+
"shardName": "shard-2",
16+
"numOrphanedDocs": 0,
17+
"numOwnedDocuments": 6,
18+
"ownedSizeBytes": 366,
19+
"orphanedSizeBytes": 0
20+
}
21+
]
22+
}
23+
]
24+

source/reference/operator/aggregation/shardedDataDistribution.txt

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,4 @@ Examples
5959

6060
Example output:
6161

62-
.. code-block:: json
63-
64-
[
65-
{
66-
"ns": "test.names",
67-
"shards": [
68-
{
69-
"shardName": "shard-1",
70-
"numOrphanedDocs": 0,
71-
"numOwnedDocuments": 6,
72-
"ownedSizeBytes": 366,
73-
"orphanedSizeBytes": 0
74-
},
75-
{
76-
"shardName": "shard-2",
77-
"numOrphanedDocs": 0,
78-
"numOwnedDocuments": 6,
79-
"ownedSizeBytes": 366,
80-
"orphanedSizeBytes": 0
81-
}
82-
]
83-
}
84-
]
85-
62+
.. include:: /includes/shardedDataDistribution-output-example.rst

source/release-notes/6.0.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,11 @@ performance. For more information and an example, see
10011001
General Improvements
10021002
--------------------
10031003

1004+
Drop a Hashed Shard Key Index
1005+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1006+
1007+
.. include:: /includes/drop-hashed-shard-key-index.rst
1008+
10041009
OpenSSL3 FIPS Support
10051010
~~~~~~~~~~~~~~~~~~~~~
10061011

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
.. _drop-a-hashed-shard-key-index:
2+
3+
=============================
4+
Drop a Hashed Shard Key Index
5+
=============================
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
.. include:: /includes/drop-hashed-shard-key-index-main.rst
16+
17+
About this Task
18+
---------------
19+
20+
Dropping an `unnecessary index
21+
<http://www.mongodb.com/developer/products/mongodb/schema-design-anti-pattern-unnecessary-indexes/>`_
22+
can speed up CRUD operations. Each CRUD operation has to update all the
23+
indexes related to a document. Removing one index can increase the
24+
speed of all CRUD operations.
25+
26+
When you drop a hashed shard key index, the server disables balancing
27+
for that collection and excludes the collection from future balancing
28+
rounds. In order to include the collection in balancing rounds once
29+
again, you must recreate the shard key index.
30+
31+
Steps
32+
-----
33+
34+
.. procedure::
35+
:style: normal
36+
37+
.. step:: Stop the balancer
38+
39+
Run the following command to stop the balancer:
40+
41+
.. code-block:: javascript
42+
43+
sh.stopBalancer()
44+
45+
You can only run ``sh.stopBalancer()`` on ``mongos``.
46+
``sh.stopBalancer()`` produces an error if run on ``mongod``.
47+
48+
.. step:: Confirm there are no orphaned documents in your collection
49+
50+
Starting in MongoDB 6.0.3, you can run an aggregation using the
51+
:pipeline:`$shardedDataDistribution` stage to confirm no orphaned
52+
documents remain:
53+
54+
.. code-block:: javascript
55+
56+
db.aggregate([
57+
{ $shardedDataDistribution: {} },
58+
{ $match: { "ns": "<database>.<collection>" } }
59+
])
60+
61+
``$shardedDataDistribution`` has output similar to the following:
62+
63+
.. include:: /includes/shardedDataDistribution-output-example.rst
64+
65+
Ensure that ``"numOrphanedDocs"`` is ``0`` for each shard in the
66+
cluster.
67+
68+
.. step:: Drop the hashed shard key index
69+
70+
Run the following command to drop the index:
71+
72+
.. code-block:: javascript
73+
74+
db.collection.dropIndex("<index name>")
75+
76+
.. step:: Restart the balancer
77+
78+
Run the following command to restart the balancer on the cluster:
79+
80+
.. code-block:: javascript
81+
82+
sh.startBalancer()
83+
84+
85+
Learn More
86+
----------
87+
88+
- :ref:`sharding-hashed`
89+
- :ref:`sharding-balancing`
90+
- :method:`db.collection.dropIndex()`
91+
- :method:`sh.stopBalancer()`
92+
- :method:`sh.startBalancer()`
93+
- :method:`sh.getBalancerState()`

0 commit comments

Comments
 (0)