Skip to content

Commit 9eb4ad5

Browse files
committed
Cleanup: Access lower_case_table_names, tdc_size directly
dict_sys_t::evict_table_LRU(): Replaces dict_make_room_in_cache() and srv_master_evict_from_table_cache(). innobase_get_table_cache_size(): Replaced with direct read of tdc_size, in dict_sys_t::evict_table_LRU(). innobase_get_lower_case_table_names(): Replaced with direct reads of lower_case_table_names.
1 parent 383f77c commit 9eb4ad5

File tree

8 files changed

+54
-149
lines changed

8 files changed

+54
-149
lines changed

storage/innobase/dict/dict0dict.cc

Lines changed: 37 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,14 +1248,10 @@ inline void dict_sys_t::add(dict_table_t* table)
12481248
ut_ad(dict_lru_validate());
12491249
}
12501250

1251-
/**********************************************************************//**
1252-
Test whether a table can be evicted from the LRU cache.
1253-
@return TRUE if table can be evicted. */
1254-
static
1255-
ibool
1256-
dict_table_can_be_evicted(
1257-
/*======================*/
1258-
dict_table_t* table) /*!< in: table to test */
1251+
/** Test whether a table can be evicted from dict_sys.table_LRU.
1252+
@param table table to be considered for eviction
1253+
@return whether the table can be evicted */
1254+
static bool dict_table_can_be_evicted(dict_table_t *table)
12591255
{
12601256
ut_d(dict_sys.assert_locked());
12611257
ut_a(table->can_be_evicted);
@@ -1269,25 +1265,26 @@ dict_table_can_be_evicted(
12691265
the table instance is in "use". */
12701266

12711267
if (lock_table_has_locks(table)) {
1272-
return(FALSE);
1268+
return false;
12731269
}
12741270

12751271
#ifdef BTR_CUR_HASH_ADAPT
12761272
/* We cannot really evict the table if adaptive hash
12771273
index entries are pointing to any of its indexes. */
1278-
for (dict_index_t* index = dict_table_get_first_index(table);
1279-
index != NULL;
1280-
index = dict_table_get_next_index(index)) {
1274+
for (const dict_index_t* index
1275+
= dict_table_get_first_index(table);
1276+
index; index = dict_table_get_next_index(index)) {
12811277
if (index->n_ahi_pages()) {
1282-
return(FALSE);
1278+
return false;
12831279
}
12841280
}
12851281
#endif /* BTR_CUR_HASH_ADAPT */
12861282

1287-
return(TRUE);
1283+
ut_ad(!table->fts);
1284+
return true;
12881285
}
12891286

1290-
return(FALSE);
1287+
return false;
12911288
}
12921289

12931290
#ifdef BTR_CUR_HASH_ADAPT
@@ -1354,64 +1351,49 @@ dict_index_t *dict_index_t::clone_if_needed()
13541351
}
13551352
#endif /* BTR_CUR_HASH_ADAPT */
13561353

1357-
/**********************************************************************//**
1358-
Make room in the table cache by evicting an unused table. The unused table
1359-
should not be part of FK relationship and currently not used in any user
1360-
transaction. There is no guarantee that it will remove a table.
1361-
@return number of tables evicted. If the number of tables in the dict_LRU
1362-
is less than max_tables it will not do anything. */
1363-
ulint
1364-
dict_make_room_in_cache(
1365-
/*====================*/
1366-
ulint max_tables, /*!< in: max tables allowed in cache */
1367-
ulint pct_check) /*!< in: max percent to check */
1354+
/** Evict unused, unlocked tables from table_LRU.
1355+
@param half whether to consider half the tables only (instead of all)
1356+
@return number of tables evicted */
1357+
ulint dict_sys_t::evict_table_LRU(bool half)
13681358
{
1369-
ulint i;
1370-
ulint len;
1371-
dict_table_t* table;
1372-
ulint check_up_to;
1373-
ulint n_evicted = 0;
1359+
#ifdef MYSQL_DYNAMIC_PLUGIN
1360+
constexpr ulint max_tables = 400;
1361+
#else
1362+
extern ulong tdc_size;
1363+
const ulint max_tables = tdc_size;
1364+
#endif
1365+
ulint n_evicted = 0;
13741366

1375-
ut_a(pct_check > 0);
1376-
ut_a(pct_check <= 100);
1377-
ut_d(dict_sys.assert_locked());
1367+
lock(SRW_LOCK_CALL);
13781368
ut_ad(dict_lru_validate());
13791369

1380-
i = len = UT_LIST_GET_LEN(dict_sys.table_LRU);
1370+
const ulint len = UT_LIST_GET_LEN(table_LRU);
13811371

13821372
if (len < max_tables) {
1383-
return(0);
1373+
func_exit:
1374+
unlock();
1375+
return(n_evicted);
13841376
}
13851377

1386-
check_up_to = len - ((len * pct_check) / 100);
1387-
1388-
/* Check for overflow */
1389-
ut_a(i == 0 || check_up_to <= i);
1378+
const ulint check_up_to = half ? len / 2 : 0;
1379+
ulint i = len;
13901380

13911381
/* Find a suitable candidate to evict from the cache. Don't scan the
13921382
entire LRU list. Only scan pct_check list entries. */
13931383

1394-
for (table = UT_LIST_GET_LAST(dict_sys.table_LRU);
1395-
table != NULL
1396-
&& i > check_up_to
1397-
&& (len - n_evicted) > max_tables;
1398-
--i) {
1399-
1400-
dict_table_t* prev_table;
1401-
1402-
prev_table = UT_LIST_GET_PREV(table_LRU, table);
1384+
for (dict_table_t *table = UT_LIST_GET_LAST(table_LRU);
1385+
table && i > check_up_to && (len - n_evicted) > max_tables; --i) {
1386+
dict_table_t* prev_table = UT_LIST_GET_PREV(table_LRU, table);
14031387

14041388
if (dict_table_can_be_evicted(table)) {
1405-
ut_ad(!table->fts);
1406-
dict_sys.remove(table, true);
1407-
1389+
remove(table, true);
14081390
++n_evicted;
14091391
}
14101392

14111393
table = prev_table;
14121394
}
14131395

1414-
return(n_evicted);
1396+
goto func_exit;
14151397
}
14161398

14171399
/** Looks for an index with the given id given a table instance.
@@ -3411,7 +3393,7 @@ dict_get_referenced_table(
34113393
/* Values; 0 = Store and compare as given; case sensitive
34123394
1 = Store and compare in lower; case insensitive
34133395
2 = Store as given, compare in lower; case semi-sensitive */
3414-
if (innobase_get_lower_case_table_names() == 2) {
3396+
if (lower_case_table_names == 2) {
34153397
innobase_casedn_str(ref);
34163398
*table = dict_table_get_low(ref);
34173399
memcpy(ref, database_name, database_name_len);
@@ -3420,7 +3402,7 @@ dict_get_referenced_table(
34203402

34213403
} else {
34223404
#ifndef _WIN32
3423-
if (innobase_get_lower_case_table_names() == 1) {
3405+
if (lower_case_table_names == 1) {
34243406
innobase_casedn_str(ref);
34253407
}
34263408
#else

storage/innobase/dict/dict0load.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,8 +3181,7 @@ dict_load_foreigns(
31813181
goto next_rec;
31823182
}
31833183

3184-
if (innobase_get_lower_case_table_names() != 2
3185-
&& memcmp(field, table_name, len)) {
3184+
if (lower_case_table_names != 2 && memcmp(field, table_name, len)) {
31863185
goto next_rec;
31873186
}
31883187

storage/innobase/dict/dict0mem.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ dict_mem_foreign_table_name_lookup_set(
833833
dict_foreign_t* foreign, /*!< in/out: foreign struct */
834834
ibool do_alloc) /*!< in: is an alloc needed */
835835
{
836-
if (innobase_get_lower_case_table_names() == 2) {
836+
if (lower_case_table_names == 2) {
837837
if (do_alloc) {
838838
ulint len;
839839

@@ -863,7 +863,7 @@ dict_mem_referenced_table_name_lookup_set(
863863
dict_foreign_t* foreign, /*!< in/out: foreign struct */
864864
ibool do_alloc) /*!< in: is an alloc needed */
865865
{
866-
if (innobase_get_lower_case_table_names() == 2) {
866+
if (lower_case_table_names == 2) {
867867
if (do_alloc) {
868868
ulint len;
869869

storage/innobase/handler/ha_innodb.cc

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ void close_thread_tables(THD* thd);
136136

137137
#ifdef MYSQL_DYNAMIC_PLUGIN
138138
#define tc_size 400
139-
#define tdc_size 400
140139
#endif
141140

142141
#include <mysql/plugin.h>
@@ -2362,31 +2361,6 @@ innobase_get_stmt_unsafe(
23622361
return NULL;
23632362
}
23642363

2365-
/**********************************************************************//**
2366-
Get the current setting of the tdc_size global parameter. We do
2367-
a dirty read because for one there is no synchronization object and
2368-
secondly there is little harm in doing so even if we get a torn read.
2369-
@return value of tdc_size */
2370-
ulint
2371-
innobase_get_table_cache_size(void)
2372-
/*===============================*/
2373-
{
2374-
return(tdc_size);
2375-
}
2376-
2377-
/**********************************************************************//**
2378-
Get the current setting of the lower_case_table_names global parameter from
2379-
mysqld.cc. We do a dirty read because for one there is no synchronization
2380-
object and secondly there is little harm in doing so even if we get a torn
2381-
read.
2382-
@return value of lower_case_table_names */
2383-
ulint
2384-
innobase_get_lower_case_table_names(void)
2385-
/*=====================================*/
2386-
{
2387-
return(lower_case_table_names);
2388-
}
2389-
23902364
/**
23912365
Test a file path whether it is same as mysql data directory path.
23922366

@@ -6088,7 +6062,7 @@ ha_innobase::open_dict_table(
60886062
sensitive platform in Windows, we might need to
60896063
check the existence of table name without lower
60906064
case in the system table. */
6091-
if (innobase_get_lower_case_table_names() == 1) {
6065+
if (lower_case_table_names == 1) {
60926066
char par_case_name[FN_REFLEN];
60936067

60946068
#ifndef _WIN32
@@ -13352,8 +13326,7 @@ inline int ha_innobase::delete_table(const char* name, enum_sql_command sqlcom)
1335213326

1335313327
err = row_drop_table_for_mysql(norm_name, trx, sqlcom);
1335413328

13355-
if (err == DB_TABLE_NOT_FOUND
13356-
&& innobase_get_lower_case_table_names() == 1) {
13329+
if (err == DB_TABLE_NOT_FOUND && lower_case_table_names == 1) {
1335713330
char* is_part = is_partition(norm_name);
1335813331

1335913332
if (is_part) {
@@ -13451,7 +13424,7 @@ inline dberr_t innobase_rename_table(trx_t *trx, const char *from,
1345113424

1345213425
if (error != DB_SUCCESS) {
1345313426
if (error == DB_TABLE_NOT_FOUND
13454-
&& innobase_get_lower_case_table_names() == 1) {
13427+
&& lower_case_table_names == 1) {
1345513428
char* is_part = is_partition(norm_from);
1345613429

1345713430
if (is_part) {

storage/innobase/include/dict0dict.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -942,16 +942,6 @@ dict_index_find_on_id_low(
942942
/*======================*/
943943
index_id_t id) /*!< in: index id */
944944
MY_ATTRIBUTE((warn_unused_result));
945-
/**********************************************************************//**
946-
Make room in the table cache by evicting an unused table. The unused table
947-
should not be part of FK relationship and currently not used in any user
948-
transaction. There is no guarantee that it will remove a table.
949-
@return number of tables evicted. */
950-
ulint
951-
dict_make_room_in_cache(
952-
/*====================*/
953-
ulint max_tables, /*!< in: max tables allowed in cache */
954-
ulint pct_check); /*!< in: max percent to check */
955945

956946
/** Adds an index to the dictionary cache, with possible indexing newly
957947
added column.
@@ -1587,6 +1577,11 @@ class dict_sys_t
15871577
+ temp_id_hash.n_cells) * sizeof(hash_cell_t);
15881578
return size;
15891579
}
1580+
1581+
/** Evict unused, unlocked tables from table_LRU.
1582+
@param half whether to consider half the tables only (instead of all)
1583+
@return number of tables evicted */
1584+
ulint evict_table_LRU(bool half);
15901585
};
15911586

15921587
/** the data dictionary cache */

storage/innobase/include/ha_prototypes.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -257,25 +257,6 @@ const char*
257257
thd_innodb_tmpdir(
258258
THD* thd);
259259

260-
/**********************************************************************//**
261-
Get the current setting of the table_cache_size global parameter. We do
262-
a dirty read because for one there is no synchronization object and
263-
secondly there is little harm in doing so even if we get a torn read.
264-
@return SQL statement string */
265-
ulint
266-
innobase_get_table_cache_size(void);
267-
/*===============================*/
268-
269-
/**********************************************************************//**
270-
Get the current setting of the lower_case_table_names global parameter from
271-
mysqld.cc. We do a dirty read because for one there is no synchronization
272-
object and secondly there is little harm in doing so even if we get a torn
273-
read.
274-
@return value of lower_case_table_names */
275-
ulint
276-
innobase_get_lower_case_table_names(void);
277-
/*=====================================*/
278-
279260
/******************************************************************//**
280261
compare two character string case insensitively according to their charset. */
281262
int

storage/innobase/row/row0mysql.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3815,10 +3815,9 @@ row_rename_table_for_mysql(
38153815
is_part = strstr((char *)old_name, (char *)"#P#");
38163816
#endif /* __WIN__ */
38173817

3818-
/* MySQL partition engine hard codes the file name
3819-
separator as "#P#". The text case is fixed even if
3820-
lower_case_table_names is set to 1 or 2. This is true
3821-
for sub-partition names as well. InnoDB always
3818+
/* MariaDB partition engine hard codes the file name
3819+
separator as "#P#" and "#SP#". The text case is fixed even if
3820+
lower_case_table_names is set to 1 or 2. InnoDB always
38223821
normalises file names to lower case on Windows, this
38233822
can potentially cause problems when copying/moving
38243823
tables between platforms.
@@ -3832,9 +3831,7 @@ row_rename_table_for_mysql(
38323831
sensitive platform in Windows, we might need to
38333832
check the existence of table name without lowering
38343833
case them in the system table. */
3835-
if (!table &&
3836-
is_part &&
3837-
innobase_get_lower_case_table_names() == 1) {
3834+
if (!table && is_part && lower_case_table_names == 1) {
38383835
char par_case_name[MAX_FULL_NAME_LEN + 1];
38393836
#ifndef __WIN__
38403837
/* Check for the table using lower

storage/innobase/srv/srv0srv.cc

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,27 +1487,6 @@ srv_sync_log_buffer_in_background(void)
14871487
}
14881488
}
14891489

1490-
/********************************************************************//**
1491-
Make room in the table cache by evicting an unused table.
1492-
@return number of tables evicted. */
1493-
static
1494-
ulint
1495-
srv_master_evict_from_table_cache(
1496-
/*==============================*/
1497-
ulint pct_check) /*!< in: max percent to check */
1498-
{
1499-
ulint n_tables_evicted = 0;
1500-
1501-
dict_sys_lock();
1502-
1503-
n_tables_evicted = dict_make_room_in_cache(
1504-
innobase_get_table_cache_size(), pct_check);
1505-
1506-
dict_sys_unlock();
1507-
1508-
return(n_tables_evicted);
1509-
}
1510-
15111490
/*********************************************************************//**
15121491
This function prints progress message every 60 seconds during server
15131492
shutdown, for any activities that master thread is pending on. */
@@ -1640,7 +1619,7 @@ srv_master_do_active_tasks(void)
16401619

16411620
if (cur_time % SRV_MASTER_DICT_LRU_INTERVAL == 0) {
16421621
srv_main_thread_op_info = "enforcing dict cache limit";
1643-
ulint n_evicted = srv_master_evict_from_table_cache(50);
1622+
ulint n_evicted = dict_sys.evict_table_LRU(true);
16441623
if (n_evicted != 0) {
16451624
MONITOR_INC_VALUE(
16461625
MONITOR_SRV_DICT_LRU_EVICT_COUNT_ACTIVE, n_evicted);
@@ -1694,8 +1673,7 @@ srv_master_do_idle_tasks(void)
16941673
}
16951674

16961675
srv_main_thread_op_info = "enforcing dict cache limit";
1697-
ulint n_evicted = srv_master_evict_from_table_cache(100);
1698-
if (n_evicted != 0) {
1676+
if (ulint n_evicted = dict_sys.evict_table_LRU(false)) {
16991677
MONITOR_INC_VALUE(
17001678
MONITOR_SRV_DICT_LRU_EVICT_COUNT_IDLE, n_evicted);
17011679
}

0 commit comments

Comments
 (0)