Skip to content

Commit f553924

Browse files
author
yawzhang
committed
add http api for reconcile leader in case of imbalanced leadership distribution
1 parent 9bc58d9 commit f553924

6 files changed

Lines changed: 53 additions & 1 deletion

File tree

‎conanfile.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class HomeObjectConan(ConanFile):
1212
name = "homeobject"
13-
version = "2.7.3"
13+
version = "2.7.4"
1414

1515
homepage = "https://github.com/eBay/HomeObject"
1616
description = "Blob Store built on HomeReplication"

‎src/lib/homestore_backend/hs_homeobject.cpp‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,30 @@ void HSHomeObject::trigger_immediate_gc() {
478478
}
479479
}
480480

481+
void HSHomeObject::reconcile_pg_leader(int32_t pg_id) {
482+
if (pg_id == -1) {
483+
LOGI("PG id not set, start reconciling leaders for all PGs");
484+
std::shared_lock lock_guard(_pg_lock);
485+
std::vector< std::future< void > > futures;
486+
for (const auto& [id, pg] : _pg_map) {
487+
auto hs_pg = static_cast< HS_PG* >(pg.get());
488+
futures.emplace_back(std::async(std::launch::async, [hs_pg, id]() {
489+
hs_pg->reconcile_leader();
490+
LOGI("Triggered reconcile leader for PG {}", id);
491+
}));
492+
}
493+
for (auto& future : futures) {
494+
future.get();
495+
}
496+
} else {
497+
LOGI("Reconciling leader for PG {}", pg_id);
498+
auto hs_pg = get_hs_pg(pg_id);
499+
if (hs_pg) {
500+
hs_pg->reconcile_leader();
501+
} else {
502+
LOGE("PG {} not found", pg_id);
503+
}
504+
}
505+
}
506+
481507
} // namespace homeobject

‎src/lib/homestore_backend/hs_homeobject.hpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ class HSHomeObject : public HomeObjectImpl {
361361
* Returns all replication info of all peers.
362362
*/
363363
void get_peer_info(std::vector< peer_info >& members) const;
364+
365+
void reconcile_leader() const;
364366
};
365367

366368
struct HS_Shard : public Shard {
@@ -881,6 +883,17 @@ class HSHomeObject : public HomeObjectImpl {
881883
cshared< HeapChunkSelector > chunk_selector() const { return chunk_selector_; }
882884
cshared< GCManager > gc_manager() const { return gc_mgr_; }
883885

886+
/**
887+
* @brief Reconciles the leaders for all PGs or a specific PG identified by pg_id.
888+
*
889+
* This function ensures that the leadership status of PGs is consistent across the system.
890+
* If a specific pg_id is provided, it reconciles the leader for that particular PG.
891+
* If pg_id is -1 (default), it reconciles leaders for all PGs.
892+
*
893+
* @param pg_id The ID of the PG to reconcile. Default is -1, which indicates all PGs.
894+
*/
895+
void reconcile_pg_leader(int32_t pg_id = -1);
896+
884897
// Blob manager related.
885898
void on_blob_message_rollback(int64_t lsn, sisl::blob const& header, sisl::blob const& key,
886899
cintrusive< homestore::repl_req_ctx >& hs_ctx);

‎src/lib/homestore_backend/hs_http_manager.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ HttpManager::HttpManager(HSHomeObject& ho) : ho_(ho) {
3333
Pistache::Rest::Routes::bind(&HttpManager::get_obj_life, this)},
3434
{Pistache::Http::Method::Get, "/api/v1/mallocStats",
3535
Pistache::Rest::Routes::bind(&HttpManager::get_malloc_stats, this)},
36+
{Pistache::Http::Method::Post, "/api/v1/reconcile_leader",
37+
Pistache::Rest::Routes::bind(&HttpManager::reconcile_leader, this)},
3638
#ifdef _PRERELEASE
3739
{Pistache::Http::Method::Post, "/api/v1/crashSystem",
3840
Pistache::Rest::Routes::bind(&HttpManager::crash_system, this)},
@@ -63,6 +65,14 @@ void HttpManager::get_malloc_stats(const Pistache::Rest::Request& request, Pista
6365
response.send(Pistache::Http::Code::Ok, sisl::get_malloc_stats_detailed().dump(2));
6466
}
6567

68+
void HttpManager::reconcile_leader(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) {
69+
const auto pg_id_param = request.query().get("pg_id");
70+
int32_t pg_id = std::stoi(pg_id_param.value_or("-1"));
71+
LOGINFO("Received reconcile leader request for pg_id {}", pg_id);
72+
ho_.reconcile_pg_leader(pg_id);
73+
response.send(Pistache::Http::Code::Ok, "Reconcile leader request submitted");
74+
}
75+
6676
#ifdef _PRERELEASE
6777
void HttpManager::crash_system(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) {
6878
std::string crash_type;

‎src/lib/homestore_backend/hs_http_manager.hpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class HttpManager {
2626
private:
2727
void get_obj_life(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response);
2828
void get_malloc_stats(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response);
29+
void reconcile_leader(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response);
2930

3031
#ifdef _PRERELEASE
3132
void crash_system(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response);

‎src/lib/homestore_backend/hs_pg_manager.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,8 @@ void HSHomeObject::HS_PG::get_peer_info(std::vector< peer_info >& members) const
765765
}
766766
}
767767

768+
void HSHomeObject::HS_PG::reconcile_leader() const { repl_dev_->reconcile_leader(); }
769+
768770
// NOTE: caller should hold the _pg_lock
769771
const HSHomeObject::HS_PG* HSHomeObject::_get_hs_pg_unlocked(pg_id_t pg_id) const {
770772
auto iter = _pg_map.find(pg_id);

0 commit comments

Comments
 (0)