mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Remove SQLite Validations table
This commit is contained in:
committed by
Nik Bougalis
parent
e1adbd7ddd
commit
c5a95f1eb5
@@ -657,118 +657,6 @@ SHAMapStoreImp::clearPrior (LedgerIndex lastRotated)
|
||||
if (health())
|
||||
return;
|
||||
|
||||
{
|
||||
/*
|
||||
Steps for migration:
|
||||
Assume: online_delete = 100, lastRotated = 1000,
|
||||
Last shutdown was at ledger # 1080.
|
||||
The current network validated ledger is 1090.
|
||||
Implies: Ledgers has entries from 900 to 1080.
|
||||
Validations has entries for all 1080 ledgers,
|
||||
including orphan validations that were not included
|
||||
in a validated ledger.
|
||||
1) Columns are created in Validations with default NULL values.
|
||||
2) During syncing, Ledgers and Validations for 1080 - 1090
|
||||
are received from the network. Records are created in
|
||||
Validations with InitialSeq approximately 1080 (exact value
|
||||
doesn't matter), and later validated with the matching
|
||||
LedgerSeq value.
|
||||
3) rippled participates in ledgers 1091-1100. Validations
|
||||
received are created with InitialSeq in that range, and
|
||||
appropriate LedgerSeqs. Maybe some of those ledgers are
|
||||
not accepted, so LedgerSeq stays null.
|
||||
4) At ledger 1100, this function is called with
|
||||
lastRotated = 1000. The first query tries to delete
|
||||
rows WHERE LedgerSeq < 1000. It finds none.
|
||||
5) The second round of deletions does not run.
|
||||
6) Ledgers continue to advance from 1100-1200 as described
|
||||
in step 3.
|
||||
7) At ledger 1200, this function is called again with
|
||||
lastRotated = 1100. The first query again tries to delete
|
||||
rows WHERE LedgerSeq < 1100. It finds the rows for 1080-1099.
|
||||
8) The second round of deletions runs. It gets
|
||||
WHERE v.LedgerSeq is NULL AND
|
||||
(v.InitialSeq IS NULL OR v.InitialSeq < 1100)
|
||||
The rows that are found include (a) ALL of the Validations
|
||||
for the first 1080 ledgers. (b) Any orphan validations that
|
||||
were created in step 3.
|
||||
9) This continues. The next rotation cycle does the same as steps
|
||||
7 & 8, except that none of the original Validations (8a) exist
|
||||
anymore, and 8b gets the orphans from step 6.
|
||||
*/
|
||||
|
||||
static auto anyValDeleted = false;
|
||||
auto const valDeleted = clearSql(*ledgerDb_, lastRotated,
|
||||
"SELECT MIN(LedgerSeq) FROM Validations;",
|
||||
"DELETE FROM Validations WHERE LedgerSeq < %u;");
|
||||
anyValDeleted |= valDeleted;
|
||||
|
||||
if (health())
|
||||
return;
|
||||
|
||||
if (anyValDeleted)
|
||||
{
|
||||
/* Delete the old NULL LedgerSeqs - the Validations that
|
||||
aren't linked to a validated ledger - but only if we
|
||||
deleted rows in the matching `clearSql` call, and only
|
||||
for those created with an old InitialSeq.
|
||||
*/
|
||||
using namespace std::chrono;
|
||||
auto const deleteBatch = setup_.deleteBatch;
|
||||
auto const continueLimit = (deleteBatch + 1) / 2;
|
||||
|
||||
std::string const deleteQuery(
|
||||
R"sql(DELETE FROM Validations
|
||||
WHERE LedgerHash IN
|
||||
(
|
||||
SELECT v.LedgerHash
|
||||
FROM Validations v
|
||||
WHERE v.LedgerSeq is NULL AND
|
||||
(v.InitialSeq IS NULL OR v.InitialSeq < )sql" +
|
||||
std::to_string(lastRotated) +
|
||||
") LIMIT " +
|
||||
std::to_string (deleteBatch) +
|
||||
");");
|
||||
|
||||
JLOG(journal_.debug()) << "start: " << deleteQuery << " of "
|
||||
<< deleteBatch << " rows.";
|
||||
long long totalRowsAffected = 0;
|
||||
long long rowsAffected;
|
||||
auto st = [&]
|
||||
{
|
||||
auto db = ledgerDb_->checkoutDb();
|
||||
return soci::statement(db->prepare << deleteQuery);
|
||||
}();
|
||||
if (health())
|
||||
return;
|
||||
do
|
||||
{
|
||||
{
|
||||
auto db = ledgerDb_->checkoutDb();
|
||||
auto const start = high_resolution_clock::now();
|
||||
st.execute(true);
|
||||
rowsAffected = st.get_affected_rows();
|
||||
totalRowsAffected += rowsAffected;
|
||||
auto const ms = duration_cast<milliseconds>(
|
||||
high_resolution_clock::now() - start).count();
|
||||
JLOG(journal_.trace()) << "step: deleted " << rowsAffected
|
||||
<< " rows in " << ms << "ms.";
|
||||
}
|
||||
if (health())
|
||||
return;
|
||||
if (rowsAffected >= continueLimit)
|
||||
std::this_thread::sleep_for(
|
||||
std::chrono::milliseconds(setup_.backOff));
|
||||
}
|
||||
while (rowsAffected && rowsAffected >= continueLimit);
|
||||
JLOG(journal_.debug()) << "finished: " << deleteQuery << ". Deleted "
|
||||
<< totalRowsAffected << " rows.";
|
||||
}
|
||||
}
|
||||
|
||||
if (health())
|
||||
return;
|
||||
|
||||
clearSql (*transactionDb_, lastRotated,
|
||||
"SELECT MIN(LedgerSeq) FROM Transactions;",
|
||||
"DELETE FROM Transactions WHERE LedgerSeq < %u;");
|
||||
|
||||
Reference in New Issue
Block a user