mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-30 08:35:52 +00:00
fix up some issues with async indexer
This commit is contained in:
@@ -123,12 +123,27 @@ public:
|
||||
void
|
||||
finish(uint32_t ledgerSequence, BackendInterface const& backend);
|
||||
void
|
||||
writeNext(uint32_t ledgerSequence, BackendInterface const& backend);
|
||||
writeFlagLedgerAsync(
|
||||
uint32_t ledgerSequence,
|
||||
BackendInterface const& backend);
|
||||
uint32_t
|
||||
getShift()
|
||||
{
|
||||
return shift_;
|
||||
}
|
||||
uint32_t
|
||||
getIndexOfSeq(uint32_t seq) const
|
||||
{
|
||||
if (isFlagLedger(seq))
|
||||
return seq;
|
||||
auto incr = (1 << shift_);
|
||||
return (seq >> shift_ << shift_) + incr;
|
||||
}
|
||||
bool
|
||||
isFlagLedger(uint32_t ledgerSequence) const
|
||||
{
|
||||
return (ledgerSequence % (1 << shift_)) == 0;
|
||||
}
|
||||
};
|
||||
|
||||
class BackendInterface
|
||||
@@ -151,15 +166,27 @@ public:
|
||||
std::optional<uint32_t>
|
||||
getIndexOfSeq(uint32_t seq) const
|
||||
{
|
||||
if (!fetchLedgerRange())
|
||||
if (indexer_.isFlagLedger(seq))
|
||||
return seq;
|
||||
auto rng = fetchLedgerRange();
|
||||
if (!rng)
|
||||
return {};
|
||||
if (fetchLedgerRange()->minSequence == seq)
|
||||
if (rng->minSequence == seq)
|
||||
return seq;
|
||||
uint32_t shift = indexer_.getShift();
|
||||
uint32_t incr = (1 << shift);
|
||||
if ((seq % incr) == 0)
|
||||
return seq;
|
||||
return (seq >> shift << shift) + incr;
|
||||
return indexer_.getIndexOfSeq(seq);
|
||||
}
|
||||
|
||||
bool
|
||||
finishWrites(uint32_t ledgerSequence) const
|
||||
{
|
||||
indexer_.finish(ledgerSequence, *this);
|
||||
auto commitRes = doFinishWrites();
|
||||
if (commitRes)
|
||||
{
|
||||
if (indexer_.isFlagLedger(ledgerSequence))
|
||||
indexer_.writeFlagLedgerAsync(ledgerSequence, *this);
|
||||
}
|
||||
return commitRes;
|
||||
}
|
||||
|
||||
virtual std::optional<uint32_t>
|
||||
@@ -171,6 +198,22 @@ public:
|
||||
virtual std::optional<LedgerRange>
|
||||
fetchLedgerRange() const = 0;
|
||||
|
||||
std::optional<LedgerRange>
|
||||
fetchLedgerRangeNoThrow() const
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
return fetchLedgerRange();
|
||||
}
|
||||
catch (DatabaseTimeout& t)
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual std::optional<Blob>
|
||||
fetchLedgerObject(ripple::uint256 const& key, uint32_t sequence) const = 0;
|
||||
|
||||
@@ -286,13 +329,6 @@ public:
|
||||
virtual void
|
||||
startWrites() const = 0;
|
||||
|
||||
bool
|
||||
finishWrites(uint32_t ledgerSequence) const
|
||||
{
|
||||
indexer_.finish(ledgerSequence, *this);
|
||||
indexer_.writeNext(ledgerSequence, *this);
|
||||
return doFinishWrites();
|
||||
}
|
||||
virtual bool
|
||||
doFinishWrites() const = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user