@@ -54,9 +54,6 @@ static const ulint FTS_OPTIMIZE_INTERVAL_IN_SECS = 300;
54
54
/* * Server is shutting down, so does we exiting the optimize thread */
55
55
static bool fts_opt_start_shutdown = false ;
56
56
57
- /* Event to wait for shutdown of the optimize thread */
58
- static os_event_t fts_opt_shutdown_event = NULL ;
59
-
60
57
/* * Initial size of nodes in fts_word_t. */
61
58
static const ulint FTS_WORD_NODES_INIT_SIZE = 64 ;
62
59
@@ -191,7 +188,7 @@ struct fts_encode_t {
191
188
/* * We use this information to determine when to start the optimize
192
189
cycle for a table. */
193
190
struct fts_slot_t {
194
- char * table_name; /* !< Table to optimize */
191
+ dict_table_t * table; /* !< Table to optimize */
195
192
196
193
fts_state_t state; /* !< State of this slot */
197
194
@@ -211,7 +208,7 @@ struct fts_slot_t {
211
208
212
209
/* * A table remove message for the FTS optimize thread. */
213
210
struct fts_msg_del_t {
214
- char * table_name; /* !< The table to remove */
211
+ dict_table_t * table; /* !< The table to remove */
215
212
216
213
os_event_t event; /* !< Event to synchronize acknowledgement
217
214
of receipt and processing of the
@@ -2444,31 +2441,20 @@ static __attribute__((nonnull))
2444
2441
dberr_t
2445
2442
fts_optimize_table_bk(
2446
2443
/* ==================*/
2447
- fts_slot_t * slot) /* !< in: table to optimize */
2444
+ fts_slot_t * slot) /* !< in: table to optimiza */
2448
2445
{
2449
- dict_table_t * table;
2446
+ dberr_t error;
2447
+ dict_table_t * table = slot->table ;
2448
+ fts_t * fts = table->fts ;
2450
2449
2451
2450
/* Avoid optimizing tables that were optimized recently. */
2452
2451
if (slot->last_run > 0
2453
2452
&& (ut_time () - slot->last_run ) < slot->interval_time ) {
2454
2453
2455
2454
return (DB_SUCCESS);
2456
2455
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) {
2472
2458
2473
2459
error = fts_optimize_table (table);
2474
2460
@@ -2477,16 +2463,15 @@ fts_optimize_table_bk(
2477
2463
slot->last_run = 0 ;
2478
2464
slot->completed = ut_time ();
2479
2465
}
2466
+ } else {
2467
+ error = DB_SUCCESS;
2480
2468
}
2481
2469
2482
- dict_table_close (table, FALSE , FALSE );
2483
-
2484
2470
/* Note time this run completed. */
2485
2471
slot->last_run = ut_time ();
2486
2472
2487
2473
return (error);
2488
2474
}
2489
-
2490
2475
/* ********************************************************************/ /* *
2491
2476
Run OPTIMIZE on the given table.
2492
2477
@return DB_SUCCESS if all OK */
@@ -2617,8 +2602,10 @@ fts_optimize_add_table(
2617
2602
return ;
2618
2603
}
2619
2604
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);
2622
2609
2623
2610
ib_wqueue_add (fts_optimize_wq, msg, msg->heap );
2624
2611
}
@@ -2637,8 +2624,7 @@ fts_optimize_do_table(
2637
2624
return ;
2638
2625
}
2639
2626
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);
2642
2628
2643
2629
ib_wqueue_add (fts_optimize_wq, msg, msg->heap );
2644
2630
}
@@ -2675,7 +2661,7 @@ fts_optimize_remove_table(
2675
2661
remove = static_cast <fts_msg_del_t *>(
2676
2662
mem_heap_alloc (msg->heap , sizeof (*remove )));
2677
2663
2678
- remove ->table_name = mem_heap_strdup (msg-> heap , table-> name . m_name ) ;
2664
+ remove ->table = table;
2679
2665
remove ->event = event;
2680
2666
msg->ptr = remove ;
2681
2667
@@ -2694,7 +2680,7 @@ fts_slot_t*
2694
2680
fts_optimize_find_slot (
2695
2681
/* ===================*/
2696
2682
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 */
2698
2684
{
2699
2685
ulint i;
2700
2686
@@ -2703,7 +2689,7 @@ fts_optimize_find_slot(
2703
2689
2704
2690
slot = static_cast <fts_slot_t *>(ib_vector_get (tables, i));
2705
2691
2706
- if (strcmp ( slot->table_name , name) == 0 ) {
2692
+ if (slot->table -> id == table-> id ) {
2707
2693
return (slot);
2708
2694
}
2709
2695
}
@@ -2718,14 +2704,14 @@ void
2718
2704
fts_optimize_start_table (
2719
2705
/* =====================*/
2720
2706
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 */
2722
2708
{
2723
2709
fts_slot_t * slot;
2724
2710
2725
- slot = fts_optimize_find_slot (tables, name );
2711
+ slot = fts_optimize_find_slot (tables, table );
2726
2712
2727
2713
if (slot == NULL ) {
2728
- ib::error () << " Table " << name << " not registered"
2714
+ ib::error () << " Table " << table-> name << " not registered"
2729
2715
" with the optimize thread." ;
2730
2716
} else {
2731
2717
slot->last_run = 0 ;
@@ -2740,7 +2726,7 @@ ibool
2740
2726
fts_optimize_new_table (
2741
2727
/* ===================*/
2742
2728
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 */
2744
2730
{
2745
2731
ulint i;
2746
2732
fts_slot_t * slot;
@@ -2754,7 +2740,7 @@ fts_optimize_new_table(
2754
2740
2755
2741
if (slot->state == FTS_STATE_EMPTY) {
2756
2742
empty_slot = i;
2757
- } else if (strcmp ( slot->table_name , name) == 0 ) {
2743
+ } else if (slot->table -> id == table-> id ) {
2758
2744
/* Already exists in our optimize queue. */
2759
2745
return (FALSE );
2760
2746
}
@@ -2775,7 +2761,7 @@ fts_optimize_new_table(
2775
2761
2776
2762
memset (slot, 0x0 , sizeof (*slot));
2777
2763
2778
- slot->table_name = mem_strdup (name) ;
2764
+ slot->table = table ;
2779
2765
slot->state = FTS_STATE_LOADED;
2780
2766
slot->interval_time = FTS_OPTIMIZE_INTERVAL_IN_SECS;
2781
2767
@@ -2789,9 +2775,10 @@ ibool
2789
2775
fts_optimize_del_table (
2790
2776
/* ===================*/
2791
2777
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 */
2793
2779
{
2794
2780
ulint i;
2781
+ dict_table_t * table = msg->table ;
2795
2782
2796
2783
for (i = 0 ; i < ib_vector_size (tables); ++i) {
2797
2784
fts_slot_t * slot;
@@ -2800,15 +2787,14 @@ fts_optimize_del_table(
2800
2787
2801
2788
/* FIXME: Should we assert on this ? */
2802
2789
if (slot->state != FTS_STATE_EMPTY
2803
- && strcmp ( slot->table_name , name) == 0 ) {
2790
+ && slot->table -> id == table-> id ) {
2804
2791
2805
2792
if (fts_enable_diag_print) {
2806
2793
ib::info () << " FTS Optimize Removing table "
2807
- << name;
2794
+ << table-> name ;
2808
2795
}
2809
2796
2810
- ut_free (slot->table_name );
2811
- slot->table_name = NULL ;
2797
+ slot->table = NULL ;
2812
2798
slot->state = FTS_STATE_EMPTY;
2813
2799
2814
2800
return (TRUE );
@@ -2901,24 +2887,8 @@ fts_is_sync_needed(
2901
2887
slot = static_cast <const fts_slot_t *>(
2902
2888
ib_vector_get_const (tables, i));
2903
2889
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 ;
2922
2892
}
2923
2893
2924
2894
if (total_memory > fts_max_total_cache_size) {
@@ -2994,6 +2964,7 @@ fts_optimize_thread(
2994
2964
ulint current = 0 ;
2995
2965
ibool done = FALSE ;
2996
2966
ulint n_tables = 0 ;
2967
+ os_event_t exit_event = 0 ;
2997
2968
ulint n_optimize = 0 ;
2998
2969
ib_wqueue_t * wq = (ib_wqueue_t *) arg;
2999
2970
@@ -3064,38 +3035,39 @@ fts_optimize_thread(
3064
3035
3065
3036
case FTS_MSG_STOP:
3066
3037
done = TRUE ;
3038
+ exit_event = (os_event_t ) msg->ptr ;
3067
3039
break ;
3068
3040
3069
3041
case FTS_MSG_ADD_TABLE:
3070
3042
ut_a (!done);
3071
3043
if (fts_optimize_new_table (
3072
- tables, static_cast <char *>(msg->ptr ))) {
3044
+ tables,
3045
+ static_cast <dict_table_t *>(
3046
+ msg->ptr ))) {
3073
3047
++n_tables;
3074
3048
}
3075
-
3076
3049
break ;
3077
3050
3078
3051
case FTS_MSG_OPTIMIZE_TABLE:
3079
3052
if (!done) {
3080
3053
fts_optimize_start_table (
3081
3054
tables,
3082
- static_cast <char *>(msg->ptr ));
3055
+ static_cast <dict_table_t *>(
3056
+ msg->ptr ));
3083
3057
}
3084
-
3085
3058
break ;
3086
3059
3087
3060
case FTS_MSG_DEL_TABLE:
3088
- fts_msg_del_t * remove ;
3089
-
3090
- remove = static_cast <fts_msg_del_t *>(msg->ptr );
3091
3061
if (fts_optimize_del_table (
3092
- tables, remove ->table_name )) {
3062
+ tables, static_cast <fts_msg_del_t *>(
3063
+ msg->ptr ))) {
3093
3064
--n_tables;
3094
3065
}
3095
3066
3096
3067
/* Signal the producer that we have
3097
3068
removed the table. */
3098
- os_event_set (remove ->event );
3069
+ os_event_set (
3070
+ ((fts_msg_del_t *) msg->ptr )->event );
3099
3071
break ;
3100
3072
3101
3073
default :
@@ -3112,17 +3084,6 @@ fts_optimize_thread(
3112
3084
}
3113
3085
}
3114
3086
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
-
3126
3087
/* Server is being shutdown, sync the data from FTS cache to disk
3127
3088
if needed */
3128
3089
if (n_tables > 0 ) {
@@ -3137,24 +3098,22 @@ fts_optimize_thread(
3137
3098
if (slot->state != FTS_STATE_EMPTY) {
3138
3099
dict_table_t * table = NULL ;
3139
3100
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 ,
3142
3103
DICT_ERR_IGNORE_INDEX_ROOT);
3143
3104
3144
- if (table != NULL ) {
3105
+ if (table) {
3145
3106
3146
3107
if (dict_table_has_fts_index (table)) {
3147
3108
fts_sync_table (table);
3148
3109
}
3149
3110
3150
- if (table->fts != NULL ) {
3111
+ if (table->fts ) {
3151
3112
fts_free (table);
3152
3113
}
3153
3114
3154
3115
dict_table_close (table, FALSE , FALSE );
3155
3116
}
3156
-
3157
- ut_free (slot->table_name );
3158
3117
}
3159
3118
}
3160
3119
}
@@ -3163,7 +3122,7 @@ fts_optimize_thread(
3163
3122
3164
3123
ib::info () << " FTS optimize thread exiting." ;
3165
3124
3166
- os_event_set (fts_opt_shutdown_event );
3125
+ os_event_set (exit_event );
3167
3126
my_thread_end ();
3168
3127
3169
3128
/* We count the number of threads in os_thread_exit(). A created
@@ -3210,6 +3169,7 @@ fts_optimize_start_shutdown(void)
3210
3169
ut_ad (!srv_read_only_mode);
3211
3170
3212
3171
fts_msg_t * msg;
3172
+ os_event_t event;
3213
3173
3214
3174
/* If there is an ongoing activity on dictionary, such as
3215
3175
srv_master_evict_from_table_cache(), wait for it */
@@ -3224,15 +3184,16 @@ fts_optimize_start_shutdown(void)
3224
3184
/* We tell the OPTIMIZE thread to switch to state done, we
3225
3185
can't delete the work queue here because the add thread needs
3226
3186
deregister the FTS tables. */
3227
- fts_opt_shutdown_event = os_event_create (0 );
3187
+ event = os_event_create (0 );
3228
3188
3229
3189
msg = fts_optimize_create_msg (FTS_MSG_STOP, NULL );
3190
+ msg->ptr = event;
3230
3191
3231
3192
ib_wqueue_add (fts_optimize_wq, msg, msg->heap );
3232
3193
3233
- os_event_wait (fts_opt_shutdown_event );
3194
+ os_event_wait (event );
3234
3195
3235
- os_event_destroy (fts_opt_shutdown_event );
3196
+ os_event_destroy (event );
3236
3197
3237
3198
ib_wqueue_free (fts_optimize_wq);
3238
3199
}
0 commit comments