From 344209e5e60865a5829b1cafe387057f488b92cc Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 13 Apr 2023 21:42:11 -0700 Subject: [PATCH] lib/fs: rename MustWriteFileAndSync to MustWriteSync in order to improve readability a bit This is a follow-up for 2a8395be0503c934073ccc06c82a4ab6e37f3889 --- lib/fs/fs.go | 6 +++--- lib/mergeset/inmemory_part.go | 8 ++++---- lib/mergeset/part_header.go | 2 +- lib/storage/inmemory_part.go | 8 ++++---- lib/storage/part_header.go | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/fs/fs.go b/lib/fs/fs.go index d343f1fb5e..380a1cba4d 100644 --- a/lib/fs/fs.go +++ b/lib/fs/fs.go @@ -25,7 +25,7 @@ func MustSyncPath(path string) { mustSyncPath(path) } -// MustWriteFileAndSync writes data to the file at path and then calls fsync on the created file. +// MustWriteSync writes data to the file at path and then calls fsync on the created file. // // The fsync guarantees that the written data survives hardware reset after successful call. // @@ -33,7 +33,7 @@ func MustSyncPath(path string) { // in the middle of the write. // Use WriteFileAtomically if the file at the path must be either written in full // or not written at all on app crash in the middle of the write. -func MustWriteFileAndSync(path string, data []byte) { +func MustWriteSync(path string, data []byte) { f, err := filestream.Create(path, false) if err != nil { logger.Panicf("FATAL: cannot create file: %s", err) @@ -69,7 +69,7 @@ func WriteFileAtomically(path string, data []byte, canOverwrite bool) error { // Write data to a temporary file. n := atomic.AddUint64(&tmpFileNum, 1) tmpPath := fmt.Sprintf("%s.tmp.%d", path, n) - MustWriteFileAndSync(tmpPath, data) + MustWriteSync(tmpPath, data) // Atomically move the temporary file from tmpPath to path. if err := os.Rename(tmpPath, path); err != nil { diff --git a/lib/mergeset/inmemory_part.go b/lib/mergeset/inmemory_part.go index 500bc18832..794f1dedca 100644 --- a/lib/mergeset/inmemory_part.go +++ b/lib/mergeset/inmemory_part.go @@ -38,16 +38,16 @@ func (mp *inmemoryPart) StoreToDisk(path string) error { return fmt.Errorf("cannot create directory %q: %w", path, err) } metaindexPath := filepath.Join(path, metaindexFilename) - fs.MustWriteFileAndSync(metaindexPath, mp.metaindexData.B) + fs.MustWriteSync(metaindexPath, mp.metaindexData.B) indexPath := filepath.Join(path, indexFilename) - fs.MustWriteFileAndSync(indexPath, mp.indexData.B) + fs.MustWriteSync(indexPath, mp.indexData.B) itemsPath := filepath.Join(path, itemsFilename) - fs.MustWriteFileAndSync(itemsPath, mp.itemsData.B) + fs.MustWriteSync(itemsPath, mp.itemsData.B) lensPath := filepath.Join(path, lensFilename) - fs.MustWriteFileAndSync(lensPath, mp.lensData.B) + fs.MustWriteSync(lensPath, mp.lensData.B) mp.ph.MustWriteMetadata(path) diff --git a/lib/mergeset/part_header.go b/lib/mergeset/part_header.go index c77de65c10..8ff1432a95 100644 --- a/lib/mergeset/part_header.go +++ b/lib/mergeset/part_header.go @@ -128,5 +128,5 @@ func (ph *partHeader) MustWriteMetadata(partPath string) { // There is no need in calling fs.WriteFileAtomically() here, // since the file is created only once during part creatinng // and the part directory is synced aftewards. - fs.MustWriteFileAndSync(metadataPath, metadata) + fs.MustWriteSync(metadataPath, metadata) } diff --git a/lib/storage/inmemory_part.go b/lib/storage/inmemory_part.go index 56719afa70..b5b9b05599 100644 --- a/lib/storage/inmemory_part.go +++ b/lib/storage/inmemory_part.go @@ -41,16 +41,16 @@ func (mp *inmemoryPart) StoreToDisk(path string) error { return fmt.Errorf("cannot create directory %q: %w", path, err) } timestampsPath := filepath.Join(path, timestampsFilename) - fs.MustWriteFileAndSync(timestampsPath, mp.timestampsData.B) + fs.MustWriteSync(timestampsPath, mp.timestampsData.B) valuesPath := filepath.Join(path, valuesFilename) - fs.MustWriteFileAndSync(valuesPath, mp.valuesData.B) + fs.MustWriteSync(valuesPath, mp.valuesData.B) indexPath := filepath.Join(path, indexFilename) - fs.MustWriteFileAndSync(indexPath, mp.indexData.B) + fs.MustWriteSync(indexPath, mp.indexData.B) metaindexPath := filepath.Join(path, metaindexFilename) - fs.MustWriteFileAndSync(metaindexPath, mp.metaindexData.B) + fs.MustWriteSync(metaindexPath, mp.metaindexData.B) mp.ph.MustWriteMetadata(path) diff --git a/lib/storage/part_header.go b/lib/storage/part_header.go index 7da20e60c1..79495ec980 100644 --- a/lib/storage/part_header.go +++ b/lib/storage/part_header.go @@ -174,5 +174,5 @@ func (ph *partHeader) MustWriteMetadata(partPath string) { // There is no need in calling fs.WriteFileAtomically() here, // since the file is created only once during part creatinng // and the part directory is synced aftewards. - fs.MustWriteFileAndSync(metadataPath, metadata) + fs.MustWriteSync(metadataPath, metadata) }