mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/fs: consistency renaming SyncPath -> MustSyncPath, since it doesnt return error
This commit is contained in:
parent
3fa4c28f6b
commit
51e2e255a6
7 changed files with 27 additions and 27 deletions
14
lib/fs/fs.go
14
lib/fs/fs.go
|
@ -72,8 +72,8 @@ var (
|
||||||
readersCount = metrics.NewCounter(`vm_fs_readers`)
|
readersCount = metrics.NewCounter(`vm_fs_readers`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// SyncPath syncs contents of the given path.
|
// MustSyncPath syncs contents of the given path.
|
||||||
func SyncPath(path string) {
|
func MustSyncPath(path string) {
|
||||||
d, err := os.Open(path)
|
d, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Panicf("FATAL: cannot open %q: %s", path, err)
|
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)
|
return fmt.Errorf("cannot obtain absolute path to %q: %s", path, err)
|
||||||
}
|
}
|
||||||
parentDirPath := filepath.Dir(absPath)
|
parentDirPath := filepath.Dir(absPath)
|
||||||
SyncPath(parentDirPath)
|
MustSyncPath(parentDirPath)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ func mkdirSync(path string) error {
|
||||||
// Sync the parent directory, so the created directory becomes visible
|
// Sync the parent directory, so the created directory becomes visible
|
||||||
// in the fs after power loss.
|
// in the fs after power loss.
|
||||||
parentDirPath := filepath.Dir(path)
|
parentDirPath := filepath.Dir(path)
|
||||||
SyncPath(parentDirPath)
|
MustSyncPath(parentDirPath)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ func RemoveDirContents(dir string) {
|
||||||
logger.Panicf("FATAL: cannot remove %q: %s", fullPath, err)
|
logger.Panicf("FATAL: cannot remove %q: %s", fullPath, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SyncPath(dir)
|
MustSyncPath(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustClose must close the given file f.
|
// MustClose must close the given file f.
|
||||||
|
@ -203,7 +203,7 @@ func IsPathExist(path string) bool {
|
||||||
func MustRemoveAllSynced(path string) {
|
func MustRemoveAllSynced(path string) {
|
||||||
MustRemoveAll(path)
|
MustRemoveAll(path)
|
||||||
parentDirPath := filepath.Dir(path)
|
parentDirPath := filepath.Dir(path)
|
||||||
SyncPath(parentDirPath)
|
MustSyncPath(parentDirPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustRemoveAll removes path with all the contents.
|
// MustRemoveAll removes path with all the contents.
|
||||||
|
@ -297,7 +297,7 @@ func HardLinkFiles(srcDir, dstDir string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncPath(dstDir)
|
MustSyncPath(dstDir)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,7 @@ func (bsw *blockStreamWriter) MustClose() {
|
||||||
// Sync bsw.path contents to make sure it doesn't disappear
|
// Sync bsw.path contents to make sure it doesn't disappear
|
||||||
// after system crash or power loss.
|
// after system crash or power loss.
|
||||||
if bsw.path != "" {
|
if bsw.path != "" {
|
||||||
fs.SyncPath(bsw.path)
|
fs.MustSyncPath(bsw.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
bsw.reset()
|
bsw.reset()
|
||||||
|
|
|
@ -861,7 +861,7 @@ func openParts(path string) ([]*partWrapper, error) {
|
||||||
return nil, fmt.Errorf("cannot create %q: %s", tmpDir, err)
|
return nil, fmt.Errorf("cannot create %q: %s", tmpDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.SyncPath(path)
|
fs.MustSyncPath(path)
|
||||||
|
|
||||||
// Open parts.
|
// Open parts.
|
||||||
fis, err := d.Readdir(-1)
|
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)
|
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))
|
logger.Infof("created Table snapshot of %q at %q in %s", srcDir, dstDir, time.Since(startTime))
|
||||||
return nil
|
return nil
|
||||||
|
@ -1061,7 +1061,7 @@ func runTransaction(txnLock *sync.RWMutex, pathPrefix, txnPath string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flush pathPrefix directory metadata to the underying storage.
|
// Flush pathPrefix directory metadata to the underying storage.
|
||||||
fs.SyncPath(pathPrefix)
|
fs.MustSyncPath(pathPrefix)
|
||||||
|
|
||||||
// Remove the transaction file.
|
// Remove the transaction file.
|
||||||
if err := os.Remove(txnPath); err != nil {
|
if err := os.Remove(txnPath); err != nil {
|
||||||
|
|
|
@ -149,7 +149,7 @@ func (bsw *blockStreamWriter) MustClose() {
|
||||||
// Sync bsw.path contents to make sure it doesn't disappear
|
// Sync bsw.path contents to make sure it doesn't disappear
|
||||||
// after system crash or power loss.
|
// after system crash or power loss.
|
||||||
if bsw.path != "" {
|
if bsw.path != "" {
|
||||||
fs.SyncPath(bsw.path)
|
fs.MustSyncPath(bsw.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
bsw.reset()
|
bsw.reset()
|
||||||
|
|
|
@ -1342,8 +1342,8 @@ func (pt *partition) createSnapshot(srcDir, dstDir string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.SyncPath(dstDir)
|
fs.MustSyncPath(dstDir)
|
||||||
fs.SyncPath(filepath.Dir(dstDir))
|
fs.MustSyncPath(filepath.Dir(dstDir))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1444,8 +1444,8 @@ func runTransaction(txnLock *sync.RWMutex, pathPrefix1, pathPrefix2, txnPath str
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flush pathPrefix* directory metadata to the underying storage.
|
// Flush pathPrefix* directory metadata to the underying storage.
|
||||||
fs.SyncPath(pathPrefix1)
|
fs.MustSyncPath(pathPrefix1)
|
||||||
fs.SyncPath(pathPrefix2)
|
fs.MustSyncPath(pathPrefix2)
|
||||||
|
|
||||||
// Remove the transaction file.
|
// Remove the transaction file.
|
||||||
if err := os.Remove(txnPath); err != nil {
|
if err := os.Remove(txnPath); err != nil {
|
||||||
|
@ -1487,6 +1487,6 @@ func createPartitionDirs(path string) error {
|
||||||
if err := fs.MkdirAllFailIfExist(tmpPath); err != nil {
|
if err := fs.MkdirAllFailIfExist(tmpPath); err != nil {
|
||||||
return fmt.Errorf("cannot create tmp directory %q: %s", tmpPath, err)
|
return fmt.Errorf("cannot create tmp directory %q: %s", tmpPath, err)
|
||||||
}
|
}
|
||||||
fs.SyncPath(path)
|
fs.MustSyncPath(path)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,7 @@ func (s *Storage) CreateSnapshot() (string, error) {
|
||||||
if err := fs.SymlinkRelative(bigDir, dstBigDir); err != nil {
|
if err := fs.SymlinkRelative(bigDir, dstBigDir); err != nil {
|
||||||
return "", fmt.Errorf("cannot create symlink from %q to %q: %s", bigDir, dstBigDir, err)
|
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)
|
idbSnapshot := fmt.Sprintf("%s/indexdb/snapshots/%s", s.path, snapshotName)
|
||||||
idb := s.idb()
|
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)
|
return "", fmt.Errorf("cannot create symlink from %q to %q: %s", idbSnapshot, dstIdbDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.SyncPath(dstDir)
|
fs.MustSyncPath(dstDir)
|
||||||
fs.SyncPath(srcDir + "/snapshots")
|
fs.MustSyncPath(srcDir + "/snapshots")
|
||||||
|
|
||||||
logger.Infof("created Storage snapshot for %q at %q in %s", srcDir, dstDir, time.Since(startTime))
|
logger.Infof("created Storage snapshot for %q at %q in %s", srcDir, dstDir, time.Since(startTime))
|
||||||
return snapshotName, nil
|
return snapshotName, nil
|
||||||
|
@ -401,7 +401,7 @@ func (s *Storage) mustRotateIndexDB() {
|
||||||
s.idbCurr.Store(idbNew)
|
s.idbCurr.Store(idbNew)
|
||||||
|
|
||||||
// Persist changes on the file system.
|
// Persist changes on the file system.
|
||||||
fs.SyncPath(s.path)
|
fs.MustSyncPath(s.path)
|
||||||
|
|
||||||
// Flush tsidCache, so idbNew can be populated with fresh data.
|
// Flush tsidCache, so idbNew can be populated with fresh data.
|
||||||
s.tsidCache.Reset()
|
s.tsidCache.Reset()
|
||||||
|
@ -904,7 +904,7 @@ func openIndexDBTables(path string, metricIDCache, metricNameCache *fastcache.Ca
|
||||||
}
|
}
|
||||||
|
|
||||||
// Persist changes on the file system.
|
// Persist changes on the file system.
|
||||||
fs.SyncPath(path)
|
fs.MustSyncPath(path)
|
||||||
|
|
||||||
// Open the last two tables.
|
// Open the last two tables.
|
||||||
currPath := path + "/" + tableNames[len(tableNames)-1]
|
currPath := path + "/" + tableNames[len(tableNames)-1]
|
||||||
|
|
|
@ -164,10 +164,10 @@ func (tb *table) CreateSnapshot(snapshotName string) (string, string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.SyncPath(dstSmallDir)
|
fs.MustSyncPath(dstSmallDir)
|
||||||
fs.SyncPath(dstBigDir)
|
fs.MustSyncPath(dstBigDir)
|
||||||
fs.SyncPath(filepath.Dir(dstSmallDir))
|
fs.MustSyncPath(filepath.Dir(dstSmallDir))
|
||||||
fs.SyncPath(filepath.Dir(dstBigDir))
|
fs.MustSyncPath(filepath.Dir(dstBigDir))
|
||||||
|
|
||||||
logger.Infof("created table snapshot for %q at (%q, %q) in %s", tb.path, dstSmallDir, dstBigDir, time.Since(startTime))
|
logger.Infof("created table snapshot for %q at (%q, %q) in %s", tb.path, dstSmallDir, dstBigDir, time.Since(startTime))
|
||||||
return dstSmallDir, dstBigDir, nil
|
return dstSmallDir, dstBigDir, nil
|
||||||
|
|
Loading…
Reference in a new issue