Skip to content

[FIXED] Propagate stream interest policy changes to consumers in all cases #6995

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

Merged
merged 1 commit into from
Jun 20, 2025
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
46 changes: 46 additions & 0 deletions server/jetstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20164,3 +20164,49 @@ func TestJetStreamDirectGetStartTimeSingleMsg(t *testing.T) {
})
}
}

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

nc, js := jsClientConnect(t, s)
defer nc.Close()

for _, tc := range []struct {
from RetentionPolicy
to RetentionPolicy
}{
{LimitsPolicy, InterestPolicy},
{InterestPolicy, LimitsPolicy},
} {
from, to, name := tc.from, tc.to, fmt.Sprintf("%sTo%s", tc.from, tc.to)
t.Run(name, func(t *testing.T) {
sc, err := jsStreamCreate(t, nc, &StreamConfig{
Name: name,
Subjects: []string{name},
Retention: from,
Storage: FileStorage,
})
require_NoError(t, err)

_, err = js.AddConsumer(name, &nats.ConsumerConfig{
Name: "test_consumer",
AckPolicy: nats.AckExplicitPolicy,
})
require_NoError(t, err)

mset, err := s.globalAccount().lookupStream(name)
require_NoError(t, err)

o := mset.lookupConsumer("test_consumer")
require_NotNil(t, err)
require_Equal(t, o.retention, from)

sc.Retention = to
_, err = jsStreamUpdate(t, nc, sc)
require_NoError(t, err)

require_Equal(t, o.retention, to)
})
}
}
2 changes: 1 addition & 1 deletion server/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2177,7 +2177,7 @@ func (mset *stream) updateWithAdvisory(config *StreamConfig, sendAdvisory bool,

// If we're changing retention and haven't errored because of consumer
// replicas by now, whip through and update the consumer retention.
if ocfg.Retention != cfg.Retention && cfg.Retention == InterestPolicy {
if ocfg.Retention != cfg.Retention {
toUpdate := make([]*consumer, 0, len(mset.consumers))
for _, c := range mset.consumers {
toUpdate = append(toUpdate, c)
Expand Down
Loading