X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/a7a482db3954fa6470be74f0e00f6e1e105e0b6c..178a1c6d587f4e5edf1be08261e00af90169c702:/services/keepstore/unix_volume.go diff --git a/services/keepstore/unix_volume.go b/services/keepstore/unix_volume.go index ceccd11c92..a746166048 100644 --- a/services/keepstore/unix_volume.go +++ b/services/keepstore/unix_volume.go @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: AGPL-3.0 -package main +package keepstore import ( "context" @@ -172,10 +172,10 @@ func (v *UnixVolume) Touch(loc string) error { return e } defer v.unlockfile(f) - ts := syscall.NsecToTimespec(time.Now().UnixNano()) + ts := time.Now() v.os.stats.TickOps("utimes") v.os.stats.Tick(&v.os.stats.UtimesOps) - err = syscall.UtimesNano(p, []syscall.Timespec{ts, ts}) + err = os.Chtimes(p, ts, ts) v.os.stats.TickErr(err) return err } @@ -298,6 +298,19 @@ func (v *UnixVolume) WriteBlock(ctx context.Context, loc string, rdr io.Reader) v.os.Remove(tmpfile.Name()) return err } + // ext4 uses a low-precision clock and effectively backdates + // files by up to 10 ms, sometimes across a 1-second boundary, + // which produces confusing results in logs and tests. We + // avoid this by setting the output file's timestamps + // explicitly, using a higher resolution clock. + ts := time.Now() + v.os.stats.TickOps("utimes") + v.os.stats.Tick(&v.os.stats.UtimesOps) + if err = os.Chtimes(tmpfile.Name(), ts, ts); err != nil { + err = fmt.Errorf("error setting timestamps on %s: %s", tmpfile.Name(), err) + v.os.Remove(tmpfile.Name()) + return err + } if err := v.os.Rename(tmpfile.Name(), bpath); err != nil { err = fmt.Errorf("error renaming %s to %s: %s", tmpfile.Name(), bpath, err) v.os.Remove(tmpfile.Name()) @@ -686,10 +699,20 @@ func (v *UnixVolume) EmptyTrash() { err := filepath.Walk(v.Root, func(path string, info os.FileInfo, err error) error { if err != nil { v.logger.WithError(err).Errorf("EmptyTrash: filepath.Walk(%q) failed", path) + // Don't give up -- keep walking other + // files/dirs + return nil + } else if !info.Mode().IsDir() { + todo <- dirent{path, info} return nil + } else if path == v.Root || blockDirRe.MatchString(info.Name()) { + // Descend into a directory that we might have + // put trash in. + return nil + } else { + // Don't descend into other dirs. + return filepath.SkipDir } - todo <- dirent{path, info} - return nil }) close(todo) wg.Wait()