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] Process sourced streams consumer sequences inline iff R1. #6219

Merged
merged 1 commit into from
Dec 5, 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
33 changes: 19 additions & 14 deletions server/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -3692,6 +3692,15 @@ func (mset *stream) startingSequenceForSources() {
}
}()

update := func(iName string, seq uint64) {
// Only update active in case we have older ones in here that got configured out.
if si := mset.sources[iName]; si != nil {
if _, ok := seqs[iName]; !ok {
seqs[iName] = seq
}
}
}

var smv StoreMsg
for seq := state.LastSeq; seq >= state.FirstSeq; seq-- {
sm, err := mset.store.LoadMsg(seq, &smv)
Expand All @@ -3703,15 +3712,6 @@ func (mset *stream) startingSequenceForSources() {
continue
}

var update = func(iName string, seq uint64) {
// Only update active in case we have older ones in here that got configured out.
if si := mset.sources[iName]; si != nil {
if _, ok := seqs[iName]; !ok {
seqs[iName] = seq
}
}
}

streamName, iName, sseq := streamAndSeq(string(ss))
if iName == _EMPTY_ { // Pre-2.10 message header means it's a match for any source using that stream name
for _, ssi := range mset.cfg.Sources {
Expand Down Expand Up @@ -3793,12 +3793,17 @@ func (mset *stream) subscribeToStream() error {
} else if len(mset.cfg.Sources) > 0 && mset.sourcesConsumerSetup == nil {
// Setup the initial source infos for the sources
mset.resetSourceInfo()
// Delay the actual source consumer(s) creation(s) for after a delay
mset.sourcesConsumerSetup = time.AfterFunc(time.Duration(rand.Intn(int(500*time.Millisecond)))+100*time.Millisecond, func() {
mset.mu.Lock()
// Delay the actual source consumer(s) creation(s) for after a delay if a replicated stream.
// If it's an R1, this is done at startup and we will do inline.
if mset.cfg.Replicas == 1 {
mset.setupSourceConsumers()
mset.mu.Unlock()
})
} else {
mset.sourcesConsumerSetup = time.AfterFunc(time.Duration(rand.Intn(int(500*time.Millisecond)))+100*time.Millisecond, func() {
mset.mu.Lock()
mset.setupSourceConsumers()
mset.mu.Unlock()
})
}
}
// Check for direct get access.
// We spin up followers for clustered streams in monitorStream().
Expand Down
Loading