Menu Docs
Página inicial do Docs
/
Manual do MongoDB
/ /

Mesclar grupos em um cluster fragmentado

Nesta página

  • Visão geral
  • Procedimento

O comando mergeChunks permite combinar chunks contínuos no mesmo shard em um único chunk. Este tutorial explica como mesclar chunks vizinhos em um cluster fragmentado.

Observação

Os exemplos deste procedimento usam uma collection members no reconhecimento de data center dados test , usando o campo username como a chave de fragmento.

Em mongosh, identifique as faixas de chunks com a seguinte operação:

sh.status()

Na saída, os intervalos de parte aparecem após as contagens de parte para cada collection fragmentada, como no exemplo a seguir:

--- 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", "partitioned" : true }
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", "partitioned" : true, "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)

Os intervalos de parte aparecem após as contagens de parte para cada collection fragmentada. Por exemplo, a seguir estão as partes para a collection 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)

Mesclar chunks contíguos no mesmo fragmento.

Por exemplo, considere os seguintes intervalos de chunks no shardA :

Observação

As partes a serem mescladas estão em destaque.

{ "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 mesclar a parte contígua destacada, emita o comando { mergeChunks admin no reconhecimento de data center :

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

Em caso de sucesso, mergeChunks produz o seguinte resultado:

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

Em qualquer condição de falha, o mergeChunks retorna um documento onde o valor do campo ok é 0 .

Após mesclar as partes identificadas, confirme a nova parte da seguinte maneira:

sh.status()

A saída de sh.status() deve ser semelhante:

--- 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", "partitioned" : true }
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", "partitioned" : true, "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)

Após a mesclagem, o balanceador pode migrar blocos entre fragmentos para garantir uma distribuição mais uniforme de blocos.

Voltar

Divida partes