Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[events-api] Create cfg file in parallel without data truncation (glu…
…ster#4079) * [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: gluster#3714 Updates: gluster#3715 Signed-off-by: black-dragon74 <[email protected]> * [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 <[email protected]> * [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 <[email protected]> * [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 <[email protected]> * [events-api] Remove zombie file in case of exception Signed-off-by: black-dragon74 <[email protected]> * [events-api] Refactor code as per reviews Signed-off-by: black-dragon74 <[email protected]> * Fix regression failures due to py3 syntax Change-Id: I976ded40393c6b84c4c08428f3a025df1e21b614 Signed-off-by: black-dragon74 <[email protected]> --------- Signed-off-by: black-dragon74 <[email protected]>
- Loading branch information