Skip to content

Commit 0d7edc7

Browse files
eurekakasre-bot
authored andcommitted
config: add validation for capacity of prepare plan cache (pingcap#14232)
1 parent 7c902dc commit 0d7edc7

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

config/config.go

+3
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,9 @@ func (c *Config) Valid() error {
751751
if c.AlterPrimaryKey && c.Experimental.AllowAutoRandom {
752752
return fmt.Errorf("allow-auto-random is unavailable when alter-primary-key is enabled")
753753
}
754+
if c.PreparedPlanCache.Capacity < 1 {
755+
return fmt.Errorf("capacity in [prepared-plan-cache] should be at least 1")
756+
}
754757
return nil
755758
}
756759

util/kvcache/simple_lru.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ type SimpleLRUCache struct {
4848
// NewSimpleLRUCache creates a SimpleLRUCache object, whose capacity is "capacity".
4949
// NOTE: "capacity" should be a positive value.
5050
func NewSimpleLRUCache(capacity uint, guard float64, quota uint64) *SimpleLRUCache {
51-
if capacity == 0 {
52-
panic("capacity of LRU Cache should be positive.")
51+
if capacity < 1 {
52+
panic("capacity of LRU Cache should be at least 1.")
5353
}
5454
return &SimpleLRUCache{
5555
capacity: capacity,

0 commit comments

Comments
 (0)