diff --git a/server/filestore.go b/server/filestore.go index 33229c54..62439de7 100644 --- a/server/filestore.go +++ b/server/filestore.go @@ -463,6 +463,7 @@ func (mb *msgBlock) rebuildState() (*LostStreamData, error) { // Clear state we need to rebuild. mb.msgs, mb.bytes = 0, 0 mb.last.seq, mb.last.ts = 0, 0 + mb.first.seq, mb.first.ts = 0, 0 buf, err := ioutil.ReadFile(mb.mfn) if err != nil { @@ -514,6 +515,8 @@ func (mb *msgBlock) rebuildState() (*LostStreamData, error) { return &ld } + firstNeedsSet := true + for index, lbuf := uint32(0), uint32(len(buf)); index < lbuf; { if index+msgHdrSize >= lbuf { truncate(index) @@ -542,12 +545,6 @@ func (mb *msgBlock) rebuildState() (*LostStreamData, error) { seq := le.Uint64(hdr[4:]) ts := int64(le.Uint64(hdr[12:])) - // If the first seq we read does not match our indexed first seq, reset. - if index == 0 && seq > mb.first.seq { - mb.first.seq = seq - mb.first.ts = ts - } - // This is an old erased message, or a new one that we can track. if seq == 0 || seq&ebit != 0 || seq < mb.first.seq { seq = seq &^ ebit @@ -582,7 +579,8 @@ func (mb *msgBlock) rebuildState() (*LostStreamData, error) { copy(mb.lchk[0:], checksum) } - if mb.first.seq == 0 { + if firstNeedsSet { + firstNeedsSet = false mb.first.seq = seq mb.first.ts = ts }