Monitor Defragmentation of a Sharded Collection监视分片集合的分片整理
On this page本页内容
To monitor defragmentation of a sharded collection, use the 要监视分片化集合的分片整理,请使用balancerCollectionStatus command.balancerCollectionStatus命令。
You can see the current defragmentation state and the number of remaining chunks to process. 您可以看到当前的分片整理状态和要处理的剩余块的数量。This shows you the defragmentation progress.这将显示分片整理的进度。
About this Task任务介绍
Defragmentation uses the following phases to reduce the number of chunks in a collection and improve performance:分片整理使用以下阶段来减少集合中的块数并提高性能:
Merge chunks on the same shard that can be merged.在可以合并的同一分片上合并块。Migrate smaller chunks to other shards.将较小的区块迁移到其他分片。A small chunk is one that contains data less than 25% of the小区块是指包含的数据小于chunkSizesetting.chunkSize设置的25%。Merge remaining chunks on the same shard that can be merged.合并可以合并的同一分片上的剩余块。
The procedure in this task uses an example sharded collection named 此任务中的过程在名为ordersShardedCollection in a database named test.test的数据库中使用了一个名为ordersShardedCollection的示例分片集合。
You can use your own sharded collection and database in the procedure.您可以在过程中使用自己的分片集合和数据库。
In the procedure for this task, you monitor the phases and see the defragmentation progress.在该任务的过程中,您将监视各个阶段并查看分片整理进度。
Before you Begin开始之前
Start defragmenting a sharded collection.开始对已分片化的集合进行分片整理。For details, see Start Defragmenting a Sharded Collection.有关详细信息,请参阅开始对分片集合进行分片整理。Connect to连接到mongos.mongos。
Procedure过程
Examine output document检查输出文档
The previous command returns a document with information about defragmentation status, current phase, and the defragmentation work remaining. 上一个命令返回一个文档,其中包含有关分片整理状态、当前阶段和剩余分片整理工作的信息。For example:例如:
{
"balancerCompliant": false,
"firstComplianceViolation": "defragmentingChunks",
"details": {
"currentPhase": "moveAndMergeChunks",
"progress": { "remainingChunksToProcess": 1 }
}
}
The following table describes the document fields.下表介绍了文档字段。
balancerCompliant | Boolean | false if collection chunks must be moved. Otherwise, true.false。否则,是true。 |
firstComplianceViolation | String | balancerCompliant is false.balancerCompliant为false时返回。 |
details | Object | firstComplianceViolation is defragmentingChunks.firstComplianceViolation是defragmentingChunks时返回。 |
currentPhase | String |
|
remainingChunksToProcess | Integer |
For additional information about the returned document fields, see the balancer collection status output document.有关返回的文档字段的其他信息,请参阅平衡器集合状态输出文档。
Confirm that defragmentation is complete确认分片整理已完成
After defragmentation completes, the command returns either:分片整理完成后,该命令将返回以下任一项:
如果集合是平衡的,则balancerCompliant: trueif your collection is balanced.balancerCompliant: true。如果集合尚未平衡,则balancerCompliant: falsewithfirstComplianceViolationset to a string other thandefragmentingChunksif your collection is not balanced.balancerCompliant: false并且firstComplianceViolation设置为并非是defragmentingChunks的字符串。
Example output for a balanced collection after defragmentation completes:分片整理完成后平衡集合的输出示例:
{
chunkSize: 0.2,
balancerCompliant: true,
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1677543079, i: 1 }),
signature: {
hash: Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0),
keyId: Long("0")
}
},
operationTime: Timestamp({ t: 1677543079, i: 1 })
}
Next Steps下一步
If defragmentation has not yet completed, you can stop it. For details, see Stop Defragmenting a Sharded Collection.如果分片整理尚未完成,您可以停止它。有关详细信息,请参阅停止对分片集合进行分片整理。
Learn More了解更多信息
Start defragmenting a sharded collection开始对已分片化的集合进行分片整理Stop defragmenting a sharded collection停止对已分片化的集合进行分片整理To view the balancer collection status output document, see要查看平衡器集合状态输出文档,请参阅Balancer collection status output document平衡器集合状态输出文档
Print shard status, see打印分片状态,请参阅db.printShardingStatus()Retrieve shard status details, see检索分片状态详细信息,请参阅sh.status()View shard status collection fields, see查看分片状态集合字段,请参阅Sharded Collection分片系列See active mongos instances, see查看活动mongos实例,请参阅Active活动mongosInstancesmongos实例Monitor shards using MongoDB Atlas, see使用MongoDB Atlas监控分片,请参阅Review Sharded Clusters查看分片集群