How to "restart" Cloud MongoDB Atlas Database

Viewed 3161

Today I was stress testing multiprocessing in Python against our cloud MongoDB (Atlas).

It's currently running at 100%, and I'd like to do something like a "restart". I have found a "Shutdown" command, but I can't find a command to start it up after it has shutdown, so I'm afraid to run just the "Shutdown".

I have tried killing processes one at a time in the lower right section of the screen below, but after refreshing the page, the same processes numbers are there, and I think there are more on the bottom of the list. I think they are all backed up.

Doing an insert of a large document does not return to the Python program in 5 minutes. I need to get that working again (should update in 10-15 seconds as it has in the past).

I am able to open a command window and connect to that server. Just unclear what commands to run.

enter image description here

Here is an example of how I tried to kill some of the processes:

enter image description here

Also note that the "Performance Adviser" page is not recommending any new indexes.

Update 1:

Alternatively, can I kill all running, hung, or locked processes? I was reading about killop here:(https://docs.mongodb.com/manual/tutorial/terminate-running-operations/), but found it confusing with the versions, and the fact that I'm using Atlas.

1 Answers

I'm not sure if there is an easier way, but this is what I did.

First, I ran a Python program to extract all the desired operation IDs based on my database and collection name. You have to look at the file created to understand the if statements in the code below. NOTE: it says that db.current_op is deprecated, and I haven't found out how to do this without that command (from PyMongo).

Note the doc page warns against killing certain types of operations, so I was careful to pick ones that were doing inserts on one specific collection. (Do not attempt to kill all processes in the JSON returned).

import requests
import os
import sys
import traceback
import pprint
import json
from datetime import datetime as datetime1, timedelta, timezone
import datetime
from time import time
import time as time2
import configHandler
import pymongo
from pymongo import MongoClient
from uuid import UUID

def uuid_convert(o):
        if isinstance(o, UUID):
            return o.hex


# This get's all my config from a config.json file, not including that code here. 
config_dict = configHandler.getConfigVariables()

cluster = MongoClient(config_dict['MONGODB_CONNECTION_STRING_ADMIN'])
db = cluster[config_dict['MONGODB_CLUSTER']]
current_ops = db.current_op(True)

count_ops = 0
for op in current_ops["inprog"]:
    count_ops += 1
    #db.kill- no such command
    if op["type"] == "op":
        if "op" in op:
            if op["op"] == "insert" and op["command"]["insert"] == "TestCollectionName":
                #print(op["opid"], op["command"]["insert"])
                print('db.adminCommand({"killOp": 1, "op": ' + str(op["opid"]) + '})')

print("\n\ncount_ops=", count_ops)

currDateTime = datetime.datetime.now()

print("type(current_ops) = ", type(current_ops))
# this dictionary has nested fields
# current_ops_str = json.dumps(current_ops, indent=4)

# https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior
filename = "./data/currents_ops" + currDateTime.strftime("%y_%m_%d__%H_%M_%S") + ".json"
with open(filename, "w") as file1:
    #file1.write(current_ops_str)
    json.dump(current_ops, file1, indent=4, default=uuid_convert)
    print("Wrote to filename=", filename)

It writes the full ops file to disk, but I did a copy/paste from the command windows to a file. Then from the command line, I ran something like this:

mongo "mongodb+srv://mycluster0.otwxp.mongodb.net/mydbame" --username myuser --password abc1234 <kill_opid_script.js

The kill_opid_script.js looked like this. I added the print(db) because the first time I ran it didn't seem to do anything.

print(db)
db.adminCommand({"killOp": 1, "op": 648685})
db.adminCommand({"killOp": 1, "op": 667396})
db.adminCommand({"killOp": 1, "op": 557439})
 etc... for 400+ times... 
print(db)
Related