mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-17 11:24:44 -07:00
Merge branch 'main' into dev
Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
@@ -41,7 +41,7 @@ var (
|
||||
|
||||
const (
|
||||
// VERSION is the current version for the server.
|
||||
VERSION = "2.10.0-beta.46"
|
||||
VERSION = "2.10.0-beta.47"
|
||||
|
||||
// PROTO is the currently supported protocol.
|
||||
// 0 was the original
|
||||
|
||||
@@ -6223,6 +6223,8 @@ func (mb *msgBlock) recalculateFirstForSubj(subj string, startSeq uint64, ss *Si
|
||||
if startSlot >= len(mb.cache.idx) {
|
||||
ss.First = ss.Last
|
||||
return
|
||||
} else if startSlot < 0 {
|
||||
startSlot = 0
|
||||
}
|
||||
|
||||
var le = binary.LittleEndian
|
||||
|
||||
@@ -5673,3 +5673,35 @@ func TestFileStoreInitialFirstSeq(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestFileStoreRecaluclateFirstForSubjBug(t *testing.T) {
|
||||
fs, err := newFileStore(FileStoreConfig{StoreDir: t.TempDir()}, StreamConfig{Name: "zzz", Subjects: []string{"*"}, Storage: FileStorage})
|
||||
require_NoError(t, err)
|
||||
|
||||
fs.StoreMsg("foo", nil, nil) // 1
|
||||
fs.StoreMsg("bar", nil, nil) // 2
|
||||
fs.StoreMsg("foo", nil, nil) // 3
|
||||
|
||||
// Now remove first 2..
|
||||
fs.RemoveMsg(1)
|
||||
fs.RemoveMsg(2)
|
||||
|
||||
// Now grab first (and only) block.
|
||||
fs.mu.RLock()
|
||||
mb := fs.blks[0]
|
||||
fs.mu.RUnlock()
|
||||
|
||||
// Since we lazy update the first, simulate that we have not updated it as of yet.
|
||||
ss := &SimpleState{Msgs: 1, First: 1, Last: 3, firstNeedsUpdate: true}
|
||||
|
||||
mb.mu.Lock()
|
||||
defer mb.mu.Unlock()
|
||||
|
||||
// Flush the cache.
|
||||
mb.clearCacheAndOffset()
|
||||
// Now call with start sequence of 1, the old one
|
||||
// This will panic without the fix.
|
||||
mb.recalculateFirstForSubj("foo", 1, ss)
|
||||
// Make sure it was update properly.
|
||||
require_True(t, *ss == SimpleState{Msgs: 1, First: 3, Last: 3, firstNeedsUpdate: false})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user