From eb7df27e2025eba294f1ddd3bd73ee81d10a99df Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 13 Apr 2023 21:18:39 -0700 Subject: [PATCH] lib/{mergeset,storage}: properly fsync part directory listing after writing in-memory part to disk This is a follow-up after 42bba64aa797fd2f5f8239e11425c8a0fa63d06f Previously the part directory listing was fsync'ed implicitly inside partHeader.WriteMetadata() by calling fs.WriteFileAtomically(). Now it must be fsync'ed explicitly. There is no need in fsync'ing the parent directory, since it is fsync'ed by the caller when updating parts.json file. --- lib/mergeset/inmemory_part.go | 5 ++--- lib/storage/inmemory_part.go | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/mergeset/inmemory_part.go b/lib/mergeset/inmemory_part.go index 058abae8d7..a638a410d5 100644 --- a/lib/mergeset/inmemory_part.go +++ b/lib/mergeset/inmemory_part.go @@ -56,9 +56,8 @@ func (mp *inmemoryPart) StoreToDisk(path string) error { if err := mp.ph.WriteMetadata(path); err != nil { return fmt.Errorf("cannot store metadata: %w", err) } - // Sync parent directory in order to make sure the written files remain visible after hardware reset - parentDirPath := filepath.Dir(path) - fs.MustSyncPath(parentDirPath) + fs.MustSyncPath(path) + // Do not sync parent directory - it must be synced by the caller. return nil } diff --git a/lib/storage/inmemory_part.go b/lib/storage/inmemory_part.go index 45f3f4eb15..a8c6c3543f 100644 --- a/lib/storage/inmemory_part.go +++ b/lib/storage/inmemory_part.go @@ -59,9 +59,8 @@ func (mp *inmemoryPart) StoreToDisk(path string) error { if err := mp.ph.WriteMetadata(path); err != nil { return fmt.Errorf("cannot store metadata: %w", err) } - // Sync parent directory in order to make sure the written files remain visible after hardware reset - parentDirPath := filepath.Dir(path) - fs.MustSyncPath(parentDirPath) + fs.MustSyncPath(path) + // Do not sync parent directory - it must be synced by the caller. return nil }