Ejemplo n.º 1
0
    def _sync(self):
        """ Sync databases and oplog.
        """
        if self._conf.start_optime:
            log.info("locating oplog, it will take a while")
            doc = self._src.client()['local']['oplog.rs'].find_one({'ts': {'$gte': self._conf.start_optime}})
            if not doc:
                log.error('oplog is stale')
                return
            start_optime = doc['ts']
            log.info('start timestamp is %s actually' % start_optime)
            self._stage = Stage.OPLOG_SYNC
            self._replay_oplog(start_optime)
        else:
            # initial sync
            self._initial_sync_start_optime = get_optime(self._src.client())
            self._stage = Stage.INITIAL_SYNC

            self._initial_sync()

            self._stage = Stage.POST_INITIAL_SYNC
            self._initial_sync_end_optime = get_optime(self._src.client())

            # oplog sync
            if self._optime_logger:
                self._optime_logger.write(self._initial_sync_start_optime)
            self._replay_oplog(self._initial_sync_start_optime)
Ejemplo n.º 2
0
 def _sync(self):
     """ Sync databases and oplog.
     """
     if self._conf.start_optime:
         log.info("locating oplog, it will take a while")
         oplog_start = self._conf.start_optime
         doc = self._src.client()['local']['oplog.rs'].find_one(
             {'ts': {
                 '$gte': oplog_start
             }})
         if not doc:
             log.error('oplog is stale')
             return
         oplog_start = doc['ts']
         log.info('start timestamp is %s actually' % oplog_start)
         self._last_optime = oplog_start
         self._replay_oplog(oplog_start)
     else:
         oplog_start = get_optime(self._src.client())
         if not oplog_start:
             log.error('get oplog_start failed, terminate')
             sys.exit(1)
         self._last_optime = oplog_start
         self._initial_sync()
         if self._optime_logger:
             self._optime_logger.write(oplog_start)
             log.info('first %s' % oplog_start)
         self._replay_oplog(oplog_start)
Ejemplo n.º 3
0
    def _sync(self):
        """ Sync databases and oplog.
        """
        if self._conf.start_optime:
            log.info("locating oplog, it will take a while")
            doc = None
            cur = self._src.client()['local']['oplog.rs'].find(
                {
                    'ts': {
                        '$lte': self._conf.start_optime
                    }
                }, {
                    "ts": 1
                }).sort("$natural", -1).limit(1)
            try:
                doc = cur.next()
            except StopIteration:
                pass
            if not doc:
                log.error('oplog is stale')
                return
            start_optime = doc['ts']
            log.info('start timestamp is %s actually' % start_optime)
            self._stage = Stage.OPLOG_SYNC
            self._replay_oplog(start_optime)
        else:
            # initial sync
            self._initial_sync_start_optime = get_optime(self._src.client())
            self._stage = Stage.INITIAL_SYNC

            self._initial_sync()

            self._stage = Stage.POST_INITIAL_SYNC
            self._initial_sync_end_optime = get_optime(self._src.client())

            # oplog sync
            if self._optime_logger:
                self._optime_logger.write(self._initial_sync_start_optime)
            self._replay_oplog(self._initial_sync_start_optime)