Make ShardArchiveHandler downloads more resilient:

* Make ShardArchiveHandler a singleton.
* Add state database for ShardArchiveHandler.
* Use temporary database for SSLHTTPDownloader downloads.
* Make ShardArchiveHandler a Stoppable class.
* Automatically resume interrupted downloads at server start.
This commit is contained in:
Devon White
2019-12-03 13:56:19 -05:00
committed by manojsdoshi
parent cc452dfa9b
commit 905a97e0aa
21 changed files with 2308 additions and 209 deletions

View File

@@ -64,6 +64,7 @@
#include <ripple/rpc/impl/RPCHelpers.h>
#include <ripple/beast/asio/io_latency_probe.h>
#include <ripple/beast/core/LexicalCast.h>
#include <ripple/rpc/ShardArchiveHandler.h>
#include <boost/algorithm/string/predicate.hpp>
#include <ripple/app/main/GRPCServer.h>
@@ -1610,6 +1611,53 @@ bool ApplicationImp::setup()
}
}
if (shardStore_)
{
using namespace boost::filesystem;
auto stateDb(
RPC::ShardArchiveHandler::getDownloadDirectory(*config_)
/ stateDBName);
try
{
if (exists(stateDb) &&
is_regular_file(stateDb) &&
!RPC::ShardArchiveHandler::hasInstance())
{
auto handler = RPC::ShardArchiveHandler::recoverInstance(
*this,
*m_jobQueue);
assert(handler);
if (!handler->initFromDB())
{
JLOG(m_journal.fatal())
<< "Failed to initialize ShardArchiveHandler.";
return false;
}
if (!handler->start())
{
JLOG(m_journal.fatal())
<< "Failed to start ShardArchiveHandler.";
return false;
}
}
}
catch(std::exception const& e)
{
JLOG(m_journal.fatal())
<< "Exception when starting ShardArchiveHandler from "
"state database: " << e.what();
return false;
}
}
return true;
}