mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-29 18:10:34 +00:00
Relational DB interface
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/app/misc/NetworkOPs.h>
|
||||
#include <ripple/app/rdb/RelationalDBInterface_shards.h>
|
||||
#include <ripple/basics/Archive.h>
|
||||
#include <ripple/basics/BasicConfig.h>
|
||||
#include <ripple/core/ConfigSections.h>
|
||||
@@ -92,7 +93,7 @@ ShardArchiveHandler::init()
|
||||
{
|
||||
std::lock_guard lock(m_);
|
||||
|
||||
if (process_ || downloader_ != nullptr || sqliteDB_ != nullptr)
|
||||
if (process_ || downloader_ != nullptr || sqlDB_ != nullptr)
|
||||
{
|
||||
JLOG(j_.warn()) << "Archives already being processed";
|
||||
return false;
|
||||
@@ -115,11 +116,7 @@ ShardArchiveHandler::init()
|
||||
{
|
||||
create_directories(downloadDir_);
|
||||
|
||||
sqliteDB_ = std::make_unique<DatabaseCon>(
|
||||
downloadDir_,
|
||||
stateDBName,
|
||||
DownloaderDBPragma,
|
||||
ShardArchiveHandlerDBInit);
|
||||
sqlDB_ = makeArchiveDB(downloadDir_, stateDBName);
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
@@ -144,31 +141,20 @@ ShardArchiveHandler::initFromDB(std::lock_guard<std::mutex> const& lock)
|
||||
exists(downloadDir_ / stateDBName) &&
|
||||
is_regular_file(downloadDir_ / stateDBName));
|
||||
|
||||
sqliteDB_ = std::make_unique<DatabaseCon>(
|
||||
downloadDir_,
|
||||
stateDBName,
|
||||
DownloaderDBPragma,
|
||||
ShardArchiveHandlerDBInit);
|
||||
sqlDB_ = makeArchiveDB(downloadDir_, stateDBName);
|
||||
|
||||
auto& session{sqliteDB_->getSession()};
|
||||
|
||||
soci::rowset<soci::row> rs =
|
||||
(session.prepare << "SELECT * FROM State;");
|
||||
|
||||
for (auto it = rs.begin(); it != rs.end(); ++it)
|
||||
{
|
||||
readArchiveDB(*sqlDB_, [&](std::string const& url_, int state) {
|
||||
parsedURL url;
|
||||
|
||||
if (!parseUrl(url, it->get<std::string>(1)))
|
||||
if (!parseUrl(url, url_))
|
||||
{
|
||||
JLOG(j_.error())
|
||||
<< "Failed to parse url: " << it->get<std::string>(1);
|
||||
JLOG(j_.error()) << "Failed to parse url: " << url_;
|
||||
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
add(it->get<int>(0), std::move(url), lock);
|
||||
}
|
||||
add(state, std::move(url), lock);
|
||||
});
|
||||
|
||||
// Failed to load anything
|
||||
// from the state database.
|
||||
@@ -223,10 +209,7 @@ ShardArchiveHandler::add(
|
||||
if (!add(shardIndex, std::forward<parsedURL>(url.first), lock))
|
||||
return false;
|
||||
|
||||
auto& session{sqliteDB_->getSession()};
|
||||
|
||||
session << "INSERT INTO State VALUES (:index, :url);",
|
||||
soci::use(shardIndex), soci::use(url.second);
|
||||
insertArchiveDB(*sqlDB_, shardIndex, url.second);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -537,10 +520,7 @@ ShardArchiveHandler::remove(std::lock_guard<std::mutex> const&)
|
||||
app_.getShardStore()->removePreShard(shardIndex);
|
||||
archives_.erase(shardIndex);
|
||||
|
||||
auto& session{sqliteDB_->getSession()};
|
||||
|
||||
session << "DELETE FROM State WHERE ShardIndex = :index;",
|
||||
soci::use(shardIndex);
|
||||
deleteFromArchiveDB(*sqlDB_, shardIndex);
|
||||
|
||||
auto const dstDir{downloadDir_ / std::to_string(shardIndex)};
|
||||
try
|
||||
@@ -561,13 +541,9 @@ ShardArchiveHandler::doRelease(std::lock_guard<std::mutex> const&)
|
||||
app_.getShardStore()->removePreShard(ar.first);
|
||||
archives_.clear();
|
||||
|
||||
{
|
||||
auto& session{sqliteDB_->getSession()};
|
||||
dropArchiveDB(*sqlDB_);
|
||||
|
||||
session << "DROP TABLE State;";
|
||||
}
|
||||
|
||||
sqliteDB_.reset();
|
||||
sqlDB_.reset();
|
||||
|
||||
// Remove temp root download directory
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user