Skip to content

Commit

Permalink
Removed LedgerEntry SQL code
Browse files Browse the repository at this point in the history
  • Loading branch information
SirTyson committed Oct 10, 2024
1 parent 2c65abb commit e296214
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 4,408 deletions.
170 changes: 74 additions & 96 deletions src/bucket/test/BucketManagerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,112 +189,90 @@ TEST_CASE("skip list", "[bucket][bucketmanager]")

TEST_CASE_VERSIONS("bucketmanager ownership", "[bucket][bucketmanager]")
{
auto test = [&](bool bucketListDB) {
VirtualClock clock;
Config cfg = getTestConfig();

// Make sure all Buckets serialize indexes to disk for test
cfg.BUCKETLIST_DB_INDEX_CUTOFF = 0;
cfg.MANUAL_CLOSE = false;

if (bucketListDB)
{
// Enable BucketListDB with persistent indexes
cfg.NODE_IS_VALIDATOR = false;
cfg.FORCE_SCP = false;
}

for_versions_with_differing_bucket_logic(cfg, [&](Config const& cfg) {
Application::pointer app = createTestApplication(clock, cfg);

std::vector<LedgerEntry> live(
LedgerTestUtils::generateValidUniqueLedgerEntriesWithExclusions(
{CONFIG_SETTING}, 10));
std::vector<LedgerKey> dead{};

std::shared_ptr<LiveBucket> b1;

{
std::shared_ptr<LiveBucket> b2 = LiveBucket::fresh(
app->getBucketManager(), getAppLedgerVersion(app), {}, live,
dead, /*countMergeEvents=*/true, clock.getIOContext(),
/*doFsync=*/true);
b1 = b2;

// Bucket is referenced by b1, b2 and the BucketManager.
CHECK(b1.use_count() == 3);

std::shared_ptr<LiveBucket> b3 = LiveBucket::fresh(
app->getBucketManager(), getAppLedgerVersion(app), {}, live,
dead, /*countMergeEvents=*/true, clock.getIOContext(),
/*doFsync=*/true);
std::shared_ptr<LiveBucket> b4 = LiveBucket::fresh(
app->getBucketManager(), getAppLedgerVersion(app), {}, live,
dead, /*countMergeEvents=*/true, clock.getIOContext(),
/*doFsync=*/true);
// Bucket is referenced by b1, b2, b3, b4 and the BucketManager.
CHECK(b1.use_count() == 5);
}

// Take pointer by reference to not mess up use_count()
auto dropBucket = [&](std::shared_ptr<LiveBucket>& b) {
std::string filename = b->getFilename().string();
std::string indexFilename =
app->getBucketManager().bucketIndexFilename(b->getHash());
CHECK(fs::exists(filename));
if (bucketListDB)
{
CHECK(fs::exists(indexFilename));
}
VirtualClock clock;
Config cfg = getTestConfig();

b.reset();
app->getBucketManager().forgetUnreferencedBuckets();
CHECK(!fs::exists(filename));
CHECK(!fs::exists(indexFilename));
};
// Make sure all Buckets serialize indexes to disk for test
cfg.BUCKETLIST_DB_INDEX_CUTOFF = 0;
cfg.MANUAL_CLOSE = false;

// Bucket is now only referenced by b1 and the BucketManager.
CHECK(b1.use_count() == 2);
for_versions_with_differing_bucket_logic(cfg, [&](Config const& cfg) {
Application::pointer app = createTestApplication(clock, cfg);

// Drop bucket ourselves then purge bucketManager.
dropBucket(b1);
std::vector<LedgerEntry> live(
LedgerTestUtils::generateValidUniqueLedgerEntriesWithExclusions(
{CONFIG_SETTING}, 10));
std::vector<LedgerKey> dead{};

// Try adding a bucket to the BucketManager's bucketlist
auto& bl = app->getBucketManager().getLiveBucketList();
bl.addBatch(*app, 1, getAppLedgerVersion(app), {}, live, dead);
clearFutures(app, bl);
b1 = bl.getLevel(0).getCurr();
std::shared_ptr<LiveBucket> b1;

// Bucket should be referenced by bucketlist itself, BucketManager
// cache and b1.
CHECK(b1.use_count() == 3);
{
std::shared_ptr<LiveBucket> b2 = LiveBucket::fresh(
app->getBucketManager(), getAppLedgerVersion(app), {}, live,
dead, /*countMergeEvents=*/true, clock.getIOContext(),
/*doFsync=*/true);
b1 = b2;

// This shouldn't change if we forget unreferenced buckets since
// it's referenced by bucketlist.
app->getBucketManager().forgetUnreferencedBuckets();
// Bucket is referenced by b1, b2 and the BucketManager.
CHECK(b1.use_count() == 3);

// But if we mutate the curr bucket of the bucketlist, it should.
live[0] = LedgerTestUtils::generateValidLedgerEntryWithExclusions(
{CONFIG_SETTING});
bl.addBatch(*app, 1, getAppLedgerVersion(app), {}, live, dead);
clearFutures(app, bl);
CHECK(b1.use_count() == 2);

// Drop it again.
dropBucket(b1);
});
};
std::shared_ptr<LiveBucket> b3 = LiveBucket::fresh(
app->getBucketManager(), getAppLedgerVersion(app), {}, live,
dead, /*countMergeEvents=*/true, clock.getIOContext(),
/*doFsync=*/true);
std::shared_ptr<LiveBucket> b4 = LiveBucket::fresh(
app->getBucketManager(), getAppLedgerVersion(app), {}, live,
dead, /*countMergeEvents=*/true, clock.getIOContext(),
/*doFsync=*/true);
// Bucket is referenced by b1, b2, b3, b4 and the BucketManager.
CHECK(b1.use_count() == 5);
}

SECTION("BucketListDB")
{
test(true);
}
// Take pointer by reference to not mess up use_count()
auto dropBucket = [&](std::shared_ptr<LiveBucket>& b) {
std::string filename = b->getFilename().string();
std::string indexFilename =
app->getBucketManager().bucketIndexFilename(b->getHash());
CHECK(fs::exists(filename));
CHECK(fs::exists(indexFilename));

SECTION("SQL")
{
test(false);
}
b.reset();
app->getBucketManager().forgetUnreferencedBuckets();
CHECK(!fs::exists(filename));
CHECK(!fs::exists(indexFilename));
};

// Bucket is now only referenced by b1 and the BucketManager.
CHECK(b1.use_count() == 2);

// Drop bucket ourselves then purge bucketManager.
dropBucket(b1);

// Try adding a bucket to the BucketManager's bucketlist
auto& bl = app->getBucketManager().getLiveBucketList();
bl.addBatch(*app, 1, getAppLedgerVersion(app), {}, live, dead);
clearFutures(app, bl);
b1 = bl.getLevel(0).getCurr();

// Bucket should be referenced by bucketlist itself, BucketManager
// cache and b1.
CHECK(b1.use_count() == 3);

// This shouldn't change if we forget unreferenced buckets since
// it's referenced by bucketlist.
app->getBucketManager().forgetUnreferencedBuckets();
CHECK(b1.use_count() == 3);

// But if we mutate the curr bucket of the bucketlist, it should.
live[0] = LedgerTestUtils::generateValidLedgerEntryWithExclusions(
{CONFIG_SETTING});
bl.addBatch(*app, 1, getAppLedgerVersion(app), {}, live, dead);
clearFutures(app, bl);
CHECK(b1.use_count() == 2);

// Drop it again.
dropBucket(b1);
});
}

TEST_CASE("bucketmanager missing buckets fail", "[bucket][bucketmanager]")
Expand Down
45 changes: 0 additions & 45 deletions src/ledger/InMemoryLedgerTxnRoot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,56 +108,11 @@ InMemoryLedgerTxnRoot::deleteOffersModifiedOnOrAfterLedger(
{
}

void
InMemoryLedgerTxnRoot::dropAccounts(bool)
{
}

void
InMemoryLedgerTxnRoot::dropData(bool)
{
}

void
InMemoryLedgerTxnRoot::dropOffers(bool)
{
}

void
InMemoryLedgerTxnRoot::dropTrustLines(bool)
{
}

void
InMemoryLedgerTxnRoot::dropClaimableBalances(bool)
{
}

void
InMemoryLedgerTxnRoot::dropLiquidityPools(bool)
{
}

void
InMemoryLedgerTxnRoot::dropContractData(bool)
{
}

void
InMemoryLedgerTxnRoot::dropContractCode(bool)
{
}

void
InMemoryLedgerTxnRoot::dropConfigSettings(bool)
{
}

void
InMemoryLedgerTxnRoot::dropTTL(bool)
{
}

double
InMemoryLedgerTxnRoot::getPrefetchHitRate() const
{
Expand Down
9 changes: 0 additions & 9 deletions src/ledger/InMemoryLedgerTxnRoot.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,7 @@ class InMemoryLedgerTxnRoot : public AbstractLedgerTxnParent

void deleteOffersModifiedOnOrAfterLedger(uint32_t ledger) const override;

void dropAccounts(bool rebuild) override;
void dropData(bool rebuild) override;
void dropOffers(bool rebuild) override;
void dropTrustLines(bool rebuild) override;
void dropClaimableBalances(bool rebuild) override;
void dropLiquidityPools(bool rebuild) override;
void dropContractData(bool rebuild) override;
void dropContractCode(bool rebuild) override;
void dropConfigSettings(bool rebuild) override;
void dropTTL(bool rebuild) override;
double getPrefetchHitRate() const override;
uint32_t prefetchClassic(UnorderedSet<LedgerKey> const& keys) override;
uint32_t prefetchSoroban(UnorderedSet<LedgerKey> const& keys,
Expand Down
109 changes: 0 additions & 109 deletions src/ledger/LedgerTxn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2022,67 +2022,12 @@ LedgerTxn::deleteOffersModifiedOnOrAfterLedger(uint32_t ledger) const
"called deleteOffersModifiedOnOrAfterLedger on non-root LedgerTxn");
}

void
LedgerTxn::dropAccounts(bool rebuild)
{
throw std::runtime_error("called dropAccounts on non-root LedgerTxn");
}

void
LedgerTxn::dropData(bool rebuild)
{
throw std::runtime_error("called dropData on non-root LedgerTxn");
}

void
LedgerTxn::dropOffers(bool rebuild)
{
throw std::runtime_error("called dropOffers on non-root LedgerTxn");
}

void
LedgerTxn::dropTrustLines(bool rebuild)
{
throw std::runtime_error("called dropTrustLines on non-root LedgerTxn");
}

void
LedgerTxn::dropClaimableBalances(bool rebuild)
{
throw std::runtime_error(
"called dropClaimableBalances on non-root LedgerTxn");
}

void
LedgerTxn::dropLiquidityPools(bool rebuild)
{
throw std::runtime_error("called dropLiquidityPools on non-root LedgerTxn");
}

void
LedgerTxn::dropContractData(bool rebuild)
{
throw std::runtime_error("called dropContractData on non-root LedgerTxn");
}

void
LedgerTxn::dropContractCode(bool rebuild)
{
throw std::runtime_error("called dropContractCode on non-root LedgerTxn");
}

void
LedgerTxn::dropConfigSettings(bool rebuild)
{
throw std::runtime_error("called dropConfigSettings on non-root LedgerTxn");
}

void
LedgerTxn::dropTTL(bool rebuild)
{
throw std::runtime_error("called dropTTL on non-root LedgerTxn");
}

double
LedgerTxn::getPrefetchHitRate() const
{
Expand Down Expand Up @@ -2796,66 +2741,12 @@ LedgerTxnRoot::Impl::deleteOffersModifiedOnOrAfterLedger(uint32_t ledger) const
mApp.getDatabase().getSession() << query, use(ledger);
}

void
LedgerTxnRoot::dropAccounts(bool rebuild)
{
mImpl->dropAccounts(rebuild);
}

void
LedgerTxnRoot::dropData(bool rebuild)
{
mImpl->dropData(rebuild);
}

void
LedgerTxnRoot::dropOffers(bool rebuild)
{
mImpl->dropOffers(rebuild);
}

void
LedgerTxnRoot::dropTrustLines(bool rebuild)
{
mImpl->dropTrustLines(rebuild);
}

void
LedgerTxnRoot::dropClaimableBalances(bool rebuild)
{
mImpl->dropClaimableBalances(rebuild);
}

void
LedgerTxnRoot::dropLiquidityPools(bool rebuild)
{
mImpl->dropLiquidityPools(rebuild);
}

void
LedgerTxnRoot::dropContractData(bool rebuild)
{
mImpl->dropContractData(rebuild);
}

void
LedgerTxnRoot::dropContractCode(bool rebuild)
{
mImpl->dropContractCode(rebuild);
}

void
LedgerTxnRoot::dropConfigSettings(bool rebuild)
{
mImpl->dropConfigSettings(rebuild);
}

void
LedgerTxnRoot::dropTTL(bool rebuild)
{
mImpl->dropTTL(rebuild);
}

uint32_t
LedgerTxnRoot::prefetchClassic(UnorderedSet<LedgerKey> const& keys)
{
Expand Down
Loading

0 comments on commit e296214

Please sign in to comment.