Verified Commit 366d84e1 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

ChunkStorage: Acknoledge R/W before close()

Acknowledge the main thread that the IO operation had terminate before
to actually close the file.

This is a "dirty" fix that waits to be refactored.

WARNING: Error on close will not be reported to the client that issued the IO
operation.
parent 14a835da
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
#ifndef IFS_CHUNK_STORAGE_HPP
#define IFS_CHUNK_STORAGE_HPP

#include <abt.h>
#include <string>
#include <memory>

@@ -24,10 +25,12 @@ class ChunkStorage {

    public:
        ChunkStorage(const std::string& path);
        unsigned int write_chunk(const std::string& file_path, unsigned int chunk_id,
                                 const char * buff, size_t size, off64_t offset) const;
        unsigned int read_chunk(const std::string& file_path, unsigned int chunk_id,
                                char * buff, size_t size, off64_t offset) const;
        void write_chunk(const std::string& file_path, unsigned int chunk_id,
                         const char * buff, size_t size, off64_t offset,
                         ABT_eventual& eventual) const;
        void read_chunk(const std::string& file_path, unsigned int chunk_id,
                         char * buff, size_t size, off64_t offset,
                         ABT_eventual& eventual) const;
        void destroy_chunk_space(const std::string& file_path) const;
};

+9 −1
Original line number Diff line number Diff line
@@ -11,5 +11,13 @@ target_sources(storage

target_link_libraries(storage
    PRIVATE
    ${Boost_LIBRARIES}
    Boost::filesystem
    ${ABT_LIBRARIES}
    ${ABT_SNOOZER_LIBRARIES}
    )

target_include_directories(storage
    PRIVATE
    ${ABT_INCLUDE_DIRS}
    ${ABT_SNOOZER_INCLUDE_DIRS}
    )
+10 −8
Original line number Diff line number Diff line
@@ -54,8 +54,8 @@ void ChunkStorage::init_chunk_space(const std::string& file_path) const {
    }
}

unsigned int ChunkStorage::write_chunk(const std::string& file_path, unsigned int chunk_id,
        const char * buff, size_t size, off64_t offset) const {
void ChunkStorage::write_chunk(const std::string& file_path, unsigned int chunk_id,
        const char * buff, size_t size, off64_t offset, ABT_eventual& eventual) const {

    init_chunk_space(file_path);

@@ -73,17 +73,18 @@ unsigned int ChunkStorage::write_chunk(const std::string& file_path, unsigned in
        throw std::system_error(errno, std::system_category(), "Failed to write chunk file");
    }

    ABT_eventual_set(eventual, &wrote, sizeof(size_t));

    auto err = close(fd);
    if (err < 0) {
        log->error("Failed to close chunk file after write. File: {}, Error: {}",
                chunk_path, std::strerror(errno));
        throw std::system_error(errno, std::system_category(), "Failed to close chunk file");
        //throw std::system_error(errno, std::system_category(), "Failed to close chunk file");
    }
    return wrote;
}

unsigned int ChunkStorage::read_chunk(const std::string& file_path, unsigned int chunk_id,
        char * buff, size_t size, off64_t offset) const {
void ChunkStorage::read_chunk(const std::string& file_path, unsigned int chunk_id,
        char * buff, size_t size, off64_t offset, ABT_eventual& eventual) const {

    auto chunk_path = absolute(get_chunk_path(file_path, chunk_id));
    int fd = open(chunk_path.c_str(), O_RDONLY);
@@ -99,11 +100,12 @@ unsigned int ChunkStorage::read_chunk(const std::string& file_path, unsigned int
        throw std::system_error(errno, std::system_category(), "Failed to read chunk file");
    }

    ABT_eventual_set(eventual, &read, sizeof(size_t));

    auto err = close(fd);
    if (err < 0) {
        log->error("Failed to close chunk file after read. File: {}, Error: {}",
                chunk_path, std::strerror(errno));
        throw std::system_error(errno, std::system_category(), "Failed to close chunk file");
        //throw std::system_error(errno, std::system_category(), "Failed to close chunk file");
    }
    return read;
}
 No newline at end of file
+8 −10
Original line number Diff line number Diff line
@@ -30,20 +30,19 @@ struct write_chunk_args {
 * @return written_size<size_t> is put into eventual and returned that way
 */
void write_file_abt(void* _arg) {
    size_t write_size = 0;
    // Unpack args
    auto* arg = static_cast<struct write_chunk_args*>(_arg);
    const std::string& path = *(arg->path);

    try {
        write_size = ADAFS_DATA->storage()->write_chunk(path, arg->chnk_id,
                arg->buf, arg->size, arg->off);
        ADAFS_DATA->storage()->write_chunk(path, arg->chnk_id,
                arg->buf, arg->size, arg->off, arg->eventual);
    } catch (const std::exception& e){
        ADAFS_DATA->spdlogger()->error("{}() Error writing chunk {} of file {}", __func__, arg->chnk_id, path);
        write_size = static_cast<size_t>(EIO);
        auto err = static_cast<size_t>(EIO);
        ABT_eventual_set(arg->eventual, &err, sizeof(size_t));
    }

    ABT_eventual_set(arg->eventual, &write_size, sizeof(size_t));
}

struct read_chunk_args {
@@ -68,19 +67,18 @@ struct read_chunk_args {
 * @return read_size<size_t> is put into eventual and returned that way
 */
void read_file_abt(void* _arg) {
    size_t read_size = 0;
    //unpack args
    auto* arg = static_cast<struct read_chunk_args*>(_arg);
    const std::string& path = *(arg->path);

    try {
        read_size = ADAFS_DATA->storage()->read_chunk(path, arg->chnk_id,
                arg->buf, arg->size, arg->off);
        ADAFS_DATA->storage()->read_chunk(path, arg->chnk_id,
                arg->buf, arg->size, arg->off, arg->eventual);
    } catch (const std::exception& e){
        ADAFS_DATA->spdlogger()->error("{}() Error reading chunk {} of file {}", __func__, arg->chnk_id, path);
        read_size = static_cast<size_t>(EIO);
        auto err = static_cast<size_t>(EIO);
        ABT_eventual_set(arg->eventual, &err, sizeof(size_t));
    }
    ABT_eventual_set(arg->eventual, &read_size, sizeof(size_t));
}

/**