0
0
Fork 0

making NumSnapshotsToKeep configurable

This commit is contained in:
Sreekanth Sivasankaran 2018-03-06 16:22:11 +05:30
parent 4ebf3f1d44
commit fa5de8e09a
1 changed files with 8 additions and 3 deletions

View File

@ -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{}{}
}