From a76731e1a13933548ad4eaf6ee8b599cbc1260b6 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Thu, 24 Feb 2022 19:42:43 +0530 Subject: MDEV-27913 innodb_ft_cache_size max possible value (80000000) is too small for practical purposes - Make innodb_ft_cache_size & innodb_ft_total_cache_size are dynamic variable and increase the maximum value of innodb_ft_cache_size to 512MB for 32-bit system and 1 TB for 64-bit system and set innodb_ft_total_cache_size maximum value to 1 TB for 64-bit system. - Print warning if the fts cache exceeds the innodb_ft_cache_size and also unlock the cache if fts cache memory reduces less than innodb_ft_cache_size. --- storage/innobase/fts/fts0fts.cc | 37 ++++++++++++++++++---- storage/innobase/fts/fts0opt.cc | 15 ++++++++- storage/innobase/handler/ha_innodb.cc | 58 +++++++++++++++++++++++++++++++---- storage/innobase/include/fts0fts.h | 4 +-- 4 files changed, 99 insertions(+), 15 deletions(-) (limited to 'storage') diff --git a/storage/innobase/fts/fts0fts.cc b/storage/innobase/fts/fts0fts.cc index 32982256302..acab4791d8b 100644 --- a/storage/innobase/fts/fts0fts.cc +++ b/storage/innobase/fts/fts0fts.cc @@ -53,14 +53,26 @@ by looking up the key word in the obsolete table names */ /** This is maximum FTS cache for each table and would be a configurable variable */ -ulong fts_max_cache_size; +size_t fts_max_cache_size; + +static size_t fts_get_max_cache() +{ +#if UNIV_WORD_SIZE == 4 + return my_atomic_load32_explicit(&fts_max_cache_size, + MY_MEMORY_ORDER_RELAXED); +#else + return my_atomic_load64_explicit( + reinterpret_cast(&fts_max_cache_size), + MY_MEMORY_ORDER_RELAXED); +#endif +} /** Whether the total memory used for FTS cache is exhausted, and we will need a sync to free some memory */ bool fts_need_sync = false; /** Variable specifying the total memory allocated for FTS cache */ -ulong fts_max_total_cache_size; +size_t fts_max_total_cache_size; /** This is FTS result cache limit for each query and would be a configurable variable */ @@ -3381,7 +3393,7 @@ fts_add_doc_from_tuple( rw_lock_x_unlock(&table->fts->cache->lock); - if (cache->total_size > fts_max_cache_size / 5 + if (cache->total_size > fts_get_max_cache() / 5 || fts_need_sync) { fts_sync(cache->sync, true, false); } @@ -3546,7 +3558,7 @@ fts_add_doc_by_id( && (fts_need_sync || (cache->total_size - cache->total_size_at_sync) - > fts_max_cache_size / 10); + > fts_get_max_cache() / 10); if (need_sync) { cache->total_size_at_sync = cache->total_size; @@ -4284,7 +4296,7 @@ fts_sync( ulint i; dberr_t error = DB_SUCCESS; fts_cache_t* cache = sync->table->fts->cache; - + size_t fts_cache_size= 0; rw_lock_x_lock(&cache->lock); /* Check if cache is being synced. @@ -4309,11 +4321,17 @@ fts_sync( fts_sync_begin(sync); begin_sync: - if (cache->total_size > fts_max_cache_size) { + fts_cache_size= fts_get_max_cache(); + if (cache->total_size > fts_cache_size) { /* Avoid the case: sync never finish when insert/update keeps comming. */ ut_ad(sync->unlock_cache); sync->unlock_cache = false; + ib::warn() << "Total InnoDB FTS size " + << cache->total_size << " for the table " + << cache->sync->table->name + << " exceeds the innodb_ft_cache_size " + << fts_cache_size; } for (i = 0; i < ib_vector_size(cache->indexes); ++i) { @@ -4336,6 +4354,13 @@ begin_sync: if (error != DB_SUCCESS) { goto end_sync; } + + if (!sync->unlock_cache + && cache->total_size < fts_get_max_cache()) { + /* Reset the unlock cache if the value + is less than innodb_ft_cache_size */ + sync->unlock_cache = true; + } } DBUG_EXECUTE_IF("fts_instrument_sync_interrupted", diff --git a/storage/innobase/fts/fts0opt.cc b/storage/innobase/fts/fts0opt.cc index 0288377d4ea..376f09b8ff5 100644 --- a/storage/innobase/fts/fts0opt.cc +++ b/storage/innobase/fts/fts0opt.cc @@ -2734,6 +2734,19 @@ static ulint fts_optimize_how_many() return(n_tables); } +/** @return innodb_ft_total_cache_size */ +static size_t fts_get_max_total_cache_size() +{ +#if UNIV_WORD_SIZE == 4 + return my_atomic_load32_explicit( + &fts_max_total_cache_size, MY_MEMORY_ORDER_RELAXED); +#else + return my_atomic_load64_explicit((volatile int64 *) + reinterpret_cast(&fts_max_total_cache_size), + MY_MEMORY_ORDER_RELAXED); +#endif +} + /**********************************************************************//** Check if the total memory used by all FTS table exceeds the maximum limit. @return true if a sync is needed, false otherwise */ @@ -2761,7 +2774,7 @@ static bool fts_is_sync_needed() total_memory += slot->table->fts->cache->total_size; } - if (total_memory > fts_max_total_cache_size) { + if (total_memory > fts_get_max_total_cache_size()) { return(true); } } diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 8ab39e85ec9..e5b18413c18 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -800,6 +800,36 @@ innodb_stopword_table_validate( for update function */ struct st_mysql_value* value); /*!< in: incoming string */ +static +void innodb_ft_cache_size_update(THD*, st_mysql_sys_var*, void*, const void* save) +{ +#if UNIV_WORD_SIZE == 4 + my_atomic_store32_explicit( + &fts_max_cache_size, *static_cast(save), + MY_MEMORY_ORDER_RELAXED); +#else + my_atomic_store64_explicit( + reinterpret_cast(&fts_max_cache_size), + *static_cast(save), + MY_MEMORY_ORDER_RELAXED); +#endif +} + +static +void innodb_ft_total_cache_size_update(THD*, st_mysql_sys_var*, void*, const void* save) +{ +#if UNIV_WORD_SIZE == 4 + my_atomic_store32_explicit( + &fts_max_total_cache_size, *static_cast(save), + MY_MEMORY_ORDER_RELAXED); +#else + my_atomic_store64_explicit( + reinterpret_cast(&fts_max_total_cache_size), + *static_cast(save), + MY_MEMORY_ORDER_RELAXED); +#endif +} + static bool is_mysql_datadir_path(const char *path); /** Validate passed-in "value" is a valid directory name. @@ -19787,15 +19817,31 @@ static MYSQL_SYSVAR_STR(ft_aux_table, innodb_ft_aux_table, "FTS internal auxiliary table to be checked", innodb_ft_aux_table_validate, NULL, NULL); -static MYSQL_SYSVAR_ULONG(ft_cache_size, fts_max_cache_size, - PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, +#if UNIV_WORD_SIZE == 4 + +static MYSQL_SYSVAR_SIZE_T(ft_cache_size, fts_max_cache_size, + PLUGIN_VAR_RQCMDARG, "InnoDB Fulltext search cache size in bytes", - NULL, NULL, 8000000, 1600000, 80000000, 0); + NULL, innodb_ft_cache_size_update, 8000000, 1600000, 1U << 29, 0); -static MYSQL_SYSVAR_ULONG(ft_total_cache_size, fts_max_total_cache_size, - PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, +static MYSQL_SYSVAR_SIZE_T(ft_total_cache_size, fts_max_total_cache_size, + PLUGIN_VAR_RQCMDARG, "Total memory allocated for InnoDB Fulltext Search cache", - NULL, NULL, 640000000, 32000000, 1600000000, 0); + NULL, innodb_ft_total_cache_size_update, 640000000, 32000000, 1600000000, 0); + +#else + +static MYSQL_SYSVAR_SIZE_T(ft_cache_size, fts_max_cache_size, + PLUGIN_VAR_RQCMDARG, + "InnoDB Fulltext search cache size in bytes", + NULL, innodb_ft_cache_size_update, 8000000, 1600000, 1ULL << 40, 0); + +static MYSQL_SYSVAR_SIZE_T(ft_total_cache_size, fts_max_total_cache_size, + PLUGIN_VAR_RQCMDARG, + "Total memory allocated for InnoDB Fulltext Search cache", + NULL, innodb_ft_total_cache_size_update, 640000000, 32000000, 1ULL << 40, 0); + +#endif static MYSQL_SYSVAR_SIZE_T(ft_result_cache_limit, fts_result_cache_limit, PLUGIN_VAR_RQCMDARG, diff --git a/storage/innobase/include/fts0fts.h b/storage/innobase/include/fts0fts.h index 0b4712c7389..7a7c13a5384 100644 --- a/storage/innobase/include/fts0fts.h +++ b/storage/innobase/include/fts0fts.h @@ -352,10 +352,10 @@ struct fts_stopword_t; extern const char* fts_default_stopword[]; /** Variable specifying the maximum FTS cache size for each table */ -extern ulong fts_max_cache_size; +extern size_t fts_max_cache_size; /** Variable specifying the total memory allocated for FTS cache */ -extern ulong fts_max_total_cache_size; +extern size_t fts_max_total_cache_size; /** Variable specifying the FTS result cache limit for each query */ extern size_t fts_result_cache_limit; -- cgit v1.2.1