Skip to content

Fix chunk reading from ancient v3 schema #1779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/chunk/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ func (c *Chunk) Decode(decodeContext *DecodeContext, input []byte) error {
if err != nil {
return errors.Wrap(err, "when decoding chunk metadata")
}
if len(input)-r.Len() != int(metadataLen) {
metadataRead := len(input) - r.Len()
// Older versions of Cortex included the initial length word; newer versions do not.
if !(metadataRead == int(metadataLen) || metadataRead == int(metadataLen)+4) {
return ErrMetadataLength
}

Expand Down
1 change: 1 addition & 0 deletions pkg/chunk/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
)

var (
chunkTimeRangeKeyV1a = []byte{1}
chunkTimeRangeKeyV1 = []byte{'1'}
chunkTimeRangeKeyV2 = []byte{'2'}
chunkTimeRangeKeyV3 = []byte{'3'}
Expand Down
3 changes: 3 additions & 0 deletions pkg/chunk/schema_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ func parseChunkTimeRangeValue(rangeValue []byte, value []byte) (

// v3 schema had four components - label name, label value, chunk ID and version.
// "version" is 1 and label value is base64 encoded.
// (older code wrote "version" as 1, not '1')
case bytes.Equal(components[3], chunkTimeRangeKeyV1a):
fallthrough
case bytes.Equal(components[3], chunkTimeRangeKeyV1):
chunkID = string(components[2])
labelValue, err = decodeBase64Value(components[1])
Expand Down