|
@ -54,11 +54,11 @@ func (n *Needle) ReadBytes(bytes []byte, offset int64, size Size, version Versio |
|
|
if n.Size != size { |
|
|
if n.Size != size { |
|
|
// cookie is not always passed in for this API. Use size to do preliminary checking.
|
|
|
// cookie is not always passed in for this API. Use size to do preliminary checking.
|
|
|
if OffsetSize == 4 && offset < int64(MaxPossibleVolumeSize) { |
|
|
if OffsetSize == 4 && offset < int64(MaxPossibleVolumeSize) { |
|
|
stats.VolumeServerRequestCounter.WithLabelValues(stats.ErrorSizeMismatchOffsetSize).Inc() |
|
|
|
|
|
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorSizeMismatchOffsetSize).Inc() |
|
|
glog.Errorf("entry not found1: offset %d found id %x size %d, expected size %d", offset, n.Id, n.Size, size) |
|
|
glog.Errorf("entry not found1: offset %d found id %x size %d, expected size %d", offset, n.Id, n.Size, size) |
|
|
return ErrorSizeMismatch |
|
|
return ErrorSizeMismatch |
|
|
} |
|
|
} |
|
|
stats.VolumeServerRequestCounter.WithLabelValues(stats.ErrorSizeMismatch).Inc() |
|
|
|
|
|
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorSizeMismatch).Inc() |
|
|
return fmt.Errorf("entry not found: offset %d found id %x size %d, expected size %d", offset, n.Id, n.Size, size) |
|
|
return fmt.Errorf("entry not found: offset %d found id %x size %d, expected size %d", offset, n.Id, n.Size, size) |
|
|
} |
|
|
} |
|
|
switch version { |
|
|
switch version { |
|
@ -75,7 +75,7 @@ func (n *Needle) ReadBytes(bytes []byte, offset int64, size Size, version Versio |
|
|
newChecksum := NewCRC(n.Data) |
|
|
newChecksum := NewCRC(n.Data) |
|
|
if checksum != newChecksum.Value() && checksum != uint32(newChecksum) { |
|
|
if checksum != newChecksum.Value() && checksum != uint32(newChecksum) { |
|
|
// the crc.Value() function is to be deprecated. this double checking is for backward compatible.
|
|
|
// the crc.Value() function is to be deprecated. this double checking is for backward compatible.
|
|
|
stats.VolumeServerRequestCounter.WithLabelValues(stats.ErrorCRC).Inc() |
|
|
|
|
|
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorCRC).Inc() |
|
|
return errors.New("CRC error! Data On Disk Corrupted") |
|
|
return errors.New("CRC error! Data On Disk Corrupted") |
|
|
} |
|
|
} |
|
|
n.Checksum = newChecksum |
|
|
n.Checksum = newChecksum |
|
@ -108,7 +108,7 @@ func (n *Needle) readNeedleDataVersion2(bytes []byte) (err error) { |
|
|
n.DataSize = util.BytesToUint32(bytes[index : index+4]) |
|
|
n.DataSize = util.BytesToUint32(bytes[index : index+4]) |
|
|
index = index + 4 |
|
|
index = index + 4 |
|
|
if int(n.DataSize)+index > lenBytes { |
|
|
if int(n.DataSize)+index > lenBytes { |
|
|
stats.VolumeServerRequestCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc() |
|
|
|
|
|
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc() |
|
|
return fmt.Errorf("index out of range %d", 1) |
|
|
return fmt.Errorf("index out of range %d", 1) |
|
|
} |
|
|
} |
|
|
n.Data = bytes[index : index+int(n.DataSize)] |
|
|
n.Data = bytes[index : index+int(n.DataSize)] |
|
@ -127,7 +127,7 @@ func (n *Needle) readNeedleDataVersion2NonData(bytes []byte) (index int, err err |
|
|
n.NameSize = uint8(bytes[index]) |
|
|
n.NameSize = uint8(bytes[index]) |
|
|
index = index + 1 |
|
|
index = index + 1 |
|
|
if int(n.NameSize)+index > lenBytes { |
|
|
if int(n.NameSize)+index > lenBytes { |
|
|
stats.VolumeServerRequestCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc() |
|
|
|
|
|
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc() |
|
|
return index, fmt.Errorf("index out of range %d", 2) |
|
|
return index, fmt.Errorf("index out of range %d", 2) |
|
|
} |
|
|
} |
|
|
n.Name = bytes[index : index+int(n.NameSize)] |
|
|
n.Name = bytes[index : index+int(n.NameSize)] |
|
@ -137,7 +137,7 @@ func (n *Needle) readNeedleDataVersion2NonData(bytes []byte) (index int, err err |
|
|
n.MimeSize = uint8(bytes[index]) |
|
|
n.MimeSize = uint8(bytes[index]) |
|
|
index = index + 1 |
|
|
index = index + 1 |
|
|
if int(n.MimeSize)+index > lenBytes { |
|
|
if int(n.MimeSize)+index > lenBytes { |
|
|
stats.VolumeServerRequestCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc() |
|
|
|
|
|
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc() |
|
|
return index, fmt.Errorf("index out of range %d", 3) |
|
|
return index, fmt.Errorf("index out of range %d", 3) |
|
|
} |
|
|
} |
|
|
n.Mime = bytes[index : index+int(n.MimeSize)] |
|
|
n.Mime = bytes[index : index+int(n.MimeSize)] |
|
@ -145,7 +145,7 @@ func (n *Needle) readNeedleDataVersion2NonData(bytes []byte) (index int, err err |
|
|
} |
|
|
} |
|
|
if index < lenBytes && n.HasLastModifiedDate() { |
|
|
if index < lenBytes && n.HasLastModifiedDate() { |
|
|
if LastModifiedBytesLength+index > lenBytes { |
|
|
if LastModifiedBytesLength+index > lenBytes { |
|
|
stats.VolumeServerRequestCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc() |
|
|
|
|
|
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc() |
|
|
return index, fmt.Errorf("index out of range %d", 4) |
|
|
return index, fmt.Errorf("index out of range %d", 4) |
|
|
} |
|
|
} |
|
|
n.LastModified = util.BytesToUint64(bytes[index : index+LastModifiedBytesLength]) |
|
|
n.LastModified = util.BytesToUint64(bytes[index : index+LastModifiedBytesLength]) |
|
@ -153,7 +153,7 @@ func (n *Needle) readNeedleDataVersion2NonData(bytes []byte) (index int, err err |
|
|
} |
|
|
} |
|
|
if index < lenBytes && n.HasTtl() { |
|
|
if index < lenBytes && n.HasTtl() { |
|
|
if TtlBytesLength+index > lenBytes { |
|
|
if TtlBytesLength+index > lenBytes { |
|
|
stats.VolumeServerRequestCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc() |
|
|
|
|
|
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc() |
|
|
return index, fmt.Errorf("index out of range %d", 5) |
|
|
return index, fmt.Errorf("index out of range %d", 5) |
|
|
} |
|
|
} |
|
|
n.Ttl = LoadTTLFromBytes(bytes[index : index+TtlBytesLength]) |
|
|
n.Ttl = LoadTTLFromBytes(bytes[index : index+TtlBytesLength]) |
|
@ -161,13 +161,13 @@ func (n *Needle) readNeedleDataVersion2NonData(bytes []byte) (index int, err err |
|
|
} |
|
|
} |
|
|
if index < lenBytes && n.HasPairs() { |
|
|
if index < lenBytes && n.HasPairs() { |
|
|
if 2+index > lenBytes { |
|
|
if 2+index > lenBytes { |
|
|
stats.VolumeServerRequestCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc() |
|
|
|
|
|
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc() |
|
|
return index, fmt.Errorf("index out of range %d", 6) |
|
|
return index, fmt.Errorf("index out of range %d", 6) |
|
|
} |
|
|
} |
|
|
n.PairsSize = util.BytesToUint16(bytes[index : index+2]) |
|
|
n.PairsSize = util.BytesToUint16(bytes[index : index+2]) |
|
|
index += 2 |
|
|
index += 2 |
|
|
if int(n.PairsSize)+index > lenBytes { |
|
|
if int(n.PairsSize)+index > lenBytes { |
|
|
stats.VolumeServerRequestCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc() |
|
|
|
|
|
|
|
|
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorIndexOutOfRange).Inc() |
|
|
return index, fmt.Errorf("index out of range %d", 7) |
|
|
return index, fmt.Errorf("index out of range %d", 7) |
|
|
} |
|
|
} |
|
|
end := index + int(n.PairsSize) |
|
|
end := index + int(n.PairsSize) |
|
|