*: make changes to tidb_schema_cache_size effective immediately (#54279)

ref pingcap/tidb#50959
This commit is contained in:
tangenta
2024-07-02 21:32:56 +08:00
committed by GitHub
parent 7fea27eb46
commit abfee2337c
5 changed files with 33 additions and 0 deletions

View File

@ -40,6 +40,8 @@ func (do *Domain) initDomainSysVars() {
setGlobalResourceControlFunc := do.setGlobalResourceControl
variable.SetGlobalResourceControl.Store(&setGlobalResourceControlFunc)
variable.SetLowResolutionTSOUpdateInterval = do.setLowResolutionTSOUpdateInterval
variable.ChangeSchemaCacheSize = do.changeSchemaCacheSize
}
// setStatsCacheCapacity sets statsCache cap
@ -115,3 +117,9 @@ func (do *Domain) setExternalTimestamp(ctx context.Context, ts uint64) error {
func (do *Domain) getExternalTimestamp(ctx context.Context) (uint64, error) {
return do.store.GetOracle().GetExternalTimestamp(ctx)
}
func (do *Domain) changeSchemaCacheSize(size uint64) {
if size > 0 {
do.infoCache.Data.SetCacheCapacity(size)
}
}

View File

@ -197,6 +197,11 @@ func (isd *Data) CacheCapacity() uint64 {
return isd.tableCache.Capacity()
}
// SetCacheCapacity sets the cache capacity size in bytes.
func (isd *Data) SetCacheCapacity(capacity uint64) {
isd.tableCache.SetCapacityAndWaitEvict(capacity)
}
func (isd *Data) add(item tableItem, tbl table.Table) {
isd.byID.Set(item)
isd.byName.Set(item)

View File

@ -103,6 +103,21 @@ func (s *Sieve[K, V]) SetCapacity(capacity uint64) {
s.hook.onUpdateLimit(capacity)
}
func (s *Sieve[K, V]) SetCapacityAndWaitEvict(capacity uint64) {
s.SetCapacity(capacity)
for {
s.mu.Lock()
if s.size <= s.capacity {
s.mu.Unlock()
break
}
for i := 0; s.size > s.capacity && i < 10; i++ {
s.evict()
}
s.mu.Unlock()
}
}
func (s *Sieve[K, V]) Capacity() uint64 {
s.mu.Lock()
defer s.mu.Unlock()

View File

@ -3154,6 +3154,9 @@ var defaultSysVars = []*SysVar{
if err != nil {
return err
}
if SchemaCacheSize.Load() != bt && ChangeSchemaCacheSize != nil {
ChangeSchemaCacheSize(bt)
}
SchemaCacheSize.Store(bt)
SchemaCacheSizeOriginText.Store(str)
return nil

View File

@ -1647,6 +1647,8 @@ var (
ValidateCloudStorageURI func(ctx context.Context, uri string) error
// SetLowResolutionTSOUpdateInterval is the func registered by domain to set slow resolution tso update interval.
SetLowResolutionTSOUpdateInterval func(interval time.Duration) error = nil
// ChangeSchemaCacheSize is called when tidb_schema_cache_size is changed.
ChangeSchemaCacheSize func(size uint64)
)
// Hooks functions for Cluster Resource Control.