Skip to content

Commit

Permalink
refactor based on latest main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
zichanglai committed Sep 28, 2023
2 parents 514efcd + 185381e commit 5372d26
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 25 deletions.
4 changes: 2 additions & 2 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ def package(self):
def package_info(self):
self.cpp_info.names["cmake_find_package"] = "HomeObject"
self.cpp_info.names["cmake_find_package_multi"] = "HomeObject"
self.cpp_info.components["homestore"].libs = ["homeobject", "home_replication_mock"]
self.cpp_info.components["homestore"].libs = ["homeobject"]
self.cpp_info.components["homestore"].requires = ["homestore::homestore"]
self.cpp_info.components["memory"].libs = ["homeobject_memory", "home_replication_mock"]
self.cpp_info.components["memory"].libs = ["homeobject_memory"]
self.cpp_info.components["memory"].requires = ["homestore::homestore"]

if self.settings.os == "Linux":
Expand Down
2 changes: 1 addition & 1 deletion src/lib/homestore_backend/hs_homeobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void HSHomeObject::init_homestore() {
{HS_SERVICE::INDEX, hs_format_params{.size_pct = 5.0}},
});
}

LOGINFO("Initialize and start HomeStore is successfully");
}

Expand All @@ -69,7 +70,6 @@ void HSHomeObject::register_homestore_metablk_callback() {
HomeStore::instance()->meta_service().register_handler(
"ShardManager",
[this](homestore::meta_blk* mblk, sisl::byte_view buf, size_t size) { on_shard_meta_blk_found(mblk, buf); },

[this](bool success) { on_shard_meta_blk_recover_completed(success); }, true);

HomeStore::instance()->meta_service().register_handler(
Expand Down
6 changes: 5 additions & 1 deletion src/lib/homestore_backend/hs_shard_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ void HSHomeObject::on_shard_message_commit(int64_t lsn, sisl::blob const& header
}

// hs_ctx will be nullptr when HS is restarting and replay all commited log entries from the last checkpoint;
// and then we need re-read value from PBA;
// but do we really need to handle this for create_shard or seal_shard?
// because this raft log had been commit before HO restarts and commit result is already saved in HS metablks
// when HS restarts, all PG/Shard infos will be recovered from HS metablks and if we commit again, it will cause duplication;
#if 0
sisl::sg_list value;
value.size = blkids.blk_count() * repl_dev->get_blk_size();
auto value_buf = iomanager.iobuf_alloc(512, value.size);
Expand All @@ -135,6 +138,7 @@ void HSHomeObject::on_shard_message_commit(int64_t lsn, sisl::blob const& header
}
iomanager.iobuf_free(r_cast< uint8_t* >(value.iovs[0].iov_base));
});
#endif
}

void HSHomeObject::do_shard_message_commit(int64_t lsn, const ReplicationMessageHeader& header,
Expand Down
1 change: 0 additions & 1 deletion src/lib/homestore_backend/replication_state_machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class ReplicationStateMachine : public homestore::ReplDevListener {
///
/// @param header Header originally passed with repl_dev::write() api on the leader
/// @return Expected to return blk_alloc_hints for this write

homestore::blk_alloc_hints get_blk_alloc_hints(sisl::blob const& header,
cintrusive< homestore::repl_req_ctx >& ctx) override;

Expand Down
21 changes: 13 additions & 8 deletions src/lib/homestore_backend/tests/test_home_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,27 @@ SISL_LOGGING_INIT(logging, HOMEOBJECT_LOG_MODS)
SISL_OPTIONS_ENABLE(logging)

class FixtureApp : public homeobject::HomeObjectApplication {
private:
std::string fpath_{"/tmp/test_home_object.data.{}" + std::to_string(rand())};

public:
bool spdk_mode() const override { return false; }
uint32_t threads() const override { return 2; }
std::list< std::filesystem::path > devices() const override {
/* create files */
LOGINFO("creating device files with size {} ", 1, homestore::in_bytes(2 * Gi));
const std::string fpath{"/tmp/test_homestore.data"};
LOGINFO("creating {} device file", fpath);
if (std::filesystem::exists(fpath)) { std::filesystem::remove(fpath); }
std::ofstream ofs{fpath, std::ios::binary | std::ios::out | std::ios::trunc};
std::filesystem::resize_file(fpath, 2 * Gi);
LOGINFO("creating {} device file with size={}", fpath_, homestore::in_bytes(2 * Gi));
if (std::filesystem::exists(fpath_)) { std::filesystem::remove(fpath_); }
std::ofstream ofs{fpath_, std::ios::binary | std::ios::out | std::ios::trunc};
std::filesystem::resize_file(fpath_, 2 * Gi);

auto device_info = std::list< std::filesystem::path >();
device_info.emplace_back(std::filesystem::canonical(fpath));
device_info.emplace_back(std::filesystem::canonical(fpath_));
return device_info;
}

~FixtureApp() {
if (!fpath_.empty()) { std::filesystem::remove(fpath_); }
}

homeobject::peer_id_t discover_svcid(std::optional< homeobject::peer_id_t > const&) const override {
return boost::uuids::random_generator()();
}
Expand Down
27 changes: 16 additions & 11 deletions src/lib/homestore_backend/tests/test_shard_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,27 @@ SISL_LOGGING_INIT(logging, HOMEOBJECT_LOG_MODS)
SISL_OPTIONS_ENABLE(logging)

class FixtureApp : public homeobject::HomeObjectApplication {
private:
std::string fpath_{"/tmp/test_shard_manager.data.{}" + std::to_string(rand())};

public:
bool spdk_mode() const override { return false; }
uint32_t threads() const override { return 2; }
std::list< std::filesystem::path > devices() const override {
/* create files */
LOGINFO("creating device files with size {} ", 1, homestore::in_bytes(2 * Gi));
const std::string fpath{"/tmp/test_homestore.data"};
LOGINFO("creating {} device file", fpath);
if (std::filesystem::exists(fpath)) { std::filesystem::remove(fpath); }
std::ofstream ofs{fpath, std::ios::binary | std::ios::out | std::ios::trunc};
std::filesystem::resize_file(fpath, 2 * Gi);
LOGINFO("creating {} device file with size={}", fpath_, homestore::in_bytes(2 * Gi));
if (std::filesystem::exists(fpath_)) { std::filesystem::remove(fpath_); }
std::ofstream ofs{fpath_, std::ios::binary | std::ios::out | std::ios::trunc};
std::filesystem::resize_file(fpath_, 2 * Gi);

auto device_info = std::list< std::filesystem::path >();
device_info.emplace_back(std::filesystem::canonical(fpath));
device_info.emplace_back(std::filesystem::canonical(fpath_));
return device_info;
}

~FixtureApp() {
if (std::filesystem::exists(fpath_)) { std::filesystem::remove(fpath_); }
}

homeobject::peer_id_t discover_svcid(std::optional< homeobject::peer_id_t > const&) const override {
return boost::uuids::random_generator()();
}
Expand Down Expand Up @@ -212,7 +217,7 @@ TEST_F(ShardManagerTesting, MockSealShard) {
auto& check_shard = pg_result->shards_.front();
EXPECT_EQ(ShardInfo::State::SEALED, check_shard->info.state);
}
/*

class FixtureAppWithRecovery : public FixtureApp {
public:
std::list< std::filesystem::path > devices() const override {
Expand Down Expand Up @@ -260,7 +265,8 @@ TEST_F(ShardManagerTestingRecovery, ShardManagerRecovery) {
EXPECT_EQ(Mi, shard_info.total_capacity_bytes);
EXPECT_EQ(Mi, shard_info.available_capacity_bytes);
EXPECT_EQ(0ul, shard_info.deleted_capacity_bytes);
EXPECT_EQ(_pg_id, shard_info.placement_group);
EXPECT_EQ(_pg_id, shard_info.placement_group);

homeobject::HSHomeObject* ho = dynamic_cast< homeobject::HSHomeObject* >(_home_object.get());
auto pg_iter = ho->_pg_map.find(_pg_id);
EXPECT_TRUE(pg_iter != ho->_pg_map.end());
Expand All @@ -286,7 +292,6 @@ TEST_F(ShardManagerTestingRecovery, ShardManagerRecovery) {
EXPECT_TRUE(hs_shard->sb_->id == shard_info.id);
EXPECT_TRUE(hs_shard->sb_->id == shard_info.id);
}
*/

int main(int argc, char* argv[]) {
int parsed_argc = argc;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/tests/fixture_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using homeobject::BlobError;
using homeobject::peer_id_t;

class FixtureApp : public homeobject::HomeObjectApplication {
std::string path_{"/tmp/test_homestore.data"};
std::string path_{"/tmp/test_homestore.data." + std::to_string(rand())};

public:
FixtureApp() {
Expand Down

0 comments on commit 5372d26

Please sign in to comment.