Skip to content

Commit fddf273

Browse files
DOCSP-26021 sharding metadata consistency (#3114)
* Fixes per Ali * DOCSP-26021 Adds checkMetadataConsistency command * Adds example * Fixes build issue * Fixes links * Documents batching checkMetadataConsistency * Documents checkIndexes option * Fixes example * Fixes table * Fixes per Ian * Fixes per Ian * Fixes example issue * Fixes per Ian * Fix build issue * Fixes build issue * Fixes per Tocci * Fixes per Tocci * Fixes per Tocci * Fixes per Tocci * Fixes per Tocci * Fixes build issues * Fixes per Sarah Co-authored-by: Sarah Olson <[email protected]> * Fixes per Sarah --------- Co-authored-by: Sarah Olson <[email protected]>
1 parent 1850690 commit fddf273

File tree

5 files changed

+237
-1
lines changed

5 files changed

+237
-1
lines changed

source/core/sharded-cluster-requirements.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,25 @@ Unique Indexes in Sharded Collections
5656

5757
.. include:: /includes/limits-sharding-unique-indexes.rst
5858

59+
Consistent Indexes
60+
~~~~~~~~~~~~~~~~~~
61+
62+
MongoDB does not guarantee consistent indexes across shards. Index creation
63+
during :dbcommand:`addShard` operations or chunk migrations may not propagate
64+
to new shards.
65+
66+
To check a sharded cluster for consistent indexes, use the
67+
:dbcommand:`checkMetadataConsistency` command:
68+
69+
70+
.. code-block:: javascript
71+
72+
db.runCommand( {
73+
checkMetadataConsistency: 1,
74+
checkIndexes: true
75+
} )
76+
77+
5978
Sharding Existing Collection Data Size
6079
--------------------------------------
6180

source/reference/command.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,12 @@ Sharding Commands
447447

448448
- Stops the balancer thread.
449449

450+
* - :dbcommand:`checkMetadataConsistency`
451+
452+
- Performs a series of consistency checks on sharding metadata.
453+
454+
.. versionadded:: 7.0
455+
450456
* - :dbcommand:`checkShardingIndex`
451457

452458
- Internal command that validates index on shard key.
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
========================
2+
checkMetadataConsistency
3+
========================
4+
5+
.. contents:: On this page
6+
:local:
7+
:backlinks: none
8+
:depth: 2
9+
:class: singlecol
10+
11+
12+
Definition
13+
----------
14+
15+
.. dbcommand:: checkMetadataConsistency
16+
17+
Performs a series of consistency checks on sharding metadata for a cluster,
18+
database, or collection. The command returns a cursor with either all or a
19+
batch of the inconsistency results found.
20+
21+
Run this command after major maintenance operations, such as upgrades and
22+
downgrades, to check the state of the catalog.
23+
24+
By default, the command does not check indexes for consistency across
25+
the shards. To check indexes, set the ``checkIndexes`` option.
26+
27+
.. versionadded:: 7.0
28+
29+
Syntax
30+
------
31+
32+
- To check the entire cluster for sharding metadata inconsistencies, run
33+
the command from the ``admin`` database.
34+
35+
.. code-block:: javascript
36+
37+
db.getSiblingDB("admin").runCommand( {
38+
checkMetadataConsistency: 1
39+
} )
40+
41+
- To check the database for sharding metadata inconsistencies, run the command
42+
from the database context:
43+
44+
.. code-block:: javascript
45+
46+
use cars
47+
db.runCommand( {
48+
checkMetadataConsistency: 1
49+
} )
50+
51+
- To check a collection for sharding metadata inconsistencies, run the command
52+
with the ``coll`` option:
53+
54+
.. code-block:: javascript
55+
56+
use library
57+
db.runCommand( {
58+
checkMetadataConsistency: 1,
59+
coll: "authors",
60+
} )
61+
62+
63+
Command Fields
64+
~~~~~~~~~~~~~~
65+
66+
.. list-table::
67+
:header-rows: 1
68+
69+
* - Field
70+
- Type
71+
- Description
72+
73+
* - ``checkIndexes``
74+
- boolean
75+
- Sets whether the command also checks indexes in sharding metadata.
76+
77+
For more information, see :ref:`checkMetadataConsistency-indexes`.
78+
79+
* - ``coll``
80+
- string
81+
- Sets the collection to check for sharding metadata inconsistencies.
82+
83+
* - ``cursor``
84+
- document
85+
- Configures the return cursor.
86+
87+
* - ``cursor.batchSize``
88+
- integer
89+
- Maximum number of inconsistency results to include in each batch.
90+
91+
Output
92+
~~~~~~
93+
94+
The ``checkMetadataConsistency`` command returns a cursor with a document for
95+
each inconsistency found in sharding metadata.
96+
97+
The return document has the following fields:
98+
99+
.. list-table::
100+
:header-rows: 1
101+
:widths: 25 30 45
102+
103+
* - Field
104+
- Type
105+
- Description
106+
107+
* - ``cursor``
108+
- document
109+
- Cursor with the results of the inconsistency checks.
110+
111+
* - ``cursor.id``
112+
- integer
113+
- A 64-bit integer indicated the cursor ID. Use the ``cursor.id`` value
114+
with the :dbcommand:`getMore` command to retrieve the next batch
115+
of inconsistencies.
116+
117+
If the cursor returns an ID of ``0``, it indicates that there are no
118+
more batches of information.
119+
120+
121+
* - ``cursor.ns``
122+
- string
123+
- The database and collection checked for inconsistencies.
124+
125+
* - ``cursor.firstBatch``
126+
- array
127+
- Results of metadata consistency checks.
128+
129+
* - ``ok``
130+
- boolean
131+
- Indicates whether the command was successful.
132+
133+
Behavior
134+
--------
135+
136+
Batch Results
137+
~~~~~~~~~~~~~
138+
139+
The ``checkMetadataConsistency`` command returns results in batches. To
140+
customize the batch size, the ``batchSize`` option:
141+
142+
.. code-block:: javascript
143+
144+
var cur = db.runCommand( {
145+
checkMetadataConsistency: 1,
146+
cursor: {
147+
batchSize: 10
148+
}
149+
} )
150+
151+
If the ``cursor.id`` field is greater than 0, you can use with the
152+
:dbcommand:`getMore` command to retrieve the next batch of results.
153+
154+
155+
.. _checkMetadataConsistency-indexes:
156+
157+
Check Indexes
158+
~~~~~~~~~~~~~
159+
160+
The ``checkMetadataConsistency`` command does not check indexes by default.
161+
To check metadata consistency and indexes, use the ``checkIndexes`` option:
162+
163+
.. code-block:: javascript
164+
165+
db.runCommand( {
166+
checkMetadataConsistency: 1,
167+
checkIndexes: true
168+
} )
169+
170+
171+
Example
172+
-------
173+
174+
175+
Use :method:`~db.runCommand` to run the ``checkMetadataConsistency`` command:
176+
177+
.. code-block:: javascript
178+
179+
db.runCommand( { checkMetadataConsistency: 1 } )
180+
181+
Example Output:
182+
183+
.. code-block:: json
184+
:copyable: false
185+
186+
{
187+
cursor: {
188+
id: Long("0"),
189+
ns: "test.$cmd.aggregate",
190+
firstBatch: [
191+
{
192+
type: "MisplacedCollection",
193+
description: "Unsharded collection found on shard different from database primary shard",
194+
details: {
195+
namespace: "test.authors",
196+
shard: "shard02",
197+
localUUID: new UUID("1ad56770-61e2-48e9-83c6-8ecefe73cfc4")
198+
}
199+
}
200+
],
201+
},
202+
ok: 1
203+
}
204+

source/reference/command/nav-sharding.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ Sharding Commands
5555

5656
- Stops the balancer thread.
5757

58+
* - :dbcommand:`checkMetadataConsistency`
59+
60+
- Performs a series of consistency checks on sharding metadata.
61+
62+
.. versionadded:: 7.0
63+
5864
* - :dbcommand:`checkShardingIndex`
5965

6066
- Internal command that validates index on shard key.
@@ -215,6 +221,7 @@ Sharding Commands
215221
/reference/command/balancerStart
216222
/reference/command/balancerStatus
217223
/reference/command/balancerStop
224+
/reference/command/checkMetadataConsistency
218225
/reference/command/checkShardingIndex
219226
/reference/command/clearJumboFlag
220227
/reference/command/cleanupOrphaned

source/reference/explain-results.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ representative. Your output may differ significantly.
225225
}
226226
]
227227
}
228-
},
228+
}
229229
}
230230

231231
.. data:: explain.queryPlanner

0 commit comments

Comments
 (0)