@@ -549,7 +549,7 @@ func (f *FileStore) Open(ctx context.Context) error {
549549 // find the current max ID for temp directories
550550 tmpfiles , err := os .ReadDir (f .dir )
551551 if err != nil {
552- return err
552+ return fmt . Errorf ( "error calling ReadDir on %q in FileStore.Open: %w" , f . dir , err )
553553 }
554554
555555 // ascertain the current temp directory number by examining the existing
@@ -575,9 +575,10 @@ func (f *FileStore) Open(ctx context.Context) error {
575575 f .currentTempDirID = i
576576 }
577577
578- files , err := filepath .Glob (filepath .Join (f .dir , "*." + TSMFileExtension ))
578+ pattern := filepath .Join (f .dir , "*." + TSMFileExtension )
579+ files , err := filepath .Glob (pattern )
579580 if err != nil {
580- return err
581+ return fmt . Errorf ( "error in Glob for %q in FileStore.Open: %w" , pattern , err )
581582 }
582583
583584 // struct to hold the result of opening each reader in a goroutine
@@ -591,7 +592,7 @@ func (f *FileStore) Open(ctx context.Context) error {
591592 // Keep track of the latest ID
592593 generation , _ , err := f .parseFileName (fn )
593594 if err != nil {
594- return err
595+ return fmt . Errorf ( "error parsing %q in FileStore.Open: %w" , fn , err )
595596 }
596597
597598 if generation >= f .currentGeneration {
@@ -600,7 +601,7 @@ func (f *FileStore) Open(ctx context.Context) error {
600601
601602 file , err := os .OpenFile (fn , os .O_RDONLY , 0666 )
602603 if err != nil {
603- return fmt .Errorf ("error opening file %s : %v " , fn , err )
604+ return fmt .Errorf ("error calling OpenFile on %q in FileStore.Open : %w " , fn , err )
604605 }
605606
606607 go func (idx int , file * os.File ) {
@@ -624,17 +625,20 @@ func (f *FileStore) Open(ctx context.Context) error {
624625 // If we are unable to read a TSM file then log the error, rename
625626 // the file, and continue loading the shard without it.
626627 if err != nil {
628+ if cerr := file .Close (); cerr != nil {
629+ f .logger .Error ("Error closing TSM file after error" , zap .String ("path" , file .Name ()), zap .Int ("id" , idx ), zap .Error (cerr ))
630+ }
631+ // If the file is corrupt, rename it and
632+ // continue loading the shard without it.
627633 f .logger .Error ("Cannot read corrupt tsm file, renaming" , zap .String ("path" , file .Name ()), zap .Int ("id" , idx ), zap .Error (err ))
628- file .Close ()
629634 if e := os .Rename (file .Name (), file .Name ()+ "." + BadTSMFileExtension ); e != nil {
630635 f .logger .Error ("Cannot rename corrupt tsm file" , zap .String ("path" , file .Name ()), zap .Int ("id" , idx ), zap .Error (e ))
631- readerC <- & res {r : df , err : fmt .Errorf ("cannot rename corrupt file %s: %v " , file .Name (), e )}
636+ readerC <- & res {r : df , err : fmt .Errorf ("cannot rename corrupt file %s: %w " , file .Name (), e )}
632637 return
633638 }
634- readerC <- & res {r : df , err : fmt .Errorf ("cannot read corrupt file %s: %v " , file .Name (), err )}
639+ readerC <- & res {r : df , err : fmt .Errorf ("cannot read corrupt file %s: %w " , file .Name (), err )}
635640 return
636641 }
637-
638642 df .WithObserver (f .obs )
639643 readerC <- & res {r : df }
640644 }(i , file )
@@ -668,7 +672,7 @@ func (f *FileStore) Open(ctx context.Context) error {
668672 f .lastModified = fi .ModTime ().UTC ()
669673 } else {
670674 close (readerC )
671- return err
675+ return fmt . Errorf ( "error calling Stat on %q in FileStore.Open: %w" , f . dir , err )
672676 }
673677 } else {
674678 f .lastModified = time .Unix (0 , lm ).UTC ()
0 commit comments