定义
currentOp自版本 6.2 起已弃用。
在 6.2 版本及更高版本中,使用
$currentOp聚合阶段。返回一个文档,其中包含有关
mongod实例正在进行的操作的信息。currentOp自版本.6 以来,2$currentOpdb.currentOp()数据库命令已弃用。使用 聚合阶段而不是currentOp命令及其mongosh辅助方法 。
兼容性
此命令可用于以下环境中托管的部署:
- MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
注意
所有 MongoDB Atlas 集群都支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令。
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
语法
该命令具有以下语法:
db.adminCommand( { currentOp: 1 } )
注意
从MongoDB5.0 开始,使用 运行辅助方法$currentOp 时会使用db.currentOp() mongosh聚合阶段。
鉴于此,在 5.0 版本的 Shell 以及使用 mongosh 时,db.currentOp() 结果集不受针对先前 mongo 旧版本文档的 16 MB BSON 文档返回大小限制的约束。
行为
currentOp 必须针对 admin 数据库运行,并且可以接受多个可选字段。
字段 | 说明 |
|---|---|
| |
| 布尔值。如果设置为
|
<filter> | |
| 可选。用户提供的待附加到该命令的注释。设置后,该注释将与该命令的记录一起出现在以下位置:
注释可以是任何有效的 BSON 类型(字符串、整型、对象、数组等)。 |
currentOp 数据库分析器会为 CRUD 操作报告相同的基本诊断信息,包括以下内容:
getMore(OP_GET_MORE 和command)
这些操作也包含在慢查询的日志中。有关慢查询日志的更多信息,请参阅 slowOpThresholdMs。
日志校订
使用可查询加密时,带有 encryptionInformation 选项的 currentOp 操作会编辑某些信息:
输出将忽略
"command"之后的所有字段。输出编辑
"command"以仅包含第一个元素$comment以及$db。
访问控制
在使用 authorization 运行的系统上,用户必须具有包含 inprog 特权动作的访问权限。
没有 inprog 特权动作,用户也可以在 mongod 实例上使用 $ownOps,来查看自己的操作。
db.adminCommand( { currentOp: 1, "$ownOps": 1 } )
示例
以下示例使用 currentOp 命令和各种查询文档来过滤输出结果。
显示当前所有操作
db.adminCommand( { currentOp: true, "$all": true } )
等待锁定的写入操作
以下示例返回有关等待锁的所有写操作的信息:
db.adminCommand( { currentOp: true, "waitingForLock" : true, $or: [ { "op" : { "$in" : [ "insert", "update", "remove" ] } }, { "command.findandmodify": { $exists: true } } ] } )
无产出的活跃操作
以下示例将返回有关从未出现的所有正在运行的活动操作的信息:
db.adminCommand( { currentOp: true, "active" : true, "numYields" : 0, "waitingForLock" : false } )
针对特定数据库的活动操作
以下示例将返回有关运行时间超过 3 秒且针对数据库 db1 的所有活动操作的信息:
db.adminCommand( { currentOp: true, "active" : true, "secs_running" : { "$gt" : 3 }, "ns" : /^db1\./ } )
主动索引操作
以下示例返回索引创建操作的相关信息:
db.getSiblingDB("admin").aggregate( [ { $currentOp : { idleConnections: true } }, { $match: { $or: [ { "op": "command", "command.createIndexes": { $exists: true } }, { "op": "none", "msg": /^Index Build/ } ] } } ] )
MongoDB通过将 active字段设置为 false,将等待提交法定人数完成操作的索引构建索引为空闲连接。idleConnections: true 设置在 $currentOp 输出中包含这些空闲连接。
输出示例
The following is a prototype of the currentOp output when run on a standalone:
{ "inprog": [ { "type" : <string>, "host" : <string>, "desc" : <string>, "connectionId" : <number>, "client" : <string>, "appName" : <string>, "clientMetadata" : <document>, "active" : <boolean>, "currentOpTime" : <string>, "effectiveUsers" : [ { "user" : <string>, "db" : <string> } ], "opid" : <number>, "lsid" : { "id" : <UUID>, "uid" : <BinData> }, "secs_running" : <Long()>, "microsecs_running" : <number>, "op" : <string>, "ns" : <string>, "command" : <document>, "queryFramework" : <string>, "planSummary": <string>, "cursor" : { // only for getMore operations "cursorId" : <Long()>, "createdDate" : <ISODate()>, "lastAccessDate" : <ISODate()>, "nDocsReturned" : <Long()>, "nBatchesReturned" : <Long()>, "noCursorTimeout" : <boolean>, "tailable" : <boolean>, "awaitData" : <boolean>, "originatingCommand" : <document>, "planSummary" : <string>, "operationUsingCursorId" : <Long()> }, "msg": <string>, "progress" : { "done" : <number>, "total" : <number> }, "killPending" : <boolean>, "numYields" : <number>, "dataThroughputLastSecond" : <number>, "dataThroughputAverage" : <number>, "waitingForLatch" : { "timestamp" : <ISODate()>, "captureName" : <string> }, "locks" : { "ParallelBatchWriterMode" : <string>, "ReplicationStateTransition" : <string>, "Global" : <string>, "Database" : <string>, "Collection" : <string>, "Metadata" : <string>, "oplog" : <string> }, "waitingForLock" : <boolean>, "lockStats" : { "ParallelBatchWriterMode" : { "acquireCount": { "r": <NumberLong>, "w": <NumberLong>, "R": <NumberLong>, "W": <NumberLong> }, "acquireWaitCount": { "r": <NumberLong>, "w": <NumberLong>, "R": <NumberLong>, "W": <NumberLong> }, "timeAcquiringMicros" : { "r" : Long(0), "w" : Long(0), "R" : Long(0), "W" : Long(0) }, "deadlockCount" : { "r" : Long(0), "w" : Long(0), "R" : Long(0), "W" : Long(0) } }, "ReplicationStateTransition" : { ... }, "Global": { ... }, "Database" : { ... }, ... } }, ... ], "fsyncLock": <boolean>, "info": <string>, "ok": <num> }
The following is a prototype of the currentOp output when run on a primary of a replica set:
{ "inprog": [ { "type" : <string>, "host" : <string>, "desc" : <string>, "connectionId" : <number>, "client" : <string>, "appName" : <string>, "clientMetadata" : <document>, "lsid" : { "id" : <UUID>, "uid" : <BinData> }, "transaction" : { "parameters" : { "txnNumber" : <Long()>, "autocommit" : <boolean>, "readConcern" : { "level" : <string> } }, "readTimestamp" : <Timestamp>, "startWallClockTime" : <string>, "timeOpenMicros" : <Long()>, "timeActiveMicros" : <Long()>, "timeInactiveMicros" : <Long()>, "expiryTime" : <string>, }, "active" : <boolean>, "currentOpTime" : <string>, "effectiveUsers" : [ { "user" : <string>, "db" : <string> } ], "opid" : <number>, "secs_running" : <Long()>, "microsecs_running" : <number>, "op" : <string>, "ns" : <string>, "command" : <document>, "originatingCommand" : <document>, "queryFramework" : <string>, "planSummary": <string>, "prepareReadConflicts" : <Long()>, "writeConflicts" : <Long()>, "cursor" : { // only for getMore operations "cursorId" : <Long()>, "createdDate" : <ISODate()>, "lastAccessDate" : <ISODate()>, "nDocsReturned" : <Long()>, "nBatchesReturned" : <Long()>, "noCursorTimeout" : <boolean>, "tailable" : <boolean>, "awaitData" : <boolean>, "originatingCommand" : <document>, "planSummary" : <string>, "operationUsingCursorId" : <Long()> }, "msg": <string>, "progress" : { "done" : <number>, "total" : <number> }, "killPending" : <boolean>, "numYields" : <number>, "dataThroughputLastSecond" : <number>, "dataThroughputAverage" : <number>, "waitingForLatch" : { "timestamp" : <ISODate()>, "captureName" : <string> }, "locks" : { "ParallelBatchWriterMode" : <string>, "ReplicationStateTransition" : <string>, "Global" : <string>, "Database" : <string>, "Collection" : <string>, "Metadata" : <string>, "oplog" : <string> }, "waitingForLock" : <boolean>, "lockStats" : { "ParallelBatchWriterMode" : { "acquireCount": { "r": <NumberLong>, "w": <NumberLong>, "R": <NumberLong>, "W": <NumberLong> }, "acquireWaitCount": { "r": <NumberLong>, "w": <NumberLong>, "R": <NumberLong>, "W": <NumberLong> }, "timeAcquiringMicros" : { "r" : Long(0), "w" : Long(0), "R" : Long(0), "W" : Long(0) }, "deadlockCount" : { "r" : Long(0), "w" : Long(0), "R" : Long(0), "W" : Long(0) } }, "ReplicationStateTransition" : { ... }, "Global" : { ... }, "Database" : { ... }, ... } }, ... ], "fsyncLock": <boolean>, "info": <string>, "ok": <num>, "operationTime": <timestamp>, "$clusterTime": <document> }
The following is an example of the currentOp output when run on a mongos of a sharded cluster (Fields may vary depending on the operation being reported):
{ "inprog": [ { "shard": <string>, "type" : <string>, "host" : <string>, "desc" : <string>, "connectionId" : <number>, "client_s" : <string>, "appName" : <string>, "clientMetadata" : <document>, "lsid" : { "id" : <UUID>, "uid" : <BinData> }, "transaction" : { "parameters" : { "txnNumber" : <Long()>, "autocommit" : <boolean>, "readConcern" : { "level" : <string> } }, "readTimestamp" : <Timestamp>, "startWallClockTime" : <string>, "timeOpenMicros" : <Long()>, "timeActiveMicros" : <Long()>, "timeInactiveMicros" : <Long()>, "expiryTime" : <string>, }, "active" : <boolean>, "currentOpTime" : <string>, "effectiveUsers" : [ { "user" : <string>, "db" : <string> } ], "runBy" : [ { "user" : <string>, "db" : <string> } ], "twoPhaseCommitCoordinator" : { "lsid" : { "id" : <UUID>, "uid" : <BinData> }, "txnNumber" : <NumberLong>, "numParticipants" : <NumberLong>, "state" : <string>, "commitStartTime" : <ISODate>, "hasRecoveredFromFailover" : <boolean>, "stepDurations" : <document>, "decision" : <document>, "deadline" : <ISODate> } "opid" : <string>, "secs_running" : <Long()>, "microsecs_running" : <number>, "op" : <string>, "ns" : <string>, "command" : <document>, "configTime" : <Timestamp>, // Starting in 5.0 "topologyTime" : <Timestamp>, // Starting in 5.0 "queryFramework" : <string>, // Starting in 6.2 "planSummary": <string>, "prepareReadConflicts" : <Long()>, "writeConflicts" : <Long()>, "cursor" : { // only for getMore operations "cursorId" : <Long()>, "createdDate" : <ISODate()>, "lastAccessDate" : <ISODate()>, "nDocsReturned" : <Long()>, "nBatchesReturned" : <Long()>, "noCursorTimeout" : <boolean>, "tailable" : <boolean>, "awaitData" : <boolean>, "originatingCommand" : <document>, "planSummary" : <string>, "operationUsingCursorId" : <Long()> }, "msg": <string>, "progress" : { "done" : <number>, "total" : <number> }, "killPending" : <boolean>, "numYields" : <number>, "dataThroughputLastSecond" : <number>, "dataThroughputAverage" : <number>, "waitingForLatch" : { "timestamp" : <ISODate()>, "captureName" : <string> }, "locks" : { "ParallelBatchWriterMode" : <string>, "ReplicationStateTransition" : <string>, "Global" : <string>, "Database" : <string>, "Collection" : <string>, "Metadata" : <string>, "oplog" : <string> }, "waitingForLock" : <boolean>, "lockStats" : { "ParallelBatchWriterMode": { "acquireCount": { "r": <NumberLong>, "w": <NumberLong>, "R": <NumberLong>, "W": <NumberLong> }, "acquireWaitCount": { "r": <NumberLong>, "w": <NumberLong>, "R": <NumberLong>, "W": <NumberLong> }, "timeAcquiringMicros" : { "r" : Long(0), "w" : Long(0), "R" : Long(0), "W" : Long(0) }, "deadlockCount" : { "r" : Long(0), "w" : Long(0), "R" : Long(0), "W" : Long(0) } }, "ReplicationStateTransition" : { ... }, "Global" : { ... }, "Database" : { ... }, ... } }, ... ], "ok": <num>, "operationTime": <timestamp>, "$clusterTime": <document> }
特定输出示例
这些输出示例说明了特定操作的 currentOp 输出。构成实际输出的字段因服务器角色而异。
重新分片输出示例
{ type: "op", desc: "Resharding{Donor, Recipient, Coordinator}Service <reshardingUUID>", op: "command", ns: "<database>.<collection>", originatingCommand: { reshardCollection: "<database>.<collection>", key: <shardkey>, unique: <boolean>, collation: {locale: "simple"}, // Other options to the reshardCollection command are omitted // to decrease the likelihood the output is truncated. }, {donor, coordinator, recipient}State : "<service state>", approxDocumentsToCopy: NumberLong(<count>), approxBytesToCopy: NumberLong(<count>), bytesCopied: NumberLong(<count>), countWritesToStashCollections: NumberLong(<count>), countWritesDuringCriticalSection : NumberLong(<count>), countReadsDuringCriticalSection: NumberLong(<count>), deletesApplied: NumberLong(<count>), documentsCopied: NumberLong(<count>), insertsApplied: NumberLong(<count>), oplogEntriesFetched: NumberLong(<count>), oplogEntriesApplied: NumberLong(<count>), remainingOperationTimeEstimatedSecs: NumberLong(<count>), allShardsLowestRemainingOperationTimeEstimatedSecs: NumberLong(<estimate>), allShardsHighestRemainingOperationTimeEstimatedSecs: NumberLong(<estimate>), totalApplyTimeElapsedSecs: NumberLong(<count>), totalCopyTimeElapsedSecs: NumberLong(<count>), totalCriticalSectionTimeElapsedSecs : NumberLong(<count>), totalOperationTimeElapsedSecs: NumberLong(<count>), updatesApplied: NumberLong(<count>), }
全局索引示例
{ type: "op", desc: "GlobalIndex{Donor, Recipient, Coordinator}Service <globalIndexUUID}", op: "command", ns: "<database>.<collection>", originatingCommand: { createIndexes: "<database>.<collection>", key: <indexkeypattern>, unique: <boolean>, <Additional createIndexes options> }, {donor, coordinator, recipient}State : "<service state>", approxDocumentsToScan: Long(<count>), approxBytesToScan: Long(<count>), bytesWrittenFromScan: Long(<count>), countWritesToStashCollections: Long(<count>), countWritesDuringCriticalSection : Long(<count>), countReadsDuringCriticalSection: Long(<count>), keysWrittenFromScan: Long(<count>), remainingOperationTimeEstimatedSecs: Long(<count>), allShardsLowestRemainingOperationTimeEstimatedSecs: Long(<estimate>), allShardsHighestRemainingOperationTimeEstimatedSecs: Long(<estimate>), totalCopyTimeElapsedSecs: Long(<count>), totalCriticalSectionTimeElapsedSecs : Long(<count>), totalOperationTimeElapsedSecs: Long(<count>), }
输出字段
currentOp.type操作类型。值为:
opidleSessionidleCursor
If the
currentOp.typeisop,currentOp.opprovides details on the specific operation.
currentOp.descA description of the client. This string includes the
connectionId.
currentOp.client包含操作来源信息的字符串。
For multi-document transactions,
clientstores information about the most recent client to run an operation inside the transaction.
currentOp.appName运行操作的客户端应用程序的标识符。使用
appName连接字符串选项设置appName字段的自定义值。
currentOp.clientMetadata有关客户端的其他信息。
For multi-document transactions,
clientstores information about the most recent client to run an operation inside the transaction.
currentOp.runByAn array that contains a document for each user who is impersonating the
effectiveUser(s)for the operation. The runBy document contains theusername and the authenticationdb. In general, the runBy user is the__systemuser; e.g."runBy" : [ { "user" : "__system", "db" : "local" } ] 仅在分片集群上可用
currentOp.transaction一份文档,包含多文档事务信息。
只有当操作是多文档事务的一部分时才会出现。
currentOp.transaction.parameters一份文档,包含多文档事务的信息。
只有当操作是多文档事务的一部分时才会出现。
currentOp.transaction.parameters.readConcern事务的读关注。
多文档事务支持读关注
"snapshot"、"local"和"majority"。只有当操作是多文档事务的一部分时才会出现。
currentOp.transaction.timeOpenMicros事务的持续时间(以微秒计)。
The
timeActiveMicrosvalue added to thetimeInactiveMicrosshould equal thetimeOpenMicros.只有当操作是多文档事务的一部分时才会出现。
currentOp.transaction.timeActiveMicros事务处于活动状态的总时长;即事务运行各种操作的总时长。
The
timeActiveMicrosvalue added to thetimeInactiveMicrosshould equal thetimeOpenMicros.只有当操作是多文档事务的一部分时才会出现。
currentOp.transaction.timeInactiveMicros事务处于非活动状态的总时长;即事务没有运行任何操作的总时长。
The
timeInactiveMicrosvalue added to thetimeActiveMicrosshould equal thetimeOpenMicros.只有当操作是多文档事务的一部分时才会出现。
currentOp.transaction.expiryTime事务超时并中止的日期和时间(带时区)。
The
currentOp.transaction.expiryTimeequals thecurrentOp.transaction.startWallClockTime+ thetransactionLifetimeLimitSeconds.有关更多信息,请参阅事务的运行时间限制。
只有当操作是多文档事务的一部分时才会出现。
currentOp.twoPhaseCommitCoordinator有关以下任一信息:
用于跨多个分片写入操作的事务的提交协调指标。
提交协调由分片处理,
currentOp(在mongos或分片节点上运行)仅针对当前由该分片协调的事务返回分片的协调信息。要仅过滤提交协调指标:
db.currentOp( { desc: "transaction coordinator" }) A specific commit coordination operation (i.e.
currentOp.typeisopandcurrentOp.descis"TransactionCoordinator") spawned by the transaction coordinator.
currentOp.twoPhaseCommitCoordinator.lsid多分片事务的会话标识符。
The combination of the
lsidandtxnNumberidentifies the transaction.
currentOp.twoPhaseCommitCoordinator.txnNumber多分片事务的交易编号。
The combination of the
txnNumberandlsididentifies the transaction.
currentOp.twoPhaseCommitCoordinator.action事务协调器生成的特定提交协调操作:
"sendingPrepare""sendingCommit""sendingAbort""writingParticipantList""writingDecision""deletingCoordinatorDoc"
仅适用于特定的协调操作。
currentOp.twoPhaseCommitCoordinator.numParticipants参与本次提交的分片数量。
仅适用于提交协调指标。
currentOp.twoPhaseCommitCoordinator.state提交协调过程的当前步骤/状态。
步骤/阶段说明inactive不是提交的主动部分。
writingParticipantList写入属于该多分片事务的分片列表的本地记录。
waitingForVotes等待参与者通过投票作出提交或终止响应。
writingDecision写入协调器根据投票作出提交或终止决定的本地记录。
waitingForDecisionAck等待参与者确认协调器提交或中止的决定。
deletingCoordinatorDoc删除提交决策的本地记录。
仅适用于提交协调指标。
currentOp.twoPhaseCommitCoordinator.commitStartTime提交操作的开始日期和时间。
仅适用于提交协调指标。
currentOp.twoPhaseCommitCoordinator.hasRecoveredFromFailover一个布尔值,指示提交协调是否由于协调提交的分片故障转移而重新启动。
If
hasRecoveredFromFailoveris true, then the times specified incurrentOp.twoPhaseCommitCoordinator.stepDurationsmay not be accurate for all steps.仅适用于提交协调指标。
currentOp.twoPhaseCommitCoordinator.stepDurationsA document that contains the duration, in microseconds, of the commit coordination
steps/statecompleted or in progress:"stepDurations" : { "writingParticipantListMicros" : Long(17801), "totalCommitDurationMicros" : Long(42488463), "waitingForVotesMicros" : Long(30378502), "writingDecisionMicros" : Long(15015), "waitingForDecisionAcksMicros" : Long(12077145), "deletingCoordinatorDocMicros" : Long(6009) }, If
currentOp.twoPhaseCommitCoordinator.hasRecoveredFromFailoveris true, then the times specified instepDurationsmay not be accurate for all steps.对于处于
inactive状态的协调器来说,文档为空:"stepDurations" : { } 仅适用于提交协调指标。
currentOp.twoPhaseCommitCoordinator.decision包含提交/中止决策的文档,例如:
对于提交决策:
"decision" : { "decision" : "commit", "commitTimestamp" : Timestamp(1572034669, 3) } 对于中止决策:
"decision" : { "decision" : "abort", "abortStatus" : { "code" : 282, "codeName" : "TransactionCoordinatorReachedAbortDecision", "errmsg" : "Transaction exceeded deadline" } }
仅适用于提交协调指标。
currentOp.twoPhaseCommitCoordinator.deadline必须完成提交的日期和时间。
仅适用于提交协调指标。
currentOp.opidThe identifier for the operation. You can pass this value to
db.killOp()inmongoshto terminate the operation.警告
终止正在运行的操作时要格外小心。仅使用
db.killOp()来终止客户端发起的操作,而不会终止数据库内部操作。
currentOp.active布尔值,指定操作是否已启动。如果操作已启动,则值为
true;如果操作处于空闲状态(例如空闲连接或当前空闲的内部线程),则值为false。即使该操作已让位于另一个操作,该操作仍可处于活动状态。对于某些不活动的后台线程,例如不活动的signalProcessingThread,MongoDB 会抑制各种空字段。
currentOp.secs_running操作的持续时间(以秒计)。MongoDB 通过从操作开始时间减去当前时间来计算此值。
Only appears if the operation is running; i.e. if
activeistrue.
currentOp.microsecs_running操作的持续时间(以微秒计)。MongoDB 通过从操作开始时间减去当前时间来计算此值。
Only appears if the operation is running; i.e. if
activeistrue.
currentOp.opA string that identifies the specific operation type. Only present if
currentOp.typeisop.可能的值为:
"none""update""insert""query""command""getmore""remove""killcursors"
"query"操作包括读取操作。"command"操作包括大多数命令,比如createIndexes和findAndModify。
currentOp.command包含与此操作相关的完整命令对象的文档。
例如,以下输出包含在
test数据库中items集合上执行的find操作的命令对象:"command" : { "find" : "items", "filter" : { "sku" : 1403978 }, ... "$db" : "test" } 以下示例输出包含
getMore操作的命令对象,该命令对象由游标 ID 为19234103609的命令在名为test的数据库中名为items的集合上生成:"command" : { "getMore" : Long("19234103609"), "collection" : "items", "batchSize" : 10, ... "$db" : "test" }, 如果命令文档的大小超过 1 KB,则文档的格式如下:
"command" : { "$truncated": <string>, "comment": <string> } $truncated字段包含文档的字符串概要,不包括文档的comment字段(如果存在)。如果概要仍然超过 1 KB,则会进一步截断,在字符串末尾用省略号 (...) 表示。如果将注释传递给操作,则会出现
comment字段。任何数据库命令都可以附加注释。
currentOp.cursorA document that contains the cursor information for
getmoreoperations; i.e. whereopisgetmore.If reporting on a
getmoreoperation before thegetmorehas accessed its cursor information, thecursorfield is not available.currentOp.cursor.noCursorTimeout此标记指示游标空闲时未超时;即,如果游标设置了
noTimeout选项。如果为 true,则游标在空闲时不会超时。
如果为 false,则游标在空闲时超时。
currentOp.cursor.tailable此标记指示游标是否为固定大小集合的可追加游标。在客户端用尽初始游标中的结果后,可追加游标将保持打开状态。
currentOp.waitingForLatchThe
waitingForLatchdocument is only available if the operation is waiting to acquire an internal locking primitive (a.k.a. a latch) or for an internal condition to be met.例如,
"waitingForLatch" : { "timestamp" : ISODate("2020-03-19T23:25:58.412Z"), "captureName" : "FutureResolution", }, 输出字段说明timestamp
操作开始等待的日期和时间。
captureName
当前操作受阻的区段的内部名称。
4.2.2版本新增。
currentOp.locksThe
locksdocument reports the type and mode of locks the operation currently holds. The possible lock types are as follows:锁类型说明ParallelBatchWriterMode代表并行批量写入模式的锁。
在早期版本中,PBWM 信息作为
Global锁信息的一部分进行报告。ReplicationStateTransition表示副本集节点状态转换采用的锁。
Global代表全局锁定。
Database代表数据库锁。
Collection代表集合锁。
Mutex代表互斥锁。
Metadata代表元数据锁。
oplog表示 oplog 上的锁。
可能的模式如下:
锁模式说明R代表共享(S)锁。
W代表独占 (X) 锁。
r代表意向共享(IS)锁。
w代表意图独占 (IX) 锁。
currentOp.admissionPriority供内部使用。该值是操作在尝试获取票证以执行存储引擎操作时所具有的优先级。
可能的值为:“低”、“正常”和“立即”。仅报告值为“低”的操作。
currentOp输出示例:{ type: 'op', host: 'ip-10-122-5-147:27017', desc: 'JournalFlusher', active: true, currentOpTime: '2022-10-11T12:45:52.053+00:00', opid: 201, op: 'none', ns: '', command: {}, numYields: 0, admissionPriority: 'low', locks: {}, waitingForLock: false, lockStats: {}, waitingForFlowControl: false, flowControlStats: {} } admissionPriority值还会记录在慢速日志中。6.3版本新增。
currentOp.waitingForLockReturns a boolean value.
waitingForLockistrueif the operation is waiting for a lock andfalseif the operation has the required lock.
currentOp.msgThe
msgprovides a message that describes the status and progress of the operation. In the case of indexing or mapReduce operations, the field reports the completion percentage.
currentOp.progressReports on the progress of mapReduce or indexing operations. The
progressfields corresponds to the completion percentage in themsgfield. Theprogressspecifies the following information:
currentOp.numYieldsnumYields是计数器,用于报告为让其他操作完成而让出的操作次数。通常,当操作需要访问 MongoDB 尚未完全读入内存的数据时,它们就会让出。这使得在 MongoDB 读取让出操作的数据时,其他已经在内存中有数据的操作可以完成。
currentOp.dataThroughputLastSecondvalidate操作在上一秒处理的数据量(以 MiB 为单位)。仅适用于当前正在扫描文档的validate操作。例如:"msg" : "Validate: scanning documents Validate: scanning documents: 7258/24000 30%", "progress" : { "done" : 7258, "total" : 24000 }, "numYields" : 0, "dataThroughputLastSecond" : 15.576952934265137, "dataThroughputAverage" : 15.375944137573242,
currentOp.dataThroughputAveragevalidate操作处理的平均数据量(以 MiB 为单位)。仅适用于当前正在扫描文档的validate操作。例如:"msg" : "Validate: scanning documents Validate: scanning documents: 7258/24000 30%", "progress" : { "done" : 7258, "total" : 24000 }, "numYields" : 0, "dataThroughputLastSecond" : 15.576952934265137, "dataThroughputAverage" : 15.375944137573242,
currentOp.fsyncLock指定当前是否已为
fsync write/snapshot锁定数据库。Only appears if locked; i.e. if
fsyncLockistrue.
currentOp.infoInformation regarding how to unlock database from
db.fsyncLock(). Only appears iffsyncLockistrue.
currentOp.lockStatsFor each lock type and mode (see
currentOp.locksfor descriptions of lock types and modes), returns the following information:currentOp.lockStats.acquireWaitCountNumber of times the operation had to wait for the
acquireCountlock acquisitions because the locks were held in a conflicting mode.acquireWaitCountis less than or equal toacquireCount.
currentOp.lockStats.timeAcquiringMicros操作获取锁所需等待的累计时间(以微秒为单位)。
timeAcquiringMicrosdivided byacquireWaitCountgives an approximate average wait time for the particular lock mode.
currentOp.waitingForFlowControl一个布尔值,指示操作是否正在等待流控制。
currentOp.totalOperationTimeElapsedSecs当前重新分片操作所用的总时间(秒)。开始新的重新分片操作时,时间设置为 0。
仅当正在进行重新分片操作时才存在。
版本 5.0 中的新增功能。
从 MongoDB 6.1 开始,该指标在重新分片期间也可在协调器上使用。
currentOp.remainingOperationTimeEstimatedSecsremainingOperationTimeEstimatedSecs:当前重新分片操作的预计剩余时间(以秒为单位)。当新的重新分片操作开始时,将返回-1。开始于:
MongoDB 5.0,但在 MongoDB 6.1 之前,
remainingOperationTimeEstimatedSecs仅在重新分片操作期间在接收分片上可用。MongoDB 6.1,在重新分片操作期间,协调器上也可以使用
remainingOperationTimeEstimatedSecs。
重新分片操作按顺序执行以下阶段:
克隆阶段复制当前的集合数据。
追赶阶段将所有待处理的写入操作应用于重新分片的集合。
remainingOperationTimeEstimatedSecs设置为悲观的时间估计值:将追赶阶段时间估计值设置为克隆阶段时间,这是一个相对较长的时间。
实际上,如果只有几个待处理的写入操作,则实际的追赶阶段时间相对较短。
版本 5.0 中的新增功能。
currentOp.allShardsLowestRemainingOperationTimeEstimatedSecs在所有分片上计算的剩余秒数的最低估值。
仅在执行重新分片操作时才出现在协调器上。
6.1版本新增。
currentOp.allShardsHighestRemainingOperationTimeEstimatedSecs在所有分片上计算的剩余描述的最高估值。
仅在执行重新分片操作时才出现在协调器上。
6.1版本新增。
currentOp.approxDocumentsToCopy在重新分片操作期间要从发送分片复制到接收分片的大致文档数量。此数字是在重新分片操作开始时设置的估计值,设置后不会更改。开始新的重新分片操作时,该数字将被设置为 0。如果重新分片后的数据分布不完全均匀,则
$currentOp.documentsCopied和$currentOp.bytesCopied最终可能分别超过$currentOp.approxDocumentsToCopy和$currentOp.approxBytesToCopy。仅在执行重新分片操作时出现在接收分片上。
版本 5.0 中的新增功能。
currentOp.documentsCopied在重新分片操作期间,从发送分片复制到接收分片的文档数量。开始新的重新分片操作时,该数字设置为 0。
仅在执行重新分片操作时出现在接收分片上。
版本 5.0 中的新增功能。
currentOp.approxBytesToCopy在重新分片操作期间从发送分片复制到接收分片的大致字节数。此数字是在重新分片操作开始时设置的估计值,设置后不会更改。开始新的重新分片操作时,该数字将被设置为 0。如果重新分片后的数据分布不完全均匀,则
$currentOp.documentsCopied和$currentOp.bytesCopied最终可能分别超过$currentOp.approxDocumentsToCopy和$currentOp.approxBytesToCopy。仅在执行重新分片操作时出现在接收分片上。
版本 5.0 中的新增功能。
currentOp.bytesCopied在重新分片操作期间从捐赠分片复制到接收分片的字节数。开始新的重新分片操作时,该数字被设置为 0。
仅在执行重新分片操作时出现在接收分片上。
版本 5.0 中的新增功能。
currentOp.countWritesToStashCollections写入接收储藏集合的次数。
仅在执行重新分片操作时出现在接收分片上。
6.1版本新增。
currentOp.totalCopyTimeElapsedSecs当前重新分片操作从发送分片到接收分片的持续数据复制任务所花费的总时间(以秒计)。开始新的重新分片操作时,时间设置为 0。
仅在执行重新分片操作时出现在接收分片上。
版本 5.0 中的新增功能。
从 MongoDB 6.1 开始,该指标在重新分片期间也可在协调器上使用。
currentOp.oplogEntriesFetched从当前重新分片操作的 oplog 获取的条目数。开始新的重新分片操作时,该数字将被设置为 0。
仅在执行重新分片操作时出现在接收分片上。
版本 5.0 中的新增功能。
currentOp.oplogEntriesApplied应用于当前的重新分片操作的 oplog 的条目数。开始新的重新分片操作时,该数字将被设置为 0。
仅在执行重新分片操作时出现在接收分片上。
版本 5.0 中的新增功能。
currentOp.totalApplyTimeElapsedSecs当前重新分片操作的应用步骤所用的总时间(以秒为单位)。在应用步骤中,接收分片应用 oplog 条目,根据来自发送分片的新传入写入来修改其数据。开始新的重新分片操作时,时间设置为 0。
仅在执行重新分片操作时出现在接收分片上。
版本 5.0 中的新增功能。
从 MongoDB 6.1 开始,该指标在重新分片期间也可在协调器上使用。
currentOp.countWritesDuringCriticalSection当前重新分片操作在关键部分执行的写入次数。关键部分可防止对当前正在重新分片的集合进行新的传入写入。开始新的重新分片操作时,该数字将被设置为 0。
仅在执行重新分片操作时才出现在发送分片上。
版本 5.0 中的新增功能。
currentOp.totalCriticalSectionTimeElapsedSecs当前重新分片操作的关键部分所用的总时间(以秒为单位)。关键部分可防止对当前正在重新分片的集合进行新的传入写入。开始新的重新分片操作时,时间设置为 0。
仅在执行重新分片操作时才出现在发送分片上。
版本 5.0 中的新增功能。
从 MongoDB 6.1 开始,该指标在重新分片期间也可在协调器上使用。
currentOp.donorState重新分片操作中发送分片的当前状态。当新的重新分片操作开始时,该状态将被设置为
unused。仅在执行重新分片操作时才出现在发送分片上。
州说明unused重新分片操作即将开始或从主节点故障转移中恢复。
preparing-to-donate源分片正准备向接收分片提供数据。
donating-initial-data发送分片正在向接收分片发送数据。
donating-oplog-entries发送分片正在向接收分片发送 oplog 条目。
preparing-to-block-writes发送分片即将阻止对正在重新分片的集合进行新的传入写入操作。
error重新分片操作过程中发生错误。
blocking-writes发送分片正在阻止新的传入写入操作,并且发送分片已通知所有接收分片新的传入写入已禁止。
done发送分片已经删除旧的分片集合,重新分片操作已完成。
版本 5.0 中的新增功能。
currentOp.recipientState重新分片操作中接收分片的当前状态。当新的重新分片操作开始时,该状态将被设置为
unused。仅在执行重新分片操作时才出现在发送分片上。
州说明unused重新分片操作即将开始或从主节点故障转移中恢复。
awaiting-fetch-timestamp接收分片正在等待发送分片做好发送数据的准备。
creating-collection接收分片正在创建新的分片集合。
cloning接收分片正在接收来自发送分片的数据。
applying接收分片正在应用 oplog 条目,以根据来自发送分片的新传入写入来修改数据副本。
error重新分片操作过程中发生错误。
strict-consistency接收分片将所有数据更改存储在临时集合中。
done重新分片操作已完成。
版本 5.0 中的新增功能。
currentOp.coordinatorState当前重新分片操作的重新分片协调器的状态。重新分片协调器是在配置服务器主节点上运行的操作。当新的重新分片操作开始时,该状态将被设置为
unused。仅存在于协调配置服务器上。
州说明unused重新分片操作即将开始或从主节点故障转移中恢复。
initializing重新分片协调器已将协调器文档插入
config.reshardingOperations中,并将reshardingFields添加到原始集合的config.collections条目中。preparing-to-donate重新分片协调器
已为临时重新分片集合创建了一个
config.collections条目。已在
config.chunks中插入了基于新分片键的范围条目。已将条目插入到与新分片键关联的任何区域的
config.tags中。
协调器通知参与分片开始重新分片操作。然后,协调器将等待,直到所有发送分片都选择了一个
minFetchTimestamp并准备好发送。cloning重新分片协调节点通知发送分片将数据发送给接收分片。协调节点等待所有接收分片完成对发送分片数据的克隆。
applying重新分片协调器通知接收分片根据来自发送分片的新传入写入来修改其数据副本。协调器等待所有接收分片完成应用 oplog 条目。
blocking-writes重新分片协调节点通知发送分片,以防止对正在重新分片的集合进行新的传入写入操作。然后,协调节点等待所有接收分片进行所有数据更改。
aborting在重新分片操作或运行
abortReshardCollection命令(或sh.abortReshardCollection()方法)期间出现不可恢复的错误。committing重新分片协调器删除了临时重新分区集合的
config.collections条目。然后,协调器将recipientFields添加到源集合的条目中。版本 5.0 中的新增功能。
currentOp.startTime查询采样开始的时间。
此字段仅显示在与查询采样相关的文档上。有关详细信息,请参阅采样查询。
7.0版本新增。
currentOp.samplesPerSecond每秒待采样的最大查询数。
在分片集群上,这在
mongos上而不是mongod上报告。在副本集上,mongod会报告此问题。此字段仅显示在与查询采样相关的文档上。有关详细信息,请参阅采样查询。
7.0版本新增。
currentOp.sampledReadsCount已采样读取查询的总数。
此字段仅显示在与查询采样相关的文档上。有关详细信息,请参阅采样查询。
7.0版本新增。
currentOp.sampledWritesCount采样写入查询的总数。
此字段仅显示在与查询采样相关的文档上。有关详细信息,请参阅采样查询。
7.0版本新增。
currentOp.sampledReadsBytes采样读取查询的大小,以字节为单位。
在副本集上,每个
mongod都会报告此问题。在分片集群上,这仅在启用了
--shardsvr的mongod上报告。此字段仅显示在与查询采样相关的文档上。有关详细信息,请参阅采样查询。
7.0版本新增。
currentOp.sampledWritesBytes采样写入查询的大小,以字节为单位。
在副本集上,每个
mongod都会报告此问题。在分片集群上,这仅在启用了
--shardsvr的mongod上报告。此字段仅显示在与查询采样相关的文档上。有关详细信息,请参阅采样查询。
7.0版本新增。