Helper function for SHOW BINLOG/RELAYLOG EVENTS */
| 2382 | |
| 2383 | /* Helper function for SHOW BINLOG/RELAYLOG EVENTS */ |
| 2384 | bool show_binlog_events(THD *thd, MYSQL_BIN_LOG *binary_log) |
| 2385 | { |
| 2386 | Protocol *protocol= thd->protocol; |
| 2387 | List<Item> field_list; |
| 2388 | const char *errmsg = 0; |
| 2389 | bool ret = TRUE; |
| 2390 | IO_CACHE log; |
| 2391 | File file = -1; |
| 2392 | int old_max_allowed_packet= thd->variables.max_allowed_packet; |
| 2393 | LOG_INFO linfo; |
| 2394 | |
| 2395 | DBUG_ENTER("show_binlog_events"); |
| 2396 | |
| 2397 | DBUG_ASSERT(thd->lex->sql_command == SQLCOM_SHOW_BINLOG_EVENTS || |
| 2398 | thd->lex->sql_command == SQLCOM_SHOW_RELAYLOG_EVENTS); |
| 2399 | |
| 2400 | Format_description_log_event *description_event= new |
| 2401 | Format_description_log_event(3); /* MySQL 4.0 by default */ |
| 2402 | |
| 2403 | if (binary_log->is_open()) |
| 2404 | { |
| 2405 | LEX_MASTER_INFO *lex_mi= &thd->lex->mi; |
| 2406 | SELECT_LEX_UNIT *unit= &thd->lex->unit; |
| 2407 | ha_rows event_count, limit_start, limit_end; |
| 2408 | my_off_t pos = max<my_off_t>(BIN_LOG_HEADER_SIZE, lex_mi->pos); // user-friendly |
| 2409 | char search_file_name[FN_REFLEN], *name; |
| 2410 | const char *log_file_name = lex_mi->log_file_name; |
| 2411 | mysql_mutex_t *log_lock = binary_log->get_log_lock(); |
| 2412 | Log_event* ev; |
| 2413 | |
| 2414 | unit->set_limit(thd->lex->current_select); |
| 2415 | limit_start= unit->offset_limit_cnt; |
| 2416 | limit_end= unit->select_limit_cnt; |
| 2417 | |
| 2418 | name= search_file_name; |
| 2419 | if (log_file_name) |
| 2420 | binary_log->make_log_name(search_file_name, log_file_name); |
| 2421 | else |
| 2422 | name=0; // Find first log |
| 2423 | |
| 2424 | linfo.index_file_offset = 0; |
| 2425 | |
| 2426 | if (binary_log->find_log_pos(&linfo, name, true/*need_lock_index=true*/)) |
| 2427 | { |
| 2428 | errmsg = "Could not find target log"; |
| 2429 | goto err; |
| 2430 | } |
| 2431 | |
| 2432 | mysql_mutex_lock(&LOCK_thread_count); |
| 2433 | thd->current_linfo = &linfo; |
| 2434 | mysql_mutex_unlock(&LOCK_thread_count); |
| 2435 | |
| 2436 | if ((file=open_binlog_file(&log, linfo.log_file_name, &errmsg)) < 0) |
| 2437 | goto err; |
| 2438 | |
| 2439 | my_off_t end_pos; |
| 2440 | /* |
| 2441 | Acquire LOCK_log only for the duration to calculate the |
no test coverage detected