Inject journals:

Calls to WriteLog are replaced with injected journals
This commit is contained in:
seelabs
2015-09-19 11:06:12 -07:00
committed by Vinnie Falco
parent df6ac8f7f5
commit 92b2ca70b7
131 changed files with 1336 additions and 1076 deletions

View File

@@ -118,7 +118,7 @@ countSectionEntries (IniFileSections& secSource, std::string const& strSection)
}
bool getSingleSection (IniFileSections& secSource,
std::string const& strSection, std::string& strValue)
std::string const& strSection, std::string& strValue, beast::Journal j)
{
IniFileSections::mapped_type* pmtEntries =
getIniFileSection (secSource, strSection);
@@ -130,9 +130,9 @@ bool getSingleSection (IniFileSections& secSource,
}
else if (pmtEntries)
{
WriteLog (lsWARNING, parseIniFile) << boost::str (boost::format ("Section [%s]: requires 1 line not %d lines.")
% strSection
% pmtEntries->size ());
JLOG (j.warning) << boost::str (
boost::format ("Section [%s]: requires 1 line not %d lines.") %
strSection % pmtEntries->size ());
}
return bSingle;
@@ -359,7 +359,7 @@ void Config::loadFromString (std::string const& fileContents)
{
std::string dbPath;
if (getSingleSection (secConfig, "database_path", dbPath))
if (getSingleSection (secConfig, "database_path", dbPath, j_))
{
boost::filesystem::path p(dbPath);
legacy("database_path",
@@ -367,16 +367,16 @@ void Config::loadFromString (std::string const& fileContents)
}
}
(void) getSingleSection (secConfig, SECTION_VALIDATORS_SITE, VALIDATORS_SITE);
(void) getSingleSection (secConfig, SECTION_VALIDATORS_SITE, VALIDATORS_SITE, j_);
std::string strTemp;
if (getSingleSection (secConfig, SECTION_PEER_PRIVATE, strTemp))
if (getSingleSection (secConfig, SECTION_PEER_PRIVATE, strTemp, j_))
PEER_PRIVATE = beast::lexicalCastThrow <bool> (strTemp);
if (getSingleSection (secConfig, SECTION_PEERS_MAX, strTemp))
if (getSingleSection (secConfig, SECTION_PEERS_MAX, strTemp, j_))
PEERS_MAX = beast::lexicalCastThrow <int> (strTemp);
if (getSingleSection (secConfig, SECTION_NODE_SIZE, strTemp))
if (getSingleSection (secConfig, SECTION_NODE_SIZE, strTemp, j_))
{
if (strTemp == "tiny")
NODE_SIZE = 0;
@@ -399,19 +399,19 @@ void Config::loadFromString (std::string const& fileContents)
}
}
if (getSingleSection (secConfig, SECTION_ELB_SUPPORT, strTemp))
if (getSingleSection (secConfig, SECTION_ELB_SUPPORT, strTemp, j_))
ELB_SUPPORT = beast::lexicalCastThrow <bool> (strTemp);
if (getSingleSection (secConfig, SECTION_WEBSOCKET_PING_FREQ, strTemp))
if (getSingleSection (secConfig, SECTION_WEBSOCKET_PING_FREQ, strTemp, j_))
WEBSOCKET_PING_FREQ = beast::lexicalCastThrow <int> (strTemp);
getSingleSection (secConfig, SECTION_SSL_VERIFY_FILE, SSL_VERIFY_FILE);
getSingleSection (secConfig, SECTION_SSL_VERIFY_DIR, SSL_VERIFY_DIR);
getSingleSection (secConfig, SECTION_SSL_VERIFY_FILE, SSL_VERIFY_FILE, j_);
getSingleSection (secConfig, SECTION_SSL_VERIFY_DIR, SSL_VERIFY_DIR, j_);
if (getSingleSection (secConfig, SECTION_SSL_VERIFY, strTemp))
if (getSingleSection (secConfig, SECTION_SSL_VERIFY, strTemp, j_))
SSL_VERIFY = beast::lexicalCastThrow <bool> (strTemp);
if (getSingleSection (secConfig, SECTION_VALIDATION_SEED, strTemp))
if (getSingleSection (secConfig, SECTION_VALIDATION_SEED, strTemp, j_))
{
VALIDATION_SEED.setSeedGeneric (strTemp);
@@ -422,7 +422,7 @@ void Config::loadFromString (std::string const& fileContents)
}
}
if (getSingleSection (secConfig, SECTION_NODE_SEED, strTemp))
if (getSingleSection (secConfig, SECTION_NODE_SEED, strTemp, j_))
{
NODE_SEED.setSeedGeneric (strTemp);
@@ -433,25 +433,25 @@ void Config::loadFromString (std::string const& fileContents)
}
}
if (getSingleSection (secConfig, SECTION_NETWORK_QUORUM, strTemp))
if (getSingleSection (secConfig, SECTION_NETWORK_QUORUM, strTemp, j_))
NETWORK_QUORUM = beast::lexicalCastThrow <std::size_t> (strTemp);
if (getSingleSection (secConfig, SECTION_VALIDATION_QUORUM, strTemp))
if (getSingleSection (secConfig, SECTION_VALIDATION_QUORUM, strTemp, j_))
VALIDATION_QUORUM = std::max (0, beast::lexicalCastThrow <int> (strTemp));
if (getSingleSection (secConfig, SECTION_FEE_ACCOUNT_RESERVE, strTemp))
if (getSingleSection (secConfig, SECTION_FEE_ACCOUNT_RESERVE, strTemp, j_))
FEE_ACCOUNT_RESERVE = beast::lexicalCastThrow <std::uint64_t> (strTemp);
if (getSingleSection (secConfig, SECTION_FEE_OWNER_RESERVE, strTemp))
if (getSingleSection (secConfig, SECTION_FEE_OWNER_RESERVE, strTemp, j_))
FEE_OWNER_RESERVE = beast::lexicalCastThrow <std::uint64_t> (strTemp);
if (getSingleSection (secConfig, SECTION_FEE_OFFER, strTemp))
if (getSingleSection (secConfig, SECTION_FEE_OFFER, strTemp, j_))
FEE_OFFER = beast::lexicalCastThrow <int> (strTemp);
if (getSingleSection (secConfig, SECTION_FEE_DEFAULT, strTemp))
if (getSingleSection (secConfig, SECTION_FEE_DEFAULT, strTemp, j_))
FEE_DEFAULT = beast::lexicalCastThrow <int> (strTemp);
if (getSingleSection (secConfig, SECTION_LEDGER_HISTORY, strTemp))
if (getSingleSection (secConfig, SECTION_LEDGER_HISTORY, strTemp, j_))
{
boost::to_lower (strTemp);
@@ -463,7 +463,7 @@ void Config::loadFromString (std::string const& fileContents)
LEDGER_HISTORY = beast::lexicalCastThrow <std::uint32_t> (strTemp);
}
if (getSingleSection (secConfig, SECTION_FETCH_DEPTH, strTemp))
if (getSingleSection (secConfig, SECTION_FETCH_DEPTH, strTemp, j_))
{
boost::to_lower (strTemp);
@@ -478,21 +478,21 @@ void Config::loadFromString (std::string const& fileContents)
FETCH_DEPTH = 10;
}
if (getSingleSection (secConfig, SECTION_PATH_SEARCH_OLD, strTemp))
if (getSingleSection (secConfig, SECTION_PATH_SEARCH_OLD, strTemp, j_))
PATH_SEARCH_OLD = beast::lexicalCastThrow <int> (strTemp);
if (getSingleSection (secConfig, SECTION_PATH_SEARCH, strTemp))
if (getSingleSection (secConfig, SECTION_PATH_SEARCH, strTemp, j_))
PATH_SEARCH = beast::lexicalCastThrow <int> (strTemp);
if (getSingleSection (secConfig, SECTION_PATH_SEARCH_FAST, strTemp))
if (getSingleSection (secConfig, SECTION_PATH_SEARCH_FAST, strTemp, j_))
PATH_SEARCH_FAST = beast::lexicalCastThrow <int> (strTemp);
if (getSingleSection (secConfig, SECTION_PATH_SEARCH_MAX, strTemp))
if (getSingleSection (secConfig, SECTION_PATH_SEARCH_MAX, strTemp, j_))
PATH_SEARCH_MAX = beast::lexicalCastThrow <int> (strTemp);
if (getSingleSection (secConfig, SECTION_VALIDATORS_FILE, strTemp))
if (getSingleSection (secConfig, SECTION_VALIDATORS_FILE, strTemp, j_))
{
VALIDATORS_FILE = strTemp;
}
if (getSingleSection (secConfig, SECTION_DEBUG_LOGFILE, strTemp))
if (getSingleSection (secConfig, SECTION_DEBUG_LOGFILE, strTemp, j_))
DEBUG_LOGFILE = strTemp;
{

View File

@@ -65,11 +65,11 @@ DatabaseCon::Setup setup_DatabaseCon (Config const& c)
return setup;
}
void DatabaseCon::setupCheckpointing (JobQueue* q)
void DatabaseCon::setupCheckpointing (JobQueue* q, Logs& l)
{
if (! q)
throw std::logic_error ("No JobQueue");
checkpointer_ = makeCheckpointer (session_, *q);
checkpointer_ = makeCheckpointer (session_, *q, l);
}
} // ripple

View File

@@ -72,11 +72,11 @@ public:
//--------------------------------------------------------------------------
JobQueueImp (beast::insight::Collector::ptr const& collector,
Stoppable& parent, beast::Journal journal)
Stoppable& parent, beast::Journal journal, Logs& logs)
: JobQueue ("JobQueue", parent)
, m_journal (journal)
, m_lastJob (0)
, m_invalidJobData (getJobTypes ().getInvalid (), collector)
, m_invalidJobData (getJobTypes ().getInvalid (), collector, logs)
, m_processCount (0)
, m_workers (*this, "JobQueue", 0)
, m_cancelCallback (std::bind (&Stoppable::isStopping, this))
@@ -96,7 +96,7 @@ public:
// And create dynamic information for all jobs
auto const result (m_jobData.emplace (std::piecewise_construct,
std::forward_as_tuple (jt.type ()),
std::forward_as_tuple (jt, m_collector)));
std::forward_as_tuple (jt, m_collector, logs)));
assert (result.second == true);
(void) result.second;
}
@@ -695,9 +695,9 @@ JobQueue::JobQueue (char const* name, Stoppable& parent)
std::unique_ptr <JobQueue> make_JobQueue (
beast::insight::Collector::ptr const& collector,
beast::Stoppable& parent, beast::Journal journal)
beast::Stoppable& parent, beast::Journal journal, Logs& logs)
{
return std::make_unique <JobQueueImp> (collector, parent, journal);
return std::make_unique <JobQueueImp> (collector, parent, journal, logs);
}
}

View File

@@ -45,7 +45,7 @@ LoadMonitor::Stats::Stats()
//------------------------------------------------------------------------------
LoadMonitor::LoadMonitor ()
LoadMonitor::LoadMonitor (beast::Journal j)
: mCounts (0)
, mLatencyEvents (0)
, mLatencyMSAvg (0)
@@ -53,6 +53,7 @@ LoadMonitor::LoadMonitor ()
, mTargetLatencyAvg (0)
, mTargetLatencyPk (0)
, mLastUpdate (UptimeTimer::getInstance ().getElapsedSeconds ())
, j_ (j)
{
}
@@ -146,7 +147,8 @@ void LoadMonitor::addLoadSample (LoadEvent const& sample)
if (latency.inSeconds() > 0.5)
{
WriteLog ((latency.inSeconds() > 1.0) ? lsWARNING : lsINFO, LoadMonitor)
auto& mj = latency.inSeconds() > 1.0 ? j_.warning : j_.info;
JLOG (mj)
<< "Job: " << name << " ExecutionTime: " << printElapsed (sample.getSecondsRunning()) <<
" WaitingTime: " << printElapsed (sample.getSecondsWaiting());
}

View File

@@ -185,8 +185,8 @@ namespace {
class WALCheckpointer : public Checkpointer
{
public:
WALCheckpointer (sqlite_api::sqlite3& conn, JobQueue& q)
: conn_ (conn), jobQueue_ (q)
WALCheckpointer (sqlite_api::sqlite3& conn, JobQueue& q, Logs& logs)
: conn_ (conn), jobQueue_ (q), j_ (logs.journal ("WALCheckpointer"))
{
sqlite_api::sqlite3_wal_hook (&conn_, &sqliteWALHook, this);
}
@@ -199,6 +199,7 @@ private:
JobQueue& jobQueue_;
bool running_ = false;
beast::Journal j_;
static
int sqliteWALHook (
@@ -235,13 +236,13 @@ private:
auto fname = sqlite3_db_filename (&conn_, "main");
if (ret != SQLITE_OK)
{
WriteLog ((ret == SQLITE_LOCKED) ? lsTRACE : lsWARNING,
WALCheckpointer)
auto& jm = (ret == SQLITE_LOCKED) ? j_.trace : j_.warning;
JLOG (jm)
<< "WAL(" << fname << "): error " << ret;
}
else
{
WriteLog (lsTRACE, WALCheckpointer)
JLOG (j_.trace)
<< "WAL(" << fname << "): frames="
<< log << ", written=" << ckpt;
}
@@ -254,10 +255,10 @@ private:
} // namespace
std::unique_ptr <Checkpointer> makeCheckpointer (
soci::session& session, JobQueue& queue)
soci::session& session, JobQueue& queue, Logs& logs)
{
if (auto conn = getConnection (session))
return std::make_unique <WALCheckpointer> (*conn, queue);
return std::make_unique <WALCheckpointer> (*conn, queue, logs);
return {};
}