Commit 08687f7e authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: my_checksum

remove my_crc_dbug_check (gdb can do it itself).
use 0 instead of my_checkum(0, 0, 0) - just as 10.0 does now.
parent 66b9a940
...@@ -615,7 +615,6 @@ my_off_t my_b_safe_tell(IO_CACHE* info); /* picks the correct tell() */ ...@@ -615,7 +615,6 @@ my_off_t my_b_safe_tell(IO_CACHE* info); /* picks the correct tell() */
int my_b_pread(IO_CACHE *info, uchar *Buffer, size_t Count, my_off_t pos); int my_b_pread(IO_CACHE *info, uchar *Buffer, size_t Count, my_off_t pos);
typedef uint32 ha_checksum; typedef uint32 ha_checksum;
extern ulong my_crc_dbug_check;
#include <my_alloc.h> #include <my_alloc.h>
......
SET @start_global_value = @@global.debug_crc_break;
select @@global.debug_crc_break;
@@global.debug_crc_break
0
select @@session.debug_crc_break;
ERROR HY000: Variable 'debug_crc_break' is a GLOBAL variable
show global variables like 'debug_crc_break';
Variable_name Value
debug_crc_break 0
show session variables like 'debug_crc_break';
Variable_name Value
debug_crc_break 0
select * from information_schema.global_variables where variable_name='debug_crc_break';
VARIABLE_NAME VARIABLE_VALUE
DEBUG_CRC_BREAK 0
select * from information_schema.session_variables where variable_name='debug_crc_break';
VARIABLE_NAME VARIABLE_VALUE
DEBUG_CRC_BREAK 0
set global debug_crc_break=1;
select @@global.debug_crc_break;
@@global.debug_crc_break
1
set session debug_crc_break=1;
ERROR HY000: Variable 'debug_crc_break' is a GLOBAL variable and should be set with SET GLOBAL
set global debug_crc_break=1.1;
ERROR 42000: Incorrect argument type to variable 'debug_crc_break'
set global debug_crc_break=1e1;
ERROR 42000: Incorrect argument type to variable 'debug_crc_break'
set global debug_crc_break="foo";
ERROR 42000: Incorrect argument type to variable 'debug_crc_break'
set global debug_crc_break=0;
select @@global.debug_crc_break;
@@global.debug_crc_break
0
set global debug_crc_break=cast(-1 as unsigned int);
select @@global.debug_crc_break;
@@global.debug_crc_break
18446744073709551615
SET @@global.debug_crc_break = @start_global_value;
...@@ -29,20 +29,6 @@ NUMERIC_BLOCK_SIZE 1 ...@@ -29,20 +29,6 @@ NUMERIC_BLOCK_SIZE 1
ENUM_VALUE_LIST NULL ENUM_VALUE_LIST NULL
READ_ONLY NO READ_ONLY NO
COMMAND_LINE_ARGUMENT REQUIRED COMMAND_LINE_ARGUMENT REQUIRED
VARIABLE_NAME DEBUG_CRC_BREAK
SESSION_VALUE NULL
GLOBAL_VALUE 0
GLOBAL_VALUE_ORIGIN COMPILE-TIME
DEFAULT_VALUE 0
VARIABLE_SCOPE GLOBAL
VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT Call my_debug_put_break_here() if crc matches this number (for debug)
NUMERIC_MIN_VALUE 0
NUMERIC_MAX_VALUE 18446744073709551615
NUMERIC_BLOCK_SIZE 1
ENUM_VALUE_LIST NULL
READ_ONLY NO
COMMAND_LINE_ARGUMENT REQUIRED
VARIABLE_NAME DEBUG_DBUG VARIABLE_NAME DEBUG_DBUG
SESSION_VALUE SESSION_VALUE
GLOBAL_VALUE GLOBAL_VALUE
......
--source include/have_debug.inc
# ulong global
SET @start_global_value = @@global.debug_crc_break;
#
# exists as global only
#
select @@global.debug_crc_break;
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
select @@session.debug_crc_break;
show global variables like 'debug_crc_break';
show session variables like 'debug_crc_break';
select * from information_schema.global_variables where variable_name='debug_crc_break';
select * from information_schema.session_variables where variable_name='debug_crc_break';
#
# show that it's writable
#
set global debug_crc_break=1;
select @@global.debug_crc_break;
--error ER_GLOBAL_VARIABLE
set session debug_crc_break=1;
#
# incorrect types
#
--error ER_WRONG_TYPE_FOR_VAR
set global debug_crc_break=1.1;
--error ER_WRONG_TYPE_FOR_VAR
set global debug_crc_break=1e1;
--error ER_WRONG_TYPE_FOR_VAR
set global debug_crc_break="foo";
#
# min/max values
#
set global debug_crc_break=0;
select @@global.debug_crc_break;
--disable_warnings
set global debug_crc_break=cast(-1 as unsigned int);
--enable_warnings
--replace_result 4294967295 18446744073709551615
select @@global.debug_crc_break;
SET @@global.debug_crc_break = @start_global_value;
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
#include <my_sys.h> #include <my_sys.h>
#include <zlib.h> #include <zlib.h>
ulong my_crc_dbug_check= ~0; /* Cannot happen */
/* /*
Calculate a long checksum for a memoryblock. Calculate a long checksum for a memoryblock.
...@@ -34,7 +32,5 @@ ha_checksum my_checksum(ha_checksum crc, const uchar *pos, size_t length) ...@@ -34,7 +32,5 @@ ha_checksum my_checksum(ha_checksum crc, const uchar *pos, size_t length)
{ {
crc= (ha_checksum) crc32((uint)crc, pos, (uint) length); crc= (ha_checksum) crc32((uint)crc, pos, (uint) length);
DBUG_PRINT("info", ("crc: %lu", (ulong) crc)); DBUG_PRINT("info", ("crc: %lu", (ulong) crc));
if ((ulong)crc == my_crc_dbug_check)
my_debug_put_break_here();
return crc; return crc;
} }
...@@ -6585,7 +6585,7 @@ int MYSQL_BIN_LOG::write_cache(THD *thd, IO_CACHE *cache) ...@@ -6585,7 +6585,7 @@ int MYSQL_BIN_LOG::write_cache(THD *thd, IO_CACHE *cache)
long val; long val;
ulong end_log_pos_inc= 0; // each event processed adds BINLOG_CHECKSUM_LEN 2 t ulong end_log_pos_inc= 0; // each event processed adds BINLOG_CHECKSUM_LEN 2 t
uchar header[LOG_EVENT_HEADER_LEN]; uchar header[LOG_EVENT_HEADER_LEN];
ha_checksum crc= 0, crc_0= 0; ha_checksum crc= 0;
my_bool do_checksum= (binlog_checksum_options != BINLOG_CHECKSUM_ALG_OFF); my_bool do_checksum= (binlog_checksum_options != BINLOG_CHECKSUM_ALG_OFF);
uchar buf[BINLOG_CHECKSUM_LEN]; uchar buf[BINLOG_CHECKSUM_LEN];
DBUG_ENTER("MYSQL_BIN_LOG::write_cache"); DBUG_ENTER("MYSQL_BIN_LOG::write_cache");
...@@ -6655,7 +6655,7 @@ int MYSQL_BIN_LOG::write_cache(THD *thd, IO_CACHE *cache) ...@@ -6655,7 +6655,7 @@ int MYSQL_BIN_LOG::write_cache(THD *thd, IO_CACHE *cache)
if (do_checksum) if (do_checksum)
{ {
DBUG_ASSERT(crc == crc_0 && remains == 0); DBUG_ASSERT(crc == 0 && remains == 0);
crc= my_checksum(crc, header, carry); crc= my_checksum(crc, header, carry);
remains= uint4korr(header + EVENT_LEN_OFFSET) - carry - remains= uint4korr(header + EVENT_LEN_OFFSET) - carry -
BINLOG_CHECKSUM_LEN; BINLOG_CHECKSUM_LEN;
...@@ -6678,7 +6678,7 @@ int MYSQL_BIN_LOG::write_cache(THD *thd, IO_CACHE *cache) ...@@ -6678,7 +6678,7 @@ int MYSQL_BIN_LOG::write_cache(THD *thd, IO_CACHE *cache)
if (do_checksum && hdr_offs >= length) if (do_checksum && hdr_offs >= length)
{ {
DBUG_ASSERT(remains != 0 && crc != crc_0); DBUG_ASSERT(remains != 0 && crc != 0);
crc= my_checksum(crc, cache->read_pos, length); crc= my_checksum(crc, cache->read_pos, length);
remains -= length; remains -= length;
...@@ -6689,7 +6689,7 @@ int MYSQL_BIN_LOG::write_cache(THD *thd, IO_CACHE *cache) ...@@ -6689,7 +6689,7 @@ int MYSQL_BIN_LOG::write_cache(THD *thd, IO_CACHE *cache)
int4store(buf, crc); int4store(buf, crc);
if (my_b_write(&log_file, buf, BINLOG_CHECKSUM_LEN)) if (my_b_write(&log_file, buf, BINLOG_CHECKSUM_LEN))
DBUG_RETURN(ER_ERROR_ON_WRITE); DBUG_RETURN(ER_ERROR_ON_WRITE);
crc= crc_0; crc= 0;
} }
} }
...@@ -6708,7 +6708,7 @@ int MYSQL_BIN_LOG::write_cache(THD *thd, IO_CACHE *cache) ...@@ -6708,7 +6708,7 @@ int MYSQL_BIN_LOG::write_cache(THD *thd, IO_CACHE *cache)
finish off with remains of the last event that crawls finish off with remains of the last event that crawls
from previous into the current buffer from previous into the current buffer
*/ */
DBUG_ASSERT(crc != crc_0); DBUG_ASSERT(crc != 0);
crc= my_checksum(crc, cache->read_pos, hdr_offs); crc= my_checksum(crc, cache->read_pos, hdr_offs);
int4store(buf, crc); int4store(buf, crc);
remains -= hdr_offs; remains -= hdr_offs;
...@@ -6716,7 +6716,7 @@ int MYSQL_BIN_LOG::write_cache(THD *thd, IO_CACHE *cache) ...@@ -6716,7 +6716,7 @@ int MYSQL_BIN_LOG::write_cache(THD *thd, IO_CACHE *cache)
if (my_b_write(&log_file, cache->read_pos, hdr_offs) || if (my_b_write(&log_file, cache->read_pos, hdr_offs) ||
my_b_write(&log_file, buf, BINLOG_CHECKSUM_LEN)) my_b_write(&log_file, buf, BINLOG_CHECKSUM_LEN))
DBUG_RETURN(ER_ERROR_ON_WRITE); DBUG_RETURN(ER_ERROR_ON_WRITE);
crc= crc_0; crc= 0;
} }
} }
...@@ -6753,7 +6753,7 @@ int MYSQL_BIN_LOG::write_cache(THD *thd, IO_CACHE *cache) ...@@ -6753,7 +6753,7 @@ int MYSQL_BIN_LOG::write_cache(THD *thd, IO_CACHE *cache)
int4store(buf, crc); int4store(buf, crc);
if (my_b_write(&log_file, buf, BINLOG_CHECKSUM_LEN)) if (my_b_write(&log_file, buf, BINLOG_CHECKSUM_LEN))
DBUG_RETURN(ER_ERROR_ON_WRITE); DBUG_RETURN(ER_ERROR_ON_WRITE);
crc= crc_0; // crc is complete crc= 0; // crc is complete
} }
} }
...@@ -6787,7 +6787,7 @@ int MYSQL_BIN_LOG::write_cache(THD *thd, IO_CACHE *cache) ...@@ -6787,7 +6787,7 @@ int MYSQL_BIN_LOG::write_cache(THD *thd, IO_CACHE *cache)
DBUG_ASSERT(carry == 0); DBUG_ASSERT(carry == 0);
DBUG_ASSERT(!do_checksum || remains == 0); DBUG_ASSERT(!do_checksum || remains == 0);
DBUG_ASSERT(!do_checksum || crc == crc_0); DBUG_ASSERT(!do_checksum || crc == 0);
DBUG_RETURN(0); // All OK DBUG_RETURN(0); // All OK
} }
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include <base64.h> #include <base64.h>
#include <my_bitmap.h> #include <my_bitmap.h>
#include "rpl_utility.h" #include "rpl_utility.h"
#include "rpl_constants.h"
#include "sql_digest.h" #include "sql_digest.h"
#define my_b_write_string(A, B) my_b_write((A), (uchar*)(B), (uint) (sizeof(B) - 1)) #define my_b_write_string(A, B) my_b_write((A), (uchar*)(B), (uint) (sizeof(B) - 1))
...@@ -3750,7 +3751,7 @@ Query_log_event::dummy_event(String *packet, ulong ev_offset, ...@@ -3750,7 +3751,7 @@ Query_log_event::dummy_event(String *packet, ulong ev_offset,
if (checksum_alg == BINLOG_CHECKSUM_ALG_CRC32) if (checksum_alg == BINLOG_CHECKSUM_ALG_CRC32)
{ {
ha_checksum crc= my_checksum(0L, p, data_len); ha_checksum crc= my_checksum(0, p, data_len);
int4store(p + data_len, crc); int4store(p + data_len, crc);
} }
return 0; return 0;
...@@ -3815,7 +3816,7 @@ Query_log_event::begin_event(String *packet, ulong ev_offset, ...@@ -3815,7 +3816,7 @@ Query_log_event::begin_event(String *packet, ulong ev_offset,
if (checksum_alg == BINLOG_CHECKSUM_ALG_CRC32) if (checksum_alg == BINLOG_CHECKSUM_ALG_CRC32)
{ {
ha_checksum crc= my_checksum(0L, p, data_len); ha_checksum crc= my_checksum(0, p, data_len);
int4store(p + data_len, crc); int4store(p + data_len, crc);
} }
return 0; return 0;
......
...@@ -1192,10 +1192,8 @@ bool event_checksum_test(uchar *event_buf, ulong event_len, uint8 alg) ...@@ -1192,10 +1192,8 @@ bool event_checksum_test(uchar *event_buf, ulong event_len, uint8 alg)
compile_time_assert(BINLOG_CHECKSUM_ALG_ENUM_END <= 0x80); compile_time_assert(BINLOG_CHECKSUM_ALG_ENUM_END <= 0x80);
} }
incoming= uint4korr(event_buf + event_len - BINLOG_CHECKSUM_LEN); incoming= uint4korr(event_buf + event_len - BINLOG_CHECKSUM_LEN);
computed= 0; /* checksum the event content without the checksum part itself */
/* checksum the event content but the checksum part itself */ computed= my_checksum(0, event_buf, event_len - BINLOG_CHECKSUM_LEN);
computed= my_checksum(computed, (const uchar*) event_buf,
event_len - BINLOG_CHECKSUM_LEN);
if (flags != 0) if (flags != 0)
{ {
/* restoring the orig value of flags of FD */ /* restoring the orig value of flags of FD */
......
...@@ -404,11 +404,11 @@ inline void fix_checksum(String *packet, ulong ev_offset) ...@@ -404,11 +404,11 @@ inline void fix_checksum(String *packet, ulong ev_offset)
{ {
/* recalculate the crc for this event */ /* recalculate the crc for this event */
uint data_len = uint4korr(packet->ptr() + ev_offset + EVENT_LEN_OFFSET); uint data_len = uint4korr(packet->ptr() + ev_offset + EVENT_LEN_OFFSET);
ha_checksum crc= my_checksum(0L, NULL, 0); ha_checksum crc;
DBUG_ASSERT(data_len == DBUG_ASSERT(data_len ==
LOG_EVENT_MINIMAL_HEADER_LEN + FORMAT_DESCRIPTION_HEADER_LEN + LOG_EVENT_MINIMAL_HEADER_LEN + FORMAT_DESCRIPTION_HEADER_LEN +
BINLOG_CHECKSUM_ALG_DESC_LEN + BINLOG_CHECKSUM_LEN); BINLOG_CHECKSUM_ALG_DESC_LEN + BINLOG_CHECKSUM_LEN);
crc= my_checksum(crc, (uchar *)packet->ptr() + ev_offset, data_len - crc= my_checksum(0, (uchar *)packet->ptr() + ev_offset, data_len -
BINLOG_CHECKSUM_LEN); BINLOG_CHECKSUM_LEN);
int4store(packet->ptr() + ev_offset + data_len - BINLOG_CHECKSUM_LEN, crc); int4store(packet->ptr() + ev_offset + data_len - BINLOG_CHECKSUM_LEN, crc);
} }
...@@ -810,8 +810,7 @@ static int send_heartbeat_event(binlog_send_info *info, ...@@ -810,8 +810,7 @@ static int send_heartbeat_event(binlog_send_info *info,
if (do_checksum) if (do_checksum)
{ {
char b[BINLOG_CHECKSUM_LEN]; char b[BINLOG_CHECKSUM_LEN];
ha_checksum crc; ha_checksum crc= my_checksum(0, (uchar*) header, sizeof(header));
crc= my_checksum(0, (uchar*) header, sizeof(header));
crc= my_checksum(crc, (uchar*) p, ident_len); crc= my_checksum(crc, (uchar*) p, ident_len);
int4store(b, crc); int4store(b, crc);
packet->append(b, sizeof(b)); packet->append(b, sizeof(b));
......
...@@ -4986,14 +4986,6 @@ static Sys_var_ulong Sys_deadlock_timeout_depth_long( ...@@ -4986,14 +4986,6 @@ static Sys_var_ulong Sys_deadlock_timeout_depth_long(
SESSION_VAR(wt_timeout_long), CMD_LINE(REQUIRED_ARG), SESSION_VAR(wt_timeout_long), CMD_LINE(REQUIRED_ARG),
VALID_RANGE(0, UINT_MAX), DEFAULT(50000000), BLOCK_SIZE(1)); VALID_RANGE(0, UINT_MAX), DEFAULT(50000000), BLOCK_SIZE(1));
#ifndef DBUG_OFF
static Sys_var_ulong Sys_debug_crc_break(
"debug_crc_break",
"Call my_debug_put_break_here() if crc matches this number (for debug)",
GLOBAL_VAR(my_crc_dbug_check), CMD_LINE(REQUIRED_ARG),
VALID_RANGE(0, ULONG_MAX), DEFAULT(0), BLOCK_SIZE(1));
#endif
static Sys_var_uint Sys_extra_port( static Sys_var_uint Sys_extra_port(
"extra_port", "extra_port",
"Extra port number to use for tcp connections in a " "Extra port number to use for tcp connections in a "
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment