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: interest across gateways #2750

Merged
merged 1 commit into from
Dec 20, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 11 additions & 9 deletions server/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,15 +786,16 @@ func (o *consumer) setLeader(isLeader bool) {
if o.isPushMode() {
o.inch = make(chan bool, 8)
o.acc.sl.registerNotification(o.cfg.DeliverSubject, o.cfg.DeliverGroup, o.inch)
if o.active = <-o.inch; !o.active {
// Check gateways in case they are enabled.
if s.gateway.enabled {
if o.active = <-o.inch; o.active {
o.checkQueueInterest()
}
// Check gateways in case they are enabled.
if s.gateway.enabled {
if !o.active {
o.active = s.hasGatewayInterest(o.acc.Name, o.cfg.DeliverSubject)
stopAndClearTimer(&o.gwdtmr)
o.gwdtmr = time.AfterFunc(time.Second, func() { o.watchGWinterest() })
}
} else {
o.checkQueueInterest()
stopAndClearTimer(&o.gwdtmr)
o.gwdtmr = time.AfterFunc(time.Second, func() { o.watchGWinterest() })
}
}

Expand Down Expand Up @@ -1277,7 +1278,7 @@ func (o *consumer) updateDeliverSubjectLocked(newDeliver string) {
o.forceExpirePending()
}

o.acc.sl.ClearNotification(o.dsubj, o.inch)
o.acc.sl.clearNotification(o.dsubj, o.cfg.DeliverGroup, o.inch)
o.dsubj, o.cfg.DeliverSubject = newDeliver, newDeliver
// When we register new one it will deliver to update state loop.
o.acc.sl.registerNotification(newDeliver, o.cfg.DeliverGroup, o.inch)
Expand Down Expand Up @@ -3133,6 +3134,7 @@ func (o *consumer) stopWithFlags(dflag, sdflag, doSignal, advisory bool) error {
o.signalNewMessages()
}
n := o.node
qgroup := o.cfg.DeliverGroup
o.mu.Unlock()

if c != nil {
Expand All @@ -3143,7 +3145,7 @@ func (o *consumer) stopWithFlags(dflag, sdflag, doSignal, advisory bool) error {
}

if delivery != _EMPTY_ {
a.sl.ClearNotification(delivery, o.inch)
a.sl.clearNotification(delivery, qgroup, o.inch)
}

mset.mu.Lock()
Expand Down
48 changes: 48 additions & 0 deletions server/jetstream_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9716,6 +9716,54 @@ func TestJetStreamConsumerUpdates(t *testing.T) {
t.Run("Clustered", func(t *testing.T) { testConsumerUpdate(t, c.randomServer(), 2) })
}

func TestJetStreamSuperClusterPushConsumerInterest(t *testing.T) {
sc := createJetStreamSuperCluster(t, 3, 2)
defer sc.shutdown()

for _, test := range []struct {
name string
queue string
}{
{"non queue", _EMPTY_},
{"queue", "queue"},
} {
t.Run(test.name, func(t *testing.T) {
testInterest := func(s *Server) {
t.Helper()
nc, js := jsClientConnect(t, s)
defer nc.Close()

_, err := js.AddStream(&nats.StreamConfig{
Name: "TEST",
Subjects: []string{"foo"},
Replicas: 3,
})
require_NoError(t, err)

var sub *nats.Subscription
if test.queue != _EMPTY_ {
sub, err = js.QueueSubscribeSync("foo", test.queue)
} else {
sub, err = js.SubscribeSync("foo", nats.Durable("dur"))
}
require_NoError(t, err)

js.Publish("foo", []byte("msg1"))
// Since the GW watcher is checking every 1sec, make sure we are
// giving it enough time for the delivery to start.
_, err = sub.NextMsg(2 * time.Second)
require_NoError(t, err)
}

// Create the durable push consumer from cluster "0"
testInterest(sc.clusters[0].servers[0])

// Now "move" to a server in cluster "1"
testInterest(sc.clusters[1].servers[0])
})
}
}

// Support functions

// Used to setup superclusters for tests.
Expand Down