kaloianm / workscripts

Miscellaneous scripts to improve my MongoDB work productivity
The Unlicense
11 stars 11 forks source link

Defrag script crash on 4.4 due to unexpected balancer setting format. #57

Closed toto-dev closed 2 years ago

toto-dev commented 2 years ago

On a 4.4.10 cluster:

╰─ ./defragment_sharded_collection.py "mongodb://user:password@localhost:27017"  --ns "POCDB.POCCOLL" --phases phase1                                                                                                                                                                                                                                                    ─╯
2021-11-05 10:53:45,047 [INFO] Starting with parameters: 'mongodb://user:password@localhost:27017 --ns POCDB.POCCOLL --phases phase1'
Server is running at FCV 4.4
Traceback (most recent call last):
  File "./defragment_sharded_collection.py", line 1069, in <module>
    loop.run_until_complete(main(args))
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "./defragment_sharded_collection.py", line 222, in main
    if not args.dryrun and (balancer_doc is None or balancer_doc['mode'] != 'off'):
KeyError: 'mode'

#----------------

Renatos-MBP-2(mongos-4.4.10)[mongos] config> db.settings.find()
{
  "_id": "balancer",
  "stopped": true
}
toto-dev commented 2 years ago

We should use the balancerStatus command to check if the balancer is on. The result of this command is guaranteed to be consistent on all the supported releases.