Skip to content

Commit fc8742e

Browse files
committed
MDEV-31678: UPDATE_ROWS_EVENT not setting updating columns in read_set
When binlog_row_image=MINIMAL, UPDATE_ROWS_EVENT may change columns that are not in the before image. Such columns had their bit set in table->write_set, but was missing their bit in table->read_set. As part of this patch, bitmap_union() is extended to handle bitmaps of different sizes, similar to bitmap_intersect(). Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
1 parent e25abdd commit fc8742e

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
include/master-slave.inc
2+
[connection master]
3+
connection slave;
4+
SET @old_format= @@GLOBAL.binlog_row_image;
5+
SET GLOBAL binlog_row_image=MINIMAL;
6+
include/stop_slave.inc
7+
include/start_slave.inc
8+
SET GLOBAL binlog_row_image= @old_format;
9+
connection default;
10+
SET SESSION binlog_row_image=MINIMAL;
11+
CREATE TABLE t (id INT AUTO_INCREMENT, col_int BIGINT NOT NULL, UNIQUE (col_int), KEY(id)) ENGINE=InnoDB;
12+
INSERT INTO t VALUES (1,1);
13+
UPDATE t SET id = 2;
14+
connection slave;
15+
connection master;
16+
DROP TABLE t;
17+
include/rpl_end.inc
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--source include/have_innodb.inc
2+
--source include/have_binlog_format_row.inc
3+
--source include/master-slave.inc
4+
5+
--connection slave
6+
SET @old_format= @@GLOBAL.binlog_row_image;
7+
SET GLOBAL binlog_row_image=MINIMAL;
8+
--source include/stop_slave.inc
9+
--source include/start_slave.inc
10+
SET GLOBAL binlog_row_image= @old_format;
11+
--connection default
12+
SET SESSION binlog_row_image=MINIMAL;
13+
14+
CREATE TABLE t (id INT AUTO_INCREMENT, col_int BIGINT NOT NULL, UNIQUE (col_int), KEY(id)) ENGINE=InnoDB;
15+
INSERT INTO t VALUES (1,1);
16+
UPDATE t SET id = 2;
17+
18+
--sync_slave_with_master
19+
20+
# Cleanup
21+
--connection master
22+
DROP TABLE t;
23+
--source include/rpl_end.inc

mysys/my_bitmap.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,11 +538,16 @@ void bitmap_subtract(MY_BITMAP *map, const MY_BITMAP *map2)
538538

539539
void bitmap_union(MY_BITMAP *map, const MY_BITMAP *map2)
540540
{
541-
my_bitmap_map *to= map->bitmap, *from= map2->bitmap, *end= map->last_word_ptr;
542-
DBUG_ASSERT_IDENTICAL_BITMAPS(map,map2);
541+
my_bitmap_map *to= map->bitmap, *from= map2->bitmap, *end;
542+
uint len= no_words_in_map(map), len2= no_words_in_map(map2);
543+
uint32 num_bits= MY_MIN(map->n_bits, map2->n_bits);
544+
DBUG_ASSERT_DIFFERENT_BITMAPS(map,map2);
543545

544-
while (to <= end)
546+
end= to + MY_MIN(len, len2) - 1;
547+
548+
while (to < end)
545549
*to++ |= *from++;
550+
*to|= *from & ~last_bit_mask(num_bits); /* Omit last not relevant bits */
546551
}
547552

548553

sql/log_event_server.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8543,9 +8543,11 @@ Update_rows_log_event::do_exec_row(rpl_group_info *rgi)
85438543
#endif /* WSREP_PROC_INFO */
85448544

85458545
thd_proc_info(thd, message);
8546-
// Temporary fix to find out why it fails [/Matz]
8547-
memcpy(m_table->read_set->bitmap, m_cols.bitmap, (m_table->read_set->n_bits + 7) / 8);
8548-
memcpy(m_table->write_set->bitmap, m_cols_ai.bitmap, (m_table->write_set->n_bits + 7) / 8);
8546+
/* Must read also after-image columns to be able to update them. */
8547+
bitmap_copy(m_table->read_set, &m_cols);
8548+
bitmap_union(m_table->read_set, &m_cols_ai);
8549+
/* Must update after-image columns. */
8550+
bitmap_copy(m_table->write_set, &m_cols_ai);
85498551

85508552
m_table->mark_columns_per_binlog_row_image();
85518553

0 commit comments

Comments
 (0)