Skip to content

Commit 4db3ca3

Browse files
author
Kay Kim
committed
DOCS-12247: killOps on sharded clusters
1 parent 3440aeb commit 4db3ca3

File tree

3 files changed

+272
-11
lines changed

3 files changed

+272
-11
lines changed

source/reference/command/killOp.txt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ Definition
4040
.. include:: /includes/extracts/warning-terminating-ops-command.rst
4141

4242

43-
.. versionchanged:: 4.0
44-
45-
The ``killOp`` command can be run on a :binary:`~bin.mongos` and can
46-
kill queries that span shards in a cluster. For information on how
47-
to list sharding operations that are active on a mongos, see the
48-
``localOps`` parameter in :pipeline:`$currentOp`.
4943

5044
Access Control
5145
--------------
@@ -58,6 +52,25 @@ includes the :authaction:`killop` privilege action.
5852
On :binary:`~bin.mongod` instances, users can kill their own operations
5953
even without the :authaction:`killop` privilege action.
6054

55+
Sharded Cluster
56+
---------------
57+
58+
Starting in MongoDB 4.0, the :dbcommand:`killOp` command can be run on
59+
a :binary:`~bin.mongos` and can kill queries (i.e. read operations)
60+
that span shards in a cluster. The :dbcommand:`killOp` command from the
61+
:binary:`~bin.mongos` does not propagate to the shards when the
62+
operation to be killed is a write operation.
63+
64+
For information on how to list sharding operations that are active on a
65+
mongos, see the ``localOps`` parameter in :pipeline:`$currentOp`.
66+
67+
For more information and examples on killing operations on a sharded
68+
cluster, see:
69+
70+
- :ref:`kill-read-ops-sharded-cluster`
71+
72+
- :ref:`kill-write-ops-sharded-cluster`
73+
6174
Example
6275
-------
6376

source/reference/command/killSessions.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,7 @@ The following operation kills the specified session for the user:
6565
.. code-block:: javascript
6666

6767
db.runCommand( { killSessions: [ { id: UUID("f9b3d8d9-9496-4fff-868f-04a6196fc58a") } ] } )
68+
69+
.. seealso::
70+
71+
:ref:`kill-write-ops-sharded-cluster`

source/reference/method/db.killOp.txt

Lines changed: 249 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,254 @@ Description
2727

2828
.. include:: /includes/extracts/warning-terminating-ops-method.rst
2929

30-
.. versionchanged:: 4.0
3130

32-
The ``db.killOp()`` method can be run on a :binary:`~bin.mongos` and can
33-
kill queries that are running on more than one shard in a cluster.
34-
For information on how to list sharding operations that are active on
35-
a mongos, see the ``localOps`` parameter in :pipeline:`$currentOp`.
31+
Sharded Cluster
32+
---------------
33+
34+
.. _kill-read-ops-sharded-cluster:
35+
36+
Kill Read Operations
37+
~~~~~~~~~~~~~~~~~~~~
38+
39+
Starting in MongoDB 4.0
40+
The :method:`db.killOp()` method can be run on a
41+
:binary:`~bin.mongos` and can kill queries that are running on more
42+
than one shard in a cluster.
43+
44+
For example, to kill a query operation on a MongoDB 4.0+ sharded
45+
cluster:
46+
47+
.. tabs::
48+
49+
tabs:
50+
51+
- id: mongos
52+
name: From the mongos Instance
53+
content: |
54+
55+
#. On the **same** :binary:`~bin.mongos` where the client issued the
56+
query, find the opid of the query operation to kill by running the
57+
aggregation pipeline :pipeline:`$currentOp` with the ``localOps:
58+
true``:
59+
60+
.. code-block:: javascript
61+
62+
use admin
63+
db.aggregate( [
64+
{ $currentOp : { allUsers: true, localOps: true } },
65+
{ $match : <filter condition> } // Optional. Specify the condition to find the op.
66+
// e.g. { op: "getmore", "command.collection": "someCollection" }
67+
] )
68+
69+
.. important::
70+
71+
You must issue this aggregation operation on the **same**
72+
:binary:`~bin.mongos` where the client issued the query.
73+
74+
#. Once you find the query operation to kill, issue
75+
:method:`db.killOp()` with the opid on the :binary:`~bin.mongos`:
76+
77+
.. code-block:: javascript
78+
79+
db.killOp(<opid of the query to kill>)
80+
81+
.. seealso:: The ``localOps`` parameter in :pipeline:`$currentOp`.
82+
83+
- id: mongod
84+
name: From a shard member
85+
content: |
86+
87+
Alternatively, you can find and kill the operation from a
88+
shard member where the operation is running. MongoDB 4.0+
89+
propagates the kill operation to the other shards and
90+
:binary:`~bin.mongos` instances:
91+
92+
#. On one of the shards where the operation is running, find the opid
93+
of the query operation to kill:
94+
95+
.. code-block:: javascript
96+
97+
use admin
98+
db.aggregate( [
99+
{ $currentOp : { allUsers: true } },
100+
{ $match : <filter condition> } // Optional. Specify the condition to find the op.
101+
// e.g. { op: "getmore", "command.collection": "someCollection" }
102+
] )
103+
104+
#. Once you find the query operation to kill, issue
105+
:method:`db.killOp()` with the opid on the shard member:
106+
107+
.. code-block:: javascript
108+
109+
db.killOp(<opid of the query to kill>)
110+
111+
MongoDB 4.0+ propagates the kill operation to the
112+
other shards and :binary:`~bin.mongos` instances.
113+
114+
For MongoDB 3.6 and earlier
115+
To kill a query running on 3.6 (or earlier) sharded clusters, you must kill the
116+
operation on all the shards associated with the query.
117+
118+
#. From a :binary:`~bin.mongos`, run the aggregation pipeline
119+
:pipeline:`$currentOp` to find the opid(s) of the query operation on
120+
the shards:
121+
122+
.. code-block:: javascript
123+
124+
use admin
125+
db.aggregate( [
126+
{ $currentOp : { allUsers: true } },
127+
{ $match : <filter condition> } // Optional. Specify the condition to find the op.
128+
// e.g. { op: "getmore", "command.collection": "someCollection" }
129+
] )
130+
131+
When run on a :binary:`~bin.mongos`, :pipeline:`$currentOp`
132+
returns the opids in the format of ``"<shardName>:<opid on that
133+
shard>"``; e.g.
134+
135+
.. code-block:: javascript
136+
137+
{
138+
"shard" : "shardB",
139+
..
140+
"opid" : "shardB:79014",
141+
...
142+
},
143+
{
144+
"shard" : "shardA",
145+
..
146+
"opid" : "shardA:100813",
147+
...
148+
},
149+
150+
151+
#. Using the opid information, issue :method:`db.killOp()` on the
152+
:binary:`~bin.mongos` to kill the operation on the shards.
153+
154+
.. code-block:: javascript
155+
156+
db.killOp("shardB:79014");
157+
db.killOp("shardA:100813");
158+
159+
160+
.. _kill-write-ops-sharded-cluster:
161+
162+
Kill Write Operations
163+
~~~~~~~~~~~~~~~~~~~~~
164+
165+
Within a Session
166+
Starting in MongoDB 3.6, MongoDB drivers associate all operations
167+
with a :doc:`server session </reference/server-sessions>`, with the
168+
exception of unacknowledged writes.
169+
170+
If the write operation is associated with a session, you can use the
171+
:dbcommand:`killSessions` command on the :binary:`~bin.mongos` to
172+
kill the write operation across shards.
173+
174+
.. tabs::
175+
176+
tabs:
177+
178+
- id: "4.0"
179+
name: "MongoDB 4.0+"
180+
content: |
181+
182+
#. Run the aggregation pipeline :pipeline:`$currentOp` on
183+
the :binary:`~bin.mongos` to find the
184+
``lsid`` (logical session id).
185+
186+
.. code-block:: javascript
187+
188+
use admin
189+
db.aggregate( [
190+
{ $currentOp : { allUsers: true, localOps: true } },
191+
{ $match : <filter condition> } // Optional. Specify the condition to find the op.
192+
// e.g. { "op" : "update", "ns": "mydb.someCollection" }
193+
] )
194+
195+
#. Using the returned ``lsid`` information, issue the
196+
:dbcommand:`killSessions` command on the
197+
:binary:`~bin.mongos` to kill the operation on the shards.
198+
199+
.. code-block:: javascript
200+
201+
db.adminCommand( { killSessions: [
202+
{ "id" : UUID("80e48c5a-f7fb-4541-8ac0-9e3a1ed224a4"), "uid" : BinData(0,"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=") }
203+
] } )
204+
205+
206+
- id: "3.6"
207+
name: "MongoDB 3.6"
208+
content: |
209+
210+
#. Run the aggregation pipeline :pipeline:`$currentOp` on
211+
the :binary:`~bin.mongos` or the individual shards find the
212+
``lsid`` (logical session id).
213+
214+
.. code-block:: javascript
215+
216+
use admin
217+
db.aggregate( [
218+
{ $currentOp : { allUsers: true } },
219+
{ $match : <filter condition> } // Optional. Specify the condition to find the op.
220+
// e.g. { "op" : "update", "ns": "mydb.someCollection" }
221+
] )
222+
223+
#. Using the returned lsid information, issue the
224+
:dbcommand:`killSessions` command on the
225+
:binary:`~bin.mongos` to kill the operation on the
226+
shards.
227+
228+
.. code-block:: javascript
229+
230+
db.adminCommand( { killSessions: [
231+
{ "id" : UUID("80e48c5a-f7fb-4541-8ac0-9e3a1ed224a4"), "uid" : BinData(0,"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=") }
232+
] } )
233+
234+
Without a Session
235+
If the write operation is **not** associated with a session, you must find and kill the
236+
operation on all the shards associated with the write.
237+
238+
239+
#. From a :binary:`~bin.mongos`, run the aggregation pipeline
240+
:pipeline:`$currentOp` to find the opid(s) of the query operation on
241+
the shards:
242+
243+
.. code-block:: javascript
244+
245+
use admin
246+
db.aggregate( [
247+
{ $currentOp : { allUsers: true } },
248+
{ $match : <filter condition> } // Optional. Specify the condition to find the op.
249+
] )
250+
251+
When run on a :binary:`~bin.mongos`, :pipeline:`$currentOp`
252+
returns the opids in the format of ``"<shardName>:<opid on that
253+
shard>"``; e.g.
254+
255+
.. code-block:: javascript
256+
257+
{
258+
"shard" : "shardB",
259+
..
260+
"opid" : "shardB:79214",
261+
...
262+
},
263+
{
264+
"shard" : "shardA",
265+
..
266+
"opid" : "shardA:100913",
267+
...
268+
},
269+
270+
#. Using the opid information, issue :method:`db.killOp()` on the
271+
:binary:`~bin.mongos` to kill the operation on the shards.
272+
273+
.. code-block:: javascript
274+
275+
db.killOp("shardB:79014");
276+
db.killOp("shardA:100813");
277+
36278

37279
Access Control
38280
--------------
@@ -44,3 +286,5 @@ includes the :authaction:`killop` privilege action.
44286
.. versionchanged:: 3.2.9
45287
On :binary:`~bin.mongod` instances, users can kill their own operations
46288
even without the :authaction:`killop` privilege action.
289+
290+
.. seealso:: :pipeline:`$currentOp`

0 commit comments

Comments
 (0)