-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIXED] Subject state consistency #6226
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2614,10 +2614,6 @@ func (fs *fileStore) numFilteredPendingWithLast(filter string, last bool, ss *Si | |
// Always reset. | ||
ss.First, ss.Last, ss.Msgs = 0, 0, 0 | ||
|
||
if filter == _EMPTY_ { | ||
filter = fwcs | ||
} | ||
|
||
// We do need to figure out the first and last sequences. | ||
wc := subjectHasWildcard(filter) | ||
start, stop := uint32(math.MaxUint32), uint32(0) | ||
|
@@ -7502,6 +7498,9 @@ func (fs *fileStore) Compact(seq uint64) (uint64, error) { | |
// Update fss | ||
smb.removeSeqPerSubject(sm.subj, mseq) | ||
fs.removePerSubject(sm.subj) | ||
// Need to mark the sequence as deleted. Otherwise, recalculating ss.First | ||
// for per-subject info would be able to find it still. | ||
smb.dmap.Insert(mseq) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another important addition; |
||
} | ||
} | ||
|
||
|
@@ -7943,11 +7942,16 @@ func (mb *msgBlock) removeSeqPerSubject(subj string, seq uint64) { | |
|
||
// Only one left. | ||
if ss.Msgs == 1 { | ||
if seq == ss.Last { | ||
ss.Last = ss.First | ||
} else { | ||
ss.First = ss.Last | ||
// Update first if we need to, we must check if this removal is about what's going to be ss.First | ||
if ss.firstNeedsUpdate { | ||
mb.recalculateFirstForSubj(subj, ss.First, ss) | ||
} | ||
// If we're removing the first message, we must recalculate again. | ||
// ss.Last is lazy as well, so need to calculate new ss.First and set ss.Last to it. | ||
if ss.First == seq { | ||
mb.recalculateFirstForSubj(subj, ss.First, ss) | ||
} | ||
ss.Last = ss.First | ||
ss.firstNeedsUpdate = false | ||
return | ||
} | ||
|
@@ -7977,8 +7981,12 @@ func (mb *msgBlock) recalculateFirstForSubj(subj string, startSeq uint64, ss *Si | |
startSlot = 0 | ||
} | ||
|
||
fseq := startSeq + 1 | ||
if mbFseq := atomic.LoadUint64(&mb.first.seq); fseq < mbFseq { | ||
fseq = mbFseq | ||
} | ||
var le = binary.LittleEndian | ||
for slot, fseq := startSlot, atomic.LoadUint64(&mb.first.seq); slot < len(mb.cache.idx); slot++ { | ||
for slot := startSlot; slot < len(mb.cache.idx); slot++ { | ||
bi := mb.cache.idx[slot] &^ hbit | ||
if bi == dbit { | ||
// delete marker so skip. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is redundant, if
isAll := filter == _EMPTY_ || filter == fwcs
we early return above.