Skip to content

Commit

Permalink
[FOLD] Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelportilla committed Jul 10, 2019
1 parent 4406bcb commit e96f9e9
Showing 1 changed file with 0 additions and 109 deletions.
109 changes: 0 additions & 109 deletions src/ripple/app/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,9 +863,6 @@ class ApplicationImp
setup.startUp == Config::LOAD_FILE ||
setup.startUp == Config::REPLAY)
{
// perform any needed table updates
updateTxnDB();

// Check if AccountTransactions has primary key
std::string cid, name, type;
std::size_t notnull, dflt_value, pk;
Expand Down Expand Up @@ -1261,7 +1258,6 @@ class ApplicationImp
// and new validations must be greater than this.
std::atomic<LedgerIndex> maxDisallowedLedger_ {0};

void updateTxnDB ();
bool nodeToShards ();
bool validateShards ();
void startGenesisLedger ();
Expand Down Expand Up @@ -2079,111 +2075,6 @@ ApplicationImp::journal (std::string const& name)
return logs_->journal (name);
}

void
ApplicationImp::updateTxnDB()
{
auto schemaHas = [&](std::string const& column)
{
std::string cid, name;
soci::statement st = (mTxnDB->getSession().prepare <<
("PRAGMA table_info(AccountTransactions);"),
soci::into(cid),
soci::into(name));

st.execute();
while (st.fetch())
{
if (name == column)
return true;
}

return false;
};

assert(schemaHas("TransID"));
assert(!schemaHas("foobar"));

if (schemaHas("TxnSeq"))
return;

JLOG (m_journal.warn()) << "Transaction sequence field is missing";

auto& session = getTxnDB ().getSession ();

std::vector< std::pair<uint256, int> > txIDs;
txIDs.reserve (300000);

JLOG (m_journal.info()) << "Parsing transactions";
int i = 0;
uint256 transID;

boost::optional<std::string> strTransId;
soci::blob sociTxnMetaBlob(session);
soci::indicator tmi;
Blob txnMeta;

soci::statement st =
(session.prepare <<
"SELECT TransID, TxnMeta FROM Transactions;",
soci::into(strTransId),
soci::into(sociTxnMetaBlob, tmi));

st.execute ();
while (st.fetch ())
{
if (soci::i_ok == tmi)
convert (sociTxnMetaBlob, txnMeta);
else
txnMeta.clear ();

std::string tid = strTransId.value_or("");
transID.SetHex (tid, true);

if (txnMeta.size () == 0)
{
txIDs.push_back (std::make_pair (transID, -1));
JLOG (m_journal.info()) << "No metadata for " << transID;
}
else
{
TxMeta m (transID, 0, txnMeta);
txIDs.push_back (std::make_pair (transID, m.getIndex ()));
}

if ((++i % 1000) == 0)
{
JLOG (m_journal.info()) << i << " transactions read";
}
}

JLOG (m_journal.info()) << "All " << i << " transactions read";

soci::transaction tr(session);

JLOG (m_journal.info()) << "Dropping old index";
session << "DROP INDEX AcctTxIndex;";

JLOG (m_journal.info()) << "Altering table";
session << "ALTER TABLE AccountTransactions ADD COLUMN TxnSeq INTEGER;";

boost::format fmt ("UPDATE AccountTransactions SET TxnSeq = %d WHERE TransID = '%s';");
i = 0;
for (auto& t : txIDs)
{
session << boost::str (fmt % t.second % to_string (t.first));

if ((++i % 1000) == 0)
{
JLOG (m_journal.info()) << i << " transactions updated";
}
}

JLOG (m_journal.info()) << "Building new index";
session << "CREATE INDEX AcctTxIndex ON AccountTransactions(Account, LedgerSeq, TxnSeq, TransID);";

tr.commit ();
}

bool ApplicationImp::nodeToShards()
{
assert(m_overlay);
Expand Down

0 comments on commit e96f9e9

Please sign in to comment.