mirror of
https://github.com/Zygo/bees.git
synced 2025-05-17 21:35:45 +02:00
hash: clean up comments, audit for bugs
We stopped supporting shared hash tables a long time ago. Remove comments describing the behavior of shared hash tables. Add an event counter for pushing a hash to the front when it is already at the front. Audited the code for a bug related to bucket handling that impairs space efficiency when the bucket size is greater than 1. Didn't find one. Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
parent
570b3f7de0
commit
f17cf084e6
@ -35,7 +35,7 @@ dump_bucket_locked(BeesHashTable::Cell *p, BeesHashTable::Cell *q)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const bool VERIFY_CLEARS_BUGS = false;
|
static const bool VERIFY_CLEARS_BUGS = false;
|
||||||
|
|
||||||
bool
|
bool
|
||||||
verify_cell_range(BeesHashTable::Cell *p, BeesHashTable::Cell *q, bool clear_bugs = VERIFY_CLEARS_BUGS)
|
verify_cell_range(BeesHashTable::Cell *p, BeesHashTable::Cell *q, bool clear_bugs = VERIFY_CLEARS_BUGS)
|
||||||
@ -396,10 +396,10 @@ BeesHashTable::fetch_missing_extent_by_index(uint64_t extent_index)
|
|||||||
catch_all([&]() {
|
catch_all([&]() {
|
||||||
BEESTOOLONG("pread(fd " << m_fd << " '" << name_fd(m_fd)<< "', length " << to_hex(dirty_extent_end - dirty_extent) << ", offset " << to_hex(dirty_extent - m_byte_ptr) << ")");
|
BEESTOOLONG("pread(fd " << m_fd << " '" << name_fd(m_fd)<< "', length " << to_hex(dirty_extent_end - dirty_extent) << ", offset " << to_hex(dirty_extent - m_byte_ptr) << ")");
|
||||||
pread_or_die(m_fd, dirty_extent, dirty_extent_end - dirty_extent, dirty_extent - m_byte_ptr);
|
pread_or_die(m_fd, dirty_extent, dirty_extent_end - dirty_extent, dirty_extent - m_byte_ptr);
|
||||||
});
|
|
||||||
|
|
||||||
// Only count extents successfully read
|
// Only count extents successfully read
|
||||||
BEESCOUNT(hash_extent_in);
|
BEESCOUNT(hash_extent_in);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -425,11 +425,9 @@ BeesHashTable::find_cell(HashType hash)
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move an entry to the end of the list. Used after an attempt to resolve
|
/// Remove a hash from the table, leaving an empty space on the list
|
||||||
// an address in the hash table fails. Probably more correctly called
|
/// where the hash used to be. Used when an invalid address is found
|
||||||
// push_back_hash_addr, except it never inserts. Shared hash tables
|
/// because lookups on invalid addresses really hurt.
|
||||||
// never erase anything, since there is no way to tell if an entry is
|
|
||||||
// out of date or just belonging to the wrong filesystem.
|
|
||||||
void
|
void
|
||||||
BeesHashTable::erase_hash_addr(HashType hash, AddrType addr)
|
BeesHashTable::erase_hash_addr(HashType hash, AddrType addr)
|
||||||
{
|
{
|
||||||
@ -441,7 +439,6 @@ BeesHashTable::erase_hash_addr(HashType hash, AddrType addr)
|
|||||||
Cell *ip = find(er.first, er.second, mv);
|
Cell *ip = find(er.first, er.second, mv);
|
||||||
bool found = (ip < er.second);
|
bool found = (ip < er.second);
|
||||||
if (found) {
|
if (found) {
|
||||||
// Lookups on invalid addresses really hurt us. Kill it with fire!
|
|
||||||
*ip = Cell(0, 0);
|
*ip = Cell(0, 0);
|
||||||
set_extent_dirty_locked(hash_to_extent_index(hash));
|
set_extent_dirty_locked(hash_to_extent_index(hash));
|
||||||
BEESCOUNT(hash_erase);
|
BEESCOUNT(hash_erase);
|
||||||
@ -450,14 +447,17 @@ BeesHashTable::erase_hash_addr(HashType hash, AddrType addr)
|
|||||||
BEESLOGDEBUG("while erasing hash " << hash << " addr " << addr);
|
BEESLOGDEBUG("while erasing hash " << hash << " addr " << addr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
} else {
|
||||||
|
BEESCOUNT(hash_erase_miss);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If entry is already present in list, move it to the front of the
|
/// Insert a hash entry at the head of the list. If entry is already
|
||||||
// list without dropping any entries, and return true. If entry is not
|
/// present in list, move it to the front of the list without dropping
|
||||||
// present in list, insert it at the front of the list, possibly dropping
|
/// any entries, and return true. If entry is not present in list,
|
||||||
// the last entry in the list, and return false. Used to move duplicate
|
/// insert it at the front of the list, possibly dropping the last entry
|
||||||
// hash blocks to the front of the list.
|
/// in the list, and return false. Used to move duplicate hash blocks
|
||||||
|
/// to the front of the list.
|
||||||
bool
|
bool
|
||||||
BeesHashTable::push_front_hash_addr(HashType hash, AddrType addr)
|
BeesHashTable::push_front_hash_addr(HashType hash, AddrType addr)
|
||||||
{
|
{
|
||||||
@ -481,7 +481,7 @@ BeesHashTable::push_front_hash_addr(HashType hash, AddrType addr)
|
|||||||
auto dp = ip;
|
auto dp = ip;
|
||||||
--sp;
|
--sp;
|
||||||
// If we are deleting the last entry then don't copy it
|
// If we are deleting the last entry then don't copy it
|
||||||
if (ip == er.second) {
|
if (dp == er.second) {
|
||||||
--sp;
|
--sp;
|
||||||
--dp;
|
--dp;
|
||||||
BEESCOUNT(hash_evict);
|
BEESCOUNT(hash_evict);
|
||||||
@ -495,6 +495,8 @@ BeesHashTable::push_front_hash_addr(HashType hash, AddrType addr)
|
|||||||
er.first[0] = mv;
|
er.first[0] = mv;
|
||||||
set_extent_dirty_locked(hash_to_extent_index(hash));
|
set_extent_dirty_locked(hash_to_extent_index(hash));
|
||||||
BEESCOUNT(hash_front);
|
BEESCOUNT(hash_front);
|
||||||
|
} else {
|
||||||
|
BEESCOUNT(hash_front_already);
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
if (verify_cell_range(er.first, er.second)) {
|
if (verify_cell_range(er.first, er.second)) {
|
||||||
@ -504,11 +506,12 @@ BeesHashTable::push_front_hash_addr(HashType hash, AddrType addr)
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If entry is already present in list, returns true and does not
|
/// Insert a hash entry at some unspecified point in the list.
|
||||||
// modify list. If entry is not present in list, returns false and
|
/// If entry is already present in list, returns true and does not
|
||||||
// inserts at a random position in the list, possibly evicting the entry
|
/// modify list. If entry is not present in list, returns false and
|
||||||
// at the end of the list. Used to insert new unique (not-yet-duplicate)
|
/// inserts at a random position in the list, possibly evicting the entry
|
||||||
// blocks in random order.
|
/// at the end of the list. Used to insert new unique (not-yet-duplicate)
|
||||||
|
/// blocks in random order.
|
||||||
bool
|
bool
|
||||||
BeesHashTable::push_random_hash_addr(HashType hash, AddrType addr)
|
BeesHashTable::push_random_hash_addr(HashType hash, AddrType addr)
|
||||||
{
|
{
|
||||||
@ -573,7 +576,12 @@ BeesHashTable::push_random_hash_addr(HashType hash, AddrType addr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Evict something and insert at pos
|
// Evict something and insert at pos
|
||||||
move_backward(er.first + pos, er.second - 1, er.second);
|
// move_backward(er.first + pos, er.second - 1, er.second);
|
||||||
|
ip = er.second - 1;
|
||||||
|
while (ip > er.first + pos) {
|
||||||
|
auto dp = ip;
|
||||||
|
*dp = *--ip;
|
||||||
|
}
|
||||||
er.first[pos] = mv;
|
er.first[pos] = mv;
|
||||||
BEESCOUNT(hash_evict);
|
BEESCOUNT(hash_evict);
|
||||||
case_cond = 5;
|
case_cond = 5;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user