Skip to content

Commit

Permalink
[FIXED] Had a perf regression with some fss fixes. (#5632)
Browse files Browse the repository at this point in the history
We could still use find if we know the status of wildcard.

Signed-off-by: Derek Collison <derek@nats.io>
  • Loading branch information
derekcollison authored Jul 9, 2024
2 parents ed7ab4c + fc2f9f6 commit 733f234
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions server/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2323,10 +2323,14 @@ func (mb *msgBlock) firstMatching(filter string, wc bool, start uint64, sm *Stor

// If we only have 1 subject currently and it matches our filter we can also set isAll.
if !isAll && mb.fss.Size() == 1 {
// Since mb.fss.Find won't work if filter is a wildcard, need to use Match instead.
mb.fss.Match(stringToBytes(filter), func(subject []byte, _ *SimpleState) {
isAll = true
})
if !wc {
_, isAll = mb.fss.Find(stringToBytes(filter))
} else {
// Since mb.fss.Find won't work if filter is a wildcard, need to use Match instead.
mb.fss.Match(stringToBytes(filter), func(subject []byte, _ *SimpleState) {
isAll = true
})
}
}
// Make sure to start at mb.first.seq if fseq < mb.first.seq
if seq := atomic.LoadUint64(&mb.first.seq); seq > fseq {
Expand Down Expand Up @@ -2982,17 +2986,14 @@ func (fs *fileStore) NumPending(sseq uint64, filter string, lastPerSubject bool)
}

isAll := filter == _EMPTY_ || filter == fwcs
if isAll && filter == _EMPTY_ {
filter = fwcs
}
wc := subjectHasWildcard(filter)

// See if filter was provided but its the only subject.
if !isAll && !wc && fs.psim.Size() == 1 {
// Since fs.psim.Find won't work if filter is a wildcard, need to use Match instead.
fs.psim.Match(stringToBytes(filter), func(subject []byte, _ *psi) {
isAll = true
})
}
if isAll && filter == _EMPTY_ {
filter = fwcs
_, isAll = fs.psim.Find(stringToBytes(filter))
}
// If we are isAll and have no deleted we can do a simpler calculation.
if !lastPerSubject && isAll && (fs.state.LastSeq-fs.state.FirstSeq+1) == fs.state.Msgs {
Expand Down

0 comments on commit 733f234

Please sign in to comment.