mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 08:23:34 +01:00
lib/{storage,mergeset}: return dst on error from unmarshalBlockHeaders, so it could be reused
This commit is contained in:
parent
2f42b85e0e
commit
7e831741f9
@ -148,18 +148,18 @@ func unmarshalBlockHeaders(dst []blockHeader, src []byte, blockHeadersCount int)
|
|||||||
for i := 0; i < blockHeadersCount; i++ {
|
for i := 0; i < blockHeadersCount; i++ {
|
||||||
tail, err := dst[dstLen+i].Unmarshal(src)
|
tail, err := dst[dstLen+i].Unmarshal(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot unmarshal block header: %s", err)
|
return dst, fmt.Errorf("cannot unmarshal block header: %s", err)
|
||||||
}
|
}
|
||||||
src = tail
|
src = tail
|
||||||
}
|
}
|
||||||
if len(src) > 0 {
|
if len(src) > 0 {
|
||||||
return nil, fmt.Errorf("unexpected non-zero tail left after unmarshaling %d block headers; len(tail)=%d", blockHeadersCount, len(src))
|
return dst, fmt.Errorf("unexpected non-zero tail left after unmarshaling %d block headers; len(tail)=%d", blockHeadersCount, len(src))
|
||||||
}
|
}
|
||||||
newBHS := dst[dstLen:]
|
newBHS := dst[dstLen:]
|
||||||
|
|
||||||
// Verify that block headers are sorted by firstItem.
|
// Verify that block headers are sorted by firstItem.
|
||||||
if !sort.SliceIsSorted(newBHS, func(i, j int) bool { return string(newBHS[i].firstItem) < string(newBHS[j].firstItem) }) {
|
if !sort.SliceIsSorted(newBHS, func(i, j int) bool { return string(newBHS[i].firstItem) < string(newBHS[j].firstItem) }) {
|
||||||
return nil, fmt.Errorf("block headers must be sorted by firstItem; unmarshaled unsorted block headers: %#v", newBHS)
|
return dst, fmt.Errorf("block headers must be sorted by firstItem; unmarshaled unsorted block headers: %#v", newBHS)
|
||||||
}
|
}
|
||||||
|
|
||||||
return dst, nil
|
return dst, nil
|
||||||
|
@ -189,7 +189,7 @@ func unmarshalBlockHeaders(dst []blockHeader, src []byte, blockHeadersCount int)
|
|||||||
for len(src) > 0 {
|
for len(src) > 0 {
|
||||||
tmp, err := bh.Unmarshal(src)
|
tmp, err := bh.Unmarshal(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot unmarshal block header: %s", err)
|
return dst, fmt.Errorf("cannot unmarshal block header: %s", err)
|
||||||
}
|
}
|
||||||
src = tmp
|
src = tmp
|
||||||
dst = append(dst, bh)
|
dst = append(dst, bh)
|
||||||
@ -199,12 +199,12 @@ func unmarshalBlockHeaders(dst []blockHeader, src []byte, blockHeadersCount int)
|
|||||||
|
|
||||||
// Verify the number of read block headers.
|
// Verify the number of read block headers.
|
||||||
if len(newBHS) != blockHeadersCount {
|
if len(newBHS) != blockHeadersCount {
|
||||||
return nil, fmt.Errorf("invalid number of block headers found: %d; want %d block headers", len(newBHS), blockHeadersCount)
|
return dst, fmt.Errorf("invalid number of block headers found: %d; want %d block headers", len(newBHS), blockHeadersCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that block headers are sorted by tsid.
|
// Verify that block headers are sorted by tsid.
|
||||||
if !sort.SliceIsSorted(newBHS, func(i, j int) bool { return newBHS[i].TSID.Less(&newBHS[j].TSID) }) {
|
if !sort.SliceIsSorted(newBHS, func(i, j int) bool { return newBHS[i].TSID.Less(&newBHS[j].TSID) }) {
|
||||||
return nil, fmt.Errorf("block headers must be sorted by tsid; unmarshaled unsorted block headers: %+v", newBHS)
|
return dst, fmt.Errorf("block headers must be sorted by tsid; unmarshaled unsorted block headers: %+v", newBHS)
|
||||||
}
|
}
|
||||||
|
|
||||||
return dst, nil
|
return dst, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user