[MediaWiki-commits] [Gerrit] operations/dumps[master]: fix check that file we have fcntl lock is empty
ArielGlenn has submitted this change and it was merged. Change subject: fix check that file we have fcntl lock is empty .. fix check that file we have fcntl lock is empty don't read contents by path, check size of filehandle via stat Change-Id: Ia530f00b800ae2d187b85b0eac6f949cba6ab8d4 --- M xmldumps-backup/miscdumplib.py 1 file changed, 11 insertions(+), 10 deletions(-) Approvals: ArielGlenn: Looks good to me, approved jenkins-bot: Verified diff --git a/xmldumps-backup/miscdumplib.py b/xmldumps-backup/miscdumplib.py index 64ce6a8..5f92108 100644 --- a/xmldumps-backup/miscdumplib.py +++ b/xmldumps-backup/miscdumplib.py @@ -306,32 +306,33 @@ ''' given number of seconds, see if file is older than this many seconds and remove file if so. we do this by opening the file exclusively first, -stat on the open fdesc, then remove path if it checks out. +stat on the open file handle, then remove path if it checks out. return True on removal, False for anything else including errors. ''' removed = False try: # we're not going to write anything but have to open for write # in order to get LOCK_EX -fdesc = open(self.lockfile.get_path(), "a+") +fhandle = open(self.lockfile.get_path(), "a+") # try to get the lock. if we can't then we give up try: -fcntl.lockf(fdesc, fcntl.LOCK_EX | fcntl.LOCK_NB) +fcntl.lockf(fhandle, fcntl.LOCK_EX | fcntl.LOCK_NB) except Exception: # fail to get lock or some other error -fdesc.close() +fhandle.close() return removed -if self._is_stale(cutoff, fdesc.fileno()): +if self._is_stale(cutoff, fhandle.fileno()): removed = self._unlock() else: # if the file did not exist, our open call would have created -# it, and then we would have an empty file. See if that's the -# case and if so, clean it up -contents = FileUtils.read_file(self.lockfile.get_path(self.date)) -if not contents: +# it, and then we would have an empty file. No one else would +# have written to it because we have the LOCK_EX here. +# See if that's the case and if so, clean up +filesize = os.fstat(fhandle.fileno()).st_size +if not filesize: removed = self._unlock() # lock removed now -fdesc.close() +fhandle.close() return removed except Exception: pass -- To view, visit https://gerrit.wikimedia.org/r/324246 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ia530f00b800ae2d187b85b0eac6f949cba6ab8d4 Gerrit-PatchSet: 1 Gerrit-Project: operations/dumps Gerrit-Branch: master Gerrit-Owner: ArielGlennGerrit-Reviewer: ArielGlenn Gerrit-Reviewer: jenkins-bot <> ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] operations/dumps[master]: fix check that file we have fcntl lock is empty
ArielGlenn has uploaded a new change for review. https://gerrit.wikimedia.org/r/324246 Change subject: fix check that file we have fcntl lock is empty .. fix check that file we have fcntl lock is empty don't read contents by path, check size of filehandle via stat Change-Id: Ia530f00b800ae2d187b85b0eac6f949cba6ab8d4 --- M xmldumps-backup/miscdumplib.py 1 file changed, 11 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/operations/dumps refs/changes/46/324246/1 diff --git a/xmldumps-backup/miscdumplib.py b/xmldumps-backup/miscdumplib.py index 64ce6a8..5f92108 100644 --- a/xmldumps-backup/miscdumplib.py +++ b/xmldumps-backup/miscdumplib.py @@ -306,32 +306,33 @@ ''' given number of seconds, see if file is older than this many seconds and remove file if so. we do this by opening the file exclusively first, -stat on the open fdesc, then remove path if it checks out. +stat on the open file handle, then remove path if it checks out. return True on removal, False for anything else including errors. ''' removed = False try: # we're not going to write anything but have to open for write # in order to get LOCK_EX -fdesc = open(self.lockfile.get_path(), "a+") +fhandle = open(self.lockfile.get_path(), "a+") # try to get the lock. if we can't then we give up try: -fcntl.lockf(fdesc, fcntl.LOCK_EX | fcntl.LOCK_NB) +fcntl.lockf(fhandle, fcntl.LOCK_EX | fcntl.LOCK_NB) except Exception: # fail to get lock or some other error -fdesc.close() +fhandle.close() return removed -if self._is_stale(cutoff, fdesc.fileno()): +if self._is_stale(cutoff, fhandle.fileno()): removed = self._unlock() else: # if the file did not exist, our open call would have created -# it, and then we would have an empty file. See if that's the -# case and if so, clean it up -contents = FileUtils.read_file(self.lockfile.get_path(self.date)) -if not contents: +# it, and then we would have an empty file. No one else would +# have written to it because we have the LOCK_EX here. +# See if that's the case and if so, clean up +filesize = os.fstat(fhandle.fileno()).st_size +if not filesize: removed = self._unlock() # lock removed now -fdesc.close() +fhandle.close() return removed except Exception: pass -- To view, visit https://gerrit.wikimedia.org/r/324246 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia530f00b800ae2d187b85b0eac6f949cba6ab8d4 Gerrit-PatchSet: 1 Gerrit-Project: operations/dumps Gerrit-Branch: master Gerrit-Owner: ArielGlenn___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits