Exemple #1
0
    def acquire(self):
        """Renew an existing lock, or acquire a new one.

        The old lock must have already been released if shard_num is specified.
        client.NotFound may be raised if the log contains no entries.
        """
        log.debug('acquire lock')
        with self.lock:
            now = time.time()
            client.lock_shard(self.conn, self.type, self.shard_num,
                              self.zone_id, self.timeout, self.locker_id)
            self.last_locked = now
Exemple #2
0
    def acquire_log_lock(self, lock_id, zone_id, shard_num):

        log.debug('acquiring lock on shard %d', shard_num)

        try:
            client.lock_shard(self.source_conn, self._type, shard_num, zone_id,
                              self.log_lock_time, self.local_lock_id)
        except client.HttpError as e:
            log.error('locking shard %d in zone %s failed: %s',
                     shard_num, zone_id, e)
            # clear this flag for the next pass
            self.relock_log = False
            raise

        # twiddle the boolean flag to false
        self.relock_log = False

        # then start the timer to twiddle it back to true
        self.relock_timer = threading.Timer(0.5 * self.log_lock_time, \
                                            self.flip_log_lock)
        self.relock_timer.start()
Exemple #3
0
 def _acquire(self):
     # same as aqcuire() but assumes self.lock is held
     now = time.time()
     client.lock_shard(self.conn, self.type, self.shard_num, self.zone_id,
                       self.timeout, self.locker_id)
     self.last_locked = now
Exemple #4
0
 def _acquire(self):
     # same as aqcuire() but assumes self.lock is held
     now = time.time()
     client.lock_shard(self.conn, self.type, self.shard_num,
                       self.zone_id, self.timeout, self.locker_id)
     self.last_locked = now