Use getSLEi to get an immutable SLE. This lets us cache them.

This commit is contained in:
JoelKatz
2013-02-20 12:00:38 -08:00
parent ba37349b95
commit 25c52b1a4d
10 changed files with 35 additions and 13 deletions

View File

@@ -35,9 +35,9 @@ void AccountItems::fillItems(const uint160& accountID, Ledger::ref ledger)
BOOST_FOREACH(uint256& uNode, svOwnerNodes.peekValue()) BOOST_FOREACH(uint256& uNode, svOwnerNodes.peekValue())
{ {
SLE::pointer sleCur = ledger->getSLE(uNode); SLE::pointer sleCur = ledger->getSLEi(uNode);
AccountItem::pointer item=mOfType->makeItem(accountID, sleCur); AccountItem::pointer item = mOfType->makeItem(accountID, sleCur);
if(item) if(item)
{ {
mItems.push_back(item); mItems.push_back(item);

View File

@@ -41,7 +41,7 @@ DatabaseCon::~DatabaseCon()
Application::Application() : Application::Application() :
mIOWork(mIOService), mAuxWork(mAuxService), mUNL(mIOService), mNetOps(mIOService, &mLedgerMaster), mIOWork(mIOService), mAuxWork(mAuxService), mUNL(mIOService), mNetOps(mIOService, &mLedgerMaster),
mTempNodeCache("NodeCache", 16384, 90), mHashedObjectStore(16384, 300), mTempNodeCache("NodeCache", 16384, 90), mHashedObjectStore(16384, 300), mSLECache("LedgerEntryCache", 4096, 120),
mSNTPClient(mAuxService), mRPCHandler(&mNetOps), mFeeTrack(), mSNTPClient(mAuxService), mRPCHandler(&mNetOps), mFeeTrack(),
mRpcDB(NULL), mTxnDB(NULL), mLedgerDB(NULL), mWalletDB(NULL), mHashNodeDB(NULL), mNetNodeDB(NULL), mRpcDB(NULL), mTxnDB(NULL), mLedgerDB(NULL), mWalletDB(NULL), mHashNodeDB(NULL), mNetNodeDB(NULL),
mConnectionPool(mIOService), mPeerDoor(NULL), mRPCDoor(NULL), mWSPublicDoor(NULL), mWSPrivateDoor(NULL), mConnectionPool(mIOService), mPeerDoor(NULL), mRPCDoor(NULL), mWSPublicDoor(NULL), mWSPrivateDoor(NULL),
@@ -301,6 +301,7 @@ void Application::sweep()
mTempNodeCache.sweep(); mTempNodeCache.sweep();
mValidations.sweep(); mValidations.sweep();
getMasterLedgerAcquire().sweep(); getMasterLedgerAcquire().sweep();
mSLECache.sweep();
mSweepTimer.expires_from_now(boost::posix_time::seconds(theConfig.getSize(siSweepInterval))); mSweepTimer.expires_from_now(boost::posix_time::seconds(theConfig.getSize(siSweepInterval)));
mSweepTimer.async_wait(boost::bind(&Application::sweep, this)); mSweepTimer.async_wait(boost::bind(&Application::sweep, this));
} }

View File

@@ -29,6 +29,7 @@
class RPCDoor; class RPCDoor;
class PeerDoor; class PeerDoor;
typedef TaggedCache< uint256, std::vector<unsigned char> > NodeCache; typedef TaggedCache< uint256, std::vector<unsigned char> > NodeCache;
typedef TaggedCache< uint256, SLE > SLECache;
class DatabaseCon class DatabaseCon
{ {
@@ -60,6 +61,7 @@ class Application
ValidationCollection mValidations; ValidationCollection mValidations;
SuppressionTable mSuppressions; SuppressionTable mSuppressions;
HashedObjectStore mHashedObjectStore; HashedObjectStore mHashedObjectStore;
SLECache mSLECache;
SNTPClient mSNTPClient; SNTPClient mSNTPClient;
JobQueue mJobQueue; JobQueue mJobQueue;
RPCHandler mRPCHandler; RPCHandler mRPCHandler;
@@ -118,6 +120,7 @@ public:
TXQueue& getTxnQueue() { return mTxnQueue; } TXQueue& getTxnQueue() { return mTxnQueue; }
PeerDoor& getPeerDoor() { return *mPeerDoor; } PeerDoor& getPeerDoor() { return *mPeerDoor; }
OrderBookDB& getOrderBookDB() { return mOrderBookDB; } OrderBookDB& getOrderBookDB() { return mOrderBookDB; }
SLECache& getSLECache() { return mSLECache; }
bool isNew(const uint256& s) { return mSuppressions.addSuppression(s); } bool isNew(const uint256& s) { return mSuppressions.addSuppression(s); }

View File

@@ -954,6 +954,22 @@ SLE::pointer Ledger::getSLE(const uint256& uHash)
return boost::make_shared<SLE>(node->peekSerializer(), node->getTag()); return boost::make_shared<SLE>(node->peekSerializer(), node->getTag());
} }
SLE::pointer Ledger::getSLEi(const uint256& uId)
{
uint256 hash;
SHAMapItem::pointer node = mAccountStateMap->peekItem(uId, hash);
if (!node)
return SLE::pointer();
SLE::pointer ret = theApp->getSLECache().fetch(hash);
if (!ret)
{
ret = boost::make_shared<SLE>(node->peekSerializer(), node->getTag());
theApp->getSLECache().canonicalize(hash, ret);
}
return ret;
}
uint256 Ledger::getFirstLedgerIndex() uint256 Ledger::getFirstLedgerIndex()
{ {
SHAMapItem::pointer node = mAccountStateMap->peekFirstItem(); SHAMapItem::pointer node = mAccountStateMap->peekFirstItem();
@@ -1179,7 +1195,7 @@ uint256 Ledger::getLedgerHash(uint32 ledgerIndex)
int diff = mLedgerSeq - ledgerIndex; int diff = mLedgerSeq - ledgerIndex;
if (diff <= 256) if (diff <= 256)
{ {
SLE::pointer hashIndex = getSLE(getLedgerHashIndex()); SLE::pointer hashIndex = getSLEi(getLedgerHashIndex());
if (hashIndex) if (hashIndex)
{ {
assert(hashIndex->getFieldU32(sfLastLedgerSequence) == (mLedgerSeq - 1)); assert(hashIndex->getFieldU32(sfLastLedgerSequence) == (mLedgerSeq - 1));
@@ -1199,7 +1215,7 @@ uint256 Ledger::getLedgerHash(uint32 ledgerIndex)
} }
// in skiplist // in skiplist
SLE::pointer hashIndex = getSLE(getLedgerHashIndex(ledgerIndex)); SLE::pointer hashIndex = getSLEi(getLedgerHashIndex(ledgerIndex));
if (hashIndex) if (hashIndex)
{ {
int lastSeq = hashIndex->getFieldU32(sfLastLedgerSequence); int lastSeq = hashIndex->getFieldU32(sfLastLedgerSequence);
@@ -1219,7 +1235,7 @@ uint256 Ledger::getLedgerHash(uint32 ledgerIndex)
std::vector< std::pair<uint32, uint256> > Ledger::getLedgerHashes() std::vector< std::pair<uint32, uint256> > Ledger::getLedgerHashes()
{ {
std::vector< std::pair<uint32, uint256> > ret; std::vector< std::pair<uint32, uint256> > ret;
SLE::pointer hashIndex = getSLE(getLedgerHashIndex()); SLE::pointer hashIndex = getSLEi(getLedgerHashIndex());
if (hashIndex) if (hashIndex)
{ {
STVector256 vec = hashIndex->getFieldV256(sfHashes); STVector256 vec = hashIndex->getFieldV256(sfHashes);

View File

@@ -201,7 +201,8 @@ public:
void pendSave(bool fromConsensus); void pendSave(bool fromConsensus);
// next/prev function // next/prev function
SLE::pointer getSLE(const uint256& uHash); SLE::pointer getSLE(const uint256& uHash); // SLE is mutable
SLE::pointer getSLEi(const uint256& uHash); // SLE is immutable
uint256 getFirstLedgerIndex(); uint256 getFirstLedgerIndex();
uint256 getLastLedgerIndex(); uint256 getLastLedgerIndex();
uint256 getNextLedgerIndex(const uint256& uHash); // first node >hash uint256 getNextLedgerIndex(const uint256& uHash); // first node >hash

View File

@@ -399,7 +399,7 @@ void LedgerEntrySet::calcRawMeta(Serializer& s, TER result, uint32 index)
if (type == &sfGeneric) if (type == &sfGeneric)
continue; continue;
SLE::pointer origNode = mLedger->getSLE(it.first); SLE::pointer origNode = mLedger->getSLEi(it.first);
SLE::pointer curNode = it.second.mEntry; SLE::pointer curNode = it.second.mEntry;
if ((type == &sfModifiedNode) && (*curNode == *origNode)) if ((type == &sfModifiedNode) && (*curNode == *origNode))

View File

@@ -538,7 +538,7 @@ Json::Value NetworkOPs::getOwnerInfo(Ledger::pointer lpLedger, const RippleAddre
BOOST_FOREACH(const uint256& uDirEntry, vuiIndexes) BOOST_FOREACH(const uint256& uDirEntry, vuiIndexes)
{ {
SLE::pointer sleCur = lpLedger->getSLE(uDirEntry); SLE::pointer sleCur = lpLedger->getSLEi(uDirEntry);
switch (sleCur->getType()) switch (sleCur->getType())
{ {

View File

@@ -165,6 +165,7 @@ public:
void setLastValidation(SerializedValidation::ref v) { mLastValidation = v; } void setLastValidation(SerializedValidation::ref v) { mLastValidation = v; }
SLE::pointer getSLE(Ledger::pointer lpLedger, const uint256& uHash) { return lpLedger->getSLE(uHash); } SLE::pointer getSLE(Ledger::pointer lpLedger, const uint256& uHash) { return lpLedger->getSLE(uHash); }
SLE::pointer getSLEi(Ledger::pointer lpLedger, const uint256& uHash) { return lpLedger->getSLEi(uHash); }
// //
// Transaction operations // Transaction operations

View File

@@ -39,7 +39,7 @@ void OrderBookDB::setup(Ledger::ref ledger)
while (currentIndex.isNonZero()) while (currentIndex.isNonZero())
{ {
SLE::pointer entry=ledger->getSLE(currentIndex); SLE::pointer entry=ledger->getSLEi(currentIndex);
OrderBook::pointer book = OrderBook::newOrderBook(entry); OrderBook::pointer book = OrderBook::newOrderBook(entry);
if (book) if (book)

View File

@@ -217,7 +217,7 @@ Json::Value RPCHandler::transactionSign(Json::Value jvRequest, bool bSubmit)
if (!txJSON.isMember("Flags")) txJSON["Flags"] = 0; if (!txJSON.isMember("Flags")) txJSON["Flags"] = 0;
Ledger::pointer lpCurrent = mNetOps->getCurrentLedger(); Ledger::pointer lpCurrent = mNetOps->getCurrentLedger();
SLE::pointer sleAccountRoot = mNetOps->getSLE(lpCurrent, Ledger::getAccountRootIndex(raSrcAddressID.getAccountID())); SLE::pointer sleAccountRoot = mNetOps->getSLEi(lpCurrent, Ledger::getAccountRootIndex(raSrcAddressID.getAccountID()));
if (!sleAccountRoot) if (!sleAccountRoot)
{ {
@@ -2364,7 +2364,7 @@ Json::Value RPCHandler::doLedgerEntry(Json::Value jvRequest)
if (!!uNodeIndex) if (!!uNodeIndex)
{ {
SLE::pointer sleNode = mNetOps->getSLE(lpLedger, uNodeIndex); SLE::pointer sleNode = mNetOps->getSLEi(lpLedger, uNodeIndex);
if (!sleNode) if (!sleNode)
{ {