44 enum status_severity {
50 #define SHUTTING_DOWN() (UNIV_UNLIKELY(srv_shutdown_state \
51 != SRV_SHUTDOWN_NONE))
55 static ibool buf_dump_should_start = FALSE;
56 static ibool buf_load_should_start = FALSE;
58 static ibool buf_load_abort_flag = FALSE;
64 typedef ib_uint64_t buf_dump_t;
67 #define BUF_DUMP_CREATE(space, page) ut_ull_create(space, page)
68 #define BUF_DUMP_SPACE(a) ((ulint) ((a) >> 32))
69 #define BUF_DUMP_PAGE(a) ((ulint) ((a) & 0xFFFFFFFFUL))
81 buf_dump_should_start = TRUE;
95 buf_load_should_start = TRUE;
108 static __attribute__((nonnull, format(printf, 2, 3)))
112 enum status_severity severity,
126 if (severity == STATUS_NOTICE || severity == STATUS_ERR) {
128 fprintf(stderr,
" InnoDB: %s\n",
144 static __attribute__((nonnull, format(printf, 2, 3)))
148 enum status_severity severity,
161 if (severity == STATUS_NOTICE || severity == STATUS_ERR) {
163 fprintf(stderr,
" InnoDB: %s\n",
183 #define SHOULD_QUIT() (SHUTTING_DOWN() && obey_shutdown)
185 char full_filename[OS_FILE_MAX_PATH];
186 char tmp_filename[OS_FILE_MAX_PATH];
193 "%s%c%s", srv_data_home, SRV_PATH_SEPARATOR,
197 "%s.incomplete", full_filename);
199 buf_dump_status(STATUS_NOTICE,
"Dumping buffer pool(s) to %s",
202 f = fopen(tmp_filename,
"w");
204 buf_dump_status(STATUS_ERR,
205 "Cannot open '%s' for writing: %s",
206 tmp_filename, strerror(errno));
212 for (i = 0; i < srv_buf_pool_instances && !SHOULD_QUIT(); i++) {
233 dump =
static_cast<buf_dump_t*
>(
239 buf_dump_status(STATUS_ERR,
240 "Cannot allocate " ULINTPF
" bytes: %s",
241 (ulint) (n_pages *
sizeof(*dump)),
261 for (j = 0; j < n_pages && !SHOULD_QUIT(); j++) {
262 ret = fprintf(f, ULINTPF
"," ULINTPF
"\n",
263 BUF_DUMP_SPACE(dump[j]),
264 BUF_DUMP_PAGE(dump[j]));
268 buf_dump_status(STATUS_ERR,
269 "Cannot write to '%s': %s",
270 tmp_filename, strerror(errno));
278 "Dumping buffer pool "
279 ULINTPF
"/" ULINTPF
", "
280 "page " ULINTPF
"/" ULINTPF,
281 i + 1, srv_buf_pool_instances,
291 buf_dump_status(STATUS_ERR,
292 "Cannot close '%s': %s",
293 tmp_filename, strerror(errno));
298 ret = unlink(full_filename);
299 if (ret != 0 && errno != ENOENT) {
300 buf_dump_status(STATUS_ERR,
301 "Cannot delete '%s': %s",
302 full_filename, strerror(errno));
308 ret = rename(tmp_filename, full_filename);
310 buf_dump_status(STATUS_ERR,
311 "Cannot rename '%s' to '%s': %s",
312 tmp_filename, full_filename,
323 buf_dump_status(STATUS_NOTICE,
324 "Buffer pool(s) dump completed at %s", now);
341 }
else if (d1 == d2) {
374 char full_filename[OS_FILE_MAX_PATH];
378 buf_dump_t* dump_tmp;
380 ulint total_buffer_pools_pages;
387 buf_load_abort_flag = FALSE;
390 "%s%c%s", srv_data_home, SRV_PATH_SEPARATOR,
393 buf_load_status(STATUS_NOTICE,
394 "Loading buffer pool(s) from %s", full_filename);
396 f = fopen(full_filename,
"r");
398 buf_load_status(STATUS_ERR,
399 "Cannot open '%s' for reading: %s",
400 full_filename, strerror(errno));
409 while (fscanf(f, ULINTPF
"," ULINTPF, &space_id, &page_no) == 2
410 && !SHUTTING_DOWN()) {
414 if (!SHUTTING_DOWN() && !feof(f)) {
423 buf_load_status(STATUS_ERR,
"Error %s '%s', "
424 "unable to load buffer pool (stage 1)",
425 what, full_filename);
433 * srv_buf_pool_instances;
434 if (dump_n > total_buffer_pools_pages) {
435 dump_n = total_buffer_pools_pages;
438 dump =
static_cast<buf_dump_t*
>(
ut_malloc(dump_n *
sizeof(*dump)));
442 buf_load_status(STATUS_ERR,
443 "Cannot allocate " ULINTPF
" bytes: %s",
444 (ulint) (dump_n *
sizeof(*dump)),
449 dump_tmp =
static_cast<buf_dump_t*
>(
452 if (dump_tmp == NULL) {
455 buf_load_status(STATUS_ERR,
456 "Cannot allocate " ULINTPF
" bytes: %s",
457 (ulint) (dump_n *
sizeof(*dump_tmp)),
464 for (i = 0; i < dump_n && !SHUTTING_DOWN(); i++) {
465 fscanf_ret = fscanf(f, ULINTPF
"," ULINTPF,
466 &space_id, &page_no);
468 if (fscanf_ret != 2) {
477 buf_load_status(STATUS_ERR,
478 "Error parsing '%s', unable "
479 "to load buffer pool (stage 2)",
484 if (space_id > ULINT32_MASK || page_no > ULINT32_MASK) {
488 buf_load_status(STATUS_ERR,
489 "Error parsing '%s': bogus "
490 "space,page " ULINTPF
"," ULINTPF
491 " at line " ULINTPF
", "
492 "unable to load buffer pool",
499 dump[
i] = BUF_DUMP_CREATE(space_id, page_no);
512 buf_load_status(STATUS_NOTICE,
513 "Buffer pool(s) load completed at %s "
514 "(%s was empty)", now, full_filename);
518 if (!SHUTTING_DOWN()) {
519 buf_dump_sort(dump, dump_tmp, 0, dump_n);
524 for (i = 0; i < dump_n && !SHUTTING_DOWN(); i++) {
527 BUF_DUMP_PAGE(dump[i]));
534 buf_load_status(STATUS_INFO,
535 "Loaded " ULINTPF
"/" ULINTPF
" pages",
539 if (buf_load_abort_flag) {
540 buf_load_abort_flag = FALSE;
544 "Buffer pool(s) load aborted on request");
553 buf_load_status(STATUS_NOTICE,
554 "Buffer pool(s) load completed at %s", now);
566 buf_load_abort_flag = TRUE;
574 extern "C" UNIV_INTERN
578 void* arg __attribute__((unused)))
583 srv_buf_dump_thread_active = TRUE;
585 buf_dump_status(STATUS_INFO,
"not started");
586 buf_load_status(STATUS_INFO,
"not started");
588 if (srv_buffer_pool_load_at_startup) {
592 while (!SHUTTING_DOWN()) {
596 if (buf_dump_should_start) {
597 buf_dump_should_start = FALSE;
601 if (buf_load_should_start) {
602 buf_load_should_start = FALSE;
614 srv_buf_dump_thread_active = FALSE;
620 OS_THREAD_DUMMY_RETURN;