@@ -256,6 +256,12 @@ class Index0 : public IComboIndex {
256256 }
257257 } alloc_blk;
258258
259+ // Block rewrite tracking for telemetry
260+ struct rewrite_stats {
261+ uint64_t total_blocks_written = 0 ; // Total blocks written (in 512B units)
262+ uint64_t rewritten_blocks = 0 ; // Blocks that overwrote previous data
263+ } m_rewrite_stats;
264+
259265 // Index0(const set<SegmentMapping> &mapping) : mapping(mapping){};
260266
261267 Index0 (const SegmentMapping *pmappings = nullptr , size_t n = 0 ) {
@@ -314,6 +320,31 @@ class Index0 : public IComboIndex {
314320 virtual void insert (SegmentMapping m) override {
315321 if (m.length == 0 )
316322 return ;
323+
324+ // Track total blocks written for rewrite telemetry
325+ m_rewrite_stats.total_blocks_written += m.length ;
326+
327+ // Count blocks that will be overwritten (rewritten)
328+ uint64_t rewritten = 0 ;
329+ auto check_it = mapping.lower_bound (m);
330+ // Check previous mapping for overlap
331+ if (check_it != mapping.begin ()) {
332+ auto prev_it = std::prev (check_it);
333+ if (prev_it->end () > m.offset ) {
334+ // Previous mapping overlaps with new write
335+ rewritten += std::min (prev_it->end (), m.end ()) - m.offset ;
336+ }
337+ }
338+ // Check current and subsequent mappings for overlap
339+ for (auto it = check_it; it != mapping.end () && it->offset < m.end (); ++it) {
340+ uint64_t overlap_start = std::max (it->offset , m.offset );
341+ uint64_t overlap_end = std::min (it->end (), m.end ());
342+ if (overlap_end > overlap_start) {
343+ rewritten += overlap_end - overlap_start;
344+ }
345+ }
346+ m_rewrite_stats.rewritten_blocks += rewritten;
347+
317348 alloc_blk += m;
318349 auto it = mapping.lower_bound (m);
319350 if (it == mapping.end ()) {
@@ -369,6 +400,13 @@ class Index0 : public IComboIndex {
369400 return alloc_blk.m_alloc ;
370401 }
371402
403+ virtual RewriteStats rewrite_stats () const override {
404+ return RewriteStats{
405+ m_rewrite_stats.total_blocks_written ,
406+ m_rewrite_stats.rewritten_blocks
407+ };
408+ }
409+
372410 // returns the first and last mapping in the index
373411 // the there's no one, return an invalid mapping: [INVALID_OFFSET, 0) ==> 0
374412 virtual SegmentMapping front () const override {
0 commit comments