Skip to content

Commit 057ed8f

Browse files
authored
Merge pull request #1779 from cortexproject/fix-ancient-reads
Fix chunk reading from ancient v3 schema
2 parents 491b9de + b89dd55 commit 057ed8f

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

pkg/chunk/chunk.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ func (c *Chunk) Decode(decodeContext *DecodeContext, input []byte) error {
288288
if err != nil {
289289
return errors.Wrap(err, "when decoding chunk metadata")
290290
}
291-
if len(input)-r.Len() != int(metadataLen) {
291+
metadataRead := len(input) - r.Len()
292+
// Older versions of Cortex included the initial length word; newer versions do not.
293+
if !(metadataRead == int(metadataLen) || metadataRead == int(metadataLen)+4) {
292294
return ErrMetadataLength
293295
}
294296

pkg/chunk/schema.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
var (
16+
chunkTimeRangeKeyV1a = []byte{1}
1617
chunkTimeRangeKeyV1 = []byte{'1'}
1718
chunkTimeRangeKeyV2 = []byte{'2'}
1819
chunkTimeRangeKeyV3 = []byte{'3'}

pkg/chunk/schema_util.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ func parseChunkTimeRangeValue(rangeValue []byte, value []byte) (
187187

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

0 commit comments

Comments
 (0)