[Checkins] SVN: relstorage/trunk/relstorage/ Added the pack-dry-run option and enabled keyword options for the
Shane Hathaway
shane at hathawaymix.org
Sun Jan 25 02:37:52 EST 2009
Log message for revision 95005:
Added the pack-dry-run option and enabled keyword options for the
RelStorage constructor.
Changed:
U relstorage/trunk/relstorage/adapters/common.py
U relstorage/trunk/relstorage/component.xml
U relstorage/trunk/relstorage/relstorage.py
-=-
Modified: relstorage/trunk/relstorage/adapters/common.py
===================================================================
--- relstorage/trunk/relstorage/adapters/common.py 2009-01-25 06:43:54 UTC (rev 95004)
+++ relstorage/trunk/relstorage/adapters/common.py 2009-01-25 07:37:51 UTC (rev 95005)
@@ -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/trunk/relstorage/component.xml
===================================================================
--- relstorage/trunk/relstorage/component.xml 2009-01-25 06:43:54 UTC (rev 95004)
+++ relstorage/trunk/relstorage/component.xml 2009-01-25 07:37:51 UTC (rev 95005)
@@ -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/trunk/relstorage/relstorage.py
===================================================================
--- relstorage/trunk/relstorage/relstorage.py 2009-01-25 06:43:54 UTC (rev 95004)
+++ relstorage/trunk/relstorage/relstorage.py 2009-01-25 07:37:51 UTC (rev 95005)
@@ -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