mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 22:45: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
|
#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 << "\".";
|
cLog(lsWARNING) << "Hashed object import from \"" << file << "\".";
|
||||||
UPTR_T<Database> importDB(new SqliteDatabase(file.c_str()));
|
UPTR_T<Database> importDB(new SqliteDatabase(file.c_str()));
|
||||||
importDB->connect();
|
importDB->connect();
|
||||||
|
|
||||||
|
leveldb::DB* db = theApp->getHashNodeLDB();
|
||||||
|
leveldb::WriteOptions wo;
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
SQL_FOREACH(importDB, "SELECT * FROM CommittedObjects;")
|
SQL_FOREACH(importDB, "SELECT * FROM CommittedObjects;")
|
||||||
@@ -386,17 +389,19 @@ int HashedObjectStore::import(const std::string& file, bool checkHashes)
|
|||||||
}
|
}
|
||||||
else
|
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;
|
std::string type;
|
||||||
importDB->getStr("ObjType", 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;
|
HashedObjectType htype = hotUNKNOWN;
|
||||||
switch (type[0])
|
switch (type[0])
|
||||||
{
|
{
|
||||||
@@ -408,17 +413,17 @@ int HashedObjectStore::import(const std::string& file, bool checkHashes)
|
|||||||
assert(false);
|
assert(false);
|
||||||
cLog(lsERROR) << "Invalid hashed object";
|
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
|
cLog(lsFATAL) << "Failed to store hash node";
|
||||||
<< " " << Serializer::getSHA512Half(data);
|
assert(false);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
store(htype, index, data, hash);
|
|
||||||
++count;
|
|
||||||
}
|
}
|
||||||
|
++count;
|
||||||
}
|
}
|
||||||
if ((count % 10000) == 0)
|
if ((count % 10000) == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public:
|
|||||||
void tune(int size, int age);
|
void tune(int size, int age);
|
||||||
void sweep() { mCache.sweep(); mNegativeCache.sweep(); }
|
void sweep() { mCache.sweep(); mNegativeCache.sweep(); }
|
||||||
|
|
||||||
int import(const std::string& fileName, bool checkHashes);
|
int import(const std::string& fileName);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ void Application::updateTables(bool ldbImport)
|
|||||||
if (theConfig.LDB_IMPORT)
|
if (theConfig.LDB_IMPORT)
|
||||||
{
|
{
|
||||||
Log(lsWARNING) << "Importing SQLite -> LevelDB";
|
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";
|
Log(lsWARNING) << "Remove or remname the hashnode.db file";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user