@@ -77,18 +77,6 @@ Bucket::Bucket()
77
77
{
78
78
}
79
79
80
- XDRInputFileStream&
81
- Bucket::getStream ()
82
- {
83
- if (!mStream )
84
- {
85
- mStream = std::make_unique<XDRInputFileStream>();
86
- releaseAssertOrThrow (!mFilename .empty ());
87
- mStream ->open (mFilename .string ());
88
- }
89
- return *mStream ;
90
- }
91
-
92
80
Hash const &
93
81
Bucket::getHash () const
94
82
{
@@ -139,157 +127,6 @@ void
139
127
Bucket::freeIndex ()
140
128
{
141
129
mIndex .reset (nullptr );
142
- mStream .reset (nullptr );
143
- }
144
-
145
- std::optional<BucketEntry>
146
- Bucket::getEntryAtOffset (LedgerKey const & k, std::streamoff pos,
147
- size_t pageSize)
148
- {
149
- ZoneScoped;
150
- auto & stream = getStream ();
151
- stream.seek (pos);
152
-
153
- BucketEntry be;
154
- if (pageSize == 0 )
155
- {
156
- if (stream.readOne (be))
157
- {
158
- return std::make_optional (be);
159
- }
160
- }
161
- else if (stream.readPage (be, k, pageSize))
162
- {
163
- return std::make_optional (be);
164
- }
165
-
166
- // Mark entry miss for metrics
167
- getIndex ().markBloomMiss ();
168
- return std::nullopt;
169
- }
170
-
171
- std::optional<BucketEntry>
172
- Bucket::getBucketEntry (LedgerKey const & k)
173
- {
174
- ZoneScoped;
175
- auto pos = getIndex ().lookup (k);
176
- if (pos.has_value ())
177
- {
178
- return getEntryAtOffset (k, pos.value (), getIndex ().getPageSize ());
179
- }
180
-
181
- return std::nullopt;
182
- }
183
-
184
- // When searching for an entry, BucketList calls this function on every bucket.
185
- // Since the input is sorted, we do a binary search for the first key in keys.
186
- // If we find the entry, we remove the found key from keys so that later buckets
187
- // do not load shadowed entries. If we don't find the entry, we do not remove it
188
- // from keys so that it will be searched for again at a lower level.
189
- void
190
- Bucket::loadKeys (std::set<LedgerKey, LedgerEntryIdCmp>& keys,
191
- std::vector<LedgerEntry>& result)
192
- {
193
- ZoneScoped;
194
-
195
- auto currKeyIt = keys.begin ();
196
- auto const & index = getIndex ();
197
- auto indexIter = index .begin ();
198
- while (currKeyIt != keys.end () && indexIter != index .end ())
199
- {
200
- auto [offOp, newIndexIter] = index .scan (indexIter, *currKeyIt);
201
- indexIter = newIndexIter;
202
- if (offOp)
203
- {
204
- auto entryOp =
205
- getEntryAtOffset (*currKeyIt, *offOp, getIndex ().getPageSize ());
206
- if (entryOp)
207
- {
208
- if (entryOp->type () != DEADENTRY)
209
- {
210
- result.push_back (entryOp->liveEntry ());
211
- }
212
-
213
- currKeyIt = keys.erase (currKeyIt);
214
- continue ;
215
- }
216
- }
217
-
218
- ++currKeyIt;
219
- }
220
- }
221
-
222
- void
223
- Bucket::loadPoolShareTrustLinessByAccount (
224
- AccountID const & accountID, UnorderedSet<LedgerKey>& deadTrustlines,
225
- UnorderedMap<LedgerKey, LedgerEntry>& liquidityPoolKeyToTrustline,
226
- LedgerKeySet& liquidityPoolKeys)
227
- {
228
- ZoneScoped;
229
-
230
- // Takes a LedgerKey or LedgerEntry::_data_t, returns true if entry is a
231
- // poolshare trusline for the given accountID
232
- auto trustlineCheck = [&accountID](auto const & entry) {
233
- return entry.type () == TRUSTLINE &&
234
- entry.trustLine ().asset .type () == ASSET_TYPE_POOL_SHARE &&
235
- entry.trustLine ().accountID == accountID;
236
- };
237
-
238
- // Get upper and lower bound for poolshare trustline range associated
239
- // with this account
240
- auto searchRange = getIndex ().getPoolshareTrustlineRange (accountID);
241
- if (searchRange.first == 0 )
242
- {
243
- // No poolshare trustlines, exit
244
- return ;
245
- }
246
-
247
- BucketEntry be;
248
- auto & stream = getStream ();
249
- stream.seek (searchRange.first );
250
- while (stream && stream.pos () < searchRange.second && stream.readOne (be))
251
- {
252
- LedgerEntry entry;
253
- switch (be.type ())
254
- {
255
- case LIVEENTRY:
256
- case INITENTRY:
257
- entry = be.liveEntry ();
258
- break ;
259
- case DEADENTRY:
260
- {
261
- auto key = be.deadEntry ();
262
-
263
- // If we find a valid trustline key and we have not seen the
264
- // key yet, mark it as dead so we do not load a shadowed version
265
- // later
266
- if (trustlineCheck (key))
267
- {
268
- deadTrustlines.emplace (key);
269
- }
270
- continue ;
271
- }
272
- case METAENTRY:
273
- default :
274
- throw std::invalid_argument (" Indexed METAENTRY" );
275
- }
276
-
277
- // If this is a pool share trustline that matches the accountID and
278
- // is not shadowed, add it to results
279
- if (trustlineCheck (entry.data ) &&
280
- deadTrustlines.find (LedgerEntryKey (entry)) == deadTrustlines.end ())
281
- {
282
- auto const & poolshareID =
283
- entry.data .trustLine ().asset .liquidityPoolID ();
284
-
285
- LedgerKey key;
286
- key.type (LIQUIDITY_POOL);
287
- key.liquidityPool ().liquidityPoolID = poolshareID;
288
-
289
- liquidityPoolKeyToTrustline.emplace (key, entry);
290
- liquidityPoolKeys.emplace (key);
291
- }
292
- }
293
130
}
294
131
295
132
#ifdef BUILD_TESTS
@@ -837,12 +674,12 @@ mergeCasesWithEqualKeys(MergeCounters& mc, BucketInputIterator& oi,
837
674
}
838
675
839
676
bool
840
- Bucket::scanForEviction (AbstractLedgerTxn& ltx, EvictionIterator& iter,
841
- uint64_t & bytesToScan, uint32_t & maxEntriesToEvict ,
842
- uint32_t ledgerSeq,
843
- medida::Counter& entriesEvictedCounter,
844
- medida::Counter& bytesScannedForEvictionCounter,
845
- std::optional<EvictionMetrics >& metrics)
677
+ Bucket::scanForEvictionLegacySQL (
678
+ AbstractLedgerTxn& ltx, EvictionIterator& iter, uint64_t & bytesToScan ,
679
+ uint32_t & maxEntriesToEvict, uint32_t ledgerSeq,
680
+ medida::Counter& entriesEvictedCounter,
681
+ medida::Counter& bytesScannedForEvictionCounter,
682
+ std::optional<EvictionStatistics >& stats) const
846
683
{
847
684
ZoneScoped;
848
685
if (isEmpty ())
@@ -857,7 +694,8 @@ Bucket::scanForEviction(AbstractLedgerTxn& ltx, EvictionIterator& iter,
857
694
return true ;
858
695
}
859
696
860
- auto & stream = getStream ();
697
+ XDRInputFileStream stream{};
698
+ stream.open (mFilename );
861
699
stream.seek (iter.bucketFileOffset );
862
700
863
701
BucketEntry be;
@@ -898,10 +736,10 @@ Bucket::scanForEviction(AbstractLedgerTxn& ltx, EvictionIterator& iter,
898
736
if (shouldEvict ())
899
737
{
900
738
ZoneNamedN (evict, " evict entry" , true );
901
- if (metrics .has_value ())
739
+ if (stats .has_value ())
902
740
{
903
- ++metrics ->numEntriesEvicted ;
904
- metrics ->evictedEntriesAgeSum +=
741
+ ++stats ->numEntriesEvicted ;
742
+ stats ->evictedEntriesAgeSum +=
905
743
ledgerSeq - liveUntilLedger;
906
744
}
907
745
0 commit comments