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
......@@ -136,12 +136,19 @@ class WatcherState(object):
if "node" not in self._data:
self._data["node"] = {}
self._orig_data = self._data.copy()
def Save(self):
"""Save state to file, then unlock and close it.
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)
# 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.
fd = utils.WriteFile(constants.WATCHER_STATEFILE,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment