2019-04-19 12:43:36 +08:00
|
|
|
package needle
|
2012-12-21 13:57:03 +08:00
|
|
|
|
|
|
|
import (
|
2012-12-21 14:32:21 +08:00
|
|
|
"errors"
|
2013-01-17 16:22:18 +08:00
|
|
|
"fmt"
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/stats"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/backend"
|
|
|
|
. "github.com/seaweedfs/seaweedfs/weed/storage/types"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
2021-03-22 15:03:16 +08:00
|
|
|
"io"
|
2012-12-21 13:57:03 +08:00
|
|
|
)
|
|
|
|
|
2013-01-20 19:40:04 +08:00
|
|
|
const (
|
2020-06-20 13:45:27 +08:00
|
|
|
FlagIsCompressed = 0x01
|
2013-07-09 14:38:38 +08:00
|
|
|
FlagHasName = 0x02
|
|
|
|
FlagHasMime = 0x04
|
|
|
|
FlagHasLastModifiedDate = 0x08
|
2014-09-21 03:38:59 +08:00
|
|
|
FlagHasTtl = 0x10
|
2017-01-08 09:16:29 +08:00
|
|
|
FlagHasPairs = 0x20
|
2015-12-15 14:38:58 +08:00
|
|
|
FlagIsChunkManifest = 0x80
|
2013-07-09 14:38:38 +08:00
|
|
|
LastModifiedBytesLength = 5
|
2014-09-21 03:38:59 +08:00
|
|
|
TtlBytesLength = 2
|
2013-01-20 19:40:04 +08:00
|
|
|
)
|
|
|
|
|
2020-10-28 04:11:56 +08:00
|
|
|
var ErrorSizeMismatch = errors.New("size mismatch")
|
2022-10-24 05:00:15 +08:00
|
|
|
var ErrorSizeInvalid = errors.New("size invalid")
|
2020-10-28 04:11:56 +08:00
|
|
|
|
2018-07-24 16:36:04 +08:00
|
|
|
func (n *Needle) DiskSize(version Version) int64 {
|
2019-05-28 15:51:01 +08:00
|
|
|
return GetActualSize(n.Size, version)
|
2013-01-21 11:44:23 +08:00
|
|
|
}
|
2017-01-07 02:22:20 +08:00
|
|
|
|
2020-08-19 08:04:28 +08:00
|
|
|
func ReadNeedleBlob(r backend.BackendStorageFile, offset int64, size Size, version Version) (dataSlice []byte, err error) {
|
2019-08-28 21:48:06 +08:00
|
|
|
|
|
|
|
dataSize := GetActualSize(size, version)
|
2019-10-01 19:21:44 +08:00
|
|
|
dataSlice = make([]byte, int(dataSize))
|
2019-08-28 21:48:06 +08:00
|
|
|
|
2021-02-21 04:39:25 +08:00
|
|
|
var n int
|
|
|
|
n, err = r.ReadAt(dataSlice, offset)
|
|
|
|
if err != nil && int64(n) == dataSize {
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
fileSize, _, _ := r.GetStat()
|
2021-09-03 03:32:46 +08:00
|
|
|
glog.Errorf("%s read %d dataSize %d offset %d fileSize %d: %v", r.Name(), n, dataSize, offset, fileSize, err)
|
2021-02-21 04:39:25 +08:00
|
|
|
}
|
2019-11-09 16:10:59 +08:00
|
|
|
return dataSlice, err
|
|
|
|
|
2016-04-14 16:30:26 +08:00
|
|
|
}
|
|
|
|
|
2019-05-28 02:59:03 +08:00
|
|
|
// ReadBytes hydrates the needle from the bytes buffer, with only n.Id is set.
|
2020-08-19 08:04:28 +08:00
|
|
|
func (n *Needle) ReadBytes(bytes []byte, offset int64, size Size, version Version) (err error) {
|
2015-05-26 15:58:41 +08:00
|
|
|
n.ParseNeedleHeader(bytes)
|
|
|
|
if n.Size != size {
|
2020-10-28 04:11:56 +08:00
|
|
|
// cookie is not always passed in for this API. Use size to do preliminary checking.
|
|
|
|
if OffsetSize == 4 && offset < int64(MaxPossibleVolumeSize) {
|
2024-01-11 02:05:27 +08:00
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorSizeMismatchOffsetSize).Inc()
|
2020-10-28 04:11:56 +08:00
|
|
|
glog.Errorf("entry not found1: offset %d found id %x size %d, expected size %d", offset, n.Id, n.Size, size)
|
|
|
|
return ErrorSizeMismatch
|
|
|
|
}
|
2024-01-11 02:05:27 +08:00
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorSizeMismatch).Inc()
|
2020-08-05 13:09:07 +08:00
|
|
|
return fmt.Errorf("entry not found: offset %d found id %x size %d, expected size %d", offset, n.Id, n.Size, size)
|
2015-05-26 15:58:41 +08:00
|
|
|
}
|
2013-01-17 16:22:18 +08:00
|
|
|
switch version {
|
|
|
|
case Version1:
|
2019-04-19 15:39:34 +08:00
|
|
|
n.Data = bytes[NeedleHeaderSize : NeedleHeaderSize+size]
|
2018-07-24 16:36:04 +08:00
|
|
|
case Version2, Version3:
|
2019-04-19 15:39:34 +08:00
|
|
|
err = n.readNeedleDataVersion2(bytes[NeedleHeaderSize : NeedleHeaderSize+int(n.Size)])
|
2012-12-21 13:57:03 +08:00
|
|
|
}
|
2019-04-30 11:22:19 +08:00
|
|
|
if err != nil && err != io.EOF {
|
2019-03-19 20:34:43 +08:00
|
|
|
return err
|
2016-07-25 11:40:35 +08:00
|
|
|
}
|
2019-04-19 16:56:38 +08:00
|
|
|
if size > 0 {
|
|
|
|
checksum := util.BytesToUint32(bytes[NeedleHeaderSize+size : NeedleHeaderSize+size+NeedleChecksumSize])
|
|
|
|
newChecksum := NewCRC(n.Data)
|
2022-06-06 06:24:02 +08:00
|
|
|
if checksum != newChecksum.Value() && checksum != uint32(newChecksum) {
|
|
|
|
// the crc.Value() function is to be deprecated. this double checking is for backward compatible.
|
2024-01-11 02:05:27 +08:00
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorCRC).Inc()
|
2019-04-19 16:56:38 +08:00
|
|
|
return errors.New("CRC error! Data On Disk Corrupted")
|
|
|
|
}
|
|
|
|
n.Checksum = newChecksum
|
2015-05-26 15:58:41 +08:00
|
|
|
}
|
2018-07-24 16:36:04 +08:00
|
|
|
if version == Version3 {
|
2019-04-19 15:39:34 +08:00
|
|
|
tsOffset := NeedleHeaderSize + size + NeedleChecksumSize
|
2018-07-24 16:38:08 +08:00
|
|
|
n.AppendAtNs = util.BytesToUint64(bytes[tsOffset : tsOffset+TimestampSize])
|
2018-07-24 16:36:04 +08:00
|
|
|
}
|
2015-05-26 15:58:41 +08:00
|
|
|
return nil
|
2012-12-21 13:57:03 +08:00
|
|
|
}
|
2018-07-08 17:28:04 +08:00
|
|
|
|
2019-05-28 02:59:03 +08:00
|
|
|
// ReadData hydrates the needle from the file, with only n.Id is set.
|
2020-08-19 08:04:28 +08:00
|
|
|
func (n *Needle) ReadData(r backend.BackendStorageFile, offset int64, size Size, version Version) (err error) {
|
2019-05-28 02:59:03 +08:00
|
|
|
bytes, err := ReadNeedleBlob(r, offset, size, version)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-01-16 08:16:46 +08:00
|
|
|
|
|
|
|
err = n.ReadBytes(bytes, offset, size, version)
|
|
|
|
if err == ErrorSizeMismatch && OffsetSize == 4 {
|
|
|
|
offset = offset + int64(MaxPossibleVolumeSize)
|
|
|
|
bytes, err = ReadNeedleBlob(r, offset, size, version)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = n.ReadBytes(bytes, offset, size, version)
|
|
|
|
}
|
|
|
|
return err
|
2019-05-28 02:59:03 +08:00
|
|
|
}
|
|
|
|
|
2015-05-26 15:58:41 +08:00
|
|
|
func (n *Needle) ParseNeedleHeader(bytes []byte) {
|
2018-07-08 17:28:04 +08:00
|
|
|
n.Cookie = BytesToCookie(bytes[0:CookieSize])
|
2018-07-24 16:38:08 +08:00
|
|
|
n.Id = BytesToNeedleId(bytes[CookieSize : CookieSize+NeedleIdSize])
|
2020-08-19 08:04:28 +08:00
|
|
|
n.Size = BytesToSize(bytes[CookieSize+NeedleIdSize : NeedleHeaderSize])
|
2012-12-21 18:13:02 +08:00
|
|
|
}
|
2018-07-08 17:28:04 +08:00
|
|
|
|
2019-03-19 20:34:43 +08:00
|
|
|
func (n *Needle) readNeedleDataVersion2(bytes []byte) (err error) {
|
2012-12-21 18:20:38 +08:00
|
|
|
index, lenBytes := 0, len(bytes)
|
|
|
|
if index < lenBytes {
|
2018-07-24 16:38:08 +08:00
|
|
|
n.DataSize = util.BytesToUint32(bytes[index : index+4])
|
2012-12-21 18:20:38 +08:00
|
|
|
index = index + 4
|
2019-03-20 11:56:27 +08:00
|
|
|
if int(n.DataSize)+index > lenBytes {
|
2024-01-11 02:05:27 +08:00
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc()
|
2019-03-20 11:56:27 +08:00
|
|
|
return fmt.Errorf("index out of range %d", 1)
|
2015-03-09 15:34:26 +08:00
|
|
|
}
|
2018-07-24 16:38:08 +08:00
|
|
|
n.Data = bytes[index : index+int(n.DataSize)]
|
2012-12-21 18:20:38 +08:00
|
|
|
index = index + int(n.DataSize)
|
2022-06-05 09:15:39 +08:00
|
|
|
}
|
|
|
|
_, err = n.readNeedleDataVersion2NonData(bytes[index:])
|
|
|
|
return
|
|
|
|
}
|
|
|
|
func (n *Needle) readNeedleDataVersion2NonData(bytes []byte) (index int, err error) {
|
|
|
|
lenBytes := len(bytes)
|
|
|
|
if index < lenBytes {
|
2012-12-21 18:20:38 +08:00
|
|
|
n.Flags = bytes[index]
|
|
|
|
index = index + 1
|
|
|
|
}
|
2012-12-23 04:38:09 +08:00
|
|
|
if index < lenBytes && n.HasName() {
|
2012-12-21 18:13:02 +08:00
|
|
|
n.NameSize = uint8(bytes[index])
|
|
|
|
index = index + 1
|
2019-03-20 11:56:27 +08:00
|
|
|
if int(n.NameSize)+index > lenBytes {
|
2024-01-11 02:05:27 +08:00
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc()
|
2022-06-05 09:15:39 +08:00
|
|
|
return index, fmt.Errorf("index out of range %d", 2)
|
2019-03-19 20:34:43 +08:00
|
|
|
}
|
2018-07-24 16:38:08 +08:00
|
|
|
n.Name = bytes[index : index+int(n.NameSize)]
|
2012-12-21 18:13:02 +08:00
|
|
|
index = index + int(n.NameSize)
|
|
|
|
}
|
2012-12-23 04:38:09 +08:00
|
|
|
if index < lenBytes && n.HasMime() {
|
2012-12-21 18:13:02 +08:00
|
|
|
n.MimeSize = uint8(bytes[index])
|
|
|
|
index = index + 1
|
2019-03-20 11:56:27 +08:00
|
|
|
if int(n.MimeSize)+index > lenBytes {
|
2024-01-11 02:05:27 +08:00
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc()
|
2022-06-05 09:15:39 +08:00
|
|
|
return index, fmt.Errorf("index out of range %d", 3)
|
2019-03-19 20:34:43 +08:00
|
|
|
}
|
2018-07-24 16:38:08 +08:00
|
|
|
n.Mime = bytes[index : index+int(n.MimeSize)]
|
2013-07-09 14:38:38 +08:00
|
|
|
index = index + int(n.MimeSize)
|
|
|
|
}
|
|
|
|
if index < lenBytes && n.HasLastModifiedDate() {
|
2019-03-20 11:56:27 +08:00
|
|
|
if LastModifiedBytesLength+index > lenBytes {
|
2024-01-11 02:05:27 +08:00
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc()
|
2022-06-05 09:15:39 +08:00
|
|
|
return index, fmt.Errorf("index out of range %d", 4)
|
2019-03-19 20:34:43 +08:00
|
|
|
}
|
2018-07-24 16:38:08 +08:00
|
|
|
n.LastModified = util.BytesToUint64(bytes[index : index+LastModifiedBytesLength])
|
2013-07-09 14:38:38 +08:00
|
|
|
index = index + LastModifiedBytesLength
|
2012-12-21 18:13:02 +08:00
|
|
|
}
|
2014-09-21 03:38:59 +08:00
|
|
|
if index < lenBytes && n.HasTtl() {
|
2019-03-20 11:56:27 +08:00
|
|
|
if TtlBytesLength+index > lenBytes {
|
2024-01-11 02:05:27 +08:00
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc()
|
2022-06-05 09:15:39 +08:00
|
|
|
return index, fmt.Errorf("index out of range %d", 5)
|
2019-03-19 20:34:43 +08:00
|
|
|
}
|
2018-07-24 16:38:08 +08:00
|
|
|
n.Ttl = LoadTTLFromBytes(bytes[index : index+TtlBytesLength])
|
2014-09-21 03:38:59 +08:00
|
|
|
index = index + TtlBytesLength
|
|
|
|
}
|
2017-01-08 09:16:29 +08:00
|
|
|
if index < lenBytes && n.HasPairs() {
|
2019-03-20 11:56:27 +08:00
|
|
|
if 2+index > lenBytes {
|
2024-01-11 02:05:27 +08:00
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc()
|
2022-06-05 09:15:39 +08:00
|
|
|
return index, fmt.Errorf("index out of range %d", 6)
|
2019-03-19 20:34:43 +08:00
|
|
|
}
|
2018-07-24 16:38:08 +08:00
|
|
|
n.PairsSize = util.BytesToUint16(bytes[index : index+2])
|
2017-01-08 09:16:29 +08:00
|
|
|
index += 2
|
2019-03-20 11:56:27 +08:00
|
|
|
if int(n.PairsSize)+index > lenBytes {
|
2024-01-11 02:05:27 +08:00
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc()
|
2022-06-05 09:15:39 +08:00
|
|
|
return index, fmt.Errorf("index out of range %d", 7)
|
2019-03-19 20:34:43 +08:00
|
|
|
}
|
2017-01-08 09:16:29 +08:00
|
|
|
end := index + int(n.PairsSize)
|
|
|
|
n.Pairs = bytes[index:end]
|
|
|
|
index = end
|
|
|
|
}
|
2022-06-05 09:15:39 +08:00
|
|
|
return index, nil
|
2012-12-21 18:13:02 +08:00
|
|
|
}
|
2013-01-21 11:44:23 +08:00
|
|
|
|
2019-11-29 10:33:18 +08:00
|
|
|
func ReadNeedleHeader(r backend.BackendStorageFile, version Version, offset int64) (n *Needle, bytes []byte, bodyLength int64, err error) {
|
2012-12-21 14:32:21 +08:00
|
|
|
n = new(Needle)
|
2018-07-24 16:36:04 +08:00
|
|
|
if version == Version1 || version == Version2 || version == Version3 {
|
2019-04-19 15:39:34 +08:00
|
|
|
bytes = make([]byte, NeedleHeaderSize)
|
2019-08-28 21:48:06 +08:00
|
|
|
|
2019-11-09 16:10:59 +08:00
|
|
|
var count int
|
|
|
|
count, err = r.ReadAt(bytes, offset)
|
|
|
|
if count <= 0 || err != nil {
|
|
|
|
return nil, bytes, 0, err
|
2012-12-21 14:32:21 +08:00
|
|
|
}
|
2019-11-09 16:10:59 +08:00
|
|
|
|
2015-05-26 15:58:41 +08:00
|
|
|
n.ParseNeedleHeader(bytes)
|
2018-07-24 16:36:04 +08:00
|
|
|
bodyLength = NeedleBodyLength(n.Size, version)
|
2012-12-21 16:36:55 +08:00
|
|
|
}
|
2019-08-28 21:48:06 +08:00
|
|
|
|
2012-12-21 16:36:55 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-08-19 08:04:28 +08:00
|
|
|
func PaddingLength(needleSize Size, version Version) Size {
|
2018-07-24 16:36:04 +08:00
|
|
|
if version == Version3 {
|
|
|
|
// this is same value as version2, but just listed here for clarity
|
2019-04-19 15:39:34 +08:00
|
|
|
return NeedlePaddingSize - ((NeedleHeaderSize + needleSize + NeedleChecksumSize + TimestampSize) % NeedlePaddingSize)
|
2018-07-24 16:36:04 +08:00
|
|
|
}
|
2019-04-19 15:39:34 +08:00
|
|
|
return NeedlePaddingSize - ((NeedleHeaderSize + needleSize + NeedleChecksumSize) % NeedlePaddingSize)
|
2018-07-24 16:36:04 +08:00
|
|
|
}
|
|
|
|
|
2020-08-19 08:04:28 +08:00
|
|
|
func NeedleBodyLength(needleSize Size, version Version) int64 {
|
2018-07-24 16:36:04 +08:00
|
|
|
if version == Version3 {
|
|
|
|
return int64(needleSize) + NeedleChecksumSize + TimestampSize + int64(PaddingLength(needleSize, version))
|
|
|
|
}
|
|
|
|
return int64(needleSize) + NeedleChecksumSize + int64(PaddingLength(needleSize, version))
|
|
|
|
}
|
|
|
|
|
2022-09-07 14:51:27 +08:00
|
|
|
// n should be a needle already read the header
|
|
|
|
// the input stream will read until next file entry
|
2019-11-29 10:33:18 +08:00
|
|
|
func (n *Needle) ReadNeedleBody(r backend.BackendStorageFile, version Version, offset int64, bodyLength int64) (bytes []byte, err error) {
|
2019-03-18 14:28:43 +08:00
|
|
|
|
2013-02-07 06:30:44 +08:00
|
|
|
if bodyLength <= 0 {
|
2019-04-18 15:18:29 +08:00
|
|
|
return nil, nil
|
2013-02-07 06:30:44 +08:00
|
|
|
}
|
2019-04-19 10:22:13 +08:00
|
|
|
bytes = make([]byte, bodyLength)
|
|
|
|
if _, err = r.ReadAt(bytes, offset); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err = n.ReadNeedleBodyBytes(bytes, version)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Needle) ReadNeedleBodyBytes(needleBody []byte, version Version) (err error) {
|
|
|
|
|
|
|
|
if len(needleBody) <= 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2013-01-17 16:22:18 +08:00
|
|
|
switch version {
|
|
|
|
case Version1:
|
2019-04-19 10:22:13 +08:00
|
|
|
n.Data = needleBody[:n.Size]
|
2012-12-21 16:36:55 +08:00
|
|
|
n.Checksum = NewCRC(n.Data)
|
2018-07-24 16:36:04 +08:00
|
|
|
case Version2, Version3:
|
2019-04-19 10:22:13 +08:00
|
|
|
err = n.readNeedleDataVersion2(needleBody[0:n.Size])
|
2012-12-21 18:13:02 +08:00
|
|
|
n.Checksum = NewCRC(n.Data)
|
2019-03-18 14:28:43 +08:00
|
|
|
|
|
|
|
if version == Version3 {
|
2019-03-19 20:34:43 +08:00
|
|
|
tsOffset := n.Size + NeedleChecksumSize
|
2019-04-19 10:22:13 +08:00
|
|
|
n.AppendAtNs = util.BytesToUint64(needleBody[tsOffset : tsOffset+TimestampSize])
|
2019-03-18 14:28:43 +08:00
|
|
|
}
|
2013-01-20 19:40:04 +08:00
|
|
|
default:
|
2019-04-19 10:22:13 +08:00
|
|
|
err = fmt.Errorf("unsupported version %d!", version)
|
2012-12-21 13:57:03 +08:00
|
|
|
}
|
2012-12-21 14:32:21 +08:00
|
|
|
return
|
2012-12-21 13:57:03 +08:00
|
|
|
}
|
2012-12-22 18:10:45 +08:00
|
|
|
|
2020-06-20 13:45:27 +08:00
|
|
|
func (n *Needle) IsCompressed() bool {
|
|
|
|
return n.Flags&FlagIsCompressed > 0
|
2012-12-23 04:38:09 +08:00
|
|
|
}
|
2020-06-20 13:45:27 +08:00
|
|
|
func (n *Needle) SetIsCompressed() {
|
|
|
|
n.Flags = n.Flags | FlagIsCompressed
|
2012-12-23 04:38:09 +08:00
|
|
|
}
|
|
|
|
func (n *Needle) HasName() bool {
|
2013-01-20 19:40:04 +08:00
|
|
|
return n.Flags&FlagHasName > 0
|
2012-12-23 04:38:09 +08:00
|
|
|
}
|
|
|
|
func (n *Needle) SetHasName() {
|
2013-01-20 19:40:04 +08:00
|
|
|
n.Flags = n.Flags | FlagHasName
|
2012-12-23 04:38:09 +08:00
|
|
|
}
|
|
|
|
func (n *Needle) HasMime() bool {
|
2013-01-20 19:40:04 +08:00
|
|
|
return n.Flags&FlagHasMime > 0
|
2012-12-22 18:10:45 +08:00
|
|
|
}
|
2012-12-23 04:38:09 +08:00
|
|
|
func (n *Needle) SetHasMime() {
|
2013-01-20 19:40:04 +08:00
|
|
|
n.Flags = n.Flags | FlagHasMime
|
2012-12-22 18:10:45 +08:00
|
|
|
}
|
2013-07-09 14:38:38 +08:00
|
|
|
func (n *Needle) HasLastModifiedDate() bool {
|
|
|
|
return n.Flags&FlagHasLastModifiedDate > 0
|
|
|
|
}
|
|
|
|
func (n *Needle) SetHasLastModifiedDate() {
|
|
|
|
n.Flags = n.Flags | FlagHasLastModifiedDate
|
|
|
|
}
|
2014-09-21 03:38:59 +08:00
|
|
|
func (n *Needle) HasTtl() bool {
|
|
|
|
return n.Flags&FlagHasTtl > 0
|
|
|
|
}
|
|
|
|
func (n *Needle) SetHasTtl() {
|
|
|
|
n.Flags = n.Flags | FlagHasTtl
|
|
|
|
}
|
2015-11-29 23:49:41 +08:00
|
|
|
|
2015-12-01 20:53:44 +08:00
|
|
|
func (n *Needle) IsChunkedManifest() bool {
|
2015-12-15 14:38:58 +08:00
|
|
|
return n.Flags&FlagIsChunkManifest > 0
|
2015-11-29 23:49:41 +08:00
|
|
|
}
|
|
|
|
|
2015-12-15 14:38:58 +08:00
|
|
|
func (n *Needle) SetIsChunkManifest() {
|
|
|
|
n.Flags = n.Flags | FlagIsChunkManifest
|
2015-11-29 23:49:41 +08:00
|
|
|
}
|
2017-01-08 09:16:29 +08:00
|
|
|
|
|
|
|
func (n *Needle) HasPairs() bool {
|
|
|
|
return n.Flags&FlagHasPairs != 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Needle) SetHasPairs() {
|
|
|
|
n.Flags = n.Flags | FlagHasPairs
|
|
|
|
}
|
2019-04-19 12:43:36 +08:00
|
|
|
|
2020-08-19 08:04:28 +08:00
|
|
|
func GetActualSize(size Size, version Version) int64 {
|
2019-04-19 15:39:34 +08:00
|
|
|
return NeedleHeaderSize + NeedleBodyLength(size, version)
|
2019-04-19 12:43:36 +08:00
|
|
|
}
|