[Checkins] SVN: relstorage/trunk/ Exposed the commit-lock-timeout and commit-lock-id options.

Shane Hathaway shane at hathawaymix.org
Fri Oct 30 03:58:04 EDT 2009


Log message for revision 105380:
  Exposed the commit-lock-timeout and commit-lock-id options.
  

Changed:
  U   relstorage/trunk/README.txt
  U   relstorage/trunk/relstorage/adapters/connmanager.py
  U   relstorage/trunk/relstorage/adapters/locker.py
  U   relstorage/trunk/relstorage/adapters/mysql.py
  U   relstorage/trunk/relstorage/adapters/oracle.py
  U   relstorage/trunk/relstorage/adapters/postgresql.py
  U   relstorage/trunk/relstorage/adapters/tests/test_connmanager.py
  U   relstorage/trunk/relstorage/component.xml
  U   relstorage/trunk/relstorage/options.py

-=-
Modified: relstorage/trunk/README.txt
===================================================================
--- relstorage/trunk/README.txt	2009-10-30 07:20:27 UTC (rev 105379)
+++ relstorage/trunk/README.txt	2009-10-30 07:58:03 UTC (rev 105380)
@@ -519,11 +519,23 @@
 
 ``cache-delta-size-limit``
         This is an advanced option. RelStorage uses a system of
-        checkpoints to achieve a high cache hit rate. This parameter
+        checkpoints to improve the cache hit rate. This parameter
         configures how many objects should be stored before creating a
         new checkpoint. The default is 10000.
 
+``commit-lock-timeout``
+        During commit, RelStorage acquires a database-wide lock. This
+        parameter specifies how long to wait for the lock before
+        failing the attempt to commit. The default is 30 seconds.
 
+        The MySQL and Oracle adapters support this parameter. The
+        PostgreSQL adapter currently does not.
+
+``commit-lock-id``
+        During commit, RelStorage acquires a database-wide lock. This
+        parameter specifies the lock ID. This parameter currently
+        applies only to the Oracle adapter.
+
 Adapter Options
 ===============
 

Modified: relstorage/trunk/relstorage/adapters/connmanager.py
===================================================================
--- relstorage/trunk/relstorage/adapters/connmanager.py	2009-10-30 07:20:27 UTC (rev 105379)
+++ relstorage/trunk/relstorage/adapters/connmanager.py	2009-10-30 07:58:03 UTC (rev 105380)
@@ -37,9 +37,9 @@
     # will be called whenever a store cursor is opened or rolled back.
     on_store_opened = None
 
-    def __init__(self, options=None):
+    def __init__(self, options):
         # options is a relstorage.options.Options instance
-        if options is not None and options.replica_conf:
+        if options.replica_conf:
             self.replica_selector = ReplicaSelector(options)
         else:
             self.replica_selector = None

Modified: relstorage/trunk/relstorage/adapters/locker.py
===================================================================
--- relstorage/trunk/relstorage/adapters/locker.py	2009-10-30 07:20:27 UTC (rev 105379)
+++ relstorage/trunk/relstorage/adapters/locker.py	2009-10-30 07:58:03 UTC (rev 105380)
@@ -18,22 +18,22 @@
 from ZODB.POSException import StorageError
 from zope.interface import implements
 
-commit_lock_timeout = 30
 
-
 class Locker(object):
 
-    def __init__(self, keep_history, lock_exceptions):
-        self.keep_history = keep_history
+    def __init__(self, options, lock_exceptions):
+        self.keep_history = options.keep_history
+        self.commit_lock_timeout = options.commit_lock_timeout
+        self.commit_lock_id = options.commit_lock_id
         self.lock_exceptions = lock_exceptions
 
 
 class PostgreSQLLocker(Locker):
     implements(ILocker)
 
-    def __init__(self, keep_history, lock_exceptions, version_detector):
+    def __init__(self, options, lock_exceptions, version_detector):
         super(PostgreSQLLocker, self).__init__(
-            keep_history=keep_history, lock_exceptions=lock_exceptions)
+            options=options, lock_exceptions=lock_exceptions)
         self.version_detector = version_detector
 
     def hold_commit_lock(self, cursor, ensure_current=False):
@@ -98,7 +98,7 @@
 
     def hold_commit_lock(self, cursor, ensure_current=False):
         stmt = "SELECT GET_LOCK(CONCAT(DATABASE(), '.commit'), %s)"
-        cursor.execute(stmt, (commit_lock_timeout,))
+        cursor.execute(stmt, (self.commit_lock_timeout,))
         locked = cursor.fetchone()[0]
         if not locked:
             raise StorageError("Unable to acquire commit lock")
@@ -127,11 +127,9 @@
 class OracleLocker(Locker):
     implements(ILocker)
 
-    def __init__(self, keep_history, lock_exceptions,
-            commit_lock_id, inputsize_NUMBER):
-        self.keep_history = keep_history
-        self.lock_exceptions = lock_exceptions
-        self.commit_lock_id = commit_lock_id
+    def __init__(self, options, lock_exceptions, inputsize_NUMBER):
+        super(OracleLocker, self).__init__(
+            options=options, lock_exceptions=lock_exceptions)
         self.inputsize_NUMBER = inputsize_NUMBER
 
     def hold_commit_lock(self, cursor, ensure_current=False):
@@ -140,7 +138,7 @@
         status = cursor.callfunc(
             "sys.relstorage_util.request_lock",
             self.inputsize_NUMBER,
-            (self.commit_lock_id, commit_lock_timeout))
+            (self.commit_lock_id, self.commit_lock_timeout))
         if status != 0:
             if status >= 1 and status <= 5:
                 msg = ('', 'timeout', 'deadlock', 'parameter error',

Modified: relstorage/trunk/relstorage/adapters/mysql.py
===================================================================
--- relstorage/trunk/relstorage/adapters/mysql.py	2009-10-30 07:20:27 UTC (rev 105379)
+++ relstorage/trunk/relstorage/adapters/mysql.py	2009-10-30 07:58:03 UTC (rev 105380)
@@ -67,6 +67,7 @@
 from relstorage.adapters.scriptrunner import ScriptRunner
 from relstorage.adapters.stats import MySQLStats
 from relstorage.adapters.txncontrol import MySQLTransactionControl
+from relstorage.options import Options
 
 log = logging.getLogger(__name__)
 
@@ -88,20 +89,19 @@
     implements(IRelStorageAdapter)
 
     def __init__(self, options=None, **params):
-        # options is a relstorage.options.Options or None
+        if options is None:
+            options = Options()
         self.options = options
-        if options is not None:
-            self.keep_history = options.keep_history
-        else:
-            self.keep_history = True
+        self.keep_history = options.keep_history
         self._params = params
+
         self.connmanager = MySQLdbConnectionManager(
             params=params,
             options=options,
             )
         self.runner = ScriptRunner()
         self.locker = MySQLLocker(
-            keep_history=self.keep_history,
+            options=options,
             lock_exceptions=(MySQLdb.DatabaseError,),
             )
         self.schema = MySQLSchemaInstaller(
@@ -180,7 +180,7 @@
     disconnected_exceptions = disconnected_exceptions
     close_exceptions = close_exceptions
 
-    def __init__(self, params, options=None):
+    def __init__(self, params, options):
         self._orig_params = params.copy()
         self._params = self._orig_params
         # _params_derived_from_replica contains the replica that

Modified: relstorage/trunk/relstorage/adapters/oracle.py
===================================================================
--- relstorage/trunk/relstorage/adapters/oracle.py	2009-10-30 07:20:27 UTC (rev 105379)
+++ relstorage/trunk/relstorage/adapters/oracle.py	2009-10-30 07:58:03 UTC (rev 105380)
@@ -32,6 +32,7 @@
 from relstorage.adapters.scriptrunner import OracleScriptRunner
 from relstorage.adapters.stats import OracleStats
 from relstorage.adapters.txncontrol import OracleTransactionControl
+from relstorage.options import Options
 
 log = logging.getLogger(__name__)
 
@@ -63,16 +64,14 @@
         commit process.  This is disabled by default.  Even when this option
         is disabled, the ZODB two-phase commit is still in effect.
         """
-        # options is a relstorage.options.Options or None
         self._user = user
         self._password = password
         self._dsn = dsn
         self._twophase = twophase
+        if options is None:
+            options = Options()
         self.options = options
-        if options is not None:
-            self.keep_history = options.keep_history
-        else:
-            self.keep_history = True
+        self.keep_history = options.keep_history
 
         self.connmanager = CXOracleConnectionManager(
             user=user,
@@ -83,9 +82,8 @@
             )
         self.runner = CXOracleScriptRunner()
         self.locker = OracleLocker(
-            keep_history=self.keep_history,
+            options=self.options,
             lock_exceptions=(cx_Oracle.DatabaseError,),
-            commit_lock_id=commit_lock_id,
             inputsize_NUMBER=cx_Oracle.NUMBER,
             )
         self.schema = OracleSchemaInstaller(
@@ -242,7 +240,7 @@
     disconnected_exceptions = disconnected_exceptions
     close_exceptions = close_exceptions
 
-    def __init__(self, user, password, dsn, twophase, options=None):
+    def __init__(self, user, password, dsn, twophase, options):
         self._user = user
         self._password = password
         self._dsn = dsn

Modified: relstorage/trunk/relstorage/adapters/postgresql.py
===================================================================
--- relstorage/trunk/relstorage/adapters/postgresql.py	2009-10-30 07:20:27 UTC (rev 105379)
+++ relstorage/trunk/relstorage/adapters/postgresql.py	2009-10-30 07:58:03 UTC (rev 105380)
@@ -34,6 +34,7 @@
 from relstorage.adapters.scriptrunner import ScriptRunner
 from relstorage.adapters.stats import PostgreSQLStats
 from relstorage.adapters.txncontrol import PostgreSQLTransactionControl
+from relstorage.options import Options
 
 log = logging.getLogger(__name__)
 
@@ -56,20 +57,18 @@
     def __init__(self, dsn='', options=None):
         # options is a relstorage.options.Options or None
         self._dsn = dsn
+        if options is None:
+            options = Options()
         self.options = options
-        if options is not None:
-            self.keep_history = options.keep_history
-        else:
-            self.keep_history = True
+        self.keep_history = options.keep_history
         self.version_detector = PostgreSQLVersionDetector()
         self.connmanager = Psycopg2ConnectionManager(
             dsn=dsn,
             options=options,
-            keep_history=self.keep_history,
             )
         self.runner = ScriptRunner()
         self.locker = PostgreSQLLocker(
-            keep_history=self.keep_history,
+            options=options,
             lock_exceptions=(psycopg2.DatabaseError,),
             version_detector=self.version_detector,
             )
@@ -151,10 +150,10 @@
     disconnected_exceptions = disconnected_exceptions
     close_exceptions = close_exceptions
 
-    def __init__(self, dsn, options=None, keep_history=True):
+    def __init__(self, dsn, options):
         self._orig_dsn = dsn
         self._dsn = dsn
-        self.keep_history = keep_history
+        self.keep_history = options.keep_history
         # _dsn_derived_from_replica contains the replica that
         # was used to set self._dsn.
         self._dsn_derived_from_replica = None

Modified: relstorage/trunk/relstorage/adapters/tests/test_connmanager.py
===================================================================
--- relstorage/trunk/relstorage/adapters/tests/test_connmanager.py	2009-10-30 07:20:27 UTC (rev 105379)
+++ relstorage/trunk/relstorage/adapters/tests/test_connmanager.py	2009-10-30 07:58:03 UTC (rev 105380)
@@ -18,7 +18,7 @@
 
     def test_without_replica_conf(self):
         from relstorage.adapters.connmanager import AbstractConnectionManager
-        cm = AbstractConnectionManager()
+        cm = AbstractConnectionManager(MockOptions())
 
         conn = MockConnection()
         cm.restart_load(conn, MockCursor())
@@ -58,7 +58,7 @@
 
 
 class MockOptions:
-    def __init__(self, fn):
+    def __init__(self, fn=None):
         self.replica_conf = fn
         self.replica_timeout = 600.0
 

Modified: relstorage/trunk/relstorage/component.xml
===================================================================
--- relstorage/trunk/relstorage/component.xml	2009-10-30 07:20:27 UTC (rev 105379)
+++ relstorage/trunk/relstorage/component.xml	2009-10-30 07:58:03 UTC (rev 105380)
@@ -190,11 +190,28 @@
     <key name="cache-delta-size-limit" datatype="integer" required="no">
       <description>
         This is an advanced option. RelStorage uses a system of
-        checkpoints to achieve a high cache hit rate. This parameter
+        checkpoints to improve the cache hit rate. This parameter
         configures how many objects should be stored before creating a
-        new checkpoint. The default is 10000.
+        new checkpoint in the cache. The default is 10000.
       </description>
     </key>
+    <key name="commit-lock-timeout" datatype="integer" required="no">
+      <description>
+        During commit, RelStorage acquires a database-wide lock. This
+        parameter specifies how long to wait for the lock before
+        failing the attempt to commit. The default is 30 seconds.
+
+        The MySQL and Oracle adapters support this parameter. The
+        PostgreSQL adapter currently does not.
+      </description>
+    </key>
+    <key name="commit-lock-id" datatype="integer" required="no">
+      <description>
+        During commit, RelStorage acquires a database-wide lock. This
+        parameter specifies the lock ID. This paramter currently
+        applies only to the Oracle adapter.
+      </description>
+    </key>
   </sectiontype>
 
   <sectiontype name="postgresql" implements="relstorage.adapter"

Modified: relstorage/trunk/relstorage/options.py
===================================================================
--- relstorage/trunk/relstorage/options.py	2009-10-30 07:20:27 UTC (rev 105379)
+++ relstorage/trunk/relstorage/options.py	2009-10-30 07:58:03 UTC (rev 105380)
@@ -41,6 +41,8 @@
         self.cache_prefix = ''
         self.cache_local_mb = 10
         self.cache_delta_size_limit = 10000
+        self.commit_lock_timeout = 30
+        self.commit_lock_id = 0
 
         for key, value in kwoptions.iteritems():
             if key in self.__dict__:



More information about the checkins mailing list