Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
It is recommend to upgrade the storage components first (Receive, Store, etc.) and then Queriers. This will enable batching support. Otherwise, you risk high memory usage in the Querier component if gRPC compression is enabled.

### Fixed
- [#8684](https://github.com/thanos-io/thanos/pull/8684): Fix: EncodeAggrChunk created corrupt block if the last chunk is empty

### Added

Expand Down
6 changes: 6 additions & 0 deletions pkg/compact/downsample/aggr.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type AggrChunk []byte
func EncodeAggrChunk(chks [5]chunkenc.Chunk) *AggrChunk {
var b []byte
buf := [8]byte{}
lastNil := chks[AggrCounter] == nil

for _, c := range chks {
// Unset aggregates are marked with a zero length entry.
Expand All @@ -37,6 +38,11 @@ func EncodeAggrChunk(chks [5]chunkenc.Chunk) *AggrChunk {
b = append(b, byte(c.Encoding()))
b = append(b, c.Bytes()...)
}
// Keep one trailing byte when the last aggregate is missing so decoders that
// validate size before handling zero-length entries don't fail on the final field.
if lastNil {
b = append(b, 0)
}
chk := AggrChunk(b)
return &chk
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/compact/downsample/aggr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,17 @@ func TestAggrChunk(t *testing.T) {
}
testutil.Equals(t, input, res)
}

func TestAggrChunk_TrailingNilAggregate(t *testing.T) {
var chks [5]chunkenc.Chunk

chks[AggrCount] = chunkenc.NewXORChunk()
a, err := chks[AggrCount].Appender()
testutil.Ok(t, err)
a.Append(100, 1)

// Keep AggrCounter (the last aggregate) nil. It should decode as missing aggregate.
ac := EncodeAggrChunk(chks)
_, err = ac.Get(AggrCounter)
testutil.Equals(t, ErrAggrNotExist, err)
}
Loading