Skip to content

Commit 444be96

Browse files
author
xiongjianqiang
committed
update
1 parent b435931 commit 444be96

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

mongo_sync/oplog_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def start(self):
143143
self._running = True
144144
self._thread = threading.Thread(target=self.run_dumping)
145145
self._thread.start()
146-
LOG.info('Started pid={}, dumping thread={}'.format(
146+
LOG.warning('Started pid={}, dumping thread={}'.format(
147147
os.getpid(), self._thread.ident))
148148

149149
def safe_stop(self):

mongo_sync/oplog_reader.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,29 @@ def load_oplog(self):
5757
return None
5858

5959
def replay(self, oplog):
60-
for n, entry in enumerate(oplog):
60+
for entry in oplog:
6161
# TODO: log excep
6262
self.docman.process(entry)
6363

6464
self._last_ts = entry['ts']
6565
LOG.info('Current progress={}'.format(ts2localtime(self._last_ts)))
6666

6767
def run(self):
68-
while self._running:
69-
LOG.info('Loading ts={}, last progress={}'.format(
70-
self._last_ts, ts2localtime(self._last_ts)))
71-
oplog = self.load_oplog()
72-
73-
if oplog is None:
74-
LOG.info('Loaded None. No more oplog to sync.')
75-
time.sleep(10)
76-
else:
77-
LOG.info('Loaded ts={}, size={}'.format(
78-
self._last_ts, len(oplog)))
79-
self.replay(oplog)
68+
try:
69+
while self._running:
70+
LOG.info('Loading ts={}, last progress={}'.format(
71+
self._last_ts, ts2localtime(self._last_ts)))
72+
oplog = self.load_oplog()
73+
74+
if oplog is None:
75+
LOG.info('Loaded None. No more oplog to sync.')
76+
time.sleep(10)
77+
else:
78+
LOG.info('Loaded ts={}, size={}'.format(
79+
self._last_ts, len(oplog)))
80+
self.replay(oplog)
81+
except Exception as e:
82+
LOG.error(str(e), exc_info=True)
8083

8184
LOG.warning('Oplog syncing stopped.')
8285

@@ -85,7 +88,7 @@ def start(self):
8588
self._running = True
8689
self._thread = threading.Thread(target=self.run)
8790
self._thread.start()
88-
LOG.info('Started pid={}, syncing thread={}'.format(
91+
LOG.warning('Started pid={}, syncing thread={}'.format(
8992
os.getpid(), self._thread.ident))
9093

9194
def safe_stop(self):

0 commit comments

Comments
 (0)