disk-cache: Improve hole management

Make coalescing of neighboring holes robust. Speed up hole finding.
Cost is we replace a single array tracking holes with three hashmaps
tracking size->[pos] pos->size and endpos->size.
This commit is contained in:
Kovid Goyal
2024-07-15 19:42:07 +05:30
parent 2058cac203
commit 24e6dda0bc
2 changed files with 137 additions and 51 deletions

View File

@@ -263,7 +263,7 @@ class TestGraphics(BaseTest):
self.assertEqual(sz, dc.size_on_disk())
self.assertEqual(holes, {x[1] for x in dc.holes()})
self.assertEqual(sz, dc.size_on_disk())
# fill holes largest first to ensure small one doesnt go into large accidentally causing fragmentation
# fill holes largest first to ensure small one doesn't go into large accidentally causing fragmentation
for i, x in enumerate(sorted(holes, reverse=True)):
x = 'ABCDEFGH'[i] * x
add(x, x)
@@ -341,6 +341,17 @@ class TestGraphics(BaseTest):
dc.wait_for_write()
self.ae(sz, dc.size_on_disk())
# test hole coalescing
reset()
for i in range(1, 6):
self.assertIsNone(add(i, str(i)*i))
dc.wait_for_write()
remove(2)
remove(4)
self.assertEqual(dc.holes(), {(1, 2), (6, 4)})
remove(3)
self.assertEqual(dc.holes(), {(1, 9)})
def test_suppressing_gr_command_responses(self):
s, g, pl, sl = load_helpers(self)
self.ae(pl('abcd', s=10, v=10, q=1), 'ENODATA:Insufficient image data: 4 < 400')