aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2024-11-12 16:56:14 -0500
committerGitHub <noreply@github.com>2024-11-12 13:56:14 -0800
commit3003c9e17e06db92f5a426c191ebaab15a1764a1 (patch)
tree1ec421bb8a10c08de562561fd3d3ad867d58338c
parent31d8907e7759c27e4ca764cb8680ae79e707b5c2 (diff)
downloadseaweedfs-3003c9e17e06db92f5a426c191ebaab15a1764a1.tar.xz
seaweedfs-3003c9e17e06db92f5a426c191ebaab15a1764a1.zip
added backward compatible CRC check and extra explanatory comments (#6233)
-rw-r--r--weed/storage/needle/needle_read.go4
-rw-r--r--weed/storage/volume_read.go9
2 files changed, 10 insertions, 3 deletions
diff --git a/weed/storage/needle/needle_read.go b/weed/storage/needle/needle_read.go
index 1041e924d..f8468e9e2 100644
--- a/weed/storage/needle/needle_read.go
+++ b/weed/storage/needle/needle_read.go
@@ -74,7 +74,9 @@ func (n *Needle) ReadBytes(bytes []byte, offset int64, size Size, version Versio
checksum := util.BytesToUint32(bytes[NeedleHeaderSize+size : NeedleHeaderSize+size+NeedleChecksumSize])
newChecksum := NewCRC(n.Data)
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 compatibility
+ // with seaweed version using crc.Value() instead of uint32(crc), which appears in commit 056c480eb
+ // and switch appeared in version 3.09.
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorCRC).Inc()
return errors.New("CRC error! Data On Disk Corrupted")
}
diff --git a/weed/storage/volume_read.go b/weed/storage/volume_read.go
index e18ce9016..f82e3e72d 100644
--- a/weed/storage/volume_read.go
+++ b/weed/storage/volume_read.go
@@ -164,7 +164,10 @@ func (v *Volume) readNeedleDataInto(n *needle.Needle, readOption *ReadOption, wr
toWrite := min(count, int(offset+size-x))
if toWrite > 0 {
crc = crc.Update(buf[0:toWrite])
- if offset == 0 && size == int64(n.DataSize) && int64(count) == size && (n.Checksum != crc) {
+ // the crc.Value() function is to be deprecated. this double checking is for backward compatibility
+ // with seaweed version using crc.Value() instead of uint32(crc), which appears in commit 056c480eb
+ // and switch appeared in version 3.09.
+ if offset == 0 && size == int64(n.DataSize) && int64(count) == size && (n.Checksum != crc && uint32(n.Checksum) != crc.Value()) {
// This check works only if the buffer is big enough to hold the whole needle data
// and we ask for all needle data.
// Otherwise we cannot check the validity of partially aquired data.
@@ -187,7 +190,9 @@ func (v *Volume) readNeedleDataInto(n *needle.Needle, readOption *ReadOption, wr
}
}
if offset == 0 && size == int64(n.DataSize) && (n.Checksum != crc && uint32(n.Checksum) != crc.Value()) {
- // 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 compatibility
+ // with seaweed version using crc.Value() instead of uint32(crc), which appears in commit 056c480eb
+ // and switch appeared in version 3.09.
stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorCRC).Inc()
return fmt.Errorf("ReadNeedleData checksum %v expected %v for Needle: %v,%v", crc, n.Checksum, v.Id, n)
}