Browse Source

parallel logic for read and write

pull/2/head
Chris Lu 12 years ago
parent
commit
37afb31d05
  1. 24
      weed-fs/src/pkg/storage/needle_read_write.go

24
weed-fs/src/pkg/storage/needle_read_write.go

@ -19,7 +19,7 @@ func (n *Needle) Append(w io.Writer, version Version) uint32 {
rest := NeedlePaddingSize - ((NeedleHeaderSize + n.Size + 4) % NeedlePaddingSize) rest := NeedlePaddingSize - ((NeedleHeaderSize + n.Size + 4) % NeedlePaddingSize)
util.Uint32toBytes(header[0:4], n.Checksum.Value()) util.Uint32toBytes(header[0:4], n.Checksum.Value())
w.Write(header[0 : 4+rest]) w.Write(header[0 : 4+rest])
return n.Size
return n.Size
} else if version == Version2 { } else if version == Version2 {
header := make([]byte, NeedleHeaderSize) header := make([]byte, NeedleHeaderSize)
util.Uint32toBytes(header[0:4], n.Cookie) util.Uint32toBytes(header[0:4], n.Cookie)
@ -56,7 +56,7 @@ func (n *Needle) Append(w io.Writer, version Version) uint32 {
rest := NeedlePaddingSize - ((NeedleHeaderSize + n.Size + 4) % NeedlePaddingSize) rest := NeedlePaddingSize - ((NeedleHeaderSize + n.Size + 4) % NeedlePaddingSize)
util.Uint32toBytes(header[0:4], n.Checksum.Value()) util.Uint32toBytes(header[0:4], n.Checksum.Value())
w.Write(header[0 : 4+rest]) w.Write(header[0 : 4+rest])
return n.DataSize
return n.DataSize
} }
return n.Size return n.Size
} }
@ -90,20 +90,22 @@ func (n *Needle) readNeedleHeader(bytes []byte) {
n.Size = util.BytesToUint32(bytes[12:NeedleHeaderSize]) n.Size = util.BytesToUint32(bytes[12:NeedleHeaderSize])
} }
func (n *Needle) readNeedleDataVersion2(bytes []byte) { func (n *Needle) readNeedleDataVersion2(bytes []byte) {
index := 0
n.DataSize = util.BytesToUint32(bytes[index : index+4])
index = index + 4
n.Data = bytes[index : index+int(n.DataSize)]
index = index + int(n.DataSize)
n.Flags = bytes[index]
index = index + 1
if index < len(bytes) {
index, lenBytes := 0, len(bytes)
if index < lenBytes {
n.DataSize = util.BytesToUint32(bytes[index : index+4])
index = index + 4
n.Data = bytes[index : index+int(n.DataSize)]
index = index + int(n.DataSize)
n.Flags = bytes[index]
index = index + 1
}
if index < lenBytes {
n.NameSize = uint8(bytes[index]) n.NameSize = uint8(bytes[index])
index = index + 1 index = index + 1
n.Name = bytes[index : index+int(n.NameSize)] n.Name = bytes[index : index+int(n.NameSize)]
index = index + int(n.NameSize) index = index + int(n.NameSize)
} }
if index < len(bytes) {
if index < lenBytes {
n.MimeSize = uint8(bytes[index]) n.MimeSize = uint8(bytes[index])
index = index + 1 index = index + 1
n.Mime = bytes[index : index+int(n.MimeSize)] n.Mime = bytes[index : index+int(n.MimeSize)]

Loading…
Cancel
Save