I'm writing logic for a patchable game, and patching involves modifying multiple files.
type UpdateInfo {
file string
data []byte
at int64
}
func AtomicUpdate(ui <-chan UpdateInfo) error {
for _, v := range ui {
file, err := os.OpenFile(v.file, os.O_RDWR|os.O_CREATE, 0)
if err != nil {
return err
}
_, err = file.WriteAt(v.data, v.at)
if err != nil {
return err
}
}
}
ui
represents a single atomic set of modifications that should be done in order to maintain a consistent state. The stakes of inconsistent state is users might have to redownload everything, which is pretty bad but isn't a catastrophe.
The question is then, what is a reasonable design to recover from a failed AtomicUpdate
where state may be left inconsistent?
There is also a possibility of some interrupt (such as users tripping over their power) may happen during AtomicUpdate
and doesn't even allow for normal error handling. Should this be a concern and how do I recover from that?