Fix bug on cache download from peer when ledger not found (#370)

This commit is contained in:
CJ Cobb
2022-10-26 22:30:39 -04:00
committed by GitHub
parent dc89d23e5a
commit 8bd8ab9b8a

View File

@@ -971,6 +971,8 @@ ReportingETL::loadCacheFromClioPeer(
return request; return request;
}; };
bool started = false;
size_t numAttempts = 0;
do do
{ {
// Send the message // Send the message
@@ -1013,14 +1015,27 @@ ReportingETL::loadCacheFromClioPeer(
auto const& err = response.at("error"); auto const& err = response.at("error");
if (err.is_string() && err.as_string() == "lgrNotFound") if (err.is_string() && err.as_string() == "lgrNotFound")
{ {
++numAttempts;
if (numAttempts >= 5)
{
BOOST_LOG_TRIVIAL(error)
<< __func__
<< " ledger not found at peer after 5 attempts. "
"peer = "
<< ip << " ledger = " << ledgerIndex
<< ". Check your config and the health of the peer";
return false;
}
BOOST_LOG_TRIVIAL(warning) BOOST_LOG_TRIVIAL(warning)
<< __func__ << __func__
<< " ledger not found. ledger = " << ledgerIndex << " ledger not found. ledger = " << ledgerIndex
<< ". trying again"; << ". Sleeping and trying again";
std::this_thread::sleep_for(std::chrono::seconds(1));
continue; continue;
} }
return false; return false;
} }
started = true;
auto const& response = parsed.as_object()["result"].as_object(); auto const& response = parsed.as_object()["result"].as_object();
if (!response.contains("cache_full") || if (!response.contains("cache_full") ||
@@ -1063,7 +1078,7 @@ ReportingETL::loadCacheFromClioPeer(
BOOST_LOG_TRIVIAL(debug) BOOST_LOG_TRIVIAL(debug)
<< __func__ << " - At marker " << *marker; << __func__ << " - At marker " << *marker;
} while (marker); } while (marker || !started);
BOOST_LOG_TRIVIAL(info) BOOST_LOG_TRIVIAL(info)
<< __func__ << __func__
<< " Finished downloading ledger from clio node. ip = " << ip; << " Finished downloading ledger from clio node. ip = " << ip;