db.killOp()
On this page本页内容
Description描述
db.killOp(opid)
-
Terminates an operation as specified by the operation ID.根据操作ID指定终止操作。To find operations and their corresponding IDs, see要查找操作及其相应的ID,请参阅$currentOp
ordb.currentOp()
.$currentOp
或db.currentOp()
。Thedb.killOp()
method has the following parameter:db.killOp()
方法具有以下参数:Parameter参数Type类型Description描述op
number An operation ID.操作ID。WarningTerminate running operations with extreme caution.终止运行操作时要格外小心。Only use仅使用db.killOp()
to terminate operations initiated by clients and do not terminate internal database operations.db.killOp()
终止客户端启动的操作,而不终止内部数据库操作。
Sharded Cluster分片集群
Kill Read Operations终止读取操作
The db.killOp()
method can be run on a mongos
and can kill queries (read operations) that are running on more than one shard in a cluster.db.killOp()
方法可以在mongos
上运行,并可以终止在集群中多个分片上运行的查询(读取操作)。
For example, to kill a query operation on a sharded cluster:例如,要终止对分片集群的查询操作:
-
On the same在客户端发出查询的同一mongos
where the client issued the query, find the opid of the query operation to kill by running the aggregation pipeline$currentOp
with thelocalOps:true
:mongos
上,通过运行带有localOps:true
的聚合管道$currentOp
来找到要杀掉的查询操作的opid:use admin
db.aggregate( [
{ $currentOp : { allUsers: true, localOps: true } },
{ $match : <filter condition> } // Optional. Specify the condition to find the op.
// e.g. { op: "getmore", "command.collection": "someCollection" }
] )ImportantYou must issue this aggregation operation on the same您必须在客户端发出查询的同一mongos
where the client issued the query.mongos
上发出此聚合操作。 -
Once you find the query operation to kill, issue找到要终止的查询操作后,在db.killOp()
with the opid on themongos
:mongos
上发出带有opid的db.killOp()
:db.killOp(<opid of the query to kill>)
See also: 另请参阅:
The localOps
parameter in $currentOp
.$currentOp
中的localOps
参数。
Alternatively, you can find and kill the read operation from a shard member where the operation is running. MongoDB propagates the kill operation to the other shards and 或者,您可以从运行读取操作的分片成员中查找并终止该操作。MongoDB将kill操作传播到其他分片和mongos
instances:mongos
实例:
-
On one of the shards where the operation is running, find the opid of the query operation to kill:在运行该操作的一个分片上,找到要终止的查询操作的opid:use admin
db.aggregate( [
{ $currentOp : { allUsers: true } },
{ $match : <filter condition> } // Optional. Specify the condition to find the op.
// e.g. { op: "getmore", "command.collection": "someCollection" }
] ) -
Once you find the query operation to kill, issue找到要终止的查询操作后,在分片成员上发出带有opid的db.killOp()
with the opid on the shard member:db.killOp()
:db.killOp(<opid of the query to kill>)
MongoDB propagates the kill operation to the other shards andMongoDB将kill操作传播到其他分片和mongos
instances.mongos
实例。
Kill Write Operations终止写入操作
Within a Session在会话中-
MongoDB drivers associate all operations with a server session, with the exception of unacknowledged writes.MongoDB驱动程序将所有操作与服务器会话相关联,但未确认的写入除外。If the write operation is associated with a session, you can use the如果写操作与会话相关联,则可以在killSessions
command on themongos
to kill the write operation across shards.mongos
上使用killSessions
命令来终止跨分片的写操作。Run the aggregation pipeline在$currentOp
on themongos
to find thelsid
(logical session id).mongos
上运行聚合管道$currentOp
以查找lsid
(逻辑会话id)。use admin
db.aggregate( [
{ $currentOp : { allUsers: true, localOps: true } },
{ $match : <filter condition> } // Optional. Specify the condition to find the op.
// e.g. { "op" : "update", "ns": "mydb.someCollection" }
] )Using the returned使用返回的lsid
information, issue thekillSessions
command on themongos
to kill the operation on the shards.lsid
信息,在mongos
上发出killSessions
命令以终止对分片的操作。db.adminCommand( { killSessions: [
{ "id" : UUID("80e48c5a-f7fb-4541-8ac0-9e3a1ed224a4"), "uid" : BinData(0,"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=") }
] } )
Without a Session没有会话-
If the write operation is not associated with a session, you must find and kill the operation on all the shards associated with the write.如果写入操作与会话不关联,则必须查找并终止与写入关联的所有分片上的操作。From a从mongos
, run the aggregation pipeline$currentOp
to find the opid(s) of the query operation on the shards:mongos
中,运行聚合管道$currentOp
来查找分片上查询操作的opid:use admin
db.aggregate( [
{ $currentOp : { allUsers: true } },
{ $match : <filter condition> } // Optional. Specify the condition to find the op.
] )When run on a当在mongos
,$currentOp
returns the opids in the format of"<shardName>:<opid on that shard>"
; e.g.mongos
上运行时,$currentOp
以"<shardName>:<opid on that shard>"
的格式返回opid;例如。{
"shard" : "shardB",
..
"opid" : "shardB:79214",
...
},
{
"shard" : "shardA",
..
"opid" : "shardA:100913",
...
},Using the opid information, issue使用opid信息,在db.killOp()
on themongos
to kill the operation on the shards.mongos
上发出db.killOp()
来终止对分片的操作。db.killOp("shardB:79014");
db.killOp("shardA:100813");
Access Control访问控制
On systems running with 在使用authorization
, to kill operations not owned by the user, the user must have access that includes the killop
privilege action.authorization
运行的系统上,要终止非用户所有的操作,用户必须具有包括killop
权限操作的访问权限。
On 在mongod
instances, users can kill their own operations even without the killop
privilege action.mongod
实例中,即使没有killop
权限操作,用户也可以终止自己的操作。