[ARVADOS] updated: 3f556ca1b44b7e01874bd172abbb7cb3df0615db
Git user
git at public.curoverse.com
Fri Dec 30 14:58:20 EST 2016
Summary of changes:
services/keepstore/pipe_adapters.go | 8 ++++----
services/keepstore/volume.go | 12 ++++++++++++
services/keepstore/volume_unix.go | 10 ++++++----
3 files changed, 22 insertions(+), 8 deletions(-)
via 3f556ca1b44b7e01874bd172abbb7cb3df0615db (commit)
from b4d9dfe1e7acb1f45c2cc699020bf9299a0db5c9 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 3f556ca1b44b7e01874bd172abbb7cb3df0615db
Author: Tom Clegg <tom at curoverse.com>
Date: Fri Dec 30 14:58:00 2016 -0500
10467: Use BlockReader and BlockWriter interfaces instead of passing methods to get/putWithPipe.
diff --git a/services/keepstore/pipe_adapters.go b/services/keepstore/pipe_adapters.go
index 0b3999c..3cb01f1 100644
--- a/services/keepstore/pipe_adapters.go
+++ b/services/keepstore/pipe_adapters.go
@@ -10,10 +10,10 @@ import (
// getWithPipe invokes getter and copies the resulting data into
// buf. If ctx is done before all data is copied, getWithPipe closes
// the pipe with an error, and returns early with an error.
-func getWithPipe(ctx context.Context, loc string, buf []byte, getter func(context.Context, string, io.Writer) error) (int, error) {
+func getWithPipe(ctx context.Context, loc string, buf []byte, br BlockReader) (int, error) {
piper, pipew := io.Pipe()
go func() {
- pipew.CloseWithError(getter(ctx, loc, pipew))
+ pipew.CloseWithError(br.ReadBlock(ctx, loc, pipew))
}()
done := make(chan struct{})
var size int
@@ -39,7 +39,7 @@ func getWithPipe(ctx context.Context, loc string, buf []byte, getter func(contex
// from buf into the pipe. If ctx is done before all data is copied,
// putWithPipe closes the pipe with an error, and returns early with
// an error.
-func putWithPipe(ctx context.Context, loc string, buf []byte, putter func(context.Context, string, io.Reader) error) error {
+func putWithPipe(ctx context.Context, loc string, buf []byte, bw BlockWriter) error {
piper, pipew := io.Pipe()
copyErr := make(chan error)
go func() {
@@ -50,7 +50,7 @@ func putWithPipe(ctx context.Context, loc string, buf []byte, putter func(contex
putErr := make(chan error, 1)
go func() {
- putErr <- putter(ctx, loc, piper)
+ putErr <- bw.WriteBlock(ctx, loc, piper)
close(putErr)
}()
diff --git a/services/keepstore/volume.go b/services/keepstore/volume.go
index b72258d..778f27f 100644
--- a/services/keepstore/volume.go
+++ b/services/keepstore/volume.go
@@ -7,6 +7,18 @@ import (
"time"
)
+type BlockWriter interface {
+ // WriteBlock reads all data from r, writes it to a backing
+ // store as "loc", and returns the number of bytes written.
+ WriteBlock(ctx context.Context, loc string, r io.Reader) error
+}
+
+type BlockReader interface {
+ // ReadBlock retrieves data previously stored as "loc" and
+ // writes it to w.
+ ReadBlock(ctx context.Context, loc string, w io.Writer) error
+}
+
// A Volume is an interface representing a Keep back-end storage unit:
// for example, a single mounted disk, a RAID array, an Amazon S3 volume,
// etc.
diff --git a/services/keepstore/volume_unix.go b/services/keepstore/volume_unix.go
index 52fdad3..234eec1 100644
--- a/services/keepstore/volume_unix.go
+++ b/services/keepstore/volume_unix.go
@@ -213,10 +213,11 @@ func (v *UnixVolume) stat(path string) (os.FileInfo, error) {
// Get retrieves a block, copies it to the given slice, and returns
// the number of bytes copied.
func (v *UnixVolume) Get(ctx context.Context, loc string, buf []byte) (int, error) {
- return getWithPipe(ctx, loc, buf, v.get)
+ return getWithPipe(ctx, loc, buf, v)
}
-func (v *UnixVolume) get(ctx context.Context, loc string, w io.Writer) error {
+// ReadBlock implements BlockReader.
+func (v *UnixVolume) ReadBlock(ctx context.Context, loc string, w io.Writer) error {
path := v.blockPath(loc)
stat, err := v.stat(path)
if err != nil {
@@ -249,10 +250,11 @@ func (v *UnixVolume) Compare(ctx context.Context, loc string, expect []byte) err
// returns a FullError. If the write fails due to some other error,
// that error is returned.
func (v *UnixVolume) Put(ctx context.Context, loc string, block []byte) error {
- return putWithPipe(ctx, loc, block, v.put)
+ return putWithPipe(ctx, loc, block, v)
}
-func (v *UnixVolume) put(ctx context.Context, loc string, rdr io.Reader) error {
+// ReadBlock implements BlockWriter.
+func (v *UnixVolume) WriteBlock(ctx context.Context, loc string, rdr io.Reader) error {
if v.ReadOnly {
return MethodDisabledError
}
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list