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

Change default test backend to BucketListDB #4462

Merged
merged 6 commits into from
Sep 14, 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
11 changes: 10 additions & 1 deletion src/bucket/Bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,23 @@ Bucket::apply(Application& app) const
{
ZoneScoped;

auto filter = [&](LedgerEntryType t) {
if (app.getConfig().isUsingBucketListDB())
{
return t == OFFER;
}

return true;
};

std::unordered_set<LedgerKey> emptySet;
BucketApplicator applicator(
app, app.getConfig().LEDGER_PROTOCOL_VERSION,
0 /*set to 0 so we always load from the parent to check state*/,
0 /*set to a level that's not the bottom so we don't treat live entries
as init*/
,
shared_from_this(), [](LedgerEntryType) { return true; }, emptySet);
shared_from_this(), filter, emptySet);
BucketApplicator::Counters counters(app.getClock().now());
while (applicator)
{
Expand Down
8 changes: 8 additions & 0 deletions src/bucket/BucketListSnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ SearchableBucketListSnapshot::getLedgerSeq() const
return mSnapshot->getLedgerSeq();
}

LedgerHeader const&
SearchableBucketListSnapshot::getLedgerHeader()
{
releaseAssert(mSnapshot);
mSnapshotManager.maybeUpdateSnapshot(mSnapshot, mHistoricalSnapshots);
return mSnapshot->getLedgerHeader();
}

EvictionResult
SearchableBucketListSnapshot::scanForEviction(
uint32_t ledgerSeq, EvictionCounters& counters,
Expand Down
6 changes: 1 addition & 5 deletions src/bucket/BucketListSnapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ class SearchableBucketListSnapshot : public NonMovableOrCopyable
std::shared_ptr<EvictionStatistics> stats,
StateArchivalSettings const& sas);
uint32_t getLedgerSeq() const;
LedgerHeader const&
getLedgerHeader() const
{
return mSnapshot->getLedgerHeader();
}
LedgerHeader const& getLedgerHeader();
};
}
2 changes: 1 addition & 1 deletion src/bucket/test/BucketIndexTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ TEST_CASE("ContractData key with same ScVal", "[bucket][bucketindex]")

TEST_CASE("serialize bucket indexes", "[bucket][bucketindex]")
{
Config cfg(getTestConfig(0, Config::TESTDB_ON_DISK_SQLITE));
Config cfg(getTestConfig(0, Config::TESTDB_BUCKET_DB_PERSISTENT));

// All levels use range config
cfg.BUCKETLIST_DB_INDEX_CUTOFF = 0;
Expand Down
36 changes: 25 additions & 11 deletions src/bucket/test/BucketListTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ TEST_CASE_VERSIONS("bucket list", "[bucket][bucketlist]")
lh.ledgerSeq = i;
addBatchAndUpdateSnapshot(
bl, *app, lh, {},
LedgerTestUtils::generateValidUniqueLedgerEntries(8),
LedgerTestUtils::
generateValidUniqueLedgerEntriesWithExclusions(
{CONFIG_SETTING}, 8),
LedgerTestUtils::generateValidLedgerEntryKeysWithExclusions(
{CONFIG_SETTING}, 5));
if (i % 10 == 0)
Expand Down Expand Up @@ -256,7 +258,8 @@ TEST_CASE_VERSIONS("bucket list shadowing pre/post proto 12",
{
app->getClock().crank(false);
auto liveBatch =
LedgerTestUtils::generateValidUniqueLedgerEntries(5);
LedgerTestUtils::generateValidUniqueLedgerEntriesWithExclusions(
{CONFIG_SETTING}, 5);

BucketEntry BucketEntryAlice, BucketEntryBob;
alice.balance++;
Expand Down Expand Up @@ -351,14 +354,16 @@ TEST_CASE_VERSIONS("bucket tombstones expire at bottom level",
auto& level = bl.getLevel(i);
level.setCurr(Bucket::fresh(
bm, getAppLedgerVersion(app), {},
LedgerTestUtils::generateValidUniqueLedgerEntries(8),
LedgerTestUtils::generateValidUniqueLedgerEntriesWithExclusions(
{CONFIG_SETTING}, 8),
LedgerTestUtils::generateValidLedgerEntryKeysWithExclusions(
{CONFIG_SETTING}, 5),
/*countMergeEvents=*/true, clock.getIOContext(),
/*doFsync=*/true));
level.setSnap(Bucket::fresh(
bm, getAppLedgerVersion(app), {},
LedgerTestUtils::generateValidUniqueLedgerEntries(8),
LedgerTestUtils::generateValidUniqueLedgerEntriesWithExclusions(
{CONFIG_SETTING}, 8),
LedgerTestUtils::generateValidLedgerEntryKeysWithExclusions(
{CONFIG_SETTING}, 5),
/*countMergeEvents=*/true, clock.getIOContext(),
Expand All @@ -377,7 +382,9 @@ TEST_CASE_VERSIONS("bucket tombstones expire at bottom level",
lh.ledgerSeq = j;
addBatchAndUpdateSnapshot(
bl, *app, lh, {},
LedgerTestUtils::generateValidUniqueLedgerEntries(8),
LedgerTestUtils::
generateValidUniqueLedgerEntriesWithExclusions(
{CONFIG_SETTING}, 8),
LedgerTestUtils::generateValidLedgerEntryKeysWithExclusions(
{CONFIG_SETTING}, 5));
app->getClock().crank(false);
Expand Down Expand Up @@ -502,7 +509,9 @@ TEST_CASE_VERSIONS("single entry bubbling up",
addBatchAndUpdateSnapshot(
bl, *app,
app->getLedgerManager().getLastClosedLedgerHeader().header, {},
LedgerTestUtils::generateValidLedgerEntries(1), emptySet);
LedgerTestUtils::generateValidLedgerEntriesWithExclusions(
{CONFIG_SETTING}, 1),
emptySet);

CLOG_DEBUG(Bucket, "Adding empty batches to bucket list");
for (uint32_t i = 2;
Expand Down Expand Up @@ -664,7 +673,9 @@ TEST_CASE("BucketList check bucket sizes", "[bucket][bucketlist][count]")
Application::pointer app = createTestApplication(clock, cfg);
BucketList& bl = app->getBucketManager().getBucketList();
std::vector<LedgerKey> emptySet;
auto ledgers = LedgerTestUtils::generateValidUniqueLedgerEntries(256);
auto ledgers =
LedgerTestUtils::generateValidUniqueLedgerEntriesWithExclusions(
marta-lokhova marked this conversation as resolved.
Show resolved Hide resolved
{CONFIG_SETTING}, 256);
for (uint32_t ledgerSeq = 1; ledgerSeq <= 256; ++ledgerSeq)
{
if (ledgerSeq >= 2)
Expand All @@ -688,7 +699,7 @@ TEST_CASE("BucketList check bucket sizes", "[bucket][bucketlist][count]")
TEST_CASE_VERSIONS("network config snapshots BucketList size", "[bucketlist]")
{
VirtualClock clock;
Config cfg(getTestConfig(0, Config::TESTDB_IN_MEMORY_SQLITE));
Config cfg(getTestConfig(0, Config::TESTDB_IN_MEMORY_NO_OFFERS));
cfg.USE_CONFIG_FOR_GENESIS = true;

auto app = createTestApplication<BucketTestApplication>(clock, cfg);
Expand Down Expand Up @@ -760,7 +771,10 @@ TEST_CASE_VERSIONS("network config snapshots BucketList size", "[bucketlist]")
}

lm.setNextLedgerEntryBatchForBucketTesting(
{}, LedgerTestUtils::generateValidUniqueLedgerEntries(10), {});
{},
LedgerTestUtils::generateValidUniqueLedgerEntriesWithExclusions(
{CONFIG_SETTING}, 10),
{});
closeLedger(*app);
if ((ledger + 1) % networkConfig.stateArchivalSettings()
.bucketListWindowSamplePeriod ==
Expand All @@ -775,7 +789,7 @@ TEST_CASE_VERSIONS("network config snapshots BucketList size", "[bucketlist]")
TEST_CASE_VERSIONS("eviction scan", "[bucketlist]")
{
VirtualClock clock;
Config cfg(getTestConfig(0, Config::TESTDB_IN_MEMORY_SQLITE));
Config cfg(getTestConfig());
cfg.USE_CONFIG_FOR_GENESIS = true;

auto test = [&](bool backgroundScan) {
Expand Down Expand Up @@ -1250,7 +1264,7 @@ TEST_CASE_VERSIONS("eviction scan", "[bucketlist]")
TEST_CASE_VERSIONS("Searchable BucketListDB snapshots", "[bucketlist]")
{
VirtualClock clock;
Config cfg(getTestConfig(0, Config::TESTDB_IN_MEMORY_SQLITE));
Config cfg(getTestConfig());
cfg.DEPRECATED_SQL_LEDGER_STATE = false;

auto app = createTestApplication<BucketTestApplication>(clock, cfg);
Expand Down
43 changes: 28 additions & 15 deletions src/bucket/test/BucketManagerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ TEST_CASE_VERSIONS("bucketmanager ownership", "[bucket][bucketmanager]")
Application::pointer app = createTestApplication(clock, cfg);

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

std::shared_ptr<Bucket> b1;
Expand Down Expand Up @@ -303,7 +304,7 @@ TEST_CASE_VERSIONS("bucketmanager ownership", "[bucket][bucketmanager]")

TEST_CASE("bucketmanager missing buckets fail", "[bucket][bucketmanager]")
{
Config cfg(getTestConfig(0, Config::TESTDB_ON_DISK_SQLITE));
Config cfg(getTestConfig(0, Config::TESTDB_BUCKET_DB_PERSISTENT));
std::string someBucketFileName;
{
VirtualClock clock;
Expand All @@ -318,7 +319,10 @@ TEST_CASE("bucketmanager missing buckets fail", "[bucket][bucketmanager]")
{
++ledger;
lm.setNextLedgerEntryBatchForBucketTesting(
{}, LedgerTestUtils::generateValidUniqueLedgerEntries(10), {});
{},
LedgerTestUtils::generateValidUniqueLedgerEntriesWithExclusions(
{CONFIG_SETTING}, 10),
{});
closeLedger(*app);
} while (!BucketList::levelShouldSpill(ledger, level - 1));
auto someBucket = bl.getLevel(1).getCurr();
Expand All @@ -341,7 +345,7 @@ TEST_CASE_VERSIONS("bucketmanager reattach to finished merge",
"[bucket][bucketmanager]")
{
VirtualClock clock;
Config cfg(getTestConfig(0, Config::TESTDB_IN_MEMORY_SQLITE));
Config cfg(getTestConfig());
cfg.ARTIFICIALLY_PESSIMIZE_MERGES_FOR_TESTING = true;
cfg.MANUAL_CLOSE = false;

Expand All @@ -363,7 +367,9 @@ TEST_CASE_VERSIONS("bucketmanager reattach to finished merge",
lh.ledgerSeq = ledger;
addBatchAndUpdateSnapshot(
bl, *app, lh, {},
LedgerTestUtils::generateValidUniqueLedgerEntries(10), {});
LedgerTestUtils::generateValidLedgerEntriesWithExclusions(
{CONFIG_SETTING}, 10),
{});
bm.forgetUnreferencedBuckets();
} while (!BucketList::levelShouldSpill(ledger, level - 1));

Expand Down Expand Up @@ -406,7 +412,7 @@ TEST_CASE_VERSIONS("bucketmanager reattach to running merge",
"[bucket][bucketmanager]")
{
VirtualClock clock;
Config cfg(getTestConfig(0, Config::TESTDB_IN_MEMORY_SQLITE));
Config cfg(getTestConfig(0, Config::TESTDB_BUCKET_DB_PERSISTENT));
cfg.ARTIFICIALLY_PESSIMIZE_MERGES_FOR_TESTING = true;
cfg.MANUAL_CLOSE = false;

Expand Down Expand Up @@ -450,7 +456,9 @@ TEST_CASE_VERSIONS("bucketmanager reattach to running merge",
lh.ledgerSeq = ledger;
addBatchAndUpdateSnapshot(
bl, *app, lh, {},
LedgerTestUtils::generateValidUniqueLedgerEntries(100), {});
LedgerTestUtils::generateValidUniqueLedgerEntriesWithExclusions(
{CONFIG_SETTING}, 100),
{});

bm.forgetUnreferencedBuckets();

Expand Down Expand Up @@ -488,9 +496,10 @@ TEST_CASE("bucketmanager do not leak empty-merge futures",
// The point of this test is to confirm that
// BucketManager::noteEmptyMergeOutput is being called properly from merges
// that produce empty outputs, and that the input buckets to those merges
// are thereby not leaking.
// are thereby not leaking. Disable BucketListDB so that snapshots do not
// hold persist buckets, complicating bucket counting.
VirtualClock clock;
Config cfg(getTestConfig(0, Config::TESTDB_IN_MEMORY_SQLITE));
Config cfg(getTestConfig(0, Config::TESTDB_IN_MEMORY_NO_OFFERS));
cfg.ARTIFICIALLY_PESSIMIZE_MERGES_FOR_TESTING = true;
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION =
static_cast<uint32_t>(
Expand Down Expand Up @@ -588,7 +597,9 @@ TEST_CASE_VERSIONS(
lh.ledgerSeq++;
addBatchAndUpdateSnapshot(
bl, *app, lh, {},
LedgerTestUtils::generateValidUniqueLedgerEntries(100), {});
LedgerTestUtils::generateValidUniqueLedgerEntriesWithExclusions(
{CONFIG_SETTING}, 100),
{});
clock.crank(false);
bm.forgetUnreferencedBuckets();
}
Expand Down Expand Up @@ -1064,7 +1075,7 @@ class StopAndRestartBucketMergesTest
collectControlSurveys()
{
VirtualClock clock;
Config cfg(getTestConfig(0, Config::TESTDB_IN_MEMORY_SQLITE));
Config cfg(getTestConfig(0, Config::TESTDB_BUCKET_DB_PERSISTENT));
cfg.ARTIFICIALLY_PESSIMIZE_MERGES_FOR_TESTING = true;
cfg.ARTIFICIALLY_REDUCE_MERGE_COUNTS_FOR_TESTING = true;
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION = mProtocol;
Expand Down Expand Up @@ -1175,10 +1186,11 @@ class StopAndRestartBucketMergesTest
runStopAndRestartTest(uint32_t firstProtocol, uint32_t secondProtocol)
{
std::unique_ptr<VirtualClock> clock = std::make_unique<VirtualClock>();
Config cfg(getTestConfig(0, Config::TESTDB_ON_DISK_SQLITE));
Config cfg(getTestConfig(0, Config::TESTDB_BUCKET_DB_PERSISTENT));
cfg.ARTIFICIALLY_PESSIMIZE_MERGES_FOR_TESTING = true;
cfg.ARTIFICIALLY_REDUCE_MERGE_COUNTS_FOR_TESTING = true;
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION = firstProtocol;
cfg.INVARIANT_CHECKS = {};
assert(!mDesignatedLedgers.empty());
uint32_t finalLedger = (*mDesignatedLedgers.rbegin()) + 1;
uint32_t currProtocol = firstProtocol;
Expand Down Expand Up @@ -1367,17 +1379,18 @@ TEST_CASE_VERSIONS("bucket persistence over app restart",
std::vector<stellar::LedgerKey> emptySet;
std::vector<stellar::LedgerEntry> emptySetEntry;

Config cfg0(getTestConfig(0, Config::TESTDB_ON_DISK_SQLITE));
Config cfg0(getTestConfig(0, Config::TESTDB_BUCKET_DB_PERSISTENT));
cfg0.MANUAL_CLOSE = false;

for_versions_with_differing_bucket_logic(cfg0, [&](Config const& cfg0) {
Config cfg1(getTestConfig(1, Config::TESTDB_ON_DISK_SQLITE));
Config cfg1(getTestConfig(1, Config::TESTDB_BUCKET_DB_PERSISTENT));
cfg1.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION =
cfg0.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION;
cfg1.ARTIFICIALLY_PESSIMIZE_MERGES_FOR_TESTING = true;

auto batch_entries =
LedgerTestUtils::generateValidUniqueLedgerEntries(111);
LedgerTestUtils::generateValidUniqueLedgerEntriesWithExclusions(
{CONFIG_SETTING, OFFER}, 111);
auto alice = batch_entries.back();
batch_entries.pop_back();
std::vector<std::vector<LedgerEntry>> batches;
Expand Down
3 changes: 2 additions & 1 deletion src/bucket/test/BucketMergeMapTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ TEST_CASE("bucket merge map", "[bucket][bucketmergemap]")

auto getValidBucket = [&](int numEntries = 10) {
std::vector<LedgerEntry> live =
LedgerTestUtils::generateValidUniqueLedgerEntries(numEntries);
LedgerTestUtils::generateValidUniqueLedgerEntriesWithExclusions(
{CONFIG_SETTING}, numEntries);
std::shared_ptr<Bucket> b1 = Bucket::fresh(
app->getBucketManager(), BucketTestUtils::getAppLedgerVersion(app),
{}, live, {},
Expand Down
18 changes: 5 additions & 13 deletions src/bucket/test/BucketTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ TEST_CASE_VERSIONS("merging bucket entries", "[bucket]")
SECTION("random live entries overwrite live entries in any order")
{
std::vector<LedgerEntry> live =
LedgerTestUtils::generateValidUniqueLedgerEntries(100);
LedgerTestUtils::generateValidUniqueLedgerEntriesWithExclusions(
{CONFIG_SETTING}, 100);
std::vector<LedgerKey> dead;
std::shared_ptr<Bucket> b1 = Bucket::fresh(
app->getBucketManager(), getAppLedgerVersion(app), {}, live,
Expand Down Expand Up @@ -910,10 +911,10 @@ TEST_CASE_VERSIONS("merging bucket entries with initentry with shadows",
});
}

TEST_CASE_VERSIONS("bucket apply", "[bucket]")
TEST_CASE_VERSIONS("legacy bucket apply", "[bucket]")
{
VirtualClock clock;
Config cfg(getTestConfig());
Config cfg(getTestConfig(0, Config::TESTDB_IN_MEMORY_OFFERS));
for_versions_with_differing_bucket_logic(cfg, [&](Config const& cfg) {
Application::pointer app = createTestApplication(clock, cfg);

Expand Down Expand Up @@ -983,14 +984,5 @@ TEST_CASE("bucket apply bench", "[bucketbench][!hide]")
birth->apply(*app);
};

SECTION("sqlite")
{
runtest(Config::TESTDB_ON_DISK_SQLITE);
}
#ifdef USE_POSTGRES
SECTION("postgresql")
{
runtest(Config::TESTDB_POSTGRESQL);
}
#endif
runtest(Config::TESTDB_BUCKET_DB_PERSISTENT);
}
4 changes: 2 additions & 2 deletions src/database/test/DatabaseTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ transactionTest(Application::pointer app)

TEST_CASE("database smoketest", "[db]")
{
Config const& cfg = getTestConfig(0, Config::TESTDB_IN_MEMORY_SQLITE);
Config const& cfg = getTestConfig(0, Config::TESTDB_IN_MEMORY_OFFERS);

VirtualClock clock;
Application::pointer app = createTestApplication(clock, cfg, true, false);
Expand Down Expand Up @@ -349,7 +349,7 @@ TEST_CASE("postgres performance", "[db][pgperf][!hide]")

TEST_CASE("schema test", "[db]")
{
Config const& cfg = getTestConfig(0, Config::TESTDB_IN_MEMORY_SQLITE);
Config const& cfg = getTestConfig(0, Config::TESTDB_IN_MEMORY_OFFERS);

VirtualClock clock;
Application::pointer app = createTestApplication(clock, cfg);
Expand Down
Loading
Loading