diff --git a/capio/server/include/handlers/close.hpp b/capio/server/include/handlers/close.hpp index a9133327f..18e98a53a 100644 --- a/capio/server/include/handlers/close.hpp +++ b/capio/server/include/handlers/close.hpp @@ -23,8 +23,8 @@ inline void handle_close(int tid, int fd) { c_file.closed()) { LOG("Capio File %s is closed and commit rule is on_close. setting it to complete", path.c_str()); - c_file.setComplete(); - c_file.commit(); + c_file.setCommitted(); + c_file.dump(); } LOG("Deleting capio file %s from tid=%d", path.c_str(), tid); diff --git a/capio/server/include/handlers/exig.hpp b/capio/server/include/handlers/exig.hpp index 443a8a6e3..fa784a062 100644 --- a/capio/server/include/handlers/exig.hpp +++ b/capio/server/include/handlers/exig.hpp @@ -14,17 +14,17 @@ inline void handle_exit_group(int tid) { LOG("Handling file %s", path.c_str()); if (CapioCLEngine::get().getCommitRule(path) == capiocl::commitRules::ON_TERMINATION) { CapioFile &c_file = storage_manager->get(path); - if (c_file.directory()) { + if (c_file.isDirectory()) { LOG("file %s is dir", path.c_str()); - long int n_committed = c_file.n_files_expected; - if (n_committed <= c_file.n_files) { + long int n_committed = c_file.getDirectoryExpectedFileCount(); + if (n_committed <= c_file.getCurrentDirectoryFileCount()) { LOG("Setting file %s to complete", path.c_str()); - c_file.setComplete(); + c_file.setCommitted(); } } else { LOG("Setting file %s to complete", path.c_str()); - c_file.setComplete(); - c_file.commit(); + c_file.setCommitted(); + c_file.dump(); } c_file.close(); } diff --git a/capio/server/include/handlers/getdents.hpp b/capio/server/include/handlers/getdents.hpp index df2074f02..d53002391 100644 --- a/capio/server/include/handlers/getdents.hpp +++ b/capio/server/include/handlers/getdents.hpp @@ -19,13 +19,14 @@ inline void request_remote_getdents(int tid, int fd, off64_t count) { off64_t end_of_read = offset + count; off64_t end_of_sector = c_file.getSectorEnd(offset); - if (c_file.complete() && (end_of_read <= end_of_sector || - (end_of_sector == -1 ? 0 : end_of_sector) == c_file.real_file_size)) { + if (c_file.isCommitted() && + (end_of_read <= end_of_sector || + (end_of_sector == -1 ? 0 : end_of_sector) == c_file.getRealFileSize())) { LOG("Handling local read"); send_dirent_to_client(tid, fd, c_file, offset, count); } else if (end_of_read <= end_of_sector) { LOG("?"); - c_file.createBufferIfNeeded(storage_manager->getPath(tid, fd), false); + c_file.createBuffer(storage_manager->getPath(tid, fd), false); client_manager->replyToClient(tid, offset, c_file.getBuffer(), count); storage_manager->setFileOffset(tid, fd, offset + count); } else { diff --git a/capio/server/include/handlers/open.hpp b/capio/server/include/handlers/open.hpp index a6c6a6896..18df1108b 100644 --- a/capio/server/include/handlers/open.hpp +++ b/capio/server/include/handlers/open.hpp @@ -18,9 +18,9 @@ inline void update_file_metadata(const std::filesystem::path &path, int tid, int : storage_manager->add(path, false, get_file_initial_size()); storage_manager->addFileToTid(tid, fd, path, offset); - if (c_file.first_write && is_creat) { + if (c_file.isFirstWrite() && is_creat) { client_manager->registerProducedFile(tid, path); - c_file.first_write = false; + c_file.registerFirstWrite(); write_file_location(path); storage_manager->updateDirectory(tid, path); } diff --git a/capio/server/include/handlers/read.hpp b/capio/server/include/handlers/read.hpp index 07d2f69b6..2cff9afe8 100644 --- a/capio/server/include/handlers/read.hpp +++ b/capio/server/include/handlers/read.hpp @@ -30,7 +30,7 @@ inline void handle_pending_read(int tid, int fd, long int process_offset, long i bytes_read = end_of_sector - process_offset; } - c_file.createBufferIfNeeded(path, false); + c_file.createBuffer(path, false); client_manager->replyToClient(tid, process_offset, c_file.getBuffer(), bytes_read); storage_manager->setFileOffset(tid, fd, process_offset + bytes_read); @@ -47,13 +47,13 @@ inline void handle_local_read(int tid, int fd, off64_t count, bool is_prod) { off64_t process_offset = storage_manager->getFileOffset(tid, fd); // if a process is the producer of a file, then the file is always complete for that process - const bool file_complete = c_file.complete() || is_prod; + const bool file_complete = c_file.isCommitted() || is_prod; if (!(file_complete || CapioCLEngine::get().isFirable(path))) { // wait for file to be completed and then do what is done inside handle pending read LOG("Data is not available yet. Starting async thread to wait for file availability"); std::thread t([&c_file, tid, fd, count, process_offset] { - c_file.waitForCompletion(); + c_file.waitForCommit(); handle_pending_read(tid, fd, process_offset, count); }); t.detach(); @@ -85,7 +85,7 @@ inline void handle_local_read(int tid, int fd, off64_t count, bool is_prod) { const auto read_size = std::min(count, end_of_sector - process_offset); LOG("Requested read within end of sector, and data is available. Serving %ld bytes", read_size); - c_file.createBufferIfNeeded(path, false); + c_file.createBuffer(path, false); client_manager->replyToClient(tid, process_offset, c_file.getBuffer(), read_size); storage_manager->setFileOffset(tid, fd, process_offset + read_size); } @@ -99,13 +99,14 @@ inline void request_remote_read(int tid, int fd, off64_t count) { off64_t end_of_read = offset + count; off64_t end_of_sector = c_file.getSectorEnd(offset); - if (c_file.complete() && (end_of_read <= end_of_sector || - (end_of_sector == -1 ? 0 : end_of_sector) == c_file.real_file_size)) { + if (c_file.isCommitted() && + (end_of_read <= end_of_sector || + (end_of_sector == -1 ? 0 : end_of_sector) == c_file.getRealFileSize())) { LOG("Handling local read"); handle_local_read(tid, fd, count, true); } else if (end_of_read <= end_of_sector) { LOG("Data is present locally and can be served to client"); - c_file.createBufferIfNeeded(path, false); + c_file.createBuffer(path, false); client_manager->replyToClient(tid, offset, c_file.getBuffer(), count); storage_manager->setFileOffset(tid, fd, offset + count); diff --git a/capio/server/include/handlers/stat.hpp b/capio/server/include/handlers/stat.hpp index ef4c6a597..8ff9352fe 100644 --- a/capio/server/include/handlers/stat.hpp +++ b/capio/server/include/handlers/stat.hpp @@ -25,11 +25,11 @@ void wait_for_file_completion(int tid, const std::filesystem::path &path) { CapioFile &c_file = storage_manager->get(path); // if file is streamable - if (c_file.complete() || CapioCLEngine::get().isFirable(path) || + if (c_file.isCommitted() || CapioCLEngine::get().isFirable(path) || strcmp(std::get<0>(get_file_location(path)), node_name) == 0) { client_manager->replyToClient(tid, c_file.getFileSize()); - client_manager->replyToClient(tid, static_cast(c_file.directory() ? 1 : 0)); + client_manager->replyToClient(tid, static_cast(c_file.isDirectory() ? 1 : 0)); } else { handle_remote_stat_request(tid, path); @@ -72,15 +72,15 @@ inline void reply_stat(int tid, const std::filesystem::path &path) { LOG("File is now present from remote node. retrieving file again."); file_location_opt = get_file_location_opt(path); } - if (c_file.complete() || strcmp(std::get<0>(file_location_opt->get()), node_name) == 0 || + if (c_file.isCommitted() || strcmp(std::get<0>(file_location_opt->get()), node_name) == 0 || CapioCLEngine::get().isFirable(path) || capio_dir == path) { LOG("Sending response to client"); client_manager->replyToClient(tid, c_file.getFileSize()); - client_manager->replyToClient(tid, static_cast(c_file.directory() ? 1 : 0)); + client_manager->replyToClient(tid, static_cast(c_file.isDirectory() ? 1 : 0)); } else { LOG("Delegating backend to reply to remote stats"); // send a request for file. then start a thread to wait for the request completion - c_file.createBufferIfNeeded(path, false); + c_file.createBuffer(path, false); handle_remote_stat_request(tid, path); } } diff --git a/capio/server/include/handlers/write.hpp b/capio/server/include/handlers/write.hpp index a65c7db7c..dec309a6f 100644 --- a/capio/server/include/handlers/write.hpp +++ b/capio/server/include/handlers/write.hpp @@ -15,10 +15,10 @@ void write_handler(const char *const str) { off64_t end_of_write = offset + count; const std::filesystem::path &path = storage_manager->getPath(tid, fd); CapioFile &c_file = storage_manager->get(path); - off64_t file_shm_size = c_file.getBufferSize(); + off64_t file_shm_size = c_file.getBufSize(); SPSCQueue &data_buf = client_manager->getClientToServerDataBuffers(tid); - c_file.createBufferIfNeeded(path, true); + c_file.createBuffer(path, true); if (end_of_write > file_shm_size) { c_file.expandBuffer(end_of_write); } @@ -26,8 +26,8 @@ void write_handler(const char *const str) { client_manager->registerProducedFile(tid, path); c_file.insertSector(offset, end_of_write); - if (c_file.first_write) { - c_file.first_write = false; + if (c_file.isFirstWrite()) { + c_file.registerFirstWrite(); write_file_location(path); // TODO: it works only if there is one prod per file storage_manager->updateDirectory(tid, path); diff --git a/capio/server/include/remote/handlers/read.hpp b/capio/server/include/remote/handlers/read.hpp index 474241784..d4a4f6cd2 100644 --- a/capio/server/include/remote/handlers/read.hpp +++ b/capio/server/include/remote/handlers/read.hpp @@ -44,12 +44,12 @@ inline void handle_read_reply(int tid, int fd, long count, off64_t file_size, of const std::filesystem::path &path = storage_manager->getPath(tid, fd); CapioFile &c_file = storage_manager->get(path); off64_t offset = storage_manager->getFileOffset(tid, fd); - c_file.real_file_size = file_size; + c_file.setRealFileSize(file_size); c_file.insertSector(offset, offset + nbytes); - c_file.setComplete(complete); + c_file.setCommitted(complete); off64_t end_of_sector = c_file.getSectorEnd(offset); - c_file.createBufferIfNeeded(path, false); + c_file.createBuffer(path, false); off64_t bytes_read; off64_t end_of_read = offset + count; if (end_of_sector > end_of_read) { @@ -75,7 +75,7 @@ void wait_for_data(const std::filesystem::path &path, const std::string &dest, i const CapioFile &c_file = storage_manager->get(path); // wait that nbytes are written c_file.waitForData(offset + count); - serve_remote_read(path, dest, tid, fd, count, offset, c_file.complete(), is_getdents); + serve_remote_read(path, dest, tid, fd, count, offset, c_file.isCommitted(), is_getdents); } inline void handle_remote_read(const std::filesystem::path &path, const std::string &source, @@ -86,8 +86,8 @@ inline void handle_remote_read(const std::filesystem::path &path, const std::str CapioFile &c_file = storage_manager->get(path); bool data_available = (offset + count <= c_file.getStoredSize()); - if (c_file.complete() || (CapioCLEngine::get().isFirable(path) && data_available)) { - serve_remote_read(path, source, tid, fd, count, offset, c_file.complete(), is_getdents); + if (c_file.isCommitted() || (CapioCLEngine::get().isFirable(path) && data_available)) { + serve_remote_read(path, source, tid, fd, count, offset, c_file.isCommitted(), is_getdents); } else { std::thread t(wait_for_data, path, source, tid, fd, count, offset, is_getdents); t.detach(); @@ -107,9 +107,9 @@ inline void handle_remote_read_reply(const std::string &source, int tid, int fd, off64_t offset = storage_manager->getFileOffset(tid, fd); CapioFile &c_file = storage_manager->get(path); - c_file.createBufferIfNeeded(path, false); + c_file.createBuffer(path, false); if (nbytes != 0) { - auto file_shm_size = c_file.getBufferSize(); + auto file_shm_size = c_file.getBufSize(); auto file_size_recv = offset + nbytes; if (file_size_recv > file_shm_size) { c_file.expandBuffer(file_size_recv); diff --git a/capio/server/include/remote/handlers/stat.hpp b/capio/server/include/remote/handlers/stat.hpp index c328221f5..80cd4cc47 100644 --- a/capio/server/include/remote/handlers/stat.hpp +++ b/capio/server/include/remote/handlers/stat.hpp @@ -16,7 +16,7 @@ inline void serve_remote_stat(const std::filesystem::path &path, const std::stri const CapioFile &c_file = storage_manager->get(path); off64_t file_size = c_file.getFileSize(); - bool is_dir = c_file.directory(); + bool is_dir = c_file.isDirectory(); serve_remote_stat_request(path, source_tid, file_size, is_dir, dest); } @@ -26,7 +26,7 @@ void wait_for_completion(const std::filesystem::path &path, int source_tid, dest.c_str()); const CapioFile &c_file = storage_manager->get(path); - c_file.waitForCompletion(); + c_file.waitForCommit(); LOG("File %s has been completed. serving stats data", path.c_str()); serve_remote_stat(path, dest, source_tid); } @@ -39,7 +39,7 @@ inline void handle_remote_stat(int source_tid, const std::filesystem::path &path const auto c_file = storage_manager->tryGet(path); if (c_file) { LOG("File %s is present on capio file system", path.c_str()); - if (c_file->get().complete() || CapioCLEngine::get().isFirable(path)) { + if (c_file->get().isCommitted() || CapioCLEngine::get().isFirable(path)) { LOG("file is complete. serving file"); serve_remote_stat(path, dest, source_tid); } else { // wait for completion diff --git a/capio/server/include/storage/capio_file.hpp b/capio/server/include/storage/capio_file.hpp index 79406842c..c1f0b69bf 100644 --- a/capio/server/include/storage/capio_file.hpp +++ b/capio/server/include/storage/capio_file.hpp @@ -49,36 +49,36 @@ class CapioFile { std::set, compare> _sectors; // vector of (tid, fd) std::vector> _threads_fd; - bool _complete = false; // whether the file is completed / committed + bool _committed = false; // whether the file is completed / committed /*sync variables*/ mutable std::mutex _mutex; mutable std::condition_variable _complete_cv; mutable std::condition_variable _data_avail_cv; - inline off64_t _getStoredSize() const { + off64_t _getStoredSize() const { auto it = _sectors.rbegin(); return (it == _sectors.rend()) ? 0 : it->second; } + bool _first_write = true; + long _n_files = 0; // useful for directories + long _n_files_expected = -1; // useful for directories - public: - bool first_write = true; - long int n_files = 0; // useful for directories - long int n_files_expected = -1; // useful for directories /* * file size in the home node. In a given moment could not be up-to-date. * This member is useful because a node different from the home node * could need to known the size of the file but not its content */ - std::size_t real_file_size = 0; + std::size_t _real_file_size = 0; + public: CapioFile() : _buf_size(0), _directory(false), _permanent(false) {} CapioFile(bool directory, long int n_files_expected, bool permanent, off64_t init_size, long int n_close_expected) : _buf_size(init_size), _directory(directory), _n_close_expected(n_close_expected), - _permanent(permanent), n_files_expected(n_files_expected + 2) {} + _permanent(permanent), _n_files_expected(n_files_expected + 2) {} CapioFile(bool directory, bool permanent, off64_t init_size, long int n_close_expected = -1) : _buf_size(init_size), _directory(directory), _n_close_expected(n_close_expected), @@ -105,33 +105,34 @@ class CapioFile { } } - [[nodiscard]] bool complete() const { - START_LOG(gettid(), "capio_file is complete? %s", this->_complete ? "true" : "false"); + [[nodiscard]] bool isCommitted() const { + START_LOG(gettid(), "capio_file is complete? %s", this->_committed ? "true" : "false"); std::lock_guard lg(_mutex); - return this->_complete; + return this->_committed; } - void waitForCompletion() const { + void waitForCommit() const { START_LOG(gettid(), "call()"); LOG("Thread waiting for file to be committed"); std::unique_lock lock(_mutex); - _complete_cv.wait(lock, [this] { return _complete; }); + _complete_cv.wait(lock, [this] { return _committed; }); } void waitForData(long offset) const { START_LOG(gettid(), "call()"); LOG("Thread waiting for data to be available"); std::unique_lock lock(_mutex); - _data_avail_cv.wait( - lock, [offset, this] { return (offset >= this->_getStoredSize()) || this->_complete; }); + _data_avail_cv.wait(lock, [offset, this] { + return (offset >= this->_getStoredSize()) || this->_committed; + }); } - void setComplete(bool complete = true) { + void setCommitted(bool complete = true) { START_LOG(gettid(), "setting capio_file._complete=%s", complete ? "true" : "false"); std::lock_guard lg(_mutex); - if (this->_complete != complete) { - this->_complete = complete; - if (this->_complete) { + if (this->_committed != complete) { + this->_committed = complete; + if (this->_committed) { _complete_cv.notify_all(); _data_avail_cv.notify_all(); } @@ -140,17 +141,12 @@ class CapioFile { void addFd(int tid, int fd) { _threads_fd.emplace_back(tid, fd); } - [[nodiscard]] bool bufToAllocate() const { - std::lock_guard lg(_mutex); - return _buf == nullptr; - } - void close() { _n_close++; _n_opens--; } - void commit() { + void dump() { START_LOG(gettid(), "call()"); if (_permanent && !_directory && _home_node) { @@ -173,36 +169,31 @@ class CapioFile { START_LOG(gettid(), "call(path=%s, home_node=%s)", path.c_str(), home_node ? "true" : "false"); std::lock_guard lock(_mutex); - // TODO: will use malloc in order to be able to use realloc - _home_node = home_node; - if (_permanent && home_node) { - if (_directory) { - std::filesystem::create_directory(path); - std::filesystem::permissions(path, std::filesystem::perms::owner_all); - _buf = new char[_buf_size]; - } else { - LOG("creating mem mapped file"); - _fd = ::open(path.c_str(), O_RDWR | O_CREAT, S_IRWXU | S_IRGRP | S_IROTH); - if (_fd == -1) { - ERR_EXIT("open %s CapioFile constructor", path.c_str()); - } - if (ftruncate(_fd, _buf_size) == -1) { - ERR_EXIT("ftruncate CapioFile constructor"); - } - _buf = - (char *) mmap(nullptr, _buf_size, PROT_READ | PROT_WRITE, MAP_SHARED, _fd, 0); - if (_buf == MAP_FAILED) { - ERR_EXIT("mmap CapioFile constructor"); + if (this->_buf == nullptr) { + _home_node = home_node; + if (_permanent && home_node) { + if (_directory) { + std::filesystem::create_directory(path); + std::filesystem::permissions(path, std::filesystem::perms::owner_all); + _buf = new char[_buf_size]; + } else { + LOG("creating mem mapped file"); + _fd = ::open(path.c_str(), O_RDWR | O_CREAT, S_IRWXU | S_IRGRP | S_IROTH); + if (_fd == -1) { + ERR_EXIT("open %s CapioFile constructor", path.c_str()); + } + if (ftruncate(_fd, _buf_size) == -1) { + ERR_EXIT("ftruncate CapioFile constructor"); + } + _buf = (char *) mmap(nullptr, _buf_size, PROT_READ | PROT_WRITE, MAP_SHARED, + _fd, 0); + if (_buf == MAP_FAILED) { + ERR_EXIT("mmap CapioFile constructor"); + } } + } else { + _buf = new char[_buf_size]; } - } else { - _buf = new char[_buf_size]; - } - } - - void createBufferIfNeeded(const std::filesystem::path &path, bool home_node) { - if (bufToAllocate()) { - createBuffer(path, home_node); } } @@ -232,7 +223,7 @@ class CapioFile { char *getBuffer() { return _buf; } - [[nodiscard]] off64_t getBufferSize() const { return _buf_size; } + [[nodiscard]] off64_t getBufSize() const { return _buf_size; } [[nodiscard]] const std::vector> &getFds() const { return _threads_fd; } @@ -368,7 +359,7 @@ class CapioFile { [[nodiscard]] bool deletable() const { return _n_opens <= 0; } - [[nodiscard]] bool directory() const { return _directory; } + [[nodiscard]] bool isDirectory() const { return _directory; } void open() { _n_opens++; } @@ -472,6 +463,44 @@ class CapioFile { queue.read(_buf + offset, num_bytes); _data_avail_cv.notify_all(); } + + // TODO: Understand the scope of this method and find a better name + std::size_t getRealFileSize() const { + std::lock_guard lg(_mutex); + return this->_real_file_size; + } + + void setRealFileSize(const off64_t size) { + std::lock_guard lg(_mutex); + this->_real_file_size = size; + } + + bool isFirstWrite() const { + std::lock_guard lg(_mutex); + return this->_first_write; + } + + // TODO: add a dedicated CapioFile::write() and CapioFile::read() method, remove this method + // from public scope + void registerFirstWrite() { + std::lock_guard lg(_mutex); + this->_first_write = false; + } + + void incrementDirectoryFileCount(const int count = 1) { + std::lock_guard lg(_mutex); + this->_n_files += count; + } + + long getCurrentDirectoryFileCount() const { + std::lock_guard lg(_mutex); + return this->_n_files; + } + + long getDirectoryExpectedFileCount() const { + std::lock_guard lg(_mutex); + return this->_n_files_expected; + } }; #endif // CAPIO_SERVER_STORAGE_CAPIO_FILE_HPP \ No newline at end of file diff --git a/capio/server/include/utils/common.hpp b/capio/server/include/utils/common.hpp index 0b2d0ef38..2682fd2f8 100644 --- a/capio/server/include/utils/common.hpp +++ b/capio/server/include/utils/common.hpp @@ -51,7 +51,7 @@ inline void send_dirent_to_client(int tid, int fd, CapioFile &c_file, off64_t of } const auto &path_to_check = storage_manager->getPath(tid, fd); - if (!c_file.complete() && CapioCLEngine::get().isFirable(path_to_check)) { + if (!c_file.isCommitted() && CapioCLEngine::get().isFirable(path_to_check)) { LOG("File %s has mode no_update and not enough data is available", path_to_check.c_str()); std::thread t(wait_for_dirent_data, (last_entry + 1) * sizeof(linux_dirent64), tid, fd, count, std::ref(c_file)); diff --git a/capio/server/src/storage_manager.cpp b/capio/server/src/storage_manager.cpp index adb139b8e..93639cfc1 100644 --- a/capio/server/src/storage_manager.cpp +++ b/capio/server/src/storage_manager.cpp @@ -39,18 +39,18 @@ void StorageManager::addDirectoryEntry(const pid_t tid, const std::filesystem::p ld.d_reclen = sizeof(linux_dirent64); CapioFile &c_file = get(dir); - c_file.createBufferIfNeeded(dir, true); + c_file.createBuffer(dir, true); void *file_shm = c_file.getBuffer(); const off64_t file_size = c_file.getStoredSize(); const off64_t data_size = file_size + ld.d_reclen; - const size_t file_shm_size = c_file.getBufferSize(); + const size_t file_shm_size = c_file.getBufSize(); ld.d_off = data_size; if (data_size > file_shm_size) { file_shm = c_file.expandBuffer(data_size); } - ld.d_type = (c_file.directory() ? DT_DIR : DT_REG); + ld.d_type = (c_file.isDirectory() ? DT_DIR : DT_REG); memcpy((char *) file_shm + file_size, &ld, sizeof(ld)); const off64_t base_offset = file_size; @@ -59,10 +59,10 @@ void StorageManager::addDirectoryEntry(const pid_t tid, const std::filesystem::p reinterpret_cast(static_cast(file_shm) + file_size)->d_name); c_file.insertSector(base_offset, data_size); - ++c_file.n_files; + c_file.incrementDirectoryFileCount(); client_manager->registerProducedFile(tid, dir); - if (c_file.n_files == c_file.n_files_expected) { - c_file.setComplete(); + if (c_file.getCurrentDirectoryFileCount() == c_file.getDirectoryExpectedFileCount()) { + c_file.setCommitted(); } } StorageManager::StorageManager() { @@ -305,8 +305,8 @@ off64_t StorageManager::addDirectory(const pid_t tid, const std::filesystem::pat if (!get_file_location_opt(path)) { CapioFile &c_file = add(path, true, CAPIO_DEFAULT_DIR_INITIAL_SIZE); - if (c_file.first_write) { - c_file.first_write = false; + if (c_file.isFirstWrite()) { + c_file.registerFirstWrite(); // TODO: it works only if there is one prod per file if (is_capio_dir(path)) { add_file_location(path, node_name, -1); @@ -326,8 +326,8 @@ off64_t StorageManager::addDirectory(const pid_t tid, const std::filesystem::pat void StorageManager::updateDirectory(const pid_t tid, const std::filesystem::path &file_path) { START_LOG(gettid(), "call(file_path=%s)", file_path.c_str()); const auto &dir = get_parent_dir_path(file_path); - if (CapioFile &c_file = get(dir.c_str()); c_file.first_write) { - c_file.first_write = false; + if (CapioFile &c_file = get(dir.c_str()); c_file.isFirstWrite()) { + c_file.registerFirstWrite(); write_file_location(dir); } addDirectoryEntry(tid, file_path, dir, REGULAR_ENTRY); diff --git a/capio/tests/unit/server/src/storage_manager.cpp b/capio/tests/unit/server/src/storage_manager.cpp index 6f550a215..e86229e8f 100644 --- a/capio/tests/unit/server/src/storage_manager.cpp +++ b/capio/tests/unit/server/src/storage_manager.cpp @@ -48,12 +48,12 @@ TEST(StorageManagerTestEnvironment, testInitDirectory) { const auto &dir = storage_manager->get("myDirectory"); - EXPECT_EQ(dir.getBufferSize(), CAPIO_DEFAULT_DIR_INITIAL_SIZE); + EXPECT_EQ(dir.getBufSize(), CAPIO_DEFAULT_DIR_INITIAL_SIZE); storage_manager->updateDirectory(1, "myDirectory"); const auto &dir1 = storage_manager->get("myDirectory"); - EXPECT_FALSE(dir1.first_write); + EXPECT_FALSE(dir1.isFirstWrite()); } TEST(StorageManagerTestEnvironment, testAddDirectoryFailure) {