Unverified Commit 94a44560 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

Make ChunkStorage aware of chunksize

The ChunkStorage class now store the chunksize in order to perform
runtime checks upon chunks bundaries.
parent 4e16397e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -18,13 +18,14 @@ class ChunkStorage {
        std::shared_ptr<spdlog::logger> log;

        std::string root_path;
        size_t chunksize;
        inline std::string absolute(const std::string& internal_path) const;
        static inline std::string get_chunks_dir(const std::string& file_path);
        static inline std::string get_chunk_path(const std::string& file_path, unsigned int chunk_id);
        void init_chunk_space(const std::string& file_path) const;

    public:
        ChunkStorage(const std::string& path);
        ChunkStorage(const std::string& path, const size_t chunksize);
        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;
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ bool init_environment() {
    ADAFS_DATA->spdlogger()->debug("{}() Creating chunk storage directory: '{}'", __func__, chunk_storage_path);
    bfs::create_directories(chunk_storage_path);
    try {
        ADAFS_DATA->storage(std::make_shared<ChunkStorage>(chunk_storage_path));
        ADAFS_DATA->storage(std::make_shared<ChunkStorage>(chunk_storage_path, CHUNKSIZE));
    } catch (const std::exception & e) {
        ADAFS_DATA->spdlogger()->error("{}() unable to initialize storage backend: {}", __func__, e.what());
    }
+6 −3
Original line number Diff line number Diff line
@@ -12,8 +12,9 @@ std::string ChunkStorage::absolute(const std::string& internal_path) const {
    return root_path + '/' + internal_path;
}

ChunkStorage::ChunkStorage(const std::string& path) :
    root_path(path)
ChunkStorage::ChunkStorage(const std::string& path, const size_t chunksize) :
    root_path(path),
    chunksize(chunksize)
{
    //TODO check path: absolute, exists, permission to write etc...
    assert(is_absolute_path(root_path));
@@ -57,6 +58,8 @@ void ChunkStorage::init_chunk_space(const std::string& file_path) 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 {

    assert((offset + size) <= chunksize);

    init_chunk_space(file_path);

    auto chunk_path = absolute(get_chunk_path(file_path, chunk_id));
@@ -85,7 +88,7 @@ void ChunkStorage::write_chunk(const std::string& file_path, unsigned int chunk_

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 {

    assert((offset + size) <= chunksize);
    auto chunk_path = absolute(get_chunk_path(file_path, chunk_id));
    int fd = open(chunk_path.c_str(), O_RDONLY);
    if(fd < 0) {