DataDog / kvexpress

## Auto-archived due to inactivity. ## Go program to move data in and out of Consul's KV store.
Apache License 2.0
129 stars 13 forks source link

Atomic rename instead of truncate and write in place. #89

Closed darron closed 8 years ago

darron commented 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

Arkelenia commented 8 years ago

LGTM :+1:

Arkelenia commented 8 years ago

Thanks for this change :)

darron commented 8 years ago

Closes #88.

miketheman commented 8 years ago

Awesome! Curious - do you still need the Chown operation that follows the rename?

darron commented 8 years ago

Yes - I removed the chmod that wasn't necessary anymore - that's handled by the WriteFile - but the chown is still required.

You can't set the oid and gid with WriteFile - this makes sure that's consistent.