Skip to content

Commit

Permalink
Fixed TestChunkDiskMapper_WriteChunk_Chunk_IterateChunks for go1.16
Browse files Browse the repository at this point in the history
Fixes #8403

Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
  • Loading branch information
bwplotka committed Feb 23, 2021
1 parent 8c8de46 commit 0adfa7c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
4 changes: 3 additions & 1 deletion tsdb/chunks/head_chunks.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,14 @@ func (cdm *ChunkDiskMapper) IterateAllChunks(f func(seriesRef, chunkRef uint64,
}
}
if allZeros {
// End of segment chunk file content.
break
}
return &CorruptionErr{
Dir: cdm.dir.Name(),
FileIndex: segID,
Err: errors.Errorf("head chunk file doesn't include enough bytes to read the chunk header - required:%v, available:%v, file:%d", idx+MaxHeadChunkMetaSize, fileEnd, segID),
Err: errors.Errorf("head chunk file has some unread data, but doesn't include enough bytes to read the chunk header"+
" - required:%v, available:%v, file:%d", idx+MaxHeadChunkMetaSize, fileEnd, segID),
}
}
chkCRC32.Reset()
Expand Down
11 changes: 2 additions & 9 deletions tsdb/chunks/head_chunks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ func TestChunkDiskMapper_WriteChunk_Chunk_IterateChunks(t *testing.T) {
fileEnd := HeadChunkFileHeaderSize + len(expectedBytes)
require.Equal(t, expectedBytes, actualBytes[HeadChunkFileHeaderSize:fileEnd])

// Test for the next chunk header to be all 0s. That marks the end of the file.
for _, b := range actualBytes[fileEnd : fileEnd+MaxHeadChunkMetaSize] {
require.Equal(t, byte(0), b)
}

// Testing reading of chunks.
for _, exp := range expectedData {
actChunk, err := hrw.Chunk(exp.chunkRef)
Expand All @@ -137,7 +132,7 @@ func TestChunkDiskMapper_WriteChunk_Chunk_IterateChunks(t *testing.T) {
require.NoError(t, err)

idx := 0
err = hrw.IterateAllChunks(func(seriesRef, chunkRef uint64, mint, maxt int64, numSamples uint16) error {
require.NoError(t, hrw.IterateAllChunks(func(seriesRef, chunkRef uint64, mint, maxt int64, numSamples uint16) error {
t.Helper()

expData := expectedData[idx]
Expand All @@ -153,10 +148,8 @@ func TestChunkDiskMapper_WriteChunk_Chunk_IterateChunks(t *testing.T) {

idx++
return nil
})
require.NoError(t, err)
}))
require.Equal(t, len(expectedData), idx)

}

// TestChunkDiskMapper_Truncate tests
Expand Down

0 comments on commit 0adfa7c

Please sign in to comment.