]> git.hungrycats.org Git - bees/commitdiff
context: route dedup() physical-address logging through bees_extent_addr
authorZygo Blaxell <bees@furryterror.org>
Thu, 23 Apr 2026 02:57:08 +0000 (22:57 -0400)
committerZygo Blaxell <bees@furryterror.org>
Tue, 6 Oct 2026 05:51:40 +0000 (01:51 -0400)
Replace the open-coded BeesAddress lookup in BeesContext::dedup() with
the new bees_extent_addr() / bees_extent_same_bytenr() helpers.

Three things go away:

  - The optional<BeesAddress> + addr_string() lambda + two try/catches
    that wrapped the legacy BeesAddress(int, off_t) constructor (which
    can throw on missing extents).  bees_extent_addr() never throws and
    renders {} for missing items, so the call sites become unconditional.

  - The {addr_string(...)} brace-wrapping in the BEESLOGINFO and BEESNOTE
    lines.  bees_extent_addr() returns its own braces, so the format
    string just embeds the call directly.

  - The first_addr / second_addr equality check via get_physical_or_zero(),
    replaced by a single bees_extent_same_bytenr() call that does the
    same "both defined and equal" check inside the helper.

Behavioural changes vs. the prior log output:

  - PREALLOC and compressed extents now render with a tag suffix
    (:prealloc, :zlib, :lzo, :zstd) instead of dropping back to
    "addr-unavailable" or printing only the bytenr.
  - HOLE/INLINE extents now render as {HOLE} / {INLINE} instead of
    triggering the catch path with "addr-unavailable".
  - The +OFFSET inside the braces is the data's logical offset within
    the uncompressed extent, not the physical bytenr-plus-something
    that the old BeesAddress<< produced for compressed extents.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: Zygo Blaxell <bees@furryterror.org>
src/bees-context.cc

index 1eb4ba6abc6062542002c55440ea31ebc3017eac..229e5a20b7ab92cf64dd7e48f26edd8f1eb4ea16 100644 (file)
@@ -169,13 +169,10 @@ BeesContext::dedup(const BeesRangePair &brp_in)
 
        BEESTOOLONG("dedup " << brp);
 
-       BeesAddress first_addr(brp.first.fd(), brp.first.begin());
-       BeesAddress second_addr(brp.second.fd(), brp.second.begin());
-
-       const auto first_gpoz = first_addr.get_physical_or_zero();
-       const auto second_gpoz = second_addr.get_physical_or_zero();
-       if (first_gpoz == second_gpoz) {
-               BEESLOGDEBUG("equal physical addresses " << first_addr << " and " << second_addr << " in dedup");
+       if (bees_extent_same_bytenr(m_root_fd, brp.first, brp.second)) {
+               BEESLOGDEBUG("equal physical addresses "
+                       << bees_extent_addr(m_root_fd, brp.first) << " and "
+                       << bees_extent_addr(m_root_fd, brp.second) << " in dedup");
                BEESCOUNT(bug_dedup_same_physical);
        }
 
@@ -184,16 +181,17 @@ BeesContext::dedup(const BeesRangePair &brp_in)
 
        BEESCOUNT(dedup_try);
 
-       BEESNOTE("waiting to dedup " << brp);
-       auto lock = MultiLocker::get_lock("dedupe");
-
-       BEESLOGINFO("dedup: src " << pretty(brp.first.size())  << " [" << to_hex(brp.first.begin())  << ".." << to_hex(brp.first.end())  << "] {" << first_addr  << "} " << name_fd(brp.first.fd()) << "\n"
-                << "       dst " << pretty(brp.second.size()) << " [" << to_hex(brp.second.begin()) << ".." << to_hex(brp.second.end()) << "] {" << second_addr << "} " << name_fd(brp.second.fd()));
-       BEESNOTE("dedup: src " << pretty(brp.first.size())  << " [" << to_hex(brp.first.begin())  << ".." << to_hex(brp.first.end())  << "] {" << first_addr  << "} " << name_fd(brp.first.fd()) << "\n"
-                << "       dst " << pretty(brp.second.size()) << " [" << to_hex(brp.second.begin()) << ".." << to_hex(brp.second.end()) << "] {" << second_addr << "} " << name_fd(brp.second.fd()));
+       BEESLOGINFO("dedup: src " << pretty(brp.first.size())  << " [" << to_hex(brp.first.begin())  << ".." << to_hex(brp.first.end())  << "] " << bees_extent_addr(m_root_fd, brp.first)  << " " << name_fd(brp.first.fd()) << "\n"
+                << "       dst " << pretty(brp.second.size()) << " [" << to_hex(brp.second.begin()) << ".." << to_hex(brp.second.end()) << "] " << bees_extent_addr(m_root_fd, brp.second) << " " << name_fd(brp.second.fd()));
 
        while (true) {
                try {
+                       BEESNOTE("waiting to dedup " << brp);
+                       auto lock = MultiLocker::get_lock("dedupe");
+
+                       BEESNOTE("dedup: src " << pretty(brp.first.size())  << " [" << to_hex(brp.first.begin())  << ".." << to_hex(brp.first.end())  << "] " << bees_extent_addr(m_root_fd, brp.first)  << " " << name_fd(brp.first.fd()) << "\n"
+                                << "       dst " << pretty(brp.second.size()) << " [" << to_hex(brp.second.begin()) << ".." << to_hex(brp.second.end()) << "] " << bees_extent_addr(m_root_fd, brp.second) << " " << name_fd(brp.second.fd()));
+
                        Timer dedup_timer;
                        const bool rv = btrfs_extent_same(brp.first.fd(), brp.first.begin(), brp.first.size(), brp.second.fd(), brp.second.begin());
                        BEESCOUNTADD(dedup_ms, dedup_timer.age() * 1000);