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 ++++++++++++++- 2 files changed, 45 insertions(+), 7 deletions(-) (limited to 'storage/innobase/fts') 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); } } -- cgit v1.2.1