Loading include/global/chunk_calc_util.hpp +5 −5 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ #include <unistd.h> #include <cassert> namespace gkfs::utils { namespace gkfs::utils::arithmetic { /** * Check whether integer `n` is a power of 2. Loading Loading @@ -53,7 +53,7 @@ log2(uint64_t n) { */ constexpr bool is_divisible(const uint64_t n, const size_t block_size) { using gkfs::utils::log2; using gkfs::utils::arithmetic::log2; assert(is_power_of_2(block_size)); return !(n & ((1u << log2(block_size)) - 1)); } Loading Loading @@ -151,7 +151,7 @@ chnk_rpad(const uint64_t offset, const size_t block_size) { constexpr uint64_t chnk_id_for_offset(const uint64_t offset, const size_t block_size) { using gkfs::utils::log2; using gkfs::utils::arithmetic::log2; // This check is automatically removed in release builds assert(is_power_of_2(block_size)); Loading @@ -178,7 +178,7 @@ constexpr std::size_t chnk_count_for_offset(const uint64_t offset, const size_t count, const size_t chnk_size) { using gkfs::utils::log2; using gkfs::utils::arithmetic::log2; // These checks are automatically removed in release builds assert(is_power_of_2(chnk_size)); Loading @@ -198,6 +198,6 @@ chnk_count_for_offset(const uint64_t offset, const size_t count, mask; } } // namespace gkfs::utils } // namespace gkfs::utils::arithmetic #endif src/client/rpc/forward_data.cpp +28 −23 Original line number Diff line number Diff line Loading @@ -48,6 +48,9 @@ forward_write(const string& path, const void* buf, const bool append_flag, const off64_t in_offset, const size_t write_size, const int64_t updated_metadentry_size) { // import pow2-optimized arithmetic functions using namespace gkfs::utils::arithmetic; assert(write_size > 0); // Calculate chunkid boundaries and numbers so that daemons know in Loading @@ -55,10 +58,9 @@ forward_write(const string& path, const void* buf, const bool append_flag, off64_t offset = append_flag ? in_offset : (updated_metadentry_size - write_size); auto chnk_start = gkfs::utils::chnk_id_for_offset( offset, gkfs::config::rpc::chunksize); auto chnk_end = gkfs::utils::chnk_id_for_offset( (offset + write_size) - 1, gkfs::config::rpc::chunksize); auto chnk_start = chnk_id_for_offset(offset, gkfs::config::rpc::chunksize); auto chnk_end = chnk_id_for_offset((offset + write_size) - 1, gkfs::config::rpc::chunksize); // Collect all chunk ids within count that have the same destination so // that those are send in one rpc bulk transfer Loading Loading @@ -125,14 +127,13 @@ forward_write(const string& path, const void* buf, const bool append_flag, // receiver of first chunk must subtract the offset from first chunk if(target == chnk_start_target) { total_chunk_size -= gkfs::utils::chnk_lpad(offset, gkfs::config::rpc::chunksize); total_chunk_size -= chnk_lpad(offset, gkfs::config::rpc::chunksize); } // receiver of last chunk must subtract if(target == chnk_end_target) { total_chunk_size -= gkfs::utils::chnk_rpad( offset + write_size, gkfs::config::rpc::chunksize); total_chunk_size -= chnk_rpad(offset + write_size, gkfs::config::rpc::chunksize); } auto endp = CTX->hosts().at(target); Loading @@ -145,8 +146,8 @@ forward_write(const string& path, const void* buf, const bool append_flag, path, // first offset in targets is the chunk with // a potential offset gkfs::utils::chnk_lpad(offset, gkfs::config::rpc::chunksize), target, CTX->hosts().size(), chnk_lpad(offset, gkfs::config::rpc::chunksize), target, CTX->hosts().size(), // number of chunks handled by that destination target_chnks[target].size(), // chunk start id of this write Loading Loading @@ -228,12 +229,14 @@ pair<int, ssize_t> forward_read(const string& path, void* buf, const off64_t offset, const size_t read_size) { // import pow2-optimized arithmetic functions using namespace gkfs::utils::arithmetic; // Calculate chunkid boundaries and numbers so that daemons know in which // interval to look for chunks auto chnk_start = gkfs::utils::chnk_id_for_offset( offset, gkfs::config::rpc::chunksize); auto chnk_end = gkfs::utils::chnk_id_for_offset( (offset + read_size - 1), gkfs::config::rpc::chunksize); auto chnk_start = chnk_id_for_offset(offset, gkfs::config::rpc::chunksize); auto chnk_end = chnk_id_for_offset((offset + read_size - 1), gkfs::config::rpc::chunksize); // Collect all chunk ids within count that have the same destination so // that those are send in one rpc bulk transfer Loading Loading @@ -300,14 +303,13 @@ forward_read(const string& path, void* buf, const off64_t offset, // receiver of first chunk must subtract the offset from first chunk if(target == chnk_start_target) { total_chunk_size -= gkfs::utils::chnk_lpad(offset, gkfs::config::rpc::chunksize); total_chunk_size -= chnk_lpad(offset, gkfs::config::rpc::chunksize); } // receiver of last chunk must subtract if(target == chnk_end_target) { total_chunk_size -= gkfs::utils::chnk_rpad( offset + read_size, gkfs::config::rpc::chunksize); total_chunk_size -= chnk_rpad(offset + read_size, gkfs::config::rpc::chunksize); } auto endp = CTX->hosts().at(target); Loading @@ -320,8 +322,8 @@ forward_read(const string& path, void* buf, const off64_t offset, path, // first offset in targets is the chunk with // a potential offset gkfs::utils::chnk_lpad(offset, gkfs::config::rpc::chunksize), target, CTX->hosts().size(), chnk_lpad(offset, gkfs::config::rpc::chunksize), target, CTX->hosts().size(), // number of chunks handled by that destination target_chnks[target].size(), // chunk start id of this write Loading Loading @@ -400,13 +402,16 @@ int forward_truncate(const std::string& path, size_t current_size, size_t new_size) { // import pow2-optimized arithmetic functions using namespace gkfs::utils::arithmetic; assert(current_size > new_size); // Find out which data servers need to delete data chunks in order to // contact only them const unsigned int chunk_start = gkfs::utils::chnk_id_for_offset( new_size, gkfs::config::rpc::chunksize); const unsigned int chunk_end = gkfs::utils::chnk_id_for_offset( const unsigned int chunk_start = chnk_id_for_offset(new_size, gkfs::config::rpc::chunksize); const unsigned int chunk_end = chnk_id_for_offset( current_size - new_size - 1, gkfs::config::rpc::chunksize); std::unordered_set<unsigned int> hosts; Loading src/daemon/ops/data.cpp +7 −4 Original line number Diff line number Diff line Loading @@ -41,6 +41,10 @@ namespace data { */ void ChunkTruncateOperation::truncate_abt(void* _arg) { // import pow2-optimized arithmetic functions using namespace gkfs::utils::arithmetic; assert(_arg); // Unpack args auto* arg = static_cast<struct chunk_truncate_args*>(_arg); Loading @@ -49,11 +53,10 @@ ChunkTruncateOperation::truncate_abt(void* _arg) { int err_response = 0; try { // get chunk from where to cut off auto chunk_id_start = gkfs::utils::chnk_id_for_offset( size, gkfs::config::rpc::chunksize); auto chunk_id_start = chnk_id_for_offset(size, gkfs::config::rpc::chunksize); // do not last delete chunk if it is in the middle of a chunk auto left_pad = gkfs::utils::chnk_lpad(size, gkfs::config::rpc::chunksize); auto left_pad = chnk_lpad(size, gkfs::config::rpc::chunksize); if(left_pad != 0) { GKFS_DATA->storage()->truncate_chunk_file(path, chunk_id_start, left_pad); Loading tests/unit/test_util_numeric.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ #include <global/chunk_calc_util.hpp> #include <fmt/format.h> using namespace gkfs::utils; using namespace gkfs::utils::arithmetic; constexpr auto test_reps = 200u; namespace { Loading Loading
include/global/chunk_calc_util.hpp +5 −5 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ #include <unistd.h> #include <cassert> namespace gkfs::utils { namespace gkfs::utils::arithmetic { /** * Check whether integer `n` is a power of 2. Loading Loading @@ -53,7 +53,7 @@ log2(uint64_t n) { */ constexpr bool is_divisible(const uint64_t n, const size_t block_size) { using gkfs::utils::log2; using gkfs::utils::arithmetic::log2; assert(is_power_of_2(block_size)); return !(n & ((1u << log2(block_size)) - 1)); } Loading Loading @@ -151,7 +151,7 @@ chnk_rpad(const uint64_t offset, const size_t block_size) { constexpr uint64_t chnk_id_for_offset(const uint64_t offset, const size_t block_size) { using gkfs::utils::log2; using gkfs::utils::arithmetic::log2; // This check is automatically removed in release builds assert(is_power_of_2(block_size)); Loading @@ -178,7 +178,7 @@ constexpr std::size_t chnk_count_for_offset(const uint64_t offset, const size_t count, const size_t chnk_size) { using gkfs::utils::log2; using gkfs::utils::arithmetic::log2; // These checks are automatically removed in release builds assert(is_power_of_2(chnk_size)); Loading @@ -198,6 +198,6 @@ chnk_count_for_offset(const uint64_t offset, const size_t count, mask; } } // namespace gkfs::utils } // namespace gkfs::utils::arithmetic #endif
src/client/rpc/forward_data.cpp +28 −23 Original line number Diff line number Diff line Loading @@ -48,6 +48,9 @@ forward_write(const string& path, const void* buf, const bool append_flag, const off64_t in_offset, const size_t write_size, const int64_t updated_metadentry_size) { // import pow2-optimized arithmetic functions using namespace gkfs::utils::arithmetic; assert(write_size > 0); // Calculate chunkid boundaries and numbers so that daemons know in Loading @@ -55,10 +58,9 @@ forward_write(const string& path, const void* buf, const bool append_flag, off64_t offset = append_flag ? in_offset : (updated_metadentry_size - write_size); auto chnk_start = gkfs::utils::chnk_id_for_offset( offset, gkfs::config::rpc::chunksize); auto chnk_end = gkfs::utils::chnk_id_for_offset( (offset + write_size) - 1, gkfs::config::rpc::chunksize); auto chnk_start = chnk_id_for_offset(offset, gkfs::config::rpc::chunksize); auto chnk_end = chnk_id_for_offset((offset + write_size) - 1, gkfs::config::rpc::chunksize); // Collect all chunk ids within count that have the same destination so // that those are send in one rpc bulk transfer Loading Loading @@ -125,14 +127,13 @@ forward_write(const string& path, const void* buf, const bool append_flag, // receiver of first chunk must subtract the offset from first chunk if(target == chnk_start_target) { total_chunk_size -= gkfs::utils::chnk_lpad(offset, gkfs::config::rpc::chunksize); total_chunk_size -= chnk_lpad(offset, gkfs::config::rpc::chunksize); } // receiver of last chunk must subtract if(target == chnk_end_target) { total_chunk_size -= gkfs::utils::chnk_rpad( offset + write_size, gkfs::config::rpc::chunksize); total_chunk_size -= chnk_rpad(offset + write_size, gkfs::config::rpc::chunksize); } auto endp = CTX->hosts().at(target); Loading @@ -145,8 +146,8 @@ forward_write(const string& path, const void* buf, const bool append_flag, path, // first offset in targets is the chunk with // a potential offset gkfs::utils::chnk_lpad(offset, gkfs::config::rpc::chunksize), target, CTX->hosts().size(), chnk_lpad(offset, gkfs::config::rpc::chunksize), target, CTX->hosts().size(), // number of chunks handled by that destination target_chnks[target].size(), // chunk start id of this write Loading Loading @@ -228,12 +229,14 @@ pair<int, ssize_t> forward_read(const string& path, void* buf, const off64_t offset, const size_t read_size) { // import pow2-optimized arithmetic functions using namespace gkfs::utils::arithmetic; // Calculate chunkid boundaries and numbers so that daemons know in which // interval to look for chunks auto chnk_start = gkfs::utils::chnk_id_for_offset( offset, gkfs::config::rpc::chunksize); auto chnk_end = gkfs::utils::chnk_id_for_offset( (offset + read_size - 1), gkfs::config::rpc::chunksize); auto chnk_start = chnk_id_for_offset(offset, gkfs::config::rpc::chunksize); auto chnk_end = chnk_id_for_offset((offset + read_size - 1), gkfs::config::rpc::chunksize); // Collect all chunk ids within count that have the same destination so // that those are send in one rpc bulk transfer Loading Loading @@ -300,14 +303,13 @@ forward_read(const string& path, void* buf, const off64_t offset, // receiver of first chunk must subtract the offset from first chunk if(target == chnk_start_target) { total_chunk_size -= gkfs::utils::chnk_lpad(offset, gkfs::config::rpc::chunksize); total_chunk_size -= chnk_lpad(offset, gkfs::config::rpc::chunksize); } // receiver of last chunk must subtract if(target == chnk_end_target) { total_chunk_size -= gkfs::utils::chnk_rpad( offset + read_size, gkfs::config::rpc::chunksize); total_chunk_size -= chnk_rpad(offset + read_size, gkfs::config::rpc::chunksize); } auto endp = CTX->hosts().at(target); Loading @@ -320,8 +322,8 @@ forward_read(const string& path, void* buf, const off64_t offset, path, // first offset in targets is the chunk with // a potential offset gkfs::utils::chnk_lpad(offset, gkfs::config::rpc::chunksize), target, CTX->hosts().size(), chnk_lpad(offset, gkfs::config::rpc::chunksize), target, CTX->hosts().size(), // number of chunks handled by that destination target_chnks[target].size(), // chunk start id of this write Loading Loading @@ -400,13 +402,16 @@ int forward_truncate(const std::string& path, size_t current_size, size_t new_size) { // import pow2-optimized arithmetic functions using namespace gkfs::utils::arithmetic; assert(current_size > new_size); // Find out which data servers need to delete data chunks in order to // contact only them const unsigned int chunk_start = gkfs::utils::chnk_id_for_offset( new_size, gkfs::config::rpc::chunksize); const unsigned int chunk_end = gkfs::utils::chnk_id_for_offset( const unsigned int chunk_start = chnk_id_for_offset(new_size, gkfs::config::rpc::chunksize); const unsigned int chunk_end = chnk_id_for_offset( current_size - new_size - 1, gkfs::config::rpc::chunksize); std::unordered_set<unsigned int> hosts; Loading
src/daemon/ops/data.cpp +7 −4 Original line number Diff line number Diff line Loading @@ -41,6 +41,10 @@ namespace data { */ void ChunkTruncateOperation::truncate_abt(void* _arg) { // import pow2-optimized arithmetic functions using namespace gkfs::utils::arithmetic; assert(_arg); // Unpack args auto* arg = static_cast<struct chunk_truncate_args*>(_arg); Loading @@ -49,11 +53,10 @@ ChunkTruncateOperation::truncate_abt(void* _arg) { int err_response = 0; try { // get chunk from where to cut off auto chunk_id_start = gkfs::utils::chnk_id_for_offset( size, gkfs::config::rpc::chunksize); auto chunk_id_start = chnk_id_for_offset(size, gkfs::config::rpc::chunksize); // do not last delete chunk if it is in the middle of a chunk auto left_pad = gkfs::utils::chnk_lpad(size, gkfs::config::rpc::chunksize); auto left_pad = chnk_lpad(size, gkfs::config::rpc::chunksize); if(left_pad != 0) { GKFS_DATA->storage()->truncate_chunk_file(path, chunk_id_start, left_pad); Loading
tests/unit/test_util_numeric.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ #include <global/chunk_calc_util.hpp> #include <fmt/format.h> using namespace gkfs::utils; using namespace gkfs::utils::arithmetic; constexpr auto test_reps = 200u; namespace { Loading