Skip to content

Commit 7e9ac7b

Browse files
committed
MDEV-10296 - Multi-instance table cache
Improve scalability by implementing multi-instance table cache.
1 parent 6c1c27e commit 7e9ac7b

File tree

9 files changed

+186
-185
lines changed

9 files changed

+186
-185
lines changed

mysql-test/r/mysqld--help.result

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,8 @@ The following options may be given as the first argument:
10911091
The number of cached table definitions
10921092
--table-open-cache=#
10931093
The number of cached open tables
1094+
--table-open-cache-instances=#
1095+
The number of table cache instances
10941096
--tc-heuristic-recover=name
10951097
Decision to use in heuristic recover process. One of: OFF,
10961098
COMMIT, ROLLBACK
@@ -1457,6 +1459,7 @@ sysdate-is-now FALSE
14571459
table-cache 431
14581460
table-definition-cache 400
14591461
table-open-cache 431
1462+
table-open-cache-instances 1
14601463
tc-heuristic-recover OFF
14611464
thread-cache-size 151
14621465
thread-pool-idle-timeout 60

mysql-test/suite/sys_vars/r/sysvars_server_embedded.result

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3887,6 +3887,20 @@ NUMERIC_BLOCK_SIZE 1
38873887
ENUM_VALUE_LIST NULL
38883888
READ_ONLY NO
38893889
COMMAND_LINE_ARGUMENT REQUIRED
3890+
VARIABLE_NAME TABLE_OPEN_CACHE_INSTANCES
3891+
SESSION_VALUE NULL
3892+
GLOBAL_VALUE 1
3893+
GLOBAL_VALUE_ORIGIN COMPILE-TIME
3894+
DEFAULT_VALUE 1
3895+
VARIABLE_SCOPE GLOBAL
3896+
VARIABLE_TYPE BIGINT UNSIGNED
3897+
VARIABLE_COMMENT The number of table cache instances
3898+
NUMERIC_MIN_VALUE 1
3899+
NUMERIC_MAX_VALUE 64
3900+
NUMERIC_BLOCK_SIZE 1
3901+
ENUM_VALUE_LIST NULL
3902+
READ_ONLY YES
3903+
COMMAND_LINE_ARGUMENT REQUIRED
38903904
VARIABLE_NAME THREAD_CACHE_SIZE
38913905
SESSION_VALUE NULL
38923906
GLOBAL_VALUE 151

mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4657,6 +4657,20 @@ NUMERIC_BLOCK_SIZE 1
46574657
ENUM_VALUE_LIST NULL
46584658
READ_ONLY NO
46594659
COMMAND_LINE_ARGUMENT REQUIRED
4660+
VARIABLE_NAME TABLE_OPEN_CACHE_INSTANCES
4661+
SESSION_VALUE NULL
4662+
GLOBAL_VALUE 1
4663+
GLOBAL_VALUE_ORIGIN COMPILE-TIME
4664+
DEFAULT_VALUE 1
4665+
VARIABLE_SCOPE GLOBAL
4666+
VARIABLE_TYPE BIGINT UNSIGNED
4667+
VARIABLE_COMMENT The number of table cache instances
4668+
NUMERIC_MIN_VALUE 1
4669+
NUMERIC_MAX_VALUE 64
4670+
NUMERIC_BLOCK_SIZE 1
4671+
ENUM_VALUE_LIST NULL
4672+
READ_ONLY YES
4673+
COMMAND_LINE_ARGUMENT REQUIRED
46604674
VARIABLE_NAME THREAD_CACHE_SIZE
46614675
SESSION_VALUE NULL
46624676
GLOBAL_VALUE 151

sql/mysqld.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4974,8 +4974,7 @@ static int init_server_components()
49744974
all things are initialized so that unireg_abort() doesn't fail
49754975
*/
49764976
mdl_init();
4977-
tdc_init();
4978-
if (hostname_cache_init())
4977+
if (tdc_init() || hostname_cache_init())
49794978
unireg_abort(1);
49804979

49814980
query_cache_set_min_res_unit(query_cache_min_res_unit);
@@ -7643,7 +7642,6 @@ struct my_option my_long_options[]=
76437642
MYSQL_TO_BE_IMPLEMENTED_OPTION("eq-range-index-dive-limit"),
76447643
MYSQL_COMPATIBILITY_OPTION("server-id-bits"),
76457644
MYSQL_TO_BE_IMPLEMENTED_OPTION("slave-rows-search-algorithms"), // HAVE_REPLICATION
7646-
MYSQL_COMPATIBILITY_OPTION("table-open-cache-instances"),
76477645
MYSQL_TO_BE_IMPLEMENTED_OPTION("slave-allow-batching"), // HAVE_REPLICATION
76487646
MYSQL_COMPATIBILITY_OPTION("slave-checkpoint-period"), // HAVE_REPLICATION
76497647
MYSQL_COMPATIBILITY_OPTION("slave-checkpoint-group"), // HAVE_REPLICATION

sql/sql_base.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,7 @@ void close_thread_table(THD *thd, TABLE **table_ptr)
878878
Do this *before* entering the TABLE_SHARE::tdc.LOCK_table_share
879879
critical section.
880880
*/
881-
if (table->file != NULL)
882-
MYSQL_UNBIND_TABLE(table->file);
881+
MYSQL_UNBIND_TABLE(table->file);
883882

884883
tc_release_table(table);
885884
DBUG_VOID_RETURN;

sql/sys_vars.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3227,6 +3227,11 @@ static Sys_var_ulong Sys_table_cache_size(
32273227
BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
32283228
ON_UPDATE(fix_table_open_cache));
32293229

3230+
static Sys_var_ulong Sys_table_cache_instances(
3231+
"table_open_cache_instances", "The number of table cache instances",
3232+
READ_ONLY GLOBAL_VAR(tc_instances), CMD_LINE(REQUIRED_ARG),
3233+
VALID_RANGE(1, 64), DEFAULT(1), BLOCK_SIZE(1));
3234+
32303235
static Sys_var_ulong Sys_thread_cache_size(
32313236
"thread_cache_size",
32323237
"How many threads we should keep in a cache for reuse. These are freed after 5 minutes of idle time",

sql/table.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,13 +1021,13 @@ struct TABLE
10211021
One should use methods of I_P_List template instead.
10221022
*/
10231023
TABLE *share_all_next, **share_all_prev;
1024+
TABLE *global_free_next, **global_free_prev;
10241025
friend struct All_share_tables;
1026+
friend class Table_cache_instance;
10251027

10261028
public:
10271029

10281030
THD *in_use; /* Which thread uses this */
1029-
/* Time when table was released to table cache. Valid for unused tables. */
1030-
ulonglong tc_time;
10311031
Field **field; /* Pointer to fields */
10321032

10331033
uchar *record[2]; /* Pointer to records */

0 commit comments

Comments
 (0)