From 2f883084c4393dc7b730df2e778b9f2fc14f70e0 Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Thu, 9 Sep 2010 13:30:39 -0700 Subject: [PATCH] Allow cleaner to delete unused log segments. It will not delete segments cleaned out in the current pass, just those that were unreferenced at the start of the cleaning process. --- cleaner/cleaner | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cleaner/cleaner b/cleaner/cleaner index 445bdeb..b018d0d 100755 --- a/cleaner/cleaner +++ b/cleaner/cleaner @@ -49,6 +49,9 @@ class FileBackend: fp.write(data) fp.close() + def delete(self, filename): + os.unlink(os.path.join(self.path, filename)) + def loc_to_name(self, location): return "log-%08d-%08d" % (location) @@ -268,8 +271,10 @@ class InodeMap: print print "Segment utilizations:" for (s, u) in sorted(util.segments.items()): - #if u[1] > 0: print "%s: %s %s" % (s, u, float(u[1]) / u[0]) + if u[1] == 0: + print "Deleting..." + backend.delete(s) self.inodes = inodes self.util = util @@ -341,7 +346,7 @@ def run_cleaner(backend, inode_map, log): # Determine which segments are poorly utilized and should be cleaned. We # need better heuristics here. for (s, u) in sorted(inode_map.util.segments.items()): - if float(u[1]) / u[0] < 0.95 and u[1] > 0: + if float(u[1]) / u[0] < 0.6 and u[1] > 0: print "Should clean segment", s loc = backend.name_to_loc(s) if s: inode_map.obsolete_segments.add(loc) @@ -381,7 +386,7 @@ if __name__ == '__main__': imap.build(backend, chkpt) print chkpt - log_dir = LogDirectory(backend, 1) + log_dir = LogDirectory(backend, 0) run_cleaner(backend, imap, log_dir) imap.write(backend, log_dir) log_dir.close_all() -- 2.20.1