diff --git a/weed-fs/src/pkg/storage/needle_read_write.go b/weed-fs/src/pkg/storage/needle_read_write.go index e6b9d6601..00844bad3 100644 --- a/weed-fs/src/pkg/storage/needle_read_write.go +++ b/weed-fs/src/pkg/storage/needle_read_write.go @@ -5,6 +5,7 @@ import ( "io" "os" "pkg/util" + "fmt" ) func (n *Needle) Append(w io.Writer, version Version) uint32 { @@ -72,9 +73,21 @@ func (n *Needle) Read(r io.Reader, size uint32, version Version) (int, error) { } return ret, e } else if version == Version2 { + if size == 0 { + return 0, nil + } bytes := make([]byte, NeedleHeaderSize+size+NeedleChecksumSize) ret, e := r.Read(bytes) + if e != nil { + return 0, e + } + if ret != int(NeedleHeaderSize+size+NeedleChecksumSize) { + return 0, errors.New("File Entry Not Found!") + } n.readNeedleHeader(bytes) + if n.Size != size { + return 0, fmt.Errorf("File Entry Not Found! Needle %d Memory %d", n.Size, size) + } n.readNeedleDataVersion2(bytes[NeedleHeaderSize : NeedleHeaderSize+int(n.Size)]) checksum := util.BytesToUint32(bytes[NeedleHeaderSize+n.Size : NeedleHeaderSize+n.Size+NeedleChecksumSize]) if checksum != NewCRC(n.Data).Value() { diff --git a/weed-fs/src/pkg/storage/volume.go b/weed-fs/src/pkg/storage/volume.go index d983e1213..0220bf895 100644 --- a/weed-fs/src/pkg/storage/volume.go +++ b/weed-fs/src/pkg/storage/volume.go @@ -116,7 +116,7 @@ func (v *Volume) delete(n *Needle) uint32 { v.accessLock.Lock() defer v.accessLock.Unlock() nv, ok := v.nm.Get(n.Id) - //log.Println("key", n.Id, "volume offset", nv.Offset, "data_size", n.Size, "cached size", nv.Size) + //fmt.Println("key", n.Id, "volume offset", nv.Offset, "data_size", n.Size, "cached size", nv.Size) if ok { v.nm.Delete(n.Id) v.dataFile.Seek(int64(nv.Offset*NeedlePaddingSize), 0)