fix issue where we incorrectly seed the nextSegmentID on Open()
This commit is contained in:
parent
0c0f05e398
commit
a575be4d56
|
@ -22,6 +22,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/RoaringBitmap/roaring"
|
"github.com/RoaringBitmap/roaring"
|
||||||
|
@ -318,10 +319,9 @@ func (s *Scorch) loadFromBolt() error {
|
||||||
}
|
}
|
||||||
indexSnapshot.epoch = snapshotEpoch
|
indexSnapshot.epoch = snapshotEpoch
|
||||||
// set the nextSegmentID
|
// set the nextSegmentID
|
||||||
for _, segment := range indexSnapshot.segment {
|
s.nextSegmentID, err = s.maxSegmentIDOnDisk()
|
||||||
if segment.id > s.nextSegmentID {
|
if err != nil {
|
||||||
s.nextSegmentID = segment.id
|
return err
|
||||||
}
|
|
||||||
}
|
}
|
||||||
s.nextSegmentID++
|
s.nextSegmentID++
|
||||||
s.nextSnapshotEpoch = snapshotEpoch + 1
|
s.nextSnapshotEpoch = snapshotEpoch + 1
|
||||||
|
@ -485,6 +485,29 @@ func (s *Scorch) removeOldBoltSnapshots() (numRemoved int, err error) {
|
||||||
return numRemoved, err
|
return numRemoved, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Scorch) maxSegmentIDOnDisk() (uint64, error) {
|
||||||
|
currFileInfos, err := ioutil.ReadDir(s.path)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var rv uint64
|
||||||
|
for _, finfo := range currFileInfos {
|
||||||
|
fname := finfo.Name()
|
||||||
|
if filepath.Ext(fname) == ".zap" {
|
||||||
|
prefix := strings.TrimSuffix(fname, ".zap")
|
||||||
|
id, err2 := strconv.ParseUint(prefix, 16, 64)
|
||||||
|
if err2 != nil {
|
||||||
|
return 0, err2
|
||||||
|
}
|
||||||
|
if id > rv {
|
||||||
|
rv = id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rv, err
|
||||||
|
}
|
||||||
|
|
||||||
// Removes any *.zap files which aren't listed in the rootBolt.
|
// Removes any *.zap files which aren't listed in the rootBolt.
|
||||||
func (s *Scorch) removeOldZapFiles() error {
|
func (s *Scorch) removeOldZapFiles() error {
|
||||||
liveFileNames, err := s.loadZapFileNames()
|
liveFileNames, err := s.loadZapFileNames()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user