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

Cap min and max ring size to 4K #5801

Merged
merged 2 commits into from Nov 18, 2022
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
2 changes: 1 addition & 1 deletion xds/internal/balancer/clusterresolver/config_test.go
Expand Up @@ -249,7 +249,7 @@ func TestParseConfig(t *testing.T) {
},
XDSLBPolicy: &internalserviceconfig.BalancerConfig{
Name: ringhash.Name,
Config: &ringhash.LBConfig{MinRingSize: 1024, MaxRingSize: 8388608}, // Ringhash LB config with default min and max.
Config: &ringhash.LBConfig{MinRingSize: 1024, MaxRingSize: 4096}, // Ringhash LB config with default min and max.
},
},
wantErr: false,
Expand Down
10 changes: 9 additions & 1 deletion xds/internal/balancer/ringhash/config.go
Expand Up @@ -35,7 +35,9 @@ type LBConfig struct {

const (
defaultMinSize = 1024
defaultMaxSize = 8 * 1024 * 1024 // 8M
defaultMaxSize = 4096
// TODO(apolcyn): make makeRingSizeCap configurable, with either a dial option or global setting
maxRingSizeCap = 4096
)

func parseConfig(c json.RawMessage) (*LBConfig, error) {
Expand All @@ -49,6 +51,12 @@ func parseConfig(c json.RawMessage) (*LBConfig, error) {
if cfg.MaxRingSize == 0 {
cfg.MaxRingSize = defaultMaxSize
}
if cfg.MinRingSize > maxRingSizeCap {
cfg.MinRingSize = maxRingSizeCap
}
if cfg.MaxRingSize > maxRingSizeCap {
cfg.MaxRingSize = maxRingSizeCap
}
if cfg.MinRingSize > cfg.MaxRingSize {
return nil, fmt.Errorf("min %v is greater than max %v", cfg.MinRingSize, cfg.MaxRingSize)
}
Comment on lines 60 to 62
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this check be done first? Otherwise it passes if Min > Max > MaxCap. Or is that okay?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because MaxCap is supposed to clamp min and max, I don't see a benefit of failing (beyond catching weird configuration). The client is still able to make use of such data sensibly, because of the clamp, so it seems overly fragile to fail.

Expand Down