Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marta-lokhova committed Oct 12, 2024
1 parent 453ab78 commit f630856
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
14 changes: 9 additions & 5 deletions src/history/CheckpointBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ CheckpointBuilder::CheckpointBuilder(Application& app) : mApp(app)
void
CheckpointBuilder::appendTransactionSet(uint32_t ledgerSeq,
TxSetXDRFrameConstPtr const& txSet,
TransactionResultSet const& resultSet)
TransactionResultSet const& resultSet,
bool skipStartupCheck)
{
ZoneScoped;
TransactionHistoryEntry txs;
Expand All @@ -113,11 +114,12 @@ CheckpointBuilder::appendTransactionSet(uint32_t ledgerSeq,
void
CheckpointBuilder::appendTransactionSet(uint32_t ledgerSeq,
TransactionHistoryEntry const& txSet,
TransactionResultSet const& resultSet)
TransactionResultSet const& resultSet,
bool skipStartupCheck)
{
ZoneScoped;
if (!mStartupValidationComplete &&
ledgerSeq != LedgerManager::GENESIS_LEDGER_SEQ)
ledgerSeq != LedgerManager::GENESIS_LEDGER_SEQ && !skipStartupCheck)
{
throw std::runtime_error("Startup validation not performed");
}
Expand All @@ -134,11 +136,13 @@ CheckpointBuilder::appendTransactionSet(uint32_t ledgerSeq,
}

void
CheckpointBuilder::appendLedgerHeader(LedgerHeader const& header)
CheckpointBuilder::appendLedgerHeader(LedgerHeader const& header,
bool skipStartupCheck)
{
ZoneScoped;
if (!mStartupValidationComplete &&
header.ledgerSeq != LedgerManager::GENESIS_LEDGER_SEQ)
header.ledgerSeq != LedgerManager::GENESIS_LEDGER_SEQ &&
!skipStartupCheck)
{
throw std::runtime_error("Startup validation not performed");
}
Expand Down
9 changes: 6 additions & 3 deletions src/history/CheckpointBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ class CheckpointBuilder
CheckpointBuilder(Application& app);
void appendTransactionSet(uint32_t ledgerSeq,
TxSetXDRFrameConstPtr const& txSet,
TransactionResultSet const& resultSet);
TransactionResultSet const& resultSet,
bool skipStartupCheck = false);
void appendTransactionSet(uint32_t ledgerSeq,
TransactionHistoryEntry const& txSet,
TransactionResultSet const& resultSet);
void appendLedgerHeader(LedgerHeader const& header);
TransactionResultSet const& resultSet,
bool skipStartupCheck = false);
void appendLedgerHeader(LedgerHeader const& header,
bool skipStartupCheck = false);

// Cleanup publish files according to the latest LCL.
// Publish files might contain dirty data if a crash occurred after append
Expand Down
22 changes: 15 additions & 7 deletions src/history/HistoryManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ HistoryManagerImpl::dropSQLBasedPublish()
// function is atomic
releaseAssert(threadIsMain());

// In case previous schema migration rolled back, cleanup files
fs::deltree(publishQueuePath(mApp.getConfig()));
fs::deltree(getPublishHistoryDir(FileType::HISTORY_FILE_TYPE_LEDGER,
mApp.getConfig())
.parent_path());
createPublishDir(FileType::HISTORY_FILE_TYPE_LEDGER, mApp.getConfig());
createPublishDir(FileType::HISTORY_FILE_TYPE_TRANSACTIONS,
mApp.getConfig());
createPublishDir(FileType::HISTORY_FILE_TYPE_RESULTS, mApp.getConfig());
HistoryManager::createPublishQueueDir(mApp.getConfig());

std::set<uint32_t> checkpointLedgers;
// Migrate all the existing queued checkpoints to the new format
{
Expand All @@ -126,8 +137,6 @@ HistoryManagerImpl::dropSQLBasedPublish()
}

auto freq = getCheckpointFrequency();
uint32_t lclCheckpoint = checkpointContainingLedger(
mApp.getLedgerManager().getLastClosedLedgerNum());
uint32_t lastQueued = 0;
for (auto const& checkpoint : checkpointLedgers)
{
Expand All @@ -142,14 +151,13 @@ HistoryManagerImpl::dropSQLBasedPublish()
lastQueued = std::max(lastQueued, checkpoint);
}

if (lclCheckpoint < lastQueued)
if (lastQueued != 0)
{
releaseAssert(isFirstLedgerInCheckpoint(lastQueued + 1));
// Then, reconstruct any partial checkpoints that haven't yet been
// queued
populateCheckpointFilesFromDB(
mApp, mApp.getDatabase().getSession(),
firstLedgerInCheckpointContaining(lclCheckpoint), freq,
*mCheckpoint);
populateCheckpointFilesFromDB(mApp, mApp.getDatabase().getSession(),
lastQueued + 1, freq, *mCheckpoint);
}

// Now it's safe to drop obsolete SQL tables
Expand Down
3 changes: 2 additions & 1 deletion src/ledger/LedgerHeaderUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ copyToStream(Database& db, soci::session& sess, uint32_t ledgerSeq,
lhe.header = decodeFromData(headerEncoded);
lhe.hash = xdrSha256(lhe.header);
CLOG_DEBUG(Ledger, "Streaming ledger-header {}", lhe.header.ledgerSeq);
checkpointBuilder.appendLedgerHeader(lhe.header);
checkpointBuilder.appendLedgerHeader(lhe.header,
/* skipStartupCheck */ true);
++n;
st.fetch();
}
Expand Down
8 changes: 4 additions & 4 deletions src/transactions/TransactionSQL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ writeNonGeneralizedTxSetToStream(
TransactionHistoryEntry hist;
hist.ledgerSeq = ledgerSeq;
txSet->toXDR(hist.txSet);
checkpointBuilder.appendTransactionSet(ledgerSeq, hist,
results.txResultSet);
checkpointBuilder.appendTransactionSet(ledgerSeq, hist, results.txResultSet,
/* skipStartupCheck */ true);
}

void
Expand Down Expand Up @@ -205,8 +205,8 @@ writeGeneralizedTxSetToStream(uint32 ledgerSeq,
hist.ext.v(1);
xdr_argpack_archive(unpacker, hist.ext.generalizedTxSet());

checkpointBuilder.appendTransactionSet(ledgerSeq, hist,
results.txResultSet);
checkpointBuilder.appendTransactionSet(ledgerSeq, hist, results.txResultSet,
/* skipStartupCheck */ true);
}

void
Expand Down

0 comments on commit f630856

Please sign in to comment.