Skip to content
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] Fixed bug that would return no msg found for loadLast. #5578

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions server/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -6279,6 +6279,8 @@ func (fs *fileStore) loadLast(subj string, sm *StoreMsg) (lsm *StoreMsg, err err
if stop == 0 {
return nil, ErrStoreMsgNotFound
}
// These need to be swapped.
start, stop = stop, start
} else if info, ok := fs.psim.Find(stringToBytes(subj)); ok {
start, stop = info.lblk, info.fblk
} else {
Expand Down
19 changes: 19 additions & 0 deletions server/filestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7039,6 +7039,25 @@ func TestFileStoreLoadLastWildcard(t *testing.T) {
require_Equal(t, cloads, 1)
}

func TestFileStoreLoadLastWildcardWithPresenceMultipleBlocks(t *testing.T) {
sd := t.TempDir()
fs, err := newFileStore(
FileStoreConfig{StoreDir: sd, BlockSize: 64},
StreamConfig{Name: "zzz", Subjects: []string{"foo.*.*"}, Storage: FileStorage})
require_NoError(t, err)
defer fs.Stop()

// Make sure we have "foo.222.bar" in multiple blocks to show bug.
fs.StoreMsg("foo.22.bar", nil, []byte("hello"))
fs.StoreMsg("foo.22.baz", nil, []byte("ok"))
fs.StoreMsg("foo.22.baz", nil, []byte("ok"))
fs.StoreMsg("foo.22.bar", nil, []byte("hello22"))
require_True(t, fs.numMsgBlocks() > 1)
sm, err := fs.LoadLastMsg("foo.*.bar", nil)
require_NoError(t, err)
require_Equal(t, "hello22", string(sm.msg))
}

// We want to make sure that we update psim correctly on a miss.
func TestFileStoreFilteredPendingPSIMFirstBlockUpdate(t *testing.T) {
sd := t.TempDir()
Expand Down