@@ -3863,23 +3863,21 @@ Event_log::write_description_event(enum_binlog_checksum_alg checksum_alg,
38633863 bool encrypt, bool dont_set_created,
38643864 bool is_relay_log)
38653865{
3866- Format_description_log_event s (BINLOG_VERSION );
3866+ Format_description_log_event s (BINLOG_VERSION , NULL , checksum_alg );
38673867 /*
38683868 don't set LOG_EVENT_BINLOG_IN_USE_F for SEQ_READ_APPEND io_cache
38693869 as we won't be able to reset it later
38703870 */
38713871 if (io_cache_type == WRITE_CACHE )
38723872 s.flags |= LOG_EVENT_BINLOG_IN_USE_F ;
3873- s.checksum_alg = checksum_alg;
38743873 if (is_relay_log)
38753874 s.set_relay_log_event ();
38763875
38773876 crypto.scheme = 0 ;
3878- DBUG_ASSERT (s.checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF );
38793877 if (!s.is_valid ())
38803878 return -1 ;
38813879 s.dont_set_created = dont_set_created;
3882- if (write_event (&s, 0 , &log_file))
3880+ if (write_event (&s, checksum_alg, 0 , &log_file))
38833881 return -1 ;
38843882
38853883 if (encrypt)
@@ -3897,8 +3895,7 @@ Event_log::write_description_event(enum_binlog_checksum_alg checksum_alg,
38973895 return -1 ;
38983896
38993897 Start_encryption_log_event sele (1 , key_version, crypto.nonce );
3900- sele.checksum_alg = s.checksum_alg ;
3901- if (write_event (&sele, 0 , &log_file))
3898+ if (write_event (&sele, checksum_alg, 0 , &log_file))
39023899 return -1 ;
39033900
39043901 // Start_encryption_log_event is written, enable the encryption
@@ -4172,7 +4169,8 @@ bool MYSQL_BIN_LOG::open(const char *log_name,
41724169 /* Don't set log_pos in event header */
41734170 description_event_for_queue->set_artificial_event ();
41744171
4175- if (write_event (description_event_for_queue))
4172+ if (write_event (description_event_for_queue,
4173+ description_event_for_queue->used_checksum_alg ))
41764174 goto err;
41774175 bytes_written+= description_event_for_queue->data_written ;
41784176 }
@@ -5616,17 +5614,19 @@ int MYSQL_BIN_LOG::new_file_impl()
56165614 */
56175615 Rotate_log_event r (new_name + dirname_length (new_name), 0 , LOG_EVENT_OFFSET ,
56185616 is_relay_log ? Rotate_log_event::RELAY_LOG : 0 );
5617+ enum_binlog_checksum_alg checksum_alg = BINLOG_CHECKSUM_ALG_UNDEF ;
56195618 /*
56205619 The current relay-log's closing Rotate event must have checksum
56215620 value computed with an algorithm of the last relay-logged FD event.
56225621 */
56235622 if (is_relay_log)
5624- r.checksum_alg = relay_log_checksum_alg;
5625- DBUG_ASSERT (!is_relay_log ||
5626- relay_log_checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF );
5623+ checksum_alg= relay_log_checksum_alg;
5624+ else
5625+ checksum_alg= (enum_binlog_checksum_alg)binlog_checksum_options;
5626+ DBUG_ASSERT (checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF );
56275627 if ((DBUG_IF (" fault_injection_new_file_rotate_event" ) &&
56285628 (error= close_on_error= TRUE )) ||
5629- (error= write_event (&r)))
5629+ (error= write_event (&r, checksum_alg )))
56305630 {
56315631 DBUG_EXECUTE_IF (" fault_injection_new_file_rotate_event" , errno= 2 ;);
56325632 close_on_error= TRUE ;
@@ -5743,10 +5743,22 @@ int MYSQL_BIN_LOG::new_file_impl()
57435743 DBUG_RETURN (error);
57445744}
57455745
5746- bool Event_log::write_event (Log_event *ev, binlog_cache_data *cache_data ,
5746+ bool Event_log::write_event (Log_event *ev, binlog_cache_data *data ,
57475747 IO_CACHE *file)
57485748{
5749- Log_event_writer writer (file, 0 , &crypto);
5749+ return write_event (ev, ev->select_checksum_alg (), data, file);
5750+ }
5751+
5752+ bool MYSQL_BIN_LOG::write_event (Log_event *ev)
5753+ {
5754+ return write_event (ev, ev->select_checksum_alg (), 0 , &log_file);
5755+ }
5756+
5757+ bool MYSQL_BIN_LOG::write_event (Log_event *ev,
5758+ enum_binlog_checksum_alg checksum_alg,
5759+ binlog_cache_data *cache_data, IO_CACHE *file)
5760+ {
5761+ Log_event_writer writer (file, 0 , checksum_alg, &crypto);
57505762 if (crypto.scheme && file == &log_file)
57515763 {
57525764 writer.ctx = alloca (crypto.ctx_size );
@@ -5757,25 +5769,27 @@ bool Event_log::write_event(Log_event *ev, binlog_cache_data *cache_data,
57575769 return writer.write (ev);
57585770}
57595771
5760- bool MYSQL_BIN_LOG::append (Log_event *ev)
5772+ bool MYSQL_BIN_LOG::append (Log_event *ev,
5773+ enum_binlog_checksum_alg checksum_alg)
57615774{
57625775 bool res;
57635776 mysql_mutex_lock (&LOCK_log);
5764- res= append_no_lock (ev);
5777+ res= append_no_lock (ev, checksum_alg );
57655778 mysql_mutex_unlock (&LOCK_log);
57665779 return res;
57675780}
57685781
57695782
5770- bool MYSQL_BIN_LOG::append_no_lock (Log_event* ev)
5783+ bool MYSQL_BIN_LOG::append_no_lock (Log_event* ev,
5784+ enum_binlog_checksum_alg checksum_alg)
57715785{
57725786 bool error = 0 ;
57735787 DBUG_ENTER (" MYSQL_BIN_LOG::append" );
57745788
57755789 mysql_mutex_assert_owner (&LOCK_log);
57765790 DBUG_ASSERT (log_file.type == SEQ_READ_APPEND );
57775791
5778- if (write_event (ev))
5792+ if (write_event (ev, checksum_alg ))
57795793 {
57805794 error=1 ;
57815795 goto err;
@@ -6175,7 +6189,8 @@ THD::binlog_start_trans_and_stmt()
61756189 uchar *buf= 0 ;
61766190 size_t len= 0 ;
61776191 IO_CACHE tmp_io_cache;
6178- Log_event_writer writer (&tmp_io_cache, 0 );
6192+ // Replicated events in writeset doesn't have checksum
6193+ Log_event_writer writer (&tmp_io_cache, 0 , BINLOG_CHECKSUM_ALG_OFF , NULL );
61796194 if (!open_cached_file (&tmp_io_cache, mysql_tmpdir, TEMP_PREFIX ,
61806195 128 , MYF (MY_WME )))
61816196 {
@@ -6190,8 +6205,6 @@ THD::binlog_start_trans_and_stmt()
61906205 }
61916206 Gtid_log_event gtid_event (this , seqno, domain_id, true ,
61926207 LOG_EVENT_SUPPRESS_USE_F , true , 0 );
6193- // Replicated events in writeset doesn't have checksum
6194- gtid_event.checksum_alg = BINLOG_CHECKSUM_ALG_OFF ;
61956208 gtid_event.server_id = server_id;
61966209 writer.write (>id_event);
61976210 wsrep_write_cache_buf (&tmp_io_cache, &buf, &len);
@@ -6392,7 +6405,7 @@ bool MYSQL_BIN_LOG::write_table_map(THD *thd, TABLE *table, bool with_annotate)
63926405 binlog_cache_data *cache_data= (cache_mngr->
63936406 get_binlog_cache_data (is_transactional));
63946407 IO_CACHE *file= &cache_data->cache_log ;
6395- Log_event_writer writer (file, cache_data);
6408+ Log_event_writer writer (file, cache_data, the_event. select_checksum_alg (), NULL );
63966409
63976410 if (with_annotate)
63986411 if (thd->binlog_write_annotated_row (&writer))
@@ -6578,7 +6591,8 @@ Event_log::flush_and_set_pending_rows_event(THD *thd, Rows_log_event* event,
65786591
65796592 if (Rows_log_event* pending= cache_data->pending ())
65806593 {
6581- Log_event_writer writer (&cache_data->cache_log , cache_data);
6594+ Log_event_writer writer (&cache_data->cache_log , cache_data,
6595+ pending->select_checksum_alg (), NULL );
65826596
65836597 /*
65846598 Write pending event to the cache.
@@ -7704,11 +7718,13 @@ class CacheWriter: public Log_event_writer
77047718public:
77057719 size_t remains;
77067720
7707- CacheWriter (THD *thd_arg, IO_CACHE *file_arg, bool do_checksum,
7721+ CacheWriter (THD *thd_arg, IO_CACHE *file_arg,
7722+ enum_binlog_checksum_alg checksum_alg,
77087723 Binlog_crypt_data *cr)
7709- : Log_event_writer(file_arg, 0 , cr), remains(0 ), thd(thd_arg),
7724+ : Log_event_writer(file_arg, 0 , checksum_alg, cr), remains(0 ), thd(thd_arg),
77107725 first (true )
7711- { checksum_len= do_checksum ? BINLOG_CHECKSUM_LEN : 0 ; }
7726+ {
7727+ }
77127728
77137729 ~CacheWriter ()
77147730 { status_var_add (thd->status_var .binlog_bytes_written , bytes_written); }
@@ -7904,7 +7920,9 @@ int Event_log::write_cache(THD *thd, IO_CACHE *cache)
79047920 size_t val;
79057921 size_t end_log_pos_inc= 0 ; // each event processed adds BINLOG_CHECKSUM_LEN 2 t
79067922 uchar header[LOG_EVENT_HEADER_LEN ];
7907- CacheWriter writer (thd, get_log_file (), binlog_checksum_options, &crypto);
7923+ CacheWriter writer (thd, get_log_file (),
7924+ (enum_binlog_checksum_alg)binlog_checksum_options,
7925+ &crypto);
79087926
79097927 if (crypto.scheme )
79107928 {
@@ -9447,11 +9465,11 @@ void MYSQL_BIN_LOG::close(uint exiting)
94479465 {
94489466 Stop_log_event s;
94499467 // the checksumming rule for relay-log case is similar to Rotate
9450- s. checksum_alg = is_relay_log ? relay_log_checksum_alg
9451- : (enum_binlog_checksum_alg)binlog_checksum_options;
9452- DBUG_ASSERT (!is_relay_log ||
9453- relay_log_checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF );
9454- write_event (&s);
9468+ enum_binlog_checksum_alg checksum_alg= is_relay_log ?
9469+ relay_log_checksum_alg :
9470+ (enum_binlog_checksum_alg)binlog_checksum_options;
9471+ DBUG_ASSERT (checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF );
9472+ write_event (&s, checksum_alg );
94559473 bytes_written+= s.data_written ;
94569474 flush_io_cache (&log_file);
94579475 update_binlog_end_pos ();
@@ -11619,7 +11637,7 @@ bool Recovery_context::decide_or_assess(xid_recovery_member *member, int round,
1161911637 if (truncate_gtid.seq_no == 0 /* was reset or never set */ ||
1162011638 (truncate_set_in_1st && round == 2 /* reevaluted at round turn */ ))
1162111639 {
11622- if (set_truncate_coord (linfo, round, fdle->checksum_alg ))
11640+ if (set_truncate_coord (linfo, round, fdle->used_checksum_alg ))
1162311641 return true ;
1162411642 }
1162511643 else
0 commit comments