Skip to content

Commit 3a4ce7e

Browse files
Merge pull request #161 from islue/160_tailer_thread_utf8_codec_cant_decode
tail oplog.rs with unicode_decode_error_handler="ignore"
2 parents 3a6dd6a + 30a6920 commit 3a4ce7e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

mongodb_consistent_backup/Oplog/Tailer/TailThread.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
# Skip bson in requirements , pymongo provides
55
# noinspection PyPackageRequirements
6+
from bson.codec_options import CodecOptions
67
from multiprocessing import Process
78
from pymongo import CursorType
89
from pymongo.errors import AutoReconnect
@@ -67,13 +68,14 @@ def run(self):
6768
self.conn = DB(self.uri, self.config, True, 'secondary').connection()
6869
db = self.conn['local']
6970
oplog = self.oplog()
71+
oplog_rs = db.oplog.rs.with_options(codec_options=CodecOptions(unicode_decode_error_handler="ignore"))
7072

71-
tail_start_ts = db.oplog.rs.find().sort('$natural', -1)[0]['ts']
73+
tail_start_ts = oplog_rs.find().sort('$natural', -1)[0]['ts']
7274
self.state.set('running', True)
7375
while not self.do_stop.is_set():
7476
# http://api.mongodb.com/python/current/examples/tailable.html
7577
query = {'ts':{'$gt':tail_start_ts}}
76-
cursor = db.oplog.rs.find(query, cursor_type=CursorType.TAILABLE_AWAIT, oplog_replay=True)
78+
cursor = oplog_rs.find(query, cursor_type=CursorType.TAILABLE_AWAIT, oplog_replay=True)
7779
try:
7880
while not self.do_stop.is_set():
7981
try:

0 commit comments

Comments
 (0)