mirror of
https://github.com/gluster/glusterfs.git
synced 2026-02-06 00:49:30 +01:00
* [events-api] Write cfg file with exclusive locks to prevent race cases that might occur when several nodes are trying to create the config file at the same time if it is non existent (first run). Fixes: #3714 Updates: #3715 Signed-off-by: black-dragon74 <niryadav@redhat.com> * [events-api] Use tempfiles for parallel writes without contention The tempfile created is different everytime, the logic of which is encapsulated in `NamedTempOpen` class. Once we are done writing the data to the file it is then persisted to the disk with `os.rename()` call under the name of `filename` passed as an arg when instantiating the class. This approach saves us the need of fcntl locks and still guarantees the sanity of the file. Signed-off-by: black-dragon74 <niryadav@redhat.com> * [events-api] Close FD before renaming the file As after rename fop, the already open file descriptor will be stale and in a bad state which is erroneous. Signed-off-by: black-dragon74 <niryadav@redhat.com> * [events-api] Hidden temp file and use dest dir as wd The temp file created by `NamedTempOpen` is now hidden (prefixed with a '.'). Additionally the temp file is now created in the dest dir of the named file, i.e. in case the filepath is /foo/bar, the temp file will be created inside /foo. In case the dest dir cannot be determined (cases where the path is just a filename eg. 'myfile.json`), cwd of the process is used. However, we will never encounter this use case as we always provide the full path. Signed-off-by: black-dragon74 <niryadav@redhat.com> * [events-api] Remove zombie file in case of exception Signed-off-by: black-dragon74 <niryadav@redhat.com> * [events-api] Refactor code as per reviews Signed-off-by: black-dragon74 <niryadav@redhat.com> * Fix regression failures due to py3 syntax Change-Id: I976ded40393c6b84c4c08428f3a025df1e21b614 Signed-off-by: black-dragon74 <niryadav@redhat.com> --------- Signed-off-by: black-dragon74 <niryadav@redhat.com>