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

sessionctx,infoschema: change @@tidb_schema_cache_size lower bound to 64MB #56316

Merged
merged 3 commits into from
Sep 26, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions pkg/infoschema/infoschema_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,13 +607,6 @@ func (is *infoschemaV2) TableByID(ctx context.Context, id int64) (val table.Tabl
return
}

// Get from the cache.
key := tableCacheKey{id, is.infoSchema.schemaMetaVersion}
tbl, found := is.tableCache.Get(key)
if found && tbl != nil {
return tbl, true
}

itm, ok := is.searchTableItemByID(id)
if !ok {
return nil, false
Expand All @@ -635,11 +628,8 @@ func (is *infoschemaV2) TableByID(ctx context.Context, id int64) (val table.Tabl

// get cache with old key
oldKey := tableCacheKey{itm.tableID, itm.schemaVersion}
tbl, found = is.tableCache.Get(oldKey)
tbl, found := is.tableCache.Get(oldKey)
if found && tbl != nil {
if refill {
is.tableCache.Set(key, tbl)
}
return tbl, true
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/sessionctx/variable/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1648,12 +1648,12 @@ func TestTiDBSchemaCacheSize(t *testing.T) {
// Check default value
require.Equal(t, schemaCacheSize.Value, strconv.Itoa(DefTiDBSchemaCacheSize))

// MinValue is 512 MB
err = mock.SetGlobalSysVar(context.Background(), TiDBSchemaCacheSize, strconv.FormatUint(100*mb, 10))
// MinValue is 64 MB
err = mock.SetGlobalSysVar(context.Background(), TiDBSchemaCacheSize, strconv.FormatUint(63*mb, 10))
require.NoError(t, err)
val, err = mock.GetGlobalSysVar(TiDBSchemaCacheSize)
require.NoError(t, err)
require.Equal(t, "512MB", val)
require.Equal(t, "64MB", val)

// MaxValue is 9223372036854775807
err = mock.SetGlobalSysVar(context.Background(), TiDBSchemaCacheSize, strconv.FormatUint(maxValue, 10))
Expand All @@ -1663,11 +1663,11 @@ func TestTiDBSchemaCacheSize(t *testing.T) {
require.Equal(t, strconv.FormatUint(maxValue, 10), val)

// test MinValue-1
err = mock.SetGlobalSysVar(context.Background(), TiDBSchemaCacheSize, strconv.FormatUint(100*mb-1, 10))
err = mock.SetGlobalSysVar(context.Background(), TiDBSchemaCacheSize, strconv.FormatUint(64*mb-1, 10))
require.NoError(t, err)
val, err = mock.GetGlobalSysVar(TiDBSchemaCacheSize)
require.NoError(t, err)
require.Equal(t, "512MB", val)
require.Equal(t, "64MB", val)

// test MaxValue+1
err = mock.SetGlobalSysVar(context.Background(), TiDBSchemaCacheSize, strconv.FormatUint(maxValue+1, 10))
Expand Down Expand Up @@ -1702,8 +1702,8 @@ func TestTiDBSchemaCacheSize(t *testing.T) {
require.NoError(t, err)
val, err = mock.GetGlobalSysVar(TiDBSchemaCacheSize)
require.NoError(t, err)
require.Equal(t, SchemaCacheSize.Load(), uint64(512<<20))
require.Equal(t, "512MB", val)
require.Equal(t, SchemaCacheSize.Load(), uint64(64<<20))
require.Equal(t, "64MB", val)

err = mock.SetGlobalSysVar(context.Background(), TiDBSchemaCacheSize, "12345678KB")
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/sessionctx/variable/varsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,10 @@ func ParseAnalyzeSkipColumnTypes(val string) map[string]struct{} {
var (
// SchemaCacheSizeLowerBound will adjust the schema cache size to this value if
// it is lower than this value.
SchemaCacheSizeLowerBound uint64 = 512 * units.MiB
SchemaCacheSizeLowerBound uint64 = 64 * units.MiB
// SchemaCacheSizeLowerBoundStr is the string representation of
// SchemaCacheSizeLowerBound.
SchemaCacheSizeLowerBoundStr = "512MB"
SchemaCacheSizeLowerBoundStr = "64MB"
)

func parseSchemaCacheSize(s *SessionVars, normalizedValue string, originalValue string) (byteSize uint64, normalizedStr string, err error) {
Expand Down