From 2983925da2a29b698334b09568346802c62fb542 Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 11 Mar 2026 20:21:31 +0000 Subject: [PATCH] Refactor naming scheme of class CapioFile --- capio/server/capio_server.cpp | 2 +- capio/server/include/handlers/close.hpp | 4 +- capio/server/include/handlers/exig.hpp | 6 +- capio/server/include/handlers/getdents.hpp | 15 ++- capio/server/include/handlers/read.hpp | 32 +++--- capio/server/include/handlers/seek.hpp | 4 +- capio/server/include/handlers/stat.hpp | 14 +-- capio/server/include/handlers/unlink.hpp | 2 +- capio/server/include/handlers/write.hpp | 10 +- capio/server/include/remote/handlers/read.hpp | 34 +++--- capio/server/include/remote/handlers/stat.hpp | 8 +- .../include/{utils => storage}/capio_file.hpp | 106 +++++++++--------- capio/server/include/storage/manager.hpp | 2 +- capio/server/include/utils/common.hpp | 12 +- capio/server/src/storage_manager.cpp | 26 ++--- capio/tests/unit/server/src/capio_file.cpp | 36 +++--- .../tests/unit/server/src/storage_manager.cpp | 14 +-- 17 files changed, 160 insertions(+), 167 deletions(-) rename capio/server/include/{utils => storage}/capio_file.hpp (81%) diff --git a/capio/server/capio_server.cpp b/capio/server/capio_server.cpp index d6fcb2a01..59f22f4b6 100644 --- a/capio/server/capio_server.cpp +++ b/capio/server/capio_server.cpp @@ -30,7 +30,7 @@ #include "common/logger.hpp" #include "common/requests.hpp" #include "common/semaphore.hpp" -#include "utils/capio_file.hpp" +#include "storage/capio_file.hpp" #include "utils/common.hpp" #include "utils/env.hpp" #include "utils/types.hpp" diff --git a/capio/server/include/handlers/close.hpp b/capio/server/include/handlers/close.hpp index e9be35c6c..a9133327f 100644 --- a/capio/server/include/handlers/close.hpp +++ b/capio/server/include/handlers/close.hpp @@ -20,10 +20,10 @@ inline void handle_close(int tid, int fd) { LOG("File was closed", path.c_str()); if (CapioCLEngine::get().getCommitRule(path) == capiocl::commitRules::ON_CLOSE && - c_file.is_closed()) { + c_file.closed()) { LOG("Capio File %s is closed and commit rule is on_close. setting it to complete", path.c_str()); - c_file.set_complete(); + c_file.setComplete(); c_file.commit(); } diff --git a/capio/server/include/handlers/exig.hpp b/capio/server/include/handlers/exig.hpp index c41cc0ffd..443a8a6e3 100644 --- a/capio/server/include/handlers/exig.hpp +++ b/capio/server/include/handlers/exig.hpp @@ -14,16 +14,16 @@ 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.is_dir()) { + if (c_file.directory()) { LOG("file %s is dir", path.c_str()); long int n_committed = c_file.n_files_expected; if (n_committed <= c_file.n_files) { LOG("Setting file %s to complete", path.c_str()); - c_file.set_complete(); + c_file.setComplete(); } } else { LOG("Setting file %s to complete", path.c_str()); - c_file.set_complete(); + c_file.setComplete(); c_file.commit(); } c_file.close(); diff --git a/capio/server/include/handlers/getdents.hpp b/capio/server/include/handlers/getdents.hpp index dee5d77f0..df2074f02 100644 --- a/capio/server/include/handlers/getdents.hpp +++ b/capio/server/include/handlers/getdents.hpp @@ -17,17 +17,16 @@ inline void request_remote_getdents(int tid, int fd, off64_t count) { CapioFile &c_file = storage_manager->get(tid, fd); off64_t offset = storage_manager->getFileOffset(tid, fd); off64_t end_of_read = offset + count; - off64_t end_of_sector = c_file.get_sector_end(offset); + off64_t end_of_sector = c_file.getSectorEnd(offset); - if (c_file.is_complete() && - (end_of_read <= end_of_sector || - (end_of_sector == -1 ? 0 : end_of_sector) == c_file.real_file_size)) { + if (c_file.complete() && (end_of_read <= end_of_sector || + (end_of_sector == -1 ? 0 : end_of_sector) == c_file.real_file_size)) { 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.create_buffer_if_needed(storage_manager->getPath(tid, fd), false); - client_manager->replyToClient(tid, offset, c_file.get_buffer(), count); + c_file.createBufferIfNeeded(storage_manager->getPath(tid, fd), false); + client_manager->replyToClient(tid, offset, c_file.getBuffer(), count); storage_manager->setFileOffset(tid, fd, offset + count); } else { LOG("Delegating to backend remote read"); @@ -53,6 +52,7 @@ inline void handle_getdents(int tid, int fd, long int count) { if (strcmp(std::get<0>(get_file_location(path_to_check)), node_name) == 0) { handle_getdents(tid, fd, count); } else { + request_remote_getdents(tid, fd, count); } }); @@ -63,8 +63,7 @@ inline void handle_getdents(int tid, int fd, long int count) { off64_t offset = storage_manager->getFileOffset(tid, fd); send_dirent_to_client(tid, fd, c_file, offset, count); } else { - LOG("File is remote"); - LOG("Delegating to backend remote read"); + LOG("File is remote. Delegating to backend remote read"); request_remote_getdents(tid, fd, count); } } diff --git a/capio/server/include/handlers/read.hpp b/capio/server/include/handlers/read.hpp index 29b9c2bc1..07d2f69b6 100644 --- a/capio/server/include/handlers/read.hpp +++ b/capio/server/include/handlers/read.hpp @@ -20,7 +20,7 @@ inline void handle_pending_read(int tid, int fd, long int process_offset, long i const std::filesystem::path &path = storage_manager->getPath(tid, fd); CapioFile &c_file = storage_manager->get(path); - off64_t end_of_sector = c_file.get_sector_end(process_offset); + off64_t end_of_sector = c_file.getSectorEnd(process_offset); off64_t end_of_read = process_offset + count; off64_t bytes_read; @@ -30,8 +30,8 @@ inline void handle_pending_read(int tid, int fd, long int process_offset, long i bytes_read = end_of_sector - process_offset; } - c_file.create_buffer_if_needed(path, false); - client_manager->replyToClient(tid, process_offset, c_file.get_buffer(), bytes_read); + c_file.createBufferIfNeeded(path, false); + client_manager->replyToClient(tid, process_offset, c_file.getBuffer(), bytes_read); storage_manager->setFileOffset(tid, fd, process_offset + bytes_read); // TODO: check if the file was moved to the disk @@ -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.is_complete() || is_prod; + const bool file_complete = c_file.complete() || 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.wait_for_completion(); + c_file.waitForCompletion(); handle_pending_read(tid, fd, process_offset, count); }); t.detach(); @@ -63,7 +63,7 @@ inline void handle_local_read(int tid, int fd, off64_t count, bool is_prod) { LOG("Data can be served. Condition met: %s %s", file_complete ? "c_file.is_complete()" : "", CapioCLEngine::get().isFirable(path) ? "CapioCLEngine::get().isFirable(path)" : ""); - const off64_t end_of_sector = c_file.get_sector_end(process_offset); + const off64_t end_of_sector = c_file.getSectorEnd(process_offset); if (end_of_sector == -1) { LOG("End of sector is -1. returning process_offset without serving data"); client_manager->replyToClient(tid, process_offset); @@ -74,7 +74,7 @@ inline void handle_local_read(int tid, int fd, off64_t count, bool is_prod) { LOG("Mode is NO_UPDATE, but not enough data is available. Awaiting for data on " "a separate thread before sending it to client"); std::thread t([&c_file, tid, fd, count, process_offset] { - c_file.wait_for_data(process_offset + count); + c_file.waitForData(process_offset + count); handle_pending_read(tid, fd, process_offset, count); }); t.detach(); @@ -85,8 +85,8 @@ 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.create_buffer_if_needed(path, false); - client_manager->replyToClient(tid, process_offset, c_file.get_buffer(), read_size); + c_file.createBufferIfNeeded(path, false); + client_manager->replyToClient(tid, process_offset, c_file.getBuffer(), read_size); storage_manager->setFileOffset(tid, fd, process_offset + read_size); } @@ -97,18 +97,17 @@ inline void request_remote_read(int tid, int fd, off64_t count) { CapioFile &c_file = storage_manager->get(path); off64_t offset = storage_manager->getFileOffset(tid, fd); off64_t end_of_read = offset + count; - off64_t end_of_sector = c_file.get_sector_end(offset); + off64_t end_of_sector = c_file.getSectorEnd(offset); - if (c_file.is_complete() && - (end_of_read <= end_of_sector || - (end_of_sector == -1 ? 0 : end_of_sector) == c_file.real_file_size)) { + if (c_file.complete() && (end_of_read <= end_of_sector || + (end_of_sector == -1 ? 0 : end_of_sector) == c_file.real_file_size)) { 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.create_buffer_if_needed(path, false); + c_file.createBufferIfNeeded(path, false); - client_manager->replyToClient(tid, offset, c_file.get_buffer(), count); + client_manager->replyToClient(tid, offset, c_file.getBuffer(), count); storage_manager->setFileOffset(tid, fd, offset + count); } else { LOG("Delegating to backend remote read"); @@ -151,8 +150,7 @@ inline void handle_read(int tid, int fd, off64_t count) { LOG("File is local. handling local read"); handle_local_read(tid, fd, count, is_prod); } else { - LOG("File is remote"); - LOG("Delegating to backend remote read"); + LOG("File is remote. Delegating to backend remote read"); request_remote_read(tid, fd, count); } } diff --git a/capio/server/include/handlers/seek.hpp b/capio/server/include/handlers/seek.hpp index 9335d44a5..c804b8de9 100644 --- a/capio/server/include/handlers/seek.hpp +++ b/capio/server/include/handlers/seek.hpp @@ -19,7 +19,7 @@ void handle_seek_data(int tid, int fd, off64_t offset) { START_LOG(gettid(), "call(tid=%d, fd=%d, offset=%ld)", tid, fd, offset); CapioFile &c_file = storage_manager->get(tid, fd); - offset = c_file.seek_data(offset); + offset = c_file.seekData(offset); storage_manager->setFileOffset(tid, fd, offset); client_manager->replyToClient(tid, offset); } @@ -35,7 +35,7 @@ inline void handle_seek_hole(int tid, int fd, off64_t offset) { START_LOG(gettid(), "call(tid=%d, fd=%d, offset=%ld)", tid, fd, offset); CapioFile &c_file = storage_manager->get(tid, fd); - offset = c_file.seek_hole(offset); + offset = c_file.seekHole(offset); storage_manager->setFileOffset(tid, fd, offset); client_manager->replyToClient(tid, offset); } diff --git a/capio/server/include/handlers/stat.hpp b/capio/server/include/handlers/stat.hpp index e4fb06cf5..ef4c6a597 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.is_complete() || CapioCLEngine::get().isFirable(path) || + if (c_file.complete() || CapioCLEngine::get().isFirable(path) || strcmp(std::get<0>(get_file_location(path)), node_name) == 0) { - client_manager->replyToClient(tid, c_file.get_file_size()); - client_manager->replyToClient(tid, static_cast(c_file.is_dir() ? 1 : 0)); + client_manager->replyToClient(tid, c_file.getFileSize()); + client_manager->replyToClient(tid, static_cast(c_file.directory() ? 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.is_complete() || strcmp(std::get<0>(file_location_opt->get()), node_name) == 0 || + if (c_file.complete() || 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.get_file_size()); - client_manager->replyToClient(tid, static_cast(c_file.is_dir() ? 1 : 0)); + client_manager->replyToClient(tid, c_file.getFileSize()); + client_manager->replyToClient(tid, static_cast(c_file.directory() ? 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.create_buffer_if_needed(path, false); + c_file.createBufferIfNeeded(path, false); handle_remote_stat_request(tid, path); } } diff --git a/capio/server/include/handlers/unlink.hpp b/capio/server/include/handlers/unlink.hpp index 22b670001..19135dcf2 100644 --- a/capio/server/include/handlers/unlink.hpp +++ b/capio/server/include/handlers/unlink.hpp @@ -17,7 +17,7 @@ void unlink_handler(const char *const str) { const auto c_file_opt = storage_manager->tryGet(path); if (c_file_opt) { // TODO: it works only in the local case CapioFile &c_file = c_file_opt->get(); - if (c_file.is_deletable()) { + if (c_file.deletable()) { storage_manager->remove(path); delete_from_files_location(path); } diff --git a/capio/server/include/handlers/write.hpp b/capio/server/include/handlers/write.hpp index b9233ccd2..a65c7db7c 100644 --- a/capio/server/include/handlers/write.hpp +++ b/capio/server/include/handlers/write.hpp @@ -15,17 +15,17 @@ 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.get_buf_size(); + off64_t file_shm_size = c_file.getBufferSize(); SPSCQueue &data_buf = client_manager->getClientToServerDataBuffers(tid); - c_file.create_buffer_if_needed(path, true); + c_file.createBufferIfNeeded(path, true); if (end_of_write > file_shm_size) { - c_file.expand_buffer(end_of_write); + c_file.expandBuffer(end_of_write); } - c_file.read_from_queue(data_buf, offset, count); + c_file.readFromQueue(data_buf, offset, count); client_manager->registerProducedFile(tid, path); - c_file.insert_sector(offset, end_of_write); + c_file.insertSector(offset, end_of_write); if (c_file.first_write) { c_file.first_write = false; write_file_location(path); diff --git a/capio/server/include/remote/handlers/read.hpp b/capio/server/include/remote/handlers/read.hpp index 787d4f854..474241784 100644 --- a/capio/server/include/remote/handlers/read.hpp +++ b/capio/server/include/remote/handlers/read.hpp @@ -19,18 +19,18 @@ inline void serve_remote_read(const std::filesystem::path &path, const std::stri // Send all the rest of the file not only the number of bytes requested // Useful for caching CapioFile &c_file = storage_manager->get(path); - long int nbytes = c_file.get_stored_size() - offset; + long int nbytes = c_file.getStoredSize() - offset; off64_t prefetch_data_size = get_prefetch_data_size(); if (prefetch_data_size != 0 && nbytes > prefetch_data_size) { nbytes = prefetch_data_size; } - const off64_t file_size = c_file.get_stored_size(); + const off64_t file_size = c_file.getStoredSize(); // send request serve_remote_read_request(tid, fd, count, nbytes, file_size, complete, is_getdents, dest); // send data - backend->send_file(c_file.get_buffer() + offset, nbytes, dest); + backend->send_file(c_file.getBuffer() + offset, nbytes, dest); } inline void handle_read_reply(int tid, int fd, long count, off64_t file_size, off64_t nbytes, @@ -45,11 +45,11 @@ inline void handle_read_reply(int tid, int fd, long count, off64_t file_size, of CapioFile &c_file = storage_manager->get(path); off64_t offset = storage_manager->getFileOffset(tid, fd); c_file.real_file_size = file_size; - c_file.insert_sector(offset, offset + nbytes); - c_file.set_complete(complete); + c_file.insertSector(offset, offset + nbytes); + c_file.setComplete(complete); - off64_t end_of_sector = c_file.get_sector_end(offset); - c_file.create_buffer_if_needed(path, false); + off64_t end_of_sector = c_file.getSectorEnd(offset); + c_file.createBufferIfNeeded(path, false); off64_t bytes_read; off64_t end_of_read = offset + count; if (end_of_sector > end_of_read) { @@ -61,7 +61,7 @@ inline void handle_read_reply(int tid, int fd, long count, off64_t file_size, of if (is_getdents) { send_dirent_to_client(tid, fd, c_file, offset, bytes_read); } else { - client_manager->replyToClient(tid, offset, c_file.get_buffer(), count); + client_manager->replyToClient(tid, offset, c_file.getBuffer(), count); storage_manager->setFileOffset(tid, fd, offset + count); } } @@ -74,8 +74,8 @@ 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.wait_for_data(offset + count); - serve_remote_read(path, dest, tid, fd, count, offset, c_file.is_complete(), is_getdents); + c_file.waitForData(offset + count); + serve_remote_read(path, dest, tid, fd, count, offset, c_file.complete(), is_getdents); } inline void handle_remote_read(const std::filesystem::path &path, const std::string &source, @@ -85,9 +85,9 @@ inline void handle_remote_read(const std::filesystem::path &path, const std::str path.c_str(), source.c_str(), tid, fd, count, offset, is_getdents ? "true" : "false"); CapioFile &c_file = storage_manager->get(path); - bool data_available = (offset + count <= c_file.get_stored_size()); - if (c_file.is_complete() || (CapioCLEngine::get().isFirable(path) && data_available)) { - serve_remote_read(path, source, tid, fd, count, offset, c_file.is_complete(), is_getdents); + 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); } else { std::thread t(wait_for_data, path, source, tid, fd, count, offset, is_getdents); t.detach(); @@ -107,14 +107,14 @@ 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.create_buffer_if_needed(path, false); + c_file.createBufferIfNeeded(path, false); if (nbytes != 0) { - auto file_shm_size = c_file.get_buf_size(); + auto file_shm_size = c_file.getBufferSize(); auto file_size_recv = offset + nbytes; if (file_size_recv > file_shm_size) { - c_file.expand_buffer(file_size_recv); + c_file.expandBuffer(file_size_recv); } - c_file.read_from_node(source, offset, nbytes); + c_file.readFromNode(source, offset, nbytes); nbytes *= sizeof(char); } handle_read_reply(tid, fd, count, file_size, nbytes, complete, is_getdents); diff --git a/capio/server/include/remote/handlers/stat.hpp b/capio/server/include/remote/handlers/stat.hpp index f9cc7b231..c328221f5 100644 --- a/capio/server/include/remote/handlers/stat.hpp +++ b/capio/server/include/remote/handlers/stat.hpp @@ -15,8 +15,8 @@ inline void serve_remote_stat(const std::filesystem::path &path, const std::stri source_tid); const CapioFile &c_file = storage_manager->get(path); - off64_t file_size = c_file.get_file_size(); - bool is_dir = c_file.is_dir(); + off64_t file_size = c_file.getFileSize(); + bool is_dir = c_file.directory(); 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.wait_for_completion(); + c_file.waitForCompletion(); 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().is_complete() || CapioCLEngine::get().isFirable(path)) { + if (c_file->get().complete() || 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/utils/capio_file.hpp b/capio/server/include/storage/capio_file.hpp similarity index 81% rename from capio/server/include/utils/capio_file.hpp rename to capio/server/include/storage/capio_file.hpp index 15cbebbc8..79406842c 100644 --- a/capio/server/include/utils/capio_file.hpp +++ b/capio/server/include/storage/capio_file.hpp @@ -1,5 +1,5 @@ -#ifndef CAPIO_SERVER_UTILS_CAPIO_FILE_HPP -#define CAPIO_SERVER_UTILS_CAPIO_FILE_HPP +#ifndef CAPIO_SERVER_STORAGE_CAPIO_FILE_HPP +#define CAPIO_SERVER_STORAGE_CAPIO_FILE_HPP #include #include @@ -33,7 +33,6 @@ struct compare { }; class CapioFile { - private: char *_buf = nullptr; // buffer containing the data off64_t _buf_size; bool _directory = false; @@ -57,7 +56,7 @@ class CapioFile { mutable std::condition_variable _complete_cv; mutable std::condition_variable _data_avail_cv; - inline off64_t _get_stored_size() const { + inline off64_t _getStoredSize() const { auto it = _sectors.rbegin(); return (it == _sectors.rend()) ? 0 : it->second; } @@ -106,31 +105,30 @@ class CapioFile { } } - [[nodiscard]] inline bool is_complete() const { + [[nodiscard]] bool complete() const { START_LOG(gettid(), "capio_file is complete? %s", this->_complete ? "true" : "false"); - std::lock_guard lg(_mutex); + std::lock_guard lg(_mutex); return this->_complete; } - inline void wait_for_completion() const { + void waitForCompletion() const { START_LOG(gettid(), "call()"); LOG("Thread waiting for file to be committed"); - std::unique_lock lock(_mutex); + std::unique_lock lock(_mutex); _complete_cv.wait(lock, [this] { return _complete; }); } - inline void wait_for_data(long offset) const { + 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->_get_stored_size()) || this->_complete; - }); + std::unique_lock lock(_mutex); + _data_avail_cv.wait( + lock, [offset, this] { return (offset >= this->_getStoredSize()) || this->_complete; }); } - inline void set_complete(bool complete = true) { + void setComplete(bool complete = true) { START_LOG(gettid(), "setting capio_file._complete=%s", complete ? "true" : "false"); - std::lock_guard lg(_mutex); + std::lock_guard lg(_mutex); if (this->_complete != complete) { this->_complete = complete; if (this->_complete) { @@ -140,14 +138,14 @@ class CapioFile { } } - inline void add_fd(int tid, int fd) { _threads_fd.emplace_back(tid, fd); } + void addFd(int tid, int fd) { _threads_fd.emplace_back(tid, fd); } - [[nodiscard]] inline bool buf_to_allocate() const { - std::lock_guard lg(_mutex); + [[nodiscard]] bool bufToAllocate() const { + std::lock_guard lg(_mutex); return _buf == nullptr; } - inline void close() { + void close() { _n_close++; _n_opens--; } @@ -156,7 +154,7 @@ class CapioFile { START_LOG(gettid(), "call()"); if (_permanent && !_directory && _home_node) { - off64_t size = get_file_size(); + off64_t size = getFileSize(); if (ftruncate(_fd, size) == -1) { ERR_EXIT("ftruncate commit capio_file"); } @@ -171,10 +169,10 @@ class CapioFile { * To be called when a process * execute a read or a write syscall */ - void create_buffer(const std::filesystem::path &path, bool home_node) { + void createBuffer(const std::filesystem::path &path, bool home_node) { START_LOG(gettid(), "call(path=%s, home_node=%s)", path.c_str(), home_node ? "true" : "false"); - std::lock_guard lock(_mutex); + 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) { @@ -202,13 +200,13 @@ class CapioFile { } } - inline void create_buffer_if_needed(const std::filesystem::path &path, bool home_node) { - if (buf_to_allocate()) { - create_buffer(path, home_node); + void createBufferIfNeeded(const std::filesystem::path &path, bool home_node) { + if (bufToAllocate()) { + createBuffer(path, home_node); } } - void memcpy_capio_file(char *new_p, char *old_p) const { + void memcopyCapioFile(char *new_p, char *old_p) const { for (auto §or : _sectors) { off64_t lbound = sector.first; off64_t ubound = sector.second; @@ -217,31 +215,29 @@ class CapioFile { } } - char *expand_buffer(off64_t data_size) { // TODO: use realloc + char *expandBuffer(off64_t data_size) { // TODO: use realloc off64_t double_size = _buf_size * 2; off64_t new_size = data_size > double_size ? data_size : double_size; char *new_buf = new char[new_size]; - std::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); // memcpy(new_p, old_p, file_shm_size); //TODO memcpy only the // sector // stored in CapioFile - memcpy_capio_file(new_buf, _buf); + memcopyCapioFile(new_buf, _buf); delete[] _buf; _buf = new_buf; _buf_size = new_size; return new_buf; } - inline char *get_buffer() { return _buf; } + char *getBuffer() { return _buf; } - [[nodiscard]] inline off64_t get_buf_size() const { return _buf_size; } + [[nodiscard]] off64_t getBufferSize() const { return _buf_size; } - [[nodiscard]] inline const std::vector> &get_fds() const { - return _threads_fd; - } + [[nodiscard]] const std::vector> &getFds() const { return _threads_fd; } - [[nodiscard]] inline off64_t get_file_size() const { - std::lock_guard lock(_mutex); + [[nodiscard]] off64_t getFileSize() const { + std::lock_guard lock(_mutex); if (!_sectors.empty()) { return _sectors.rbegin()->second; } else { @@ -255,7 +251,7 @@ class CapioFile { * sector, -1 otherwise * */ - [[nodiscard]] off64_t get_sector_end(off64_t offset) const { + [[nodiscard]] off64_t getSectorEnd(off64_t offset) const { START_LOG(gettid(), "call(offset=%ld)", offset); off64_t sector_end = -1; @@ -271,7 +267,7 @@ class CapioFile { return sector_end; } - [[nodiscard]] inline const std::set, compare> &get_sectors() const { + [[nodiscard]] const std::set, compare> &getSectors() const { return _sectors; } @@ -280,9 +276,9 @@ class CapioFile { * If the node is the home node then this is equals to * the real size of the file */ - [[nodiscard]] inline off64_t get_stored_size() const { - std::lock_guard lock(_mutex); - return this->_get_stored_size(); + [[nodiscard]] off64_t getStoredSize() const { + std::lock_guard lock(_mutex); + return this->_getStoredSize(); } /* @@ -297,11 +293,11 @@ class CapioFile { * in undefined * */ - void insert_sector(off64_t new_start, off64_t new_end) { + void insertSector(off64_t new_start, off64_t new_end) { START_LOG(gettid(), "call(new_start=%ld, new_end=%ld)", new_start, new_end); auto p = std::make_pair(new_start, new_end); - std::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); if (_sectors.empty()) { LOG("Insert sector <%ld, %ld>", p.first, p.second); @@ -366,15 +362,15 @@ class CapioFile { } } - [[nodiscard]] inline bool is_closed() const { + [[nodiscard]] bool closed() const { return _n_close_expected == -1 || _n_close == _n_close_expected; } - [[nodiscard]] inline bool is_deletable() const { return _n_opens <= 0; } + [[nodiscard]] bool deletable() const { return _n_opens <= 0; } - [[nodiscard]] inline bool is_dir() const { return _directory; } + [[nodiscard]] bool directory() const { return _directory; } - inline void open() { _n_opens++; } + void open() { _n_opens++; } /* * From the manual: @@ -387,7 +383,7 @@ class CapioFile { * Fails if offset points past the end of the file. * */ - off64_t seek_data(off64_t offset) { + off64_t seekData(off64_t offset) { if (_sectors.empty()) { if (offset == 0) { return 0; @@ -426,7 +422,7 @@ class CapioFile { * Fails if offset points past the end of the file. * */ - [[nodiscard]] off64_t seek_hole(off64_t offset) const { + [[nodiscard]] off64_t seekHole(off64_t offset) const { if (_sectors.empty()) { if (offset == 0) { return 0; @@ -451,7 +447,7 @@ class CapioFile { } } - inline void remove_fd(int tid, int fd) { + void removeFd(int tid, int fd) { auto it = std::find(_threads_fd.begin(), _threads_fd.end(), std::make_pair(tid, fd)); if (it != _threads_fd.end()) { _threads_fd.erase(it); @@ -463,19 +459,19 @@ class CapioFile { * @param buffer * @return */ - inline void read_from_node(const std::string &dest, off64_t offset, off64_t buffer_size) { - std::unique_lock lock(_mutex); + void readFromNode(const std::string &dest, off64_t offset, off64_t buffer_size) { + std::unique_lock lock(_mutex); backend->recv_file(_buf + offset, dest, buffer_size); _data_avail_cv.notify_all(); } - inline void read_from_queue(SPSCQueue &queue, size_t offset, long int num_bytes) { + void readFromQueue(SPSCQueue &queue, size_t offset, long int num_bytes) { START_LOG(gettid(), "call()"); - std::unique_lock lock(_mutex); + std::unique_lock lock(_mutex); queue.read(_buf + offset, num_bytes); _data_avail_cv.notify_all(); } }; -#endif // CAPIO_SERVER_UTILS_CAPIO_FILE_HPP \ No newline at end of file +#endif // CAPIO_SERVER_STORAGE_CAPIO_FILE_HPP \ No newline at end of file diff --git a/capio/server/include/storage/manager.hpp b/capio/server/include/storage/manager.hpp index 069c99132..eeef0d65f 100644 --- a/capio/server/include/storage/manager.hpp +++ b/capio/server/include/storage/manager.hpp @@ -4,7 +4,7 @@ #include #include -#include "utils/capio_file.hpp" +#include "capio_file.hpp" #include "utils/shared_mutex.hpp" #include diff --git a/capio/server/include/utils/common.hpp b/capio/server/include/utils/common.hpp index f850b7122..0b2d0ef38 100644 --- a/capio/server/include/utils/common.hpp +++ b/capio/server/include/utils/common.hpp @@ -7,8 +7,8 @@ #include "capiocl_adapter.hpp" #include "client-manager/client_manager.hpp" #include "common/dirent.hpp" +#include "storage/capio_file.hpp" #include "storage/manager.hpp" -#include "utils/capio_file.hpp" extern ClientManager *client_manager; extern StorageManager *storage_manager; @@ -22,9 +22,9 @@ inline void send_dirent_to_client(int tid, int fd, CapioFile &c_file, off64_t of struct linux_dirent64 *dir_entity; - char *incoming = c_file.get_buffer(); + char *incoming = c_file.getBuffer(); int first_entry = static_cast(offset / sizeof(linux_dirent64)); - off64_t end_of_read = std::min(offset + count, c_file.get_stored_size()); + off64_t end_of_read = std::min(offset + count, c_file.getStoredSize()); int last_entry = static_cast(end_of_read / sizeof(linux_dirent64)); off64_t actual_size = (last_entry - first_entry) * static_cast(sizeof(linux_dirent64)); @@ -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.is_complete() && CapioCLEngine::get().isFirable(path_to_check)) { + if (!c_file.complete() && 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)); @@ -67,8 +67,8 @@ inline void wait_for_dirent_data(const off64_t wait_size, const int wait_tid, co const auto current_size = storage_manager->getFileOffset(wait_tid, wait_fd); START_LOG(gettid(), "call(wait_size=%d, current_size = %ld, wait_fd=%d, wait_count=%d)", wait_size, current_size, wait_fd, wait_count); - wait_c_file.wait_for_data(wait_size); - LOG("New capio file size = %ld", wait_c_file.get_stored_size()); + wait_c_file.waitForData(wait_size); + LOG("New capio file size = %ld", wait_c_file.getStoredSize()); send_dirent_to_client(wait_tid, wait_fd, wait_c_file, current_size, wait_count); } diff --git a/capio/server/src/storage_manager.cpp b/capio/server/src/storage_manager.cpp index 877b09689..adb139b8e 100644 --- a/capio/server/src/storage_manager.cpp +++ b/capio/server/src/storage_manager.cpp @@ -6,8 +6,8 @@ #include "common/dirent.hpp" #include "common/filesystem.hpp" #include "common/logger.hpp" +#include "storage/capio_file.hpp" #include "storage/manager.hpp" -#include "utils/capio_file.hpp" #include "utils/capiocl_adapter.hpp" #include "utils/common.hpp" #include "utils/location.hpp" @@ -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.create_buffer_if_needed(dir, true); - void *file_shm = c_file.get_buffer(); - const off64_t file_size = c_file.get_stored_size(); + c_file.createBufferIfNeeded(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.get_buf_size(); + const size_t file_shm_size = c_file.getBufferSize(); ld.d_off = data_size; if (data_size > file_shm_size) { - file_shm = c_file.expand_buffer(data_size); + file_shm = c_file.expandBuffer(data_size); } - ld.d_type = (c_file.is_dir() ? DT_DIR : DT_REG); + ld.d_type = (c_file.directory() ? DT_DIR : DT_REG); memcpy((char *) file_shm + file_size, &ld, sizeof(ld)); const off64_t base_offset = file_size; @@ -58,11 +58,11 @@ void StorageManager::addDirectoryEntry(const pid_t tid, const std::filesystem::p LOG("STORED FILENAME LD: %s", reinterpret_cast(static_cast(file_shm) + file_size)->d_name); - c_file.insert_sector(base_offset, data_size); + c_file.insertSector(base_offset, data_size); ++c_file.n_files; client_manager->registerProducedFile(tid, dir); if (c_file.n_files == c_file.n_files_expected) { - c_file.set_complete(); + c_file.setComplete(); } } StorageManager::StorageManager() { @@ -207,7 +207,7 @@ void StorageManager::dup(const pid_t tid, const int old_fd, const int new_fd) { _opened_fd_map[tid][new_fd]._offset = _opened_fd_map[tid][old_fd]._offset; _opened_fd_map[tid][new_fd]._pointer->open(); - _opened_fd_map[tid][new_fd]._pointer->add_fd(tid, new_fd); + _opened_fd_map[tid][new_fd]._pointer->addFd(tid, new_fd); } void StorageManager::clone(const pid_t parent_tid, const pid_t child_tid) { @@ -242,7 +242,7 @@ void StorageManager::remove(const std::filesystem::path &path) { { std::lock_guard lg(_mutex_opened_fd_map); - for (auto &[tid, fd] : c_file.get_fds()) { + for (auto &[tid, fd] : c_file.getFds()) { _removeFromTid(tid, fd); } } @@ -259,7 +259,7 @@ void StorageManager::_removeFromTid(const pid_t tid, const int fd) { return; } - _opened_fd_map[tid][fd]._pointer->remove_fd(tid, fd); + _opened_fd_map[tid][fd]._pointer->removeFd(tid, fd); _opened_fd_map[tid].erase(fd); } @@ -282,7 +282,7 @@ void StorageManager::_addNewFdToStorage(const pid_t tid, const int fd, if (register_open) { _storage[path].open(); } - _storage[path].add_fd(tid, fd); + _storage[path].addFd(tid, fd); } void StorageManager::addFileToTid(const pid_t tid, const int fd, const std::filesystem::path &path, diff --git a/capio/tests/unit/server/src/capio_file.cpp b/capio/tests/unit/server/src/capio_file.cpp index e57a71820..c1e6d4c62 100644 --- a/capio/tests/unit/server/src/capio_file.cpp +++ b/capio/tests/unit/server/src/capio_file.cpp @@ -1,22 +1,22 @@ #ifndef CAPIO_CAPIO_FILE_HPP #define CAPIO_CAPIO_FILE_HPP -#include "utils/capio_file.hpp" +#include "server/include/storage/capio_file.hpp" #include "common/env.hpp" #include TEST(ServerTest, TestInsertSingleSector) { CapioFile c_file; - c_file.insert_sector(1, 3); - auto §ors = c_file.get_sectors(); + c_file.insertSector(1, 3); + auto §ors = c_file.getSectors(); EXPECT_EQ(sectors.size(), 1); EXPECT_NE(sectors.find({1L, 3L}), sectors.end()); } TEST(ServerTest, TestInsertTwoNonOverlappingSectors) { CapioFile c_file; - c_file.insert_sector(5, 7); - c_file.insert_sector(1, 3); - auto §ors = c_file.get_sectors(); + c_file.insertSector(5, 7); + c_file.insertSector(1, 3); + auto §ors = c_file.getSectors(); EXPECT_EQ(sectors.size(), 2); auto it = sectors.begin(); EXPECT_EQ(std::make_pair(1L, 3L), *it); @@ -26,36 +26,36 @@ TEST(ServerTest, TestInsertTwoNonOverlappingSectors) { TEST(ServerTest, TestInsertTwoOverlappingSectors) { CapioFile c_file; - c_file.insert_sector(2, 4); - c_file.insert_sector(1, 3); - auto §ors = c_file.get_sectors(); + c_file.insertSector(2, 4); + c_file.insertSector(1, 3); + auto §ors = c_file.getSectors(); EXPECT_EQ(sectors.size(), 1); EXPECT_NE(sectors.find({1L, 4L}), sectors.end()); } TEST(ServerTest, TestInsertTwoOverlappingSectorsSameStart) { CapioFile c_file; - c_file.insert_sector(1, 4); - c_file.insert_sector(1, 3); - auto §ors = c_file.get_sectors(); + c_file.insertSector(1, 4); + c_file.insertSector(1, 3); + auto §ors = c_file.getSectors(); EXPECT_EQ(sectors.size(), 1); EXPECT_NE(sectors.find({1L, 4L}), sectors.end()); } TEST(ServerTest, TestInsertTwoOverlappingSectorsSameEnd) { CapioFile c_file; - c_file.insert_sector(1, 4); - c_file.insert_sector(2, 4); - auto §ors = c_file.get_sectors(); + c_file.insertSector(1, 4); + c_file.insertSector(2, 4); + auto §ors = c_file.getSectors(); EXPECT_EQ(sectors.size(), 1); EXPECT_NE(sectors.find({1L, 4L}), sectors.end()); } TEST(ServerTest, TestInsertTwoOverlappingSectorsNested) { CapioFile c_file; - c_file.insert_sector(1, 4); - c_file.insert_sector(2, 3); - auto §ors = c_file.get_sectors(); + c_file.insertSector(1, 4); + c_file.insertSector(2, 3); + auto §ors = c_file.getSectors(); EXPECT_EQ(sectors.size(), 1); EXPECT_NE(sectors.find({1L, 4L}), sectors.end()); } diff --git a/capio/tests/unit/server/src/storage_manager.cpp b/capio/tests/unit/server/src/storage_manager.cpp index 30d400d7e..6f550a215 100644 --- a/capio/tests/unit/server/src/storage_manager.cpp +++ b/capio/tests/unit/server/src/storage_manager.cpp @@ -48,7 +48,7 @@ TEST(StorageManagerTestEnvironment, testInitDirectory) { const auto &dir = storage_manager->get("myDirectory"); - EXPECT_EQ(dir.get_buf_size(), CAPIO_DEFAULT_DIR_INITIAL_SIZE); + EXPECT_EQ(dir.getBufferSize(), CAPIO_DEFAULT_DIR_INITIAL_SIZE); storage_manager->updateDirectory(1, "myDirectory"); const auto &dir1 = storage_manager->get("myDirectory"); @@ -90,13 +90,13 @@ TEST(StorageManagerTestEnvironment, testNumberOfOpensAndCloses) { storage_manager->addFileToTid(1234, 3, "myFile", 0); storage_manager->addFileToTid(1234, 4, "myFile", 0); - EXPECT_FALSE(storage_manager->get("myFile").is_deletable()); + EXPECT_FALSE(storage_manager->get("myFile").deletable()); storage_manager->get("myFile").close(); - EXPECT_FALSE(storage_manager->get("myFile").is_deletable()); + EXPECT_FALSE(storage_manager->get("myFile").deletable()); storage_manager->get("myFile").close(); - EXPECT_TRUE(storage_manager->get("myFile").is_deletable()); + EXPECT_TRUE(storage_manager->get("myFile").deletable()); } TEST(StorageManagerTestEnvironment, testNumberOfOpensAfterClone) { @@ -105,15 +105,15 @@ TEST(StorageManagerTestEnvironment, testNumberOfOpensAfterClone) { storage_manager->addFileToTid(1234, 3, "myFile", 0); storage_manager->clone(1234, 5678); - EXPECT_FALSE(storage_manager->get("myFile").is_deletable()); + EXPECT_FALSE(storage_manager->get("myFile").deletable()); storage_manager->removeFromTid(1234, 3); - EXPECT_FALSE(storage_manager->get("myFile").is_deletable()); + EXPECT_FALSE(storage_manager->get("myFile").deletable()); storage_manager->removeFromTid(5678, 3); storage_manager->get("myFile").close(); - EXPECT_TRUE(storage_manager->get("myFile").is_deletable()); + EXPECT_TRUE(storage_manager->get("myFile").deletable()); } #endif // CAPIO_STORAGE_MANAGER_TEST_HPP