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

[IMPROVED] Handling of sourcing into a WQ/Interest streamwith a limit and discard new #5372

Merged
merged 1 commit into from
May 1, 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
6 changes: 5 additions & 1 deletion server/jetstream_cluster_4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"math/rand"
"os"
"path/filepath"
"strconv"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -241,7 +242,7 @@ func TestJetStreamClusterSourceWorkingQueueWithLimit(t *testing.T) {

sendBatch := func(subject string, n int) {
for i := 0; i < n; i++ {
_, err = js.Publish(subject, []byte("OK"))
_, err = js.Publish(subject, []byte(strconv.Itoa(i)))
require_NoError(t, err)
}
}
Expand All @@ -267,6 +268,9 @@ func TestJetStreamClusterSourceWorkingQueueWithLimit(t *testing.T) {
for i := 0; i < 300; i++ {
m, err := ss.Fetch(1, nats.MaxWait(3*time.Second))
require_NoError(t, err)
p, err := strconv.Atoi(string(m[0].Data))
require_NoError(t, err)
require_Equal(t, p, i)
time.Sleep(11 * time.Millisecond)
err = m[0].Ack()
require_NoError(t, err)
Expand Down
26 changes: 18 additions & 8 deletions server/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -3297,15 +3297,25 @@ func (mset *stream) processInboundSourceMsg(si *sourceInfo, m *inMsg) bool {
mset.mu.RLock()
accName, sname, iname := mset.acc.Name, mset.cfg.Name, si.iname
mset.mu.RUnlock()
// Log some warning for errors other than errLastSeqMismatch
if err != errLastSeqMismatch {
s.RateLimitWarnf("Error processing inbound source %q for '%s' > '%s': %v",
iname, accName, sname, err)

// Can happen temporarily all the time during normal operations when the sourcing stream
// is working queue/interest with a limit and discard new.
// TODO - Improve sourcing to WQ with limit and new to use flow control rather than re-creating the consumer.
if errors.Is(err, ErrMaxMsgs) {
// Do not need to do a full retry that includes finding the last sequence in the stream
// for that source. Just re-create starting with the seq we couldn't store instead.
mset.retrySourceConsumerAtSeq(iname, si.sseq)
} else {
// Log some warning for errors other than errLastSeqMismatch or errMaxMsgs.
if !errors.Is(err, errLastSeqMismatch) {
s.RateLimitWarnf("Error processing inbound source %q for '%s' > '%s': %v",
iname, accName, sname, err)
}
// Retry in all type of errors.
// This will make sure the source is still in mset.sources map,
// find the last sequence and then call setupSourceConsumer.
mset.retrySourceConsumer(iname)
}
// Retry in all type of errors.
// This will make sure the source is still in mset.sources map,
// find the last sequence and then call setupSourceConsumer.
mset.retrySourceConsumer(iname)
}
return false
}
Expand Down