| 5799 | */ |
| 5800 | |
| 5801 | int MYSQL_BIN_LOG::do_write_cache(THD *thd, IO_CACHE *cache) |
| 5802 | { |
| 5803 | DBUG_ENTER("MYSQL_BIN_LOG::do_write_cache(IO_CACHE *)"); |
| 5804 | |
| 5805 | DBUG_EXECUTE_IF("simulate_do_write_cache_failure", |
| 5806 | { |
| 5807 | /* |
| 5808 | see binlog_cache_data::write_event() that reacts on |
| 5809 | @c simulate_disk_full_at_flush_pending. |
| 5810 | */ |
| 5811 | DBUG_SET("-d,simulate_do_write_cache_failure"); |
| 5812 | DBUG_RETURN(ER_ERROR_ON_WRITE); |
| 5813 | }); |
| 5814 | |
| 5815 | if (reinit_io_cache(cache, READ_CACHE, 0, 0, 0)) |
| 5816 | DBUG_RETURN(ER_ERROR_ON_WRITE); |
| 5817 | uint length= my_b_bytes_in_cache(cache), group, carry, hdr_offs; |
| 5818 | ulong remains= 0; // part of unprocessed yet netto length of the event |
| 5819 | long val; |
| 5820 | ulong end_log_pos_inc= 0; // each event processed adds BINLOG_CHECKSUM_LEN 2 t |
| 5821 | uchar header[LOG_EVENT_HEADER_LEN]; |
| 5822 | ha_checksum crc= 0, crc_0= 0; // assignments to keep compiler happy |
| 5823 | my_bool do_checksum= (binlog_checksum_options != BINLOG_CHECKSUM_ALG_OFF); |
| 5824 | uchar buf[BINLOG_CHECKSUM_LEN]; |
| 5825 | |
| 5826 | // while there is just one alg the following must hold: |
| 5827 | DBUG_ASSERT(!do_checksum || |
| 5828 | binlog_checksum_options == BINLOG_CHECKSUM_ALG_CRC32); |
| 5829 | |
| 5830 | /* |
| 5831 | The events in the buffer have incorrect end_log_pos data |
| 5832 | (relative to beginning of group rather than absolute), |
| 5833 | so we'll recalculate them in situ so the binlog is always |
| 5834 | correct, even in the middle of a group. This is possible |
| 5835 | because we now know the start position of the group (the |
| 5836 | offset of this cache in the log, if you will); all we need |
| 5837 | to do is to find all event-headers, and add the position of |
| 5838 | the group to the end_log_pos of each event. This is pretty |
| 5839 | straight forward, except that we read the cache in segments, |
| 5840 | so an event-header might end up on the cache-border and get |
| 5841 | split. |
| 5842 | */ |
| 5843 | |
| 5844 | group= (uint)my_b_tell(&log_file); |
| 5845 | DBUG_PRINT("debug", ("length: %llu, group: %llu", |
| 5846 | (ulonglong) length, (ulonglong) group)); |
| 5847 | hdr_offs= carry= 0; |
| 5848 | if (do_checksum) |
| 5849 | crc= crc_0= my_checksum(0L, NULL, 0); |
| 5850 | |
| 5851 | if (DBUG_EVALUATE_IF("fault_injection_crc_value", 1, 0)) |
| 5852 | crc= crc - 1; |
| 5853 | |
| 5854 | do |
| 5855 | { |
| 5856 | /* |
| 5857 | if we only got a partial header in the last iteration, |
| 5858 | get the other half now and process a full header. |
nothing calls this directly
no test coverage detected