]> git.hungrycats.org Git - bees/commitdiff
hash: remove dead verify_cell_range and debug scaffolding
authorZygo Blaxell <bees@furryterror.org>
Wed, 17 Jun 2026 01:51:02 +0000 (21:51 -0400)
committerZygo Blaxell <bees@furryterror.org>
Sat, 5 Sep 2026 04:03:58 +0000 (00:03 -0400)
verify_cell_range and dump_bucket_locked guarded against hash table
corruption from bees bugs fixed long ago.  The periodic survey was the last
live caller of verify_cell_range; it dropped that call when it switched to
summing per-extent occupancy fragments, leaving the function referenced only
from #if 0 blocks.

Delete verify_cell_range, dump_bucket_locked, and the VERIFY_CLEARS_BUGS
flag, along with the three disabled call sites in erase_hash_addr,
push_front_hash_addr and push_random_hash_addr.  The push_random case_cond
variable existed solely to label cases in that disabled diagnostic, so it
goes too; the goto targets that drove the control flow remain.

Assisted-by: Claude-Code:claude-opus-4-8
Signed-off-by: Zygo Blaxell <bees@furryterror.org>
src/bees-hash.cc

index d00360b04ad95fd42d51d4e82e1f90fb460b1c13..c7acf124f5c3ee9d5e599da1833066d3b47168f8 100644 (file)
@@ -51,49 +51,6 @@ operator<<(ostream &os, const BeesHashTable::Cell &bhte)
                  << BeesAddress(bhte.e_addr) << " }";
 }
 
-#if 0
-static
-void
-dump_bucket_locked(BeesHashTable::Cell *p, BeesHashTable::Cell *q)
-{
-       for (auto i = p; i < q; ++i) {
-               BEESLOG("Entry " << i - p << " " << *i);
-       }
-}
-#endif
-
-static const bool VERIFY_CLEARS_BUGS = false;
-
-bool
-verify_cell_range(BeesHashTable::Cell *p, BeesHashTable::Cell *q, bool clear_bugs = VERIFY_CLEARS_BUGS)
-{
-       // Must be called while holding m_bucket_mutex
-       bool bugs_found = false;
-       set<BeesHashTable::Cell> seen_it;
-       for (BeesHashTable::Cell *cell = p; cell < q; ++cell) {
-               if (cell->e_addr && cell->e_addr < 0x1000) {
-                       BEESCOUNT(bug_hash_magic_addr);
-                       BEESLOGDEBUG("Bad hash table address hash " << to_hex(cell->e_hash) << " addr " << to_hex(cell->e_addr));
-                       if (clear_bugs) {
-                               cell->e_addr = 0;
-                               cell->e_hash = 0;
-                       }
-                       bugs_found = true;
-               }
-               if (cell->e_addr && !seen_it.insert(*cell).second) {
-                       BEESCOUNT(bug_hash_duplicate_cell);
-                       // BEESLOGDEBUG("Duplicate hash table entry:\nthis = " << *cell << "\nold = " << *seen_it.find(*cell));
-                       BEESLOGDEBUG("Duplicate hash table entry: " << *cell);
-                       if (clear_bugs) {
-                               cell->e_addr = 0;
-                               cell->e_hash = 0;
-                       }
-                       bugs_found = true;
-               }
-       }
-       return bugs_found;
-}
-
 pair<BeesHashTable::Cell *, BeesHashTable::Cell *>
 BeesHashTable::get_cell_range(HashType hash)
 {
@@ -449,11 +406,6 @@ BeesHashTable::erase_hash_addr(HashType hash, AddrType addr)
                *ip = Cell(0, 0);
                set_extent_dirty_locked(hash_to_extent_index(hash));
                BEESCOUNT(hash_erase);
-#if 0
-               if (verify_cell_range(er.first, er.second)) {
-                       BEESLOGDEBUG("while erasing hash " << hash << " addr " << addr);
-               }
-#endif
        } else {
                BEESCOUNT(hash_erase_miss);
        }
@@ -517,11 +469,6 @@ BeesHashTable::push_front_hash_addr(HashType hash, AddrType addr)
        if (er.first[0] != prev_front) {
                set_extent_dirty_locked(hash_to_extent_index(hash));
        }
-#if 0
-       if (verify_cell_range(er.first, er.second)) {
-               BEESLOGDEBUG("while push_fronting hash " << hash << " addr " << addr);
-       }
-#endif
        return found;
 }
 
@@ -545,11 +492,6 @@ BeesHashTable::push_random_hash_addr(HashType hash, AddrType addr)
 
        const size_t pos = m_randomize_lru ? tl_distribution(bees_generator) : 0;
 
-       int case_cond = 0;
-#if 0
-       vector<Cell> saved(er.first, er.second);
-#endif
-
        if (found) {
                // If hash already exists after pos, swap with pos
                if (ip > er.first + pos) {
@@ -563,12 +505,10 @@ BeesHashTable::push_random_hash_addr(HashType hash, AddrType addr)
                        }
                        *dp = mv;
                        BEESCOUNT(hash_bump);
-                       case_cond = 1;
                        goto ret_dirty;
                }
                // Hash already exists before (or at) pos, leave it there
                BEESCOUNT(hash_already);
-               case_cond = 2;
                goto ret;
        }
 
@@ -576,7 +516,6 @@ BeesHashTable::push_random_hash_addr(HashType hash, AddrType addr)
        for (ip = er.first + pos; ip < er.second; ++ip) {
                if (*ip == Cell(0, 0)) {
                        *ip = mv;
-                       case_cond = 3;
                        goto ret_dirty;
                }
        }
@@ -587,7 +526,6 @@ BeesHashTable::push_random_hash_addr(HashType hash, AddrType addr)
                for (ip = er.first + pos - 1; ip >= er.first; --ip) {
                        if (*ip == Cell(0, 0)) {
                                *ip = mv;
-                               case_cond = 4;
                                goto ret_dirty;
                        }
                }
@@ -602,21 +540,10 @@ BeesHashTable::push_random_hash_addr(HashType hash, AddrType addr)
        }
        er.first[pos] = mv;
        BEESCOUNT(hash_evict);
-       case_cond = 5;
 ret_dirty:
        BEESCOUNT(hash_insert);
        set_extent_dirty_locked(hash_to_extent_index(hash));
 ret:
-#if 0
-       if (verify_cell_range(er.first, er.second, false)) {
-               BEESLOG("while push_randoming (case " << case_cond << ") pos " << pos
-                       << " ip " << (ip - er.first) << " " << mv);
-               // dump_bucket_locked(saved.data(), saved.data() + saved.size());
-               // dump_bucket_locked(er.first, er.second);
-       }
-#else
-       (void)case_cond;
-#endif
        return found;
 }