[Modeling-cvs] SF.net SVN: modeling: [997] trunk/ProjectModeling/Modeling
Status: Abandoned
Brought to you by:
sbigaret
From: <sbi...@us...> - 2006-04-22 14:00:48
|
Revision: 997 Author: sbigaret Date: 2006-04-22 07:00:35 -0700 (Sat, 22 Apr 2006) ViewCVS: http://svn.sourceforge.net/modeling/?rev=997&view=rev Log Message: ----------- Feature request #1011515: Configurability of ABORT/COMMIT on read-only transactions (postgresql/psycopg) Modified Paths: -------------- trunk/ProjectModeling/Modeling/DatabaseAdaptors/PostgresqlAdaptorLayer/PostgresqlAdaptorContext.py trunk/ProjectModeling/Modeling/DatabaseAdaptors/PostgresqlAdaptorLayer/__init__.py trunk/ProjectModeling/Modeling/TODO trunk/ProjectModeling/Modeling/doc/UserGuide/EnvironmentVariables.tex trunk/ProjectModeling/Modeling/utils.py Modified: trunk/ProjectModeling/Modeling/DatabaseAdaptors/PostgresqlAdaptorLayer/PostgresqlAdaptorContext.py =================================================================== --- trunk/ProjectModeling/Modeling/DatabaseAdaptors/PostgresqlAdaptorLayer/PostgresqlAdaptorContext.py 2006-04-22 13:34:27 UTC (rev 996) +++ trunk/ProjectModeling/Modeling/DatabaseAdaptors/PostgresqlAdaptorLayer/PostgresqlAdaptorContext.py 2006-04-22 14:00:35 UTC (rev 997) @@ -33,6 +33,39 @@ """ Concrete AdaptorContext for Postgresql [module psycopg,pgdb or pypgsql] """ + + def shouldCommitReadonlyTransactions(self): + """ + By default, the Postgresql Adaptor Layer rollbacks transactions after a + fetch, when using psycopg. The reason is that, if the isolation level is + set to serializable (it was the default in psycopg in former releases, and + is now read from database settings), changes made in other processes won't + be seen until the transaction is finished (see `Transaction Isolation + <http://www.postgresql.org/docs/8.1/static/transaction-iso.html>`_ in + Postgresql's documentation). + + The default behaviour can be changed in two different ways: + + - setting the environment variable ``MDL_COMMIT_AFTER_FETCH`` to any value + (except the empty string) + + - programmatically:: + + from Modeling.DatabaseAdaptors import PostgresqlAdaptorLayer + PostgresqlAdaptorLayer.commit_readonly_transactions = 1 + + The value is interpreted as any python boolean value. + + The environment variable is ignored as soon as it is set programmatically. + """ + from Modeling.utils import unset + from Modeling.DatabaseAdaptors.PostgresqlAdaptorLayer \ + import commit_readonly_transactions + if commit_readonly_transactions is not unset: + return commit_readonly_transactions + import os + return os.environ.get('MDL_COMMIT_AFTER_FETCH', None) + def adaptorChannelDidClose(self, aChannel): """ Invokes AbstractDBAPI2AdaptorContext.adaptorChannelDidClose(), then @@ -48,9 +81,14 @@ AbstractDBAPI2AdaptorContext.adaptorChannelDidClose(self, aChannel) from PostgresqlAdaptor import _uses_psycopg if _uses_psycopg and not self.hasOpenChannels() and self._cnx: - ## rollbacks the connexion - db_debug('psycopg specifics: ROLLBACK on cnx') - self._cnx.rollback() + if self.shouldCommitReadonlyTransactions(): + ## rollbacks the connexion + db_debug('psycopg specifics: COMMIT on cnx') + self._cnx.commit() + else: + ## rollbacks the connexion + db_debug('psycopg specifics: ROLLBACK on cnx') + self._cnx.rollback() def createAdaptorChannel(self): """ Modified: trunk/ProjectModeling/Modeling/DatabaseAdaptors/PostgresqlAdaptorLayer/__init__.py =================================================================== --- trunk/ProjectModeling/Modeling/DatabaseAdaptors/PostgresqlAdaptorLayer/__init__.py 2006-04-22 13:34:27 UTC (rev 996) +++ trunk/ProjectModeling/Modeling/DatabaseAdaptors/PostgresqlAdaptorLayer/__init__.py 2006-04-22 14:00:35 UTC (rev 997) @@ -56,3 +56,6 @@ def adaptorFactory(): from PostgresqlAdaptor import PostgresqlAdaptor return PostgresqlAdaptor + +from Modeling.utils import unset +commit_readonly_transactions = unset Modified: trunk/ProjectModeling/Modeling/TODO =================================================================== --- trunk/ProjectModeling/Modeling/TODO 2006-04-22 13:34:27 UTC (rev 996) +++ trunk/ProjectModeling/Modeling/TODO 2006-04-22 14:00:35 UTC (rev 997) @@ -182,6 +182,10 @@ Database Layer (in Access Layer) + * in relation to feature request #1011515 and isolation level: we should + check the othe postgresql's python adaptors, and also what the situation + is w/ other databases (wrt possible isolation level issues). + * Snapshotting of to-many relationships is implemented but unused for the moment being. Modified: trunk/ProjectModeling/Modeling/doc/UserGuide/EnvironmentVariables.tex =================================================================== --- trunk/ProjectModeling/Modeling/doc/UserGuide/EnvironmentVariables.tex 2006-04-22 13:34:27 UTC (rev 996) +++ trunk/ProjectModeling/Modeling/doc/UserGuide/EnvironmentVariables.tex 2006-04-22 14:00:35 UTC (rev 997) @@ -138,6 +138,34 @@ anymore) ; this does not affect the runtime core for the moment being. } {\code{'7.2'} (default), \code{'7.3'}} \hline +\lineiii{MDL_COMMIT_AFTER_FETCH}{}{} +\lineiii{}{By default, the Posgresql Adaptor Layer rollbacks transactions after + a fetch, when using psycopg. The reason is that, if the isolation level is + set to serializable (it was the default in psycopg in former releases, and + is now read from database settings), changes made in other processes won't + be seen until the transaction is finished (see Transaction + Isolation in Postgresql's documentation, at + http://www.postgresql.org/docs/8.1/static/transaction-iso.html). + \newline~\newline + Setting this variable to any value (apart from the empty string) changes the + default behaviour, so that every transaction opened for fetching is + committed instead of being rolled back. This feature was requested because + ``this can be a problem while debugging the log of an application, where + the ABORT will be the majority of the transactions'' (see the corresponding + feature request at + https://sourceforge.net/tracker/index.php?func=detail\&aid=1011515\&group_id=58935\&atid=489338). + \newline~\newline + It can also be set programmatically:\newline +{\small +\inlineverb{from Modeling.DatabaseAdaptors import PostgresqlAdaptorLayer} +\inlineverb{PostgresqlAdaptorLayer.commit_readonly_transactions = 1} +} +The value is interpreted as any python boolean value. +\newline~\newline +The environment variable is ignored as soon as it is set programmatically. + } + {e.g. '1', 'YES' (plus the empty string for de-activation)} +\hline \end{longtableiii}\label{tab:env-vars-postgresql} \newpage Modified: trunk/ProjectModeling/Modeling/utils.py =================================================================== --- trunk/ProjectModeling/Modeling/utils.py 2006-04-22 13:34:27 UTC (rev 996) +++ trunk/ProjectModeling/Modeling/utils.py 2006-04-22 14:00:35 UTC (rev 997) @@ -267,3 +267,10 @@ if os.environ.has_key('MDL_PERMANENT_DB_CONNECTION'): msg="Environment variable MDL_PERMANENT_DB_CONNECTION is deprecated since 0.9pre17 and it has no effect anymore. The framework's default behaviour is now to leave the database connection opened. This variable has been replaced by the variable MDL_TRANSIENT_DB_CONNECTION which has the inverse semantics. Please refer to the User's Guide, appendix Environment Variables, for further details" warnings.warn(msg, DeprecationWarning) + +unset = [] + +def is_unset(value): + global unset + return value is unset + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |