Skip to content

Commit

Permalink
fix(init): initialShardSize ignored HardMaxCacheSize, and so the init…
Browse files Browse the repository at this point in the history
…ial size can exceed the limit (#228)
  • Loading branch information
leeransetton authored Jun 17, 2020
1 parent bbb395e commit bbbffd3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func DefaultConfig(eviction time.Duration) Config {

// initialShardSize computes initial shard size
func (c Config) initialShardSize() int {
return max(c.MaxEntriesInWindow/c.Shards, minimumEntriesInShard)
return max(min(c.MaxEntriesInWindow/c.Shards, c.maximumShardSize()), minimumEntriesInShard)
}

// maximumShardSize computes maximum shard size
Expand Down
7 changes: 7 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ func max(a, b int) int {
return b
}

func min(a, b int) int {
if a < b {
return a
}
return b
}

func convertMBToBytes(value int) int {
return value * 1024 * 1024
}
Expand Down

0 comments on commit bbbffd3

Please sign in to comment.