memory: add end-to-end integration tests + polish
This commit is contained in:
1 parent
9381b2b661
commit
4877db85ae
4 files changed
+158
-11
No files matched your search
@@ -34,6 +34,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -337,6 +338,15 @@ func (s *Store) Compact(_ context.Context) error {
|
||||
os.Remove(tmp)
|
||||
return fmt.Errorf("rename: %w", err)
|
||||
}
|
||||
// Fsync the parent directory so the rename is durable across crashes.
|
||||
// On Linux, an unfsync'd directory metadata change can be rolled back
|
||||
// after a power loss even though the rename(2) syscall succeeded.
|
||||
// On Windows, opening a directory like this isn't supported; ignore
|
||||
// the error there since flock is also a no-op.
|
||||
if dir, err := os.Open(filepath.Dir(s.path)); err == nil {
|
||||
_ = dir.Sync()
|
||||
_ = dir.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user