@@ -947,14 +947,19 @@ TEST_CASE_VERSIONS("network config snapshots BucketList size", "[bucketlist]")
947
947
});
948
948
}
949
949
950
- TEST_CASE_VERSIONS (" eviction scan" , " [bucketlist]" )
950
+ TEST_CASE_VERSIONS (" eviction scan" , " [bucketlist][archival] " )
951
951
{
952
952
VirtualClock clock ;
953
953
Config cfg (getTestConfig ());
954
954
cfg.USE_CONFIG_FOR_GENESIS = true ;
955
955
956
- auto app = createTestApplication<BucketTestApplication>(clock , cfg);
957
- for_versions_from (20 , *app, [&] {
956
+ auto test = [&](Config& cfg) {
957
+ auto app = createTestApplication<BucketTestApplication>(clock , cfg);
958
+
959
+ bool tempOnly = protocolVersionIsBefore (
960
+ cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION ,
961
+ BucketBase::FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION);
962
+
958
963
LedgerManagerForBucketTests& lm = app->getLedgerManager ();
959
964
auto & bm = app->getBucketManager ();
960
965
auto & bl = bm.getLiveBucketList ();
@@ -1019,12 +1024,19 @@ TEST_CASE_VERSIONS("eviction scan", "[bucketlist]")
1019
1024
std::set<LedgerKey> tempEntries;
1020
1025
std::set<LedgerKey> persistentEntries;
1021
1026
std::vector<LedgerEntry> entries;
1027
+
1022
1028
for (auto & e :
1023
1029
LedgerTestUtils::generateValidUniqueLedgerEntriesWithTypes (
1024
- {CONTRACT_DATA}, 50 ))
1030
+ {CONTRACT_DATA, CONTRACT_CODE }, 50 ))
1025
1031
{
1026
- // Set half of the entries to be persistent, half temporary
1027
- if (tempEntries.empty () || rand_flip ())
1032
+ if (e.data .type () == CONTRACT_CODE)
1033
+ {
1034
+ persistentEntries.emplace (LedgerEntryKey (e));
1035
+ }
1036
+
1037
+ // Set half of the contact data entries to be persistent, half
1038
+ // temporary
1039
+ else if (tempEntries.empty () || rand_flip ())
1028
1040
{
1029
1041
e.data .contractData ().durability = TEMPORARY;
1030
1042
tempEntries.emplace (LedgerEntryKey (e));
@@ -1058,6 +1070,53 @@ TEST_CASE_VERSIONS("eviction scan", "[bucketlist]")
1058
1070
closeLedger (*app);
1059
1071
}
1060
1072
1073
+ auto expectedEvictions = tempEntries.size ();
1074
+
1075
+ if (!tempOnly)
1076
+ {
1077
+ expectedEvictions += persistentEntries.size ();
1078
+ }
1079
+
1080
+ auto checkArchivedBucketList = [&] {
1081
+ if (!tempOnly)
1082
+ {
1083
+ auto archiveSnapshot =
1084
+ bm.getBucketSnapshotManager ()
1085
+ .copySearchableHotArchiveBucketListSnapshot ();
1086
+
1087
+ // Check that persisted entries have been inserted into
1088
+ // HotArchive
1089
+ for (auto const & k : persistentEntries)
1090
+ {
1091
+ auto archivedEntry = archiveSnapshot->load (k);
1092
+ REQUIRE (archivedEntry);
1093
+
1094
+ auto seen = false ;
1095
+ for (auto const & e : entries)
1096
+ {
1097
+ if (e == archivedEntry->archivedEntry ())
1098
+ {
1099
+ seen = true ;
1100
+ break ;
1101
+ }
1102
+ }
1103
+ REQUIRE (seen);
1104
+
1105
+ // Make sure TTL keys are not archived
1106
+ auto ttl = getTTLKey (k);
1107
+ auto archivedTTL = archiveSnapshot->load (ttl);
1108
+ REQUIRE (!archivedTTL);
1109
+ }
1110
+
1111
+ // Temp entries should not be archived
1112
+ for (auto const & k : tempEntries)
1113
+ {
1114
+ auto archivedEntry = archiveSnapshot->load (k);
1115
+ REQUIRE (!archivedEntry);
1116
+ }
1117
+ }
1118
+ };
1119
+
1061
1120
SECTION (" basic eviction test" )
1062
1121
{
1063
1122
// Set eviction to start at level where the entries
@@ -1069,10 +1128,12 @@ TEST_CASE_VERSIONS("eviction scan", "[bucketlist]")
1069
1128
closeLedger (*app);
1070
1129
++ledgerSeq;
1071
1130
checkIfEntryExists (tempEntries, false );
1072
- checkIfEntryExists (persistentEntries, true );
1131
+ checkIfEntryExists (persistentEntries, tempOnly );
1073
1132
1074
1133
auto & entriesEvictedCounter = bm.getEntriesEvictedCounter ();
1075
- REQUIRE (entriesEvictedCounter.count () == tempEntries.size ());
1134
+
1135
+ REQUIRE (entriesEvictedCounter.count () == expectedEvictions);
1136
+ checkArchivedBucketList ();
1076
1137
1077
1138
// Close ledgers until evicted DEADENTRYs merge with
1078
1139
// original INITENTRYs. This checks that BucketList
@@ -1086,7 +1147,7 @@ TEST_CASE_VERSIONS("eviction scan", "[bucketlist]")
1086
1147
closeLedger (*app);
1087
1148
}
1088
1149
1089
- REQUIRE (entriesEvictedCounter.count () == tempEntries. size () );
1150
+ REQUIRE (entriesEvictedCounter.count () == expectedEvictions );
1090
1151
}
1091
1152
1092
1153
SECTION (" shadowed entries not evicted" )
@@ -1127,7 +1188,7 @@ TEST_CASE_VERSIONS("eviction scan", "[bucketlist]")
1127
1188
auto & entriesEvictedCounter = bm.getEntriesEvictedCounter ();
1128
1189
auto prevIter = evictionIter;
1129
1190
for (auto prevCount = entriesEvictedCounter.count ();
1130
- prevCount < tempEntries. size () ;)
1191
+ prevCount < expectedEvictions ;)
1131
1192
{
1132
1193
closeLedger (*app);
1133
1194
@@ -1150,12 +1211,12 @@ TEST_CASE_VERSIONS("eviction scan", "[bucketlist]")
1150
1211
1151
1212
// All entries should have been evicted
1152
1213
checkIfEntryExists (tempEntries, false );
1153
- checkIfEntryExists (persistentEntries, true );
1214
+ checkIfEntryExists (persistentEntries, tempOnly);
1215
+ checkArchivedBucketList ();
1154
1216
}
1155
1217
1156
1218
SECTION (" maxEntriesToArchive with entry modified on eviction ledger" )
1157
1219
{
1158
-
1159
1220
// This test is for an edge case in background eviction.
1160
1221
// We want to test that if entry n should be the last entry
1161
1222
// evicted due to maxEntriesToArchive, but that entry is
@@ -1172,17 +1233,25 @@ TEST_CASE_VERSIONS("eviction scan", "[bucketlist]")
1172
1233
LedgerKey entryToEvict;
1173
1234
std::optional<uint64_t > expectedEndIterPosition{};
1174
1235
1236
+ auto willBeEvicited = [&](LedgerEntry const & le) {
1237
+ if (tempOnly)
1238
+ {
1239
+ return isTemporaryEntry (le.data );
1240
+ }
1241
+ else
1242
+ {
1243
+ return isSorobanEntry (le.data );
1244
+ }
1245
+ };
1246
+
1175
1247
for (LiveBucketInputIterator in (bl.getLevel (levelToScan).getCurr ());
1176
1248
in; ++in)
1177
1249
{
1178
- // Temp entries should be sorted before persistent in
1179
- // the Bucket
1180
1250
auto be = *in;
1181
1251
if (be.type () == INITENTRY || be.type () == LIVEENTRY)
1182
1252
{
1183
1253
auto le = be.liveEntry ();
1184
- if (le.data .type () == CONTRACT_DATA &&
1185
- le.data .contractData ().durability == TEMPORARY)
1254
+ if (willBeEvicited (le))
1186
1255
{
1187
1256
if (!entryToUpdate)
1188
1257
{
@@ -1388,7 +1457,9 @@ TEST_CASE_VERSIONS("eviction scan", "[bucketlist]")
1388
1457
testIterReset (false );
1389
1458
}
1390
1459
}
1391
- });
1460
+ };
1461
+
1462
+ for_versions (20 , Config::CURRENT_LEDGER_PROTOCOL_VERSION, cfg, test);
1392
1463
}
1393
1464
1394
1465
TEST_CASE_VERSIONS (" Searchable BucketListDB snapshots" , " [bucketlist]" )
0 commit comments