Tidy up Validators logging

This commit is contained in:
Vinnie Falco
2013-11-15 13:19:10 -08:00
parent 616a514c4d
commit 580d179dd0
11 changed files with 112 additions and 82 deletions

View File

@@ -45,12 +45,12 @@ public:
virtual ~Source () { }
/** The name of the source, used in diagnostic output. */
virtual String name () = 0;
virtual std::string to_string () const = 0;
/** An identifier that uniquely describes the source.
This is used for identification in the database.
*/
virtual String uniqueID () = 0;
virtual String uniqueID () const = 0;
/** A string that is used to recreate the source from the database entry. */
virtual String createParam () = 0;
@@ -77,6 +77,8 @@ public:
/** @} */
};
std::ostream& operator<< (std::ostream& os, Source const& v);
}
}

View File

@@ -66,6 +66,16 @@ struct Count
return 0;
}
/** Output to PropertyStream. */
void onWrite (PropertyStream::Map& map)
{
map["received"] = received;
map["expected"] = expected;
map["closed"] = closed;
map["percent"] = percent ();
map["percent_orphan"] = percent_orphaned();
}
std::size_t received; // Count of validations without a closed ledger
std::size_t expected; // Count of closed ledgers without a validation
std::size_t closed; // Number of validations with closed ledgers

View File

@@ -51,6 +51,10 @@ public:
Store& m_store;
Journal m_journal;
// A small integer assigned to each closed ledger
//
int m_ledgerID;
// The chosen set of trusted validators (formerly the "UNL")
//
bool m_rebuildChosenList;
@@ -87,6 +91,7 @@ public:
explicit Logic (Store& store, Journal journal = Journal ())
: m_store (store)
, m_journal (journal)
, m_ledgerID (0)
, m_rebuildChosenList (false)
, m_seenValidations (seenValidationsCacheSize)
, m_seenLedgerHashes (seenLedgersCacheSize)
@@ -133,11 +138,13 @@ public:
{
if (findSourceByID (source->uniqueID()))
{
m_journal.error << "Duplicate static " << source->name();
m_journal.error <<
"Duplicate static " << *source;
return;
}
m_journal.info << "Addding static " << source->name();
m_journal.trace <<
"Addding static " << *source;
Source::Results results;
source->fetch (results, m_journal);
@@ -145,8 +152,9 @@ public:
if (results.success)
{
std::size_t const numAdded (merge (results.list, source));
m_journal.info << "Added " << numAdded
<< " trusted validators from " << source->name();
m_journal.trace <<
"Added " << numAdded <<
" trusted validators from " << *source;
}
else
{
@@ -161,11 +169,13 @@ public:
if (findSourceByID (source->uniqueID()))
{
std::unique_ptr <Source> object (source);
m_journal.error << "Duplicate " << source->name();
m_journal.error <<
"Duplicate " << *source;
return;
}
m_journal.info << "Adding " << source->name();
m_journal.info <<
"Adding " << *source;
{
m_sources.resize (m_sources.size() + 1);
@@ -331,20 +341,20 @@ public:
m_journal.info <<
"Fetched " << numFetched <<
"(" << (numAdded - numRemoved) << " new) " <<
" trusted validators from " << source->name();
" trusted validators from " << *source;
}
else if (numRemoved > numAdded)
{
m_journal.info <<
"Fetched " << numFetched <<
"(" << numRemoved - numAdded << " removed) " <<
" trusted validators from " << source->name();
" trusted validators from " << *source;
}
else
{
m_journal.info <<
m_journal.debug <<
"Fetched " << numFetched <<
" trusted validators from " << source->name();
" trusted validators from " << *source;
}
// See if we need to rebuild
@@ -359,7 +369,8 @@ public:
}
else
{
m_journal.error << "Failed to fetch " << source->name();
m_journal.error <<
"Failed to fetch " << *source;
++desc.numberOfFailures;
desc.status = SourceDesc::statusFailed;
@@ -429,6 +440,16 @@ public:
return;
iter->second.receiveValidation (rv.ledgerHash);
m_journal.trace <<
"New trusted validation for " << rv.ledgerHash <<
" from " << rv.publicKey;
}
else
{
m_journal.trace <<
"Untrusted validation for " << rv.ledgerHash <<
" from " << rv.publicKey;
}
}
@@ -440,6 +461,11 @@ public:
if (! m_seenLedgerHashes.insert (ledgerHash))
return;
++m_ledgerID;
m_journal.trace <<
"Closed ledger " << m_ledgerID;
for (ValidatorTable::iterator iter (m_validators.begin());
iter != m_validators.end(); ++iter)
{

View File

@@ -158,6 +158,12 @@ public:
, m_checkTimer (this)
, m_checkSources (false)
{
m_journal.trace <<
"Validators constructed";
m_journal.debug <<
"Validators constructed (debug)";
m_journal.info <<
"Validators constructed (info)";
}
~ManagerImp ()
@@ -199,12 +205,8 @@ public:
void addStaticSource (Validators::Source* source)
{
#if RIPPLE_USE_VALIDATORS
m_queue.dispatch (m_context.wrap (bind (
&Logic::addStatic, &m_logic, source)));
#else
delete source;
#endif
}
void addURL (URL const& url)
@@ -214,32 +216,24 @@ public:
void addSource (Validators::Source* source)
{
#if RIPPLE_USE_VALIDATORS
m_queue.dispatch (m_context.wrap (bind (
&Logic::add, &m_logic, source)));
#else
delete source;
#endif
}
//--------------------------------------------------------------------------
void receiveValidation (ReceivedValidation const& rv)
{
#if RIPPLE_USE_VALIDATORS
if (! isStopping())
m_queue.dispatch (m_context.wrap (bind (
&Logic::receiveValidation, &m_logic, rv)));
#endif
}
void ledgerClosed (RippleLedgerHash const& ledgerHash)
{
#if RIPPLE_USE_VALIDATORS
if (! isStopping())
m_queue.dispatch (m_context.wrap (bind (
&Logic::ledgerClosed, &m_logic, ledgerHash)));
#endif
}
//--------------------------------------------------------------------------
@@ -250,42 +244,23 @@ public:
void onPrepare ()
{
#if RIPPLE_USE_VALIDATORS
m_journal.info << "Validators preparing";
#endif
}
void onStart ()
{
#if RIPPLE_USE_VALIDATORS
m_journal.info << "Validators starting";
// Do this late so the sources have a chance to be added.
m_queue.dispatch (m_context.wrap (bind (
&ManagerImp::setCheckSources, this)));
startThread();
#endif
}
void onStop ()
{
#if RIPPLE_USE_VALIDATORS
m_journal.info << "Validators stopping";
#endif
m_logic.stop ();
if (this->Thread::isThreadRunning())
{
m_journal.debug << "Signaling thread exit";
m_queue.dispatch (m_context.wrap (bind (
&Thread::signalThreadShouldExit, this)));
}
else
{
stopped();
}
m_queue.dispatch (m_context.wrap (bind (
&Thread::signalThreadShouldExit, this)));
}
//--------------------------------------------------------------------------
@@ -306,7 +281,7 @@ public:
PropertyStream::Set items ("sources", map);
for (Logic::SourceTable::const_iterator iter (m_logic.m_sources.begin());
iter != m_logic.m_sources.end(); ++iter)
items.add (iter->source->name().toStdString());
items.add (iter->source->to_string());
}
{
@@ -314,6 +289,11 @@ public:
for (Logic::ValidatorTable::iterator iter (m_logic.m_validators.begin());
iter != m_logic.m_validators.end(); ++iter)
{
RipplePublicKey const& publicKey (iter->first);
Validator const& validator (iter->second);
PropertyStream::Map item (items);
item["public_key"] = publicKey.to_string();
validator.count().onWrite (item);
}
}
}
@@ -326,21 +306,11 @@ public:
void init ()
{
m_journal.debug << "Initializing";
File const file (File::getSpecialLocation (
File::userDocumentsDirectory).getChildFile ("validators.sqlite"));
m_journal.debug << "Opening database at '" << file.getFullPathName() << "'";
Error error (m_store.open (file));
if (error)
{
m_journal.fatal <<
"Failed to open '" << file.getFullPathName() << "'";
}
if (! error)
{
m_logic.load ();
@@ -351,7 +321,7 @@ public:
{
if (timer == m_checkTimer)
{
m_journal.debug << "Check timer expired";
m_journal.trace << "Check timer expired";
m_queue.dispatch (m_context.wrap (bind (
&ManagerImp::setCheckSources, this)));
}
@@ -359,7 +329,7 @@ public:
void setCheckSources ()
{
m_journal.debug << "Checking sources";
m_journal.trace << "Checking sources";
m_checkSources = true;
}
@@ -369,14 +339,14 @@ public:
{
if (m_logic.fetch_one () == 0)
{
m_journal.debug << "All sources checked";
m_journal.trace << "All sources checked";
// Made it through the list without interruption!
// Clear the flag and set the deadline timer again.
//
m_checkSources = false;
m_journal.debug << "Next check timer expires in " <<
m_journal.trace << "Next check timer expires in " <<
RelativeTime::seconds (checkEverySeconds);
m_checkTimer.setExpiration (checkEverySeconds);

View File

@@ -26,5 +26,11 @@ Source::Results::Results ()
{
}
std::ostream& operator<< (std::ostream& os, Source const& v)
{
os << v.to_string();
return os;
}
}
}

View File

@@ -34,12 +34,15 @@ public:
{
}
String name ()
std::string to_string () const
{
return "File: '" + m_file.getFullPathName () + "'";
std::stringstream ss;
ss <<
"File: '" << m_file.getFullPathName().toStdString() + "'";
return ss.str();
}
String uniqueID ()
String uniqueID () const
{
return "File," + m_file.getFullPathName ();
}

View File

@@ -36,13 +36,14 @@ public:
{
}
String name ()
std::string to_string () const
{
return m_name;
return m_name.toStdString();
}
String uniqueID ()
String uniqueID () const
{
// VFALCO TODO This can't be right...?
return String::empty;
}

View File

@@ -37,12 +37,15 @@ public:
{
}
String name ()
std::string to_string () const
{
return "URL: '" + m_url.toString() + "'";
std::stringstream ss;
ss <<
"URL: '" << m_url.to_string() << "'";
return ss.str();
}
String uniqueID ()
String uniqueID () const
{
return "URL," + m_url.toString();
}

View File

@@ -33,12 +33,19 @@ Error StoreSqdb::open (File const& file)
{
Error error (m_session.open (file.getFullPathName ()));
m_journal.info <<
"Opening " << file.getFullPathName();
if (!error)
error = init ();
if (!error)
error = update ();
if (error)
m_journal.error <<
"Failed opening database: " << error.what();
return error;
}
@@ -206,8 +213,8 @@ bool StoreSqdb::select (SourceDesc& desc)
if (st.execute_and_fetch (error))
{
m_journal.debug << "Found record for " <<
desc.source->name ();
m_journal.debug <<
"Found record for " << *desc.source;
found = true;
desc.lastFetchTime = Utilities::stringToTime (lastFetchTime);
@@ -215,8 +222,8 @@ bool StoreSqdb::select (SourceDesc& desc)
}
else if (! error)
{
m_journal.info << "No previous record for " <<
desc.source->name ();
m_journal.info <<
"No previous record for " << *desc.source;
}
if (error)
@@ -296,16 +303,18 @@ void StoreSqdb::selectList (SourceDesc& desc)
}
else
{
m_journal.error << "Invalid public key '" <<
publicKeyString << "' found in database";
m_journal.error <<
"Invalid public key '" << publicKeyString <<
"' found in database";
}
}
while (st.fetch (error));
if (! error)
{
m_journal.info << "Loaded " << desc.results.list.size() <<
" trusted validators for " << desc.source->name ();
m_journal.info <<
"Loaded " << desc.results.list.size() <<
" trusted validators for " << *desc.source;
}
}
}

View File

@@ -104,12 +104,12 @@ public:
{
}
String name ()
std::string to_string () const
{
return uniqueID ();
return uniqueID().toStdString();
}
String uniqueID ()
String uniqueID () const
{
return String ("Test,") + m_name + "," +
String::fromNumber (m_start) + "," +

View File

@@ -29,7 +29,7 @@ namespace Validators {
//
enum
{
#if 0
#if 1
// We will fetch a source at this interval
hoursBetweenFetches = 24
,secondsBetweenFetches = hoursBetweenFetches * 60 * 60