Skip to content

Commit cbf5ed8

Browse files
author
Shaohua Wang
committed
Revert fix of BUG#19314480 SEGV IN FTS_OPTIMIZE_THREAD, DICT_TABLE_OPEN_ON_NAME()
OR FTS_IS_SYNC_NEEDED()
1 parent 2dbc590 commit cbf5ed8

File tree

1 file changed

+52
-91
lines changed

1 file changed

+52
-91
lines changed

storage/innobase/fts/fts0opt.cc

+52-91
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ static const ulint FTS_OPTIMIZE_INTERVAL_IN_SECS = 300;
5454
/** Server is shutting down, so does we exiting the optimize thread */
5555
static bool fts_opt_start_shutdown = false;
5656

57-
/* Event to wait for shutdown of the optimize thread */
58-
static os_event_t fts_opt_shutdown_event = NULL;
59-
6057
/** Initial size of nodes in fts_word_t. */
6158
static const ulint FTS_WORD_NODES_INIT_SIZE = 64;
6259

@@ -191,7 +188,7 @@ struct fts_encode_t {
191188
/** We use this information to determine when to start the optimize
192189
cycle for a table. */
193190
struct fts_slot_t {
194-
char* table_name; /*!< Table to optimize */
191+
dict_table_t* table; /*!< Table to optimize */
195192

196193
fts_state_t state; /*!< State of this slot */
197194

@@ -211,7 +208,7 @@ struct fts_slot_t {
211208

212209
/** A table remove message for the FTS optimize thread. */
213210
struct fts_msg_del_t {
214-
char* table_name; /*!< The table to remove */
211+
dict_table_t* table; /*!< The table to remove */
215212

216213
os_event_t event; /*!< Event to synchronize acknowledgement
217214
of receipt and processing of the
@@ -2444,31 +2441,20 @@ static __attribute__((nonnull))
24442441
dberr_t
24452442
fts_optimize_table_bk(
24462443
/*==================*/
2447-
fts_slot_t* slot) /*!< in: table to optimize */
2444+
fts_slot_t* slot) /*!< in: table to optimiza */
24482445
{
2449-
dict_table_t* table;
2446+
dberr_t error;
2447+
dict_table_t* table = slot->table;
2448+
fts_t* fts = table->fts;
24502449

24512450
/* Avoid optimizing tables that were optimized recently. */
24522451
if (slot->last_run > 0
24532452
&& (ut_time() - slot->last_run) < slot->interval_time) {
24542453

24552454
return(DB_SUCCESS);
24562455

2457-
}
2458-
2459-
table = dict_table_open_on_name(
2460-
slot->table_name, FALSE, FALSE,
2461-
DICT_ERR_IGNORE_INDEX_ROOT);
2462-
2463-
if (table == NULL) {
2464-
/* Table has been dropped. */
2465-
return(DB_SUCCESS);
2466-
}
2467-
2468-
fts_t* fts = table->fts;
2469-
dberr_t error = DB_SUCCESS;
2470-
if (fts != NULL && fts->cache != NULL
2471-
&& fts->cache->deleted >= FTS_OPTIMIZE_THRESHOLD) {
2456+
} else if (fts && fts->cache
2457+
&& fts->cache->deleted >= FTS_OPTIMIZE_THRESHOLD) {
24722458

24732459
error = fts_optimize_table(table);
24742460

@@ -2477,16 +2463,15 @@ fts_optimize_table_bk(
24772463
slot->last_run = 0;
24782464
slot->completed = ut_time();
24792465
}
2466+
} else {
2467+
error = DB_SUCCESS;
24802468
}
24812469

2482-
dict_table_close(table, FALSE, FALSE);
2483-
24842470
/* Note time this run completed. */
24852471
slot->last_run = ut_time();
24862472

24872473
return(error);
24882474
}
2489-
24902475
/*********************************************************************//**
24912476
Run OPTIMIZE on the given table.
24922477
@return DB_SUCCESS if all OK */
@@ -2617,8 +2602,10 @@ fts_optimize_add_table(
26172602
return;
26182603
}
26192604

2620-
msg = fts_optimize_create_msg(FTS_MSG_ADD_TABLE, NULL);
2621-
msg->ptr = mem_heap_strdup(msg->heap, table->name.m_name);
2605+
/* Make sure table with FTS index cannot be evicted */
2606+
dict_table_prevent_eviction(table);
2607+
2608+
msg = fts_optimize_create_msg(FTS_MSG_ADD_TABLE, table);
26222609

26232610
ib_wqueue_add(fts_optimize_wq, msg, msg->heap);
26242611
}
@@ -2637,8 +2624,7 @@ fts_optimize_do_table(
26372624
return;
26382625
}
26392626

2640-
msg = fts_optimize_create_msg(FTS_MSG_OPTIMIZE_TABLE, NULL);
2641-
msg->ptr = mem_heap_strdup(msg->heap, table->name.m_name);
2627+
msg = fts_optimize_create_msg(FTS_MSG_OPTIMIZE_TABLE, table);
26422628

26432629
ib_wqueue_add(fts_optimize_wq, msg, msg->heap);
26442630
}
@@ -2675,7 +2661,7 @@ fts_optimize_remove_table(
26752661
remove = static_cast<fts_msg_del_t*>(
26762662
mem_heap_alloc(msg->heap, sizeof(*remove)));
26772663

2678-
remove->table_name = mem_heap_strdup(msg->heap, table->name.m_name);
2664+
remove->table = table;
26792665
remove->event = event;
26802666
msg->ptr = remove;
26812667

@@ -2694,7 +2680,7 @@ fts_slot_t*
26942680
fts_optimize_find_slot(
26952681
/*===================*/
26962682
ib_vector_t* tables, /*!< in: vector of tables */
2697-
const char* name) /*!< in: table name */
2683+
const dict_table_t* table) /*!< in: table to add */
26982684
{
26992685
ulint i;
27002686

@@ -2703,7 +2689,7 @@ fts_optimize_find_slot(
27032689

27042690
slot = static_cast<fts_slot_t*>(ib_vector_get(tables, i));
27052691

2706-
if (strcmp(slot->table_name, name) == 0) {
2692+
if (slot->table->id == table->id) {
27072693
return(slot);
27082694
}
27092695
}
@@ -2718,14 +2704,14 @@ void
27182704
fts_optimize_start_table(
27192705
/*=====================*/
27202706
ib_vector_t* tables, /*!< in/out: vector of tables */
2721-
const char* name) /*!< in: table to optimize */
2707+
dict_table_t* table) /*!< in: table to optimize */
27222708
{
27232709
fts_slot_t* slot;
27242710

2725-
slot = fts_optimize_find_slot(tables, name);
2711+
slot = fts_optimize_find_slot(tables, table);
27262712

27272713
if (slot == NULL) {
2728-
ib::error() << "Table " << name << " not registered"
2714+
ib::error() << "Table " << table->name << " not registered"
27292715
" with the optimize thread.";
27302716
} else {
27312717
slot->last_run = 0;
@@ -2740,7 +2726,7 @@ ibool
27402726
fts_optimize_new_table(
27412727
/*===================*/
27422728
ib_vector_t* tables, /*!< in/out: vector of tables */
2743-
const char* name) /*!< in: table name */
2729+
dict_table_t* table) /*!< in: table to add */
27442730
{
27452731
ulint i;
27462732
fts_slot_t* slot;
@@ -2754,7 +2740,7 @@ fts_optimize_new_table(
27542740

27552741
if (slot->state == FTS_STATE_EMPTY) {
27562742
empty_slot = i;
2757-
} else if (strcmp(slot->table_name, name) == 0) {
2743+
} else if (slot->table->id == table->id) {
27582744
/* Already exists in our optimize queue. */
27592745
return(FALSE);
27602746
}
@@ -2775,7 +2761,7 @@ fts_optimize_new_table(
27752761

27762762
memset(slot, 0x0, sizeof(*slot));
27772763

2778-
slot->table_name = mem_strdup(name);
2764+
slot->table = table;
27792765
slot->state = FTS_STATE_LOADED;
27802766
slot->interval_time = FTS_OPTIMIZE_INTERVAL_IN_SECS;
27812767

@@ -2789,9 +2775,10 @@ ibool
27892775
fts_optimize_del_table(
27902776
/*===================*/
27912777
ib_vector_t* tables, /*!< in/out: vector of tables */
2792-
const char* name) /*!< in: table name */
2778+
fts_msg_del_t* msg) /*!< in: table to delete */
27932779
{
27942780
ulint i;
2781+
dict_table_t* table = msg->table;
27952782

27962783
for (i = 0; i < ib_vector_size(tables); ++i) {
27972784
fts_slot_t* slot;
@@ -2800,15 +2787,14 @@ fts_optimize_del_table(
28002787

28012788
/* FIXME: Should we assert on this ? */
28022789
if (slot->state != FTS_STATE_EMPTY
2803-
&& strcmp(slot->table_name, name) == 0) {
2790+
&& slot->table->id == table->id) {
28042791

28052792
if (fts_enable_diag_print) {
28062793
ib::info() << "FTS Optimize Removing table "
2807-
<< name;
2794+
<< table->name;
28082795
}
28092796

2810-
ut_free(slot->table_name);
2811-
slot->table_name = NULL;
2797+
slot->table = NULL;
28122798
slot->state = FTS_STATE_EMPTY;
28132799

28142800
return(TRUE);
@@ -2901,24 +2887,8 @@ fts_is_sync_needed(
29012887
slot = static_cast<const fts_slot_t*>(
29022888
ib_vector_get_const(tables, i));
29032889

2904-
if (slot->state != FTS_STATE_EMPTY) {
2905-
dict_table_t* table;
2906-
2907-
table = dict_table_open_on_name(
2908-
slot->table_name, FALSE, FALSE,
2909-
DICT_ERR_IGNORE_INDEX_ROOT);
2910-
2911-
if (table == NULL) {
2912-
/* Table has been dropped. */
2913-
continue;
2914-
}
2915-
2916-
fts_t* fts = table->fts;
2917-
if (fts != NULL && fts->cache != NULL) {
2918-
total_memory += fts->cache->total_size;
2919-
}
2920-
2921-
dict_table_close(table, FALSE, FALSE);
2890+
if (slot->table && slot->table->fts) {
2891+
total_memory += slot->table->fts->cache->total_size;
29222892
}
29232893

29242894
if (total_memory > fts_max_total_cache_size) {
@@ -2994,6 +2964,7 @@ fts_optimize_thread(
29942964
ulint current = 0;
29952965
ibool done = FALSE;
29962966
ulint n_tables = 0;
2967+
os_event_t exit_event = 0;
29972968
ulint n_optimize = 0;
29982969
ib_wqueue_t* wq = (ib_wqueue_t*) arg;
29992970

@@ -3064,38 +3035,39 @@ fts_optimize_thread(
30643035

30653036
case FTS_MSG_STOP:
30663037
done = TRUE;
3038+
exit_event = (os_event_t) msg->ptr;
30673039
break;
30683040

30693041
case FTS_MSG_ADD_TABLE:
30703042
ut_a(!done);
30713043
if (fts_optimize_new_table(
3072-
tables, static_cast<char*>(msg->ptr))) {
3044+
tables,
3045+
static_cast<dict_table_t*>(
3046+
msg->ptr))) {
30733047
++n_tables;
30743048
}
3075-
30763049
break;
30773050

30783051
case FTS_MSG_OPTIMIZE_TABLE:
30793052
if (!done) {
30803053
fts_optimize_start_table(
30813054
tables,
3082-
static_cast<char*>(msg->ptr));
3055+
static_cast<dict_table_t*>(
3056+
msg->ptr));
30833057
}
3084-
30853058
break;
30863059

30873060
case FTS_MSG_DEL_TABLE:
3088-
fts_msg_del_t* remove;
3089-
3090-
remove = static_cast<fts_msg_del_t*>(msg->ptr);
30913061
if (fts_optimize_del_table(
3092-
tables, remove->table_name)) {
3062+
tables, static_cast<fts_msg_del_t*>(
3063+
msg->ptr))) {
30933064
--n_tables;
30943065
}
30953066

30963067
/* Signal the producer that we have
30973068
removed the table. */
3098-
os_event_set(remove->event);
3069+
os_event_set(
3070+
((fts_msg_del_t*) msg->ptr)->event);
30993071
break;
31003072

31013073
default:
@@ -3112,17 +3084,6 @@ fts_optimize_thread(
31123084
}
31133085
}
31143086

3115-
/* Cleanup work queue. */
3116-
while (!ib_wqueue_is_empty(wq)) {
3117-
fts_msg_t* msg;
3118-
3119-
msg = static_cast<fts_msg_t*>(
3120-
ib_wqueue_timedwait(wq, FTS_QUEUE_WAIT_IN_USECS));
3121-
ut_a(msg != NULL);
3122-
3123-
mem_heap_free(msg->heap);
3124-
}
3125-
31263087
/* Server is being shutdown, sync the data from FTS cache to disk
31273088
if needed */
31283089
if (n_tables > 0) {
@@ -3137,24 +3098,22 @@ fts_optimize_thread(
31373098
if (slot->state != FTS_STATE_EMPTY) {
31383099
dict_table_t* table = NULL;
31393100

3140-
table = dict_table_open_on_name(
3141-
slot->table_name, FALSE, FALSE,
3101+
table = dict_table_open_on_name(
3102+
slot->table->name.m_name, FALSE, FALSE,
31423103
DICT_ERR_IGNORE_INDEX_ROOT);
31433104

3144-
if (table != NULL) {
3105+
if (table) {
31453106

31463107
if (dict_table_has_fts_index(table)) {
31473108
fts_sync_table(table);
31483109
}
31493110

3150-
if (table->fts != NULL) {
3111+
if (table->fts) {
31513112
fts_free(table);
31523113
}
31533114

31543115
dict_table_close(table, FALSE, FALSE);
31553116
}
3156-
3157-
ut_free(slot->table_name);
31583117
}
31593118
}
31603119
}
@@ -3163,7 +3122,7 @@ fts_optimize_thread(
31633122

31643123
ib::info() << "FTS optimize thread exiting.";
31653124

3166-
os_event_set(fts_opt_shutdown_event);
3125+
os_event_set(exit_event);
31673126
my_thread_end();
31683127

31693128
/* We count the number of threads in os_thread_exit(). A created
@@ -3210,6 +3169,7 @@ fts_optimize_start_shutdown(void)
32103169
ut_ad(!srv_read_only_mode);
32113170

32123171
fts_msg_t* msg;
3172+
os_event_t event;
32133173

32143174
/* If there is an ongoing activity on dictionary, such as
32153175
srv_master_evict_from_table_cache(), wait for it */
@@ -3224,15 +3184,16 @@ fts_optimize_start_shutdown(void)
32243184
/* We tell the OPTIMIZE thread to switch to state done, we
32253185
can't delete the work queue here because the add thread needs
32263186
deregister the FTS tables. */
3227-
fts_opt_shutdown_event = os_event_create(0);
3187+
event = os_event_create(0);
32283188

32293189
msg = fts_optimize_create_msg(FTS_MSG_STOP, NULL);
3190+
msg->ptr = event;
32303191

32313192
ib_wqueue_add(fts_optimize_wq, msg, msg->heap);
32323193

3233-
os_event_wait(fts_opt_shutdown_event);
3194+
os_event_wait(event);
32343195

3235-
os_event_destroy(fts_opt_shutdown_event);
3196+
os_event_destroy(event);
32363197

32373198
ib_wqueue_free(fts_optimize_wq);
32383199
}

0 commit comments

Comments
 (0)