103
107
static mysql_mutex_t innobase_share_mutex;
104
108
/** to force correct commit order in binlog */
105
109
static ulong commit_threads = 0;
106
static mysql_mutex_t commit_threads_m;
107
110
static mysql_cond_t commit_cond;
108
111
static mysql_mutex_t commit_cond_m;
109
112
static bool innodb_inited = 0;
221
224
/* Keys to register pthread mutexes/cond in the current file with
222
225
performance schema */
223
226
static mysql_pfs_key_t innobase_share_mutex_key;
224
static mysql_pfs_key_t commit_threads_m_key;
225
227
static mysql_pfs_key_t commit_cond_mutex_key;
226
228
static mysql_pfs_key_t commit_cond_key;
228
230
static PSI_mutex_info all_pthread_mutexes[] = {
229
{&commit_threads_m_key, "commit_threads_m", 0},
230
231
{&commit_cond_mutex_key, "commit_cond_mutex", 0},
231
232
{&innobase_share_mutex_key, "innobase_share_mutex", 0}
398
399
/*=======================*/
402
/******************************************************************//**
403
Maps a MySQL trx isolation level code to the InnoDB isolation level code
404
@return InnoDB isolation level */
407
innobase_map_isolation_level(
408
/*=========================*/
409
enum_tx_isolation iso); /*!< in: MySQL isolation level code */
401
411
static const char innobase_hton_name[]= "InnoDB";
403
413
/*************************************************************//**
765
775
/******************************************************************//**
766
Releases possible search latch and InnoDB thread FIFO ticket. These should
767
be released at each SQL statement end, and also when mysqld passes the
768
control to the client. It does no harm to release these also in the middle
769
of an SQL statement. */
776
Force a thread to leave InnoDB even if it has spare tickets. */
772
innobase_release_stat_resources(
773
/*============================*/
774
trx_t* trx) /*!< in: transaction object */
779
innodb_srv_conc_force_exit_innodb(
780
/*==============================*/
781
trx_t* trx) /*!< in: transaction handle */
776
if (trx->has_search_latch) {
777
trx_search_latch_release_if_reserved(trx);
783
#ifdef UNIV_SYNC_DEBUG
784
ut_ad(!sync_thread_levels_nonempty_trx(trx->has_search_latch));
785
#endif /* UNIV_SYNC_DEBUG */
780
787
if (trx->declared_to_be_inside_innodb) {
781
/* Release our possible ticket in the FIFO */
783
789
srv_conc_force_exit_innodb(trx);
1201
1208
strconvert(cs, from, system_charset_info, to, (uint) len, &errors);
1211
/**********************************************************************
1212
Converts an identifier from my_charset_filename to UTF-8 charset.
1213
@return result string length, as returned by strconvert() */
1216
innobase_convert_to_system_charset(
1217
/*===============================*/
1218
char* to, /* out: converted identifier */
1219
const char* from, /* in: identifier to convert */
1220
ulint len, /* in: length of 'to', in bytes */
1221
uint* errors) /* out: error return */
1223
CHARSET_INFO* cs1 = &my_charset_filename;
1224
CHARSET_INFO* cs2 = system_charset_info;
1226
return(strconvert(cs1, from, cs2, to, len, errors));
1204
1229
/******************************************************************//**
1205
1230
Compares NUL-terminated UTF-8 strings case insensitively.
1206
1231
@return 0 if a=b, <0 if a<b, >1 if a>b */
1844
1869
mutex_exit(&kernel_mutex);
1847
innobase_release_stat_resources(trx);
1872
trx_search_latch_release_if_reserved(trx);
1873
innodb_srv_conc_force_exit_innodb(trx);
1849
1875
if (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
2157
2183
/* Initialize the prebuilt struct much like it would be inited in
2158
2184
external_lock */
2160
innobase_release_stat_resources(prebuilt->trx);
2186
trx_search_latch_release_if_reserved(prebuilt->trx);
2187
innodb_srv_conc_force_exit_innodb(prebuilt->trx);
2162
2189
/* If the transaction is not started yet, start it */
2234
2261
innobase_hton->start_consistent_snapshot=innobase_start_trx_and_assign_read_view;
2235
2262
innobase_hton->flush_logs=innobase_flush_logs;
2236
2263
innobase_hton->show_status=innobase_show_status;
2237
innobase_hton->flags=HTON_NO_FLAGS;
2264
innobase_hton->flags=HTON_EXTENDED_KEYS;
2238
2265
innobase_hton->release_temporary_latches=innobase_release_temporary_latches;
2239
2266
innobase_hton->alter_table_flags = innobase_alter_table_flags;
2240
2267
innobase_hton->kill_query = innobase_kill_query;
2593
2620
mysql_mutex_init(innobase_share_mutex_key,
2594
2621
&innobase_share_mutex,
2595
2622
MY_MUTEX_INIT_FAST);
2596
mysql_mutex_init(commit_threads_m_key,
2597
&commit_threads_m, MY_MUTEX_INIT_FAST);
2598
2623
mysql_mutex_init(commit_cond_mutex_key,
2599
2624
&commit_cond_m, MY_MUTEX_INIT_FAST);
2600
2625
mysql_cond_init(commit_cond_key, &commit_cond, NULL);
2642
2667
srv_free_paths_and_sizes();
2643
2668
my_free(internal_innobase_data_file_path);
2644
2669
mysql_mutex_destroy(&innobase_share_mutex);
2645
mysql_mutex_destroy(&commit_threads_m);
2646
2670
mysql_mutex_destroy(&commit_cond_m);
2647
2671
mysql_cond_destroy(&commit_cond);
2728
2752
search latch. Since we will reserve the kernel mutex, we have to
2729
2753
release the search system latch first to obey the latching order. */
2731
innobase_release_stat_resources(trx);
2755
trx_search_latch_release_if_reserved(trx);
2756
innodb_srv_conc_force_exit_innodb(trx);
2733
2758
/* If the transaction is not started yet, start it */
2735
2760
trx_start_if_not_started(trx);
2737
/* Assign a read view if the transaction does not have it yet */
2762
/* Assign a read view if the transaction does not have it yet.
2763
Do this only if transaction is using REPEATABLE READ isolation
2765
trx->isolation_level = innobase_map_isolation_level(
2766
thd_get_trx_isolation(thd));
2739
trx_assign_read_view(trx);
2768
if (trx->isolation_level == TRX_ISO_REPEATABLE_READ) {
2769
trx_assign_read_view(trx);
2771
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2773
"InnoDB: WITH CONSISTENT SNAPSHOT "
2774
"was ignored because this phrase "
2775
"can only be used with "
2776
"REPEATABLE READ isolation level.");
2741
2779
/* Set the MySQL flag to mark that there is an active transaction */
2961
2999
reserve the kernel mutex, we have to release the search system latch
2962
3000
first to obey the latching order. */
2964
innobase_release_stat_resources(trx);
3002
trx_search_latch_release_if_reserved(trx);
3003
innodb_srv_conc_force_exit_innodb(trx);
2966
3005
trx->n_autoinc_rows = 0; /* Reset the number AUTO-INC rows required */
3001
3040
reserve the kernel mutex, we have to release the search system latch
3002
3041
first to obey the latching order. */
3004
innobase_release_stat_resources(trx);
3043
trx_search_latch_release_if_reserved(trx);
3044
innodb_srv_conc_force_exit_innodb(trx);
3006
3046
/* If we had reserved the auto-inc lock for some table (if
3007
3047
we come here to roll back the latest SQL statement) we
3041
3081
reserve the kernel mutex, we have to release the search system latch
3042
3082
first to obey the latching order. */
3044
innobase_release_stat_resources(trx);
3084
trx_search_latch_release_if_reserved(trx);
3085
innodb_srv_conc_force_exit_innodb(trx);
3046
3087
/* TODO: use provided savepoint data area to store savepoint data */
3116
3157
reserve the kernel mutex, we have to release the search system latch
3117
3158
first to obey the latching order. */
3119
innobase_release_stat_resources(trx);
3160
trx_search_latch_release_if_reserved(trx);
3161
innodb_srv_conc_force_exit_innodb(trx);
3121
3163
/* Cannot happen outside of transaction */
3122
3164
DBUG_ASSERT(trx_is_registered_for_2pc(trx));
3904
3946
ha_innobase::open(
3905
3947
/*==============*/
3906
const char* name, /*!< in: table name */
3907
int mode, /*!< in: not used */
3908
uint test_if_locked) /*!< in: not used */
3948
const char* name, /*!< in: table name */
3949
int mode, /*!< in: not used */
3950
uint test_if_locked) /*!< in: not used */
3910
dict_table_t* ib_table;
3911
char norm_name[1000];
3913
char* is_part = NULL;
3914
ibool par_case_name_set = FALSE;
3915
char par_case_name[MAX_FULL_NAME_LEN + 1];
3952
dict_table_t* ib_table;
3953
char norm_name[1000];
3955
char* is_part = NULL;
3956
ibool par_case_name_set = FALSE;
3957
char par_case_name[MAX_FULL_NAME_LEN + 1];
3958
dict_err_ignore_t ignore_err = DICT_ERR_IGNORE_NONE;
3917
3960
DBUG_ENTER("ha_innobase::open");
3949
3992
is_part = strstr(norm_name, "#P#");
3950
3993
#endif /* __WIN__ */
3995
/* Check whether FOREIGN_KEY_CHECKS is set to 0. If so, the table
3996
can be opened even if some FK indexes are missing. If not, the table
3997
can't be opened in the same situation */
3998
if (thd_test_options(thd, OPTION_NO_FOREIGN_KEY_CHECKS)) {
3999
ignore_err = DICT_ERR_IGNORE_FK_NOKEY;
3952
4002
/* Get pointer to a table object in InnoDB dictionary cache */
3953
ib_table = dict_table_get(norm_name, TRUE);
4003
ib_table = dict_table_get(norm_name, TRUE, ignore_err);
3955
4005
if (NULL == ib_table) {
7388
7438
log_buffer_flush_to_disk();
7390
innobase_table = dict_table_get(norm_name, FALSE);
7440
innobase_table = dict_table_get(norm_name, FALSE,
7441
DICT_ERR_IGNORE_NONE);
7392
7443
DBUG_ASSERT(innobase_table != 0);
7834
7885
/* There exists possibility of not being able to find requested
7835
7886
index due to inconsistency between MySQL and InoDB dictionary info.
7836
7887
Necessary message should have been printed in innobase_get_index() */
7888
if (prebuilt->table->ibd_file_missing) {
7889
n_rows = HA_POS_ERROR;
7837
7892
if (UNIV_UNLIKELY(!index)) {
7838
7893
n_rows = HA_POS_ERROR;
7839
7894
goto func_exit;
8618
8674
do additional check */
8619
8675
prebuilt->table->corrupted = FALSE;
8621
/* Enlarge the fatal lock wait timeout during CHECK TABLE. */
8622
mutex_enter(&kernel_mutex);
8623
srv_fatal_semaphore_wait_threshold += SRV_SEMAPHORE_WAIT_EXTENSION;
8624
mutex_exit(&kernel_mutex);
8626
8677
for (index = dict_table_get_first_index(prebuilt->table);
8628
8679
index = dict_table_get_next_index(index)) {
8636
8687
/* If this is an index being created, break */
8637
8688
if (*index->name == TEMP_INDEX_PREFIX) {
8639
} else if (!btr_validate_index(index, prebuilt->trx)) {
8642
innobase_format_name(
8643
index_name, sizeof index_name,
8644
prebuilt->index->name, TRUE);
8646
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
8648
"InnoDB: The B-tree of"
8649
" index %s is corrupted.",
8691
if (!(check_opt->flags & T_QUICK)) {
8692
/* Enlarge the fatal lock wait timeout during
8694
mutex_enter(&kernel_mutex);
8695
srv_fatal_semaphore_wait_threshold +=
8696
SRV_SEMAPHORE_WAIT_EXTENSION;
8697
mutex_exit(&kernel_mutex);
8700
valid = btr_validate_index(index, prebuilt->trx);
8702
/* Restore the fatal lock wait timeout after
8704
mutex_enter(&kernel_mutex);
8705
srv_fatal_semaphore_wait_threshold -=
8706
SRV_SEMAPHORE_WAIT_EXTENSION;
8707
mutex_exit(&kernel_mutex);
8712
innobase_format_name(
8713
index_name, sizeof index_name,
8715
push_warning_printf(thd,
8716
MYSQL_ERROR::WARN_LEVEL_WARN,
8718
"InnoDB: The B-tree of"
8719
" index %s is corrupted.",
8654
8726
/* Instead of invoking change_active_index(), set up
8655
8727
a dummy template for non-locking reads, disabling
8749
8824
/* Restore the original isolation level */
8750
8825
prebuilt->trx->isolation_level = old_isolation_level;
8752
/* We validate also the whole adaptive hash index for all tables
8753
at every CHECK TABLE */
8827
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
8828
/* We validate the whole adaptive hash index for all tables
8829
at every CHECK TABLE only when QUICK flag is not present. */
8755
if (!btr_search_validate()) {
8831
if (!(check_opt->flags & T_QUICK) && !btr_search_validate()) {
8756
8832
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
8757
8833
ER_NOT_KEYFILE,
8758
8834
"InnoDB: The adaptive hash index is corrupted.");
8762
/* Restore the fatal lock wait timeout after CHECK TABLE. */
8763
mutex_enter(&kernel_mutex);
8764
srv_fatal_semaphore_wait_threshold -= SRV_SEMAPHORE_WAIT_EXTENSION;
8765
mutex_exit(&kernel_mutex);
8837
#endif /* defined UNIV_AHI_DEBUG || defined UNIV_DEBUG */
8767
8838
prebuilt->trx->op_info = "";
8768
8839
if (thd_kill_level(user_thd)) {
8769
8840
my_error(ER_QUERY_INTERRUPTED, MYF(0));
9273
9344
that may not be the case. We MUST release the search latch before an
9274
9345
INSERT, for example. */
9276
innobase_release_stat_resources(trx);
9347
trx_search_latch_release_if_reserved(trx);
9348
innodb_srv_conc_force_exit_innodb(trx);
9278
9350
/* Reset the AUTOINC statement level counter for multi-row INSERTs. */
9279
9351
trx->n_autoinc_rows = 0;
9468
9540
may reserve the kernel mutex, we have to release the search
9469
9541
system latch first to obey the latching order. */
9471
innobase_release_stat_resources(trx);
9543
trx_search_latch_release_if_reserved(trx);
9544
innodb_srv_conc_force_exit_innodb(trx);
9473
9546
/* If the MySQL lock count drops to zero we know that the current SQL
9474
9547
statement has ended */
9615
9688
const long MAX_STATUS_SIZE = 1048576;
9616
9689
ulint trx_list_start = ULINT_UNDEFINED;
9617
9690
ulint trx_list_end = ULINT_UNDEFINED;
9620
9693
DBUG_ENTER("innodb_show_status");
9621
9694
DBUG_ASSERT(hton == innodb_hton_ptr);
9623
9696
trx = check_trx_exists(thd);
9625
innobase_release_stat_resources(trx);
9698
trx_search_latch_release_if_reserved(trx);
9699
innodb_srv_conc_force_exit_innodb(trx);
9627
9701
/* We let the InnoDB Monitor to output at most MAX_STATUS_SIZE
9628
9702
bytes of text. */
9680
9754
mutex_exit(&srv_monitor_file_mutex);
9682
res= stat_print(thd, innobase_hton_name,
9683
(uint) strlen(innobase_hton_name),
9684
STRING_WITH_LEN(""), str, flen);
9756
ret_val= stat_print(thd, innobase_hton_name,
9757
(uint) strlen(innobase_hton_name),
9758
STRING_WITH_LEN(""), str, flen);
9762
DBUG_RETURN(ret_val);
9691
9765
/************************************************************************//**
10623
10697
reserve the kernel mutex, we have to release the search system latch
10624
10698
first to obey the latching order. */
10626
innobase_release_stat_resources(trx);
10700
trx_search_latch_release_if_reserved(trx);
10701
innodb_srv_conc_force_exit_innodb(trx);
10628
10703
if (!trx_is_registered_for_2pc(trx) && trx_is_started(trx)) {
12110
12184
#endif /* UNIV_COMPILE_TEST_FUNCS */
12112
12186
/**********************************************************************
12113
Converts an identifier from my_charset_filename to UTF-8 charset. */
12187
Converts an identifier from my_charset_filename to UTF-8 charset.
12188
@return result string length, as returned by strconvert() */
12116
12191
innobase_convert_to_filename_charset(
12120
12195
ulint len) /* in: length of 'to', in bytes */
12124
12198
CHARSET_INFO* cs_to = &my_charset_filename;
12125
12199
CHARSET_INFO* cs_from = system_charset_info;
12127
rlen = strconvert(cs_from, from, cs_to, to, len, &errors);
12130
fprintf(stderr, "InnoDB: There was a problem in converting"
12131
"'%s' in charset %s to charset %s", from, cs_from->name,
12138
/**********************************************************************
12139
Converts an identifier from my_charset_filename to UTF-8 charset. */
12142
innobase_convert_to_system_charset(
12143
/*===============================*/
12144
char* to, /* out: converted identifier */
12145
const char* from, /* in: identifier to convert */
12146
ulint len, /* in: length of 'to', in bytes */
12147
uint* errors) /* out: error return */
12150
CHARSET_INFO* cs1 = &my_charset_filename;
12151
CHARSET_INFO* cs2 = system_charset_info;
12153
rlen = strconvert(cs1, from, cs2, to, len, errors);
12156
fprintf(stderr, "InnoDB: There was a problem in converting"
12157
"'%s' in charset %s to charset %s", from, cs1->name,
12201
return(strconvert(cs_from, from, cs_to, to, len, &errors));