Ejemplo n.º 1
0
def recovery_by_haystack(pid, gid):

    hpath = get_haystack_path(pid, gid)
    h = haystack.Haystack(hpath)
    old_num = h.get_latest_version_num()

    ver_num, haystack_fpaths = download_haystack(pid, gid)

    renamed_paths = []

    try:

        attr_sha1 = haystack_version.get_file_sha1( haystack_fpaths['attribute'] )

        for fn_key, src_path in haystack_fpaths.items():

            dst_path = get_haystack_file_path(pid, gid, ver_num, fn_key)
            rename_force(src_path, dst_path)

            renamed_paths.append(dst_path)

        h.reset_version_num( ver_num, attr_sha1 )

    except Exception as e:
        delete_files( renamed_paths )
        delete_files( haystack_fpaths.values() )
        raise

    switch_port = partition.pid_port(pid)
    switch_url = SWITCH_VERSION_PREFIX + pid + '/' + str(gid)
    h._switch_version(switch_port, switch_url)

    if old_num != ver_num:
        h.delete_version(old_num, switch_port, switch_url)
Ejemplo n.º 2
0
def recovery_global_version_by_attr_file(pid, gid):

    hpath = get_haystack_path(pid, gid)
    h = haystack.Haystack(hpath)

    fn = get_latest_attribute_fn(hpath)
    if fn is None:
        return False

    try:
        attr_sha1 = haystack_version.get_file_sha1( os.path.join(hpath, fn) )
    except haystack_version.FileDamaged as e:
        logger.info( 'attribute file is damaged %s' %fn )
        return False

    ver_num =  fn[ len('haystack_') : -len('_attribute') ]

    h.reset_version_num(ver_num, attr_sha1)

    return True
Ejemplo n.º 3
0
def is_haystack_file_ok(pid, gid, ver_num, fn_key, sha1):

    hpath = get_haystack_path(pid, gid)
    ver = haystack_version.HaystackVersion(hpath, ver_num)

    try:

        fpath = ver.get_file_path(fn_key)
        if os.path.exists(fpath):
            fsha1 = haystack_version.get_file_sha1(fpath)
        else:
            logger.info( 'pid:%s, gid:%d, fn:%s not exist !'%(pid, gid, fpath) )
            return False

    except haystack_version.FileDamaged as e:
        logger.info(repr(e)+ 'pid:%s, gid:%d haystack_%s_%s file is damaged'%(pid, gid, ver_num, fn_key))
        return False

    if sha1 != fsha1:
        logger.info( 'pid:%s, gid:%d haystack_%s_%s file is damaged, sha1 is not right!'
                    %(pid, gid, ver_num, fn_key))
        return False
    else:
        return True