-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PS-9391 Fixes replication break error because of HASH_SCAN #5528
base: 8.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
include/master-slave.inc | ||
Warnings: | ||
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure. | ||
Note #### Storing MySQL user name or password information in the connection metadata repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START REPLICA; see the 'START REPLICA Syntax' in the MySQL Manual for more information. | ||
[connection master] | ||
[connection slave] | ||
set @prior_slave_rows_search_algorithms=@@global.slave_rows_search_algorithms; | ||
Warnings: | ||
Warning 1287 '@@slave_rows_search_algorithms' is deprecated and will be removed in a future release. | ||
set @@global.slave_rows_search_algorithms= 'HASH_SCAN'; | ||
Warnings: | ||
Warning 1287 '@@slave_rows_search_algorithms' is deprecated and will be removed in a future release. | ||
[connection master] | ||
CREATE TABLE t1 (i INT, INDEX t1_i(i)); | ||
CREATE FUNCTION f1 () RETURNS INT BEGIN | ||
UPDATE t1 SET i = 11 WHERE i = 10; | ||
UPDATE t1 SET i = 12 WHERE i = 11; | ||
RETURN 0; | ||
END| | ||
include/sync_slave_sql_with_master.inc | ||
[connection master] | ||
INSERT INTO t1 VALUES (10); | ||
SELECT f1(); | ||
f1() | ||
0 | ||
include/sync_slave_sql_with_master.inc | ||
include/assert.inc ['There is only one row in table t1'] | ||
[connection master] | ||
include/diff_tables.inc [master:test.t1, slave:test.t1] | ||
CREATE FUNCTION f2 () RETURNS INT BEGIN | ||
UPDATE t1 SET i = 11 WHERE i = 12; | ||
UPDATE t1 SET i = 13 WHERE i = 11; | ||
RETURN 0; | ||
END| | ||
include/sync_slave_sql_with_master.inc | ||
[connection master] | ||
SELECT f2(); | ||
f2() | ||
0 | ||
include/sync_slave_sql_with_master.inc | ||
include/assert.inc ['There is only one row in table t1'] | ||
[connection master] | ||
include/diff_tables.inc [master:test.t1, slave:test.t1] | ||
[connection master] | ||
SELECT * FROM t1; | ||
i | ||
13 | ||
DROP FUNCTION f1; | ||
DROP FUNCTION f2; | ||
DROP TABLE t1; | ||
[connection slave] | ||
set @@global.slave_rows_search_algorithms= @prior_slave_rows_search_algorithms; | ||
Warnings: | ||
Warning 1287 '@@slave_rows_search_algorithms' is deprecated and will be removed in a future release. | ||
include/rpl_end.inc |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Bug#115741 Test whether setting slave_rows_search_algorithms to HASH_SCAN works properly | ||
# when multiple updates are targeted to the same row within a single update rows log event | ||
|
||
--source include/have_binlog_format_row.inc | ||
--source include/set_privilege_checks_user_as_system_user.inc | ||
--source include/master-slave.inc | ||
|
||
--source include/rpl_connection_slave.inc | ||
set @prior_slave_rows_search_algorithms=@@global.slave_rows_search_algorithms; | ||
set @@global.slave_rows_search_algorithms= 'HASH_SCAN'; | ||
|
||
# Scenarios considered in this test case involve a table with no primary key but an index on the column | ||
# When slave_rows_search_algorithms is set to HASH_SCAN, a list "m_distinct_keys" is created internally | ||
# to store the unique key values which, later will be used to perform a table scan to apply the events | ||
# for the rows present in the table. | ||
--source include/rpl_connection_master.inc | ||
# Create a table, with no primary key and an index. | ||
CREATE TABLE t1 (i INT, INDEX t1_i(i)); | ||
|
||
# Scenario no.1 | ||
# Sorting the elements of m_distinct_keys doesn't alter the original order of updates | ||
# Create a stored function so that only one Update_rows_log_event is generated. | ||
--delimiter | | ||
CREATE FUNCTION f1 () RETURNS INT BEGIN | ||
UPDATE t1 SET i = 11 WHERE i = 10; | ||
UPDATE t1 SET i = 12 WHERE i = 11; | ||
RETURN 0; | ||
END| | ||
--delimiter ; | ||
--source include/sync_slave_sql_with_master.inc | ||
|
||
--source include/rpl_connection_master.inc | ||
INSERT INTO t1 VALUES (10); | ||
SELECT f1(); | ||
|
||
--source include/sync_slave_sql_with_master.inc | ||
--let $assert_text= 'There is only one row in table t1' | ||
--let $assert_cond= [SELECT COUNT(*) FROM t1] = 1 | ||
--source include/assert.inc | ||
|
||
--source include/rpl_connection_master.inc | ||
|
||
# Verify that there is no difference between tables of master and slave. | ||
--let diff_tables=master:test.t1, slave:test.t1 | ||
--source include/diff_tables.inc | ||
|
||
|
||
# Scenario no.2 | ||
# Sorting the elements of m_distinct_keys ALTERs the original order of updates causing | ||
# the case where the key value from the list doesn't exist in the table yet until other | ||
# UPDATEs are executed. | ||
--delimiter | | ||
CREATE FUNCTION f2 () RETURNS INT BEGIN | ||
UPDATE t1 SET i = 11 WHERE i = 12; | ||
UPDATE t1 SET i = 13 WHERE i = 11; | ||
RETURN 0; | ||
END| | ||
--delimiter ; | ||
--source include/sync_slave_sql_with_master.inc | ||
|
||
--source include/rpl_connection_master.inc | ||
SELECT f2(); | ||
|
||
--source include/sync_slave_sql_with_master.inc | ||
--let $assert_text= 'There is only one row in table t1' | ||
--let $assert_cond= [SELECT COUNT(*) FROM t1] = 1 | ||
--source include/assert.inc | ||
|
||
--source include/rpl_connection_master.inc | ||
|
||
# Verify that there is no difference between tables of master and slave. | ||
--let diff_tables=master:test.t1, slave:test.t1 | ||
--source include/diff_tables.inc | ||
|
||
# Cleanup | ||
--source include/rpl_connection_master.inc | ||
SELECT * FROM t1; | ||
DROP FUNCTION f1; | ||
DROP FUNCTION f2; | ||
DROP TABLE t1; | ||
|
||
--source include/rpl_connection_slave.inc | ||
set @@global.slave_rows_search_algorithms= @prior_slave_rows_search_algorithms; | ||
--source include/rpl_end.inc |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ | |
#include <functional> | ||
#include <list> | ||
#include <map> | ||
#include <set> | ||
#include <unordered_set> | ||
#include <string> | ||
#include <string_view> | ||
|
||
|
@@ -2882,30 +2882,50 @@ class Rows_log_event : public virtual binary_log::Rows_event, public Log_event { | |
uchar *m_key; /* Buffer to keep key value during searches */ | ||
uint m_key_index; | ||
KEY *m_key_info; /* Points to description of index #m_key_index */ | ||
class Key_compare { | ||
class Key_equal { | ||
public: | ||
/** | ||
@param ki Where to find KEY description | ||
@note m_distinct_keys is instantiated when Rows_log_event is constructed; | ||
it stores a Key_compare object internally. However at that moment, the | ||
it stores a Key_equal object internally. However at that moment, the | ||
index (KEY*) to use for comparisons, is not yet known. So, at | ||
instantiation, we indicate the Key_compare the place where it can | ||
instantiation, we indicate the Key_equal the place where it can | ||
find the KEY* when needed (this place is Rows_log_event::m_key_info), | ||
Key_compare remembers the place in member m_key_info. | ||
Key_equal remembers the place in member m_key_info. | ||
Before we need to do comparisons - i.e. before we need to insert | ||
elements, we update Rows_log_event::m_key_info once for all. | ||
*/ | ||
Key_compare(KEY **ki = nullptr) : m_key_info(ki) {} | ||
Key_equal(KEY **ki = nullptr) : m_key_info(ki) {} | ||
bool operator()(uchar *k1, uchar *k2) const { | ||
return key_cmp2((*m_key_info)->key_part, k1, (*m_key_info)->key_length, | ||
k2, (*m_key_info)->key_length) < 0; | ||
k2, (*m_key_info)->key_length) == 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename this helper class to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} | ||
|
||
private: | ||
KEY **m_key_info; | ||
}; | ||
std::set<uchar *, Key_compare> m_distinct_keys; | ||
std::set<uchar *, Key_compare>::iterator m_itr; | ||
class Key_hash { | ||
public: | ||
Key_hash(KEY **ki = nullptr) : m_key_info(ki) {} | ||
size_t operator()(uchar* ptr) const { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be just create a std::string_view sv{ptr, (*m_key_info)->key_length};
return std::hash(sv); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion. Done. |
||
size_t hash = 0; | ||
if (ptr) { | ||
std::string_view sv{reinterpret_cast<const char*>(ptr), | ||
(*m_key_info)->key_length}; | ||
return std::hash<std::string_view>{}(sv); | ||
} | ||
return hash; | ||
} | ||
private: | ||
KEY **m_key_info; | ||
}; | ||
std::unordered_set<uchar *, Key_hash, Key_equal> m_distinct_keys; | ||
|
||
/** | ||
A linear list to store the distinct keys preserving the insert order | ||
*/ | ||
std::vector<uchar *> m_distinct_keys_original_order; | ||
std::size_t m_distinct_key_idx = 0; | ||
/** | ||
A spare buffer which will be used when saving the distinct keys | ||
for doing an index scan with HASH_SCAN search algorithm. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we change this to
m_distinct_key_id = 0
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m_distinct_key_idx is already set to 0 when it is declared.