Ejemplo n.º 1
0
def clear_memcache_data(config_file, input_file):
    """Clear memcache data for all userids listed in the given input file."""
    logger.info("Clearing data for uids in %s", input_file)
    logger.debug("Using config file %r", config_file)
    config = syncstorage.get_configurator({"__file__": config_file})

    # Search all configured storages to find one that uses memcached.
    # We assume that all storages share a single memcached server, and
    # so we can use this single instance as a representative.  This is
    # how things are deployed at Mozilla, but is not guaranteed by the code.
    for _, backend in get_all_storages(config):
        if isinstance(backend, MemcachedStorage):
            break
    else:
        raise RuntimeError("No memcached storage backends found.")
    logger.debug("Using memcache server at %r", backend.cache.pool.server)

    with maybe_open(input_file, "rt") as input_fileobj:
        for uid in input_fileobj:
            uid = uid.strip()
            if uid:
                logger.info("Clearing data for %s", uid)
                for key in backend.iter_cache_keys(uid):
                    backend.cache.delete(key)
                logger.debug("Cleared data for %s", uid)

    logger.info("Finished clearing memcache data")
def purge_expired_items(config_file, grace_period=0, max_per_loop=1000,
                        backend_interval=0):
    """Purge expired BSOs from all storage backends in the given config file.

    This function iterates through each storage backend in the given config
    file and calls its purge_expired_items() method.  The result is a
    gradual pruning of expired items from each database.
    """
    logger.info("Purging expired items")
    logger.debug("Using config file %r", config_file)
    config = syncstorage.scripts.load_configurator(config_file)

    for hostname, backend in get_all_storages(config):
        logger.debug("Purging backend for %s", hostname)
        config.begin()
        t_start = time.time()
        try:
            backend.purge_expired_items(grace_period, max_per_loop)
        except Exception:
            logger.exception("Error while purging backend for %s", hostname)
        else:
            logger.debug("Purged backend for %s", hostname)
        finally:
            t_duration = min(0, time.time() - t_start)
            logger.debug("Purge took %.4f seconds", t_duration)
            config.end()
        logger.debug("Sleeping for %d seconds", backend_interval)
        time.sleep(backend_interval)

    logger.info("Finished purging expired items")
Ejemplo n.º 3
0
def purge_expired_items(config_file, grace_period=0, max_per_loop=1000,
                        backend_interval=0):
    """Purge expired BSOs from all storage backends in the given config file.

    This function iterates through each storage backend in the given config
    file and calls its purge_expired_items() method.  The result is a
    gradual pruning of expired items from each database.
    """
    logger.info("Purging expired items")
    logger.debug("Using config file %r", config_file)
    config = syncstorage.scripts.load_configurator(config_file)

    for hostname, backend in get_all_storages(config):
        logger.debug("Purging backend for %s", hostname)
        config.begin()
        try:
            backend.purge_expired_items(grace_period, max_per_loop)
        except Exception:
            logger.exception("Error while purging backend for %s", hostname)
        else:
            logger.debug("Purged backend for %s", hostname)
        finally:
            config.end()
        logger.debug("Sleeping for %d seconds", backend_interval)
        time.sleep(backend_interval)

    logger.info("Finished purging expired items")