63 #include <drizzled/error.h>
64 #include <drizzled/errmsg_print.h>
94 UNIV_INTERN uint srv_lower_case_table_names = 0;
98 UNIV_INTERN ulint srv_activity_count = 0;
101 UNIV_INTERN ulint srv_fatal_semaphore_wait_threshold = 600;
105 UNIV_INTERN ulint srv_dml_needed_delay = 0;
107 UNIV_INTERN ibool srv_lock_timeout_active = FALSE;
108 UNIV_INTERN ibool srv_monitor_active = FALSE;
109 UNIV_INTERN ibool srv_error_monitor_active = FALSE;
111 UNIV_INTERN
const char* srv_main_thread_op_info =
"";
118 UNIV_INTERN
char* srv_data_home = NULL;
119 #ifdef UNIV_LOG_ARCHIVE
120 UNIV_INTERN
char* srv_arch_dir = NULL;
133 #if DICT_TF_FORMAT_51
134 # error "DICT_TF_FORMAT_51 must be 0!"
144 UNIV_INTERN my_bool srv_use_native_aio = TRUE;
158 UNIV_INTERN ibool srv_use_native_conditions = FALSE;
161 UNIV_INTERN ulint srv_n_data_files = 0;
162 UNIV_INTERN
char** srv_data_file_names = NULL;
164 UNIV_INTERN ulint* srv_data_file_sizes = NULL;
167 UNIV_INTERN ibool srv_auto_extend_last_data_file = FALSE;
170 UNIV_INTERN ulint srv_last_file_size_max = 0;
173 UNIV_INTERN
unsigned int srv_auto_extend_increment = 8;
174 UNIV_INTERN ulint* srv_data_file_is_raw_partition = NULL;
179 UNIV_INTERN ibool srv_created_new_raw = FALSE;
181 UNIV_INTERN
char** srv_log_group_home_dirs = NULL;
183 UNIV_INTERN ulint srv_n_log_groups = ULINT_MAX;
184 UNIV_INTERN ulint srv_n_log_files = ULINT_MAX;
186 UNIV_INTERN ulint srv_log_file_size = ULINT_MAX;
188 UNIV_INTERN ulint srv_log_buffer_size = ULINT_MAX;
189 UNIV_INTERN ulong srv_flush_log_at_trx_commit = 1;
193 UNIV_INTERN
bool srv_adaptive_flushing = TRUE;
197 #define MAX_MUTEX_NOWAIT 20
203 #define MUTEX_NOWAIT(mutex_skipped) ((mutex_skipped) < MAX_MUTEX_NOWAIT)
207 #if defined(BUILD_DRIZZLE)
212 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
213 , 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
214 , 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
215 , 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
216 , 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27
217 , 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F
218 , 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
219 , 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F
220 , 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47
221 , 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F
222 , 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57
223 , 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F
224 , 0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47
225 , 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F
226 , 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57
227 , 0x58, 0x59, 0x5A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F
228 , 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87
229 , 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F
230 , 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97
231 , 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F
232 , 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7
233 , 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF
234 , 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7
235 , 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF
236 , 0x41, 0x41, 0x41, 0x41, 0x5C, 0x5B, 0x5C, 0x43
237 , 0x45, 0x45, 0x45, 0x45, 0x49, 0x49, 0x49, 0x49
238 , 0x44, 0x4E, 0x4F, 0x4F, 0x4F, 0x4F, 0x5D, 0xD7
239 , 0xD8, 0x55, 0x55, 0x55, 0x59, 0x59, 0xDE, 0xDF
240 , 0x41, 0x41, 0x41, 0x41, 0x5C, 0x5B, 0x5C, 0x43
241 , 0x45, 0x45, 0x45, 0x45, 0x49, 0x49, 0x49, 0x49
242 , 0x44, 0x4E, 0x4F, 0x4F, 0x4F, 0x4F, 0x5D, 0xF7
243 , 0xD8, 0x55, 0x55, 0x55, 0x59, 0x59, 0xDE, 0xFF
251 UNIV_INTERN my_bool srv_use_sys_malloc = TRUE;
261 UNIV_INTERN ulint srv_mem_pool_size = ULINT_MAX;
262 UNIV_INTERN ulint srv_lock_table_size = ULINT_MAX;
266 UNIV_INTERN ulint srv_n_file_io_threads = ULINT_MAX;
267 UNIV_INTERN ulint srv_n_read_io_threads = ULINT_MAX;
268 UNIV_INTERN ulint srv_n_write_io_threads = ULINT_MAX;
271 UNIV_INTERN ulint srv_page_size_shift = 0;
272 UNIV_INTERN ulint srv_page_size = 0;
275 UNIV_INTERN uint32_t srv_log_block_size = 0;
280 UNIV_INTERN ulong srv_read_ahead_threshold = 56;
282 #ifdef UNIV_LOG_ARCHIVE
283 UNIV_INTERN ibool srv_log_archive_on = FALSE;
284 UNIV_INTERN ibool srv_archive_recovery = 0;
285 UNIV_INTERN ib_uint64_t srv_archive_recovery_limit_lsn;
296 UNIV_INTERN ulong srv_insert_buffer_batch_size = 20;
298 UNIV_INTERN
char* srv_file_flush_method_str = NULL;
302 UNIV_INTERN ulint srv_max_n_open_files = 300;
305 UNIV_INTERN ulong srv_io_capacity = 200;
312 UNIV_INTERN ulong srv_max_buf_pool_modified_pct = 75;
315 UNIV_INTERN ulong srv_n_purge_threads = 0;
318 UNIV_INTERN ulong srv_purge_batch_size = 20;
321 UNIV_INTERN ulong srv_rollback_segments = TRX_SYS_N_RSEGS;
324 UNIV_INTERN ulint srv_data_read = 0;
329 ulong srv_innodb_stats_method = SRV_STATS_NULLS_EQUAL;
332 UNIV_INTERN ulint srv_data_written = 0;
335 UNIV_INTERN ulint srv_log_write_requests = 0;
338 UNIV_INTERN ulint srv_log_writes = 0;
341 UNIV_INTERN ulint srv_os_log_written = 0;
344 UNIV_INTERN ulint srv_os_log_pending_writes = 0;
348 UNIV_INTERN ulint srv_log_waits = 0;
352 UNIV_INTERN ulint srv_dblwr_writes = 0;
356 UNIV_INTERN ulint srv_dblwr_pages_written = 0;
359 UNIV_INTERN ulint srv_buf_pool_write_requests = 0;
364 UNIV_INTERN ulint srv_buf_pool_wait_free = 0;
368 UNIV_INTERN ulint srv_buf_pool_flushed = 0;
383 UNIV_INTERN ulint srv_force_recovery = 0;
389 UNIV_INTERN ulint srv_max_n_threads = 0;
399 UNIV_INTERN ulong srv_thread_concurrency = 0;
407 UNIV_INTERN lint srv_conc_n_threads = 0;
410 UNIV_INTERN ulint srv_conc_n_waiting_threads = 0;
434 #define SRV_FREE_TICKETS_TO_ENTER srv_n_free_tickets_to_enter
435 #define SRV_THREAD_SLEEP_DELAY srv_thread_sleep_delay
441 UNIV_INTERN ulint srv_fast_shutdown = 0;
444 UNIV_INTERN ibool srv_innodb_status = FALSE;
448 UNIV_INTERN ib_uint64_t srv_stats_sample_pages = 8;
450 UNIV_INTERN ibool srv_use_doublewrite_buf = TRUE;
451 UNIV_INTERN ibool srv_use_checksums = TRUE;
453 UNIV_INTERN ulong srv_replication_delay = 0;
455 UNIV_INTERN uint64_t srv_ibuf_max_size = 0;
456 UNIV_INTERN uint32_t srv_ibuf_active_contract = 0;
457 UNIV_INTERN uint32_t srv_ibuf_accel_rate = 100;
459 #define PCT_IBUF_IO(pct) (srv_io_capacity * srv_ibuf_accel_rate \
462 UNIV_INTERN uint32_t srv_checkpoint_age_target = 0;
463 UNIV_INTERN uint32_t srv_flush_neighbor_pages = 1;
465 UNIV_INTERN uint32_t srv_read_ahead = 3;
466 UNIV_INTERN uint32_t srv_adaptive_flushing_method = 0;
470 UNIV_INTERN ibool srv_read_only = FALSE;
471 UNIV_INTERN ibool srv_fake_write = FALSE;
472 UNIV_INTERN ibool srv_apply_log_only = FALSE;
475 UNIV_INTERN ulong srv_n_spin_wait_rounds = 30;
476 UNIV_INTERN ulong srv_n_free_tickets_to_enter = 500;
477 UNIV_INTERN ulong srv_thread_sleep_delay = 10000;
478 UNIV_INTERN ulong srv_spin_wait_delay = 6;
479 UNIV_INTERN ibool srv_priority_boost = TRUE;
482 UNIV_INTERN ibool srv_print_thread_releases = FALSE;
483 UNIV_INTERN ibool srv_print_lock_waits = FALSE;
484 UNIV_INTERN ibool srv_print_buf_io = FALSE;
485 UNIV_INTERN ibool srv_print_log_io = FALSE;
486 UNIV_INTERN ibool srv_print_latch_waits = FALSE;
489 UNIV_INTERN ulint srv_n_rows_inserted = 0;
490 UNIV_INTERN ulint srv_n_rows_updated = 0;
491 UNIV_INTERN ulint srv_n_rows_deleted = 0;
492 UNIV_INTERN ulint srv_n_rows_read = 0;
494 static ulint srv_n_rows_inserted_old = 0;
495 static ulint srv_n_rows_updated_old = 0;
496 static ulint srv_n_rows_deleted_old = 0;
497 static ulint srv_n_rows_read_old = 0;
499 UNIV_INTERN ulint srv_n_lock_wait_count = 0;
500 UNIV_INTERN ulint srv_n_lock_wait_current_count = 0;
501 UNIV_INTERN ib_int64_t srv_n_lock_wait_time = 0;
502 UNIV_INTERN ulint srv_n_lock_max_wait_time = 0;
504 UNIV_INTERN ulint srv_truncated_status_writes = 0;
510 UNIV_INTERN ibool srv_print_verbose_log = TRUE;
511 UNIV_INTERN ibool srv_print_innodb_monitor = FALSE;
512 UNIV_INTERN ibool srv_print_innodb_lock_monitor = FALSE;
513 UNIV_INTERN ibool srv_print_innodb_tablespace_monitor = FALSE;
514 UNIV_INTERN ibool srv_print_innodb_table_monitor = FALSE;
519 UNIV_INTERN
const char* srv_io_thread_op_info[SRV_MAX_N_IO_THREADS];
520 UNIV_INTERN
const char* srv_io_thread_function[SRV_MAX_N_IO_THREADS];
522 UNIV_INTERN time_t srv_last_monitor_time;
524 UNIV_INTERN
mutex_t srv_innodb_monitor_mutex;
527 UNIV_INTERN
mutex_t srv_monitor_file_mutex;
529 #ifdef UNIV_PFS_MUTEX
531 UNIV_INTERN mysql_pfs_key_t kernel_mutex_key;
533 UNIV_INTERN mysql_pfs_key_t commit_id_mutex_key;
535 UNIV_INTERN mysql_pfs_key_t srv_innodb_monitor_mutex_key;
537 UNIV_INTERN mysql_pfs_key_t srv_monitor_file_mutex_key;
539 UNIV_INTERN mysql_pfs_key_t srv_dict_tmpfile_mutex_key;
541 UNIV_INTERN mysql_pfs_key_t srv_misc_tmpfile_mutex_key;
545 UNIV_INTERN FILE* srv_monitor_file;
549 UNIV_INTERN
mutex_t srv_dict_tmpfile_mutex;
551 UNIV_INTERN FILE* srv_dict_tmpfile;
555 UNIV_INTERN
mutex_t srv_misc_tmpfile_mutex;
557 UNIV_INTERN FILE* srv_misc_tmpfile;
559 UNIV_INTERN ulint srv_main_thread_process_no = 0;
560 UNIV_INTERN ulint srv_main_thread_id = 0;
565 static ulint srv_main_1_second_loops = 0;
567 static ulint srv_main_sleeps = 0;
569 static ulint srv_main_10_second_loops = 0;
571 static ulint srv_main_background_loops = 0;
573 static ulint srv_main_flush_loops = 0;
575 static ulint srv_log_writes_and_flush = 0;
581 static time_t srv_last_log_flush_time;
586 #define SRV_PEND_IO_THRESHOLD (PCT_IO(3))
587 #define SRV_RECENT_IO_ACTIVITY (PCT_IO(5))
588 #define SRV_PAST_IO_ACTIVITY (PCT_IO(200))
764 unsigned suspended:1;
775 UNIV_INTERN
srv_slot_t* srv_mysql_table = NULL;
783 UNIV_INTERN
os_event_t srv_lock_timeout_thread_event;
789 UNIV_INTERN byte srv_pad1[64];
791 UNIV_INTERN
mutex_t* kernel_mutex_temp;
793 UNIV_INTERN
mutex_t* commit_id_mutex_temp;
797 UNIV_INTERN byte srv_pad2[64];
807 static ulint srv_meter_low_water[
SRV_MASTER + 1];
808 static ulint srv_meter_high_water[
SRV_MASTER + 1];
809 static ulint srv_meter_high_water2[
SRV_MASTER + 1];
810 static ulint srv_meter_foreground[
SRV_MASTER + 1];
817 srv_print_master_thread_info(
821 fprintf(file,
"srv_master_thread loops: %lu 1_second, %lu sleeps, "
822 "%lu 10_second, %lu background, %lu flush\n",
823 srv_main_1_second_loops, srv_main_sleeps,
824 srv_main_10_second_loops, srv_main_background_loops,
825 srv_main_flush_loops);
826 fprintf(file,
"srv_master_thread log flush and writes: %lu\n",
827 srv_log_writes_and_flush);
834 UNIV_INTERN ulint srv_n_threads_active[
SRV_MASTER + 1];
835 UNIV_INTERN ulint srv_n_threads[
SRV_MASTER + 1];
847 ut_a(i < SRV_MAX_N_IO_THREADS);
849 srv_io_thread_op_info[i] = str;
858 srv_table_get_nth_slot(
862 ut_ad(mutex_own(&kernel_mutex));
863 ut_a(index < OS_THREAD_MAX_N);
879 mutex_enter(&kernel_mutex);
883 n_threads += srv_n_threads[i];
886 mutex_exit(&kernel_mutex);
897 srv_thread_type_validate(
921 ut_ad(srv_thread_type_validate(type));
931 srv_table_reserve_slot(
938 ut_ad(srv_thread_type_validate(type));
939 ut_ad(mutex_own(&kernel_mutex));
942 slot = srv_table_get_nth_slot(i);
946 slot = srv_table_get_nth_slot(i);
952 ut_ad(srv_slot_get_type(slot) == type);
970 ut_ad(mutex_own(&kernel_mutex));
976 if (srv_print_thread_releases) {
978 "Suspending thread %lu to slot %lu\n",
983 type = srv_slot_get_type(slot);
987 ut_ad(srv_n_threads_active[type] > 0);
989 srv_n_threads_active[type]--;
1010 ut_ad(srv_thread_type_validate(type));
1012 ut_ad(mutex_own(&kernel_mutex));
1014 for (i = 0; i < OS_THREAD_MAX_N; i++) {
1016 slot = srv_table_get_nth_slot(i);
1019 && srv_slot_get_type(slot) == type) {
1023 srv_n_threads_active[type]++;
1027 if (srv_print_thread_releases) {
1029 "Releasing thread %lu type %lu"
1031 (ulong) slot->
id, (ulong) type,
1057 ulint slot_no = ULINT_UNDEFINED;
1059 ut_ad(srv_thread_type_validate(type));
1060 mutex_enter(&kernel_mutex);
1062 for (i = 0; i < OS_THREAD_MAX_N; i++) {
1065 slot = srv_table_get_nth_slot(i);
1067 if (slot->
in_use && slot->
type == (
unsigned int)type) {
1073 mutex_exit(&kernel_mutex);
1091 kernel_mutex_temp =
static_cast<ib_mutex_t *
>(mem_alloc(
sizeof(
mutex_t)));
1092 mutex_create(kernel_mutex_key, &kernel_mutex, SYNC_KERNEL);
1094 commit_id_mutex_temp =
static_cast<ib_mutex_t *
>(mem_alloc(
sizeof(
mutex_t)));
1095 mutex_create(commit_id_mutex_key, &commit_id_mutex, SYNC_COMMIT_ID_LOCK);
1097 mutex_create(srv_innodb_monitor_mutex_key,
1098 &srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
1102 for (i = 0; i < OS_THREAD_MAX_N; i++) {
1110 for (i = 0; i < OS_THREAD_MAX_N; i++) {
1111 slot = srv_mysql_table + i;
1125 srv_n_threads_active[i] = 0;
1126 srv_n_threads[i] = 0;
1129 srv_meter_low_water[i] = 50;
1130 srv_meter_high_water[i] = 100;
1131 srv_meter_high_water2[i] = 200;
1132 srv_meter_foreground[i] = 250;
1150 for (i = 0; i < OS_THREAD_MAX_N; i++) {
1151 conc_slot = srv_conc_slots + i;
1170 srv_conc_slots = NULL;
1177 kernel_mutex_temp = NULL;
1179 srv_mysql_table = NULL;
1182 commit_id_mutex_temp = NULL;
1206 UNIV_INTERN ulong srv_max_purge_lag = 0;
1218 ibool has_slept = FALSE;
1226 < (lint)srv_thread_concurrency,
1227 srv_replication_delay * 1000);
1235 if (trx->n_tickets_to_enter_innodb > 0) {
1236 trx->n_tickets_to_enter_innodb--;
1243 if (trx->declared_to_be_inside_innodb) {
1245 fputs(
" InnoDB: Error: trying to declare trx"
1246 " to enter InnoDB, but\n"
1247 "InnoDB: it already is declared.\n", stderr);
1255 ut_ad(srv_conc_n_threads >= 0);
1257 if (srv_conc_n_threads < (lint)srv_thread_concurrency) {
1259 srv_conc_n_threads++;
1260 trx->declared_to_be_inside_innodb = TRUE;
1261 trx->n_tickets_to_enter_innodb = SRV_FREE_TICKETS_TO_ENTER;
1271 if (!has_slept && !trx->has_search_latch
1277 srv_conc_n_waiting_threads++;
1281 trx->
op_info =
"sleeping before joining InnoDB queue";
1288 if (SRV_THREAD_SLEEP_DELAY > 0) {
1296 srv_conc_n_waiting_threads--;
1303 for (i = 0; i < OS_THREAD_MAX_N; i++) {
1304 slot = srv_conc_slots + i;
1312 if (i == OS_THREAD_MAX_N) {
1316 srv_conc_n_threads++;
1317 trx->declared_to_be_inside_innodb = TRUE;
1318 trx->n_tickets_to_enter_innodb = 0;
1326 if (trx->has_search_latch) {
1338 srv_conc_n_waiting_threads++;
1345 trx->
op_info =
"waiting in InnoDB queue";
1347 os_event_wait(slot->
event);
1353 srv_conc_n_waiting_threads--;
1362 trx->declared_to_be_inside_innodb = TRUE;
1363 trx->n_tickets_to_enter_innodb = SRV_FREE_TICKETS_TO_ENTER;
1378 if (UNIV_LIKELY(!srv_thread_concurrency)) {
1383 ut_ad(srv_conc_n_threads >= 0);
1387 srv_conc_n_threads++;
1388 trx->declared_to_be_inside_innodb = TRUE;
1389 trx->n_tickets_to_enter_innodb = 1;
1412 if (trx->declared_to_be_inside_innodb == FALSE) {
1419 ut_ad(srv_conc_n_threads > 0);
1420 srv_conc_n_threads--;
1421 trx->declared_to_be_inside_innodb = FALSE;
1422 trx->n_tickets_to_enter_innodb = 0;
1424 if (srv_conc_n_threads < (lint)srv_thread_concurrency) {
1440 srv_conc_n_threads++;
1460 if (trx->n_tickets_to_enter_innodb > 0) {
1481 srv_normalize_init_values(
void)
1487 n = srv_n_data_files;
1489 for (i = 0; i < n; i++) {
1490 srv_data_file_sizes[i] = srv_data_file_sizes[i]
1491 * ((1024 * 1024) / UNIV_PAGE_SIZE);
1494 srv_last_file_size_max = srv_last_file_size_max
1495 * ((1024 * 1024) / UNIV_PAGE_SIZE);
1497 srv_log_file_size = srv_log_file_size / UNIV_PAGE_SIZE;
1499 srv_log_buffer_size = srv_log_buffer_size / UNIV_PAGE_SIZE;
1519 err = srv_normalize_init_values();
1521 if (err != DB_SUCCESS) {
1543 srv_table_reserve_slot_for_mysql(
void)
1549 ut_ad(mutex_own(&kernel_mutex));
1552 slot = srv_mysql_table + i;
1557 if (UNIV_UNLIKELY(i >= OS_THREAD_MAX_N)) {
1562 " InnoDB: There appear to be %lu MySQL"
1563 " threads currently waiting\n"
1564 "InnoDB: inside InnoDB, which is the"
1565 " upper limit. Cannot continue operation.\n"
1566 "InnoDB: We intentionally generate"
1567 " a seg fault to print a stack trace\n"
1568 "InnoDB: on Linux. But first we print"
1569 " a list of waiting threads.\n", (ulong) i);
1571 for (i = 0; i < OS_THREAD_MAX_N; i++) {
1573 slot = srv_mysql_table + i;
1576 "Slot %lu: thread id %lu, type %lu,"
1577 " in use %lu, susp %lu, time %lu\n",
1590 slot = srv_mysql_table + i;
1619 ulint had_dict_lock;
1620 ibool was_declared_inside_innodb = FALSE;
1621 ib_int64_t start_time = 0;
1622 ib_int64_t finish_time;
1626 ulong lock_wait_timeout;
1628 ut_ad(!mutex_own(&kernel_mutex));
1634 mutex_enter(&kernel_mutex);
1638 if (thr->
state == QUE_THR_RUNNING) {
1645 if (trx->was_chosen_as_deadlock_victim) {
1648 trx->was_chosen_as_deadlock_victim = FALSE;
1651 mutex_exit(&kernel_mutex);
1658 slot = srv_table_reserve_slot_for_mysql();
1660 event = slot->
event;
1669 srv_n_lock_wait_count++;
1670 srv_n_lock_wait_current_count++;
1675 start_time = (ib_int64_t) sec * 1000000 + ms;
1682 mutex_exit(&kernel_mutex);
1684 if (trx->declared_to_be_inside_innodb) {
1686 was_declared_inside_innodb = TRUE;
1697 switch (had_dict_lock) {
1710 fputs(
" InnoDB: Error: dict X latch held in "
1711 "srv_suspend_mysql_thread\n", stderr);
1724 os_event_wait(event);
1729 switch (had_dict_lock) {
1731 row_mysql_freeze_data_dictionary(trx);
1737 row_mysql_lock_data_dictionary(trx);
1741 if (was_declared_inside_innodb) {
1748 mutex_enter(&kernel_mutex);
1760 finish_time = (ib_int64_t) sec * 1000000 + ms;
1763 diff_time = (ulint) (finish_time - start_time);
1765 srv_n_lock_wait_current_count--;
1766 srv_n_lock_wait_time = srv_n_lock_wait_time + diff_time;
1767 if (diff_time > srv_n_lock_max_wait_time &&
1770 start_time != -1 && finish_time != -1) {
1771 srv_n_lock_max_wait_time = diff_time;
1778 if (trx->was_chosen_as_deadlock_victim) {
1781 trx->was_chosen_as_deadlock_victim = FALSE;
1784 mutex_exit(&kernel_mutex);
1792 if (lock_wait_timeout < 100000000
1793 && wait_time > (
double) lock_wait_timeout) {
1817 ut_ad(mutex_own(&kernel_mutex));
1819 for (i = 0; i < OS_THREAD_MAX_N; i++) {
1821 slot = srv_mysql_table + i;
1839 srv_refresh_innodb_monitor_stats(
void)
1842 mutex_enter(&srv_innodb_monitor_mutex);
1844 srv_last_monitor_time = time(NULL);
1848 btr_cur_n_sea_old = btr_cur_n_sea;
1849 btr_cur_n_non_sea_old = btr_cur_n_non_sea;
1853 buf_refresh_io_stats_all();
1855 srv_n_rows_inserted_old = srv_n_rows_inserted;
1856 srv_n_rows_updated_old = srv_n_rows_updated;
1857 srv_n_rows_deleted_old = srv_n_rows_deleted;
1858 srv_n_rows_read_old = srv_n_rows_read;
1860 mutex_exit(&srv_innodb_monitor_mutex);
1878 double time_elapsed;
1879 time_t current_time;
1883 mutex_enter(&srv_innodb_monitor_mutex);
1885 current_time = time(NULL);
1891 time_elapsed = difftime(current_time, srv_last_monitor_time)
1894 srv_last_monitor_time = time(NULL);
1896 fputs(
"\n=====================================\n", file);
1900 " INNODB MONITOR OUTPUT\n"
1901 "=====================================\n"
1902 "Per second averages calculated from the last %lu seconds\n",
1903 (ulong)time_elapsed);
1905 fputs(
"-----------------\n"
1906 "BACKGROUND THREAD\n"
1907 "-----------------\n", file);
1908 srv_print_master_thread_info(file);
1910 fputs(
"----------\n"
1912 "----------\n", file);
1920 mutex_enter(&dict_foreign_err_mutex);
1922 if (ftell(dict_foreign_err_file) != 0L) {
1923 fputs(
"------------------------\n"
1924 "LATEST FOREIGN KEY ERROR\n"
1925 "------------------------\n", file);
1929 mutex_exit(&dict_foreign_err_mutex);
1938 long t = ftell(file);
1940 *trx_start = ULINT_UNDEFINED;
1942 *trx_start = (ulint) t;
1947 long t = ftell(file);
1949 *trx_end = ULINT_UNDEFINED;
1951 *trx_end = (ulint) t;
1958 "--------\n", file);
1961 fputs(
"-------------------------------------\n"
1962 "INSERT BUFFER AND ADAPTIVE HASH INDEX\n"
1963 "-------------------------------------\n", file);
1966 ha_print_info(file, btr_search_sys->
hash_index);
1969 "%.2f hash searches/s, %.2f non-hash searches/s\n",
1970 (btr_cur_n_sea - btr_cur_n_sea_old)
1972 (btr_cur_n_non_sea - btr_cur_n_non_sea_old)
1974 btr_cur_n_sea_old = btr_cur_n_sea;
1975 btr_cur_n_non_sea_old = btr_cur_n_non_sea;
1982 fputs(
"----------------------\n"
1983 "BUFFER POOL AND MEMORY\n"
1984 "----------------------\n", file);
1986 "Total memory allocated " ULINTPF
1987 "; in additional pool allocated " ULINTPF
"\n",
1990 fprintf(file,
"Dictionary memory allocated " ULINTPF
"\n",
1995 fputs(
"--------------\n"
1997 "--------------\n", file);
1998 fprintf(file,
"%ld queries inside InnoDB, %lu queries in queue\n",
1999 (
long) srv_conc_n_threads,
2000 (ulong) srv_conc_n_waiting_threads);
2002 fprintf(file,
"%lu read views open inside InnoDB\n",
2005 n_reserved = fil_space_get_n_reserved_extents(0);
2006 if (n_reserved > 0) {
2008 "%lu tablespace extents now reserved for"
2009 " B-tree split operations\n",
2010 (ulong) n_reserved);
2014 fprintf(file,
"Main thread process no. %lu, id %lu, state: %s\n",
2015 (ulong) srv_main_thread_process_no,
2016 (ulong) srv_main_thread_id,
2017 srv_main_thread_op_info);
2019 fprintf(file,
"Main thread id %lu, state: %s\n",
2020 (ulong) srv_main_thread_id,
2021 srv_main_thread_op_info);
2024 "Number of rows inserted " ULINTPF
2025 ", updated " ULINTPF
", deleted " ULINTPF
2026 ", read " ULINTPF
"\n",
2027 srv_n_rows_inserted,
2032 "%.2f inserts/s, %.2f updates/s,"
2033 " %.2f deletes/s, %.2f reads/s\n",
2034 (srv_n_rows_inserted - srv_n_rows_inserted_old)
2036 (srv_n_rows_updated - srv_n_rows_updated_old)
2038 (srv_n_rows_deleted - srv_n_rows_deleted_old)
2040 (srv_n_rows_read - srv_n_rows_read_old)
2043 srv_n_rows_inserted_old = srv_n_rows_inserted;
2044 srv_n_rows_updated_old = srv_n_rows_updated;
2045 srv_n_rows_deleted_old = srv_n_rows_deleted;
2046 srv_n_rows_read_old = srv_n_rows_read;
2048 fputs(
"----------------------------\n"
2049 "END OF INNODB MONITOR OUTPUT\n"
2050 "============================\n", file);
2051 mutex_exit(&srv_innodb_monitor_mutex);
2067 ulint flush_list_len;
2069 buf_get_total_stat(&stat);
2070 buf_get_total_list_len(&LRU_len, &free_len, &flush_list_len);
2072 mutex_enter(&srv_innodb_monitor_mutex);
2079 = fil_n_pending_log_flushes
2080 + fil_n_pending_tablespace_flushes;
2088 = srv_buf_pool_write_requests;
2101 = buf_get_latched_pages_number();
2107 #ifdef HAVE_ATOMIC_BUILTINS
2127 = srv_n_lock_wait_current_count;
2129 if (srv_n_lock_wait_count > 0) {
2131 (srv_n_lock_wait_time / 1000 / srv_n_lock_wait_count);
2136 = srv_n_lock_max_wait_time / 1000;
2143 mutex_exit(&srv_innodb_monitor_mutex);
2157 ib_int64_t sig_count;
2158 double time_elapsed;
2159 time_t current_time;
2160 time_t last_table_monitor_time;
2161 time_t last_tablespace_monitor_time;
2162 time_t last_monitor_time;
2163 ulint mutex_skipped;
2164 ibool last_srv_print_monitor;
2166 #ifdef UNIV_DEBUG_THREAD_CREATION
2167 fprintf(stderr,
"Lock timeout thread starts, id %lu\n",
2171 #ifdef UNIV_PFS_THREAD
2172 pfs_register_thread(srv_monitor_thread_key);
2175 srv_last_monitor_time =
ut_time();
2176 last_table_monitor_time =
ut_time();
2177 last_tablespace_monitor_time =
ut_time();
2178 last_monitor_time =
ut_time();
2180 last_srv_print_monitor = srv_print_innodb_monitor;
2182 srv_monitor_active = TRUE;
2193 time_elapsed = difftime(current_time, last_monitor_time);
2195 if (time_elapsed > 15) {
2196 last_monitor_time =
ut_time();
2198 if (srv_print_innodb_monitor) {
2204 if (!last_srv_print_monitor) {
2206 last_srv_print_monitor = TRUE;
2210 MUTEX_NOWAIT(mutex_skipped),
2218 last_srv_print_monitor = FALSE;
2222 if (srv_innodb_status) {
2223 mutex_enter(&srv_monitor_file_mutex);
2224 rewind(srv_monitor_file);
2226 MUTEX_NOWAIT(mutex_skipped),
2234 mutex_exit(&srv_monitor_file_mutex);
2237 if (srv_print_innodb_tablespace_monitor
2238 && difftime(current_time,
2239 last_tablespace_monitor_time) > 60) {
2240 last_tablespace_monitor_time =
ut_time();
2242 fputs(
"========================"
2243 "========================\n",
2248 fputs(
" INNODB TABLESPACE MONITOR OUTPUT\n"
2249 "========================"
2250 "========================\n",
2254 fputs(
"Validating tablespace\n", stderr);
2256 fputs(
"Validation ok\n"
2257 "---------------------------------------\n"
2258 "END OF INNODB TABLESPACE MONITOR OUTPUT\n"
2259 "=======================================\n",
2263 if (srv_print_innodb_table_monitor
2264 && difftime(current_time, last_table_monitor_time) > 60) {
2266 last_table_monitor_time =
ut_time();
2268 fputs(
"===========================================\n",
2273 fputs(
" INNODB TABLE MONITOR OUTPUT\n"
2274 "===========================================\n",
2278 fputs(
"-----------------------------------\n"
2279 "END OF INNODB TABLE MONITOR OUTPUT\n"
2280 "==================================\n",
2289 if (srv_print_innodb_monitor
2290 || srv_print_innodb_lock_monitor
2291 || srv_print_innodb_tablespace_monitor
2292 || srv_print_innodb_table_monitor) {
2296 srv_monitor_active = FALSE;
2301 srv_monitor_active = FALSE;
2308 OS_THREAD_DUMMY_RETURN;
2326 ib_int64_t sig_count;
2328 #ifdef UNIV_PFS_THREAD
2329 pfs_register_thread(srv_lock_timeout_thread_key);
2341 srv_lock_timeout_active = TRUE;
2343 mutex_enter(&kernel_mutex);
2350 for (i = 0; i < OS_THREAD_MAX_N; i++) {
2352 slot = srv_mysql_table + i;
2356 ulong lock_wait_timeout;
2367 || (lock_wait_timeout < 100000000
2368 && (wait_time > (
double) lock_wait_timeout
2369 || wait_time < 0))) {
2388 mutex_exit(&kernel_mutex);
2398 srv_lock_timeout_active = FALSE;
2403 os_event_wait(srv_lock_timeout_thread_event);
2408 srv_lock_timeout_active = FALSE;
2415 OS_THREAD_DUMMY_RETURN;
2431 ulint fatal_cnt = 0;
2432 ib_uint64_t old_lsn;
2433 ib_uint64_t new_lsn;
2434 ib_int64_t sig_count;
2439 const void* sema = NULL;
2440 const void* old_sema = NULL;
2444 #ifdef UNIV_DEBUG_THREAD_CREATION
2445 fprintf(stderr,
"Error monitor thread starts, id %lu\n",
2449 #ifdef UNIV_PFS_THREAD
2450 pfs_register_thread(srv_error_monitor_thread_key);
2454 srv_error_monitor_active = TRUE;
2461 if (new_lsn < old_lsn) {
2462 drizzled::errmsg_printf(drizzled::error::INFO,
2463 "InnoDB: Error: old log sequence number %"PRIu64
" was greater than the new log sequence number %"PRIu64
"!"
2464 "InnoDB: Please submit a bug report to http://bugs.launchpad.net/drizzle",
2470 if (difftime(time(NULL), srv_last_monitor_time) > 60) {
2474 srv_refresh_innodb_monitor_stats();
2479 buf_LRU_stat_update();
2482 buf_flush_stat_update();
2491 && sema == old_sema &&
os_thread_eq(waiter, old_waiter)) {
2493 if (fatal_cnt > 10) {
2496 "InnoDB: Error: semaphore wait has lasted"
2498 "InnoDB: We intentionally crash the server,"
2499 " because it appears to be hung.\n",
2500 (ulong) srv_fatal_semaphore_wait_threshold);
2506 old_waiter = waiter;
2524 srv_error_monitor_active = FALSE;
2531 OS_THREAD_DUMMY_RETURN;
2547 time_t last_dump_time;
2548 time_t time_elapsed;
2550 #ifdef UNIV_DEBUG_THREAD_CREATION
2551 fprintf(stderr,
"The LRU dump/restore thread has started, id %lu\n",
2556 buf_LRU_file_restore();
2558 last_dump_time = time(NULL);
2567 time_elapsed = time(NULL) - last_dump_time;
2569 if (auto_lru_dump > 0 && (time_t) auto_lru_dump < time_elapsed) {
2570 last_dump_time = time(NULL);
2571 buf_LRU_file_dump();
2581 OS_THREAD_DUMMY_RETURN;
2595 mutex_enter(&kernel_mutex);
2598 if (srv_n_threads_active[i] != 0) {
2604 mutex_exit(&kernel_mutex);
2620 srv_activity_count++;
2624 mutex_enter(&kernel_mutex);
2628 mutex_exit(&kernel_mutex);
2643 ut_ad(!mutex_own(&kernel_mutex));
2645 if (srv_n_purge_threads > 0
2648 mutex_enter(&kernel_mutex);
2652 mutex_exit(&kernel_mutex);
2663 srv_activity_count++;
2665 mutex_enter(&kernel_mutex);
2669 mutex_exit(&kernel_mutex);
2679 ut_ad(!mutex_own(&kernel_mutex));
2681 if (srv_n_purge_threads > 0) {
2683 mutex_enter(&kernel_mutex);
2687 mutex_exit(&kernel_mutex);
2698 srv_sync_log_buffer_in_background(
void)
2701 time_t current_time = time(NULL);
2703 srv_main_thread_op_info =
"flushing log";
2704 if (difftime(current_time, srv_last_log_flush_time) >= 1) {
2706 srv_last_log_flush_time = current_time;
2707 srv_log_writes_and_flush++;
2716 srv_master_do_purge(
void)
2719 ulint n_pages_purged = 0;
2721 ut_ad(!mutex_own(&kernel_mutex));
2723 ut_a(srv_n_purge_threads == 0);
2731 n_pages_purged =
trx_purge(srv_purge_batch_size);
2734 srv_sync_log_buffer_in_background();
2736 }
while (n_pages_purged > 0);
2752 ulint old_activity_count;
2753 ulint n_pages_purged = 0;
2754 ulint n_bytes_merged;
2755 ulint n_pages_flushed;
2756 uint32_t n_pages_flushed_prev = 0;
2757 ulint n_bytes_archived;
2758 ulint n_tables_to_drop;
2761 ulint n_ios_very_old;
2763 ulint next_itr_time;
2764 uint32_t prev_adaptive_flushing_method = ULINT32_UNDEFINED;
2765 uint32_t inner_loop = 0;
2766 bool skip_sleep =
false;
2769 struct t_prev_flush_info_struct {
2773 uint64_t oldest_modification;
2777 uint64_t oldest_lsn;
2779 #ifdef UNIV_DEBUG_THREAD_CREATION
2780 fprintf(stderr,
"Master thread starts, id %lu\n",
2784 #ifdef UNIV_PFS_THREAD
2785 pfs_register_thread(srv_master_thread_key);
2791 mutex_enter(&kernel_mutex);
2797 mutex_exit(&kernel_mutex);
2799 mutex_enter(&(log_sys->
mutex));
2800 lsn_old = log_sys->
lsn;
2801 mutex_exit(&(log_sys->
mutex));
2807 srv_main_thread_op_info =
"reserving kernel mutex";
2809 buf_get_total_stat(&buf_stat);
2812 mutex_enter(&kernel_mutex);
2815 old_activity_count = srv_activity_count;
2817 mutex_exit(&kernel_mutex);
2821 goto suspend_thread;
2827 srv_last_log_flush_time = time(NULL);
2834 for (i = 0; i < 10; i++) {
2837 n_pages_flushed = 0;
2843 srv_main_thread_op_info =
"doing background drop tables";
2847 srv_main_thread_op_info =
"";
2851 goto background_loop;
2854 buf_get_total_stat(&buf_stat);
2859 srv_main_thread_op_info =
"sleeping";
2860 srv_main_1_second_loops++;
2862 if (skip_sleep ==
false) {
2863 if (next_itr_time > cur_time
2870 (next_itr_time - cur_time)
2897 srv_sync_log_buffer_in_background();
2899 srv_main_thread_op_info =
"making checkpoint";
2906 buf_get_total_stat(&buf_stat);
2907 n_pend_ios = buf_get_n_pending_ios()
2911 if (n_pend_ios < SRV_PEND_IO_THRESHOLD
2912 && (n_ios - n_ios_old < SRV_RECENT_IO_ACTIVITY)) {
2913 srv_main_thread_op_info =
"doing insert buffer merge";
2914 ibuf_contract_for_n_pages(FALSE, PCT_IBUF_IO(5));
2917 srv_sync_log_buffer_in_background();
2920 if (UNIV_UNLIKELY(buf_get_modified_ratio_pct()
2921 > srv_max_buf_pool_modified_pct)) {
2926 srv_main_thread_op_info =
2927 "flushing buffer pool pages";
2928 n_pages_flushed = buf_flush_list(
2929 PCT_IO(100), IB_ULONGLONG_MAX);
2931 mutex_enter(&(log_sys->
mutex));
2932 lsn_old = log_sys->
lsn;
2933 mutex_exit(&(log_sys->
mutex));
2934 prev_adaptive_flushing_method = ULINT32_UNDEFINED;
2935 }
else if (srv_adaptive_flushing
2936 && srv_adaptive_flushing_method == 0) {
2941 ulint n_flush = buf_flush_get_desired_flush_rate();
2944 srv_main_thread_op_info =
2945 "flushing buffer pool pages";
2946 n_flush =
ut_min(PCT_IO(100), n_flush);
2953 mutex_enter(&(log_sys->
mutex));
2954 lsn_old = log_sys->
lsn;
2955 mutex_exit(&(log_sys->
mutex));
2956 prev_adaptive_flushing_method = ULINT32_UNDEFINED;
2957 }
else if (srv_adaptive_flushing
2958 && srv_adaptive_flushing_method == 1) {
2963 mutex_enter(&(log_sys->
mutex));
2965 oldest_lsn = buf_pool_get_oldest_modification();
2966 if (oldest_lsn == 0) {
2967 lsn_old = log_sys->
lsn;
2968 mutex_exit(&(log_sys->
mutex));
2971 if ((log_sys->
lsn - oldest_lsn)
2976 lsn_old = log_sys->
lsn;
2977 mutex_exit(&(log_sys->
mutex));
2978 }
else if ((log_sys->
lsn - oldest_lsn)
2982 uint64_t lsn = log_sys->
lsn;
2984 uint64_t level, bpl;
2988 mutex_exit(&(log_sys->
mutex));
2994 uint32_t n_blocks = 0;
3003 while (bpage != NULL) {
3005 if (oldest_modification != 0) {
3007 - (lsn - oldest_modification);
3014 bpl += ((ib_uint64_t) n_blocks * n_blocks
3015 * (lsn - lsn_old)) / level;
3020 if (!srv_use_doublewrite_buf) {
3022 bpl = (bpl * 7) / 8;
3027 n_pages_flushed = buf_flush_list(bpl,
3028 oldest_lsn + (lsn - lsn_old));
3029 if (n_pages_flushed == ULINT32_UNDEFINED) {
3031 goto retry_flush_batch;
3044 lsn_old = log_sys->
lsn;
3045 mutex_exit(&(log_sys->
mutex));
3048 prev_adaptive_flushing_method = 1;
3049 }
else if (srv_adaptive_flushing && srv_adaptive_flushing_method == 2) {
3055 mutex_enter(&(log_sys->
mutex));
3056 oldest_lsn = buf_pool_get_oldest_modification();
3058 mutex_exit(&(log_sys->
mutex));
3061 next_itr_time -= 900;
3063 if (inner_loop < 10) {
3069 if (prev_adaptive_flushing_method == 2) {
3071 int32_t blocks_sum = 0;
3072 uint32_t new_blocks_sum = 0;
3073 uint32_t flushed_blocks_sum = 0;
3077 int32_t blocks_num, new_blocks_num, flushed_blocks_num;
3086 while (bpage != NULL) {
3087 if (prev_flush_info[j].space == bpage->
space
3088 && prev_flush_info[j].offset == bpage->
offset
3089 && prev_flush_info[j].oldest_modification
3098 new_blocks_num = blocks_num;
3100 flushed_blocks_num = new_blocks_num
3101 + prev_flush_info[j].count
3103 if (flushed_blocks_num < 0) {
3104 flushed_blocks_num = 0;
3111 prev_flush_info[j].space = bpage->
space;
3112 prev_flush_info[j].offset = bpage->
offset;
3115 prev_flush_info[j].space = 0;
3116 prev_flush_info[j].offset = 0;
3117 prev_flush_info[j].oldest_modification = 0;
3120 new_blocks_sum += new_blocks_num;
3121 flushed_blocks_sum += flushed_blocks_num;
3122 blocks_sum += blocks_num;
3126 if (flushed_blocks_sum > n_pages_flushed_prev) {
3127 n_flush -= (flushed_blocks_sum - n_pages_flushed_prev);
3132 n_pages_flushed = buf_flush_list(n_flush, oldest_lsn + (lsn - lsn_old));
3134 n_pages_flushed = 0;
3145 prev_flush_info[j].space = bpage->
space;
3146 prev_flush_info[j].offset = bpage->
offset;
3149 prev_flush_info[j].space = 0;
3150 prev_flush_info[j].offset = 0;
3151 prev_flush_info[j].oldest_modification = 0;
3154 n_pages_flushed = 0;
3158 prev_adaptive_flushing_method = 2;
3160 mutex_enter(&(log_sys->
mutex));
3161 lsn_old = log_sys->
lsn;
3162 mutex_exit(&(log_sys->
mutex));
3163 prev_adaptive_flushing_method = ULINT32_UNDEFINED;
3166 if (n_pages_flushed == ULINT_UNDEFINED) {
3167 n_pages_flushed_prev = 0;
3169 n_pages_flushed_prev = n_pages_flushed;
3172 if (srv_activity_count == old_activity_count) {
3177 goto background_loop;
3184 #ifdef MEM_PERIODIC_CHECK
3187 mem_validate_all_blocks();
3198 buf_get_total_stat(&buf_stat);
3203 srv_main_10_second_loops++;
3204 if (n_pend_ios < SRV_PEND_IO_THRESHOLD
3205 && (n_ios - n_ios_very_old < SRV_PAST_IO_ACTIVITY)) {
3207 srv_main_thread_op_info =
"flushing buffer pool pages";
3208 buf_flush_list(PCT_IO(100), IB_ULONGLONG_MAX);
3211 srv_sync_log_buffer_in_background();
3217 srv_main_thread_op_info =
"doing insert buffer merge";
3218 ibuf_contract_for_n_pages(FALSE, PCT_IBUF_IO(5));
3221 srv_sync_log_buffer_in_background();
3223 if (srv_n_purge_threads == 0) {
3224 srv_main_thread_op_info =
"master purging";
3226 srv_master_do_purge();
3230 goto background_loop;
3234 srv_main_thread_op_info =
"flushing buffer pool pages";
3238 if (buf_get_modified_ratio_pct() > 70) {
3244 n_pages_flushed = buf_flush_list(
3245 PCT_IO(100), IB_ULONGLONG_MAX);
3251 n_pages_flushed = buf_flush_list(
3252 PCT_IO(10), IB_ULONGLONG_MAX);
3255 srv_main_thread_op_info =
"making checkpoint";
3261 srv_main_thread_op_info =
"reserving kernel mutex";
3263 mutex_enter(&kernel_mutex);
3268 if (srv_activity_count != old_activity_count) {
3269 mutex_exit(&kernel_mutex);
3273 mutex_exit(&kernel_mutex);
3285 srv_main_background_loops++;
3286 srv_main_thread_op_info =
"doing background drop tables";
3290 if (n_tables_to_drop > 0) {
3301 if (srv_n_purge_threads == 0) {
3302 srv_main_thread_op_info =
"master purging";
3304 srv_master_do_purge();
3307 srv_main_thread_op_info =
"reserving kernel mutex";
3309 mutex_enter(&kernel_mutex);
3310 if (srv_activity_count != old_activity_count) {
3311 mutex_exit(&kernel_mutex);
3314 mutex_exit(&kernel_mutex);
3316 srv_main_thread_op_info =
"doing insert buffer merge";
3325 n_bytes_merged = ibuf_contract_for_n_pages(FALSE,
3329 srv_main_thread_op_info =
"reserving kernel mutex";
3331 mutex_enter(&kernel_mutex);
3332 if (srv_activity_count != old_activity_count) {
3333 mutex_exit(&kernel_mutex);
3336 mutex_exit(&kernel_mutex);
3339 srv_main_thread_op_info =
"flushing buffer pool pages";
3340 srv_main_flush_loops++;
3341 if (srv_fast_shutdown < 2) {
3342 n_pages_flushed = buf_flush_list(
3343 PCT_IO(100), IB_ULONGLONG_MAX);
3348 n_pages_flushed = 0;
3351 srv_main_thread_op_info =
"reserving kernel mutex";
3353 mutex_enter(&kernel_mutex);
3354 if (srv_activity_count != old_activity_count) {
3355 mutex_exit(&kernel_mutex);
3358 mutex_exit(&kernel_mutex);
3360 srv_main_thread_op_info =
"waiting for buffer pool flush to end";
3364 srv_sync_log_buffer_in_background();
3366 srv_main_thread_op_info =
"making checkpoint";
3370 if (buf_get_modified_ratio_pct() > srv_max_buf_pool_modified_pct) {
3378 srv_main_thread_op_info =
"reserving kernel mutex";
3380 mutex_enter(&kernel_mutex);
3381 if (srv_activity_count != old_activity_count) {
3382 mutex_exit(&kernel_mutex);
3385 mutex_exit(&kernel_mutex);
3391 n_bytes_archived = 0;
3396 if (n_tables_to_drop + n_pages_flushed
3397 + n_bytes_archived != 0) {
3406 goto background_loop;
3408 }
else if (n_tables_to_drop
3409 + n_pages_purged + n_bytes_merged + n_pages_flushed
3410 + n_bytes_archived != 0) {
3414 goto background_loop;
3421 srv_main_thread_op_info =
"suspending";
3423 mutex_enter(&kernel_mutex);
3426 mutex_exit(&kernel_mutex);
3431 srv_suspend_thread(slot);
3433 mutex_exit(&kernel_mutex);
3439 srv_main_thread_op_info =
"waiting for server activity";
3441 os_event_wait(slot->
event);
3456 OS_THREAD_DUMMY_RETURN;
3471 ulint n_total_purged = ULINT_UNDEFINED;
3472 ulint next_itr_time;
3474 ut_a(srv_n_purge_threads == 1);
3476 #ifdef UNIV_DEBUG_THREAD_CREATION
3477 fprintf(stderr,
"InnoDB: Purge thread running, id %lu\n",
3481 mutex_enter(&kernel_mutex);
3487 mutex_exit(&kernel_mutex);
3493 ulint n_pages_purged;
3502 || (n_total_purged == 0
3503 && retries >= TRX_SYS_N_RSEGS)) {
3505 mutex_enter(&kernel_mutex);
3507 srv_suspend_thread(slot);
3509 mutex_exit(&kernel_mutex);
3511 os_event_wait(slot->
event);
3519 || srv_fast_shutdown) {
3524 if (n_total_purged == 0 && retries <= TRX_SYS_N_RSEGS) {
3526 }
else if (n_total_purged > 0) {
3534 n_pages_purged =
trx_purge(srv_purge_batch_size);
3536 n_total_purged += n_pages_purged;
3538 }
while (n_pages_purged > 0 && !srv_fast_shutdown);
3540 srv_sync_log_buffer_in_background();
3543 if (next_itr_time > cur_time) {
3545 (next_itr_time - cur_time)
3549 next_itr_time = cur_time + 1000;
3553 mutex_enter(&kernel_mutex);
3556 srv_suspend_thread(slot);
3560 mutex_exit(&kernel_mutex);
3562 #ifdef UNIV_DEBUG_THREAD_CREATION
3563 fprintf(stderr,
"InnoDB: Purge thread exiting, id %lu\n",
3571 OS_THREAD_DUMMY_RETURN;
3585 mutex_enter(&kernel_mutex);
3591 mutex_exit(&kernel_mutex);