]> git.hungrycats.org Git - bees/commitdiff
roots: log both extents when a duplicate scan is dropped
authorZygo Blaxell <bees@furryterror.org>
Tue, 1 Sep 2026 04:39:41 +0000 (00:39 -0400)
committerZygo Blaxell <bees@furryterror.org>
Sat, 10 Oct 2026 19:00:05 +0000 (15:00 -0400)
crawl_extent_dup recorded that a duplicate was dropped but nothing
about what was dropped or what it collided with, which discards the
informative part.  The duplicates seen on the reference corpus
disagreed about the extent itself:

  Task ID 19464  32M_2889dba000_12M      waiting 1473s
  Task ID 27833  32M_2889dba000_20.121M  waiting 1245s

Same tier, same bytenr, different sizes -- two scans built from
different views of what extent lives at that address, which is a
different fault from one extent queued twice from a single view.  A
counter cannot tell those apart.

Carry the identifying detail in the claim and report both sides:

  crawl_extent_dup: extent already queued for scanning
      in flight: tier 32M bytenr 0x2889dba000 size 12M gen 1611 queued 1473s ago
      dropped:   tier 32M bytenr 0x2889dba000 size 20.121M gen 1618 queued 0s ago

The claim holds scalars rather than a BeesExtent, so it does not pin a
node in the layer cache for the lifetime of the scan.

Assisted-by: Claude-Code:claude-opus-5
src/bees-roots.cc

index 24d539b45a09424c08d00336991eab982717591e..91c08a0ee286496693e4549a1c59b0c92dde80ac 100644 (file)
@@ -546,13 +546,24 @@ class BeesScanModeExtent : public BeesScanMode {
        /// cannot run, they hold crawl progress holds while they wait, and
        /// they keep the crawler from ever reporting itself idle.
        mutex m_inflight_mutex;
-       set<uint64_t> m_inflight;
 public:
-       /// Claim @p bytenr for scanning.  False if already queued.
-       bool inflight_insert(uint64_t bytenr);
+       /// Identifying detail of an extent claimed for scanning.  Kept as
+       /// scalars rather than a BeesExtent so a claim does not pin a node
+       /// in the layer cache for as long as the scan runs.
+       struct InflightExtent {
+               string          m_tier;
+               uint64_t        m_bytenr = 0;
+               uint64_t        m_length = 0;
+               uint64_t        m_gen = 0;
+               time_t          m_queued = 0;
+       };
+       /// Claim an extent for scanning.  On failure @p existing is filled
+       /// in with the claim already held, so the caller can report both.
+       bool inflight_insert(const InflightExtent &e, InflightExtent &existing);
        /// Release a claim taken by inflight_insert().
        void inflight_erase(uint64_t bytenr);
 private:
+       map<uint64_t, InflightExtent> m_inflight;
        mutex m_insert_root_mutex;
 
        /// Size range [m_min_size, m_max_size] for one extent size tier.
@@ -1029,11 +1040,25 @@ BeesScanModeExtent::build_chunk_map() const
        return cm;
 }
 
+ostream &
+operator<<(ostream &os, const BeesScanModeExtent::InflightExtent &e)
+{
+       return os << "tier " << e.m_tier
+               << " bytenr " << to_hex(e.m_bytenr)
+               << " size " << pretty(e.m_length)
+               << " gen " << e.m_gen
+               << " queued " << (time(NULL) - e.m_queued) << "s ago";
+}
+
 bool
-BeesScanModeExtent::inflight_insert(const uint64_t bytenr)
+BeesScanModeExtent::inflight_insert(const InflightExtent &e, InflightExtent &existing)
 {
        unique_lock<mutex> lock(m_inflight_mutex);
-       return m_inflight.insert(bytenr).second;
+       const auto [it, inserted] = m_inflight.insert(make_pair(e.m_bytenr, e));
+       if (!inserted) {
+               existing = it->second;
+       }
+       return inserted;
 }
 
 void
@@ -1417,8 +1442,24 @@ BeesScanModeExtent::SizeTier::find_next_extent()
                        // hold, which is what keeps a crawler from ever reporting
                        // itself idle.  Claim the bytenr, and drop the extent if
                        // someone already has it.
-                       if (!m_bsme->inflight_insert(this_bytenr)) {
+                       const BeesScanModeExtent::InflightExtent this_inflight {
+                               .m_tier = m_name,
+                               .m_bytenr = this_bytenr,
+                               .m_length = this_length,
+                               .m_gen = gen,
+                               .m_queued = time(NULL),
+                       };
+                       BeesScanModeExtent::InflightExtent held_inflight;
+                       if (!m_bsme->inflight_insert(this_inflight, held_inflight)) {
+                               // Report both descriptions.  They routinely disagree
+                               // about size and generation, which is the interesting
+                               // part: two scans built from different views of what
+                               // extent lives at this address, not one extent queued
+                               // twice from one view.
                                BEESCOUNT(crawl_extent_dup);
+                               BEESLOGWARN("crawl_extent_dup: extent already queued for scanning\n"
+                                       << "\tin flight: " << held_inflight << "\n"
+                                       << "\tdropped:   " << this_inflight);
                                continue;
                        }
                        const auto bsme = m_bsme;