7
7
// else.
8
8
#include " util/asio.h" // IWYU pragma: keep
9
9
#include " bucket/BucketBase.h"
10
- #include " bucket/BucketIndex.h"
11
10
#include " bucket/BucketInputIterator.h"
12
11
#include " bucket/BucketManager.h"
13
12
#include " bucket/BucketOutputIterator.h"
30
29
namespace stellar
31
30
{
32
31
33
- BucketIndex const &
34
- BucketBase::getIndex () const
32
+ template <class BucketT , class IndexT >
33
+ IndexT const &
34
+ BucketBase<BucketT, IndexT>::getIndex() const
35
35
{
36
36
ZoneScoped;
37
37
releaseAssertOrThrow (!mFilename .empty ());
38
38
releaseAssertOrThrow (mIndex );
39
39
return *mIndex ;
40
40
}
41
41
42
+ template <class BucketT , class IndexT >
42
43
bool
43
- BucketBase::isIndexed () const
44
+ BucketBase<BucketT, IndexT> ::isIndexed() const
44
45
{
45
46
return static_cast <bool >(mIndex );
46
47
}
47
48
48
- std::optional<std::pair<std::streamoff, std::streamoff>>
49
- BucketBase::getOfferRange () const
50
- {
51
- return getIndex ().getOfferRange ();
52
- }
53
-
49
+ template <class BucketT , class IndexT >
54
50
void
55
- BucketBase::setIndex (std::unique_ptr<BucketIndex const >&& index)
51
+ BucketBase<BucketT, IndexT> ::setIndex(std::unique_ptr<IndexT const >&& index)
56
52
{
57
53
releaseAssertOrThrow (!mIndex );
58
54
mIndex = std::move (index );
59
55
}
60
56
61
- BucketBase::BucketBase (std::string const & filename, Hash const & hash,
62
- std::unique_ptr<BucketIndex const >&& index)
57
+ template <class BucketT , class IndexT >
58
+ BucketBase<BucketT, IndexT>::BucketBase(std::string const & filename,
59
+ Hash const & hash,
60
+ std::unique_ptr<IndexT const >&& index)
63
61
: mFilename (filename), mHash (hash), mIndex (std::move(index))
64
62
{
65
63
releaseAssert (filename.empty () || fs::exists (filename));
@@ -71,30 +69,34 @@ BucketBase::BucketBase(std::string const& filename, Hash const& hash,
71
69
}
72
70
}
73
71
74
- BucketBase::BucketBase ()
72
+ template < class BucketT , class IndexT > BucketBase<BucketT, IndexT> ::BucketBase()
75
73
{
76
74
}
77
75
76
+ template <class BucketT , class IndexT >
78
77
Hash const &
79
- BucketBase::getHash () const
78
+ BucketBase<BucketT, IndexT> ::getHash() const
80
79
{
81
80
return mHash ;
82
81
}
83
82
83
+ template <class BucketT , class IndexT >
84
84
std::filesystem::path const &
85
- BucketBase::getFilename () const
85
+ BucketBase<BucketT, IndexT> ::getFilename() const
86
86
{
87
87
return mFilename ;
88
88
}
89
89
90
+ template <class BucketT , class IndexT >
90
91
size_t
91
- BucketBase::getSize () const
92
+ BucketBase<BucketT, IndexT> ::getSize() const
92
93
{
93
94
return mSize ;
94
95
}
95
96
97
+ template <class BucketT , class IndexT >
96
98
bool
97
- BucketBase::isEmpty () const
99
+ BucketBase<BucketT, IndexT> ::isEmpty() const
98
100
{
99
101
if (mFilename .empty () || isZero (mHash ))
100
102
{
@@ -105,14 +107,17 @@ BucketBase::isEmpty() const
105
107
return false ;
106
108
}
107
109
110
+ template <class BucketT , class IndexT >
108
111
void
109
- BucketBase::freeIndex ()
112
+ BucketBase<BucketT, IndexT> ::freeIndex()
110
113
{
111
114
mIndex .reset (nullptr );
112
115
}
113
116
117
+ template <class BucketT , class IndexT >
114
118
std::string
115
- BucketBase::randomFileName (std::string const & tmpDir, std::string ext)
119
+ BucketBase<BucketT, IndexT>::randomFileName(std::string const & tmpDir,
120
+ std::string ext)
116
121
{
117
122
ZoneScoped;
118
123
for (;;)
@@ -127,14 +132,16 @@ BucketBase::randomFileName(std::string const& tmpDir, std::string ext)
127
132
}
128
133
}
129
134
135
+ template <class BucketT , class IndexT >
130
136
std::string
131
- BucketBase::randomBucketName (std::string const & tmpDir)
137
+ BucketBase<BucketT, IndexT> ::randomBucketName(std::string const & tmpDir)
132
138
{
133
139
return randomFileName (tmpDir, " .xdr" );
134
140
}
135
141
142
+ template <class BucketT , class IndexT >
136
143
std::string
137
- BucketBase::randomBucketIndexName (std::string const & tmpDir)
144
+ BucketBase<BucketT, IndexT> ::randomBucketIndexName(std::string const & tmpDir)
138
145
{
139
146
return randomFileName (tmpDir, " .index" );
140
147
}
@@ -172,7 +179,7 @@ BucketBase::randomBucketIndexName(std::string const& tmpDir)
172
179
// and shadowing protocol simultaneously, the moment the first new-protocol
173
180
// bucket enters the youngest level. At least one new bucket is in every merge's
174
181
// shadows from then on in, so they all upgrade (and preserve lifecycle events).
175
- template <class BucketT >
182
+ template <class BucketT , class IndexT >
176
183
static void
177
184
calculateMergeProtocolVersion (
178
185
MergeCounters& mc, uint32_t maxProtocolVersion,
@@ -253,7 +260,7 @@ calculateMergeProtocolVersion(
253
260
// side, or entries that compare non-equal. In all these cases we just
254
261
// take the lesser (or existing) entry and advance only one iterator,
255
262
// not scrutinizing the entry type further.
256
- template <class BucketT >
263
+ template <class BucketT , class IndexT >
257
264
static bool
258
265
mergeCasesWithDefaultAcceptance (
259
266
BucketEntryIdCmp<BucketT> const & cmp, MergeCounters& mc,
@@ -299,14 +306,15 @@ mergeCasesWithDefaultAcceptance(
299
306
return false ;
300
307
}
301
308
302
- template <class BucketT >
309
+ template <class BucketT , class IndexT >
303
310
std::shared_ptr<BucketT>
304
- BucketBase::merge (BucketManager& bucketManager, uint32_t maxProtocolVersion,
305
- std::shared_ptr<BucketT> const & oldBucket,
306
- std::shared_ptr<BucketT> const & newBucket,
307
- std::vector<std::shared_ptr<BucketT>> const & shadows,
308
- bool keepTombstoneEntries, bool countMergeEvents,
309
- asio::io_context& ctx, bool doFsync)
311
+ BucketBase<BucketT, IndexT>::merge(
312
+ BucketManager& bucketManager, uint32_t maxProtocolVersion,
313
+ std::shared_ptr<BucketT> const & oldBucket,
314
+ std::shared_ptr<BucketT> const & newBucket,
315
+ std::vector<std::shared_ptr<BucketT>> const & shadows,
316
+ bool keepTombstoneEntries, bool countMergeEvents, asio::io_context& ctx,
317
+ bool doFsync)
310
318
{
311
319
BUCKET_TYPE_ASSERT (BucketT);
312
320
@@ -326,9 +334,9 @@ BucketBase::merge(BucketManager& bucketManager, uint32_t maxProtocolVersion,
326
334
327
335
uint32_t protocolVersion;
328
336
bool keepShadowedLifecycleEntries;
329
- calculateMergeProtocolVersion<BucketT>(mc, maxProtocolVersion, oi, ni,
330
- shadowIterators, protocolVersion,
331
- keepShadowedLifecycleEntries);
337
+ calculateMergeProtocolVersion<BucketT, IndexT>(
338
+ mc, maxProtocolVersion, oi, ni, shadowIterators, protocolVersion,
339
+ keepShadowedLifecycleEntries);
332
340
333
341
auto timer = bucketManager.getMergeTimer ().TimeScope ();
334
342
BucketMetadata meta;
@@ -340,14 +348,14 @@ BucketBase::merge(BucketManager& bucketManager, uint32_t maxProtocolVersion,
340
348
{
341
349
releaseAssertOrThrow (protocolVersionStartsFrom (
342
350
maxProtocolVersion,
343
- BucketBase ::FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION));
351
+ BucketT ::FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION));
344
352
meta.ext = ni.getMetadata ().ext ;
345
353
}
346
354
else if (oi.getMetadata ().ext .v () == 1 )
347
355
{
348
356
releaseAssertOrThrow (protocolVersionStartsFrom (
349
357
maxProtocolVersion,
350
- BucketBase ::FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION));
358
+ BucketT ::FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION));
351
359
meta.ext = oi.getMetadata ().ext ;
352
360
}
353
361
@@ -374,9 +382,9 @@ BucketBase::merge(BucketManager& bucketManager, uint32_t maxProtocolVersion,
374
382
}
375
383
}
376
384
377
- if (!mergeCasesWithDefaultAcceptance (cmp, mc, oi, ni, out,
378
- shadowIterators, protocolVersion,
379
- keepShadowedLifecycleEntries))
385
+ if (!mergeCasesWithDefaultAcceptance<BucketT, IndexT>(
386
+ cmp, mc, oi, ni, out, shadowIterators, protocolVersion,
387
+ keepShadowedLifecycleEntries))
380
388
{
381
389
BucketT::mergeCasesWithEqualKeys (mc, oi, ni, out, shadowIterators,
382
390
protocolVersion,
@@ -400,19 +408,6 @@ BucketBase::merge(BucketManager& bucketManager, uint32_t maxProtocolVersion,
400
408
return out.getBucket (bucketManager, &mk);
401
409
}
402
410
403
- template std::shared_ptr<LiveBucket> BucketBase::merge<LiveBucket>(
404
- BucketManager& bucketManager, uint32_t maxProtocolVersion,
405
- std::shared_ptr<LiveBucket> const & oldBucket,
406
- std::shared_ptr<LiveBucket> const & newBucket,
407
- std::vector<std::shared_ptr<LiveBucket>> const & shadows,
408
- bool keepTombstoneEntries, bool countMergeEvents, asio::io_context& ctx,
409
- bool doFsync);
410
-
411
- template std::shared_ptr<HotArchiveBucket> BucketBase::merge<HotArchiveBucket>(
412
- BucketManager& bucketManager, uint32_t maxProtocolVersion,
413
- std::shared_ptr<HotArchiveBucket> const & oldBucket,
414
- std::shared_ptr<HotArchiveBucket> const & newBucket,
415
- std::vector<std::shared_ptr<HotArchiveBucket>> const & shadows,
416
- bool keepTombstoneEntries, bool countMergeEvents, asio::io_context& ctx,
417
- bool doFsync);
411
+ template class BucketBase <LiveBucket, LiveBucket::IndexT>;
412
+ template class BucketBase <HotArchiveBucket, HotArchiveBucket::IndexT>;
418
413
}
0 commit comments