diff --git a/lib/fs/fs.go b/lib/fs/fs.go index dddb496a7..72573ebf8 100644 --- a/lib/fs/fs.go +++ b/lib/fs/fs.go @@ -72,8 +72,8 @@ var ( readersCount = metrics.NewCounter(`vm_fs_readers`) ) -// SyncPath syncs contents of the given path. -func SyncPath(path string) { +// MustSyncPath syncs contents of the given path. +func MustSyncPath(path string) { d, err := os.Open(path) if err != nil { logger.Panicf("FATAL: cannot open %q: %s", path, err) @@ -114,7 +114,7 @@ func WriteFile(path string, data []byte) error { return fmt.Errorf("cannot obtain absolute path to %q: %s", path, err) } parentDirPath := filepath.Dir(absPath) - SyncPath(parentDirPath) + MustSyncPath(parentDirPath) return nil } @@ -144,7 +144,7 @@ func mkdirSync(path string) error { // Sync the parent directory, so the created directory becomes visible // in the fs after power loss. parentDirPath := filepath.Dir(path) - SyncPath(parentDirPath) + MustSyncPath(parentDirPath) return nil } @@ -176,7 +176,7 @@ func RemoveDirContents(dir string) { logger.Panicf("FATAL: cannot remove %q: %s", fullPath, err) } } - SyncPath(dir) + MustSyncPath(dir) } // MustClose must close the given file f. @@ -203,7 +203,7 @@ func IsPathExist(path string) bool { func MustRemoveAllSynced(path string) { MustRemoveAll(path) parentDirPath := filepath.Dir(path) - SyncPath(parentDirPath) + MustSyncPath(parentDirPath) } // MustRemoveAll removes path with all the contents. @@ -297,7 +297,7 @@ func HardLinkFiles(srcDir, dstDir string) error { } } - SyncPath(dstDir) + MustSyncPath(dstDir) return nil } diff --git a/lib/mergeset/block_stream_writer.go b/lib/mergeset/block_stream_writer.go index 67826b494..8144cfafe 100644 --- a/lib/mergeset/block_stream_writer.go +++ b/lib/mergeset/block_stream_writer.go @@ -154,7 +154,7 @@ func (bsw *blockStreamWriter) MustClose() { // Sync bsw.path contents to make sure it doesn't disappear // after system crash or power loss. if bsw.path != "" { - fs.SyncPath(bsw.path) + fs.MustSyncPath(bsw.path) } bsw.reset() diff --git a/lib/mergeset/table.go b/lib/mergeset/table.go index d1b295e73..504b04027 100644 --- a/lib/mergeset/table.go +++ b/lib/mergeset/table.go @@ -861,7 +861,7 @@ func openParts(path string) ([]*partWrapper, error) { return nil, fmt.Errorf("cannot create %q: %s", tmpDir, err) } - fs.SyncPath(path) + fs.MustSyncPath(path) // Open parts. fis, err := d.Readdir(-1) @@ -965,9 +965,9 @@ func (tb *Table) CreateSnapshotAt(dstDir string) error { } } - fs.SyncPath(dstDir) + fs.MustSyncPath(dstDir) parentDir := filepath.Dir(dstDir) - fs.SyncPath(parentDir) + fs.MustSyncPath(parentDir) logger.Infof("created Table snapshot of %q at %q in %s", srcDir, dstDir, time.Since(startTime)) return nil @@ -1061,7 +1061,7 @@ func runTransaction(txnLock *sync.RWMutex, pathPrefix, txnPath string) error { } // Flush pathPrefix directory metadata to the underying storage. - fs.SyncPath(pathPrefix) + fs.MustSyncPath(pathPrefix) // Remove the transaction file. if err := os.Remove(txnPath); err != nil { diff --git a/lib/storage/block_stream_writer.go b/lib/storage/block_stream_writer.go index 3b7f56010..3e89c08a6 100644 --- a/lib/storage/block_stream_writer.go +++ b/lib/storage/block_stream_writer.go @@ -149,7 +149,7 @@ func (bsw *blockStreamWriter) MustClose() { // Sync bsw.path contents to make sure it doesn't disappear // after system crash or power loss. if bsw.path != "" { - fs.SyncPath(bsw.path) + fs.MustSyncPath(bsw.path) } bsw.reset() diff --git a/lib/storage/partition.go b/lib/storage/partition.go index 224b4ccbf..796d9b448 100644 --- a/lib/storage/partition.go +++ b/lib/storage/partition.go @@ -1342,8 +1342,8 @@ func (pt *partition) createSnapshot(srcDir, dstDir string) error { } } - fs.SyncPath(dstDir) - fs.SyncPath(filepath.Dir(dstDir)) + fs.MustSyncPath(dstDir) + fs.MustSyncPath(filepath.Dir(dstDir)) return nil } @@ -1444,8 +1444,8 @@ func runTransaction(txnLock *sync.RWMutex, pathPrefix1, pathPrefix2, txnPath str } // Flush pathPrefix* directory metadata to the underying storage. - fs.SyncPath(pathPrefix1) - fs.SyncPath(pathPrefix2) + fs.MustSyncPath(pathPrefix1) + fs.MustSyncPath(pathPrefix2) // Remove the transaction file. if err := os.Remove(txnPath); err != nil { @@ -1487,6 +1487,6 @@ func createPartitionDirs(path string) error { if err := fs.MkdirAllFailIfExist(tmpPath); err != nil { return fmt.Errorf("cannot create tmp directory %q: %s", tmpPath, err) } - fs.SyncPath(path) + fs.MustSyncPath(path) return nil } diff --git a/lib/storage/storage.go b/lib/storage/storage.go index 93a4dc744..6a1af8a24 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -181,7 +181,7 @@ func (s *Storage) CreateSnapshot() (string, error) { if err := fs.SymlinkRelative(bigDir, dstBigDir); err != nil { return "", fmt.Errorf("cannot create symlink from %q to %q: %s", bigDir, dstBigDir, err) } - fs.SyncPath(dstDataDir) + fs.MustSyncPath(dstDataDir) idbSnapshot := fmt.Sprintf("%s/indexdb/snapshots/%s", s.path, snapshotName) idb := s.idb() @@ -201,8 +201,8 @@ func (s *Storage) CreateSnapshot() (string, error) { return "", fmt.Errorf("cannot create symlink from %q to %q: %s", idbSnapshot, dstIdbDir, err) } - fs.SyncPath(dstDir) - fs.SyncPath(srcDir + "/snapshots") + fs.MustSyncPath(dstDir) + fs.MustSyncPath(srcDir + "/snapshots") logger.Infof("created Storage snapshot for %q at %q in %s", srcDir, dstDir, time.Since(startTime)) return snapshotName, nil @@ -401,7 +401,7 @@ func (s *Storage) mustRotateIndexDB() { s.idbCurr.Store(idbNew) // Persist changes on the file system. - fs.SyncPath(s.path) + fs.MustSyncPath(s.path) // Flush tsidCache, so idbNew can be populated with fresh data. s.tsidCache.Reset() @@ -904,7 +904,7 @@ func openIndexDBTables(path string, metricIDCache, metricNameCache *fastcache.Ca } // Persist changes on the file system. - fs.SyncPath(path) + fs.MustSyncPath(path) // Open the last two tables. currPath := path + "/" + tableNames[len(tableNames)-1] diff --git a/lib/storage/table.go b/lib/storage/table.go index b1f798b9b..0cb719f1b 100644 --- a/lib/storage/table.go +++ b/lib/storage/table.go @@ -164,10 +164,10 @@ func (tb *table) CreateSnapshot(snapshotName string) (string, string, error) { } } - fs.SyncPath(dstSmallDir) - fs.SyncPath(dstBigDir) - fs.SyncPath(filepath.Dir(dstSmallDir)) - fs.SyncPath(filepath.Dir(dstBigDir)) + fs.MustSyncPath(dstSmallDir) + fs.MustSyncPath(dstBigDir) + fs.MustSyncPath(filepath.Dir(dstSmallDir)) + fs.MustSyncPath(filepath.Dir(dstBigDir)) logger.Infof("created table snapshot for %q at (%q, %q) in %s", tb.path, dstSmallDir, dstBigDir, time.Since(startTime)) return dstSmallDir, dstBigDir, nil