|
1 | 1 | import logging |
2 | 2 |
|
3 | 3 | from math import ceil |
4 | | -from time import mktime, sleep |
| 4 | +from time import mktime |
5 | 5 |
|
6 | 6 | from DB import DB |
7 | 7 | from ShardingHandler import ShardingHandler |
8 | 8 |
|
9 | 9 |
|
10 | 10 | class ReplsetHandler: |
11 | | - def __init__(self, host, port, user, password, authdb, max_lag_secs, retries=5): |
| 11 | + def __init__(self, host, port, user, password, authdb, max_lag_secs): |
12 | 12 | self.host = host |
13 | 13 | self.port = port |
14 | 14 | self.user = user |
15 | 15 | self.password = password |
16 | 16 | self.authdb = authdb |
17 | 17 | self.max_lag_secs = max_lag_secs |
18 | | - self.retries = retries |
19 | 18 |
|
20 | 19 | try: |
21 | | - self.connection = DB(self.host, self.port, self.user, self.password, self.authdb).connection() |
| 20 | + self.db = DB(self.host, self.port, self.user, self.password, self.authdb) |
| 21 | + self.connection = self.db.connection() |
22 | 22 | except Exception, e: |
23 | 23 | logging.fatal("Could not get DB connection! Error: %s" % e) |
24 | 24 | raise e |
25 | 25 |
|
26 | 26 | def close(self): |
27 | 27 | return self.connection.close() |
28 | 28 |
|
29 | | - def admin_command(self, admin_command): |
30 | | - tries = 0 |
31 | | - status = None |
32 | | - while not status and tries < self.retries: |
33 | | - try: |
34 | | - status = self.connection['admin'].command(admin_command) |
35 | | - if not status: |
36 | | - raise e |
37 | | - except Exception, e: |
38 | | - logging.error("Error running command '%s': %s" % (admin_command, e)) |
39 | | - tries += 1 |
40 | | - sleep(1) |
41 | | - if not status: |
42 | | - raise Exception, "Could not get output from command: '%s' after %i retries!" % (admin_command, self.retries), None |
43 | | - return status |
44 | | - |
45 | 29 | def get_rs_status(self): |
46 | | - return self.admin_command('replSetGetStatus') |
| 30 | + return self.db.admin_command('replSetGetStatus') |
47 | 31 |
|
48 | 32 | def get_rs_config(self): |
49 | | - return self.admin_command('replSetGetConfig') |
| 33 | + return self.db.admin_command('replSetGetConfig') |
50 | 34 |
|
51 | 35 | def find_desirable_secondary(self): |
52 | 36 | rs_status = self.get_rs_status() |
|
0 commit comments