X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/109cd685ecbfb5b685347731340c6dd69e630617..e55f6e9fcb652a2b1505364b34d9d48e79adaeaf:/services/keepstore/volume_unix.go diff --git a/services/keepstore/volume_unix.go b/services/keepstore/volume_unix.go index 5d09e84f52..98c31d1eab 100644 --- a/services/keepstore/volume_unix.go +++ b/services/keepstore/volume_unix.go @@ -2,7 +2,6 @@ package main import ( "bufio" - "bytes" "errors" "flag" "fmt" @@ -209,43 +208,11 @@ func (v *UnixVolume) Get(loc string) ([]byte, error) { // bytes.Compare(), but uses less memory. func (v *UnixVolume) Compare(loc string, expect []byte) error { path := v.blockPath(loc) - stat, err := v.stat(path) - if err != nil { + if _, err := v.stat(path); err != nil { return err } - bufLen := 1 << 20 - if int64(bufLen) > stat.Size() { - bufLen = int(stat.Size()) - if bufLen < 1 { - // len(buf)==0 would prevent us from handling - // empty files the same way as non-empty - // files, because reading 0 bytes at a time - // never reaches EOF. - bufLen = 1 - } - } - cmp := expect - buf := make([]byte, bufLen) return v.getFunc(path, func(rdr io.Reader) error { - // Loop invariants: all data read so far matched what - // we expected, and the first N bytes of cmp are - // expected to equal the next N bytes read from - // reader. - for { - n, err := rdr.Read(buf) - if n > len(cmp) || bytes.Compare(cmp[:n], buf[:n]) != 0 { - return collisionOrCorrupt(loc[:32], expect[:len(expect)-len(cmp)], buf[:n], rdr) - } - cmp = cmp[n:] - if err == io.EOF { - if len(cmp) != 0 { - return collisionOrCorrupt(loc[:32], expect[:len(expect)-len(cmp)], nil, nil) - } - return nil - } else if err != nil { - return err - } - } + return compareReaderWithBuf(rdr, expect, loc[:32]) }) } @@ -500,6 +467,10 @@ func (v *UnixVolume) Writable() bool { return !v.readonly } +func (v *UnixVolume) Replication() int { + return 1 +} + // lockfile and unlockfile use flock(2) to manage kernel file locks. func lockfile(f *os.File) error { return syscall.Flock(int(f.Fd()), syscall.LOCK_EX)