Skip to content

Commit 119d5e7

Browse files
author
Tim Vaillancourt
committed
updated .close() methods and moved get_configserver to use DB:admin_command
1 parent c6d5bcc commit 119d5e7

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

MongoBackup/Backup.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,8 @@ def run(self):
233233
self.balancer_sleep
234234
)
235235
self.sharding.get_start_state()
236-
self.sharding.stop_balancer()
237236
except Exception, e:
238-
self.exception("Problem connecting-to and/or stopping balancer! Error: %s" % e)
237+
self.exception("Problem connecting to the balancer! Error: %s" % e)
239238

240239
# get shard secondaries
241240
try:
@@ -248,10 +247,15 @@ def run(self):
248247
self.max_repl_lag_secs
249248
)
250249
self.secondaries = self.replset.find_secondaries()
251-
self.replset.close()
252250
except Exception, e:
253251
self.exception("Problem getting shard secondaries! Error: %s" % e)
254252

253+
# Stop the balancer:
254+
try:
255+
self.sharding.stop_balancer()
256+
except Exception, e:
257+
self.exception("Problem stopping the balancer! Error: %s" % e)
258+
255259
# start the oplog tailer threads
256260
if self.no_oplog_tailer:
257261
logging.warning("Oplog tailing disabled! Skipping")

MongoBackup/Replset.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(self, db, user, password, authdb, max_lag_secs):
2626
raise e
2727

2828
def close(self):
29-
return self.connection.close()
29+
pass
3030

3131
def get_rs_status(self):
3232
try:
@@ -154,16 +154,15 @@ def find_secondaries(self):
154154
shard_name, members = shard['host'].split('/')
155155
host, port = members.split(',')[0].split(":")
156156

157-
db = DB(host, port, self.user, self.password, self.authdb)
158-
self.replset = Replset(db, self.user, self.password, self.authdb, self.max_lag_secs)
157+
replset_db = DB(host, port, self.user, self.password, self.authdb)
158+
self.replset = Replset(replset_db, self.user, self.password, self.authdb, self.max_lag_secs)
159159
secondary = self.replset.find_secondary()
160160
shard_secondaries[shard_name] = secondary
161161

162162
self.replset.close()
163-
db.close()
163+
replset_db.close()
164164
return shard_secondaries
165165

166166
def close(self):
167167
if self.replset:
168168
self.replset.close()
169-
self.sharding.close()

MongoBackup/Sharding.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ def __init__(self, db, user=None, password=None, authdb='admin', balancer_wait_s
2727
raise e
2828

2929
def close(self):
30-
self.restore_balancer_state()
31-
return self.connection.close()
30+
return self.restore_balancer_state()
3231

3332
def get_start_state(self):
3433
self._balancer_state_start = self.get_balancer_state()
35-
logging.info("Began with balancer state: %s" % str(self._balancer_state_start))
34+
logging.info("Began with balancer state running: %s" % str(self._balancer_state_start))
3635
return self._balancer_state_start
3736

3837
def shards(self):
@@ -96,7 +95,7 @@ def stop_balancer(self):
9695
raise Exception, "Could not stop balancer: %s:%i" % (self.host, self.port), None
9796

9897
def get_configserver(self):
99-
cmdlineopts = self.connection['admin'].command("getCmdLineOpts")
98+
cmdlineopts = self.db.admin_command("getCmdLineOpts")
10099
config_string = None
101100
if cmdlineopts.get('parsed').get('configdb'):
102101
config_string = cmdlineopts.get('parsed').get('configdb')

0 commit comments

Comments
 (0)