Beispiel #1
0
def run_coalesce(sr_type, uri):
    """
    GC/Coalesce main loop
    """
    util.daemonize()

    callbacks = util.get_sr_callbacks(sr_type)
    this_host = callbacks.get_current_host()

    while True:
        done_work = False
        try:
            remove_garbage_volumes(uri, callbacks)

            recover_journal(uri, this_host, callbacks)

            child, parent = _find_best_non_leaf_coalesceable(uri, callbacks)
            if (child, parent) != (None, None):
                non_leaf_coalesce(child, parent, uri, callbacks)
                done_work = True
            elif _find_best_leaf_coalesceable(this_host, uri, callbacks):
                done_work = True

            # If we did no work then delay by some time
            if not done_work:
                time.sleep(30)
            else:
                time.sleep(10)

        except Exception:
            import traceback
            log.error("Exception in GC main loop {}, {}".format(
                sys.exc_info(), traceback.format_exc()))
            raise
Beispiel #2
0
 def start_gc(dbg, sr_type, uri):
     # Get the command to run, need to replace pyc with py as __file__ will
     # be the byte compiled file
     dbg_msg = "{}: Starting GC sr_type={} uri={}".format(dbg, sr_type, uri)
     callbacks = util.get_sr_callbacks(sr_type)
     args = [os.path.abspath(re.sub("pyc$", "py", __file__)), sr_type, uri]
     start_task(dbg_msg, uri, callbacks, "gc", args)
     start_background_tasks(dbg, sr_type, uri, callbacks)
Beispiel #3
0
    def stop_gc(dbg, sr_type, uri):
        tasks = [('gc', None)]

        callbacks = util.get_sr_callbacks(sr_type)
        background_tasks = callbacks.get_background_tasks()
        if background_tasks:
            tasks.extend(background_tasks)

        # Stop gc first and then other background tasks.
        for name, _ in tasks:
            log.debug(
                "{}: Attempting to kill {} process for sr_type={}, uri={}".
                format(dbg, name, sr_type, uri))
            dbg_msg = "{}: {} process killed for uri={}".format(dbg, name, uri)
            stop_task(dbg_msg, uri, callbacks, name)
Beispiel #4
0
    def start_gc(dbg, sr_type, uri):
        # Ensure trash directory exists before starting GC.
        callbacks = util.get_sr_callbacks(sr_type)
        with VolumeContext(callbacks, uri, 'w') as opq:
            callbacks.create_trash_dir(opq)

        if gc_is_enabled(uri, callbacks):
            # Get the command to run, need to replace pyc with py as __file__
            # will be the byte compiled file.
            dbg_msg = "{}: Starting GC sr_type={} uri={}".format(
                dbg, sr_type, uri)
            args = [
                os.path.abspath(re.sub("pyc$", "py", __file__)), sr_type, uri
            ]
            start_task(dbg_msg, uri, callbacks, "gc", args)
        else:
            log.debug('GC is disabled, cannot start it')
        start_background_tasks(dbg, sr_type, uri, callbacks)
                last_backup_time = db.last_backup_time
                backup_interval = db.backup_interval
            next_backup_time = last_backup_time + backup_interval

            # 2. Wait before next backup.
            now = time.time()
            while now < next_backup_time:
                time.sleep(next_backup_time - now)
                now = time.time()

            # 3. Backup!
            callbacks.rolling_backup(LOG_DOMAIN, uri, backups_path)
        except IOError:
            log.error('{}: failed to write backup, abort!'.format(
                LOG_DOMAIN, uri))
            raise
        except Exception:
            log.error('{}: execution error: {}'.format(LOG_DOMAIN,
                                                       sys.exc_info()))
            log.error(traceback.format_exc())


if __name__ == '__main__':
    try:
        backup('file://{}'.format(sys.argv[2]),
               util.get_sr_callbacks(sys.argv[1]))
    except RuntimeError:
        log.error('{}: uncaught exception: {}'.format(LOG_DOMAIN,
                                                      sys.exc_info()))
        raise