[storm] How to set isolation level in storm
Jason Baker
jbaker at zeomega.com
Tue Jun 23 20:30:36 BST 2009
On Fri, Jun 19, 2009 at 1:26 PM, Gustavo Niemeyer<gustavo at niemeyer.net> wrote:
>> On Fri, Jun 19, 2009 at 10:33 AM, Tres Seaver<tseaver at palladion.com> wrote:
>>> A store is a per-thread wrapper around a database, right? And the
>>> database is what is created from the db_uri? So the properties are
>>> properties of the database, rather than the store.
>
> Indeed.
>
> (...)
>> I'm not 100% sure what will happen if you create two stores in the
>> same thread, using different database objects returned by
>> create_database, though...?
>
> Nothing surprising will happen. What may be surprising is that
> depending on what is done, the *database* may cause the thread to
> deadlock (or at least wait for a timeout) because it's waiting for the
> "other connection" to finish and, if both connections are on the same
> thread, the other connection will of course not finish. That's all
> independent of Storm, though.
>
> --
> Gustavo Niemeyer
> http://niemeyer.net
>
> --
> storm mailing list
> storm at lists.canonical.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/storm
>
If anyone's interested, here's something I cooked up to make testing
easier with Oracle (as DDL statements just don't seem to execute in
SERIALIZABLE mode):
class OracleConnection(Connection):
...
def as_read_committed(self):
return _isolation_context(self)
class _isolation_context(object):
def __init__ (self, connection):
self.connection = connection
def __enter__(self):
self.connection.commit()
self.connection.execute('ALTER SESSION SET isolation_level =
read committed')
def __exit__(self, exc_type, exc_value, traceback):
if exc_value:
self.connection.rollback()
else:
self.connection.commit()
self.connection.execute('ALTER SESSION SET isolation_level =
serializable')
self.connection.commit()
This way, I can do something like this:
with connection.as_read_committted():
connection.execute(...)
Without worrying about an exception being thrown and causing the
entire connection to get stuck in the wrong mode. In light of this
thread, I'm sure there's a better way to do this, but someone might
find the general concept useful if they need to change the isolation
level temporarily.
More information about the storm
mailing list