From d90d0976b54879e833ec08b8855603e8f4e4b432 Mon Sep 17 00:00:00 2001 From: Antoine Pultier <45740+fungiboletus@users.noreply.github.com> Date: Tue, 17 Sep 2024 16:28:33 +0200 Subject: [PATCH] fix(bstream/writeByte): ensure it appends only one byte (#14854) fix(bstream/writeByte): ensure it appends only one byte Signed-off-by: Antoine Pultier --- storage/remote/read_handler_test.go | 4 ++-- tsdb/block_test.go | 4 ++-- tsdb/chunkenc/bstream.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/storage/remote/read_handler_test.go b/storage/remote/read_handler_test.go index 4cd4647e7..fd7f3ad48 100644 --- a/storage/remote/read_handler_test.go +++ b/storage/remote/read_handler_test.go @@ -334,7 +334,7 @@ func TestStreamReadEndpoint(t *testing.T) { Type: prompb.Chunk_XOR, MinTimeMs: 7200000, MaxTimeMs: 7200000, - Data: []byte("\000\001\200\364\356\006@\307p\000\000\000\000\000\000"), + Data: []byte("\000\001\200\364\356\006@\307p\000\000\000\000\000"), }, }, }, @@ -381,7 +381,7 @@ func TestStreamReadEndpoint(t *testing.T) { Type: prompb.Chunk_XOR, MinTimeMs: 14400000, MaxTimeMs: 14400000, - Data: []byte("\000\001\200\350\335\r@\327p\000\000\000\000\000\000"), + Data: []byte("\000\001\200\350\335\r@\327p\000\000\000\000\000"), }, }, }, diff --git a/tsdb/block_test.go b/tsdb/block_test.go index 2273b812a..b418a1382 100644 --- a/tsdb/block_test.go +++ b/tsdb/block_test.go @@ -152,7 +152,7 @@ func TestCorruptedChunk(t *testing.T) { require.NoError(t, err) require.NoError(t, f.Truncate(fi.Size()-1)) }, - iterErr: errors.New("cannot populate chunk 8 from block 00000000000000000000000000: segment doesn't include enough bytes to read the chunk - required:26, available:25"), + iterErr: errors.New("cannot populate chunk 8 from block 00000000000000000000000000: segment doesn't include enough bytes to read the chunk - required:25, available:24"), }, { name: "checksum mismatch", @@ -170,7 +170,7 @@ func TestCorruptedChunk(t *testing.T) { require.NoError(t, err) require.Equal(t, 1, n) }, - iterErr: errors.New("cannot populate chunk 8 from block 00000000000000000000000000: checksum mismatch expected:cfc0526c, actual:34815eae"), + iterErr: errors.New("cannot populate chunk 8 from block 00000000000000000000000000: checksum mismatch expected:231bddcf, actual:d85ad10d"), }, } { t.Run(tc.name, func(t *testing.T) { diff --git a/tsdb/chunkenc/bstream.go b/tsdb/chunkenc/bstream.go index 8cc59f3ea..f9668c68c 100644 --- a/tsdb/chunkenc/bstream.go +++ b/tsdb/chunkenc/bstream.go @@ -86,8 +86,8 @@ func (b *bstream) writeBit(bit bit) { func (b *bstream) writeByte(byt byte) { if b.count == 0 { - b.stream = append(b.stream, 0) - b.count = 8 + b.stream = append(b.stream, byt) + return } i := len(b.stream) - 1