Skip to content

Commit 24fbb01

Browse files
MDEV-34124: Fix streaming replication offset for binlog stmt cache
As the binlog statement cache is only replicated with the last fragment, it's safe to pass zero offset instead of the stored log position, which is used only for the binlog transaction cache.
1 parent 85cd0c7 commit 24fbb01

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

sql/wsrep_binlog.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,13 @@ int wsrep_write_cache_buf(IO_CACHE *cache, uchar **buf, size_t *buf_len)
118118
*/
119119
static int wsrep_write_cache_inc(THD* const thd,
120120
IO_CACHE* const cache,
121+
size_t const log_position,
121122
size_t* const len)
122123
{
123124
DBUG_ENTER("wsrep_write_cache_inc");
124125
my_off_t const saved_pos(my_b_tell(cache));
125126

126-
if (reinit_io_cache(cache, READ_CACHE, thd->wsrep_sr().log_position(), 0, 0))
127+
if (reinit_io_cache(cache, READ_CACHE, log_position, 0, 0))
127128
{
128129
WSREP_ERROR("failed to initialize io-cache");
129130
DBUG_RETURN(1);;
@@ -157,7 +158,7 @@ static int wsrep_write_cache_inc(THD* const thd,
157158
} while ((cache->file >= 0) && (length= my_b_fill(cache)));
158159
if (ret == 0)
159160
{
160-
assert(total_length + thd->wsrep_sr().log_position() == saved_pos);
161+
assert(total_length + log_position == saved_pos);
161162
}
162163
}
163164

@@ -178,9 +179,10 @@ static int wsrep_write_cache_inc(THD* const thd,
178179
*/
179180
int wsrep_write_cache(THD* const thd,
180181
IO_CACHE* const cache,
182+
size_t const log_position,
181183
size_t* const len)
182184
{
183-
return wsrep_write_cache_inc(thd, cache, len);
185+
return wsrep_write_cache_inc(thd, cache, log_position, len);
184186
}
185187

186188
void wsrep_dump_rbr_buf(THD *thd, const void* rbr_buf, size_t buf_len)

sql/wsrep_binlog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ int wsrep_write_cache_buf(IO_CACHE *cache, uchar **buf, size_t *buf_len);
3636
This function quite the same as MYSQL_BIN_LOG::write_cache(),
3737
with the exception that here we write in buffer instead of log file.
3838
39+
@param log_position position to start writing the cache from
3940
@param len total amount of data written
4041
@return wsrep error status
4142
*/
4243
int wsrep_write_cache(THD* thd,
4344
IO_CACHE* cache,
45+
size_t log_position,
4446
size_t* len);
4547

4648
/* Dump replication buffer to disk */

sql/wsrep_client_service.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,20 @@ int Wsrep_client_service::prepare_data_for_replication()
9595
size_t transactional_data_len= 0;
9696
size_t stmt_data_len= 0;
9797

98-
// Write transactional cache
98+
// Write transactional cache from the last remembered position
9999
if (transactional_cache &&
100-
wsrep_write_cache(m_thd, transactional_cache, &transactional_data_len))
100+
wsrep_write_cache(m_thd, transactional_cache,
101+
m_thd->wsrep_sr().log_position(),
102+
&transactional_data_len))
101103
{
102104
WSREP_ERROR("rbr write fail, data_len: %zu",
103105
data_len);
104106
// wsrep_override_error(m_thd, ER_ERROR_DURING_COMMIT);
105107
DBUG_RETURN(1);
106108
}
107109

108-
// Write stmt cache
109-
if (stmt_cache && wsrep_write_cache(m_thd, stmt_cache, &stmt_data_len))
110+
// Write stmt cache fully as it's only written upon transaction commit
111+
if (stmt_cache && wsrep_write_cache(m_thd, stmt_cache, 0u, &stmt_data_len))
110112
{
111113
WSREP_ERROR("rbr write fail, data_len: %zu",
112114
data_len);

0 commit comments

Comments
 (0)