Skip to content

Commit

Permalink
Cap min and max ring size to 4K (grpc#5801)
Browse files Browse the repository at this point in the history
  • Loading branch information
apolcyn authored and jronak committed Nov 21, 2022
1 parent fcd3d71 commit 3f6e181
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
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)
}
Expand Down

0 comments on commit 3f6e181

Please sign in to comment.