Allow identifying a long-running or stuck query and killing it
Answered
Sometimes I run a query that doesn't use an index and it can take a very long time. I stop it in NoSQLBooster, but it doesn't kill the actual operation.
I need to use the following to find the query:
db.currentOp().inprog.forEach( function(op) { if(op.secs_running > 5 && op.ns != "local.oplog.rs" && op.ns != "local.replset.minvalid") printjson(op); } )And then kill the stuck operation manually. It would be great if NoSQLBooster could help me with this process.
After you press the stop button, NoSQLBooster will call db.killOp(). But MongoDB's killOp doesn't take effect immediately. if you call db.currentOp, you will find that the flag bit of killPending has flagged.
According to MongoDB online doc, currentOp.killPending Returns true if the operation is currently flagged for termination. When the operation encounters its next safe termination point, the operation will terminate.
BTW, NoSQLBooster has some build-in currentOp snippets. Enter "db.currentOp" to popup code-complete list. The following one is to return information on all active operations for db that have been running longer than 3 seconds.
After you press the stop button, NoSQLBooster will call db.killOp(). But MongoDB's killOp doesn't take effect immediately. if you call db.currentOp, you will find that the flag bit of killPending has flagged.
According to MongoDB online doc, currentOp.killPending Returns true if the operation is currently flagged for termination. When the operation encounters its next safe termination point, the operation will terminate.
BTW, NoSQLBooster has some build-in currentOp snippets. Enter "db.currentOp" to popup code-complete list. The following one is to return information on all active operations for db that have been running longer than 3 seconds.
Unfortunately it does not work at all like you described. I am not sure if the problem is related to the fact that I am running these queries on the secondaries.
When I press the stop button, the query stops immediately. But it keeps running on the server "forever". There is no "killPending" flagged. If I try to run db.killOp() in NoSQLBooster, it doesn't do anything. I just have to press the stop on that command. The only way to kill the slow operation is to SSH to the instance and run it there.
Please advice.
Unfortunately it does not work at all like you described. I am not sure if the problem is related to the fact that I am running these queries on the secondaries.
When I press the stop button, the query stops immediately. But it keeps running on the server "forever". There is no "killPending" flagged. If I try to run db.killOp() in NoSQLBooster, it doesn't do anything. I just have to press the stop on that command. The only way to kill the slow operation is to SSH to the instance and run it there.
Please advice.
Thank you for your feedback. We have worked out a new test build to support killOp with "secondary mode" connection please download and give it a try.
https://nosqlbooster.com/s3/download/releasesv4/nosqlbooster4mongo-4.5.5.dmg
Thank you for your feedback. We have worked out a new test build to support killOp with "secondary mode" connection please download and give it a try.
https://nosqlbooster.com/s3/download/releasesv4/nosqlbooster4mongo-4.5.5.dmg
Calling killOp manually works now. Thank you!
Unfortunately pressing stop still does not kill the operation, so I have to do it manually which is inconvenient.
Calling killOp manually works now. Thank you!
Unfortunately pressing stop still does not kill the operation, so I have to do it manually which is inconvenient.
Could you give me a sample script and some test data to recall the issue?
I tested the function with the following script which use $where function to simulate long-run query.
And, Use the following code to find long-run query .Could you give me a sample script and some test data to recall the issue?
I tested the function with the following script which use $where function to simulate long-run query.
And, Use the following code to find long-run query .I used the same to find the long running query.
To get an actual long-running query, I simply ran the following query on a collection with millions of entries and no index on field foo:
I pressed the "Stop" button and waited at least 30 seconds and the query was still running. It stopped immediately when I called db.killOp myself.Could you try to create a collection of (tens of) millions of entries and try the same?
I used the same to find the long running query.
To get an actual long-running query, I simply ran the following query on a collection with millions of entries and no index on field foo:
I pressed the "Stop" button and waited at least 30 seconds and the query was still running. It stopped immediately when I called db.killOp myself.Could you try to create a collection of (tens of) millions of entries and try the same?
I use NoSQLBooster's test data generator to generate 10M records, query without field index.
Then I run MongoDB shell method "show log", it shows that the kill op has been called.
2018-06-06T15:53:50.961+0800 I COMMAND [conn25] going to kill op: 510852018-06-06T15:53:50.963+0800 I COMMAND [conn24] command demo.transaction appName: "NoSQLBoosterV4" command: getMore { getMore: 227254540936, collection: "transaction", batchSize: 21.0, $clusterTime: { clusterTime: Timestamp(1528271623, 1), signature: { hash: BinData(0, 0000000000000000000000000000000000000000), keyId: 0.0 } }, $readPreference: { mode: "secondaryPreferred" }, $db: "demo" } originatingCommand: { find: "transaction", filter: { name: "xcvcvcx" }, limit: 21.0, batchSize: 0.0, $clusterTime: { c
I use NoSQLBooster's test data generator to generate 10M records, query without field index.
Then I run MongoDB shell method "show log", it shows that the kill op has been called.
2018-06-06T15:53:50.961+0800 I COMMAND [conn25] going to kill op: 510852018-06-06T15:53:50.963+0800 I COMMAND [conn24] command demo.transaction appName: "NoSQLBoosterV4" command: getMore { getMore: 227254540936, collection: "transaction", batchSize: 21.0, $clusterTime: { clusterTime: Timestamp(1528271623, 1), signature: { hash: BinData(0, 0000000000000000000000000000000000000000), keyId: 0.0 } }, $readPreference: { mode: "secondaryPreferred" }, $db: "demo" } originatingCommand: { find: "transaction", filter: { name: "xcvcvcx" }, limit: 21.0, batchSize: 0.0, $clusterTime: { c
I downloaded the binary again and tested multiple times. The on-going operation is never killed.
Here is the log:
The operation at 08:42:54 (going to kill op) is me manually killing the op after it was not killed by NoSQLBooster after about 40 seconds.I downloaded the binary again and tested multiple times. The on-going operation is never killed.
Here is the log:
The operation at 08:42:54 (going to kill op) is me manually killing the op after it was not killed by NoSQLBooster after about 40 seconds.Thank you for your patience, I am sorry, I uploaded a wrong test build, please re-download and try it again If it still does not work, please give me your MongoDB log.
https://nosqlbooster.com/s3/download/releasesv4/nosqlbooster4mongo-4.5.5.dmg
Thank you for your patience, I am sorry, I uploaded a wrong test build, please re-download and try it again If it still does not work, please give me your MongoDB log.
https://nosqlbooster.com/s3/download/releasesv4/nosqlbooster4mongo-4.5.5.dmg
I tried again using the latest build you linked to and the end result is exactly the same as before? Are you sure you are sending the right build? Could you include a build number in the file name and the "About" dialog so we could make sure I'm using the right version?
I called "show log" and it provides nothing more than what I pasted above.
I tried again using the latest build you linked to and the end result is exactly the same as before? Are you sure you are sending the right build? Could you include a build number in the file name and the "About" dialog so we could make sure I'm using the right version?
I called "show log" and it provides nothing more than what I pasted above.
Try start and stop script, focus to object tree then press CMD+SHIFT+ALT+F7 to show the developer tools windows. Can you see the killop log message in the console tab like the following picture? If read-preference mode is "primary", can this long-run query be terminated correctly?
And, What's your MongoDB server version and rs configuration? run db.version() and rs.conf()
Try start and stop script, focus to object tree then press CMD+SHIFT+ALT+F7 to show the developer tools windows. Can you see the killop log message in the console tab like the following picture? If read-preference mode is "primary", can this long-run query be terminated correctly?
And, What's your MongoDB server version and rs configuration? run db.version() and rs.conf()
Version is 3.4.14
RsConf:
There is no killop in the console. Only "connect..." (I needed to press ctrl+shift+alt+F7 even on a mac to open it)
Stopping did not work correctly on primary either.
Version is 3.4.14
RsConf:
There is no killop in the console. Only "connect..." (I needed to press ctrl+shift+alt+F7 even on a mac to open it)
Stopping did not work correctly on primary either.
If possible, could you please give me a temporarily accessible Mongodb RS (MongoDB URI) to recall the issue locally?
I can't reproduce the issue on my local test servers. I guess the problem is related to the specific configuration of the replica set or permissions. To solve this problem, I need a test environment and detailed steps to reproduce it?
Thanks a lot.
If possible, could you please give me a temporarily accessible Mongodb RS (MongoDB URI) to recall the issue locally?
I can't reproduce the issue on my local test servers. I guess the problem is related to the specific configuration of the replica set or permissions. To solve this problem, I need a test environment and detailed steps to reproduce it?
Thanks a lot.
Thank you for trying to figure out the problem!
Unfortunately I don't think I will be able to spend more time on this at this point. I will probably revive this topic when we've upgraded to a newer version of MongoDB.
Thank you for trying to figure out the problem!
Unfortunately I don't think I will be able to spend more time on this at this point. I will probably revive this topic when we've upgraded to a newer version of MongoDB.
Replies have been locked on this page!