Skip to content

Commit

Permalink
contact file creation: fsync parent directory
Browse files Browse the repository at this point in the history
On file system such as an NFS mounted file system, we may have a delay
before the file becomes visible from other process running on other
host. We already have a 1st fsync to ensure that the data of the contact
file is written to disk. This change adds a 2nd fsync to ensure that the
file metadata of the contact file is written as well - by doing an fsync
on its directory.
  • Loading branch information
matthewrmshin committed Feb 5, 2019
1 parent 5099fd6 commit 57cb26b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/cylc/suite_srv_files_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,19 @@ def detect_old_contact_file(self, reg, check_host_port=None):

def dump_contact_file(self, reg, data):
"""Create contact file. Data should be a key=value dict."""
# Note:
# 1st fsync for writing the content of the contact file to disk.
# 2nd fsync for writing the file metadata of the contact file to disk.
# The double fsync logic ensures that if the contact file is written to
# a shared file system e.g. via NFS, it will be immediately visible
# from by a process on other hosts after the current process returns.
with open(self.get_contact_file(reg), "wb") as handle:
for key, value in sorted(data.items()):
handle.write("%s=%s\n" % (key, value))
os.fsync(handle.fileno())
dir_fileno = os.open(self.get_suite_srv_dir(reg), os.O_DIRECTORY)
os.fsync(dir_fileno)
os.close(dir_fileno)

def get_contact_file(self, reg):
"""Return name of contact file."""
Expand Down

0 comments on commit 57cb26b

Please sign in to comment.