Loading include/client/cache.hpp +8 −0 Original line number Original line Diff line number Diff line Loading @@ -167,6 +167,14 @@ public: std::pair<size_t, size_t> std::pair<size_t, size_t> record(std::string path, size_t size); record(std::string path, size_t size); /** * @brief Get the cached size for a given path * @param path * @return [size_update counter, current cached size] */ std::pair<size_t, size_t> get(const std::string& path); /** /** * @brief reset entry from the cache * @brief reset entry from the cache * @param path * @param path Loading src/client/cache.cpp +10 −0 Original line number Original line Diff line number Diff line Loading @@ -150,6 +150,16 @@ WriteSizeCache::record(std::string path, size_t size) { return pair; return pair; } } std::pair<size_t, size_t> WriteSizeCache::get(const std::string& path) { std::lock_guard<std::mutex> const lock(mtx_); auto it = size_cache.find(path); if(it == size_cache.end()) { return {}; } return it->second; } std::pair<size_t, size_t> std::pair<size_t, size_t> WriteSizeCache::reset(const std::string& path, bool evict) { WriteSizeCache::reset(const std::string& path, bool evict) { std::lock_guard<std::mutex> const lock(mtx_); std::lock_guard<std::mutex> const lock(mtx_); Loading src/client/gkfs_functions.cpp +52 −7 Original line number Original line Diff line number Diff line Loading @@ -322,6 +322,8 @@ gkfs_open(const std::string& path, mode_t mode, int flags) { LOG(ERROR, "Error truncating file"); LOG(ERROR, "Error truncating file"); return -1; return -1; } } md.size(0); md.inline_data(""); } } // RENAMED OR SYMLINK NOT PROTECTED // RENAMED OR SYMLINK NOT PROTECTED return CTX->file_map()->add( return CTX->file_map()->add( Loading @@ -342,6 +344,8 @@ gkfs_open(const std::string& path, mode_t mode, int flags) { LOG(ERROR, "Error truncating file"); LOG(ERROR, "Error truncating file"); return -1; return -1; } } md.size(0); md.inline_data(""); } } auto file = std::make_shared<gkfs::filemap::OpenFile>(path, flags); auto file = std::make_shared<gkfs::filemap::OpenFile>(path, flags); if(gkfs::config::metadata::read_inline_prefetch and if(gkfs::config::metadata::read_inline_prefetch and Loading Loading @@ -654,6 +658,13 @@ int gkfs_stat(const string& path, struct stat* buf, bool follow_links, gkfs_stat(const string& path, struct stat* buf, bool follow_links, bool bypass_rename) { bool bypass_rename) { if(CTX->use_write_size_cache()) { auto err = CTX->write_size_cache()->flush(path, true).first; if(err) { LOG(ERROR, "{}() write_size_cache() failed with err '{}'", __func__, err); } } auto md = gkfs::utils::get_metadata(path, follow_links); auto md = gkfs::utils::get_metadata(path, follow_links); if(!md) { if(!md) { return -1; return -1; Loading Loading @@ -706,6 +717,13 @@ gkfs_stat(const string& path, struct stat* buf, bool follow_links, int int gkfs_statx(int dirfs, const std::string& path, int flags, unsigned int mask, gkfs_statx(int dirfs, const std::string& path, int flags, unsigned int mask, struct statx* buf, bool follow_links) { struct statx* buf, bool follow_links) { if(CTX->use_write_size_cache()) { auto err = CTX->write_size_cache()->flush(path, true).first; if(err) { LOG(ERROR, "{}() write_size_cache() failed with err '{}'", __func__, err); } } auto md = gkfs::utils::get_metadata(path, follow_links); auto md = gkfs::utils::get_metadata(path, follow_links); if(!md) { if(!md) { return -1; return -1; Loading Loading @@ -868,9 +886,18 @@ gkfs_lseek(shared_ptr<gkfs::filemap::OpenFile> gkfs_fd, off_t offset, gkfs_fd->pos(offset); gkfs_fd->pos(offset); break; break; case SEEK_CUR: case SEEK_CUR: if(offset < 0 && gkfs_fd->pos() < static_cast<unsigned long>(-offset)) { errno = EINVAL; return -1; } gkfs_fd->pos(gkfs_fd->pos() + offset); gkfs_fd->pos(gkfs_fd->pos() + offset); break; break; case SEEK_END: { case SEEK_END: { if(CTX->use_write_size_cache()) { CTX->write_size_cache()->flush(gkfs_fd->path()); } std::pair<int, off64_t> ret{}; std::pair<int, off64_t> ret{}; if(gkfs::config::proxy::fwd_get_size && CTX->use_proxy()) { if(gkfs::config::proxy::fwd_get_size && CTX->use_proxy()) { ret = gkfs::rpc::forward_get_metadentry_size_proxy( ret = gkfs::rpc::forward_get_metadentry_size_proxy( Loading Loading @@ -1136,7 +1163,24 @@ gkfs_do_write(gkfs::filemap::OpenFile& file, const char* buf, size_t count, (is_append || (is_append || (offset + count) <= gkfs::config::metadata::inline_data_size)) { (offset + count) <= gkfs::config::metadata::inline_data_size)) { bool allow_inline = true; // Check if the file is actually larger than the inline header limits us // to. This can happen if we have a write size cache enabled and the // file is large but the metadata is not updated yet on the server. If // we write inline, we might overwrite the inline data, but the file is // actually large and we should write to chunks. if(CTX->use_write_size_cache()) { auto [cnt, size] = CTX->write_size_cache()->get(file.path()); if(size > gkfs::config::metadata::inline_data_size) { allow_inline = false; LOG(DEBUG, "{}() Disable inline write. File size '{}' > inline limit '{}'", __func__, size, gkfs::config::metadata::inline_data_size); } } // Attempt inline write via Metadata RPC // Attempt inline write via Metadata RPC if(allow_inline) { auto ret_inline = gkfs::rpc::forward_write_inline( auto ret_inline = gkfs::rpc::forward_write_inline( file.path(), buf, offset, count, is_append); file.path(), buf, offset, count, is_append); auto err = ret_inline.first; auto err = ret_inline.first; Loading @@ -1146,6 +1190,7 @@ gkfs_do_write(gkfs::filemap::OpenFile& file, const char* buf, size_t count, return count; return count; } } } } } // If we are here, we are writing to chunks. // If we are here, we are writing to chunks. // Check if we need to migrate existing inline data to chunks. // Check if we need to migrate existing inline data to chunks. Loading src/daemon/backend/metadata/rocksdb_backend.cpp +27 −14 Original line number Original line Diff line number Diff line Loading @@ -314,6 +314,18 @@ RocksDBBackend::decrease_size_impl(const std::string& key, size_t size) { throw_status_excpt(s); throw_status_excpt(s); } } } } if(gkfs::config::metadata::use_inline_data) { try { std::string inline_key = key + "#inline"; std::string val = get_impl(inline_key); if(val.size() > size) { val.resize(size); put_raw_impl(inline_key, val); } } catch(const NotFoundException& e) { // Ignore } } } } /** /** Loading Loading @@ -350,6 +362,11 @@ RocksDBBackend::get_dirents_impl(const std::string& dir) const { // relative path of directory entries must not be empty // relative path of directory entries must not be empty assert(!name.empty()); assert(!name.empty()); // Filter out inline data keys if(name.size() >= 7 && name.substr(name.size() - 7) == "#inline") { continue; } Metadata md(it->value().ToString()); Metadata md(it->value().ToString()); #ifdef HAS_RENAME #ifdef HAS_RENAME // Remove entries with negative blocks (rename) // Remove entries with negative blocks (rename) Loading @@ -358,11 +375,6 @@ RocksDBBackend::get_dirents_impl(const std::string& dir) const { } } #endif // HAS_RENAME #endif // HAS_RENAME // Filter out inline data keys if(name.size() >= 7 && name.substr(name.size() - 7) == "#inline") { continue; } auto is_dir = S_ISDIR(md.mode()); auto is_dir = S_ISDIR(md.mode()); entries.emplace_back(std::move(name), is_dir); entries.emplace_back(std::move(name), is_dir); Loading Loading @@ -406,6 +418,11 @@ RocksDBBackend::get_dirents_extended_impl(const std::string& dir) const { // relative path of directory entries must not be empty // relative path of directory entries must not be empty assert(!name.empty()); assert(!name.empty()); // Filter out inline data keys if(name.size() >= 7 && name.substr(name.size() - 7) == "#inline") { continue; } Metadata md(it->value().ToString()); Metadata md(it->value().ToString()); #ifdef HAS_RENAME #ifdef HAS_RENAME // Remove entries with negative blocks (rename) // Remove entries with negative blocks (rename) Loading @@ -413,10 +430,6 @@ RocksDBBackend::get_dirents_extended_impl(const std::string& dir) const { continue; continue; } } #endif // HAS_RENAME #endif // HAS_RENAME // Filter out inline data keys if(name.size() >= 7 && name.substr(name.size() - 7) == "#inline") { continue; } auto is_dir = S_ISDIR(md.mode()); auto is_dir = S_ISDIR(md.mode()); Loading Loading @@ -456,6 +469,11 @@ RocksDBBackend::get_all_dirents_extended_impl(const std::string& dir) const { // relative path of directory entries must not be empty // relative path of directory entries must not be empty assert(!name.empty()); assert(!name.empty()); // Filter out inline data keys if(name.size() >= 7 && name.substr(name.size() - 7) == "#inline") { continue; } Metadata md(it->value().ToString()); Metadata md(it->value().ToString()); #ifdef HAS_RENAME #ifdef HAS_RENAME // Remove entries with negative blocks (rename) // Remove entries with negative blocks (rename) Loading @@ -464,11 +482,6 @@ RocksDBBackend::get_all_dirents_extended_impl(const std::string& dir) const { } } #endif // HAS_RENAME #endif // HAS_RENAME // Filter out inline data keys if(name.size() >= 7 && name.substr(name.size() - 7) == "#inline") { continue; } auto is_dir = S_ISDIR(md.mode()); auto is_dir = S_ISDIR(md.mode()); entries.emplace_back(std::forward_as_tuple(std::move(name), is_dir, entries.emplace_back(std::forward_as_tuple(std::move(name), is_dir, Loading src/daemon/handler/srv_metadata.cpp +1 −6 Original line number Original line Diff line number Diff line Loading @@ -737,13 +737,8 @@ rpc_srv_get_dirents(hg_handle_t handle) { } } // Respond // Respond <<<<<<< HEAD if(gkfs::config::rpc::use_dirents_compression) { ||||||| parent of 59cea6f7 (fix directory) out.dirents_size = transfer_size; ======= if (gkfs::config::rpc::use_dirents_compression) { if (gkfs::config::rpc::use_dirents_compression) { >>>>>>> 59cea6f7 (fix directory) out.dirents_size = transfer_size; out.dirents_size = transfer_size; } else { } else { out.dirents_size = entries.size(); out.dirents_size = entries.size(); Loading Loading
include/client/cache.hpp +8 −0 Original line number Original line Diff line number Diff line Loading @@ -167,6 +167,14 @@ public: std::pair<size_t, size_t> std::pair<size_t, size_t> record(std::string path, size_t size); record(std::string path, size_t size); /** * @brief Get the cached size for a given path * @param path * @return [size_update counter, current cached size] */ std::pair<size_t, size_t> get(const std::string& path); /** /** * @brief reset entry from the cache * @brief reset entry from the cache * @param path * @param path Loading
src/client/cache.cpp +10 −0 Original line number Original line Diff line number Diff line Loading @@ -150,6 +150,16 @@ WriteSizeCache::record(std::string path, size_t size) { return pair; return pair; } } std::pair<size_t, size_t> WriteSizeCache::get(const std::string& path) { std::lock_guard<std::mutex> const lock(mtx_); auto it = size_cache.find(path); if(it == size_cache.end()) { return {}; } return it->second; } std::pair<size_t, size_t> std::pair<size_t, size_t> WriteSizeCache::reset(const std::string& path, bool evict) { WriteSizeCache::reset(const std::string& path, bool evict) { std::lock_guard<std::mutex> const lock(mtx_); std::lock_guard<std::mutex> const lock(mtx_); Loading
src/client/gkfs_functions.cpp +52 −7 Original line number Original line Diff line number Diff line Loading @@ -322,6 +322,8 @@ gkfs_open(const std::string& path, mode_t mode, int flags) { LOG(ERROR, "Error truncating file"); LOG(ERROR, "Error truncating file"); return -1; return -1; } } md.size(0); md.inline_data(""); } } // RENAMED OR SYMLINK NOT PROTECTED // RENAMED OR SYMLINK NOT PROTECTED return CTX->file_map()->add( return CTX->file_map()->add( Loading @@ -342,6 +344,8 @@ gkfs_open(const std::string& path, mode_t mode, int flags) { LOG(ERROR, "Error truncating file"); LOG(ERROR, "Error truncating file"); return -1; return -1; } } md.size(0); md.inline_data(""); } } auto file = std::make_shared<gkfs::filemap::OpenFile>(path, flags); auto file = std::make_shared<gkfs::filemap::OpenFile>(path, flags); if(gkfs::config::metadata::read_inline_prefetch and if(gkfs::config::metadata::read_inline_prefetch and Loading Loading @@ -654,6 +658,13 @@ int gkfs_stat(const string& path, struct stat* buf, bool follow_links, gkfs_stat(const string& path, struct stat* buf, bool follow_links, bool bypass_rename) { bool bypass_rename) { if(CTX->use_write_size_cache()) { auto err = CTX->write_size_cache()->flush(path, true).first; if(err) { LOG(ERROR, "{}() write_size_cache() failed with err '{}'", __func__, err); } } auto md = gkfs::utils::get_metadata(path, follow_links); auto md = gkfs::utils::get_metadata(path, follow_links); if(!md) { if(!md) { return -1; return -1; Loading Loading @@ -706,6 +717,13 @@ gkfs_stat(const string& path, struct stat* buf, bool follow_links, int int gkfs_statx(int dirfs, const std::string& path, int flags, unsigned int mask, gkfs_statx(int dirfs, const std::string& path, int flags, unsigned int mask, struct statx* buf, bool follow_links) { struct statx* buf, bool follow_links) { if(CTX->use_write_size_cache()) { auto err = CTX->write_size_cache()->flush(path, true).first; if(err) { LOG(ERROR, "{}() write_size_cache() failed with err '{}'", __func__, err); } } auto md = gkfs::utils::get_metadata(path, follow_links); auto md = gkfs::utils::get_metadata(path, follow_links); if(!md) { if(!md) { return -1; return -1; Loading Loading @@ -868,9 +886,18 @@ gkfs_lseek(shared_ptr<gkfs::filemap::OpenFile> gkfs_fd, off_t offset, gkfs_fd->pos(offset); gkfs_fd->pos(offset); break; break; case SEEK_CUR: case SEEK_CUR: if(offset < 0 && gkfs_fd->pos() < static_cast<unsigned long>(-offset)) { errno = EINVAL; return -1; } gkfs_fd->pos(gkfs_fd->pos() + offset); gkfs_fd->pos(gkfs_fd->pos() + offset); break; break; case SEEK_END: { case SEEK_END: { if(CTX->use_write_size_cache()) { CTX->write_size_cache()->flush(gkfs_fd->path()); } std::pair<int, off64_t> ret{}; std::pair<int, off64_t> ret{}; if(gkfs::config::proxy::fwd_get_size && CTX->use_proxy()) { if(gkfs::config::proxy::fwd_get_size && CTX->use_proxy()) { ret = gkfs::rpc::forward_get_metadentry_size_proxy( ret = gkfs::rpc::forward_get_metadentry_size_proxy( Loading Loading @@ -1136,7 +1163,24 @@ gkfs_do_write(gkfs::filemap::OpenFile& file, const char* buf, size_t count, (is_append || (is_append || (offset + count) <= gkfs::config::metadata::inline_data_size)) { (offset + count) <= gkfs::config::metadata::inline_data_size)) { bool allow_inline = true; // Check if the file is actually larger than the inline header limits us // to. This can happen if we have a write size cache enabled and the // file is large but the metadata is not updated yet on the server. If // we write inline, we might overwrite the inline data, but the file is // actually large and we should write to chunks. if(CTX->use_write_size_cache()) { auto [cnt, size] = CTX->write_size_cache()->get(file.path()); if(size > gkfs::config::metadata::inline_data_size) { allow_inline = false; LOG(DEBUG, "{}() Disable inline write. File size '{}' > inline limit '{}'", __func__, size, gkfs::config::metadata::inline_data_size); } } // Attempt inline write via Metadata RPC // Attempt inline write via Metadata RPC if(allow_inline) { auto ret_inline = gkfs::rpc::forward_write_inline( auto ret_inline = gkfs::rpc::forward_write_inline( file.path(), buf, offset, count, is_append); file.path(), buf, offset, count, is_append); auto err = ret_inline.first; auto err = ret_inline.first; Loading @@ -1146,6 +1190,7 @@ gkfs_do_write(gkfs::filemap::OpenFile& file, const char* buf, size_t count, return count; return count; } } } } } // If we are here, we are writing to chunks. // If we are here, we are writing to chunks. // Check if we need to migrate existing inline data to chunks. // Check if we need to migrate existing inline data to chunks. Loading
src/daemon/backend/metadata/rocksdb_backend.cpp +27 −14 Original line number Original line Diff line number Diff line Loading @@ -314,6 +314,18 @@ RocksDBBackend::decrease_size_impl(const std::string& key, size_t size) { throw_status_excpt(s); throw_status_excpt(s); } } } } if(gkfs::config::metadata::use_inline_data) { try { std::string inline_key = key + "#inline"; std::string val = get_impl(inline_key); if(val.size() > size) { val.resize(size); put_raw_impl(inline_key, val); } } catch(const NotFoundException& e) { // Ignore } } } } /** /** Loading Loading @@ -350,6 +362,11 @@ RocksDBBackend::get_dirents_impl(const std::string& dir) const { // relative path of directory entries must not be empty // relative path of directory entries must not be empty assert(!name.empty()); assert(!name.empty()); // Filter out inline data keys if(name.size() >= 7 && name.substr(name.size() - 7) == "#inline") { continue; } Metadata md(it->value().ToString()); Metadata md(it->value().ToString()); #ifdef HAS_RENAME #ifdef HAS_RENAME // Remove entries with negative blocks (rename) // Remove entries with negative blocks (rename) Loading @@ -358,11 +375,6 @@ RocksDBBackend::get_dirents_impl(const std::string& dir) const { } } #endif // HAS_RENAME #endif // HAS_RENAME // Filter out inline data keys if(name.size() >= 7 && name.substr(name.size() - 7) == "#inline") { continue; } auto is_dir = S_ISDIR(md.mode()); auto is_dir = S_ISDIR(md.mode()); entries.emplace_back(std::move(name), is_dir); entries.emplace_back(std::move(name), is_dir); Loading Loading @@ -406,6 +418,11 @@ RocksDBBackend::get_dirents_extended_impl(const std::string& dir) const { // relative path of directory entries must not be empty // relative path of directory entries must not be empty assert(!name.empty()); assert(!name.empty()); // Filter out inline data keys if(name.size() >= 7 && name.substr(name.size() - 7) == "#inline") { continue; } Metadata md(it->value().ToString()); Metadata md(it->value().ToString()); #ifdef HAS_RENAME #ifdef HAS_RENAME // Remove entries with negative blocks (rename) // Remove entries with negative blocks (rename) Loading @@ -413,10 +430,6 @@ RocksDBBackend::get_dirents_extended_impl(const std::string& dir) const { continue; continue; } } #endif // HAS_RENAME #endif // HAS_RENAME // Filter out inline data keys if(name.size() >= 7 && name.substr(name.size() - 7) == "#inline") { continue; } auto is_dir = S_ISDIR(md.mode()); auto is_dir = S_ISDIR(md.mode()); Loading Loading @@ -456,6 +469,11 @@ RocksDBBackend::get_all_dirents_extended_impl(const std::string& dir) const { // relative path of directory entries must not be empty // relative path of directory entries must not be empty assert(!name.empty()); assert(!name.empty()); // Filter out inline data keys if(name.size() >= 7 && name.substr(name.size() - 7) == "#inline") { continue; } Metadata md(it->value().ToString()); Metadata md(it->value().ToString()); #ifdef HAS_RENAME #ifdef HAS_RENAME // Remove entries with negative blocks (rename) // Remove entries with negative blocks (rename) Loading @@ -464,11 +482,6 @@ RocksDBBackend::get_all_dirents_extended_impl(const std::string& dir) const { } } #endif // HAS_RENAME #endif // HAS_RENAME // Filter out inline data keys if(name.size() >= 7 && name.substr(name.size() - 7) == "#inline") { continue; } auto is_dir = S_ISDIR(md.mode()); auto is_dir = S_ISDIR(md.mode()); entries.emplace_back(std::forward_as_tuple(std::move(name), is_dir, entries.emplace_back(std::forward_as_tuple(std::move(name), is_dir, Loading
src/daemon/handler/srv_metadata.cpp +1 −6 Original line number Original line Diff line number Diff line Loading @@ -737,13 +737,8 @@ rpc_srv_get_dirents(hg_handle_t handle) { } } // Respond // Respond <<<<<<< HEAD if(gkfs::config::rpc::use_dirents_compression) { ||||||| parent of 59cea6f7 (fix directory) out.dirents_size = transfer_size; ======= if (gkfs::config::rpc::use_dirents_compression) { if (gkfs::config::rpc::use_dirents_compression) { >>>>>>> 59cea6f7 (fix directory) out.dirents_size = transfer_size; out.dirents_size = transfer_size; } else { } else { out.dirents_size = entries.size(); out.dirents_size = entries.size(); Loading