mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
properly release memory
fix https://github.com/chrislusf/seaweedfs/issues/301
This commit is contained in:
parent
e639f1f889
commit
f8b03c45ef
|
@ -66,8 +66,10 @@ func getBytesForFileBlock(r *os.File, offset int64, readSize int) (dataSlice []b
|
|||
}
|
||||
|
||||
func (n *Needle) ReleaseMemory() {
|
||||
if n.rawBlock != nil {
|
||||
n.rawBlock.decreaseReference()
|
||||
}
|
||||
}
|
||||
func ReleaseBytes(b []byte) {
|
||||
bytesPool.Put(b)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue