Closed darron closed 8 years ago
Instead of writing it in place, write to a different name - then rename the file.
This helps to make sure that processes are watching the file never see a 0-length file in the middle of an update.
This is being done because ioutil.Writefile truncates any existing file in place which at high velocities means bad things can happen.
This makes sure that the file is replaced atomically. This also means we can remove the chmod code we added here:
https://github.com/DataDog/kvexpress/issues/78
Since we're always creating a new file - the perms will always be correct.
Original issue: https://github.com/DataDog/kvexpress/issues/88
cc @Arkelenia @calebdoxsey
LGTM :+1:
Thanks for this change :)
Closes #88.
Awesome! Curious - do you still need the Chown operation that follows the rename?
Chown
Yes - I removed the chmod that wasn't necessary anymore - that's handled by the WriteFile - but the chown is still required.
WriteFile
You can't set the oid and gid with WriteFile - this makes sure that's consistent.
Instead of writing it in place, write to a different name - then rename the file.
This helps to make sure that processes are watching the file never see a 0-length file in the middle of an update.
This is being done because ioutil.Writefile truncates any existing file in place which at high velocities means bad things can happen.
This makes sure that the file is replaced atomically. This also means we can remove the chmod code we added here:
https://github.com/DataDog/kvexpress/issues/78
Since we're always creating a new file - the perms will always be correct.
Original issue: https://github.com/DataDog/kvexpress/issues/88
cc @Arkelenia @calebdoxsey