Fix for test failure when racing against double deletes

Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
Derek Collison
2020-05-20 15:23:39 -07:00
parent 131e276341
commit 3e5d0c343d
2 changed files with 29 additions and 9 deletions

View File

@@ -766,11 +766,28 @@ func (fs *fileStore) deleteMsgFromBlock(mb *msgBlock, seq uint64, sm *fileStored
msz := fileStoreMsgSize(sm.subj, sm.msg)
fs.mu.Lock()
mb.mu.Lock()
// Make sure the seq still exists.
if seq < mb.cache.fseq || (seq-mb.cache.fseq) >= uint64(len(mb.cache.idx)) {
mb.mu.Unlock()
fs.mu.Unlock()
return
}
// Now check dmap if it is there.
if mb.dmap != nil {
if _, ok := mb.dmap[seq]; ok {
mb.mu.Unlock()
fs.mu.Unlock()
return
}
}
// Global stats
fs.state.Msgs--
fs.state.Bytes -= msz
// Now local mb updates.
mb.mu.Lock()
mb.msgs--
mb.bytes -= msz
atomic.AddUint64(&mb.cgenid, 1)

View File

@@ -594,7 +594,6 @@ func TestFileStoreAgeLimitRecovery(t *testing.T) {
t.Fatalf("Expected %d msgs, got %d", toStore, state.Msgs)
}
fs.Stop()
time.Sleep(2 * maxAge)
fs, err = newFileStore(FileStoreConfig{StoreDir: storeDir}, StreamConfig{Name: "zzz", Storage: FileStorage, MaxAge: maxAge})
if err != nil {
@@ -602,13 +601,17 @@ func TestFileStoreAgeLimitRecovery(t *testing.T) {
}
defer fs.Stop()
state = fs.State()
if state.Msgs != 0 {
t.Fatalf("Expected no msgs, got %d", state.Msgs)
}
if state.Bytes != 0 {
t.Fatalf("Expected no bytes, got %d", state.Bytes)
}
// Make sure they expire.
checkFor(t, time.Second, 2*maxAge, func() error {
state = fs.State()
if state.Msgs != 0 {
return fmt.Errorf("Expected no msgs, got %d", state.Msgs)
}
if state.Bytes != 0 {
return fmt.Errorf("Expected no bytes, got %d", state.Bytes)
}
return nil
})
}
func TestFileStoreBitRot(t *testing.T) {