1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

BUG#49562: SBR out of sync when using numeric data types + user

variable

The User_var_log_event was not serializing the unsigned
flag. This would cause the slave to always assume signed values.

We fix this by extending the User_var_log_event to also contain
information on the unsigned_flag, meaning that it gets into the
binlog as well, therefore the slave will get this information as
well. Events without information on unsigned flag (old events)
are treated as they were before (always signed: unsigned_flag=
FALSE).

The information on the unsigned_flag, is shipped in an extra byte
appended to the end of the User_var_log_event and added by this
patch. This extra byte holds values for general purpose
User_var_log_event flags which are now packed in the binlog as
well. One of these flags contains information about whether the
value is signed or unsigned (currently this extra byte is only
used to hold data on the unsigned flag, in the future we can use
it to pack extra flags if there is the need to).
This commit is contained in:
Luis Soares
2010-01-15 17:52:46 +00:00
parent 54b2371e92
commit 2afa7085e9
6 changed files with 470 additions and 10 deletions

View File

@ -5460,7 +5460,9 @@ void User_var_log_event::pack_info(Protocol* protocol)
case INT_RESULT:
if (!(buf= (char*) my_malloc(val_offset + 22, MYF(MY_WME))))
return;
event_len= longlong10_to_str(uint8korr(val), buf + val_offset,-10)-buf;
event_len= longlong10_to_str(uint8korr(val), buf + val_offset,
((flags & User_var_log_event::UNSIGNED_F) ?
10 : -10))-buf;
break;
case DECIMAL_RESULT:
{
@ -5518,12 +5520,14 @@ User_var_log_event(const char* buf,
:Log_event(buf, description_event)
{
/* The Post-Header is empty. The Variable Data part begins immediately. */
const char *start= buf;
buf+= description_event->common_header_len +
description_event->post_header_len[USER_VAR_EVENT-1];
name_len= uint4korr(buf);
name= (char *) buf + UV_NAME_LEN_SIZE;
buf+= UV_NAME_LEN_SIZE + name_len;
is_null= (bool) *buf;
flags= User_var_log_event::UNDEF_F; // defaults to UNDEF_F
if (is_null)
{
type= STRING_RESULT;
@ -5539,6 +5543,27 @@ User_var_log_event(const char* buf,
UV_CHARSET_NUMBER_SIZE);
val= (char *) (buf + UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE +
UV_CHARSET_NUMBER_SIZE + UV_VAL_LEN_SIZE);
/**
We need to check if this is from an old server
that did not pack information for flags.
We do this by checking if there are extra bytes
after the packed value. If there are we take the
extra byte and it's value is assumed to contain
the flags value.
Old events will not have this extra byte, thence,
we keep the flags set to UNDEF_F.
*/
uint bytes_read= ((val + val_len) - start);
DBUG_ASSERT(bytes_read==data_written ||
bytes_read==(data_written-1));
if ((data_written - bytes_read) > 0)
{
flags= (uint) *(buf + UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE +
UV_CHARSET_NUMBER_SIZE + UV_VAL_LEN_SIZE +
val_len);
}
}
}
@ -5550,6 +5575,7 @@ bool User_var_log_event::write(IO_CACHE* file)
char buf1[UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE +
UV_CHARSET_NUMBER_SIZE + UV_VAL_LEN_SIZE];
uchar buf2[max(8, DECIMAL_MAX_FIELD_SIZE + 2)], *pos= buf2;
uint unsigned_len= 0;
uint buf1_length;
ulong event_length;
@ -5571,6 +5597,7 @@ bool User_var_log_event::write(IO_CACHE* file)
break;
case INT_RESULT:
int8store(buf2, *(longlong*) val);
unsigned_len= 1;
break;
case DECIMAL_RESULT:
{
@ -5595,13 +5622,14 @@ bool User_var_log_event::write(IO_CACHE* file)
}
/* Length of the whole event */
event_length= sizeof(buf)+ name_len + buf1_length + val_len;
event_length= sizeof(buf)+ name_len + buf1_length + val_len + unsigned_len;
return (write_header(file, event_length) ||
my_b_safe_write(file, (uchar*) buf, sizeof(buf)) ||
my_b_safe_write(file, (uchar*) name, name_len) ||
my_b_safe_write(file, (uchar*) buf1, buf1_length) ||
my_b_safe_write(file, pos, val_len));
my_b_safe_write(file, pos, val_len) ||
my_b_safe_write(file, (uchar*) &flags, unsigned_len));
}
#endif
@ -5642,7 +5670,8 @@ void User_var_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
break;
case INT_RESULT:
char int_buf[22];
longlong10_to_str(uint8korr(val), int_buf, -10);
longlong10_to_str(uint8korr(val), int_buf,
((flags & User_var_log_event::UNSIGNED_F) ? 10 : -10));
my_b_printf(&cache, ":=%s%s\n", int_buf, print_event_info->delimiter);
break;
case DECIMAL_RESULT:
@ -5789,7 +5818,8 @@ int User_var_log_event::do_apply_event(Relay_log_info const *rli)
a single record and with a single column. Thus, like
a column value, it could always have IMPLICIT derivation.
*/
e.update_hash(val, val_len, type, charset, DERIVATION_IMPLICIT, 0);
e.update_hash(val, val_len, type, charset, DERIVATION_IMPLICIT,
(flags & User_var_log_event::UNSIGNED_F));
free_root(thd->mem_root,0);
return 0;