@@ -21,13 +21,10 @@ namespace stellar
21
21
* hashes them while writing to either destination. Produces a Bucket when done.
22
22
*/
23
23
template <typename BucketT>
24
- BucketOutputIterator<BucketT>::BucketOutputIterator(std::string const & tmpDir,
25
- bool keepTombstoneEntries,
26
- BucketMetadata const & meta,
27
- MergeCounters& mc,
28
- asio::io_context& ctx,
29
- bool doFsync,
30
- bool rewriteLiveToInitEntries)
24
+ BucketOutputIterator<BucketT>::BucketOutputIterator(
25
+ std::string const & tmpDir, bool keepTombstoneEntries,
26
+ BucketMetadata const & meta, MergeCounters& mc, asio::io_context& ctx,
27
+ bool doFsync, bool rewriteLiveToInitEntries)
31
28
: mFilename (BucketBase::randomBucketName(tmpDir))
32
29
, mOut (ctx, doFsync)
33
30
, mCtx (ctx)
@@ -159,27 +156,30 @@ BucketOutputIterator<BucketT>::put(typename BucketT::EntryT const& e)
159
156
mBuf = std::make_unique<typename BucketT::EntryT>();
160
157
}
161
158
162
- if (mRewriteLiveToInitEntries && e.type () == LIVEENTRY &&
163
- protocolVersionStartsFrom (
164
- mMeta .ledgerVersion ,
165
- Bucket::FIRST_PROTOCOL_SUPPORTING_INITENTRY_AND_METAENTRY))
166
- {
167
- // If mRewriteLiveToInitEntries, we also want to convert the LIVEENTRY
168
- // to an INITENTRY. This is because each level of the bucket list
169
- // contains only one entry per key, and per CAP-0020, INIT ENTRY implies
170
- // that either no entry with the same ledger key exists in an older
171
- // bucket. Therefore, all entries of type LIVEENTRY in the lowest level
172
- // are also of type INITENTRY.
173
- ++mMergeCounters .mOutputIteratorLiveToInitConversions ;
174
- // Make a copy of e and set the type of the new entry to INITENTRY.
175
- BucketEntry eCopy = e;
176
- eCopy.type (INITENTRY);
177
- *mBuf = eCopy;
178
- }
179
- else
159
+ if constexpr (std::is_same_v<BucketT, LiveBucket>)
180
160
{
181
- *mBuf = e;
161
+ if (mRewriteLiveToInitEntries && e.type () == LIVEENTRY &&
162
+ protocolVersionStartsFrom (
163
+ mMeta .ledgerVersion ,
164
+ BucketT::FIRST_PROTOCOL_SUPPORTING_INITENTRY_AND_METAENTRY))
165
+ {
166
+ // If mRewriteLiveToInitEntries, we also want to convert the
167
+ // LIVEENTRY to an INITENTRY. This is because each level of the
168
+ // bucket list contains only one entry per key, and per CAP-0020,
169
+ // INIT ENTRY implies that either no entry with the same ledger key
170
+ // exists in an older bucket. Therefore, all entries of type
171
+ // LIVEENTRY in the lowest level are also of type INITENTRY.
172
+ ++mMergeCounters .mOutputIteratorLiveToInitRewrites ;
173
+ ++mMergeCounters .mOutputIteratorBufferUpdates ;
174
+ // Make a copy of e and set the type of the new entry to INITENTRY.
175
+ typename BucketT::EntryT eCopy = e;
176
+ eCopy.type (INITENTRY);
177
+ *mBuf = eCopy;
178
+ return ;
179
+ }
182
180
}
181
+ // In any case, replace *mBuf with e.
182
+ *mBuf = e;
183
183
++mMergeCounters .mOutputIteratorBufferUpdates ;
184
184
}
185
185
0 commit comments