Skip to content

Commit

Permalink
Issue #4 -- Coupled AcidFS with SQLAlchemy transactions
Browse files Browse the repository at this point in the history
In theory DB commits and AcidFS commits should be in sync: Based on this assumption shifting `transaction.commit` from `property.py` to `ext/db.py` should work. Actually it *does* work, but somehow AcidFS only commits the most recent `write` .. seems like a bug of AcidFS to me, but due to the complexity of this "test" case it could also be a flawed conclusion on my part.
  • Loading branch information
Hasan Karahan committed Aug 17, 2013
1 parent cd780b8 commit 2586768
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
15 changes: 15 additions & 0 deletions webed/ext/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import os.path
import functools
import sqlalchemy
import transaction

###############################################################################
###############################################################################
Expand Down Expand Up @@ -106,9 +107,16 @@ def decorated (*args, **kwargs):
try:
result = fn (*args, **kwargs)
self.session.commit ()

current = transaction.get()
current.setExtendedInfo ('user', app.config['FS_ACID_USER'])
current.setExtendedInfo ('email', app.config['FS_ACID_MAIL'])
transaction.commit ()

return result
except:
self.session.rollback ()
transaction.abort ()
raise

return decorated
Expand All @@ -130,9 +138,16 @@ def decorated (*args, **kwargs):
try:
result = fn (*args, **kwargs)
self.session.commit ()

current = transaction.get()
current.setExtendedInfo ('user', app.config['FS_ACID_USER'])
current.setExtendedInfo ('email', app.config['FS_ACID_MAIL'])
transaction.commit ()

return result
except:
self.session.rollback ()
transaction.abort ()
raise

return decorated
Expand Down
18 changes: 0 additions & 18 deletions webed/models/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,6 @@ def set_data (self, value, skip_patch=False):
with self.fs.open (name, mode='wb') as target:
target.write (self.encode (value))

current = transaction.get()
current.note ('Update %s' % self.node.name)
current.setExtendedInfo ('user', app.config['FS_ACID_USER'])
current.setExtendedInfo ('email', app.config['FS_ACID_MAIL'])
transaction.commit ()

def decode (self, value): return value
def encode (self, value): return value
def patch (self, value): return value
Expand Down Expand Up @@ -231,12 +225,6 @@ def on_path_update (target, src_path, dst_path, initiator):
if target.fs.exists (src_path):
target.fs.mv (src_path, dst_path)

current = transaction.get()
current.note ('Rename %s' % target.node.name)
current.setExtendedInfo ('user', app.config['FS_ACID_USER'])
current.setExtendedInfo ('email', app.config['FS_ACID_MAIL'])
transaction.commit ()

@staticmethod
def on_delete (mapper, connection, target):

Expand All @@ -249,12 +237,6 @@ def on_delete (mapper, connection, target):
if target.fs.exists (path_to):
target.fs.rm (path_to)

current = transaction.get()
current.note ('Delete %s' % target.node.name)
current.setExtendedInfo ('user', app.config['FS_ACID_USER'])
current.setExtendedInfo ('email', app.config['FS_ACID_MAIL'])
transaction.commit ()

@classmethod
def register (cls):
event.listen (cls, 'after_delete', cls.on_delete, propagate=True)
Expand Down

0 comments on commit 2586768

Please sign in to comment.