opral / inlang-message-sdk

0 stars 0 forks source link

Use rename to write v2 store files atomically #86

Open jldec opened 3 weeks ago

jldec commented 3 weeks ago

Context

If the store process exits during a write, files should not be left in a partially written state.

Proposal

First write to a temp file and then rename.

This is related to https://github.com/opral/inlang-message-sdk/issues/80, since we need to keep watching the file after rename.

samuelstroschein commented 3 weeks ago

since we need to keep watching the file after rename.

In what scenario will a file be renamed?

I assume that the file name will be the (human) id of the message. By definition, the human id will never change

jldec commented 3 weeks ago

Right, the filename known to git should not change.

The idea for this is to use a temp filename during the write, and then rename that to replace the versioned filename, when the file is fully persisted on disk. This (hopefully) makes the changes to the file atomic.

jldec commented 2 weeks ago

LIX-83