监控并中止进行中的索引构建
MongoDB维护命令
// Index builds in progress and their completion percentage:
db.getSiblingDB("admin").aggregate([
{ $currentOp: { allUsers: true } },
{ $match: { $or: [{ "command.createIndexes": { $exists: true } }, { desc: /^IndexBuildsCoordinator/ }] } },
{ $project: { opid: 1, desc: 1, ns: 1, secs_running: 1, msg: 1, progress: 1, "command.indexes.name": 1 } }
])
// Abort the build (on the primary; in a replica set it stops on all members):
db.musteri.dropIndex("idx_email")作用
列出正在运行的索引构建及已扫描的文档数和百分比进度(progress.done / progress.total);必要时用 dropIndex 中止构建。
适用场景
用于估算在大集合上启动的 createIndex 何时完成,或停止在高峰时段造成负载的构建。
注意
用 dropIndex/dropIndexes 而不是 killOp 中止索引构建;在副本集中请在 primary 上执行,使中止操作传播到所有成员。构建期间集合上的某些 DDL 操作会等待。构建结束时会短暂持有排他锁;在写入极其繁重时该时刻可能造成延迟。