Add paths to various TSI errors on opening and unmarshaling files
to help poinpoint the corrupt files.
Closes https://github.com/influxdata/influxdb/issues/23556
(cherry picked from commit 25cea95beb
)
closes https://github.com/influxdata/influxdb/issues/23559
pull/23577/head
parent
05a0b540dd
commit
4db8ab54f6
|
@ -2,6 +2,7 @@ package models_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
|
@ -2228,7 +2229,7 @@ func TestNewPointsWithBytesWithCorruptData(t *testing.T) {
|
||||||
|
|
||||||
func TestNewPointsWithShortBuffer(t *testing.T) {
|
func TestNewPointsWithShortBuffer(t *testing.T) {
|
||||||
_, err := models.NewPointFromBytes([]byte{0, 0, 0, 3, 4})
|
_, err := models.NewPointFromBytes([]byte{0, 0, 0, 3, 4})
|
||||||
if err != io.ErrShortBuffer {
|
if !errors.Is(err, io.ErrShortBuffer) {
|
||||||
t.Fatalf("NewPointFromBytes: got: (%v, %v), expected: (nil, error)", p, err)
|
t.Fatalf("NewPointFromBytes: got: (%v, %v), expected: (nil, error)", p, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,15 +170,15 @@ func (f *IndexFile) Compacting() bool {
|
||||||
func (f *IndexFile) UnmarshalBinary(data []byte) error {
|
func (f *IndexFile) UnmarshalBinary(data []byte) error {
|
||||||
// Ensure magic number exists at the beginning.
|
// Ensure magic number exists at the beginning.
|
||||||
if len(data) < len(FileSignature) {
|
if len(data) < len(FileSignature) {
|
||||||
return io.ErrShortBuffer
|
return fmt.Errorf("%q: %w", f.path, io.ErrShortBuffer)
|
||||||
} else if !bytes.Equal(data[:len(FileSignature)], []byte(FileSignature)) {
|
} else if !bytes.Equal(data[:len(FileSignature)], []byte(FileSignature)) {
|
||||||
return ErrInvalidIndexFile
|
return fmt.Errorf("%q: %w", f.path, ErrInvalidIndexFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read index file trailer.
|
// Read index file trailer.
|
||||||
t, err := ReadIndexFileTrailer(data)
|
t, err := ReadIndexFileTrailer(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("%q: %w", f.path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slice series sketch data.
|
// Slice series sketch data.
|
||||||
|
@ -191,7 +191,7 @@ func (f *IndexFile) UnmarshalBinary(data []byte) error {
|
||||||
|
|
||||||
// Unmarshal measurement block.
|
// Unmarshal measurement block.
|
||||||
if err := f.mblk.UnmarshalBinary(data[t.MeasurementBlock.Offset:][:t.MeasurementBlock.Size]); err != nil {
|
if err := f.mblk.UnmarshalBinary(data[t.MeasurementBlock.Offset:][:t.MeasurementBlock.Size]); err != nil {
|
||||||
return err
|
return fmt.Errorf("%q: %w", f.path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal each tag block.
|
// Unmarshal each tag block.
|
||||||
|
@ -208,7 +208,7 @@ func (f *IndexFile) UnmarshalBinary(data []byte) error {
|
||||||
// Unmarshal measurement block.
|
// Unmarshal measurement block.
|
||||||
var tblk TagBlock
|
var tblk TagBlock
|
||||||
if err := tblk.UnmarshalBinary(buf); err != nil {
|
if err := tblk.UnmarshalBinary(buf); err != nil {
|
||||||
return err
|
return fmt.Errorf("%q: %w", f.path, err)
|
||||||
}
|
}
|
||||||
f.tblks[string(e.name)] = &tblk
|
f.tblks[string(e.name)] = &tblk
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,7 +226,9 @@ func TestIndex_OpenFail(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, tslFile.Close())
|
require.NoError(t, tslFile.Close())
|
||||||
idx.Index = tsi1.NewIndex(idx.SeriesFile.SeriesFile, "db0", tsi1.WithPath(idx.Index.Path()))
|
idx.Index = tsi1.NewIndex(idx.SeriesFile.SeriesFile, "db0", tsi1.WithPath(idx.Index.Path()))
|
||||||
require.EqualError(t, idx.Index.Open(), "parsing binary-encoded uint64 value failed; binary.Uvarint() returned -11")
|
err = idx.Index.Open()
|
||||||
|
require.Error(t, err, "expected an error on opening the index")
|
||||||
|
require.Contains(t, err.Error(), ".tsl\": parsing binary-encoded uint64 value failed; binary.Uvarint() returned -11")
|
||||||
// ensure each partition is closed:
|
// ensure each partition is closed:
|
||||||
for i := 0; i < int(idx.Index.PartitionN); i++ {
|
for i := 0; i < int(idx.Index.PartitionN); i++ {
|
||||||
assert.Equal(t, idx.Index.PartitionAt(i).FileN(), 0)
|
assert.Equal(t, idx.Index.PartitionAt(i).FileN(), 0)
|
||||||
|
|
|
@ -153,10 +153,10 @@ func (f *LogFile) open() error {
|
||||||
for buf := f.data; len(buf) > 0; {
|
for buf := f.data; len(buf) > 0; {
|
||||||
// Read next entry. Truncate partial writes.
|
// Read next entry. Truncate partial writes.
|
||||||
var e LogEntry
|
var e LogEntry
|
||||||
if err := e.UnmarshalBinary(buf); err == io.ErrShortBuffer || err == ErrLogEntryChecksumMismatch {
|
if err := e.UnmarshalBinary(buf); errors.Is(err, io.ErrShortBuffer) || errors.Is(err, ErrLogEntryChecksumMismatch) {
|
||||||
break
|
break
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return err
|
return fmt.Errorf("%q: %w", f.path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute entry against in-memory index.
|
// Execute entry against in-memory index.
|
||||||
|
|
Loading…
Reference in New Issue