@@ -27,12 +27,254 @@ Description
27
27
28
28
.. include:: /includes/extracts/warning-terminating-ops-method.rst
29
29
30
- .. versionchanged:: 4.0
31
30
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
+
36
278
37
279
Access Control
38
280
--------------
@@ -44,3 +286,5 @@ includes the :authaction:`killop` privilege action.
44
286
.. versionchanged:: 3.2.9
45
287
On :binary:`~bin.mongod` instances, users can kill their own operations
46
288
even without the :authaction:`killop` privilege action.
289
+
290
+ .. seealso:: :pipeline:`$currentOp`
0 commit comments