Commit 4c076f4e authored by Sofia Papagiannaki's avatar Sofia Papagiannaki Committed by Georgios D. Tsoukalas
Browse files

pithos: enforce transaction isolation level

Refs: #3582 #3585
parent 1e72a824
......@@ -33,8 +33,7 @@
from sqlalchemy import create_engine
#from sqlalchemy.event import listen
from sqlalchemy.engine import Engine
from sqlalchemy.pool import NullPool, QueuePool
from sqlalchemy.pool import NullPool
from sqlalchemy.interfaces import PoolListener
......@@ -45,16 +44,20 @@ class DBWrapper(object):
if db.startswith('sqlite://'):
class ForeignKeysListener(PoolListener):
def connect(self, dbapi_con, con_record):
db_cursor = dbapi_con.execute('pragma foreign_keys=ON;')
db_cursor = dbapi_con.execute(
'pragma case_sensitive_like=ON;')
self.engine = create_engine(db, connect_args={'check_same_thread': False}, poolclass=NullPool, listeners=[ForeignKeysListener()])
dbapi_con.execute('pragma foreign_keys=ON;')
dbapi_con.execute('pragma case_sensitive_like=ON;')
self.engine = create_engine(
db, connect_args={'check_same_thread': False},
poolclass=NullPool, listeners=[ForeignKeysListener()],
isolation_level='SERIALIZABLE')
#elif db.startswith('mysql://'):
# db = '%s?charset=utf8&use_unicode=0' %db
# self.engine = create_engine(db, convert_unicode=True)
else:
#self.engine = create_engine(db, pool_size=0, max_overflow=-1)
self.engine = create_engine(db, poolclass=NullPool)
self.engine = create_engine(
db, poolclass=NullPool, isolation_level='READ COMMITTED'
)
self.engine.echo = False
self.engine.echo_pool = False
self.conn = self.engine.connect()
......
......@@ -234,14 +234,14 @@ class Node(DBWorker):
r.close()
return inserted_primary_key
def node_lookup(self, path):
def node_lookup(self, path, for_update=False):
"""Lookup the current node of the given path.
Return None if the path is not found.
"""
# Use LIKE for comparison to avoid MySQL problems with trailing spaces.
s = select([self.nodes.c.node], self.nodes.c.path.like(
self.escape_like(path), escape=ESCAPE_CHAR))
self.escape_like(path), escape=ESCAPE_CHAR), for_update=for_update)
r = self.conn.execute(s)
row = r.fetchone()
r.close()
......
......@@ -203,9 +203,11 @@ class Node(DBWorker):
props = (parent, path)
return self.execute(q, props).lastrowid
def node_lookup(self, path):
def node_lookup(self, path, **kwargs):
"""Lookup the current node of the given path.
Return None if the path is not found.
kwargs is not used: it is passed for conformance
"""
q = "select node from nodes where path = ?"
......
......@@ -1217,7 +1217,7 @@ class ModularBackend(BaseBackend):
def _lookup_container(self, account, container):
path = '/'.join((account, container))
node = self.node.node_lookup(path)
node = self.node.node_lookup(path, for_update=True)
if node is None:
raise ItemNotExists('Container does not exist')
return path, node
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment