Skip to content
Snippets Groups Projects
Commit 2fb96d39 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

ganeti-watcher: Don't write file if data didn't change

This is the safest way to detect changes and the amount of data
is small, so keeping a copy around is cheap enough.

Reviewed-by: iustinp
parent b76f660d
No related branches found
No related tags found
No related merge requests found
...@@ -136,12 +136,19 @@ class WatcherState(object): ...@@ -136,12 +136,19 @@ class WatcherState(object):
if "node" not in self._data: if "node" not in self._data:
self._data["node"] = {} self._data["node"] = {}
self._orig_data = self._data.copy()
def Save(self): def Save(self):
"""Save state to file, then unlock and close it. """Save state to file, then unlock and close it.
""" """
assert self.statefile assert self.statefile
if self._orig_data == self._data:
logging.debug("Data didn't change, just touching status file")
os.utime(constants.WATCHER_STATEFILE, None)
return
# We need to make sure the file is locked before renaming it, otherwise # We need to make sure the file is locked before renaming it, otherwise
# starting ganeti-watcher again at the same time will create a conflict. # starting ganeti-watcher again at the same time will create a conflict.
fd = utils.WriteFile(constants.WATCHER_STATEFILE, fd = utils.WriteFile(constants.WATCHER_STATEFILE,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment