diff options
Diffstat (limited to 'client/mysqlbinlog.cc')
-rw-r--r-- | client/mysqlbinlog.cc | 67 |
1 files changed, 61 insertions, 6 deletions
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 2cf91ec7da5..82af7ca65f6 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -17,10 +17,8 @@ TODO: print the catalog (some USE catalog.db ????). - Standalone program to read a MySQL binary log (or relay log); - can read files produced by 3.23, 4.x, 5.0 servers. + Standalone program to read a MySQL binary log (or relay log). - Can read binlogs from 3.23/4.x/5.0 and relay logs from 4.x/5.0. Should be able to read any file of these categories, even with --start-position. An important fact: the Format_desc event of the log is at most the 3rd event @@ -681,6 +679,7 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, { char ll_buff[21]; Log_event_type ev_type= ev->get_type_code(); + my_bool destroy_evt= TRUE; DBUG_ENTER("process_event"); print_event_info->short_form= short_form; Exit_status retval= OK_CONTINUE; @@ -689,8 +688,8 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, Format events are not concerned by --offset and such, we always need to read them to be able to process the wanted events. */ - if ((rec_count >= offset) && - ((my_time_t)(ev->when) >= start_datetime) || + if (((rec_count >= offset) && + ((my_time_t)(ev->when) >= start_datetime)) || (ev_type == FORMAT_DESCRIPTION_EVENT)) { if (ev_type != FORMAT_DESCRIPTION_EVENT) @@ -871,12 +870,63 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, break; } case TABLE_MAP_EVENT: + { + Table_map_log_event *map= ((Table_map_log_event *)ev); + if (shall_skip_database(map->get_db_name())) + { + print_event_info->m_table_map_ignored.set_table(map->get_table_id(), map); + destroy_evt= FALSE; + goto end; + } + } case WRITE_ROWS_EVENT: case DELETE_ROWS_EVENT: case UPDATE_ROWS_EVENT: case PRE_GA_WRITE_ROWS_EVENT: case PRE_GA_DELETE_ROWS_EVENT: case PRE_GA_UPDATE_ROWS_EVENT: + { + if (ev_type != TABLE_MAP_EVENT) + { + Rows_log_event *e= (Rows_log_event*) ev; + Table_map_log_event *ignored_map= + print_event_info->m_table_map_ignored.get_table(e->get_table_id()); + bool skip_event= (ignored_map != NULL); + + /* + end of statement check: + i) destroy/free ignored maps + ii) if skip event, flush cache now + */ + if (e->get_flags(Rows_log_event::STMT_END_F)) + { + /* + Now is safe to clear ignored map (clear_tables will also + delete original table map events stored in the map). + */ + if (print_event_info->m_table_map_ignored.count() > 0) + print_event_info->m_table_map_ignored.clear_tables(); + + /* + One needs to take into account an event that gets + filtered but was last event in the statement. If this is + the case, previous rows events that were written into + IO_CACHEs still need to be copied from cache to + result_file (as it would happen in ev->print(...) if + event was not skipped). + */ + if (skip_event) + { + if ((copy_event_cache_to_file_and_reinit(&print_event_info->head_cache, result_file) || + copy_event_cache_to_file_and_reinit(&print_event_info->body_cache, result_file))) + goto err; + } + } + + /* skip the event check */ + if (skip_event) + goto end; + } /* These events must be printed in base64 format, if printed. base64 format requires a FD event to be safe, so if no FD @@ -900,6 +950,7 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, goto err; } /* FALL THROUGH */ + } default: ev->print(result_file, print_event_info); } @@ -919,7 +970,8 @@ end: { if (remote_opt) ev->temp_buf= 0; - delete ev; + if (destroy_evt) /* destroy it later if not set (ignored table map) */ + delete ev; } DBUG_RETURN(retval); } @@ -934,10 +986,13 @@ static struct my_option my_long_options[] = 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, #endif {"base64-output", OPT_BASE64_OUTPUT_MODE, + /* 'unspec' is not mentioned because it is just a placeholder. */ "Determine when the output statements should be base64-encoded BINLOG " "statements: 'never' disables it and works only for binlogs without " "row-based events; 'auto' is the default and prints base64 only when " "necessary (i.e., for row-based events and format description events); " + "'decode-rows' suppresses BINLOG statements for row events, but does " + "not exit as an error if a row event is found, unlike 'never'; " "'always' prints base64 whenever possible. 'always' is for debugging " "only and should not be used in a production system. The default is " "'auto'. --base64-output is a short form for --base64-output=always." |