On Wed, Mar 20, 2019 at 12:57 AM David Collier-Brown <dav...@spamcop.net> wrote:
> Is there an idiomatic way to address this? I ended up reading influxDB > code and doing all sorts of deranged safety-critical-system DFAs to > reassure myself this will actually work, but every time I do that, my brain > hurts! > > Not in general, I think. Suppose we have something along the lines of UPDATE weather SET observations = observations + 1; We exec this statement to the database, and we issue a COMMIT. But before we receive the result of that commit, the program fails, aborts and closes the connection. At this point whether or not the above statement was executed is unknown. The database is still consistent in both states, but we have no real way of knowing, save if we make a unique tag for each observation and test if the observation was admitted later on. If you then reread the input and commit it in the same way, you have just counted the observation twice, which is almost surely not what you want to do. The problem is akin to having a buffer with written data, but before having synced it to disk. The underlying problem is that if you have ephemeral data handling, such as overwriting data or having a counter, you are throwing away information. And in general, such computation is not reversible which leads to all sorts of fun things. If you have persistent data, such as an append-only log, then you are able to stitch together what happened and then remedy the problem. It also suggests it is generally safer to write a new file to disk and then eventually move said file on top of the existing one. In short, making this a safe semantics requires one to look at the specific problem at hand and make sure there is a way to recover. You are generally guaranteed a point-in-time consistent state of your system, if the database is worth its salt. But from there on, you are on your own to ensure things. -- J. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.