[Checkins] SVN: relstorage/branches/1.1/ Merged from trunk (-r95004:95006)

Shane Hathaway shane at hathawaymix.org
Sun Jan 25 03:40:04 EST 2009


Log message for revision 95007:
  Merged from trunk (-r95004:95006)
  

Changed:
  U   relstorage/branches/1.1/CHANGES.txt
  U   relstorage/branches/1.1/relstorage/adapters/common.py
  U   relstorage/branches/1.1/relstorage/component.xml
  U   relstorage/branches/1.1/relstorage/relstorage.py

-=-
Modified: relstorage/branches/1.1/CHANGES.txt
===================================================================
--- relstorage/branches/1.1/CHANGES.txt	2009-01-25 08:37:34 UTC (rev 95006)
+++ relstorage/branches/1.1/CHANGES.txt	2009-01-25 08:40:04 UTC (rev 95007)
@@ -1,5 +1,9 @@
 Next Release
 
+- Added the pack-dry-run option, which causes pack operations to only
+  populate the pack tables with the list of objects and states to pack,
+  but not actually pack.
+
 - Refined the pack algorithm.  It was not removing as many object states
   as it should have.  As a bonus, there is now a method of adapters called
   fill_object_refs(), which could be useful for debugging.  It ensures the

Modified: relstorage/branches/1.1/relstorage/adapters/common.py
===================================================================
--- relstorage/branches/1.1/relstorage/adapters/common.py	2009-01-25 08:37:34 UTC (rev 95006)
+++ relstorage/branches/1.1/relstorage/adapters/common.py	2009-01-25 08:40:04 UTC (rev 95007)
@@ -698,6 +698,7 @@
             LEFT JOIN object_refs_added
                 ON (transaction.tid = object_refs_added.tid)
         WHERE object_refs_added.tid IS NULL
+        ORDER BY transaction.tid
         """
         cursor.execute(stmt)
         tids = [tid for (tid,) in cursor]

Modified: relstorage/branches/1.1/relstorage/component.xml
===================================================================
--- relstorage/branches/1.1/relstorage/component.xml	2009-01-25 08:37:34 UTC (rev 95006)
+++ relstorage/branches/1.1/relstorage/component.xml	2009-01-25 08:40:04 UTC (rev 95007)
@@ -55,6 +55,15 @@
         inter-database references never break.
       </description>
     </key>
+    <key name="pack-dry-run" datatype="boolean" default="false">
+      <description>
+        If pack-dry-run is true, pack operations perform a full analysis
+        of what to pack, but no data is actually removed.  After a dry run,
+        the pack_object, pack_state, and pack_state_tid tables are filled
+        with the list of object states and objects that would have been
+        removed.
+      </description>
+    </key>
     <key name="pack-batch-timeout" datatype="float" required="no">
       <description>
         Packing occurs in batches of transactions; this specifies the

Modified: relstorage/branches/1.1/relstorage/relstorage.py
===================================================================
--- relstorage/branches/1.1/relstorage/relstorage.py	2009-01-25 08:37:34 UTC (rev 95006)
+++ relstorage/branches/1.1/relstorage/relstorage.py	2009-01-25 08:40:04 UTC (rev 95007)
@@ -52,7 +52,7 @@
     """Storage to a relational database, based on invalidation polling"""
 
     def __init__(self, adapter, name=None, create=True,
-            read_only=False, options=None):
+            read_only=False, options=None, **kwoptions):
         if name is None:
             name = 'RelStorage on %s' % adapter.__class__.__name__
 
@@ -61,6 +61,14 @@
         self._is_read_only = read_only
         if options is None:
             options = Options()
+            for key, value in kwoptions.iteritems():
+                if key in options.__dict__:
+                    setattr(options, key, value)
+                else:
+                    raise TypeError("Unknown parameter: %s" % key)
+        elif kwoptions:
+            raise TypeError("The RelStorage constructor accepts either "
+                "an options parameter or keyword arguments, not both")
         self._options = options
         self._cache_client = None
 
@@ -839,20 +847,28 @@
                 # Find the latest commit before or at the pack time.
                 tid_int = adapter.choose_pack_transaction(pack_point_int)
                 if tid_int is None:
-                    # Nothing needs to be packed.
+                    log.debug("all transactions before %s have already "
+                        "been packed", time.ctime(t))
                     return
 
+                if self._options.pack_dry_run:
+                    log.info("pack: beginning dry run")
+
                 s = time.ctime(TimeStamp(p64(tid_int)).timeTime())
-                log.info("packing transactions committed %s or before", s)
+                log.info("pack: analyzing transactions committed "
+                    "%s or before", s)
 
                 # In pre_pack, the adapter fills tables with
                 # information about what to pack.  The adapter
-                # should not actually pack anything yet.
+                # must not actually pack anything yet.
                 adapter.pre_pack(tid_int, get_references, self._options)
 
-                # Now pack.
-                adapter.pack(tid_int, self._options)
-                self._after_pack()
+                if self._options.pack_dry_run:
+                    log.info("pack: dry run complete")
+                else:
+                    # Now pack.
+                    adapter.pack(tid_int, self._options)
+                    self._after_pack()
             finally:
                 adapter.release_pack_lock(lock_cursor)
         finally:
@@ -1084,10 +1100,20 @@
 
 
 class Options:
-    """Options for tuning RelStorage."""
+    """Options for tuning RelStorage.
+
+    These parameters can be provided as keyword options in the RelStorage
+    constructor.  For example:
+
+        storage = RelStorage(adapter, pack_gc=True, pack_dry_run=True)
+
+    Alternatively, the RelStorage constructor accepts an options
+    parameter, which should be an Options instance.
+    """
     def __init__(self):
         self.poll_interval = 0
         self.pack_gc = True
+        self.pack_dry_run = False
         self.pack_batch_timeout = 5.0
         self.pack_duty_cycle = 0.5
         self.pack_max_delay = 20.0



More information about the Checkins mailing list