Skip to content

Commit fc02ad2

Browse files
author
Shaohua Wang
committed
Merge branch 'mysql-5.6' into mysql-5.7
2 parents 9aa8e06 + 95302c1 commit fc02ad2

File tree

5 files changed

+64
-17
lines changed

5 files changed

+64
-17
lines changed

storage/innobase/fts/fts0fts.cc

+40-9
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,15 @@ FTS auxiliary INDEX table and clear the cache at the end.
213213
@param[in,out] sync sync state
214214
@param[in] unlock_cache whether unlock cache lock when write node
215215
@param[in] wait whether wait when a sync is in progress
216+
@param[in] background whether sync in background
216217
@return DB_SUCCESS if all OK */
217218
static
218219
dberr_t
219220
fts_sync(
220221
fts_sync_t* sync,
221222
bool unlock_cache,
222-
bool wait);
223+
bool wait,
224+
bool background);
223225

224226
/****************************************************************//**
225227
Release all resources help by the words rb tree e.g., the node ilist. */
@@ -1032,15 +1034,16 @@ fts_words_free(
10321034
}
10331035
}
10341036

1035-
/*********************************************************************//**
1036-
Clear cache. */
1037+
/** Clear cache.
1038+
@param[in,out] cache fts cache */
10371039
void
10381040
fts_cache_clear(
1039-
/*============*/
1040-
fts_cache_t* cache) /*!< in: cache */
1041+
fts_cache_t* cache)
10411042
{
10421043
ulint i;
10431044

1045+
rw_lock_x_lock(&cache->init_lock);
1046+
10441047
for (i = 0; i < ib_vector_size(cache->indexes); ++i) {
10451048
ulint j;
10461049
fts_index_cache_t* index_cache;
@@ -1078,6 +1081,8 @@ fts_cache_clear(
10781081
index_cache->doc_stats = NULL;
10791082
}
10801083

1084+
rw_lock_x_unlock(&cache->init_lock);
1085+
10811086
mem_heap_free(static_cast<mem_heap_t*>(cache->sync_heap->arg));
10821087
cache->sync_heap->arg = NULL;
10831088

@@ -3647,7 +3652,7 @@ fts_add_doc_by_id(
36473652

36483653
DBUG_EXECUTE_IF(
36493654
"fts_instrument_sync_debug",
3650-
fts_sync(cache->sync, true, true);
3655+
fts_sync(cache->sync, true, true, false);
36513656
);
36523657

36533658
DEBUG_SYNC_C("fts_instrument_sync_request");
@@ -4567,6 +4572,8 @@ fts_sync_rollback(
45674572
trx_t* trx = sync->trx;
45684573
fts_cache_t* cache = sync->table->fts->cache;
45694574

4575+
rw_lock_x_lock(&cache->init_lock);
4576+
45704577
for (ulint i = 0; i < ib_vector_size(cache->indexes); ++i) {
45714578
ulint j;
45724579
fts_index_cache_t* index_cache;
@@ -4596,6 +4603,7 @@ fts_sync_rollback(
45964603
}
45974604
}
45984605

4606+
rw_lock_x_unlock(&cache->init_lock);
45994607
rw_lock_x_unlock(&cache->lock);
46004608

46014609
fts_sql_rollback(trx);
@@ -4607,18 +4615,23 @@ FTS auxiliary INDEX table and clear the cache at the end.
46074615
@param[in,out] sync sync state
46084616
@param[in] unlock_cache whether unlock cache lock when write node
46094617
@param[in] wait whether wait when a sync is in progress
4618+
@param[in] has_dict whether has dict operation lock, if true,
4619+
unlock it before return.
46104620
@return DB_SUCCESS if all OK */
46114621
static
46124622
dberr_t
46134623
fts_sync(
46144624
fts_sync_t* sync,
46154625
bool unlock_cache,
4616-
bool wait)
4626+
bool wait,
4627+
bool has_dict)
46174628
{
46184629
ulint i;
46194630
dberr_t error = DB_SUCCESS;
46204631
fts_cache_t* cache = sync->table->fts->cache;
46214632

4633+
ut_ad(!(has_dict & wait));
4634+
46224635
rw_lock_x_lock(&cache->lock);
46234636

46244637
/* Check if cache is being synced.
@@ -4630,6 +4643,10 @@ fts_sync(
46304643
if (wait) {
46314644
os_event_wait(sync->event);
46324645
} else {
4646+
if (has_dict) {
4647+
rw_lock_s_unlock(dict_operation_lock);
4648+
}
4649+
46334650
return(DB_SUCCESS);
46344651
}
46354652

@@ -4688,7 +4705,15 @@ fts_sync(
46884705
end_sync:
46894706
if (error == DB_SUCCESS && !sync->interrupted) {
46904707
error = fts_sync_commit(sync);
4708+
4709+
if (has_dict) {
4710+
rw_lock_s_unlock(dict_operation_lock);
4711+
}
46914712
} else {
4713+
if (has_dict) {
4714+
rw_lock_s_unlock(dict_operation_lock);
4715+
}
4716+
46924717
fts_sync_rollback(sync);
46934718
}
46944719

@@ -4716,20 +4741,26 @@ FTS auxiliary INDEX table and clear the cache at the end.
47164741
@param[in,out] table fts table
47174742
@param[in] unlock_cache whether unlock cache when write node
47184743
@param[in] wait whether wait for existing sync to finish
4744+
@param[in] has_dict whether has dict operation lock, if true
4745+
unlock it before return
47194746
@return DB_SUCCESS on success, error code on failure. */
47204747
dberr_t
47214748
fts_sync_table(
47224749
dict_table_t* table,
47234750
bool unlock_cache,
4724-
bool wait)
4751+
bool wait,
4752+
bool has_dict)
47254753
{
47264754
dberr_t err = DB_SUCCESS;
47274755

47284756
ut_ad(table->fts);
47294757

47304758
if (!dict_table_is_discarded(table) && table->fts->cache
47314759
&& !dict_table_is_corrupted(table)) {
4732-
err = fts_sync(table->fts->cache->sync, unlock_cache, wait);
4760+
err = fts_sync(
4761+
table->fts->cache->sync, unlock_cache, wait, has_dict);
4762+
} else if (has_dict) {
4763+
rw_lock_s_unlock(dict_operation_lock);
47334764
}
47344765

47354766
return(err);

storage/innobase/fts/fts0opt.cc

+15-1
Original file line numberDiff line numberDiff line change
@@ -2958,15 +2958,29 @@ fts_optimize_sync_table(
29582958
{
29592959
dict_table_t* table = NULL;
29602960

2961+
/* Prevent DROP INDEX etc. from running when we are syncing
2962+
cache in background. */
2963+
if (!rw_lock_s_lock_nowait(dict_operation_lock, __FILE__, __LINE__)) {
2964+
/* Exit when fail to get dict operation lock. */
2965+
return;
2966+
}
2967+
2968+
bool has_dict_lock = true;
2969+
29612970
table = dict_table_open_on_id(table_id, FALSE, DICT_TABLE_OP_NORMAL);
29622971

29632972
if (table) {
29642973
if (dict_table_has_fts_index(table) && table->fts->cache) {
2965-
fts_sync_table(table, true, false);
2974+
fts_sync_table(table, true, false, true);
2975+
has_dict_lock = false;
29662976
}
29672977

29682978
dict_table_close(table, FALSE, FALSE);
29692979
}
2980+
2981+
if (has_dict_lock) {
2982+
rw_lock_s_unlock(dict_operation_lock);
2983+
}
29702984
}
29712985

29722986
/**********************************************************************//**

storage/innobase/handler/ha_innodb.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -14241,7 +14241,7 @@ ha_innobase::optimize(
1424114241
if (innodb_optimize_fulltext_only) {
1424214242
if (m_prebuilt->table->fts && m_prebuilt->table->fts->cache
1424314243
&& !dict_table_is_discarded(m_prebuilt->table)) {
14244-
fts_sync_table(m_prebuilt->table, false, true);
14244+
fts_sync_table(m_prebuilt->table, false, true, false);
1424514245
fts_optimize_table(m_prebuilt->table);
1424614246
}
1424714247
return(HA_ADMIN_OK);

storage/innobase/include/fts0fts.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -775,12 +775,11 @@ fts_cache_destroy(
775775
/*==============*/
776776
fts_cache_t* cache); /*!< in: cache*/
777777

778-
/*********************************************************************//**
779-
Clear cache. */
778+
/** Clear cache.
779+
@param[in,out] cache fts cache */
780780
void
781781
fts_cache_clear(
782-
/*============*/
783-
fts_cache_t* cache); /*!< in: cache */
782+
fts_cache_t* cache);
784783

785784
/*********************************************************************//**
786785
Initialize things in cache. */
@@ -827,12 +826,15 @@ FTS auxiliary INDEX table and clear the cache at the end.
827826
@param[in,out] table fts table
828827
@param[in] unlock_cache whether unlock cache when write node
829828
@param[in] wait whether wait for existing sync to finish
829+
@param[in] has_dict whether has dict operation lock, if true
830+
unlock it before return
830831
@return DB_SUCCESS on success, error code on failure. */
831832
dberr_t
832833
fts_sync_table(
833834
dict_table_t* table,
834835
bool unlock_cache,
835-
bool wait);
836+
bool wait,
837+
bool has_dict);
836838

837839
/****************************************************************//**
838840
Free the query graph but check whether dict_sys->mutex is already

storage/innobase/row/row0merge.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2633,7 +2633,7 @@ row_merge_read_clustered_index(
26332633
/* Sync fts cache for other fts indexes to keep all
26342634
fts indexes consistent in sync_doc_id. */
26352635
err = fts_sync_table(const_cast<dict_table_t*>(new_table),
2636-
false, true);
2636+
false, true, false);
26372637

26382638
if (err == DB_SUCCESS) {
26392639
fts_update_next_doc_id(

0 commit comments

Comments
 (0)