Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /

Fusionar Fragmentos en un Clúster Shardeado

La mergeChunks El comando permite combinar fragmentos continuos en la misma partición en un solo fragmento. Este tutorial explica cómo fusionar fragmentos vecinos en un clúster shardado.

Nota

Los ejemplos de este procedimiento utilizan una members colección en la test base de datos, utilizando el campo username como la Clave de partición.

En mongosh, identifica los rangos de fragmentos con la siguiente operación:

sh.status()

En la salida, los rangos de fragmentos aparecen después de los recuentos de fragmentos para cada colección particionada, como en el siguiente ejemplo:

--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5ebf0bfd3eeb6037ec7cbba9")
}
shards:
{ "_id" : "shardA", "host" : "shardA/shardA-m1.example.net:27018,shardA-m2.example.net:27018,shardA-m3.example.net:27018", "state" : 1 }
{ "_id" : "shardB", "host" : "shardB/shardB-m1.example.net:27018,shardB-m2.example.net:27018,shardB-m3.example.net:27018", "state" : 1 }
active mongoses:
"4.4.0" : 1
autosplit:
Currently enabled: yes
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
519 : Success
databases:
{ "_id" : "config", "primary" : "config" }
config.system.sessions
shard key: { "_id" : 1 }
unique: false
balancing: true
chunks:
shardA 512
shardB 512
too many chunks to print, use verbose if you want to force print
{ "_id" : "test", "primary" : "shardA", "version" : { "uuid" : UUID("22c042fc-7e3d-4c6d-992d-f3d714759781"), "lastMod" : 1 } }
test.members
shard key: { "username" : 1 }
unique: false
balancing: true
chunks:
shardA 7
shardB 7
{ "username" : { "$minKey" : 1 } } -->> { "username" : "user16643" } on : shardB Timestamp(13, 0)
{ "username" : "user16643" } -->> { "username" : "user2329" } on : shardB Timestamp(16, 0)
{ "username" : "user2329" } -->> { "username" : "user29937" } on : shardB Timestamp(17, 0)
{ "username" : "user29937" } -->> { "username" : "user36583" } on : shardB Timestamp(18, 0)
{ "username" : "user36583" } -->> { "username" : "user43229" } on : shardB Timestamp(19, 0)
{ "username" : "user43229" } -->> { "username" : "user49877" } on : shardB Timestamp(20, 0)
{ "username" : "user49877" } -->> { "username" : "user56522" } on : shardB Timestamp(21, 0)
{ "username" : "user56522" } -->> { "username" : "user63169" } on : shardA Timestamp(21, 1)
{ "username" : "user63169" } -->> { "username" : "user69816" } on : shardA Timestamp(10, 1)
{ "username" : "user69816" } -->> { "username" : "user76462" } on : shardA Timestamp(11, 1)
{ "username" : "user76462" } -->> { "username" : "user83108" } on : shardA Timestamp(12, 1)
{ "username" : "user83108" } -->> { "username" : "user89756" } on : shardA Timestamp(14, 1)
{ "username" : "user89756" } -->> { "username" : "user96401" } on : shardA Timestamp(15, 1)
{ "username" : "user96401" } -->> { "username" : { "$maxKey" : 1 } } on : shardA Timestamp(15, 2)

Los rangos de fragmentos aparecen después de los conteos de fragmentos para cada colección particionada. Por ejemplo, los siguientes son los rangos de fragmentos para la colección test.members:

{ "username" : { "$minKey" : 1 } } -->> { "username" : "user16643" } on : shardB Timestamp(13, 0)
{ "username" : "user16643" } -->> { "username" : "user2329" } on : shardB Timestamp(16, 0)
{ "username" : "user2329" } -->> { "username" : "user29937" } on : shardB Timestamp(17, 0)
{ "username" : "user29937" } -->> { "username" : "user36583" } on : shardB Timestamp(18, 0)
{ "username" : "user36583" } -->> { "username" : "user43229" } on : shardB Timestamp(19, 0)
{ "username" : "user43229" } -->> { "username" : "user49877" } on : shardB Timestamp(20, 0)
{ "username" : "user49877" } -->> { "username" : "user56522" } on : shardB Timestamp(21, 0)
{ "username" : "user56522" } -->> { "username" : "user63169" } on : shardA Timestamp(21, 1)
{ "username" : "user63169" } -->> { "username" : "user69816" } on : shardA Timestamp(10, 1)
{ "username" : "user69816" } -->> { "username" : "user76462" } on : shardA Timestamp(11, 1)
{ "username" : "user76462" } -->> { "username" : "user83108" } on : shardA Timestamp(12, 1)
{ "username" : "user83108" } -->> { "username" : "user89756" } on : shardA Timestamp(14, 1)
{ "username" : "user89756" } -->> { "username" : "user96401" } on : shardA Timestamp(15, 1)
{ "username" : "user96401" } -->> { "username" : { "$maxKey" : 1 } } on : shardA Timestamp(15, 2)

Fusionar fragmentos contiguos en el mismo fragmento.

Por ejemplo, considere los siguientes rangos de fragmentos en shardA:

Nota

Se resaltan los fragmentos que hay que combinar.

{ "username" : "user56522" } -->> { "username" : "user63169" } on : shardA Timestamp(21, 1)
{ "username" : "user63169" } -->> { "username" : "user69816" } on : shardA Timestamp(10, 1)
{ "username" : "user69816" } -->> { "username" : "user76462" } on : shardA Timestamp(11, 1)
{ "username" : "user76462" } -->> { "username" : "user83108" } on : shardA Timestamp(12, 1)
{ "username" : "user83108" } -->> { "username" : "user89756" } on : shardA Timestamp(14, 1)
{ "username" : "user89756" } -->> { "username" : "user96401" } on : shardA Timestamp(15, 1)
{ "username" : "user96401" } -->> { "username" : { "$maxKey" : 1 } } on : shardA Timestamp(15, 2)

Para fusionar los fragmentos contiguos resaltados, emita el comando contra mergeChunks la admin base de datos:

db.adminCommand( {
mergeChunks: "test.members",
bounds: [ { "username" : "user69816" },
{ "username" : "user96401" } ]
} )

En caso de éxito, mergeChunks produce la siguiente salida:

{
"ok" : 1,
"operationTime" : Timestamp(1589580356, 14),
"$clusterTime" : {
"clusterTime" : Timestamp(1589580356, 14),
"signature" : {
"hash" : BinData(0,"up5VKd49G/uPCq1iger2nOtfIHw="),
"keyId" : Long("6827188741371592725")
}
}
}

En cualquier condición de error, devuelve un documento donde el valormergeChunks del ok campo 0 es.

Después de fusionar los fragmentos identificados, confirma el nuevo fragmento de la siguiente manera:

sh.status()

La salida de sh.status() debería asemejarse a:

--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5ebef5447fa151d4bd79dd72")
}
shards:
{ "_id" : "shardA", "host" : "shardA/shardA-m1.example.net:27018,shardA-m2.example.net:27018,shardA-m3.example.net:27018", "state" : 1 }
{ "_id" : "shardB", "host" : "shardB/shardB-m1.example.net:27018,shardB-m2.example.net:27018,shardB-m3.example.net:27018", "state" : 1 }
active mongoses:
"4.4.0" : 1
autosplit:
Currently enabled: yes
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
519 : Success
databases:
{ "_id" : "config", "primary" : "config" }
config.system.sessions
shard key: { "_id" : 1 }
unique: false
balancing: true
chunks:
shardA 512
shardB 512
too many chunks to print, use verbose if you want to force print
{ "_id" : "test", "primary" : "shardA", "version" : { "uuid" : UUID("22c042fc-7e3d-4c6d-992d-f3d714759781"), "lastMod" : 1 } }
test.members
shard key: { "username" : 1 }
unique: false
balancing: true
chunks:
shardA 5
shardB 6
{ "username" : { "$minKey" : 1 } } -->> { "username" : "user16643" } on : shardA Timestamp(22, 0)
{ "username" : "user16643" } -->> { "username" : "user2329" } on : shardB Timestamp(22, 1)
{ "username" : "user2329" } -->> { "username" : "user29937" } on : shardB Timestamp(17, 0)
{ "username" : "user29937" } -->> { "username" : "user36583" } on : shardB Timestamp(18, 0)
{ "username" : "user36583" } -->> { "username" : "user43229" } on : shardB Timestamp(19, 0)
{ "username" : "user43229" } -->> { "username" : "user49877" } on : shardB Timestamp(20, 0)
{ "username" : "user49877" } -->> { "username" : "user56522" } on : shardB Timestamp(21, 0)
{ "username" : "user56522" } -->> { "username" : "user63169" } on : shardA Timestamp(21, 1)
{ "username" : "user63169" } -->> { "username" : "user69816" } on : shardA Timestamp(10, 1)
{ "username" : "user69816" } -->> { "username" : "user96401" } on : shardA Timestamp(21, 2)
{ "username" : "user96401" } -->> { "username" : { "$maxKey" : 1 } } on : shardA Timestamp(15, 2)

Después de la fusión, el balanceador puede migrar fragmentos entre particiones para garantizar una distribución más uniforme de fragmentos.

Volver

División de fragmentos

En esta página