Allow cleaner to delete unused log segments.
authorMichael Vrable <mvrable@cs.ucsd.edu>
Thu, 9 Sep 2010 20:30:39 +0000 (13:30 -0700)
committerMichael Vrable <mvrable@cs.ucsd.edu>
Thu, 9 Sep 2010 20:30:39 +0000 (13:30 -0700)
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

index 445bdeb..b018d0d 100755 (executable)
@@ -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()