71 #include "mysql/plugin.h"
75 UNIV_INTERN ulint srv_fatal_semaphore_wait_threshold = 600;
79 UNIV_INTERN ulint srv_dml_needed_delay = 0;
81 UNIV_INTERN ibool srv_monitor_active = FALSE;
82 UNIV_INTERN ibool srv_error_monitor_active = FALSE;
84 UNIV_INTERN ibool srv_buf_dump_thread_active = FALSE;
86 UNIV_INTERN ibool srv_dict_stats_thread_active = FALSE;
88 UNIV_INTERN
const char* srv_main_thread_op_info =
"";
98 UNIV_INTERN
char* srv_data_home = NULL;
110 UNIV_INTERN ulong srv_undo_logs = 1;
112 #ifdef UNIV_LOG_ARCHIVE
113 UNIV_INTERN
char* srv_arch_dir = NULL;
131 # error "UNIV_FORMAT_A must be 0!"
146 UNIV_INTERN my_bool srv_use_native_aio = TRUE;
160 UNIV_INTERN ibool srv_use_native_conditions = FALSE;
163 UNIV_INTERN ulint srv_n_data_files = 0;
164 UNIV_INTERN
char** srv_data_file_names = NULL;
166 UNIV_INTERN ulint* srv_data_file_sizes = NULL;
169 UNIV_INTERN ibool srv_auto_extend_last_data_file = FALSE;
172 UNIV_INTERN ulint srv_last_file_size_max = 0;
175 UNIV_INTERN ulong srv_auto_extend_increment = 8;
176 UNIV_INTERN ulint* srv_data_file_is_raw_partition = NULL;
181 UNIV_INTERN ibool srv_created_new_raw = FALSE;
183 UNIV_INTERN
char* srv_log_group_home_dir = NULL;
187 UNIV_INTERN ib_uint64_t srv_log_file_size = IB_UINT64_MAX;
188 UNIV_INTERN ib_uint64_t srv_log_file_size_requested;
190 UNIV_INTERN ulint srv_log_buffer_size = ULINT_MAX;
191 UNIV_INTERN ulong srv_flush_log_at_trx_commit = 1;
192 UNIV_INTERN uint srv_flush_log_at_timeout = 1;
193 UNIV_INTERN ulong srv_page_size = UNIV_PAGE_SIZE_DEF;
194 UNIV_INTERN ulong srv_page_size_shift = UNIV_PAGE_SIZE_SHIFT_DEF;
198 UNIV_INTERN
char srv_adaptive_flushing = TRUE;
202 #define MAX_MUTEX_NOWAIT 20
208 #define MUTEX_NOWAIT(mutex_skipped) ((mutex_skipped) < MAX_MUTEX_NOWAIT)
215 UNIV_INTERN my_bool srv_use_sys_malloc = TRUE;
219 UNIV_INTERN ulint srv_buf_pool_instances = 1;
229 UNIV_INTERN ulint srv_buf_pool_curr_size = 0;
231 UNIV_INTERN ulint srv_mem_pool_size = ULINT_MAX;
232 UNIV_INTERN ulint srv_lock_table_size = ULINT_MAX;
236 UNIV_INTERN ulint srv_n_file_io_threads = ULINT_MAX;
237 UNIV_INTERN ulint srv_n_read_io_threads = ULINT_MAX;
238 UNIV_INTERN ulint srv_n_write_io_threads = ULINT_MAX;
241 UNIV_INTERN my_bool srv_random_read_ahead = FALSE;
245 UNIV_INTERN ulong srv_read_ahead_threshold = 56;
247 #ifdef UNIV_LOG_ARCHIVE
248 UNIV_INTERN ibool srv_log_archive_on = FALSE;
249 UNIV_INTERN ibool srv_archive_recovery = 0;
250 UNIV_INTERN ib_uint64_t srv_archive_recovery_limit_lsn;
261 UNIV_INTERN ulong srv_insert_buffer_batch_size = 20;
263 UNIV_INTERN
char* srv_file_flush_method_str = NULL;
267 UNIV_INTERN ulint srv_max_n_open_files = 300;
270 UNIV_INTERN ulong srv_io_capacity = 200;
271 UNIV_INTERN ulong srv_max_io_capacity = 400;
278 UNIV_INTERN ulong srv_max_buf_pool_modified_pct = 75;
279 UNIV_INTERN ulong srv_max_dirty_pages_pct_lwm = 50;
283 UNIV_INTERN ulong srv_adaptive_flushing_lwm = 10;
286 UNIV_INTERN ulong srv_flushing_avg_loops = 30;
289 UNIV_INTERN ulong srv_n_purge_threads = 1;
292 UNIV_INTERN ulong srv_purge_batch_size = 20;
297 UNIV_INTERN ulong srv_innodb_stats_method = SRV_STATS_NULLS_EQUAL;
329 UNIV_INTERN ibool srv_innodb_status = FALSE;
337 UNIV_INTERN
unsigned long long srv_stats_transient_sample_pages = 8;
338 UNIV_INTERN my_bool srv_stats_persistent = TRUE;
339 UNIV_INTERN
unsigned long long srv_stats_persistent_sample_pages = 20;
340 UNIV_INTERN my_bool srv_stats_auto_recalc = TRUE;
342 UNIV_INTERN ibool srv_use_doublewrite_buf = TRUE;
350 UNIV_INTERN ulong srv_replication_delay = 0;
353 UNIV_INTERN ulong srv_n_spin_wait_rounds = 30;
354 UNIV_INTERN ulong srv_spin_wait_delay = 6;
355 UNIV_INTERN ibool srv_priority_boost = TRUE;
358 UNIV_INTERN ibool srv_print_thread_releases = FALSE;
359 UNIV_INTERN ibool srv_print_lock_waits = FALSE;
360 UNIV_INTERN ibool srv_print_buf_io = FALSE;
361 UNIV_INTERN ibool srv_print_log_io = FALSE;
362 UNIV_INTERN ibool srv_print_latch_waits = FALSE;
365 static ulint srv_n_rows_inserted_old = 0;
366 static ulint srv_n_rows_updated_old = 0;
367 static ulint srv_n_rows_deleted_old = 0;
368 static ulint srv_n_rows_read_old = 0;
370 UNIV_INTERN ulint srv_truncated_status_writes = 0;
371 UNIV_INTERN ulint srv_available_undo_logs = 0;
375 UNIV_INTERN ibool srv_print_verbose_log = TRUE;
376 UNIV_INTERN ibool srv_print_innodb_monitor = FALSE;
377 UNIV_INTERN ibool srv_print_innodb_lock_monitor = FALSE;
378 UNIV_INTERN ibool srv_print_innodb_tablespace_monitor = FALSE;
379 UNIV_INTERN ibool srv_print_innodb_table_monitor = FALSE;
384 UNIV_INTERN
const char* srv_io_thread_op_info[SRV_MAX_N_IO_THREADS];
385 UNIV_INTERN
const char* srv_io_thread_function[SRV_MAX_N_IO_THREADS];
387 UNIV_INTERN time_t srv_last_monitor_time;
389 UNIV_INTERN
ib_mutex_t srv_innodb_monitor_mutex;
392 UNIV_INTERN
ib_mutex_t srv_monitor_file_mutex;
394 #ifdef UNIV_PFS_MUTEX
395 # ifndef HAVE_ATOMIC_BUILTINS
397 UNIV_INTERN mysql_pfs_key_t server_mutex_key;
400 UNIV_INTERN mysql_pfs_key_t srv_innodb_monitor_mutex_key;
402 UNIV_INTERN mysql_pfs_key_t srv_monitor_file_mutex_key;
404 UNIV_INTERN mysql_pfs_key_t srv_dict_tmpfile_mutex_key;
406 UNIV_INTERN mysql_pfs_key_t srv_misc_tmpfile_mutex_key;
408 UNIV_INTERN mysql_pfs_key_t srv_sys_mutex_key;
410 UNIV_INTERN mysql_pfs_key_t srv_sys_tasks_mutex_key;
428 UNIV_INTERN ulint srv_main_thread_process_no = 0;
429 UNIV_INTERN ulint srv_main_thread_id = 0;
434 static ulint srv_main_active_loops = 0;
436 static ulint srv_main_idle_loops = 0;
438 static ulint srv_main_shutdown_loops = 0;
440 static ulint srv_log_writes_and_flush = 0;
446 static time_t srv_last_log_flush_time;
456 # define SRV_MASTER_CHECKPOINT_INTERVAL (7)
457 # define SRV_MASTER_PURGE_INTERVAL (10)
458 #ifdef MEM_PERIODIC_CHECK
459 # define SRV_MASTER_MEM_VALIDATE_INTERVAL (13)
461 # define SRV_MASTER_DICT_LRU_INTERVAL (47)
464 #define srv_sys_mutex_enter() do { \
465 mutex_enter(&srv_sys->mutex); \
469 #define srv_sys_mutex_own() (mutex_own(&srv_sys->mutex) \
470 && !srv_read_only_mode)
473 #define srv_sys_mutex_exit() do { \
474 mutex_exit(&srv_sys->mutex); \
477 #define fetch_lock_wait_timeout(trx) \
478 ((trx)->lock.allowed_to_wait \
479 ? thd_lock_wait_timeout((trx)->mysql_thd) \
577 #ifndef HAVE_ATOMIC_BUILTINS
599 UNIV_INTERN
char srv_buffer_pool_load_at_startup = FALSE;
602 static const ulint SRV_PURGE_SLOT = 1;
605 static const ulint SRV_MASTER_SLOT = 0;
611 srv_print_master_thread_info(
615 fprintf(file,
"srv_master_thread loops: %lu srv_active, "
616 "%lu srv_shutdown, %lu srv_idle\n",
617 srv_main_active_loops,
618 srv_main_shutdown_loops,
619 srv_main_idle_loops);
620 fprintf(file,
"srv_master_thread log flush and writes: %lu\n",
621 srv_log_writes_and_flush);
634 ut_a(i < SRV_MAX_N_IO_THREADS);
636 srv_io_thread_op_info[
i] = str;
646 for (ulint
i = 0;
i < UT_ARR_SIZE(srv_io_thread_op_info); ++
i) {
647 srv_io_thread_op_info[
i] =
"not started yet";
657 srv_thread_type_validate(
684 ut_ad(srv_thread_type_validate(type));
701 ut_ad(srv_thread_type_validate(type));
718 ut_a(slot < &srv_sys->sys_threads[
733 ut_ad(srv_slot_get_type(slot) == type);
747 srv_suspend_thread_low(
776 ut_a(srv_n_purge_threads > 1);
802 ib_int64_t sig_count = srv_suspend_thread_low(slot);
824 ut_ad(srv_thread_type_validate(type));
835 && srv_slot_get_type(slot) == type
846 ut_a(i == SRV_MASTER_SLOT);
854 ut_a(i == SRV_PURGE_SLOT);
855 ut_a(srv_n_purge_threads > 0);
860 ut_a(srv_n_purge_threads > 1);
862 < srv_n_purge_threads - 1);
895 srv_suspend_thread_low(slot);
912 ulint n_sys_threads = 0;
913 ulint srv_sys_sz =
sizeof(*srv_sys);
915 #ifndef HAVE_ATOMIC_BUILTINS
916 mutex_create(server_mutex_key, &
server_mutex, SYNC_ANY_LATCH);
919 mutex_create(srv_innodb_monitor_mutex_key,
920 &srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
925 n_sys_threads = srv_n_purge_threads + 1;
927 srv_sys_sz += n_sys_threads *
sizeof(*srv_sys->
sys_threads);
936 mutex_create(srv_sys_mutex_key, &srv_sys->
mutex, SYNC_THREADS);
938 mutex_create(srv_sys_tasks_mutex_key,
969 page_zip_stat_per_index_mutex_key,
1028 srv_normalize_init_values(
void)
1034 n = srv_n_data_files;
1036 for (i = 0; i <
n; i++) {
1037 srv_data_file_sizes[
i] = srv_data_file_sizes[
i]
1038 * ((1024 * 1024) / UNIV_PAGE_SIZE);
1041 srv_last_file_size_max = srv_last_file_size_max
1042 * ((1024 * 1024) / UNIV_PAGE_SIZE);
1044 srv_log_file_size = srv_log_file_size / UNIV_PAGE_SIZE;
1046 srv_log_buffer_size = srv_log_buffer_size / UNIV_PAGE_SIZE;
1061 srv_normalize_init_values();
1078 srv_refresh_innodb_monitor_stats(
void)
1081 mutex_enter(&srv_innodb_monitor_mutex);
1083 srv_last_monitor_time = time(NULL);
1099 mutex_exit(&srv_innodb_monitor_mutex);
1113 ulint* trx_start_pos,
1118 double time_elapsed;
1119 time_t current_time;
1123 mutex_enter(&srv_innodb_monitor_mutex);
1125 current_time = time(NULL);
1131 time_elapsed = difftime(current_time, srv_last_monitor_time)
1134 srv_last_monitor_time = time(NULL);
1136 fputs(
"\n=====================================\n", file);
1140 " INNODB MONITOR OUTPUT\n"
1141 "=====================================\n"
1142 "Per second averages calculated from the last %lu seconds\n",
1143 (ulong) time_elapsed);
1145 fputs(
"-----------------\n"
1146 "BACKGROUND THREAD\n"
1147 "-----------------\n", file);
1148 srv_print_master_thread_info(file);
1150 fputs(
"----------\n"
1152 "----------\n", file);
1160 mutex_enter(&dict_foreign_err_mutex);
1163 fputs(
"------------------------\n"
1164 "LATEST FOREIGN KEY ERROR\n"
1165 "------------------------\n", file);
1169 mutex_exit(&dict_foreign_err_mutex);
1178 if (trx_start_pos) {
1179 long t = ftell(file);
1181 *trx_start_pos = ULINT_UNDEFINED;
1183 *trx_start_pos = (ulint) t;
1194 long t = ftell(file);
1196 *trx_end = ULINT_UNDEFINED;
1198 *trx_end = (ulint) t;
1205 "--------\n", file);
1208 fputs(
"-------------------------------------\n"
1209 "INSERT BUFFER AND ADAPTIVE HASH INDEX\n"
1210 "-------------------------------------\n", file);
1216 "%.2f hash searches/s, %.2f non-hash searches/s\n",
1229 fputs(
"----------------------\n"
1230 "BUFFER POOL AND MEMORY\n"
1231 "----------------------\n", file);
1233 "Total memory allocated " ULINTPF
1234 "; in additional pool allocated " ULINTPF
"\n",
1237 fprintf(file,
"Dictionary memory allocated " ULINTPF
"\n",
1242 fputs(
"--------------\n"
1244 "--------------\n", file);
1245 fprintf(file,
"%ld queries inside InnoDB, %lu queries in queue\n",
1250 fprintf(file,
"%lu read views open inside InnoDB\n",
1254 if (n_reserved > 0) {
1256 "%lu tablespace extents now reserved for"
1257 " B-tree split operations\n",
1258 (ulong) n_reserved);
1262 fprintf(file,
"Main thread process no. %lu, id %lu, state: %s\n",
1263 (ulong) srv_main_thread_process_no,
1264 (ulong) srv_main_thread_id,
1265 srv_main_thread_op_info);
1267 fprintf(file,
"Main thread id %lu, state: %s\n",
1268 (ulong) srv_main_thread_id,
1269 srv_main_thread_op_info);
1272 "Number of rows inserted " ULINTPF
1273 ", updated " ULINTPF
", deleted " ULINTPF
1274 ", read " ULINTPF
"\n",
1280 "%.2f inserts/s, %.2f updates/s,"
1281 " %.2f deletes/s, %.2f reads/s\n",
1296 fputs(
"----------------------------\n"
1297 "END OF INNODB MONITOR OUTPUT\n"
1298 "============================\n", file);
1299 mutex_exit(&srv_innodb_monitor_mutex);
1316 ulint flush_list_len;
1322 mutex_enter(&srv_innodb_monitor_mutex);
1381 buf_get_latched_pages_number();
1388 #ifdef HAVE_ATOMIC_BUILTINS
1452 srv_truncated_status_writes;
1468 if (!done_trx_no || max_trx_id < done_trx_no - 1) {
1472 (ulint) (max_trx_id - done_trx_no + 1);
1476 || max_trx_id < up_limit_id) {
1480 (ulint) (max_trx_id - up_limit_id);
1484 mutex_exit(&srv_innodb_monitor_mutex);
1490 extern "C" UNIV_INTERN
1494 void* arg __attribute__((unused)))
1498 ib_int64_t sig_count;
1499 double time_elapsed;
1500 time_t current_time;
1501 time_t last_table_monitor_time;
1502 time_t last_tablespace_monitor_time;
1503 time_t last_monitor_time;
1504 ulint mutex_skipped;
1505 ibool last_srv_print_monitor;
1509 #ifdef UNIV_DEBUG_THREAD_CREATION
1510 fprintf(stderr,
"Lock timeout thread starts, id %lu\n",
1514 #ifdef UNIV_PFS_THREAD
1515 pfs_register_thread(srv_monitor_thread_key);
1517 srv_monitor_active = TRUE;
1520 srv_last_monitor_time =
ut_time();
1521 last_table_monitor_time =
ut_time();
1522 last_tablespace_monitor_time =
ut_time();
1523 last_monitor_time =
ut_time();
1525 last_srv_print_monitor = srv_print_innodb_monitor;
1536 time_elapsed = difftime(current_time, last_monitor_time);
1538 if (time_elapsed > 15) {
1539 last_monitor_time =
ut_time();
1541 if (srv_print_innodb_monitor) {
1547 if (!last_srv_print_monitor) {
1549 last_srv_print_monitor = TRUE;
1561 last_srv_print_monitor = FALSE;
1569 mutex_enter(&srv_monitor_file_mutex);
1580 mutex_exit(&srv_monitor_file_mutex);
1583 if (srv_print_innodb_tablespace_monitor
1584 && difftime(current_time,
1585 last_tablespace_monitor_time) > 60) {
1586 last_tablespace_monitor_time =
ut_time();
1588 fputs(
"========================"
1589 "========================\n",
1594 fputs(
" INNODB TABLESPACE MONITOR OUTPUT\n"
1595 "========================"
1596 "========================\n",
1600 fputs(
"Validating tablespace\n", stderr);
1602 fputs(
"Validation ok\n"
1603 "---------------------------------------\n"
1604 "END OF INNODB TABLESPACE MONITOR OUTPUT\n"
1605 "=======================================\n",
1609 if (srv_print_innodb_table_monitor
1610 && difftime(current_time, last_table_monitor_time) > 60) {
1612 last_table_monitor_time =
ut_time();
1614 fprintf(stderr,
"Warning: %s\n",
1615 DEPRECATED_MSG_INNODB_TABLE_MONITOR);
1617 fputs(
"===========================================\n",
1622 fputs(
" INNODB TABLE MONITOR OUTPUT\n"
1623 "===========================================\n",
1627 fputs(
"-----------------------------------\n"
1628 "END OF INNODB TABLE MONITOR OUTPUT\n"
1629 "==================================\n",
1632 fprintf(stderr,
"Warning: %s\n",
1633 DEPRECATED_MSG_INNODB_TABLE_MONITOR);
1641 if (srv_print_innodb_monitor
1642 || srv_print_innodb_lock_monitor
1643 || srv_print_innodb_tablespace_monitor
1644 || srv_print_innodb_table_monitor) {
1651 srv_monitor_active = FALSE;
1658 OS_THREAD_DUMMY_RETURN;
1665 extern "C" UNIV_INTERN
1669 void* arg __attribute__((unused)))
1674 ulint fatal_cnt = 0;
1677 ib_int64_t sig_count;
1682 const void* sema = NULL;
1683 const void* old_sema = NULL;
1689 #ifdef UNIV_DEBUG_THREAD_CREATION
1690 fprintf(stderr,
"Error monitor thread starts, id %lu\n",
1694 #ifdef UNIV_PFS_THREAD
1695 pfs_register_thread(srv_error_monitor_thread_key);
1697 srv_error_monitor_active = TRUE;
1705 if (new_lsn < old_lsn) {
1708 " InnoDB: Error: old log sequence number " LSN_PF
1710 "InnoDB: than the new log sequence number " LSN_PF
"!\n"
1711 "InnoDB: Please submit a bug report"
1712 " to http://bugs.mysql.com\n",
1719 if (difftime(time(NULL), srv_last_monitor_time) > 60) {
1723 srv_refresh_innodb_monitor_stats();
1737 && sema == old_sema &&
os_thread_eq(waiter, old_waiter)) {
1739 if (fatal_cnt > 10) {
1742 "InnoDB: Error: semaphore wait has lasted"
1744 "InnoDB: We intentionally crash the server,"
1745 " because it appears to be hung.\n",
1746 (ulong) srv_fatal_semaphore_wait_threshold);
1752 old_waiter = waiter;
1770 srv_error_monitor_active = FALSE;
1777 OS_THREAD_DUMMY_RETURN;
1838 const char* thread_active = NULL;
1842 }
else if (srv_error_monitor_active) {
1843 thread_active =
"srv_error_monitor_thread";
1845 thread_active =
"srv_lock_timeout thread";
1846 }
else if (srv_monitor_active) {
1847 thread_active =
"srv_monitor_thread";
1848 }
else if (srv_buf_dump_thread_active) {
1849 thread_active =
"buf_dump_thread";
1850 }
else if (srv_dict_stats_thread_active) {
1851 thread_active =
"dict_stats_thread";
1860 return(thread_active);
1892 ut_a(srv_slot_get_type(slot) == SRV_MASTER);
1961 ulint old_activity_count)
1973 srv_sync_log_buffer_in_background(
void)
1976 time_t current_time = time(NULL);
1978 srv_main_thread_op_info =
"flushing log";
1979 if (difftime(current_time, srv_last_log_flush_time)
1980 >= srv_flush_log_at_timeout) {
1982 srv_last_log_flush_time = current_time;
1983 srv_log_writes_and_flush++;
1992 srv_master_evict_from_table_cache(
1996 ulint n_tables_evicted = 0;
2009 return(n_tables_evicted);
2017 srv_shutdown_print_master_pending(
2021 ulint n_tables_to_drop,
2023 ulint n_bytes_merged)
2027 double time_elapsed;
2030 time_elapsed =
ut_difftime(current_time, *last_print_time);
2032 if (time_elapsed > 60) {
2035 if (n_tables_to_drop) {
2037 fprintf(stderr,
" InnoDB: Waiting for "
2038 "%lu table(s) to be dropped\n",
2039 (ulong) n_tables_to_drop);
2046 fprintf(stderr,
" InnoDB: Waiting for change "
2047 "buffer merge to complete\n"
2048 " InnoDB: number of bytes of change buffer "
2049 "just merged: %lu\n",
2064 srv_master_do_active_tasks(
void)
2073 ++srv_main_active_loops;
2080 srv_main_thread_op_info =
"doing background drop tables";
2083 MONITOR_SRV_BACKGROUND_DROP_TABLE_MICROSECOND, counter_time);
2091 srv_main_thread_op_info =
"checking free log space";
2095 srv_main_thread_op_info =
"doing insert buffer merge";
2099 MONITOR_SRV_IBUF_MERGE_MICROSECOND, counter_time);
2102 srv_main_thread_op_info =
"flushing log";
2103 srv_sync_log_buffer_in_background();
2105 MONITOR_SRV_LOG_FLUSH_MICROSECOND, counter_time);
2110 #ifdef MEM_PERIODIC_CHECK
2113 if (cur_time % SRV_MASTER_MEM_VALIDATE_INTERVAL == 0) {
2114 mem_validate_all_blocks();
2116 MONITOR_SRV_MEM_VALIDATE_MICROSECOND, counter_time);
2127 if (cur_time % SRV_MASTER_DICT_LRU_INTERVAL == 0) {
2128 srv_main_thread_op_info =
"enforcing dict cache limit";
2129 srv_master_evict_from_table_cache(50);
2131 MONITOR_SRV_DICT_LRU_MICROSECOND, counter_time);
2139 if (cur_time % SRV_MASTER_CHECKPOINT_INTERVAL == 0) {
2140 srv_main_thread_op_info =
"making checkpoint";
2143 MONITOR_SRV_CHECKPOINT_MICROSECOND, counter_time);
2157 srv_master_do_idle_tasks(
void)
2160 ullint counter_time;
2162 ++srv_main_idle_loops;
2171 srv_main_thread_op_info =
"doing background drop tables";
2174 MONITOR_SRV_BACKGROUND_DROP_TABLE_MICROSECOND,
2183 srv_main_thread_op_info =
"checking free log space";
2188 srv_main_thread_op_info =
"doing insert buffer merge";
2191 MONITOR_SRV_IBUF_MERGE_MICROSECOND, counter_time);
2197 srv_main_thread_op_info =
"enforcing dict cache limit";
2198 srv_master_evict_from_table_cache(100);
2200 MONITOR_SRV_DICT_LRU_MICROSECOND, counter_time);
2203 srv_sync_log_buffer_in_background();
2205 MONITOR_SRV_LOG_FLUSH_MICROSECOND, counter_time);
2212 srv_main_thread_op_info =
"making checkpoint";
2228 srv_master_do_shutdown_tasks(
2233 ulint n_bytes_merged = 0;
2234 ulint n_tables_to_drop = 0;
2238 ++srv_main_shutdown_loops;
2250 srv_main_thread_op_info =
"doing background drop tables";
2255 srv_main_thread_op_info =
"checking free log space";
2264 srv_main_thread_op_info =
"doing insert buffer merge";
2268 srv_sync_log_buffer_in_background();
2272 srv_main_thread_op_info =
"making checkpoint";
2277 srv_shutdown_print_master_pending(
2278 last_print_time, n_tables_to_drop, n_bytes_merged);
2281 return(n_bytes_merged || n_tables_to_drop);
2290 srv_master_sleep(
void)
2293 srv_main_thread_op_info =
"sleeping";
2295 srv_main_thread_op_info =
"";
2301 extern "C" UNIV_INTERN
2305 void* arg __attribute__((unused)))
2315 #ifdef UNIV_DEBUG_THREAD_CREATION
2316 fprintf(stderr,
"Master thread starts, id %lu\n",
2320 #ifdef UNIV_PFS_THREAD
2321 pfs_register_thread(srv_master_thread_key);
2327 slot = srv_reserve_slot(SRV_MASTER);
2333 goto suspend_thread;
2344 srv_master_do_active_tasks();
2346 srv_master_do_idle_tasks();
2350 while (srv_master_do_shutdown_tasks(&last_print_time)) {
2357 srv_main_thread_op_info =
"suspending";
2359 srv_suspend_thread(slot);
2365 srv_main_thread_op_info =
"waiting for server activity";
2367 os_event_wait(slot->
event);
2375 OS_THREAD_DUMMY_RETURN;
2383 srv_purge_should_exit(
2410 srv_task_execute(
void)
2435 os_atomic_inc_ulint(
2439 return(thr != NULL);
2445 extern "C" UNIV_INTERN
2449 void* arg __attribute__((unused)))
2457 #ifdef UNIV_DEBUG_THREAD_CREATION
2459 fprintf(stderr,
" InnoDB: worker thread starting, id %lu\n",
2465 ut_a(srv_n_purge_threads > 1);
2478 srv_suspend_thread(slot);
2480 os_event_wait(slot->
event);
2482 if (srv_task_execute()) {
2494 srv_free_slot(slot);
2504 #ifdef UNIV_DEBUG_THREAD_CREATION
2506 fprintf(stderr,
" InnoDB: Purge worker thread exiting, id %lu\n",
2514 OS_THREAD_DUMMY_RETURN;
2525 ulint* n_total_purged)
2527 ulint n_pages_purged;
2529 static ulint count = 0;
2530 static ulint n_use_threads = 0;
2531 static ulint rseg_history_len = 0;
2534 ut_a(n_threads > 0);
2543 if (n_use_threads == 0) {
2544 n_use_threads = n_threads;
2555 if (n_use_threads < n_threads) {
2560 && n_use_threads > 1) {
2573 ut_a(n_use_threads > 0);
2574 ut_a(n_use_threads <= n_threads);
2582 n_use_threads, srv_purge_batch_size,
false);
2584 if (!(count++ % TRX_SYS_N_RSEGS)) {
2587 1, srv_purge_batch_size,
true);
2590 *n_total_purged += n_pages_purged;
2592 }
while (!srv_purge_should_exit(n_pages_purged) && n_pages_purged > 0);
2594 return(rseg_history_len);
2601 srv_purge_coordinator_suspend(
2605 ulint rseg_history_len)
2614 static const ulint SRV_PURGE_MAX_TIMEOUT = 10000;
2616 ib_int64_t sig_count = srv_suspend_thread(slot);
2633 }
else if (rseg_history_len <= trx_sys->rseg_history_len) {
2635 slot->
event, SRV_PURGE_MAX_TIMEOUT, sig_count);
2656 sig_count = srv_suspend_thread(slot);
2705 extern "C" UNIV_INTERN
2709 void* arg __attribute__((unused)))
2713 ulint n_total_purged = ULINT_UNDEFINED;
2716 ut_a(srv_n_purge_threads >= 1);
2727 #ifdef UNIV_PFS_THREAD
2728 pfs_register_thread(srv_purge_thread_key);
2731 #ifdef UNIV_DEBUG_THREAD_CREATION
2733 fprintf(stderr,
" InnoDB: Purge coordinator thread created, id %lu\n",
2746 || n_total_purged == 0) {
2748 srv_purge_coordinator_suspend(slot, rseg_history_len);
2751 if (srv_purge_should_exit(n_total_purged)) {
2758 rseg_history_len = srv_do_purge(
2759 srv_n_purge_threads, &n_total_purged);
2761 }
while (!srv_purge_should_exit(n_total_purged));
2766 ut_a(srv_purge_should_exit(n_total_purged));
2768 ulint n_pages_purged = ULINT_MAX;
2774 n_pages_purged =
trx_purge(1, srv_purge_batch_size,
false);
2778 n_pages_purged =
trx_purge(1, srv_purge_batch_size,
true);
2785 srv_free_slot(slot);
2796 #ifdef UNIV_DEBUG_THREAD_CREATION
2798 fprintf(stderr,
" InnoDB: Purge coordinator exiting, id %lu\n",
2803 if (srv_n_purge_threads > 1) {
2811 OS_THREAD_DUMMY_RETURN;
2867 if (srv_n_purge_threads > 1) {
2868 ulint n_workers = srv_n_purge_threads - 1;