diff --git a/index/scorch/persister.go b/index/scorch/persister.go index f1a372e7..cab2d035 100644 --- a/index/scorch/persister.go +++ b/index/scorch/persister.go @@ -633,14 +633,19 @@ func (s *Scorch) removeOldBoltSnapshots() (numRemoved int, err error) { return 0, err } - if len(persistedEpochs) <= NumSnapshotsToKeep { + numSnapshotsToKeep := NumSnapshotsToKeep + if val, ok := s.config["numSnapshotsToKeep"].(float64); ok && val > 0 { + numSnapshotsToKeep = int(val) + } + + if len(persistedEpochs) <= numSnapshotsToKeep { // we need to keep everything return 0, nil } // make a map of epochs to protect from deletion - protectedEpochs := make(map[uint64]struct{}, NumSnapshotsToKeep) - for _, epoch := range persistedEpochs[0:NumSnapshotsToKeep] { + protectedEpochs := make(map[uint64]struct{}, numSnapshotsToKeep) + for _, epoch := range persistedEpochs[0:numSnapshotsToKeep] { protectedEpochs[epoch] = struct{}{} }