mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 14:35:52 +00:00
One more round of LeveDB import speedups.
This commit is contained in:
@@ -366,12 +366,15 @@ HashedObject::pointer HashedObjectStore::retrieveSQLite(const uint256& hash)
|
||||
|
||||
#ifdef USE_LEVELDB
|
||||
|
||||
int HashedObjectStore::import(const std::string& file, bool checkHashes)
|
||||
int HashedObjectStore::import(const std::string& file)
|
||||
{
|
||||
cLog(lsWARNING) << "Hashed object import from \"" << file << "\".";
|
||||
UPTR_T<Database> importDB(new SqliteDatabase(file.c_str()));
|
||||
importDB->connect();
|
||||
|
||||
leveldb::DB* db = theApp->getHashNodeLDB();
|
||||
leveldb::WriteOptions wo;
|
||||
|
||||
int count = 0;
|
||||
|
||||
SQL_FOREACH(importDB, "SELECT * FROM CommittedObjects;")
|
||||
@@ -386,17 +389,19 @@ int HashedObjectStore::import(const std::string& file, bool checkHashes)
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<unsigned char> data;
|
||||
std::vector<unsigned char> rawData;
|
||||
int size = importDB->getBinary("Object", NULL, 0);
|
||||
rawData.resize(9 + size);
|
||||
unsigned char* bufPtr = &rawData.front();
|
||||
|
||||
importDB->getBinary("Object", bufPtr + 9, size);
|
||||
|
||||
uint32 index = importDB->getBigInt("LedgerIndex");
|
||||
*reinterpret_cast<uint32*>(bufPtr + 0) = ntohl(index);
|
||||
*reinterpret_cast<uint32*>(bufPtr + 4) = ntohl(index);
|
||||
|
||||
std::string type;
|
||||
importDB->getStr("ObjType", type);
|
||||
uint32 index = importDB->getBigInt("LedgerIndex");
|
||||
|
||||
int size = importDB->getBinary("Object", NULL, 0);
|
||||
data.resize(size);
|
||||
importDB->getBinary("Object", &(data.front()), size);
|
||||
|
||||
assert(Serializer::getSHA512Half(data) == hash);
|
||||
|
||||
HashedObjectType htype = hotUNKNOWN;
|
||||
switch (type[0])
|
||||
{
|
||||
@@ -408,17 +413,17 @@ int HashedObjectStore::import(const std::string& file, bool checkHashes)
|
||||
assert(false);
|
||||
cLog(lsERROR) << "Invalid hashed object";
|
||||
}
|
||||
*(bufPtr + 8) = static_cast<unsigned char>(htype);
|
||||
|
||||
if (checkHashes && Serializer::getSHA512Half(data) != hash)
|
||||
leveldb::Status st = db->Put(wo,
|
||||
leveldb::Slice(reinterpret_cast<const char *>(hash.begin()), hash.size()),
|
||||
leveldb::Slice(reinterpret_cast<const char *>(bufPtr), rawData.size()));
|
||||
if (!st.ok())
|
||||
{
|
||||
cLog(lsWARNING) << "Hash mismatch in import table " << hash
|
||||
<< " " << Serializer::getSHA512Half(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
store(htype, index, data, hash);
|
||||
++count;
|
||||
cLog(lsFATAL) << "Failed to store hash node";
|
||||
assert(false);
|
||||
}
|
||||
++count;
|
||||
}
|
||||
if ((count % 10000) == 0)
|
||||
{
|
||||
|
||||
@@ -100,7 +100,7 @@ public:
|
||||
void tune(int size, int age);
|
||||
void sweep() { mCache.sweep(); mNegativeCache.sweep(); }
|
||||
|
||||
int import(const std::string& fileName, bool checkHashes);
|
||||
int import(const std::string& fileName);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -116,7 +116,7 @@ void Application::updateTables(bool ldbImport)
|
||||
if (theConfig.LDB_IMPORT)
|
||||
{
|
||||
Log(lsWARNING) << "Importing SQLite -> LevelDB";
|
||||
theApp->getHashedObjectStore().import(hashPath.string(), false);
|
||||
theApp->getHashedObjectStore().import(hashPath.string());
|
||||
Log(lsWARNING) << "Remove or remname the hashnode.db file";
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user