Skip to content

Commit

Permalink
Merge pull request #2943 from matthewrmshin/fsync-dot-service-after-c…
Browse files Browse the repository at this point in the history
…reating-contact-file

contact file creation: fsync parent directory
  • Loading branch information
kinow authored Feb 6, 2019
2 parents c45e6f8 + 57cb26b commit 268270e
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 268270e

Please sign in to comment.