[Checkins] SVN: zc.zodbdgc/branches/dev/src/zc/zodbdgc/ Avoid iterating trailing data if the specified number of trailing days

Jim Fulton jim at zope.com
Thu Jun 11 15:36:15 EDT 2009


Log message for revision 100885:
  Avoid iterating trailing data if the specified number of trailing days
  os 0.
  
  Improved help text.
  

Changed:
  U   zc.zodbdgc/branches/dev/src/zc/zodbdgc/README.test
  U   zc.zodbdgc/branches/dev/src/zc/zodbdgc/__init__.py

-=-
Modified: zc.zodbdgc/branches/dev/src/zc/zodbdgc/README.test
===================================================================
--- zc.zodbdgc/branches/dev/src/zc/zodbdgc/README.test	2009-06-11 19:35:53 UTC (rev 100884)
+++ zc.zodbdgc/branches/dev/src/zc/zodbdgc/README.test	2009-06-11 19:36:15 UTC (rev 100885)
@@ -285,11 +285,12 @@
     >>> sys.argv[0] = 'test'
     >>> try: zc.zodbdgc.gc_command([])
     ... except SystemExit: pass
-    usage: test [options] config1 [config2]
+    Usage: test [options] config1 [config2]
     <BLANKLINE>
-    options:
+    Options:
       -h, --help            show this help message and exit
-      -d DAYS, --days=DAYS  Number of trailing days to treat as non-garbage
+      -d DAYS, --days=DAYS  Number of trailing days (defaults to 1) to treat as
+                            non-garbage
       -l LEVEL, --log-level=LEVEL
                             The logging level. The default is WARNING.
 
@@ -326,11 +327,12 @@
 
     >>> _ = [d.close() for d in db.databases.values()]
 
+
 >>> try: zc.zodbdgc.check_command([])
 ... except SystemExit: pass
-usage: test [options] config
+Usage: test [options] config
 <BLANKLINE>
-options:
+Options:
   -h, --help            show this help message and exit
   -r REFDB, --references-filestorage=REFDB
                         The name of a file-storage to save reference info in.
@@ -352,17 +354,16 @@
     Removed 0 objects from db2
     []
 
-    >>> now += 90000
+Try with 0 days:
 
-    >>> sorted((name, u64(oid)) for (name, oid) in
-    ...        zc.zodbdgc.gc_command(['config', 'config2']).iterator())
+    >>> sorted((name, long(u64(oid))) for (name, oid) in
+    ...        zc.zodbdgc.gc_command(['-d0', 'config', 'config2']).iterator())
     Using secondary configuration, config2, for analysis
     Removed 0 objects from db1
     Removed 0 objects from db3
     Removed 2 objects from db2
     [('db2', 3L), ('db2', 4L)]
 
-
 Test the check command
 ----------------------
 

Modified: zc.zodbdgc/branches/dev/src/zc/zodbdgc/__init__.py
===================================================================
--- zc.zodbdgc/branches/dev/src/zc/zodbdgc/__init__.py	2009-06-11 19:35:53 UTC (rev 100884)
+++ zc.zodbdgc/branches/dev/src/zc/zodbdgc/__init__.py	2009-06-11 19:36:15 UTC (rev 100885)
@@ -74,26 +74,27 @@
         for ref in getrefs(data, name):
             good.insert(*ref)
 
-        # All non-deleted new records are good
-        for trans in storage.iterator(ptid):
-            for record in trans:
-                oid = record.oid
-                data = record.data
-                if data:
-                    if deleted.has(name, oid):
-                        raise AssertionError(
-                            "Non-deleted record after deleted")
-                    good.insert(name, oid)
+        if days:
+            # All non-deleted new records are good
+            for trans in storage.iterator(ptid):
+                for record in trans:
+                    oid = record.oid
+                    data = record.data
+                    if data:
+                        if deleted.has(name, oid):
+                            raise AssertionError(
+                                "Non-deleted record after deleted")
+                        good.insert(name, oid)
 
-                    # and anything they reference
-                    for ref in getrefs(data, name):
-                        if not deleted.has(*ref):
-                            good.insert(*ref)
-                else:
-                    # deleted record
-                    deleted.insert(name, oid)
-                    if good.has(name, oid):
-                        good.remove(name, oid)
+                        # and anything they reference
+                        for ref in getrefs(data, name):
+                            if not deleted.has(*ref):
+                                good.insert(*ref)
+                    else:
+                        # deleted record
+                        deleted.insert(name, oid)
+                        if good.has(name, oid):
+                            good.remove(name, oid)
 
         # Now iterate over older records
         for trans in storage.iterator(None, ptid):
@@ -255,7 +256,7 @@
     parser = optparse.OptionParser("usage: %prog [options] config1 [config2]")
     parser.add_option(
         '-d', '--days', dest='days', type='int', default=1,
-        help='Number of trailing days to treat as non-garbage')
+        help='Number of trailing days (defaults to 1) to treat as non-garbage')
     parser.add_option(
         '-l', '--log-level', dest='level',
         help='The logging level. The default is WARNING.')



More information about the Checkins mailing list