Bug fix: GetBlock must report a CorruptError immediately.
authorTim Pierce <twp@curoverse.com>
Tue, 22 Apr 2014 15:20:02 +0000 (11:20 -0400)
committerTim Pierce <twp@curoverse.com>
Tue, 22 Apr 2014 15:20:02 +0000 (11:20 -0400)
Refs #2620.

services/keep/src/keep/keep.go

index f13de44b79c9f0799b98295af65532c8fb66bd0f..e4a26757208eee527a723215321b7c28d8970d08 100644 (file)
@@ -365,12 +365,18 @@ func GetBlock(hash string) ([]byte, error) {
        for _, vol := range KeepVolumes {
                uv := UnixVolume{vol}
                if buf, err := uv.Read(hash); err != nil {
-                       if os.IsNotExist(err) {
-                               // IsNotExist is an expected error.
+                       // IsNotExist is an expected error and may be ignored.
+                       // (If all volumes report IsNotExist, we return a NotFoundError)
+                       // A CorruptError should be returned immediately.
+                       // Any other errors should be logged but we continue trying to
+                       // read.
+                       switch {
+                       case os.IsNotExist(err):
                                continue
-                       } else {
+                       case err == CorruptError:
+                               return nil, err
+                       default:
                                log.Printf("GetBlock: reading %s: %s\n", hash, err)
-                               return buf, err
                        }
                } else {
                        // Success!