From cb5751d6fbfb9fa23fa7b7d1b49f3efabb89c512 Mon Sep 17 00:00:00 2001 From: Brian Szmyd Date: Thu, 19 Oct 2023 11:16:23 -0700 Subject: [PATCH] Remove defer to CPUExecutor. --- conanfile.py | 2 +- src/lib/homeobject_impl.hpp | 1 - src/lib/homestore_backend/hs_blob_manager.cpp | 2 +- src/lib/homestore_backend/hs_homeobject.cpp | 2 -- src/lib/homestore_backend/hs_homeobject.hpp | 8 ++--- .../tests/test_hs_homeobject.cpp | 11 ++---- src/lib/shard_manager.cpp | 36 ++++++++----------- 7 files changed, 22 insertions(+), 40 deletions(-) diff --git a/conanfile.py b/conanfile.py index 0a262d16..a50a8d98 100644 --- a/conanfile.py +++ b/conanfile.py @@ -9,7 +9,7 @@ class HomeObjectConan(ConanFile): name = "homeobject" - version = "0.12.1" + version = "0.12.2" homepage = "https://github.com/eBay/HomeObject" description = "Blob Store built on HomeReplication" topics = ("ebay") diff --git a/src/lib/homeobject_impl.hpp b/src/lib/homeobject_impl.hpp index ad325e7f..69928770 100644 --- a/src/lib/homeobject_impl.hpp +++ b/src/lib/homeobject_impl.hpp @@ -82,7 +82,6 @@ class HomeObjectImpl : public HomeObject, virtual BlobManager::NullAsyncResult _del_blob(ShardInfo const&, blob_id_t) = 0; /// folly::Future< ShardManager::Result< ShardInfo > > _get_shard(shard_id_t id) const; - auto _defer() const { return folly::makeSemiFuture().via(folly::getGlobalCPUExecutor()); } virtual PGManager::NullAsyncResult _create_pg(PGInfo&& pg_info, std::set< std::string, std::less<> > peers) = 0; virtual PGManager::NullAsyncResult _replace_member(pg_id_t id, peer_id_t const& old_member, diff --git a/src/lib/homestore_backend/hs_blob_manager.cpp b/src/lib/homestore_backend/hs_blob_manager.cpp index 828d15df..4f3baa06 100644 --- a/src/lib/homestore_backend/hs_blob_manager.cpp +++ b/src/lib/homestore_backend/hs_blob_manager.cpp @@ -226,7 +226,7 @@ BlobManager::AsyncResult< Blob > HSHomeObject::_get_blob(ShardInfo const& shard, computed_hash, BlobHeader::blob_max_hash_len); if (std::memcmp(computed_hash, header->hash, BlobHeader::blob_max_hash_len) != 0) { LOGE("Hash mismatch for [route={}] [header={}] [computed={}]", b_route, header->to_string(), - hex_bytes(computed_hash, BlobHeader::blob_max_hash_len)); + spdlog::to_hex(computed_hash, computed_hash + BlobHeader::blob_max_hash_len)); return folly::makeUnexpected(BlobError::CHECKSUM_MISMATCH); } diff --git a/src/lib/homestore_backend/hs_homeobject.cpp b/src/lib/homestore_backend/hs_homeobject.cpp index 212d7b63..52bc9921 100644 --- a/src/lib/homestore_backend/hs_homeobject.cpp +++ b/src/lib/homestore_backend/hs_homeobject.cpp @@ -125,6 +125,4 @@ void HSHomeObject::on_shard_meta_blk_recover_completed(bool success) { chunk_selector_->build_per_dev_chunk_heap(excluding_chunks); } -std::string hex_bytes(uint8_t* bytes, size_t len) { return fmt::format("{}", spdlog::to_hex(bytes, bytes + len)); } - } // namespace homeobject diff --git a/src/lib/homestore_backend/hs_homeobject.hpp b/src/lib/homestore_backend/hs_homeobject.hpp index 27642521..61986dd0 100644 --- a/src/lib/homestore_backend/hs_homeobject.hpp +++ b/src/lib/homestore_backend/hs_homeobject.hpp @@ -19,8 +19,6 @@ class IndexTableBase; namespace homeobject { -std::string hex_bytes(uint8_t* bytes, size_t len); - class BlobRouteKey; class BlobRouteValue; using BlobIndexTable = homestore::IndexTable< BlobRouteKey, BlobRouteValue >; @@ -128,9 +126,9 @@ class HSHomeObject : public HomeObjectImpl { bool valid() const { return magic == blob_header_magic || version <= blob_header_version; } std::string to_string() { - return fmt::format("magic={:#x} version={} algo={} hash={} shard={} blob_size={} user_size={}", magic, - version, (uint8_t)hash_algorithm, hex_bytes(hash, blob_max_hash_len), shard_id, - blob_size, user_key_size); + return fmt::format("magic={:#x} version={} shard={} blob_size={} user_size={} algo={} hash={}\n", magic, + version, shard_id, blob_size, user_key_size, (uint8_t)hash_algorithm, + spdlog::to_hex(hash, hash + blob_max_hash_len)); } }; #pragma pack() diff --git a/src/lib/homestore_backend/tests/test_hs_homeobject.cpp b/src/lib/homestore_backend/tests/test_hs_homeobject.cpp index 3cd31f6e..019fb19b 100644 --- a/src/lib/homestore_backend/tests/test_hs_homeobject.cpp +++ b/src/lib/homestore_backend/tests/test_hs_homeobject.cpp @@ -22,6 +22,8 @@ using homeobject::PGMember; using homeobject::ShardError; using namespace homeobject; +#define hex_bytes(buffer, len) fmt::format("{}", spdlog::to_hex((buffer), (buffer) + (len))) + SISL_LOGGING_INIT(logging, HOMEOBJECT_LOG_MODS) SISL_OPTIONS_ENABLE(logging, test_home_object) @@ -128,15 +130,6 @@ class HomeObjectFixture : public ::testing::Test { _obj_inst = homeobject::init_homeobject(std::weak_ptr< homeobject::HomeObjectApplication >(app)); std::this_thread::sleep_for(std::chrono::seconds{1}); } - - std::string hex_bytes(uint8_t* bytes, size_t len) { - std::stringstream ss; - ss << std::hex; - for (size_t k = 0; k < len; k++) { - ss << std::setw(2) << std::setfill('0') << (int)bytes[k]; - } - return ss.str(); - } }; TEST_F(HomeObjectFixture, TestValidations) { diff --git a/src/lib/shard_manager.cpp b/src/lib/shard_manager.cpp index 049cdaed..17c39f19 100644 --- a/src/lib/shard_manager.cpp +++ b/src/lib/shard_manager.cpp @@ -6,25 +6,21 @@ std::shared_ptr< ShardManager > HomeObjectImpl::shard_manager() { return shared_ ShardManager::AsyncResult< ShardInfo > HomeObjectImpl::create_shard(pg_id_t pg_owner, uint64_t size_bytes) { if (0 == size_bytes || max_shard_size() < size_bytes) return folly::makeUnexpected(ShardError::INVALID_ARG); - return _defer().thenValue([this, pg_owner, size_bytes](auto) mutable -> ShardManager::AsyncResult< ShardInfo > { - return _create_shard(pg_owner, size_bytes); - }); + return _create_shard(pg_owner, size_bytes); } ShardManager::AsyncResult< InfoList > HomeObjectImpl::list_shards(pg_id_t pgid) const { - return _defer().thenValue([this, pgid](auto) mutable -> ShardManager::Result< InfoList > { - std::shared_lock lock_guard(_pg_lock); - auto iter = _pg_map.find(pgid); - if (iter == _pg_map.cend()) { return folly::makeUnexpected(ShardError::UNKNOWN_PG); } - auto& pg = iter->second; - - auto info_l = std::list< ShardInfo >(); - for (auto const& shard : pg->shards_) { - LOGD("found [shard={}]", shard->info.id); - info_l.push_back(shard->info); - } - return info_l; - }); + std::shared_lock lock_guard(_pg_lock); + auto iter = _pg_map.find(pgid); + if (iter == _pg_map.cend()) { return folly::makeUnexpected(ShardError::UNKNOWN_PG); } + auto& pg = iter->second; + + auto info_l = std::list< ShardInfo >(); + for (auto const& shard : pg->shards_) { + LOGD("found [shard={}]", shard->info.id); + info_l.push_back(shard->info); + } + return info_l; } ShardManager::AsyncResult< ShardInfo > HomeObjectImpl::seal_shard(shard_id_t id) { @@ -46,11 +42,9 @@ ShardManager::AsyncResult< ShardInfo > HomeObjectImpl::get_shard(shard_id_t id) // This is used as a first call for many operations and initializes the Future. // folly::Future< ShardManager::Result< ShardInfo > > HomeObjectImpl::_get_shard(shard_id_t id) const { - return _defer().thenValue([this, id](auto) -> ShardManager::Result< ShardInfo > { - auto lg = std::shared_lock(_shard_lock); - if (auto it = _shard_map.find(id); _shard_map.end() != it) return (*it->second)->info; - return folly::makeUnexpected(ShardError::UNKNOWN_SHARD); - }); + auto lg = std::shared_lock(_shard_lock); + if (auto it = _shard_map.find(id); _shard_map.end() != it) return (*it->second)->info; + return folly::makeUnexpected(ShardError::UNKNOWN_SHARD); } uint64_t HomeObjectImpl::get_current_timestamp() {