Changes to support the ledger cleaner

* Rework ledger save return values to indicate errors to callers
* Add an extra function to support the ledger cleaner.
This commit is contained in:
David Schwartz
2013-11-19 12:56:39 -08:00
committed by Vinnie Falco
parent 4577ad60c7
commit 02b5572ccc
10 changed files with 64 additions and 15 deletions

View File

@@ -12,13 +12,6 @@
## Peers.cpp
## LedgerMaster.cpp
- Change getLedgerByHash() to not use "all bits zero" to mean
"return the current ledger"
- replace uint32 with LedgerIndex and choose appropriate names
## Beast
- Change Stoppable to not require a constructor with parameters

View File

@@ -538,7 +538,7 @@ uint256 Ledger::getHash ()
return mHash;
}
void Ledger::saveValidatedLedger (bool current)
bool Ledger::saveValidatedLedger (bool current)
{
WriteLog (lsTRACE, Ledger) << "saveValidatedLedger " << (current ? "" : "fromAcquire ") << getLedgerSeq ();
static boost::format deleteLedger ("DELETE FROM Ledgers WHERE LedgerSeq = %u;");
@@ -588,7 +588,7 @@ void Ledger::saveValidatedLedger (bool current)
StaticScopedLockType sl (sPendingSaveLock, __FILE__, __LINE__);
sPendingSaves.erase(getLedgerSeq());
}
return;
return false;
}
{
@@ -664,6 +664,7 @@ void Ledger::saveValidatedLedger (bool current)
StaticScopedLockType sl (sPendingSaveLock, __FILE__, __LINE__);
sPendingSaves.erase(getLedgerSeq());
}
return true;
}
#ifndef NO_SQLITE3_PREPARE
@@ -1875,12 +1876,15 @@ uint32 Ledger::roundCloseTime (uint32 closeTime, uint32 closeResolution)
return closeTime - (closeTime % closeResolution);
}
/** Save, or arrange to save, a fully-validated ledger
Returns false on error
*/
bool Ledger::pendSaveValidated (bool isSynchronous, bool isCurrent)
{
if (!getApp().getHashRouter ().setFlag (getHash (), SF_SAVED))
{
WriteLog (lsDEBUG, Ledger) << "Double pend save for " << getLedgerSeq();
return false;
return true;
}
assert (isImmutable ());
@@ -1890,13 +1894,13 @@ bool Ledger::pendSaveValidated (bool isSynchronous, bool isCurrent)
if (!sPendingSaves.insert(getLedgerSeq()).second)
{
WriteLog (lsDEBUG, Ledger) << "Pend save with seq in pending saves " << getLedgerSeq();
return false;
return true;
}
}
if (isSynchronous)
{
saveValidatedLedger(isCurrent);
return saveValidatedLedger(isCurrent);
}
else if (isCurrent)
{

View File

@@ -63,6 +63,12 @@ protected:
// class. But then what is the meaning of a Ledger object? Is this
// really two classes in one? StoreOfAllLedgers + SingleLedgerObject?
//
/** Holds some or all of a ledger.
This can hold just the header, a partial set of data, or the entire set
of data. It all depends on what is in the corresponding SHAMap entry.
Various functions are provided to populate or depopulate the caches that
the object holds references to.
*/
class Ledger
: public boost::enable_shared_from_this <Ledger>
, public LedgerBase
@@ -470,7 +476,7 @@ protected:
{
saveValidatedLedger(current);
}
void saveValidatedLedger (bool current);
bool saveValidatedLedger (bool current);
void updateFees ();

View File

@@ -30,8 +30,8 @@
// FIXME: Need to clean up ledgers by index at some point
LedgerHistory::LedgerHistory ()
: mLedgersByHash ("LedgerCache", CACHED_LEDGER_NUM, CACHED_LEDGER_AGE)
, mConsensusValidated ("ConsensusValidated", 64, 300)
: mLedgersByHash ("LedgerCache", CACHED_LEDGER_NUM, CACHED_LEDGER_AGE)
, mConsensusValidated ("ConsensusValidated", 64, 300)
{
;
}
@@ -159,6 +159,21 @@ void LedgerHistory::validatedLedger (Ledger::ref ledger)
}
}
/** Ensure mLedgersByHash doesn't have the wrong hash for a particular index
*/
bool LedgerHistory::fixIndex (LedgerIndex ledgerIndex, LedgerHash const& ledgerHash)
{
TaggedCache::ScopedLockType sl (mLedgersByHash.peekMutex (), __FILE__, __LINE__);
std::map<uint32, uint256>::iterator it (mLedgersByIndex.find (ledgerIndex));
if ((it != mLedgersByIndex.end ()) && (it->second != ledgerHash) )
{
it->second = ledgerHash;
return false;
}
return true;
}
void LedgerHistory::tune (int size, int age)
{
mLedgersByHash.setTargetSize (size);

View File

@@ -50,6 +50,8 @@ public:
void builtLedger (Ledger::ref);
void validatedLedger (Ledger::ref);
bool fixIndex(LedgerIndex ledgerIndex, LedgerHash const& ledgerHash);
private:
TaggedCacheType <LedgerHash, Ledger, UptimeTimerAdapter> mLedgersByHash;
TaggedCacheType <LedgerIndex, std::pair< LedgerHash, LedgerHash >, UptimeTimerAdapter> mConsensusValidated;

View File

@@ -260,6 +260,11 @@ public:
checkAccept (lastClosed);
}
bool fixIndex (LedgerIndex ledgerIndex, LedgerHash const& ledgerHash)
{
return mLedgerHistory.fixIndex (ledgerIndex, ledgerHash);
}
void storeLedger (Ledger::pointer ledger)
{
mLedgerHistory.addLedger (ledger, false);

View File

@@ -122,6 +122,8 @@ public:
virtual void newPathRequest () = 0;
virtual void newOrderBookDB () = 0;
virtual bool fixIndex (LedgerIndex ledgerIndex, LedgerHash const& ledgerHash) = 0;
static bool shouldAcquire (uint32 currentLedgerID, uint32 ledgerHistory, uint32 targetLedger);
};

View File

@@ -0,0 +1,18 @@
# ripple_app
## Ledger.cpp
- Move all inlines into the .cpp, make the interface abstract
- Move static database functions into a real class, perhaps LedgerMaster
## LedgerMaster.cpp
- Change getLedgerByHash() to not use "all bits zero" to mean
"return the current ledger"
- replace uint32 with LedgerIndex and choose appropriate names
## Beast
- Change Stoppable to not require a constructor with parameters