Skip to content

Commit 82c73ff

Browse files
authored
DOCSP-33843 v6.0 backport (#6274)
* starting in 6.0.3 * backport to v6.0
1 parent 6d5abdd commit 82c73ff

File tree

8 files changed

+141
-24
lines changed

8 files changed

+141
-24
lines changed

source/administration/sharded-cluster-administration.txt

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

2930
:doc:`Config Server Administration </administration/sharded-cluster-config-servers>`
3031
This section contains articles and tutorials related to sharded
@@ -61,3 +62,6 @@ Sharded Cluster Administration
6162
Convert a replica set to a sharded cluster in which each shard is
6263
its own replica set.
6364

65+
:doc:`/tutorial/drop-a-hashed-shard-key-index`
66+
Drop a Hashed Shard Key Index.
67+

source/core/hashed-sharding.txt

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

247247

248+
Drop a Hashed Shard Key Index
249+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
250+
251+
.. include:: /includes/drop-hashed-shard-key-index.rst
248252

249253

250254
.. seealso::
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Starting in MongoDB 6.0.12 (and 5.0.22), you can drop the index for a
2+
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
@@ -1029,6 +1029,11 @@ performance. For more information and an example, see
10291029
General Improvements
10301030
--------------------
10311031

1032+
Drop a Hashed Shard Key Index
1033+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1034+
1035+
.. include:: /includes/drop-hashed-shard-key-index.rst
1036+
10321037
OpenSSL3 FIPS Support
10331038
~~~~~~~~~~~~~~~~~~~~~
10341039

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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()`
94+

0 commit comments

Comments
 (0)