Skip to content

Commit

Permalink
Also use O_SYNC for writing consumer state as well as newly generat…
Browse files Browse the repository at this point in the history
…ed encryption keys

Signed-off-by: Neil Twigg <neil@nats.io>
  • Loading branch information
neilalexander committed Jul 31, 2024
1 parent a35a7b8 commit 540468a
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions server/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -1201,9 +1201,7 @@ func (mb *msgBlock) convertCipher() error {
// the old keyfile back.
if err := fs.genEncryptionKeysForBlock(mb); err != nil {
keyFile := filepath.Join(mdir, fmt.Sprintf(keyScan, mb.index))
<-dios
os.WriteFile(keyFile, ekey, defaultFilePerms)
dios <- struct{}{}
fs.writeFileWithOptionalSync(keyFile, ekey, defaultFilePerms)
return err
}
mb.bek.XORKeyStream(buf, buf)
Expand Down Expand Up @@ -3396,9 +3394,7 @@ func (fs *fileStore) genEncryptionKeysForBlock(mb *msgBlock) error {
if _, err := os.Stat(keyFile); err != nil && !os.IsNotExist(err) {
return err
}
<-dios
err = os.WriteFile(keyFile, encrypted, defaultFilePerms)
dios <- struct{}{}
err = fs.writeFileWithOptionalSync(keyFile, encrypted, defaultFilePerms)
if err != nil {
return err
}
Expand Down Expand Up @@ -9164,9 +9160,7 @@ func (o *consumerFileStore) writeState(buf []byte) error {
o.mu.Unlock()

// Lock not held here but we do limit number of outstanding calls that could block OS threads.
<-dios
err := os.WriteFile(ifn, buf, defaultFilePerms)
dios <- struct{}{}
err := o.fs.writeFileWithOptionalSync(ifn, buf, defaultFilePerms)

o.mu.Lock()
if err != nil {
Expand Down Expand Up @@ -9530,9 +9524,7 @@ func (o *consumerFileStore) Stop() error {

if len(buf) > 0 {
o.waitOnFlusher()
<-dios
err = os.WriteFile(ifn, buf, defaultFilePerms)
dios <- struct{}{}
err = o.fs.writeFileWithOptionalSync(ifn, buf, defaultFilePerms)
}
return err
}
Expand Down

0 comments on commit 540468a

Please sign in to comment.