Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't rebuild tables after enabling BucketListDB #4267

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/ledger/LedgerTxnContractCodeSQL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,17 +364,21 @@ LedgerTxnRoot::Impl::dropContractCode(bool rebuild)
std::string coll = mApp.getDatabase().getSimpleCollationClause();

mApp.getDatabase().getSession() << "DROP TABLE IF EXISTS contractcode;";
mApp.getDatabase().getSession()
<< "CREATE TABLE contractcode ("
<< "hash TEXT " << coll << " NOT NULL, "
<< "ledgerentry TEXT " << coll << " NOT NULL, "
<< "lastmodified INT NOT NULL, "
<< "PRIMARY KEY (hash));";
if (!mApp.getDatabase().isSqlite())

if (rebuild)
{
mApp.getDatabase().getSession() << "ALTER TABLE contractcode "
<< "ALTER COLUMN hash "
<< "TYPE TEXT COLLATE \"C\";";
mApp.getDatabase().getSession()
<< "CREATE TABLE contractcode ("
<< "hash TEXT " << coll << " NOT NULL, "
<< "ledgerentry TEXT " << coll << " NOT NULL, "
<< "lastmodified INT NOT NULL, "
<< "PRIMARY KEY (hash));";
if (!mApp.getDatabase().isSqlite())
{
mApp.getDatabase().getSession() << "ALTER TABLE contractcode "
<< "ALTER COLUMN hash "
<< "TYPE TEXT COLLATE \"C\";";
}
}
}

Expand Down
24 changes: 14 additions & 10 deletions src/ledger/LedgerTxnTTLSQL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,17 +359,21 @@ LedgerTxnRoot::Impl::dropTTL(bool rebuild)
std::string coll = mApp.getDatabase().getSimpleCollationClause();

mApp.getDatabase().getSession() << "DROP TABLE IF EXISTS ttl;";
mApp.getDatabase().getSession()
<< "CREATE TABLE ttl ("
<< "keyhash TEXT " << coll << " NOT NULL, "
<< "ledgerentry TEXT " << coll << " NOT NULL, "
<< "lastmodified INT NOT NULL, "
<< "PRIMARY KEY (keyhash));";
if (!mApp.getDatabase().isSqlite())

if (rebuild)
{
mApp.getDatabase().getSession() << "ALTER TABLE ttl "
<< "ALTER COLUMN keyhash "
<< "TYPE TEXT COLLATE \"C\";";
mApp.getDatabase().getSession()
<< "CREATE TABLE ttl ("
<< "keyhash TEXT " << coll << " NOT NULL, "
<< "ledgerentry TEXT " << coll << " NOT NULL, "
<< "lastmodified INT NOT NULL, "
<< "PRIMARY KEY (keyhash));";
if (!mApp.getDatabase().isSqlite())
{
mApp.getDatabase().getSession() << "ALTER TABLE ttl "
<< "ALTER COLUMN keyhash "
<< "TYPE TEXT COLLATE \"C\";";
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/ApplicationImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,17 @@ maybeRebuildLedger(Application& app, bool applyBuckets)
auto bucketListDBEnabled = app.getConfig().isUsingBucketListDB();
for (auto let : xdr::xdr_traits<LedgerEntryType>::enum_values())
{
// If BucketListDB is enabled, drop all tables except for offers
LedgerEntryType t = static_cast<LedgerEntryType>(let);
if (ps.shouldRebuildForType(t))
if (let != OFFER && bucketListDBEnabled)
{
toRebuild.emplace(t);
toDrop.emplace(t);
continue;
}

// If bucketlist is enabled, drop all tables except for offers
if (let != OFFER && bucketListDBEnabled)
if (ps.shouldRebuildForType(t))
{
toDrop.emplace(t);
toRebuild.emplace(t);
}
}

Expand Down
Loading