[ARVADOS] updated: 8202cb5f1682588e35dcf90519f53d74c06d4aa6

git at public.curoverse.com git at public.curoverse.com
Fri Apr 18 16:53:24 EDT 2014


Summary of changes:
 services/keep/src/keep/keep.go   |   51 ++++++++--------------------------
 services/keep/src/keep/volume.go |   57 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+), 39 deletions(-)
 create mode 100644 services/keep/src/keep/volume.go

       via  8202cb5f1682588e35dcf90519f53d74c06d4aa6 (commit)
      from  afe657cad834e66867b11bef08a5e9a372f525a4 (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 8202cb5f1682588e35dcf90519f53d74c06d4aa6
Author: Tim Pierce <twp at curoverse.com>
Date:   Fri Apr 18 16:54:46 2014 -0400

    Adding a Volume interface and UnixVolume implementation.
    
    refs #2620

diff --git a/services/keep/src/keep/keep.go b/services/keep/src/keep/keep.go
index 74c3b15..f13de44 100644
--- a/services/keep/src/keep/keep.go
+++ b/services/keep/src/keep/keep.go
@@ -361,52 +361,25 @@ func IndexLocators(prefix string) string {
 }
 
 func GetBlock(hash string) ([]byte, error) {
-	var buf = make([]byte, BLOCKSIZE)
-
 	// Attempt to read the requested hash from a keep volume.
 	for _, vol := range KeepVolumes {
-		var f *os.File
-		var err error
-		var nread int
-
-		blockFilename := fmt.Sprintf("%s/%s/%s", vol, hash[0:3], hash)
-
-		f, err = os.Open(blockFilename)
-		if err != nil {
-			if !os.IsNotExist(err) {
-				// A block is stored on only one Keep disk,
-				// so os.IsNotExist is expected.  Report any other errors.
-				log.Printf("%s: opening %s: %s\n", vol, blockFilename, err)
+		uv := UnixVolume{vol}
+		if buf, err := uv.Read(hash); err != nil {
+			if os.IsNotExist(err) {
+				// IsNotExist is an expected error.
+				continue
+			} else {
+				log.Printf("GetBlock: reading %s: %s\n", hash, err)
+				return buf, err
 			}
-			continue
-		}
-
-		nread, err = f.Read(buf)
-		if err != nil {
-			log.Printf("%s: reading %s: %s\n", vol, blockFilename, err)
-			continue
-		}
-
-		// Double check the file checksum.
-		//
-		filehash := fmt.Sprintf("%x", md5.Sum(buf[:nread]))
-		if filehash != hash {
-			// TODO(twp): this condition probably represents a bad disk and
-			// should raise major alarm bells for an administrator: e.g.
-			// they should be sent directly to an event manager at high
-			// priority or logged as urgent problems.
-			//
-			log.Printf("%s: checksum mismatch: %s (actual hash %s)\n",
-				vol, blockFilename, filehash)
-			return buf, CorruptError
+		} else {
+			// Success!
+			return buf, nil
 		}
-
-		// Success!
-		return buf[:nread], nil
 	}
 
 	log.Printf("%s: not found on any volumes, giving up\n", hash)
-	return buf, NotFoundError
+	return nil, NotFoundError
 }
 
 /* PutBlock(block, hash)
diff --git a/services/keep/src/keep/volume.go b/services/keep/src/keep/volume.go
new file mode 100644
index 0000000..20113ff
--- /dev/null
+++ b/services/keep/src/keep/volume.go
@@ -0,0 +1,57 @@
+package main
+
+import (
+	"crypto/md5"
+	"fmt"
+	"log"
+	"os"
+)
+
+// A Volume is an interface that represents a Keep back-end volume.
+
+type Volume interface {
+	Read(locator string) ([]byte, error)
+	Write(locator string, block []byte) error
+}
+
+// A UnixVolume is a Volume that writes to a locally mounted disk.
+type UnixVolume struct {
+	root string // path to this volume
+}
+
+func (v *UnixVolume) Read(locator string) ([]byte, error) {
+	var f *os.File
+	var err error
+	var nread int
+
+	blockFilename := fmt.Sprintf("%s/%s/%s", v.root, locator[0:3], locator)
+
+	f, err = os.Open(blockFilename)
+	if err != nil {
+		return nil, err
+	}
+
+	var buf = make([]byte, BLOCKSIZE)
+	nread, err = f.Read(buf)
+	if err != nil {
+		log.Printf("%s: reading %s: %s\n", v.root, blockFilename, err)
+		return buf, err
+	}
+
+	// Double check the file checksum.
+	//
+	filehash := fmt.Sprintf("%x", md5.Sum(buf[:nread]))
+	if filehash != locator {
+		// TODO(twp): this condition probably represents a bad disk and
+		// should raise major alarm bells for an administrator: e.g.
+		// they should be sent directly to an event manager at high
+		// priority or logged as urgent problems.
+		//
+		log.Printf("%s: checksum mismatch: %s (actual locator %s)\n",
+			v.root, blockFilename, filehash)
+		return buf, CorruptError
+	}
+
+	// Success!
+	return buf[:nread], nil
+}

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list