mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
handle case where fetchLedgerPage times out and ledger is incomplete
This commit is contained in:
@@ -197,8 +197,15 @@ BackendInterface::fetchLedgerPage(
|
|||||||
LedgerPage page;
|
LedgerPage page;
|
||||||
page.cursor = cursor;
|
page.cursor = cursor;
|
||||||
long totalTime = 0;
|
long totalTime = 0;
|
||||||
|
long maxTime = 5000;
|
||||||
|
bool timedOut = false;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
if (totalTime >= maxTime)
|
||||||
|
{
|
||||||
|
timedOut = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
adjustedLimit = adjustedLimit >= 8192 ? 8192 : adjustedLimit * 2;
|
adjustedLimit = adjustedLimit >= 8192 ? 8192 : adjustedLimit * 2;
|
||||||
auto start = std::chrono::system_clock::now();
|
auto start = std::chrono::system_clock::now();
|
||||||
auto partial =
|
auto partial =
|
||||||
@@ -219,7 +226,7 @@ BackendInterface::fetchLedgerPage(
|
|||||||
page.objects.insert(
|
page.objects.insert(
|
||||||
page.objects.end(), partial.objects.begin(), partial.objects.end());
|
page.objects.end(), partial.objects.begin(), partial.objects.end());
|
||||||
page.cursor = partial.cursor;
|
page.cursor = partial.cursor;
|
||||||
} while (page.objects.size() < limit && page.cursor && totalTime < 5000);
|
} while (page.objects.size() < limit && page.cursor);
|
||||||
if (incomplete)
|
if (incomplete)
|
||||||
{
|
{
|
||||||
auto rng = fetchLedgerRange();
|
auto rng = fetchLedgerRange();
|
||||||
@@ -263,7 +270,15 @@ BackendInterface::fetchLedgerPage(
|
|||||||
});
|
});
|
||||||
if (page.objects.size() > limit)
|
if (page.objects.size() > limit)
|
||||||
page.objects.resize(limit);
|
page.objects.resize(limit);
|
||||||
if (page.objects.size() && page.objects.size() >= limit)
|
if (timedOut)
|
||||||
|
{
|
||||||
|
if (page.cursor && lowerPage.cursor)
|
||||||
|
page.cursor =
|
||||||
|
std::min(page.cursor.value(), lowerPage.cursor.value());
|
||||||
|
else if (lowerPage.cursor)
|
||||||
|
page.cursor = lowerPage.cursor;
|
||||||
|
}
|
||||||
|
else if (page.objects.size() && page.objects.size() >= limit)
|
||||||
page.cursor = page.objects.back().key;
|
page.cursor = page.objects.back().key;
|
||||||
}
|
}
|
||||||
return page;
|
return page;
|
||||||
|
|||||||
Reference in New Issue
Block a user