Definición
mergeChunksFor a sharded collection,
mergeChunkscombines contiguous chunk ranges on a shard into a single chunk. Issue themergeChunkscommand on theadmindatabase from amongosinstance.
Compatibilidad
Este comando está disponible en implementaciones alojadas en los siguientes entornos:
- MongoDB Atlas: El servicio totalmente gestionado para implementaciones de MongoDB en la nube
MongoDB Enterprise: La versión basada en suscripción y autogestionada de MongoDB
MongoDB Community: La versión de MongoDB con código fuente disponible, de uso gratuito y autogestionada.
Sintaxis
El comando tiene la siguiente sintaxis:
db.adminCommand( { mergeChunks: <namespace>, bounds : [ { <shardKeyField>: <minFieldValue> }, { <shardKeyField>: <maxFieldValue> } ] } )
For compound shard keys, you must include the full shard key in the bounds specification. For example, if the shard key is { x: 1, y: 1 }, mergeChunks has the following form:
db.adminCommand( { mergeChunks: <namespace>, bounds: [ { x: <minValue>, y: <minValue> }, { x: <maxValue>, y: <maxValue> } ] } )
Campos de comandos
El comando toma los siguientes campos:
Campo | Tipo | Descripción |
|---|---|---|
| namespace | El namespace completamente calificado de la colección donde existen ambos fragmentos. Los namespaces toman la forma de |
| arreglo | Un arreglo que contiene los valores mínimo y máximo de clave del nuevo fragmento. |
Control de acceso
En implementaciones que se ejecutan con authorization, el rol integrado clusterManager proporciona los privilegios necesarios.
Comportamiento
Nota
Use the mergeChunks only in special circumstances. For instance, when cleaning up your sharded cluster after removing many documents.
Para fusionar exitosamente los fragmentos, lo siguiente debe ser cierto:
En el campo
bounds,<minkey>y<maxkey>deben corresponder a los límites inferior y superior de los fragmentos a fusionar.Los fragmentos deben residir en la misma partición.
Los fragmentos deben ser contiguos.
mergeChunks retorna un error si estas condiciones no se cumplen.
Mensajes de Devolución
On success, mergeChunks returns this document:
{ "ok" : 1, "$clusterTime" : { "clusterTime" : Timestamp(1510767081, 1), "signature" : { "hash" : BinData(0,"okKHD0QuzcpbVQg7mP2YFw6lM04="), "keyId" : Long("6488693018630029321") } }, "operationTime" : Timestamp(1510767081, 1) }
Otra operación en curso
mergeChunks returns the following error message if another metadata operation is in progress on the chunks collection:
errmsg: "The collection's metadata lock is already taken."
If another process, such as balancer process, changes metadata while mergeChunks is running, you may see this error. You can retry the mergeChunks operation without side effects.
Fragmentos en diferentes particiones
If the input chunks are not on the same shard, mergeChunks returns an error similar to the following:
{ "ok" : 0, "errmsg" : "could not merge chunks, collection test.users does not contain a chunk ending at { username: \"user63169\" }", "$clusterTime" : { "clusterTime" : Timestamp(1510767081, 1), "signature" : { "hash" : BinData(0,"okKHD0QuzcpbVQg7mP2YFw6lM04="), "keyId" : Long("6488693018630029321") } }, "operationTime" : Timestamp(1510767081, 1) }
Fragmentos no contiguos
If the input chunks are not contiguous, mergeChunks returns an error similar to the following:
{ "ok" : 0, "errmsg" : "could not merge chunks, collection test.users has more than 2 chunks between [{ username: \"user29937\" }, { username: \"user49877\" })" "$clusterTime" : { "clusterTime" : Timestamp(1510767081, 1), "signature" : { "hash" : BinData(0,"okKHD0QuzcpbVQg7mP2YFw6lM04="), "keyId" : Long("6488693018630029321") } }, "operationTime" : Timestamp(1510767081, 1) }