diff options
Diffstat (limited to 'internal/persistence/txn.go')
| -rw-r--r-- | internal/persistence/txn.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/internal/persistence/txn.go b/internal/persistence/txn.go index d09feaa..8ba21fa 100644 --- a/internal/persistence/txn.go +++ b/internal/persistence/txn.go @@ -238,6 +238,15 @@ func (t *Transaction) Commit() error { } journalPath := filepath.Join(t.journalDir, "txn-"+hex.EncodeToString(id[:])+".json") if err := WriteFile(journalPath, journal, 0600); err != nil { + // WriteFile can fail AFTER the rename (e.g. the directory fsync), + // leaving a complete, valid journal whose operations were never + // applied. Remove it before returning so a later Recover cannot replay + // its before-images over newer writes; if the removal also fails, + // surface that so the caller can stop admitting mutations instead of + // serving on with an unrecoverable journal on disk. + if rErr := t.removeJournalDurable(journalPath); rErr != nil { + return fmt.Errorf("write journal: %v; journal cleanup failed (journal left on disk): %v", err, rErr) + } return fmt.Errorf("write journal: %w", err) } |
