mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-01 00:15:51 +00:00
Cleanups.
This commit is contained in:
@@ -48,22 +48,28 @@ void HashedObjectStore::tune(int size, int age)
|
|||||||
mCache.setTargetAge(age);
|
mCache.setTargetAge(age);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HashedObjectStore::waitWrite()
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock sl(mWriteMutex);
|
||||||
|
int gen = mWriteGeneration;
|
||||||
|
while (mWritePending && (mWriteGeneration == gen))
|
||||||
|
mWriteCondition.wait(sl);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_LEVELDB
|
#ifdef USE_LEVELDB
|
||||||
|
|
||||||
bool HashedObjectStore::storeLevelDB(HashedObjectType type, uint32 index,
|
bool HashedObjectStore::storeLevelDB(HashedObjectType type, uint32 index,
|
||||||
const std::vector<unsigned char>& data, const uint256& hash)
|
const std::vector<unsigned char>& data, const uint256& hash)
|
||||||
{ // return: false = already in cache, true = added to cache
|
{ // return: false = already in cache, true = added to cache
|
||||||
if (!theApp->getHashNodeLDB())
|
if (!theApp->getHashNodeLDB())
|
||||||
{
|
|
||||||
cLog(lsWARNING) << "HOS: no db";
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
if (mCache.touch(hash))
|
if (mCache.touch(hash))
|
||||||
{
|
|
||||||
cLog(lsTRACE) << "HOS: " << hash << " store: incache";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
#ifdef PARANOID
|
||||||
assert(hash == Serializer::getSHA512Half(data));
|
assert(hash == Serializer::getSHA512Half(data));
|
||||||
|
#endif
|
||||||
|
|
||||||
HashedObject::pointer object = boost::make_shared<HashedObject>(type, index, data, hash);
|
HashedObject::pointer object = boost::make_shared<HashedObject>(type, index, data, hash);
|
||||||
if (!mCache.canonicalize(hash, object))
|
if (!mCache.canonicalize(hash, object))
|
||||||
@@ -133,23 +139,20 @@ void HashedObjectStore::bulkWriteLevelDB()
|
|||||||
HashedObject::pointer HashedObjectStore::retrieveLevelDB(const uint256& hash)
|
HashedObject::pointer HashedObjectStore::retrieveLevelDB(const uint256& hash)
|
||||||
{
|
{
|
||||||
HashedObject::pointer obj = mCache.fetch(hash);
|
HashedObject::pointer obj = mCache.fetch(hash);
|
||||||
if (obj || mNegativeCache.isPresent(hash))
|
if (obj || mNegativeCache.isPresent(hash) || !theApp || !theApp->getHashNodeLDB())
|
||||||
return obj;
|
return obj;
|
||||||
|
|
||||||
if (!theApp || !theApp->getHashNodeLDB())
|
|
||||||
{
|
|
||||||
cLog(lsWARNING) << "HOS: no db";
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadEvent::autoptr event(theApp->getJobQueue().getLoadEventAP(jtHO_READ, "HOS::retrieve"));
|
|
||||||
std::string sData;
|
std::string sData;
|
||||||
leveldb::Status st = theApp->getHashNodeLDB()->Get(leveldb::ReadOptions(),
|
|
||||||
leveldb::Slice(reinterpret_cast<const char *>(hash.begin()), hash.size()), &sData);
|
|
||||||
if (!st.ok())
|
|
||||||
{
|
{
|
||||||
assert(st.IsNotFound());
|
LoadEvent::autoptr event(theApp->getJobQueue().getLoadEventAP(jtHO_READ, "HOS::retrieve"));
|
||||||
return obj;
|
leveldb::Status st = theApp->getHashNodeLDB()->Get(leveldb::ReadOptions(),
|
||||||
|
leveldb::Slice(reinterpret_cast<const char *>(hash.begin()), hash.size()), &sData);
|
||||||
|
if (!st.ok())
|
||||||
|
{
|
||||||
|
assert(st.IsNotFound());
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned char* bufPtr = reinterpret_cast<const unsigned char*>(&sData[0]);
|
const unsigned char* bufPtr = reinterpret_cast<const unsigned char*>(&sData[0]);
|
||||||
@@ -200,16 +203,6 @@ bool HashedObjectStore::storeSQLite(HashedObjectType type, uint32 index,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HashedObjectStore::waitWrite()
|
|
||||||
{
|
|
||||||
if (mLevelDB)
|
|
||||||
return;
|
|
||||||
boost::mutex::scoped_lock sl(mWriteMutex);
|
|
||||||
int gen = mWriteGeneration;
|
|
||||||
while (mWritePending && (mWriteGeneration == gen))
|
|
||||||
mWriteCondition.wait(sl);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HashedObjectStore::bulkWriteSQLite()
|
void HashedObjectStore::bulkWriteSQLite()
|
||||||
{
|
{
|
||||||
assert(!mLevelDB);
|
assert(!mLevelDB);
|
||||||
|
|||||||
Reference in New Issue
Block a user