Skip to content

Commit edb2ad7

Browse files
Fix some Oplog/TailThread.py exception problems found in testing
1 parent 492d399 commit edb2ad7

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

mongodb_consistent_backup/Common/DB.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def client_opts(self):
6262
if self.do_rp_tags and self.read_pref_tags:
6363
self.read_pref_tags = self.read_pref_tags.replace(" ", "")
6464
opts["readPreferenceTags"] = self.read_pref_tags
65+
logging.debug("Using read preference tags: %s" % self.read_pref_tags)
6566
if self.do_ssl():
6667
logging.debug("Using SSL-secured mongodb connection (ca_cert=%s, client_cert=%s, crl_file=%s, insecure=%s)" % (
6768
self.ssl_ca_file,
@@ -86,7 +87,7 @@ def connect(self):
8687
self.uri,
8788
self.replset,
8889
self.read_pref,
89-
self.read_pref_tags,
90+
self.do_rp_tags,
9091
self.do_ssl(),
9192
))
9293
conn = MongoClient(**self.client_opts())

mongodb_consistent_backup/Oplog/Tailer/TailThread.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# noinspection PyPackageRequirements
55
from multiprocessing import Process
6-
from pymongo.errors import AutoReconnect, ConnectionFailure, CursorNotFound, ExceededMaxWaiters, ExecutionTimeout, NetworkTimeout, NotMasterError
6+
from pymongo.errors import AutoReconnect, ConnectionFailure, CursorNotFound, ExceededMaxWaiters, ExecutionTimeout, NetworkTimeout, NotMasterError, ServerSelectionTimeoutError
77
from signal import signal, SIGINT, SIGTERM, SIG_IGN
88
from time import sleep, time
99

@@ -144,21 +144,25 @@ def run(self):
144144
continue
145145
sleep(1)
146146
finally:
147-
self._cursor.close()
147+
if self._cursor:
148+
logging.debug("Stopping oplog cursor on %s" % self.uri)
149+
self._cursor.close()
148150
except OperationError, e:
149151
logging.error("Tailer %s encountered error: %s" % (self.uri, e))
150152
self.exit_code = 1
151153
self.backup_stop.set()
152154
raise OperationError(e)
155+
except ServerSelectionTimeoutError, e:
156+
logging.error("Tailer %s could not connect: %s" % (self.uri, e))
157+
self.exit_code = 1
158+
self.backup_stop.set()
159+
raise OperationError(e)
153160
except Exception, e:
154161
logging.error("Tailer %s encountered an unexpected error: %s" % (self.uri, e))
155162
self.exit_code = 1
156163
self.backup_stop.set()
157164
raise e
158165
finally:
159-
if self._cursor:
160-
logging.debug("Stopping oplog cursor on %s" % self.uri)
161-
self._cursor.close()
162166
oplog.flush()
163167
oplog.close()
164168
self.stopped = True

0 commit comments

Comments
 (0)