From 346d85a7a04fb3f8207aef261578464b45b5d629 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Dec 2025 06:16:30 +0000 Subject: [PATCH 1/6] Initial plan From 12df95c427d79c1575ff735f6e627849a69f39de Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Dec 2025 06:22:35 +0000 Subject: [PATCH 2/6] Add proactive log group leader refresh on initialization This fix ensures that after initializing the log agent, we immediately refresh the leader information for all log groups. This is critical after cluster restart scenarios where log group leaders may have changed during the previous session (e.g., during bootstrap). The RefreshLeader call will query the current leader from each log group, updating the leader cache with accurate information before any log operations begin. This prevents connection failures that occur when trying to communicate with stale/incorrect leader nodes. Co-authored-by: githubzilla <10080336+githubzilla@users.noreply.github.com> --- tx_service/src/sharder.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tx_service/src/sharder.cpp b/tx_service/src/sharder.cpp index d59980b3..d6bd122a 100644 --- a/tx_service/src/sharder.cpp +++ b/tx_service/src/sharder.cpp @@ -213,6 +213,14 @@ int Sharder::Init( if (log_agent_ != nullptr) { log_agent_->Init(txlog_ips_, txlog_ports_, 0); + // Refresh leader information for all log groups immediately after + // initialization to ensure we have current leader info, especially + // important after cluster restart when leaders may have changed. + uint32_t log_group_count = log_agent_->LogGroupCount(); + for (uint32_t lg_id = 0; lg_id < log_group_count; ++lg_id) + { + log_agent_->RefreshLeader(lg_id); + } } #ifdef EXT_TX_PROC_ENABLED From 8d9f1df8f0f25ab2cf447ddb28f3b8ba0dcd0342 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Dec 2025 06:23:35 +0000 Subject: [PATCH 3/6] Add logging for log group leader refresh operations Added INFO and DEBUG level logging to track leader refresh operations for better observability and debugging. This helps verify that leader discovery is working correctly during cluster initialization and restart scenarios. Co-authored-by: githubzilla <10080336+githubzilla@users.noreply.github.com> --- tx_service/src/sharder.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tx_service/src/sharder.cpp b/tx_service/src/sharder.cpp index d6bd122a..773e62e7 100644 --- a/tx_service/src/sharder.cpp +++ b/tx_service/src/sharder.cpp @@ -217,9 +217,12 @@ int Sharder::Init( // initialization to ensure we have current leader info, especially // important after cluster restart when leaders may have changed. uint32_t log_group_count = log_agent_->LogGroupCount(); + LOG(INFO) << "Refreshing leader info for " << log_group_count + << " log group(s) after initialization"; for (uint32_t lg_id = 0; lg_id < log_group_count; ++lg_id) { log_agent_->RefreshLeader(lg_id); + DLOG(INFO) << "Refreshed leader for log group " << lg_id; } } From 7ebe25be13b3a339e2c7916dc39c6dcbacc70b36 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Dec 2025 06:24:53 +0000 Subject: [PATCH 4/6] Add validation and documentation for log group leader refresh - Add warning when no log groups are found to detect configuration issues - Add comment explaining RefreshLeader is lightweight and handles errors - Improve code robustness and observability Co-authored-by: githubzilla <10080336+githubzilla@users.noreply.github.com> --- tx_service/src/sharder.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tx_service/src/sharder.cpp b/tx_service/src/sharder.cpp index 773e62e7..a7002abb 100644 --- a/tx_service/src/sharder.cpp +++ b/tx_service/src/sharder.cpp @@ -217,12 +217,24 @@ int Sharder::Init( // initialization to ensure we have current leader info, especially // important after cluster restart when leaders may have changed. uint32_t log_group_count = log_agent_->LogGroupCount(); - LOG(INFO) << "Refreshing leader info for " << log_group_count - << " log group(s) after initialization"; - for (uint32_t lg_id = 0; lg_id < log_group_count; ++lg_id) + if (log_group_count == 0) { - log_agent_->RefreshLeader(lg_id); - DLOG(INFO) << "Refreshed leader for log group " << lg_id; + LOG(WARNING) << "No log groups found after log agent " + "initialization. Log service may not be properly " + "configured."; + } + else + { + LOG(INFO) << "Refreshing leader info for " << log_group_count + << " log group(s) after initialization"; + for (uint32_t lg_id = 0; lg_id < log_group_count; ++lg_id) + { + // RefreshLeader is typically a lightweight operation that + // updates internal cache. The log service will handle any + // connection issues gracefully with retries. + log_agent_->RefreshLeader(lg_id); + DLOG(INFO) << "Refreshed leader for log group " << lg_id; + } } } From ba9e23e35af72a801fd0efb0e60c24422852a23c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Dec 2025 06:27:02 +0000 Subject: [PATCH 5/6] Polish code formatting and style - Fix multi-line string formatting for better readability - log_group_count is already stored in a variable (no redundant calls) - Improved code consistency Co-authored-by: githubzilla <10080336+githubzilla@users.noreply.github.com> --- _codeql_detected_source_root | 1 + tx_service/src/sharder.cpp | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 120000 _codeql_detected_source_root diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root new file mode 120000 index 00000000..945c9b46 --- /dev/null +++ b/_codeql_detected_source_root @@ -0,0 +1 @@ +. \ No newline at end of file diff --git a/tx_service/src/sharder.cpp b/tx_service/src/sharder.cpp index a7002abb..ee892cb3 100644 --- a/tx_service/src/sharder.cpp +++ b/tx_service/src/sharder.cpp @@ -219,9 +219,9 @@ int Sharder::Init( uint32_t log_group_count = log_agent_->LogGroupCount(); if (log_group_count == 0) { - LOG(WARNING) << "No log groups found after log agent " - "initialization. Log service may not be properly " - "configured."; + LOG(WARNING) + << "No log groups found after log agent initialization. " + "Log service may not be properly configured."; } else { From 5adce3096d2cfa7ed7dcd0412e517630dc07d835 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Dec 2025 06:27:42 +0000 Subject: [PATCH 6/6] Remove codeql temporary file and add to gitignore The _codeql_detected_source_root file is a temporary artifact from security scanning and should not be committed to the repository. Co-authored-by: githubzilla <10080336+githubzilla@users.noreply.github.com> --- .gitignore | 1 + _codeql_detected_source_root | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 120000 _codeql_detected_source_root diff --git a/.gitignore b/.gitignore index de9ce42c..c0813a19 100644 --- a/.gitignore +++ b/.gitignore @@ -358,3 +358,4 @@ compile_commands.json cmake-build-debug/ .cache +_codeql_detected_source_root diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root deleted file mode 120000 index 945c9b46..00000000 --- a/_codeql_detected_source_root +++ /dev/null @@ -1 +0,0 @@ -. \ No newline at end of file