Пример #1
0
def repair(path, indices):
    """
    Repairs one or multiple blocks of a document
    Args:
        path(str): Path to the document
        indices(list(int)): Indices of the blocks to retrieve
    """
    if not isinstance(path, str) or not path:
        raise ValueError("Argument path must be a non-empty string")
    if not isinstance(indices, list):
        raise ValueError("Argument indices must be list")
    if not indices:
        return
    for index, index_to_reconstruct in enumerate(indices):
        if not isinstance(index_to_reconstruct, int):
            error_message = "indices[{:d}] is not an integer".format(index)
            raise ValueError(error_message)
    erasures_threshold = get_erasure_threshold()
    dispatcher = Dispatcher(get_dispatcher_configuration())
    files = Files()
    if len(indices) <= erasures_threshold:
        reconstructed_blocks = reconstruct_with_RS(path, indices)
        for index in reconstructed_blocks:
            reconstructed_block = reconstructed_blocks[index]
            metablock = files.get_block(compute_block_key(path, index))
            for provider_name in set(metablock.providers):
                dispatcher.providers[provider_name].put(reconstructed_block,
                                                        metablock.key)
    else:
        #FIXME order of blocks to reach e erasures than do RS reconstuction
        indices.sort()
        while len(indices) > erasures_threshold:
            index = indices.pop(0)
            reconstructed_block = reconstruct_as_pointer(path, index)
            metablock = files.get_block(compute_block_key(path, index))
            for provider_name in set(metablock.providers):
                dispatcher.providers[provider_name].put(reconstructed_block,
                                                        metablock.key)
        reconstructed_blocks = reconstruct_with_RS(path, indices)
        for index in reconstructed_blocks:
            reconstructed_block = reconstructed_blocks[index]
            metablock = files.get_block(compute_block_key(path, index))
            for provider_name in set(metablock.providers):
                dispatcher.providers[provider_name].put(reconstructed_block,
                                                        metablock.key)
Пример #2
0
def get_block_metadata(path, index):
    """
    Returns the block metadata
    Args:
        path(str): Path to the file
        index(int): Index of the block in the file
    Returns:
        MetaBlock: Block metadata
    """
    files = Files()
    key = compute_block_key(path, index)
    return files.get_block(key)