diff --git a/go/storage/needle_byte_cache.go b/go/storage/needle_byte_cache.go index d39ed23c4..5db0f8895 100644 --- a/go/storage/needle_byte_cache.go +++ b/go/storage/needle_byte_cache.go @@ -66,7 +66,9 @@ func getBytesForFileBlock(r *os.File, offset int64, readSize int) (dataSlice []b } func (n *Needle) ReleaseMemory() { - n.rawBlock.decreaseReference() + if n.rawBlock != nil { + n.rawBlock.decreaseReference() + } } func ReleaseBytes(b []byte) { bytesPool.Put(b) diff --git a/go/storage/needle_read_write.go b/go/storage/needle_read_write.go index 49ae4fee4..fcca2469c 100644 --- a/go/storage/needle_read_write.go +++ b/go/storage/needle_read_write.go @@ -144,10 +144,10 @@ func ReadNeedleBlob(r *os.File, offset int64, size uint32) (dataSlice []byte, bl func (n *Needle) ReadData(r *os.File, offset int64, size uint32, version Version) (err error) { bytes, block, err := ReadNeedleBlob(r, offset, size) - n.rawBlock = block if err != nil { return err } + n.rawBlock = block n.ParseNeedleHeader(bytes) if n.Size != size { return fmt.Errorf("File Entry Not Found. Needle %d Memory %d", n.Size, size) diff --git a/go/storage/volume.go b/go/storage/volume.go index af552a10f..7e330a9e4 100644 --- a/go/storage/volume.go +++ b/go/storage/volume.go @@ -159,11 +159,11 @@ func (v *Volume) isFileUnchanged(n *Needle) bool { if ok && nv.Offset > 0 { oldNeedle := new(Needle) err := oldNeedle.ReadData(v.dataFile, int64(nv.Offset)*NeedlePaddingSize, nv.Size, v.Version()) - defer oldNeedle.ReleaseMemory() if err != nil { glog.V(0).Infof("Failed to check updated file %v", err) return false } + defer oldNeedle.ReleaseMemory() if oldNeedle.Checksum == n.Checksum && bytes.Equal(oldNeedle.Data, n.Data) { n.DataSize = oldNeedle.DataSize return true @@ -289,7 +289,6 @@ func (v *Volume) readNeedle(n *Needle) (int, error) { } err := n.ReadData(v.dataFile, int64(nv.Offset)*NeedlePaddingSize, nv.Size, v.Version()) if err != nil { - n.ReleaseMemory() return 0, err } bytesRead := len(n.Data) diff --git a/go/weed/weed_server/volume_server_handlers_read.go b/go/weed/weed_server/volume_server_handlers_read.go index 5f3199738..3eb33a8c9 100644 --- a/go/weed/weed_server/volume_server_handlers_read.go +++ b/go/weed/weed_server/volume_server_handlers_read.go @@ -66,12 +66,12 @@ func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request) cookie := n.Cookie count, e := vs.store.ReadVolumeNeedle(volumeId, n) glog.V(4).Infoln("read bytes", count, "error", e) - defer n.ReleaseMemory() if e != nil || count <= 0 { glog.V(0).Infoln("read error:", e, r.URL.Path) w.WriteHeader(http.StatusNotFound) return } + defer n.ReleaseMemory() if n.Cookie != cookie { glog.V(0).Infoln("request", r.URL.Path, "with unmaching cookie seen:", cookie, "expected:", n.Cookie, "from", r.RemoteAddr, "agent", r.UserAgent()) w.WriteHeader(http.StatusNotFound) diff --git a/go/weed/weed_server/volume_server_handlers_write.go b/go/weed/weed_server/volume_server_handlers_write.go index 421802160..b0a4c7031 100644 --- a/go/weed/weed_server/volume_server_handlers_write.go +++ b/go/weed/weed_server/volume_server_handlers_write.go @@ -56,13 +56,13 @@ func (vs *VolumeServer) DeleteHandler(w http.ResponseWriter, r *http.Request) { cookie := n.Cookie _, ok := vs.store.ReadVolumeNeedle(volumeId, n) - defer n.ReleaseMemory() if ok != nil { m := make(map[string]uint32) m["size"] = 0 writeJsonQuiet(w, r, http.StatusNotFound, m) return } + defer n.ReleaseMemory() if n.Cookie != cookie { glog.V(0).Infoln("delete", r.URL.Path, "with unmaching cookie from ", r.RemoteAddr, "agent", r.UserAgent()) @@ -122,7 +122,6 @@ func (vs *VolumeServer) batchDeleteHandler(w http.ResponseWriter, r *http.Reques Status: http.StatusNotFound, Error: err.Error(), }) - n.ReleaseMemory() continue }