|
| 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 | + |
0 commit comments