4343
4444
4545# Monkey patch logging to add Logger.always
46- ALWAYS = logging .CRITICAL + 10
46+ ALWAYS = logging .CRITICAL 10
4747logging .addLevelName (ALWAYS , 'ALWAYS' )
4848
4949
@@ -124,6 +124,9 @@ def __init__(self, mongo_address, doc_managers=None, **kwargs):
124124 # Timezone awareness
125125 self .tz_aware = kwargs .get ('tz_aware' , False )
126126
127+ # If oplog access is via the proxy
128+ self .is_oplog_proxy = kwargs .get ('is_oplog_proxy' , False )
129+
127130 # SSL keyword arguments to MongoClient.
128131 ssl_certfile = kwargs .pop ('ssl_certfile' , None )
129132 ssl_ca_certs = kwargs .pop ('ssl_ca_certs' , None )
@@ -215,7 +218,8 @@ def from_config(cls, config):
215218 ssl_keyfile = config ['ssl.sslKeyfile' ],
216219 ssl_ca_certs = config ['ssl.sslCACerts' ],
217220 ssl_cert_reqs = config ['ssl.sslCertificatePolicy' ],
218- tz_aware = config ['timezoneAware' ]
221+ tz_aware = config ['timezoneAware' ],
222+ is_oplog_proxy = config ['isOplogProxy' ]
219223 )
220224 return connector
221225
@@ -242,7 +246,7 @@ def write_oplog_progress(self):
242246 return
243247
244248 # write to temp file
245- backup_file = self .oplog_checkpoint + '.backup'
249+ backup_file = self .oplog_checkpoint '.backup'
246250 os .rename (self .oplog_checkpoint , backup_file )
247251
248252 # for each of the threads write to file
@@ -314,9 +318,9 @@ def copy_uri_options(hosts, mongodb_uri):
314318 options = mongodb_uri .split ('?' , 1 )[1 ]
315319 else :
316320 options = None
317- uri = 'mongodb://' + hosts
321+ uri = 'mongodb://' hosts
318322 if options :
319- uri + = '/?' + options
323+ uri = '/?' options
320324 return uri
321325
322326 def create_authed_client (self , hosts = None , ** kwargs ):
@@ -374,12 +378,25 @@ def run(self):
374378 )
375379 return
376380
377- # Establish a connection to the replica set as a whole
378- self .main_conn .close ()
379- self .main_conn = self .create_authed_client (
380- replicaSet = is_master ['setName' ])
381-
382- self .update_version_from_client (self .main_conn )
381+ # # Establish a connection to the replica set as a whole
382+ # self.main_conn.close()
383+ # self.main_conn = self.create_authed_client(
384+ # replicaSet=is_master['setName'])
385+
386+ # self.update_version_from_client(self.main_conn)
387+ if not self .is_oplog_proxy :
388+ # Establish a connection to the replica set as a whole
389+ self .main_conn .close ()
390+ self .main_conn = self .create_authed_client (
391+ replicaSet = is_master ['setName' ])
392+ self .update_version_from_client (self .main_conn )
393+ else :
394+ try :
395+ # Check if local.oplog.rs is readable
396+ self .main_conn .local .oplog .rs .find_one ()
397+ except pymongo .errors .OperationFailure :
398+ LOG .error ('Could not read local.oplog.rs!' )
399+ sys .exit (1 )
383400
384401 # non sharded configuration
385402 oplog = OplogThread (
@@ -486,6 +503,17 @@ def add_option(*args, **kwargs):
486503 " would be a valid argument to `-m`. Don't use"
487504 " quotes around the address." )
488505
506+ is_oplog_proxy = add_option (
507+ config_key = "isOplogProxy" ,
508+ default = False ,
509+ type = bool )
510+
511+ is_oplog_proxy .add_cli (
512+ "--is_oplog_proxy" , dest = "is_oplog_proxy" , help =
513+ "True if passed uri is a proxy with access to mongo"
514+ "oplog.rs." )
515+
516+
489517 oplog_file = add_option (
490518 config_key = "oplogFile" ,
491519 default = "oplog.timestamp" ,
@@ -859,7 +887,7 @@ def apply_old_namespace_options(option, cli_values):
859887 dest_mapping = option .value ['mapping' ]
860888
861889 valid_names = set (['include' , 'exclude' , 'gridfs' , 'mapping' ])
862- valid_names |= set ('__' + name for name in valid_names )
890+ valid_names |= set ('__' name for name in valid_names )
863891 valid_names .add ('__comment__' )
864892 for key in option .value :
865893 if key not in valid_names :
0 commit comments