[FIXED] Ephemeral consumers always selects an online server#7165
Merged
neilalexander merged 1 commit intomainfrom Aug 13, 2025
Merged
[FIXED] Ephemeral consumers always selects an online server#7165neilalexander merged 1 commit intomainfrom
neilalexander merged 1 commit intomainfrom
Conversation
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
| if !isDurableConsumer(cfg) { | ||
| // We chose to have ephemerals be R=1 unless stream is interest or workqueue. | ||
| // Consumer can override. | ||
| if sa.Config.Retention == LimitsPolicy && cfg.Replicas <= 1 { |
Member
There was a problem hiding this comment.
Where is this logic now handled?
Member
Author
There was a problem hiding this comment.
It's handled as part of: replicas := cfg.replicas(sa.Config)
// Calculate accurate replicas for the consumer config with the parent stream config.
func (consCfg ConsumerConfig) replicas(strCfg *StreamConfig) int {
if consCfg.Replicas == 0 || consCfg.Replicas > strCfg.Replicas {
if !isDurableConsumer(&consCfg) && strCfg.Retention == LimitsPolicy && consCfg.Replicas == 0 {
// Matches old-school ephemerals only, where the replica count is 0.
return 1
}
return strCfg.Replicas
}
return consCfg.Replicas
}
Member
There was a problem hiding this comment.
I more meant the selection of the rg.Peers and the name selection for the consumer..
Member
Author
There was a problem hiding this comment.
That's already handled by cc.createGroupForConsumer
// First shuffle the active peers and then select to account for replica = 1.
rand.Shuffle(len(active), func(i, j int) { active[i], active[j] = active[j], active[i] })
peers = active[:replicas]
}
...
return &raftGroup{Name: groupNameForConsumer(peers, storage), Storage: storage, Peers: peers}
Member
Author
|
Will have a longer look at this tomorrow morning. |
Member
Author
|
Confirmed to be working. We now always select the right peer set with the right amount of peers in |
neilalexander
added a commit
that referenced
this pull request
Aug 13, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A Limits-based R3 stream can have ephemeral consumers that are R1. Ephemeral consumers don't specify a replica count, instead they specify
Replicas: 0, to be inferred automatically based on the stream retention and the amount of stream replicas.Before this PR,
createGroupForConsumerwould check there's at least one online server hosting the stream, but it would still select a peer set (R3 in this example) equal to the stream. After creating the group, it would be "fixed" by doingrg.Peers = []string{rg.Preferred}if it's an ephemeral consumer.In 2.12, due to this fix: #7083,
rg.setPreferred()will always only select online servers. But on 2.11 and prior, it could randomly select any node, even ones that are offline. Even though this will be fixed as well in 2.12, the real fix is to use the real replica count increateGroupForConsumer, immediately selecting the right peer set and not try fixing it outside of it.Signed-off-by: Maurice van Veen github@mauricevanveen.com