From b94da20af1124c875344a540e4e189f39cb7e75d Mon Sep 17 00:00:00 2001 From: Giorgos Korfiatis <gkorf@grnet.gr> Date: Fri, 8 May 2015 16:59:56 +0300 Subject: [PATCH] protect client db actions with transactions --- agkyra/agkyra/syncer/localfs_client.py | 8 ++++++-- agkyra/agkyra/syncer/pithos_client.py | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/agkyra/agkyra/syncer/localfs_client.py b/agkyra/agkyra/syncer/localfs_client.py index 108ef27..b1e3450 100644 --- a/agkyra/agkyra/syncer/localfs_client.py +++ b/agkyra/agkyra/syncer/localfs_client.py @@ -515,7 +515,6 @@ class LocalfsFileClient(FileClient): return {"ident": None, "info": None} def walk_filesystem(self): - db = self.get_db() candidates = {} for dirpath, dirnames, files in os.walk(self.ROOTPATH): rel_dirpath = os.path.relpath(dirpath, start=self.ROOTPATH) @@ -532,11 +531,16 @@ class LocalfsFileClient(FileClient): candidates[objname] = self.none_info() db_cands = dict((name, self.none_info()) - for name in db.list_files(self.SIGNATURE)) + for name in self.list_files()) candidates.update(db_cands) logger.info("Candidates: %s" % candidates) return candidates + @transaction() + def list_files(self): + db = self.get_db() + return db.list_files(self.SIGNATURE) + def _local_path_changes(self, name, state): local_path = utils.join_path(self.ROOTPATH, name) return local_path_changes(local_path, state) diff --git a/agkyra/agkyra/syncer/pithos_client.py b/agkyra/agkyra/syncer/pithos_client.py index 97b1c2d..9e4a8a5 100644 --- a/agkyra/agkyra/syncer/pithos_client.py +++ b/agkyra/agkyra/syncer/pithos_client.py @@ -285,7 +285,6 @@ class PithosFileClient(FileClient): return d.keys() def get_pithos_candidates(self, last_modified=None): - db = self.get_db() try: objects = self.endpoint.list_objects() except ClientError as e: @@ -313,7 +312,7 @@ class PithosFileClient(FileClient): else: candidates = upstream_all - non_deleted_in_db = set(db.list_non_deleted_files(self.SIGNATURE)) + non_deleted_in_db = set(self.list_non_deleted_files()) newly_deleted_names = non_deleted_in_db.difference(upstream_all_names) logger.debug("newly_deleted %s" % newly_deleted_names) newly_deleted = dict((name, {"ident": None, "info": {}}) @@ -324,6 +323,11 @@ class PithosFileClient(FileClient): (last_modified, candidates)) return candidates + @transaction() + def list_non_deleted_files(self): + db = self.get_db() + return db.list_non_deleted_files(self.SIGNATURE) + def notifier(self): interval = self.settings.pithos_list_interval class PollPithosThread(utils.StoppableThread): -- GitLab