Skip to content

Commit

Permalink
MDEV-35646: Limit pseudo_thread_id to UINT32_MAX
Browse files Browse the repository at this point in the history
Although the `my_thread_id` type is 64 bits, binlog format specs
limits it to 32 bits in practice. (See also: MDEV-35706)

The writable SQL variable `pseudo_thread_id` didn’t realize this though
and had a range of `ULONGLONG_MAX` (at least `UINT64_MAX` in C/C++).
It consequentially accepted larger values silently, but only the lower
32 bits of whom gets binlogged; this could lead to inconsistency.
  • Loading branch information
ParadoxV5 committed Jan 13, 2025
1 parent 04408ff commit b501593
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/my_pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ extern pthread_mutexattr_t my_errorcheck_mutexattr;
#endif

typedef uint64 my_thread_id;
#define MY_THREAD_ID_MAX UINT32_MAX //< @see MDEV-35706

extern void my_threadattr_global_init(void);
extern my_bool my_thread_global_init(void);
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/sys_vars/r/sysvars_server_embedded.result
Original file line number Diff line number Diff line change
Expand Up @@ -2877,7 +2877,7 @@ VARIABLE_SCOPE SESSION ONLY
VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT This variable is for internal server use
NUMERIC_MIN_VALUE 0
NUMERIC_MAX_VALUE 18446744073709551615
NUMERIC_MAX_VALUE 4294967295
NUMERIC_BLOCK_SIZE 1
ENUM_VALUE_LIST NULL
READ_ONLY NO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3037,7 +3037,7 @@ VARIABLE_SCOPE SESSION ONLY
VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT This variable is for internal server use
NUMERIC_MIN_VALUE 0
NUMERIC_MAX_VALUE 18446744073709551615
NUMERIC_MAX_VALUE 4294967295
NUMERIC_BLOCK_SIZE 1
ENUM_VALUE_LIST NULL
READ_ONLY NO
Expand Down
2 changes: 1 addition & 1 deletion sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9778,7 +9778,7 @@ void init_server_psi_keys(void)
*/

static my_thread_id thread_id_max= UINT_MAX32;
static my_thread_id thread_id_max= MY_THREAD_ID_MAX;

#include <vector>
#include <algorithm>
Expand Down
2 changes: 1 addition & 1 deletion sql/sys_vars.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1767,7 +1767,7 @@ Sys_pseudo_thread_id(
"pseudo_thread_id",
"This variable is for internal server use",
SESSION_ONLY(pseudo_thread_id),
NO_CMD_LINE, VALID_RANGE(0, ULONGLONG_MAX), DEFAULT(0),
NO_CMD_LINE, VALID_RANGE(0, MY_THREAD_ID_MAX), DEFAULT(0),
BLOCK_SIZE(1), NO_MUTEX_GUARD, IN_BINLOG);

static bool
Expand Down

0 comments on commit b501593

Please sign in to comment.