1
1
/* ****************************************************************************
2
2
3
- Copyright (c) 2011, 2018 , Oracle and/or its affiliates. All Rights Reserved.
3
+ Copyright (c) 2011, 2019 , Oracle and/or its affiliates. All Rights Reserved.
4
4
5
5
This program is free software; you can redistribute it and/or modify it under
6
6
the terms of the GNU General Public License as published by the Free Software
@@ -3554,6 +3554,7 @@ fts_add_doc_by_id(
3554
3554
btr_pcur_store_position (doc_pcur, &mtr);
3555
3555
mtr_commit (&mtr);
3556
3556
3557
+ DEBUG_SYNC_C (" fts_instrument_sync_cache_wait" );
3557
3558
rw_lock_x_lock (&table->fts ->cache ->lock );
3558
3559
3559
3560
if (table->fts ->cache ->stopword_info .status
@@ -3576,6 +3577,13 @@ fts_add_doc_by_id(
3576
3577
3577
3578
rw_lock_x_unlock (&table->fts ->cache ->lock );
3578
3579
3580
+ DBUG_EXECUTE_IF (
3581
+ " fts_instrument_sync_cache_wait" ,
3582
+ srv_fatal_semaphore_wait_threshold = 25 ;
3583
+ fts_max_cache_size = 100 ;
3584
+ fts_sync (cache->sync , true , true , false );
3585
+ );
3586
+
3579
3587
DBUG_EXECUTE_IF (
3580
3588
" fts_instrument_sync" ,
3581
3589
fts_optimize_request_sync_table (table);
@@ -3969,13 +3977,16 @@ fts_sync_add_deleted_cache(
3969
3977
@param[in,out] trx transaction
3970
3978
@param[in] index_cache index cache
3971
3979
@param[in] unlock_cache whether unlock cache when write node
3980
+ @param[in] sync_start_time Holds the timestamp of start of sync
3981
+ for deducing the length of sync time
3972
3982
@return DB_SUCCESS if all went well else error code */
3973
3983
static MY_ATTRIBUTE ((nonnull, warn_unused_result))
3974
3984
dberr_t
3975
3985
fts_sync_write_words(
3976
3986
trx_t * trx,
3977
3987
fts_index_cache_t * index_cache,
3978
- bool unlock_cache)
3988
+ bool unlock_cache,
3989
+ ib_time_t sync_start_time)
3979
3990
{
3980
3991
fts_table_t fts_table;
3981
3992
ulint n_nodes = 0 ;
@@ -3984,6 +3995,13 @@ fts_sync_write_words(
3984
3995
dberr_t error = DB_SUCCESS;
3985
3996
ibool print_error = FALSE ;
3986
3997
dict_table_t * table = index_cache->index ->table ;
3998
+ /* We use this to deduce threshold value of time
3999
+ that we can let sync to go on holding cache lock */
4000
+ const float cutoff = 0.98 ;
4001
+ ulint lock_threshold =
4002
+ (srv_fatal_semaphore_wait_threshold % SRV_SEMAPHORE_WAIT_EXTENSION)
4003
+ * cutoff;
4004
+ bool timeout_extended = false ;
3987
4005
#ifdef FTS_DOC_STATS_DEBUG
3988
4006
ulint n_new_words = 0 ;
3989
4007
#endif /* FTS_DOC_STATS_DEBUG */
@@ -4044,6 +4062,30 @@ fts_sync_write_words(
4044
4062
4045
4063
/* FIXME: we need to handle the error properly. */
4046
4064
if (error == DB_SUCCESS) {
4065
+ DBUG_EXECUTE_IF (" fts_instrument_sync_write" ,
4066
+ os_thread_sleep (10000000 ););
4067
+
4068
+ if (!unlock_cache) {
4069
+ ulint cache_lock_time = ut_time () - sync_start_time;
4070
+ if (cache_lock_time > lock_threshold) {
4071
+ if (!timeout_extended) {
4072
+ os_atomic_increment_ulint (
4073
+ &srv_fatal_semaphore_wait_threshold,
4074
+ SRV_SEMAPHORE_WAIT_EXTENSION);
4075
+ timeout_extended = true ;
4076
+ lock_threshold +=
4077
+ SRV_SEMAPHORE_WAIT_EXTENSION;
4078
+ } else {
4079
+ unlock_cache = true ;
4080
+ os_atomic_decrement_ulint (
4081
+ &srv_fatal_semaphore_wait_threshold,
4082
+ SRV_SEMAPHORE_WAIT_EXTENSION);
4083
+ timeout_extended = false ;
4084
+
4085
+ }
4086
+ }
4087
+ }
4088
+
4047
4089
if (unlock_cache) {
4048
4090
rw_lock_x_unlock (
4049
4091
&table->fts ->cache ->lock );
@@ -4054,6 +4096,9 @@ fts_sync_write_words(
4054
4096
&index_cache->ins_graph [selected],
4055
4097
&fts_table, &word->text , fts_node);
4056
4098
4099
+ DBUG_EXECUTE_IF (" fts_instrument_sync_write" ,
4100
+ os_thread_sleep (15000000 ););
4101
+
4057
4102
DEBUG_SYNC_C (" fts_write_node" );
4058
4103
DBUG_EXECUTE_IF (" fts_write_node_crash" ,
4059
4104
DBUG_SUICIDE (););
@@ -4379,7 +4424,8 @@ fts_sync_index(
4379
4424
4380
4425
ut_ad (rbt_validate (index_cache->words ));
4381
4426
4382
- error = fts_sync_write_words (sync ->trx , index_cache, sync ->unlock_cache );
4427
+ error = fts_sync_write_words (sync ->trx , index_cache, sync ->unlock_cache ,
4428
+ sync ->start_time );
4383
4429
4384
4430
#ifdef FTS_DOC_STATS_DEBUG
4385
4431
/* FTS_RESOLVE: the word counter info in auxiliary table "DOC_ID"
@@ -4619,7 +4665,7 @@ fts_sync(
4619
4665
ut_ad (sync ->unlock_cache );
4620
4666
sync ->unlock_cache = false ;
4621
4667
}
4622
-
4668
+ DEBUG_SYNC_C ( " fts_instrument_sync " );
4623
4669
for (i = 0 ; i < ib_vector_size (cache->indexes ); ++i) {
4624
4670
fts_index_cache_t * index_cache;
4625
4671
0 commit comments