Create new Validations columns properly:

* Thread-safe preparation of Validations cleanup query
* Followup to RIPD-870
This commit is contained in:
Edward Hennis
2016-03-04 14:15:15 -05:00
parent 64d9f7c23e
commit a327cecee6
3 changed files with 38 additions and 9 deletions

View File

@@ -923,6 +923,7 @@ public:
private: private:
void addTxnSeqField(); void addTxnSeqField();
void addValidationSeqFields();
void updateTables (); void updateTables ();
void startGenesisLedger (); void startGenesisLedger ();
@@ -1705,6 +1706,39 @@ void ApplicationImp::addTxnSeqField ()
tr.commit (); tr.commit ();
} }
void ApplicationImp::addValidationSeqFields ()
{
if (schemaHas(getLedgerDB(), "Validations", 0, "LedgerSeq", m_journal))
{
assert(schemaHas(getLedgerDB(), "Validations", 0, "InitialSeq", m_journal));
return;
}
JLOG(m_journal.warning) << "Validation sequence fields are missing";
assert(!schemaHas(getLedgerDB(), "Validations", 0, "InitialSeq", m_journal));
auto& session = getLedgerDB().getSession();
soci::transaction tr(session);
JLOG(m_journal.info) << "Altering table";
session << "ALTER TABLE Validations "
"ADD COLUMN LedgerSeq BIGINT UNSIGNED;";
session << "ALTER TABLE Validations "
"ADD COLUMN InitialSeq BIGINT UNSIGNED;";
// Create the indexes, too, so we don't have to
// wait for the next startup, which may be a while.
// These should be identical to those in LedgerDBInit
JLOG(m_journal.info) << "Building new indexes";
session << "CREATE INDEX IF NOT EXISTS "
"ValidationsBySeq ON Validations(LedgerSeq);";
session << "CREATE INDEX IF NOT EXISTS ValidationsByInitialSeq "
"ON Validations(InitialSeq, LedgerSeq);";
tr.commit();
}
void ApplicationImp::updateTables () void ApplicationImp::updateTables ()
{ {
if (config_->section (ConfigSection::nodeDatabase ()).empty ()) if (config_->section (ConfigSection::nodeDatabase ()).empty ())
@@ -1724,6 +1758,8 @@ void ApplicationImp::updateTables ()
exitWithCode(1); exitWithCode(1);
} }
addValidationSeqFields ();
if (config_->doImport) if (config_->doImport)
{ {
NodeStore::DummyScheduler scheduler; NodeStore::DummyScheduler scheduler;

View File

@@ -100,13 +100,6 @@ const char* LedgerDBInit[] =
SignTime BIGINT UNSIGNED, \ SignTime BIGINT UNSIGNED, \
RawData BLOB \ RawData BLOB \
);", );",
// This will error out if the column already exists,
// but DatabaseCon intentionally ignores errors.
"ALTER TABLE Validations \
ADD COLUMN LedgerSeq BIGINT UNSIGNED;",
"ALTER TABLE Validations \
ADD COLUMN InitialSeq BIGINT UNSIGNED;",
"CREATE INDEX IF NOT EXISTS ValidationsByHash ON \ "CREATE INDEX IF NOT EXISTS ValidationsByHash ON \
Validations(LedgerHash);", Validations(LedgerHash);",
"CREATE INDEX IF NOT EXISTS ValidationsBySeq ON \ "CREATE INDEX IF NOT EXISTS ValidationsBySeq ON \

View File

@@ -664,10 +664,10 @@ SHAMapStoreImp::clearPrior (LedgerIndex lastRotated)
<< deleteBatch << " rows."; << deleteBatch << " rows.";
long long totalRowsAffected = 0; long long totalRowsAffected = 0;
long long rowsAffected; long long rowsAffected;
soci::statement st = [&] auto st = [&]
{ {
auto db = ledgerDb_->checkoutDb(); auto db = ledgerDb_->checkoutDb();
return (db->prepare << deleteQuery); return soci::statement(db->prepare << deleteQuery);
}(); }();
if (health()) if (health())
return; return;