Skip to content

Commit

Permalink
Convert executor to a CLI toggle.
Browse files Browse the repository at this point in the history
  • Loading branch information
szmyd committed Oct 20, 2023
1 parent 32ca165 commit f65d16d
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 18 deletions.
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.13.1"
homepage = "https://github.com/eBay/HomeObject"
description = "Blob Store built on HomeReplication"
topics = ("ebay")
Expand Down
1 change: 1 addition & 0 deletions src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ add_flags("-Wno-unused-parameter")

add_library(${PROJECT_NAME}_core OBJECT)
target_sources(${PROJECT_NAME}_core PRIVATE
homeobject_impl.cpp
blob_manager.cpp
shard_manager.cpp
pg_manager.cpp
Expand Down
27 changes: 27 additions & 0 deletions src/lib/homeobject_impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "homeobject_impl.hpp"

#include <algorithm>

SISL_OPTION_GROUP(homeobject_options,
(executor_type, "", "executor", "Executor to use for Future deferal",
::cxxopts::value< std::string >()->default_value("immediate"), "immediate|cpu|io"));

namespace homeobject {

HomeObjectImpl::HomeObjectImpl(std::weak_ptr< HomeObjectApplication >&& application) :
_application(std::move(application)) {
auto exe_type = SISL_OPTIONS["executor"].as< std::string >();
std::transform(exe_type.begin(), exe_type.end(), exe_type.begin(), ::tolower);

if ("immediate" == exe_type) [[likely]]
executor_ = &folly::QueuedImmediateExecutor::instance();
else if ("io" == exe_type)
executor_ = folly::getGlobalIOExecutor();
else if ("cpu" == exe_type)
executor_ = folly::getGlobalCPUExecutor();
else
RELEASE_ASSERT(false, "Unknown Folly Executor type: [{}]", exe_type);
LOGI("initialized with [executor={}]", exe_type);
}

} // namespace homeobject
10 changes: 6 additions & 4 deletions src/lib/homeobject_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ class HomeObjectImpl : public HomeObject,
uint64_t len = 0) const = 0;
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 All @@ -95,6 +93,8 @@ class HomeObjectImpl : public HomeObject,
/// Our SvcId retrieval and SvcId->IP mapping
std::weak_ptr< HomeObjectApplication > _application;

folly::Executor::KeepAlive<> executor_;

///
mutable std::shared_mutex _pg_lock;
std::map< pg_id_t, unique< PG > > _pg_map;
Expand All @@ -103,9 +103,11 @@ class HomeObjectImpl : public HomeObject,
std::map< shard_id_t, ShardIterator > _shard_map;
///

auto _defer() const { return folly::makeSemiFuture().via(executor_); }
folly::Future< ShardManager::Result< ShardInfo > > _get_shard(shard_id_t id) const;

public:
explicit HomeObjectImpl(std::weak_ptr< HomeObjectApplication >&& application) :
_application(std::move(application)) {}
explicit HomeObjectImpl(std::weak_ptr< HomeObjectApplication >&& application);

~HomeObjectImpl() override = default;
HomeObjectImpl(const HomeObjectImpl&) = delete;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/homestore_backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ target_link_libraries(blob_homestore_test
homeobject_homestore
${COMMON_TEST_DEPS}
)
add_test(NAME BlobHomestoreTest COMMAND blob_homestore_test -csv error --num_iters 1000)
add_test(NAME BlobHomestoreTest COMMAND blob_homestore_test -csv error --executor immediate)
set_property(TEST BlobHomestoreTest PROPERTY RUN_SERIAL 1)
endif()
2 changes: 1 addition & 1 deletion src/lib/homestore_backend/index_kv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ HSHomeObject::get_from_index_table(shared< BlobIndexTable > index_table, shard_i
homestore::BtreeSingleGetRequest get_req{&index_key, &index_value};
auto status = index_table->get(get_req);
if (status != homestore::btree_status_t::success) {
LOGERROR("Failed to get from index table [route={}]", index_key);
LOGDEBUG("Failed to get from index table [route={}]", index_key);
return folly::makeUnexpected(BlobError::UNKNOWN_BLOB);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/homestore_backend/tests/hs_blob_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ TEST_F(HomeObjectFixture, SealShardWithRestart) {
int main(int argc, char* argv[]) {
int parsed_argc = argc;
::testing::InitGoogleTest(&parsed_argc, argv);
SISL_OPTIONS_LOAD(parsed_argc, argv, logging, test_home_object);
SISL_OPTIONS_LOAD(parsed_argc, argv, logging, homeobject_options, test_home_object);
sisl::logging::SetLogger(std::string(argv[0]));
spdlog::set_pattern("[%D %T.%e] [%n] [%^%l%$] [%t] %v");
parsed_argc = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/homestore_backend/tests/hs_shard_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ TEST_F(ShardManagerTestingRecovery, ShardManagerRecovery) {
int main(int argc, char* argv[]) {
int parsed_argc = argc;
::testing::InitGoogleTest(&parsed_argc, argv);
SISL_OPTIONS_LOAD(parsed_argc, argv, logging);
SISL_OPTIONS_LOAD(parsed_argc, argv, logging, homeobject_options, test_home_object);
sisl::logging::SetLogger(std::string(argv[0]));
spdlog::set_pattern("[%D %T.%e] [%n] [%^%l%$] [%t] %v");
parsed_argc = 1;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/memory_backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ target_link_libraries(blob_memory_test
homeobject_memory
${COMMON_TEST_DEPS}
)
add_test(NAME BlobMemoryTest COMMAND blob_memory_test -csv error)
add_test(NAME BlobMemoryTestCPU COMMAND blob_memory_test -csv error --num_iters 20000 --executor cpu)
add_test(NAME BlobMemoryTestImmediate COMMAND blob_memory_test -csv error --executor io)
endif()
2 changes: 1 addition & 1 deletion src/lib/tests/BlobManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ TEST_F(TestFixture, BasicTests) {
int main(int argc, char* argv[]) {
int parsed_argc = argc;
::testing::InitGoogleTest(&parsed_argc, argv);
SISL_OPTIONS_LOAD(parsed_argc, argv, logging, test_home_object);
SISL_OPTIONS_LOAD(parsed_argc, argv, logging, homeobject_options, test_home_object);
sisl::logging::SetLogger(std::string(argv[0]));
spdlog::set_pattern("[%D %T.%e] [%n] [%^%l%$] [%t] %v");
parsed_argc = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/tests/PGManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ TEST_F(TestFixture, Migrate) {
int main(int argc, char* argv[]) {
int parsed_argc = argc;
::testing::InitGoogleTest(&parsed_argc, argv);
SISL_OPTIONS_LOAD(parsed_argc, argv, logging);
SISL_OPTIONS_LOAD(parsed_argc, argv, logging, homeobject_options, test_home_object);
sisl::logging::SetLogger(std::string(argv[0]));
spdlog::set_pattern("[%D %T.%e] [%n] [%^%l%$] [%t] %v");
parsed_argc = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/tests/ShardManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ TEST_F(TestFixture, SealShard) {
int main(int argc, char* argv[]) {
int parsed_argc = argc;
::testing::InitGoogleTest(&parsed_argc, argv);
SISL_OPTIONS_LOAD(parsed_argc, argv, logging);
SISL_OPTIONS_LOAD(parsed_argc, argv, logging, homeobject_options, test_home_object);
sisl::logging::SetLogger(std::string(argv[0]));
spdlog::set_pattern("[%D %T.%e] [%n] [%^%l%$] [%t] %v");
parsed_argc = 1;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/tests/fixture_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ SISL_LOGGING_INIT(logging, HOMEOBJECT_LOG_MODS)

SISL_OPTION_GROUP(
test_home_object,
(num_iters, "", "num_iters", "number of iterations per loop",
::cxxopts::value< uint64_t >()->default_value("100000"), "number"),
(num_iters, "", "num_iters", "number of iterations per loop", ::cxxopts::value< uint64_t >()->default_value("1000"),
"number"),
(num_pgs, "", "num_pgs", "number of pgs", ::cxxopts::value< uint64_t >()->default_value("10"), "number"),
(num_shards, "", "num_shards", "number of shards", ::cxxopts::value< uint64_t >()->default_value("20"), "number"),
(num_blobs, "", "num_blobs", "number of blobs", ::cxxopts::value< uint64_t >()->default_value("50"), "number"));

SISL_OPTIONS_ENABLE(logging, test_home_object)
SISL_OPTIONS_ENABLE(logging, homeobject_options, test_home_object)

using homeobject::Blob;
using homeobject::blob_id_t;
Expand Down
8 changes: 6 additions & 2 deletions test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include <folly/init/Init.h>
#include <sisl/options/options.h>
#include <homeobject/homeobject.hpp>
#include <boost/uuid/random_generator.hpp>

SISL_LOGGING_INIT(HOMEOBJECT_LOG_MODS)

SISL_OPTIONS_ENABLE(logging)
SISL_OPTIONS_ENABLE(logging, homeobject_options)

class TestApp : public homeobject::HomeObjectApplication {
public:
Expand All @@ -18,10 +19,13 @@ class TestApp : public homeobject::HomeObjectApplication {
};

int main(int argc, char** argv) {
SISL_OPTIONS_LOAD(argc, argv, logging)
SISL_OPTIONS_LOAD(argc, argv, logging, homeobject_options)
sisl::logging::SetLogger(std::string(argv[0]));
spdlog::set_pattern("[%D %T%z] [%^%l%$] [%n] [%t] %v");

auto parsed_argc = 1;
auto f = ::folly::Init(&parsed_argc, &argv, true);

auto a = std::make_shared< TestApp >();
homeobject::init_homeobject(a);
return 0;
Expand Down

0 comments on commit f65d16d

Please sign in to comment.