X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/8cefa5450eb57cfa06f13721228ba1913e7f8c3a..04a40b8028387c4b8899d6b5b0a55d349ddab04b:/services/keepstore/volume_unix.go diff --git a/services/keepstore/volume_unix.go b/services/keepstore/volume_unix.go index 68ab06b5af..f4b49710e9 100644 --- a/services/keepstore/volume_unix.go +++ b/services/keepstore/volume_unix.go @@ -26,6 +26,7 @@ type UnixVolume struct { readonly bool } +// Touch sets the timestamp for the given locator to the current time func (v *UnixVolume) Touch(loc string) error { if v.readonly { return MethodDisabledError @@ -49,13 +50,14 @@ func (v *UnixVolume) Touch(loc string) error { return syscall.Utime(p, &utime) } +// Mtime returns the stored timestamp for the given locator. func (v *UnixVolume) Mtime(loc string) (time.Time, error) { p := v.blockPath(loc) - if fi, err := os.Stat(p); err != nil { + fi, err := os.Stat(p) + if err != nil { return time.Time{}, err - } else { - return fi.ModTime(), nil } + return fi.ModTime(), nil } // Lock the locker (if one is in use), open the file for reading, and @@ -79,7 +81,7 @@ func (v *UnixVolume) stat(path string) (os.FileInfo, error) { if err == nil { if stat.Size() < 0 { err = os.ErrInvalid - } else if stat.Size() > BLOCKSIZE { + } else if stat.Size() > BlockSize { err = TooLongError } } @@ -109,7 +111,7 @@ func (v *UnixVolume) Get(loc string) ([]byte, error) { } // Compare returns nil if Get(loc) would return the same content as -// cmp. It is functionally equivalent to Get() followed by +// expect. It is functionally equivalent to Get() followed by // bytes.Compare(), but uses less memory. func (v *UnixVolume) Compare(loc string, expect []byte) error { path := v.blockPath(loc) @@ -288,6 +290,7 @@ func (v *UnixVolume) IndexTo(prefix string, w io.Writer) error { } } +// Delete deletes the block data from the unix storage func (v *UnixVolume) Delete(loc string) error { // Touch() must be called before calling Write() on a block. Touch() // also uses lockfile(). This avoids a race condition between Write() @@ -343,7 +346,7 @@ func (v *UnixVolume) blockPath(loc string) string { } // IsFull returns true if the free space on the volume is less than -// MIN_FREE_KILOBYTES. +// MinFreeKilobytes. // func (v *UnixVolume) IsFull() (isFull bool) { fullSymlink := v.root + "/full" @@ -359,7 +362,7 @@ func (v *UnixVolume) IsFull() (isFull bool) { } if avail, err := v.FreeDiskSpace(); err == nil { - isFull = avail < MIN_FREE_KILOBYTES + isFull = avail < MinFreeKilobytes } else { log.Printf("%s: FreeDiskSpace: %s\n", v, err) isFull = false @@ -391,6 +394,7 @@ func (v *UnixVolume) String() string { return fmt.Sprintf("[UnixVolume %s]", v.root) } +// Writable returns false if all future Put, Mtime, and Delete calls are expected to fail. func (v *UnixVolume) Writable() bool { return !v.readonly }