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] JetStream would exceed limits calculation #6264

Merged
merged 1 commit into from
Dec 16, 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: 1 addition & 1 deletion server/jetstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2163,7 +2163,7 @@ func (js *jetStream) wouldExceedLimits(storeType StorageType, sz int) bool {
} else {
total, max = &js.storeUsed, js.config.MaxStore
}
return atomic.LoadInt64(total) > (max + int64(sz))
return (atomic.LoadInt64(total) + int64(sz)) > max
}

func (js *jetStream) limitsExceeded(storeType StorageType) bool {
Expand Down
16 changes: 16 additions & 0 deletions server/jetstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24721,3 +24721,19 @@ func TestJetStreamMemoryPurgeClearsSubjectsState(t *testing.T) {
require_NoError(t, err)
require_Len(t, len(si.State.Subjects), 0)
}

func TestJetStreamWouldExceedLimits(t *testing.T) {
s := RunBasicJetStreamServer(t)
defer s.Shutdown()

js := s.getJetStream()
require_NotNil(t, js)

// Storing exactly up to the limit should work.
require_False(t, js.wouldExceedLimits(MemoryStorage, int(js.config.MaxMemory)))
require_False(t, js.wouldExceedLimits(FileStorage, int(js.config.MaxStore)))

// Storing one more than the max should exceed limits.
require_True(t, js.wouldExceedLimits(MemoryStorage, int(js.config.MaxMemory)+1))
require_True(t, js.wouldExceedLimits(FileStorage, int(js.config.MaxStore)+1))
}
Loading