mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-17 03:24:40 -07:00
Under the right circumstances Compact could leave a danling last msg block leading to error opening msg block file [""]: open : no such file or directory
When the compaction would not uplevel to a normal purge, but after completion all msg blocks were empty the mb.lmb was not cleared or reset properly. Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
@@ -4911,6 +4911,11 @@ SKIP:
|
||||
}
|
||||
// Update blks slice.
|
||||
fs.blks = copyMsgBlocks(fs.blks[deleted:])
|
||||
if lb := len(fs.blks); lb == 0 {
|
||||
fs.lmb = nil
|
||||
} else {
|
||||
fs.lmb = fs.blks[lb-1]
|
||||
}
|
||||
}
|
||||
|
||||
// Update top level accounting.
|
||||
|
||||
@@ -4833,3 +4833,28 @@ func TestFileStoreBadFirstAndFailedExpireAfterRestart(t *testing.T) {
|
||||
require_True(t, state.LastSeq == 9)
|
||||
require_True(t, state.LastTime == ts)
|
||||
}
|
||||
|
||||
func TestFileStoreCompactAllWithDanglingLMB(t *testing.T) {
|
||||
storeDir := t.TempDir()
|
||||
|
||||
fs, err := newFileStore(
|
||||
FileStoreConfig{StoreDir: storeDir},
|
||||
StreamConfig{Name: "zzz", Subjects: []string{"foo"}, Storage: FileStorage},
|
||||
)
|
||||
require_NoError(t, err)
|
||||
defer fs.Stop()
|
||||
|
||||
subj, msg := "foo", []byte("ZZ")
|
||||
for i := 0; i < 100; i++ {
|
||||
_, _, err := fs.StoreMsg(subj, nil, msg)
|
||||
require_NoError(t, err)
|
||||
}
|
||||
|
||||
fs.RemoveMsg(100)
|
||||
purged, err := fs.Compact(100)
|
||||
require_NoError(t, err)
|
||||
require_True(t, purged == 99)
|
||||
|
||||
_, _, err = fs.StoreMsg(subj, nil, msg)
|
||||
require_NoError(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user