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

@@ -29,6 +29,7 @@
#include <beast/net/IPEndpoint.h>
#include <beast/module/core/files/File.h>
#include <beast/utility/ci_char_traits.h>
#include <beast/utility/Journal.h>
#include <boost/asio/ip/tcp.hpp> // VFALCO FIX: This include should not be here
#include <boost/filesystem.hpp> // VFALCO FIX: This include should not be here
#include <boost/lexical_cast.hpp>
@@ -47,7 +48,7 @@ parseIniFile (std::string const& strInput, const bool bTrim);
bool
getSingleSection (IniFileSections& secSource,
std::string const& strSection, std::string& strValue);
std::string const& strSection, std::string& strValue, beast::Journal j);
int
countSectionEntries (IniFileSections& secSource, std::string const& strSection);
@@ -131,6 +132,7 @@ private:
boost::filesystem::path DEBUG_LOGFILE;
void load ();
beast::Journal j_;
public:
//--------------------------------------------------------------------------

View File

@@ -99,7 +99,7 @@ public:
return LockedSociSession (&session_, lock_);
}
void setupCheckpointing (JobQueue*);
void setupCheckpointing (JobQueue*, Logs&);
private:
LockedSociSession::mutex lock_;

View File

@@ -30,6 +30,8 @@
namespace ripple {
class Logs;
class JobQueue : public beast::Stoppable
{
protected:
@@ -82,7 +84,7 @@ public:
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);
}

View File

@@ -20,6 +20,7 @@
#ifndef RIPPLE_CORE_JOBTYPEDATA_H_INCLUDED
#define RIPPLE_CORE_JOBTYPEDATA_H_INCLUDED
#include <ripple/basics/Log.h>
#include <ripple/core/JobTypeInfo.h>
namespace ripple
@@ -50,9 +51,10 @@ public:
beast::insight::Event dequeue;
beast::insight::Event execute;
explicit JobTypeData (JobTypeInfo const& info_,
beast::insight::Collector::ptr const& collector) noexcept
: m_collector (collector)
JobTypeData (JobTypeInfo const& info_,
beast::insight::Collector::ptr const& collector, Logs& logs) noexcept
: m_load (logs.journal ("LoadMonitor"))
, m_collector (collector)
, info (info_)
, waiting (0)
, running (0)

View File

@@ -21,6 +21,7 @@
#define RIPPLE_CORE_LOADMONITOR_H_INCLUDED
#include <ripple/core/LoadEvent.h>
#include <beast/utility/Journal.h>
#include <chrono>
#include <mutex>
@@ -33,7 +34,8 @@ namespace ripple {
class LoadMonitor
{
public:
LoadMonitor ();
explicit
LoadMonitor (beast::Journal j);
void addCount ();
@@ -78,6 +80,7 @@ private:
std::uint64_t mTargetLatencyAvg;
std::uint64_t mTargetLatencyPk;
int mLastUpdate;
beast::Journal j_;
};
} // ripple

View File

@@ -128,7 +128,7 @@ class Checkpointer
The Checkpointer contains references to the session and job queue
and so must outlive them both.
*/
std::unique_ptr <Checkpointer> makeCheckpointer (soci::session&, JobQueue&);
std::unique_ptr <Checkpointer> makeCheckpointer (soci::session&, JobQueue&, Logs&);
} // ripple

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 {};
}