diff options
author | Monty <monty@mariadb.org> | 2017-12-23 16:59:41 +0200 |
---|---|---|
committer | Monty <monty@mariadb.org> | 2017-12-29 13:35:41 +0200 |
commit | e64184134a19579dbe5bf98fc54f0f6236aabbcd (patch) | |
tree | f6fc13cef5a68539bc6554de30f01add4fc7ff94 /sql/log_event.h | |
parent | 40f4525f43aba5d579cf55bae2df504001cd04f4 (diff) | |
download | mariadb-git-e64184134a19579dbe5bf98fc54f0f6236aabbcd.tar.gz |
mysqlbinlog now prints "# Number of rows" and stops on errors
Main problem was that no log-event print function checked for disk
full error on the IO_CACHE.
All changes in this patch only affects mysqlbinlog, not the server!
- Changed all log-event print functions to return 1 on error
- Fixed memory usage when not using --flashback.
- Added printing of number of rows in row events. Can be disabled with
--print-row-count=0
- Print annotated rows when using mysqlbinlog --short-form
- Fixed that mysqlbinlog --debug works
- Fixed create_drop_binlog.test test failure
- Reorganized fields in PRINT_EVENT_INFO to be according to size to
optimize storage
- Don't change print_row_event_position or print_row_counts if set by user
- Remove some testing of argument to my_free is 0
- base64-output=never is now supported and works in all context
- Updated help information for --base64-output and --short-form
- print_row_count is now on by default. Reset automatically if --short-form
is used
- Removed obsolote warning for mysql 5.6.0
- More DBUG_PRINT for mysqltest.cc
- my_b_write_byte() now checks for flush failures. This fixed a memory
overrun on disk full
- my_b_printf() now returns 1 on failure, 0 on ok. This simplifies code
and no old code was using the old return value of my_b_printf().
- my_b_Write_backtick_quote() now returns 1 on failure and 0 on ok
- Fixed some error conditions in log printing that was not previously
handled.
- Slave_rows_error_report() can now handle longlong positions
- Write_on_release_cache() rewritten so that we can detect errors
on flush. Not depending on automatic release anymore.
- Changed types for Pos and End_log_pos to 64 bit in SHOW BINLOG EVENTS
- Fixed that copy_event_cache_to_string_and_reinit() works with strings
longer than 4G (Changed to use LEX_STRING instead of String)
- Restricted binlog_rows_event_max_size to UINT32_MAX-1 as String's are
anyway restricted to UINT32_MAX
- Fixed bug in rpl_binlog_state::write_to_iocache() which hide write
failures (duplicate variable name)
- Fixed bug in String::append if original string was not allocated
- Stop mysqlbinlog output at once if there is an error.
- Before printing error message, flush result file. This ensures that
the error message is printed last. (Easier to find)
Diffstat (limited to 'sql/log_event.h')
-rw-r--r-- | sql/log_event.h | 215 |
1 files changed, 99 insertions, 116 deletions
diff --git a/sql/log_event.h b/sql/log_event.h index 428616fcb0d..6b43dcaa763 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -802,6 +802,8 @@ class Format_description_log_event; class Relay_log_info; class binlog_cache_data; +bool copy_event_cache_to_file_and_reinit(IO_CACHE *cache, FILE *file); + #ifdef MYSQL_CLIENT enum enum_base64_output_mode { BASE64_OUTPUT_NEVER= 0, @@ -813,6 +815,8 @@ enum enum_base64_output_mode { BASE64_OUTPUT_MODE_COUNT }; +bool copy_event_cache_to_string_and_reinit(IO_CACHE *cache, LEX_STRING *to); + /* A structure for mysqlbinlog to know how to print events @@ -832,53 +836,38 @@ typedef struct st_print_event_info that was printed. We cache these so that we don't have to print them if they are unchanged. */ - // TODO: have the last catalog here ?? char db[FN_REFLEN+1]; // TODO: make this a LEX_STRING when thd->db is - bool flags2_inited; - uint32 flags2; - bool sql_mode_inited; - sql_mode_t sql_mode; /* must be same as THD.variables.sql_mode */ - ulong auto_increment_increment, auto_increment_offset; - bool charset_inited; char charset[6]; // 3 variables, each of them storable in 2 bytes char time_zone_str[MAX_TIME_ZONE_NAME_LENGTH]; + char delimiter[16]; + sql_mode_t sql_mode; /* must be same as THD.variables.sql_mode */ + my_thread_id thread_id; + ulonglong row_events; + ulong auto_increment_increment, auto_increment_offset; uint lc_time_names_number; uint charset_database_number; - my_thread_id thread_id; - bool thread_id_printed; + uint verbose; + uint32 flags2; uint32 server_id; - bool server_id_printed; uint32 domain_id; + uint8 common_header_len; + enum_base64_output_mode base64_output_mode; + my_off_t hexdump_from; + + table_mapping m_table_map; + table_mapping m_table_map_ignored; + bool flags2_inited; + bool sql_mode_inited; + bool charset_inited; + bool thread_id_printed; + bool server_id_printed; bool domain_id_printed; bool allow_parallel; bool allow_parallel_printed; - - /* - Track when @@skip_replication changes so we need to output a SET - statement for it. - */ - int skip_replication; - - st_print_event_info(); - - ~st_print_event_info() { - close_cached_file(&head_cache); - close_cached_file(&body_cache); -#ifdef WHEN_FLASHBACK_REVIEW_READY - close_cached_file(&review_sql_cache); -#endif - } - bool init_ok() /* tells if construction was successful */ - { return my_b_inited(&head_cache) && my_b_inited(&body_cache) -#ifdef WHEN_FLASHBACK_REVIEW_READY - && my_b_inited(&review_sql_cache) -#endif - ; } - - + bool found_row_event; + bool print_row_count; /* Settings on how to print the events */ bool short_form; - enum_base64_output_mode base64_output_mode; /* This is set whenever a Format_description_event is printed. Later, when an event is printed in base64, this flag is tested: if @@ -886,13 +875,11 @@ typedef struct st_print_event_info the base64 event, so an error message is generated. */ bool printed_fd_event; - my_off_t hexdump_from; - uint8 common_header_len; - char delimiter[16]; - - uint verbose; - table_mapping m_table_map; - table_mapping m_table_map_ignored; + /* + Track when @@skip_replication changes so we need to output a SET + statement for it. + */ + bool skip_replication; /* These two caches are used by the row-based replication events to @@ -905,6 +892,28 @@ typedef struct st_print_event_info /* Storing the SQL for reviewing */ IO_CACHE review_sql_cache; #endif + FILE *file; + st_print_event_info(); + + ~st_print_event_info() { + close_cached_file(&head_cache); + close_cached_file(&body_cache); +#ifdef WHEN_FLASHBACK_REVIEW_READY + close_cached_file(&review_sql_cache); +#endif + } + bool init_ok() /* tells if construction was successful */ + { return my_b_inited(&head_cache) && my_b_inited(&body_cache) +#ifdef WHEN_FLASHBACK_REVIEW_READY + && my_b_inited(&review_sql_cache) +#endif + ; } + void flush_for_error() + { + if (!copy_event_cache_to_file_and_reinit(&head_cache, file)) + copy_event_cache_to_file_and_reinit(&body_cache, file); + fflush(file); + } } PRINT_EVENT_INFO; #endif @@ -1250,11 +1259,11 @@ public: Log_event() : temp_buf(0), when(0), flags(0) {} ha_checksum crc; /* print*() functions are used by mysqlbinlog */ - virtual void print(FILE* file, PRINT_EVENT_INFO* print_event_info) = 0; - void print_timestamp(IO_CACHE* file, time_t *ts = 0); - void print_header(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info, + virtual bool print(FILE* file, PRINT_EVENT_INFO* print_event_info) = 0; + bool print_timestamp(IO_CACHE* file, time_t *ts = 0); + bool print_header(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info, bool is_more); - void print_base64(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info, + bool print_base64(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info, bool is_more); #endif /* MYSQL_SERVER */ @@ -2113,8 +2122,8 @@ public: void pack_info(Protocol* protocol); #endif /* HAVE_REPLICATION */ #else - void print_query_header(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info); - void print(FILE* file, PRINT_EVENT_INFO* print_event_info); + bool print_query_header(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info); + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info); #endif Query_log_event(); @@ -2453,7 +2462,7 @@ protected: const Format_description_log_event* description_event); public: - void print_query(THD *thd, bool need_db, const char *cs, String *buf, + bool print_query(THD *thd, bool need_db, const char *cs, String *buf, my_off_t *fn_start, my_off_t *fn_end, const char *qualify_db); my_thread_id thread_id; @@ -2519,8 +2528,8 @@ public: void pack_info(Protocol* protocol); #endif /* HAVE_REPLICATION */ #else - void print(FILE* file, PRINT_EVENT_INFO* print_event_info); - void print(FILE* file, PRINT_EVENT_INFO* print_event_info, bool commented); + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info); + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info, bool commented); #endif /* @@ -2617,7 +2626,7 @@ public: #endif /* HAVE_REPLICATION */ #else Start_log_event_v3() {} - void print(FILE* file, PRINT_EVENT_INFO* print_event_info); + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info); #endif Start_log_event_v3(const char* buf, uint event_len, @@ -2686,7 +2695,7 @@ public: write_data(nonce, BINLOG_NONCE_LENGTH); } #else - void print(FILE* file, PRINT_EVENT_INFO* print_event_info); + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info); #endif Start_encryption_log_event( @@ -2874,7 +2883,7 @@ Intvar_log_event(THD* thd_arg,uchar type_arg, ulonglong val_arg, void pack_info(Protocol* protocol); #endif /* HAVE_REPLICATION */ #else - void print(FILE* file, PRINT_EVENT_INFO* print_event_info); + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info); #endif Intvar_log_event(const char* buf, @@ -2955,7 +2964,7 @@ class Rand_log_event: public Log_event void pack_info(Protocol* protocol); #endif /* HAVE_REPLICATION */ #else - void print(FILE* file, PRINT_EVENT_INFO* print_event_info); + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info); #endif Rand_log_event(const char* buf, @@ -3005,7 +3014,7 @@ class Xid_log_event: public Log_event void pack_info(Protocol* protocol); #endif /* HAVE_REPLICATION */ #else - void print(FILE* file, PRINT_EVENT_INFO* print_event_info); + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info); #endif Xid_log_event(const char* buf, @@ -3067,7 +3076,7 @@ public: } void pack_info(Protocol* protocol); #else - void print(FILE* file, PRINT_EVENT_INFO* print_event_info); + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info); #endif User_var_log_event(const char* buf, uint event_len, @@ -3115,7 +3124,7 @@ public: Stop_log_event() :Log_event() {} #else - void print(FILE* file, PRINT_EVENT_INFO* print_event_info); + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info); #endif Stop_log_event(const char* buf, @@ -3211,7 +3220,7 @@ public: void pack_info(Protocol* protocol); #endif /* HAVE_REPLICATION */ #else - void print(FILE* file, PRINT_EVENT_INFO* print_event_info); + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info); #endif Rotate_log_event(const char* buf, uint event_len, @@ -3251,7 +3260,7 @@ public: void pack_info(Protocol *protocol); #endif #else - void print(FILE *file, PRINT_EVENT_INFO *print_event_info); + bool print(FILE *file, PRINT_EVENT_INFO *print_event_info); #endif Binlog_checkpoint_log_event(const char *buf, uint event_len, const Format_description_log_event *description_event); @@ -3376,7 +3385,7 @@ public: virtual enum_skip_reason do_shall_skip(rpl_group_info *rgi); #endif #else - void print(FILE *file, PRINT_EVENT_INFO *print_event_info); + bool print(FILE *file, PRINT_EVENT_INFO *print_event_info); #endif Gtid_log_event(const char *buf, uint event_len, const Format_description_log_event *description_event); @@ -3490,7 +3499,7 @@ public: void pack_info(Protocol *protocol); #endif #else - void print(FILE *file, PRINT_EVENT_INFO *print_event_info); + bool print(FILE *file, PRINT_EVENT_INFO *print_event_info); #endif Gtid_list_log_event(const char *buf, uint event_len, const Format_description_log_event *description_event); @@ -3554,8 +3563,8 @@ public: void pack_info(Protocol* protocol); #endif /* HAVE_REPLICATION */ #else - void print(FILE* file, PRINT_EVENT_INFO* print_event_info); - void print(FILE* file, PRINT_EVENT_INFO* print_event_info, + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info); + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info, bool enable_local); #endif @@ -3627,7 +3636,7 @@ public: virtual int get_create_or_append() const; #endif /* HAVE_REPLICATION */ #else - void print(FILE* file, PRINT_EVENT_INFO* print_event_info); + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info); #endif Append_block_log_event(const char* buf, uint event_len, @@ -3667,8 +3676,8 @@ public: void pack_info(Protocol* protocol); #endif /* HAVE_REPLICATION */ #else - void print(FILE* file, PRINT_EVENT_INFO* print_event_info); - void print(FILE* file, PRINT_EVENT_INFO* print_event_info, + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info); + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info, bool enable_local); #endif @@ -3708,7 +3717,7 @@ public: void pack_info(Protocol* protocol); #endif /* HAVE_REPLICATION */ #else - void print(FILE* file, PRINT_EVENT_INFO* print_event_info); + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info); #endif Execute_load_log_event(const char* buf, uint event_len, @@ -3804,9 +3813,9 @@ public: void pack_info(Protocol* protocol); #endif /* HAVE_REPLICATION */ #else - void print(FILE* file, PRINT_EVENT_INFO* print_event_info); + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info); /* Prints the query as LOAD DATA LOCAL and with rewritten filename */ - void print(FILE* file, PRINT_EVENT_INFO* print_event_info, + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info, const char *local_fname); #endif Execute_load_query_log_event(const char* buf, uint event_len, @@ -3851,7 +3860,7 @@ public: /* constructor for hopelessly corrupted events */ Unknown_log_event(): Log_event(), what(ENCRYPTED) {} ~Unknown_log_event() {} - void print(FILE* file, PRINT_EVENT_INFO* print_event_info); + bool print(FILE* file, PRINT_EVENT_INFO* print_event_info); Log_event_type get_type_code() { return UNKNOWN_EVENT;} bool is_valid() const { return 1; } }; @@ -3896,7 +3905,7 @@ public: #endif #ifdef MYSQL_CLIENT - virtual void print(FILE*, PRINT_EVENT_INFO*); + virtual bool print(FILE*, PRINT_EVENT_INFO*); #endif #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) @@ -4316,7 +4325,7 @@ public: #endif #ifdef MYSQL_CLIENT - virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info); + virtual bool print(FILE *file, PRINT_EVENT_INFO *print_event_info); #endif @@ -4437,15 +4446,21 @@ public: #ifdef MYSQL_CLIENT /* not for direct call, each derived has its own ::print() */ - virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info)= 0; + virtual bool print(FILE *file, PRINT_EVENT_INFO *print_event_info)= 0; void change_to_flashback_event(PRINT_EVENT_INFO *print_event_info, uchar *rows_buff, Log_event_type ev_type); - void print_verbose(IO_CACHE *file, + bool print_verbose(IO_CACHE *file, PRINT_EVENT_INFO *print_event_info); size_t print_verbose_one_row(IO_CACHE *file, table_def *td, PRINT_EVENT_INFO *print_event_info, MY_BITMAP *cols_bitmap, const uchar *ptr, const uchar *prefix, const my_bool no_fill_output= 0); // if no_fill_output=1, then print result is unnecessary + size_t calc_row_event_length(table_def *td, + PRINT_EVENT_INFO *print_event_info, + MY_BITMAP *cols_bitmap, + const uchar *value); + void count_row_events(PRINT_EVENT_INFO *print_event_info); + #endif #ifdef MYSQL_SERVER @@ -4552,7 +4567,7 @@ protected: void uncompress_buf(); #ifdef MYSQL_CLIENT - void print_helper(FILE *, PRINT_EVENT_INFO *, char const *const name); + bool print_helper(FILE *, PRINT_EVENT_INFO *, char const *const name); #endif #ifdef MYSQL_SERVER @@ -4756,7 +4771,7 @@ private: virtual Log_event_type get_general_type_code() { return (Log_event_type)TYPE_CODE; } #ifdef MYSQL_CLIENT - void print(FILE *file, PRINT_EVENT_INFO *print_event_info); + bool print(FILE *file, PRINT_EVENT_INFO *print_event_info); #endif #if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) @@ -4780,7 +4795,7 @@ public: #endif private: #if defined(MYSQL_CLIENT) - void print(FILE *file, PRINT_EVENT_INFO *print_event_info); + bool print(FILE *file, PRINT_EVENT_INFO *print_event_info); #endif }; @@ -4843,7 +4858,7 @@ protected: virtual Log_event_type get_general_type_code() { return (Log_event_type)TYPE_CODE; } #ifdef MYSQL_CLIENT - void print(FILE *file, PRINT_EVENT_INFO *print_event_info); + bool print(FILE *file, PRINT_EVENT_INFO *print_event_info); #endif #if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) @@ -4867,7 +4882,7 @@ public: #endif private: #if defined(MYSQL_CLIENT) - void print(FILE *file, PRINT_EVENT_INFO *print_event_info); + bool print(FILE *file, PRINT_EVENT_INFO *print_event_info); #endif }; @@ -4927,7 +4942,7 @@ protected: virtual Log_event_type get_general_type_code() { return (Log_event_type)TYPE_CODE; } #ifdef MYSQL_CLIENT - void print(FILE *file, PRINT_EVENT_INFO *print_event_info); + bool print(FILE *file, PRINT_EVENT_INFO *print_event_info); #endif #if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) @@ -4950,7 +4965,7 @@ public: #endif private: #if defined(MYSQL_CLIENT) - void print(FILE *file, PRINT_EVENT_INFO *print_event_info); + bool print(FILE *file, PRINT_EVENT_INFO *print_event_info); #endif }; @@ -5044,7 +5059,7 @@ public: virtual ~Incident_log_event(); #ifdef MYSQL_CLIENT - virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info); + virtual bool print(FILE *file, PRINT_EVENT_INFO *print_event_info); #endif #if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) @@ -5111,7 +5126,7 @@ public: #endif #ifdef MYSQL_CLIENT - virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info); + virtual bool print(FILE *file, PRINT_EVENT_INFO *print_event_info); #endif virtual Log_event_type get_type_code() { return IGNORABLE_LOG_EVENT; } @@ -5121,38 +5136,6 @@ public: virtual int get_data_size() { return IGNORABLE_HEADER_LEN; } }; - -static inline bool copy_event_cache_to_string_and_reinit(IO_CACHE *cache, LEX_STRING *to) -{ - String tmp; - - reinit_io_cache(cache, READ_CACHE, 0L, FALSE, FALSE); - if (tmp.append(cache, (uint32)cache->end_of_file)) - goto err; - reinit_io_cache(cache, WRITE_CACHE, 0, FALSE, TRUE); - - /* - Can't change the order, because the String::release() will clear the - length. - */ - to->length= tmp.length(); - to->str= tmp.release(); - - return false; - -err: - perror("Out of memory: can't allocate memory in copy_event_cache_to_string_and_reinit()."); - return true; -} - -static inline bool copy_event_cache_to_file_and_reinit(IO_CACHE *cache, - FILE *file) -{ - return - my_b_copy_to_file(cache, file) || - reinit_io_cache(cache, WRITE_CACHE, 0, FALSE, TRUE); -} - #ifdef MYSQL_SERVER /***************************************************************************** |