Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove defer to CPUExecutor. #89

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion src/lib/homeobject_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/homestore_backend/hs_blob_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 0 additions & 2 deletions src/lib/homestore_backend/hs_homeobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 3 additions & 5 deletions src/lib/homestore_backend/hs_homeobject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 >;
Expand Down Expand Up @@ -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()
Expand Down
11 changes: 2 additions & 9 deletions src/lib/homestore_backend/tests/test_hs_homeobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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) {
Expand Down
36 changes: 15 additions & 21 deletions src/lib/shard_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down
Loading