예제 #1
0
def _rewrite_redis_aof(veil_server=None):
    current_veil_env = get_current_veil_env()
    if not hasattr(current_veil_env.config, 'redis_servers'):
        return False
    requested = False
    for host, port in current_veil_env.config.redis_servers:
        if veil_server and veil_server.internal_ip != host:
            continue
        try:
            client = StrictRedis(host=host, port=port)
            if client.config_get('appendonly')['appendonly'] != 'yes':
                continue
            LOGGER.info('request for redis aof rewrite <%(host)s:%(port)s>', {
                'host': host,
                'port': port
            })
            client.bgrewriteaof()
            requested = True
        except Exception as e:
            if 'append only file rewriting already in progress' not in e.message:
                requested = True
                LOGGER.exception(
                    'Exception thrown while requesting for redis aof rewrite <%(host)s:%(port)s>',
                    {
                        'host': host,
                        'port': port
                    })
    return requested