예제 #1
0
    def sync_object(self, bucket, obj):
        log.debug('syncing object %s/%s', bucket, obj.name)
        self.op_id += 1
        local_op_id = self.local_lock_id + ':' +  str(self.op_id)
        found = False

        try:
            until = time.time() + self.object_sync_timeout
            client.sync_object_intra_region(self.dest_conn, bucket, obj,
                                            self.src.zone.name,
                                            self.daemon_id,
                                            local_op_id)
            found = True
        except NotModified:
            log.debug('object "%s/%s" found on master and not modified',
                      bucket, obj.name)
            found = True
        except NotFound:
            log.debug('object "%s/%s" not found on master, deleting from secondary',
                      bucket, obj.name)
            try:
                client.delete_object(self.dest_conn, bucket, obj)
            except NotFound:
                # Since we were trying to delete the object, just return
                return False
            except Exception:
                msg = 'could not delete "%s/%s" from secondary' % (bucket, obj.name)
                log.exception(msg)
                raise SyncFailed(msg)
        except SyncFailed:
            raise
        except Exception as error:
            msg = 'encountered an error during sync'
            dev_log.warn(msg, exc_info=True)
            log.warning('%s: %s' % (msg, error))
            # wait for it if the op state is in-progress
            self.wait_for_object(bucket, obj, until, local_op_id)
        # TODO: clean up old op states
        try:
            if found:
                client.remove_op_state(self.dest_conn, self.daemon_id,
                                       local_op_id, bucket, obj)
        except NotFound:
            log.debug('op state already gone')
        except Exception:
            log.exception('could not remove op state for daemon "%s" op_id %s',
                          self.daemon_id, local_op_id)

        return True
예제 #2
0
 def sync_object(self, bucket, obj):
     log.debug('sync_object %s/%s', bucket, obj)
     self.op_id += 1
     local_op_id = self.local_lock_id + ':' +  str(self.op_id)
     try:
         found = True
         until = time.time() + self.object_sync_timeout
         client.sync_object_intra_region(self.dest_conn, bucket, obj,
                                         self.src.zone.name,
                                         self.daemon_id,
                                         local_op_id)
     except client.NotFound:
         found = False
         log.debug('"%s/%s" not found on master, deleting from secondary',
                   bucket, obj)
         try:
             client.delete_object(self.dest_conn, bucket, obj)
         except client.NotFound:
             # Since we were trying to delete the object, just return
             return
         except Exception:
             msg = 'could not delete "%s/%s" from secondary' % (bucket, obj)
             log.exception(msg)
             raise SyncFailed(msg)
     except SyncFailed:
         raise
     except Exception as e:
         log.debug('exception during sync: %s', e)
         if found:
             self.wait_for_object(bucket, obj, until, local_op_id)
     # TODO: clean up old op states
     try:
         if found:
             client.remove_op_state(self.dest_conn, self.daemon_id,
                                    local_op_id, bucket, obj)
     except Exception:
         log.exception('could not remove op state for daemon "%s" op_id %s',
                       self.daemon_id, local_op_id)