Add config "ledger_history_index" functionality (RIPD-559)

This commit is contained in:
Miguel Portilla
2015-01-07 18:19:55 -05:00
committed by Vinnie Falco
parent 94629edb9b
commit 8b848770dc
8 changed files with 56 additions and 29 deletions

View File

@@ -481,6 +481,13 @@
# #
# #
# #
# [ledger_history_index]
#
# If set to greater than 0, the index number of the earliest ledger to
# acquire.
#
#
#
# [fetch_depth] # [fetch_depth]
# #
# The number of past ledgers to serve to other peers that request historical # The number of past ledgers to serve to other peers that request historical

View File

@@ -103,13 +103,14 @@ public:
// How much history do we want to keep // How much history do we want to keep
std::uint32_t const ledger_history_; std::uint32_t const ledger_history_;
// Acquire past ledgers down to this ledger index
std::uint32_t const ledger_history_index_;
int const ledger_fetch_size_; int const ledger_fetch_size_;
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
LedgerMasterImp (bool standalone, std::uint32_t fetch_depth, LedgerMasterImp (Config const& config, Stoppable& parent,
std::uint32_t ledger_history, int ledger_fetch_size, Stoppable& parent,
beast::insight::Collector::ptr const& collector, beast::Journal journal) beast::insight::Collector::ptr const& collector, beast::Journal journal)
: LedgerMaster (parent) : LedgerMaster (parent)
, m_journal (journal) , m_journal (journal)
@@ -129,11 +130,21 @@ public:
, mValidLedgerClose (0) , mValidLedgerClose (0)
, mValidLedgerSeq (0) , mValidLedgerSeq (0)
, mBuildingLedgerSeq (0) , mBuildingLedgerSeq (0)
, standalone_ (standalone) , standalone_ (config.RUN_STANDALONE)
, fetch_depth_ (getApp().getSHAMapStore().clampFetchDepth (fetch_depth)) , fetch_depth_ (getApp ().getSHAMapStore ().clampFetchDepth (config.FETCH_DEPTH))
, ledger_history_ (ledger_history) , ledger_history_ (config.LEDGER_HISTORY)
, ledger_fetch_size_ (ledger_fetch_size) , ledger_history_index_ (config.LEDGER_HISTORY_INDEX)
, ledger_fetch_size_ (config.getSize (siLedgerFetch))
{ {
if (ledger_history_index_ != 0 &&
config.nodeDatabase["online_delete"].isNotEmpty () &&
config.nodeDatabase["online_delete"].getIntValue () > 0)
{
std::stringstream ss;
ss << "[node_db] online_delete option and [ledger_history_index]"
" cannot be configured at the same time.";
throw std::runtime_error (ss.str ());
}
} }
~LedgerMasterImp () ~LedgerMasterImp ()
@@ -947,7 +958,8 @@ public:
} }
WriteLog (lsTRACE, LedgerMaster) << "tryAdvance discovered missing " << missing; WriteLog (lsTRACE, LedgerMaster) << "tryAdvance discovered missing " << missing;
if ((missing != RangeSet::absent) && (missing > 0) && if ((missing != RangeSet::absent) && (missing > 0) &&
shouldAcquire(mValidLedgerSeq, ledger_history_, missing) && shouldAcquire (mValidLedgerSeq, ledger_history_,
ledger_history_index_, missing) &&
((mFillInProgress == 0) || (missing > mFillInProgress))) ((mFillInProgress == 0) || (missing > mFillInProgress)))
{ {
WriteLog (lsTRACE, LedgerMaster) << "advanceThread should acquire"; WriteLog (lsTRACE, LedgerMaster) << "advanceThread should acquire";
@@ -1546,27 +1558,27 @@ LedgerMaster::~LedgerMaster ()
{ {
} }
bool LedgerMaster::shouldAcquire ( bool LedgerMaster::shouldAcquire (std::uint32_t currentLedger,
std::uint32_t currentLedger, std::uint32_t ledgerHistory, std::uint32_t candidateLedger) std::uint32_t ledgerHistory, std::uint32_t ledgerHistoryIndex,
std::uint32_t candidateLedger)
{ {
bool ret; bool ret (candidateLedger >= currentLedger ||
(ledgerHistoryIndex != 0 && candidateLedger >= ledgerHistoryIndex) ||
(currentLedger - candidateLedger) <= ledgerHistory);
if (candidateLedger >= currentLedger) WriteLog (lsTRACE, LedgerMaster)
ret = true; << "Missing ledger "
else << candidateLedger
ret = (currentLedger - candidateLedger) <= ledgerHistory; << (ret ? " should" : " should NOT")
<< " be acquired";
WriteLog (lsTRACE, LedgerMaster) << "Missing ledger " << candidateLedger << (ret ? " should" : " should NOT") << " be acquired";
return ret; return ret;
} }
std::unique_ptr <LedgerMaster> std::unique_ptr <LedgerMaster>
make_LedgerMaster (bool standalone, std::uint32_t fetch_depth, make_LedgerMaster (Config const& config, beast::Stoppable& parent,
std::uint32_t ledger_history, int ledger_fetch_size, beast::Stoppable& parent,
beast::insight::Collector::ptr const& collector, beast::Journal journal) beast::insight::Collector::ptr const& collector, beast::Journal journal)
{ {
return std::make_unique <LedgerMasterImp> (standalone, fetch_depth, return std::make_unique <LedgerMasterImp> (config, parent, collector, journal);
ledger_history, ledger_fetch_size, parent, collector, journal);
} }
} // ripple } // ripple

View File

@@ -23,6 +23,7 @@
#include <ripple/app/ledger/LedgerEntrySet.h> #include <ripple/app/ledger/LedgerEntrySet.h>
#include <ripple/basics/StringUtilities.h> #include <ripple/basics/StringUtilities.h>
#include <ripple/protocol/RippleLedgerHash.h> #include <ripple/protocol/RippleLedgerHash.h>
#include <ripple/core/Config.h>
#include <beast/insight/Collector.h> #include <beast/insight/Collector.h>
#include <beast/threads/Stoppable.h> #include <beast/threads/Stoppable.h>
#include <beast/threads/UnlockGuard.h> #include <beast/threads/UnlockGuard.h>
@@ -149,8 +150,9 @@ public:
virtual beast::PropertyStream::Source& getPropertySource () = 0; virtual beast::PropertyStream::Source& getPropertySource () = 0;
static bool shouldAcquire (std::uint32_t currentLedgerID, static bool shouldAcquire (std::uint32_t currentLedgerID,
std::uint32_t ledgerHistory, std::uint32_t targetLedger); std::uint32_t ledgerHistory, std::uint32_t ledgerHistoryIndex,
std::uint32_t targetLedger);
virtual void clearPriorLedgers (LedgerIndex seq) = 0; virtual void clearPriorLedgers (LedgerIndex seq) = 0;
@@ -158,8 +160,7 @@ public:
}; };
std::unique_ptr <LedgerMaster> std::unique_ptr <LedgerMaster>
make_LedgerMaster (bool standalone, std::uint32_t fetch_depth, make_LedgerMaster (Config const& config, beast::Stoppable& parent,
std::uint32_t ledger_history, int ledger_fetch_size, beast::Stoppable& parent,
beast::insight::Collector::ptr const& collector, beast::Journal journal); beast::insight::Collector::ptr const& collector, beast::Journal journal);
} // ripple } // ripple

View File

@@ -291,9 +291,7 @@ public:
, m_pathRequests (new PathRequests ( , m_pathRequests (new PathRequests (
m_logs.journal("PathRequest"), m_collectorManager->collector ())) m_logs.journal("PathRequest"), m_collectorManager->collector ()))
, m_ledgerMaster (make_LedgerMaster (getConfig ().RUN_STANDALONE, , m_ledgerMaster (make_LedgerMaster (getConfig (), *m_jobQueue,
getConfig ().FETCH_DEPTH, getConfig ().LEDGER_HISTORY,
getConfig ().getSize (siLedgerFetch), *m_jobQueue,
m_collectorManager->collector (), m_logs.journal("LedgerMaster"))) m_collectorManager->collector (), m_logs.journal("LedgerMaster")))
// VFALCO NOTE must come before NetworkOPs to prevent a crash due // VFALCO NOTE must come before NetworkOPs to prevent a crash due

View File

@@ -344,6 +344,7 @@ int run (int argc, char** argv)
{ {
getConfig ().RUN_STANDALONE = true; getConfig ().RUN_STANDALONE = true;
getConfig ().LEDGER_HISTORY = 0; getConfig ().LEDGER_HISTORY = 0;
getConfig ().LEDGER_HISTORY_INDEX = 0;
} }
} }

View File

@@ -291,6 +291,7 @@ public:
// Node storage configuration // Node storage configuration
std::uint32_t LEDGER_HISTORY; std::uint32_t LEDGER_HISTORY;
std::uint32_t LEDGER_HISTORY_INDEX;
std::uint32_t FETCH_DEPTH; std::uint32_t FETCH_DEPTH;
int NODE_SIZE; int NODE_SIZE;
@@ -310,7 +311,7 @@ public:
public: public:
Config (); Config ();
int getSize (SizedItemName); int getSize (SizedItemName) const;
void setup (std::string const& strConf, bool bQuiet); void setup (std::string const& strConf, bool bQuiet);
void load (); void load ();
}; };

View File

@@ -43,6 +43,7 @@ struct ConfigSection
#define SECTION_FEE_OWNER_RESERVE "fee_owner_reserve" #define SECTION_FEE_OWNER_RESERVE "fee_owner_reserve"
#define SECTION_FETCH_DEPTH "fetch_depth" #define SECTION_FETCH_DEPTH "fetch_depth"
#define SECTION_LEDGER_HISTORY "ledger_history" #define SECTION_LEDGER_HISTORY "ledger_history"
#define SECTION_LEDGER_HISTORY_INDEX "ledger_history_index"
#define SECTION_INSIGHT "insight" #define SECTION_INSIGHT "insight"
#define SECTION_IPS "ips" #define SECTION_IPS "ips"
#define SECTION_IPS_FIXED "ips_fixed" #define SECTION_IPS_FIXED "ips_fixed"

View File

@@ -249,6 +249,7 @@ Config::Config ()
FEE_CONTRACT_OPERATION = DEFAULT_FEE_OPERATION; FEE_CONTRACT_OPERATION = DEFAULT_FEE_OPERATION;
LEDGER_HISTORY = 256; LEDGER_HISTORY = 256;
LEDGER_HISTORY_INDEX = 0;
FETCH_DEPTH = 1000000000; FETCH_DEPTH = 1000000000;
// An explanation of these magical values would be nice. // An explanation of these magical values would be nice.
@@ -584,6 +585,11 @@ void Config::load ()
else else
LEDGER_HISTORY = beast::lexicalCastThrow <std::uint32_t> (strTemp); LEDGER_HISTORY = beast::lexicalCastThrow <std::uint32_t> (strTemp);
} }
if (getSingleSection(secConfig, SECTION_LEDGER_HISTORY_INDEX, strTemp))
{
LEDGER_HISTORY_INDEX = beast::lexicalCastThrow <std::uint32_t>(strTemp);
}
if (getSingleSection (secConfig, SECTION_FETCH_DEPTH, strTemp)) if (getSingleSection (secConfig, SECTION_FETCH_DEPTH, strTemp))
{ {
boost::to_lower (strTemp); boost::to_lower (strTemp);
@@ -628,7 +634,7 @@ void Config::load ()
} }
} }
int Config::getSize (SizedItemName item) int Config::getSize (SizedItemName item) const
{ {
SizedItem sizeTable[] = // tiny small medium large huge SizedItem sizeTable[] = // tiny small medium large huge
{ {