wal: close the directory when Fsync() encounters error
@@ -198,27 +198,33 @@ func Create(lg *zap.Logger, dirpath string, metadata []byte) (*WAL, error) {
)
return nil, perr
}
- start := time.Now()
- if perr = fileutil.Fsync(pdir); perr != nil {
+ dirCloser := func() error {
+ if perr = pdir.Close(); perr != nil {
lg.Warn(
- "failed to fsync the parent data directory file",
+ "failed to close the parent data directory file",
zap.String("parent-dir-path", filepath.Dir(w.dir)),
zap.String("dir-path", w.dir),
zap.Error(perr),
)
- return nil, perr
+ return perr
}
- walFsyncSec.Observe(time.Since(start).Seconds())
-
- if perr = pdir.Close(); perr != nil {
+ return nil
+ }
+ start := time.Now()
+ if perr = fileutil.Fsync(pdir); perr != nil {
+ dirCloser()
lg.Warn(
- "failed to close the parent data directory file",
+ "failed to fsync the parent data directory file",
zap.String("parent-dir-path", filepath.Dir(w.dir)),
zap.String("dir-path", w.dir),
zap.Error(perr),
)
return nil, perr
}
+ walFsyncSec.Observe(time.Since(start).Seconds())
+ if err = dirCloser(); err != nil {
+ return nil, err
+ }
return w, nil
}
