mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
compare read file size with in-memory file size
This commit is contained in:
parent
c35fe9d631
commit
3c8dd8592a
|
@ -5,6 +5,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"pkg/util"
|
"pkg/util"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (n *Needle) Append(w io.Writer, version Version) uint32 {
|
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
|
return ret, e
|
||||||
} else if version == Version2 {
|
} else if version == Version2 {
|
||||||
|
if size == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
bytes := make([]byte, NeedleHeaderSize+size+NeedleChecksumSize)
|
bytes := make([]byte, NeedleHeaderSize+size+NeedleChecksumSize)
|
||||||
ret, e := r.Read(bytes)
|
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)
|
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)])
|
n.readNeedleDataVersion2(bytes[NeedleHeaderSize : NeedleHeaderSize+int(n.Size)])
|
||||||
checksum := util.BytesToUint32(bytes[NeedleHeaderSize+n.Size : NeedleHeaderSize+n.Size+NeedleChecksumSize])
|
checksum := util.BytesToUint32(bytes[NeedleHeaderSize+n.Size : NeedleHeaderSize+n.Size+NeedleChecksumSize])
|
||||||
if checksum != NewCRC(n.Data).Value() {
|
if checksum != NewCRC(n.Data).Value() {
|
||||||
|
|
|
@ -116,7 +116,7 @@ func (v *Volume) delete(n *Needle) uint32 {
|
||||||
v.accessLock.Lock()
|
v.accessLock.Lock()
|
||||||
defer v.accessLock.Unlock()
|
defer v.accessLock.Unlock()
|
||||||
nv, ok := v.nm.Get(n.Id)
|
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 {
|
if ok {
|
||||||
v.nm.Delete(n.Id)
|
v.nm.Delete(n.Id)
|
||||||
v.dataFile.Seek(int64(nv.Offset*NeedlePaddingSize), 0)
|
v.dataFile.Seek(int64(nv.Offset*NeedlePaddingSize), 0)
|
||||||
|
|
Loading…
Reference in a new issue