From 67c1874e813b2dae5733cde487f17cd262635e29 Mon Sep 17 00:00:00 2001
From: Andi Skrgat <andi8647@gmail.com>
Date: Mon, 22 Jan 2024 10:15:32 +0100
Subject: [PATCH] AF callbacks

---
 src/coordination/coordinator_state.cpp | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/src/coordination/coordinator_state.cpp b/src/coordination/coordinator_state.cpp
index fa8e84ea6..bc21d1961 100644
--- a/src/coordination/coordinator_state.cpp
+++ b/src/coordination/coordinator_state.cpp
@@ -82,10 +82,10 @@ auto CoordinatorState::RegisterReplica(CoordinatorClientConfig config) -> Regist
   // has become main MG_ASSERT(replica_client_info != registered_replicas_info.end(), "Replica {} not found in
   // registered replicas info",
   //          instance_name);
-  auto find_client_info = [&](std::string_view instance_name) -> CoordinatorClientInfo & {
-    MG_ASSERT(std::holds_alternative<CoordinatorData>(data_),
+  auto find_client_info = [](CoordinatorState *coord_state, std::string_view instance_name) -> CoordinatorClientInfo & {
+    MG_ASSERT(std::holds_alternative<CoordinatorData>(coord_state->data_),
               "Can't execute CoordinatorClient's callback since variant holds wrong alternative");
-    auto &registered_replicas_info = std::get<CoordinatorData>(data_).registered_replicas_info_;
+    auto &registered_replicas_info = std::get<CoordinatorData>(coord_state->data_).registered_replicas_info_;
 
     auto replica_client_info = std::ranges::find_if(
         registered_replicas_info,
@@ -95,23 +95,21 @@ auto CoordinatorState::RegisterReplica(CoordinatorClientConfig config) -> Regist
       return *replica_client_info;
     }
 
-    auto &registered_main_info = std::get<CoordinatorData>(data_).registered_main_info_;
+    auto &registered_main_info = std::get<CoordinatorData>(coord_state->data_).registered_main_info_;
     MG_ASSERT(registered_main_info->instance_name_ == instance_name, "Instance is neither a replica nor main...");
     return *registered_main_info;
   };
 
-  auto repl_succ_cb = [&](std::string_view instance_name) -> void {
-    auto &client_info = find_client_info(instance_name);
+  auto repl_succ_cb = [&find_client_info](CoordinatorState *coord_state, std::string_view instance_name) -> void {
+    auto &client_info = find_client_info(coord_state, instance_name);
     client_info.UpdateLastResponseTime();
   };
 
-  auto repl_fail_cb = [&](std::string_view instance_name) -> void {
-    auto &client_info = find_client_info(instance_name);
+  auto repl_fail_cb = [&find_client_info](CoordinatorState *coord_state, std::string_view instance_name) -> void {
+    auto &client_info = find_client_info(coord_state, instance_name);
     client_info.UpdateInstanceStatus();
   };
 
-  // CoordinatorClient coord_client{this, std::move(config), std::move(repl_succ_cb), std::move(repl_fail_cb)};
-
   auto *coord_client = &std::get<CoordinatorData>(data_).registered_replicas_.emplace_back(
       this, std::move(config), std::move(repl_succ_cb), std::move(repl_fail_cb));