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] Ghost consumers after failed meta proposal #6088

Merged
merged 1 commit into from
Nov 7, 2024
Merged
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
29 changes: 17 additions & 12 deletions server/jetstream_cluster.go
Original file line number Diff line number Diff line change
@@ -138,10 +138,11 @@ type streamAssignment struct {
Reply string `json:"reply"`
Restore *StreamState `json:"restore_state,omitempty"`
// Internal
consumers map[string]*consumerAssignment
responded bool
recovering bool
err error
consumers map[string]*consumerAssignment
pendingConsumers map[string]struct{}
responded bool
recovering bool
err error
}

// consumerAssignment is what the meta controller uses to assign consumers to streams.
@@ -4260,6 +4261,10 @@ func (js *jetStream) processConsumerAssignment(ca *consumerAssignment) {
// Place into our internal map under the stream assignment.
// Ok to replace an existing one, we check on process call below.
sa.consumers[ca.Name] = ca
delete(sa.pendingConsumers, ca.Name)
if len(sa.pendingConsumers) == 0 {
sa.pendingConsumers = nil
}
js.mu.Unlock()

acc, err := s.LookupAccount(accName)
@@ -7411,7 +7416,7 @@ func (s *Server) jsClusteredConsumerRequest(ci *ClientInfo, acc *Account, subjec
}
if maxc > 0 {
// Don't count DIRECTS.
total := 0
total := len(sa.pendingConsumers)
for cn, ca := range sa.consumers {
if action == ActionCreateOrUpdate {
// If the consumer name is specified and we think it already exists, then
@@ -7669,14 +7674,14 @@ func (s *Server) jsClusteredConsumerRequest(ci *ClientInfo, acc *Account, subjec
ca = nca
}

// Mark this as pending.
if sa.consumers == nil {
sa.consumers = make(map[string]*consumerAssignment)
}
sa.consumers[ca.Name] = ca

// Do formal proposal.
cc.meta.Propose(encodeAddConsumerAssignment(ca))
if err := cc.meta.Propose(encodeAddConsumerAssignment(ca)); err == nil {
// Mark this as pending.
if sa.pendingConsumers == nil {
sa.pendingConsumers = make(map[string]struct{})
}
sa.pendingConsumers[ca.Name] = struct{}{}
}
}

func encodeAddConsumerAssignment(ca *consumerAssignment) []byte {
6 changes: 6 additions & 0 deletions server/jetstream_cluster_2_test.go
Original file line number Diff line number Diff line change
@@ -2072,6 +2072,12 @@ func TestJetStreamClusterMaxConsumersMultipleConcurrentRequests(t *testing.T) {
if nc := len(names); nc > 1 {
t.Fatalf("Expected only 1 consumer, got %d", nc)
}

metaLeader := c.leader()
mjs := metaLeader.getJetStream()
sa := mjs.streamAssignment(globalAccountName, "MAXCC")
require_NotNil(t, sa)
require_True(t, sa.pendingConsumers == nil)
}

func TestJetStreamClusterAccountMaxStreamsAndConsumersMultipleConcurrentRequests(t *testing.T) {