mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 11:48:43 -07:00
Make setting of mb.first.seq more reliable
Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user