Skip to content

Commit

Permalink
coordinator: atomically replace the sealed data file on store commit
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasten committed Nov 13, 2024
1 parent 73cc2ca commit 82dc444
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions coordinator/store/stdstore/stdstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,14 @@ func (s *StdStore) commit(data map[string][]byte) error {
return err
}

if err := s.fs.WriteFile(filepath.Join(s.sealDir, SealedDataFname), sealedData, 0o600); err != nil {
return err
// atomically replace the sealed data file
sealedDataPath := filepath.Join(s.sealDir, SealedDataFname)
sealedDataPathTmp := sealedDataPath + ".tmp"
if err := s.fs.WriteFile(sealedDataPathTmp, sealedData, 0o600); err != nil {
return fmt.Errorf("writing sealed data file: %w", err)
}
if err := s.fs.Rename(sealedDataPathTmp, sealedDataPath); err != nil {
return fmt.Errorf("renaming sealed data file: %w", err)
}
}

Expand Down

0 comments on commit 82dc444

Please sign in to comment.