diff --git a/tsdb/index/tsi1/index_test.go b/tsdb/index/tsi1/index_test.go index f2e8565085c..e1853bb0d5c 100644 --- a/tsdb/index/tsi1/index_test.go +++ b/tsdb/index/tsi1/index_test.go @@ -2,6 +2,7 @@ package tsi1_test import ( "compress/gzip" + "errors" "fmt" "io" "os" @@ -287,7 +288,7 @@ func TestIndex_Open(t *testing.T) { // Opening this index should return an error because the MANIFEST has an // incompatible version. err = idx.Open() - if err != tsi1.ErrIncompatibleVersion { + if !errors.Is(err, tsi1.ErrIncompatibleVersion) { idx.Close() t.Fatalf("got error %v, expected %v", err, tsi1.ErrIncompatibleVersion) } diff --git a/tsdb/index/tsi1/partition.go b/tsdb/index/tsi1/partition.go index dc01568ffec..12dbf186890 100644 --- a/tsdb/index/tsi1/partition.go +++ b/tsdb/index/tsi1/partition.go @@ -16,6 +16,7 @@ import ( "github.com/influxdata/influxdb/logger" "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/pkg/bytesutil" + errors2 "github.com/influxdata/influxdb/pkg/errors" "github.com/influxdata/influxdb/pkg/estimator" "github.com/influxdata/influxdb/tsdb" "github.com/influxdata/influxql" @@ -148,14 +149,14 @@ func (p *Partition) Open() (rErr error) { p.closing = make(chan struct{}) if p.opened { - return errors.New("index partition already open") + return fmt.Errorf("index partition already open: %q", p.path) } // Validate path is correct. p.id = filepath.Base(p.path) _, err := strconv.Atoi(p.id) if err != nil { - return err + return fmt.Errorf("poorly formed manifest file path, %q: %w", p.path, err) } // Create directory if it doesn't exist. @@ -163,8 +164,9 @@ func (p *Partition) Open() (rErr error) { return err } + filename := filepath.Join(p.path, ManifestFileName) // Read manifest file. - m, manifestSize, err := ReadManifestFile(filepath.Join(p.path, ManifestFileName)) + m, manifestSize, err := ReadManifestFile(filename) if os.IsNotExist(err) { m = NewManifest(p.ManifestPath()) } else if err != nil { @@ -278,12 +280,12 @@ func (p *Partition) openIndexFile(path string) (*IndexFile, error) { } // deleteNonManifestFiles removes all files not in the manifest. -func (p *Partition) deleteNonManifestFiles(m *Manifest) error { +func (p *Partition) deleteNonManifestFiles(m *Manifest) (rErr error) { dir, err := os.Open(p.path) if err != nil { return err } - defer dir.Close() + defer errors2.Capture(&rErr, dir.Close)() fis, err := dir.Readdir(-1) if err != nil { @@ -302,7 +304,7 @@ func (p *Partition) deleteNonManifestFiles(m *Manifest) error { } } - return dir.Close() + return nil } func (p *Partition) buildSeriesSet() error { @@ -1305,7 +1307,7 @@ func (m *Manifest) Validate() error { // If we don't have an explicit version in the manifest file then we know // it's not compatible with the latest tsi1 Index. if m.Version != Version { - return ErrIncompatibleVersion + return fmt.Errorf("%q: %w", m.path, ErrIncompatibleVersion) } return nil } @@ -1315,7 +1317,7 @@ func (m *Manifest) Validate() error { func (m *Manifest) Write() (int64, error) { buf, err := json.MarshalIndent(m, "", " ") if err != nil { - return 0, err + return 0, fmt.Errorf("failed marshaling %q: %w", m.path, err) } buf = append(buf, '\n') @@ -1336,7 +1338,7 @@ func ReadManifestFile(path string) (*Manifest, int64, error) { // Decode manifest. var m Manifest if err := json.Unmarshal(buf, &m); err != nil { - return nil, 0, err + return nil, 0, fmt.Errorf("failed unmarshaling %q: %w", path, err) } // Set the path of the manifest. diff --git a/tsdb/index/tsi1/partition_test.go b/tsdb/index/tsi1/partition_test.go index 887e9c968ca..c01e65a5f69 100644 --- a/tsdb/index/tsi1/partition_test.go +++ b/tsdb/index/tsi1/partition_test.go @@ -1,6 +1,7 @@ package tsi1_test import ( + "errors" "fmt" "os" "path/filepath" @@ -61,7 +62,7 @@ func TestPartition_Open(t *testing.T) { // Opening this index should return an error because the MANIFEST has an // incompatible version. err = p.Open() - if err != tsi1.ErrIncompatibleVersion { + if !errors.Is(err, tsi1.ErrIncompatibleVersion) { p.Close() t.Fatalf("got error %v, expected %v", err, tsi1.ErrIncompatibleVersion) }