Skip to content

Commit 811d2a0

Browse files
add fixes
1 parent 7e65c4d commit 811d2a0

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

index/scorch/persister.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,10 @@ func (s *Scorch) loadFromBolt() error {
958958
if err != nil {
959959
return err
960960
}
961-
s.checkPoints = liveSnapshots
961+
if len(liveSnapshots) != 0 {
962+
protectedSnapshots := s.getProtectedSnapshots(liveSnapshots)
963+
s.checkPoints = newCheckPoints(protectedSnapshots)
964+
}
962965
return nil
963966
}
964967

@@ -1365,15 +1368,15 @@ func (s *Scorch) getProtectedSnapshots(liveSnapshots []*snapshotMetaData) map[ui
13651368
}
13661369

13671370
func newCheckPoints(snapshots map[uint64]time.Time) []*snapshotMetaData {
1368-
rv := make([]*snapshotMetaData, 0)
1371+
rv := make([]*snapshotMetaData, 0, len(snapshots))
13691372

13701373
keys := make([]uint64, 0, len(snapshots))
13711374
for k := range snapshots {
13721375
keys = append(keys, k)
13731376
}
13741377

13751378
sort.SliceStable(keys, func(i, j int) bool {
1376-
return snapshots[keys[i]].Sub(snapshots[keys[j]]) > 0
1379+
return snapshots[keys[i]].After(snapshots[keys[j]])
13771380
})
13781381

13791382
for _, key := range keys {
@@ -1393,6 +1396,11 @@ func (s *Scorch) removeOldBoltSnapshots() (numRemoved int, err error) {
13931396
return 0, err
13941397
}
13951398

1399+
// if no live snapshots, then nothing to do
1400+
if len(liveSnapshots) == 0 {
1401+
return 0, nil
1402+
}
1403+
13961404
// then get the set of protected snapshots, which are the ones we want to keep
13971405
protectedSnapshots := s.getProtectedSnapshots(liveSnapshots)
13981406

0 commit comments

Comments
 (0)