@@ -764,7 +764,7 @@ func (s *Store) DeleteShard(shardID uint64) error {
764
764
return nil
765
765
}
766
766
767
- // Remove the shard from Store so it's not returned to callers requesting
767
+ // Remove the shard from Store, so it's not returned to callers requesting
768
768
// shards. Also mark that this shard is currently being deleted in a separate
769
769
// map so that we do not have to retain the global store lock while deleting
770
770
// files.
@@ -792,7 +792,6 @@ func (s *Store) DeleteShard(shardID uint64) error {
792
792
s .mu .Lock ()
793
793
defer s .mu .Unlock ()
794
794
delete (s .pendingShardDeletes , shardID )
795
- s .databases [db ].removeIndexType (sh .IndexType ())
796
795
}()
797
796
798
797
// Get the shard's local bitset of series IDs.
@@ -806,6 +805,7 @@ func (s *Store) DeleteShard(shardID uint64) error {
806
805
err = s .walkShards (shards , func (sh * Shard ) error {
807
806
index , err := sh .Index ()
808
807
if err != nil {
808
+ s .Logger .Error ("cannot find shard index" , zap .Uint64 ("shard_id" , sh .ID ()), zap .Error (err ))
809
809
return err
810
810
}
811
811
@@ -814,7 +814,9 @@ func (s *Store) DeleteShard(shardID uint64) error {
814
814
})
815
815
816
816
if err != nil {
817
- s .Logger .Error ("error walking shards during DeleteShard operation" , zap .Error (err ))
817
+ // We couldn't get the index for a shard. Rather than deleting series which may
818
+ // exist in that shard as well as in the current shard, we stop the current deletion
819
+ return err
818
820
}
819
821
820
822
// Remove any remaining series in the set from the series file, as they don't
@@ -823,13 +825,15 @@ func (s *Store) DeleteShard(shardID uint64) error {
823
825
sfile := s .seriesFile (db )
824
826
if sfile != nil {
825
827
ss .ForEach (func (id uint64 ) {
826
- err = sfile .DeleteSeriesID (id )
827
- if err != nil {
828
- s .Logger .Error ("error deleting series id during DeleteShard operation" , zap .Uint64 ("id" , id ), zap .Error (err ))
828
+ if err := sfile .DeleteSeriesID (id ); err != nil {
829
+ sfile .Logger .Error (
830
+ "cannot delete series in shard" ,
831
+ zap .Uint64 ("series_id" , id ),
832
+ zap .Uint64 ("shard_id" , shardID ),
833
+ zap .Error (err ))
829
834
}
830
835
})
831
836
}
832
-
833
837
}
834
838
835
839
// Close the shard.
@@ -840,9 +844,13 @@ func (s *Store) DeleteShard(shardID uint64) error {
840
844
// Remove the on-disk shard data.
841
845
if err := os .RemoveAll (sh .path ); err != nil {
842
846
return err
847
+ } else if err = os .RemoveAll (sh .walPath ); err != nil {
848
+ return err
849
+ } else {
850
+ // Remove index type from the database on success
851
+ s .databases [db ].removeIndexType (sh .IndexType ())
852
+ return nil
843
853
}
844
-
845
- return os .RemoveAll (sh .walPath )
846
854
}
847
855
848
856
// DeleteDatabase will close all shards associated with a database and remove the directory and files from disk.
0 commit comments