forked from facebook/mysql-5.6
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return hlc timestamp for a write txn (facebook#1104) (facebook#1104)
Summary: The HLC timestamp associated with a GTID of a txn is returned as part of OK packets. The HLC timestamp is stored in session response attributes tracker field of the OK packet. The HLC is stored as a key-value pair in session response attribute - the key is 'hlc_ts' and the value is the HLC timestamp. Setting the HLC timestamp in OK packets is gated by a sysvar 'session_track_hlc'. Only a RW transaction (i.e a transaction that genarates a GTID) will have a HLC timestamp retuned in its OK packet. Reference Patch: facebook@7bfac75 Pull Request resolved: facebook#1104 Reviewed By: luqun Differential Revision: D19859262 Pulled By: bhatvinay
- Loading branch information
Showing
10 changed files
with
547 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# ==== Purpose ==== | ||
# | ||
# Ensure that the server is running with GTID support on. | ||
# | ||
# ==== Usage ==== | ||
# | ||
# --source include/have_gtid.inc | ||
|
||
--source include/have_log_bin.inc | ||
|
||
if ( `SELECT @@GLOBAL.GTID_MODE = "OFF"` ) | ||
{ | ||
--skip Test requires GTID_MODE=ON. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
mysql-test/suite/binlog_gtid/r/session_attrs_contain_hlc.result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
flush logs; | ||
purge binary logs to 'binlog'; | ||
SET SESSION DEBUG="+d,allow_long_hlc_drift_for_tests"; | ||
SET @@global.minimum_hlc_ns = 2538630000000000000; | ||
SET @@session.session_track_response_attributes = on; | ||
SET @@global.enable_binlog_hlc = true; | ||
SET @@session.response_attrs_contain_hlc = true; | ||
Case 1: Single statement txn. Commit ts needs to be updated at commit time | ||
USE test; | ||
-- Tracker : SESSION_TRACK_SCHEMA | ||
-- test | ||
|
||
-- Tracker : SESSION_TRACK_RESP_ATTR | ||
-- change_db | ||
-- test | ||
|
||
CREATE TABLE t1 (a INT PRIMARY KEY, b CHAR(8)); | ||
-- Tracker : SESSION_TRACK_RESP_ATTR | ||
-- hlc_ts | ||
-- 2538630000000000001 | ||
|
||
INSERT INTO t1 VALUES(1, 'a'); | ||
-- Tracker : SESSION_TRACK_RESP_ATTR | ||
-- hlc_ts | ||
-- 2538630000000000002 | ||
|
||
INSERT INTO t1 VALUES(2, 'b'); | ||
-- Tracker : SESSION_TRACK_RESP_ATTR | ||
-- hlc_ts | ||
-- 2538630000000000003 | ||
|
||
include/show_binlog_events.inc | ||
Log_name Pos Event_type Server_id End_log_pos Info | ||
binlog.000002 # Metadata # # HLC time: 2538630000000000001 | ||
binlog.000002 # Query # # use `test`; CREATE TABLE t1 (a INT PRIMARY KEY, b CHAR(8)) | ||
binlog.000002 # Metadata # # HLC time: 2538630000000000002 | ||
binlog.000002 # Query # # BEGIN | ||
binlog.000002 # Table_map # # table_id: # (test.t1) | ||
binlog.000002 # Write_rows # # table_id: # flags: STMT_END_F | ||
binlog.000002 # Xid # # COMMIT /* XID */ | ||
binlog.000002 # Metadata # # HLC time: 2538630000000000003 | ||
binlog.000002 # Query # # BEGIN | ||
binlog.000002 # Table_map # # table_id: # (test.t1) | ||
binlog.000002 # Write_rows # # table_id: # flags: STMT_END_F | ||
binlog.000002 # Xid # # COMMIT /* XID */ | ||
Case 2: Multi statement txn. Commit ts needs to be updated at commit time | ||
BEGIN; | ||
-- Tracker : SESSION_TRACK_TRANSACTION_STATE | ||
-- T_______ | ||
|
||
INSERT INTO t1 VALUES(3, 'c'); | ||
INSERT INTO t1 VALUES(4, 'd'); | ||
COMMIT; | ||
-- Tracker : SESSION_TRACK_TRANSACTION_STATE | ||
-- ________ | ||
|
||
-- Tracker : SESSION_TRACK_RESP_ATTR | ||
-- hlc_ts | ||
-- 2538630000000000004 | ||
|
||
SELECT * FROM t1; | ||
a b | ||
1 a | ||
2 b | ||
3 c | ||
4 d | ||
include/show_binlog_events.inc | ||
Log_name Pos Event_type Server_id End_log_pos Info | ||
binlog.000002 # Metadata # # HLC time: 2538630000000000001 | ||
binlog.000002 # Query # # use `test`; CREATE TABLE t1 (a INT PRIMARY KEY, b CHAR(8)) | ||
binlog.000002 # Metadata # # HLC time: 2538630000000000002 | ||
binlog.000002 # Query # # BEGIN | ||
binlog.000002 # Table_map # # table_id: # (test.t1) | ||
binlog.000002 # Write_rows # # table_id: # flags: STMT_END_F | ||
binlog.000002 # Xid # # COMMIT /* XID */ | ||
binlog.000002 # Metadata # # HLC time: 2538630000000000003 | ||
binlog.000002 # Query # # BEGIN | ||
binlog.000002 # Table_map # # table_id: # (test.t1) | ||
binlog.000002 # Write_rows # # table_id: # flags: STMT_END_F | ||
binlog.000002 # Xid # # COMMIT /* XID */ | ||
binlog.000002 # Metadata # # HLC time: 2538630000000000004 | ||
binlog.000002 # Query # # BEGIN | ||
binlog.000002 # Table_map # # table_id: # (test.t1) | ||
binlog.000002 # Write_rows # # table_id: # flags: STMT_END_F | ||
binlog.000002 # Table_map # # table_id: # (test.t1) | ||
binlog.000002 # Write_rows # # table_id: # flags: STMT_END_F | ||
binlog.000002 # Xid # # COMMIT /* XID */ | ||
Case 3: Turning off binlog_hlc should stop sending hlc in ok packets | ||
SET @@global.enable_binlog_hlc = false; | ||
SET @@session.response_attrs_contain_hlc = true; | ||
INSERT INTO t1 VALUES(5, 'e'); | ||
COMMIT; | ||
include/show_binlog_events.inc | ||
Log_name Pos Event_type Server_id End_log_pos Info | ||
binlog.000002 # Metadata # # HLC time: 2538630000000000001 | ||
binlog.000002 # Query # # use `test`; CREATE TABLE t1 (a INT PRIMARY KEY, b CHAR(8)) | ||
binlog.000002 # Metadata # # HLC time: 2538630000000000002 | ||
binlog.000002 # Query # # BEGIN | ||
binlog.000002 # Table_map # # table_id: # (test.t1) | ||
binlog.000002 # Write_rows # # table_id: # flags: STMT_END_F | ||
binlog.000002 # Xid # # COMMIT /* XID */ | ||
binlog.000002 # Metadata # # HLC time: 2538630000000000003 | ||
binlog.000002 # Query # # BEGIN | ||
binlog.000002 # Table_map # # table_id: # (test.t1) | ||
binlog.000002 # Write_rows # # table_id: # flags: STMT_END_F | ||
binlog.000002 # Xid # # COMMIT /* XID */ | ||
binlog.000002 # Metadata # # HLC time: 2538630000000000004 | ||
binlog.000002 # Query # # BEGIN | ||
binlog.000002 # Table_map # # table_id: # (test.t1) | ||
binlog.000002 # Write_rows # # table_id: # flags: STMT_END_F | ||
binlog.000002 # Table_map # # table_id: # (test.t1) | ||
binlog.000002 # Write_rows # # table_id: # flags: STMT_END_F | ||
binlog.000002 # Xid # # COMMIT /* XID */ | ||
binlog.000002 # Query # # BEGIN | ||
binlog.000002 # Table_map # # table_id: # (test.t1) | ||
binlog.000002 # Write_rows # # table_id: # flags: STMT_END_F | ||
binlog.000002 # Xid # # COMMIT /* XID */ | ||
Case 4: Turning off response_attrs_contain_hlc should stop sending hlc in ok packets | ||
SET @@global.enable_binlog_hlc = true; | ||
SET @@session.response_attrs_contain_hlc = false; | ||
INSERT INTO t1 VALUES(6, 'f'); | ||
COMMIT; | ||
include/show_binlog_events.inc | ||
Log_name Pos Event_type Server_id End_log_pos Info | ||
binlog.000002 # Metadata # # HLC time: 2538630000000000001 | ||
binlog.000002 # Query # # use `test`; CREATE TABLE t1 (a INT PRIMARY KEY, b CHAR(8)) | ||
binlog.000002 # Metadata # # HLC time: 2538630000000000002 | ||
binlog.000002 # Query # # BEGIN | ||
binlog.000002 # Table_map # # table_id: # (test.t1) | ||
binlog.000002 # Write_rows # # table_id: # flags: STMT_END_F | ||
binlog.000002 # Xid # # COMMIT /* XID */ | ||
binlog.000002 # Metadata # # HLC time: 2538630000000000003 | ||
binlog.000002 # Query # # BEGIN | ||
binlog.000002 # Table_map # # table_id: # (test.t1) | ||
binlog.000002 # Write_rows # # table_id: # flags: STMT_END_F | ||
binlog.000002 # Xid # # COMMIT /* XID */ | ||
binlog.000002 # Metadata # # HLC time: 2538630000000000004 | ||
binlog.000002 # Query # # BEGIN | ||
binlog.000002 # Table_map # # table_id: # (test.t1) | ||
binlog.000002 # Write_rows # # table_id: # flags: STMT_END_F | ||
binlog.000002 # Table_map # # table_id: # (test.t1) | ||
binlog.000002 # Write_rows # # table_id: # flags: STMT_END_F | ||
binlog.000002 # Xid # # COMMIT /* XID */ | ||
binlog.000002 # Query # # BEGIN | ||
binlog.000002 # Table_map # # table_id: # (test.t1) | ||
binlog.000002 # Write_rows # # table_id: # flags: STMT_END_F | ||
binlog.000002 # Xid # # COMMIT /* XID */ | ||
binlog.000002 # Metadata # # HLC time: 2538630000000000005 | ||
binlog.000002 # Query # # BEGIN | ||
binlog.000002 # Table_map # # table_id: # (test.t1) | ||
binlog.000002 # Write_rows # # table_id: # flags: STMT_END_F | ||
binlog.000002 # Xid # # COMMIT /* XID */ | ||
USE test; | ||
-- Tracker : SESSION_TRACK_SCHEMA | ||
-- test | ||
|
||
-- Tracker : SESSION_TRACK_RESP_ATTR | ||
-- change_db | ||
-- test | ||
|
||
DROP TABLE t1; |
1 change: 1 addition & 0 deletions
1
mysql-test/suite/binlog_gtid/t/session_attrs_contain_hlc-master.opt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--force-restart |
81 changes: 81 additions & 0 deletions
81
mysql-test/suite/binlog_gtid/t/session_attrs_contain_hlc.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
--source include/have_binlog_format_row.inc | ||
--source include/have_debug.inc | ||
--source include/have_gtid.inc | ||
|
||
--enable_session_track_info | ||
|
||
--let $saved_minimum_hlc_ns= `SELECT @@global.minimum_hlc_ns` | ||
--let $saved_enable_binlog_hlc= `SELECT @@global.enable_binlog_hlc` | ||
--let $saved_response_attrs_contain_hlc= `SELECT @@session.response_attrs_contain_hlc` | ||
|
||
# Cleanup old binlog | ||
flush logs; | ||
let $binlog= query_get_value(SHOW MASTER STATUS, File, 1); | ||
replace_result $binlog binlog; | ||
eval purge binary logs to '$binlog'; | ||
|
||
# Setup | ||
# Set minimum_hlc_ns to a high value. Subsequent txn's should see monotonically | ||
# increasing timestamp from this point | ||
SET SESSION DEBUG="+d,allow_long_hlc_drift_for_tests"; | ||
SET @@global.minimum_hlc_ns = 2538630000000000000; # ~2050 AD | ||
|
||
# Enable tracking response attribute | ||
SET @@session.session_track_response_attributes = on; | ||
|
||
# Enable binlog_hlc | ||
SET @@global.enable_binlog_hlc = true; | ||
|
||
# Enable session to track HLC | ||
SET @@session.response_attrs_contain_hlc = true; | ||
|
||
# Case 1: Enable binlog HLC and run a single statement txn | ||
--echo Case 1: Single statement txn. Commit ts needs to be updated at commit time | ||
USE test; | ||
|
||
CREATE TABLE t1 (a INT PRIMARY KEY, b CHAR(8)); | ||
INSERT INTO t1 VALUES(1, 'a'); | ||
INSERT INTO t1 VALUES(2, 'b'); | ||
--source include/show_binlog_events.inc | ||
|
||
# Case 2: Enable binlog HLC and run multi statement txn | ||
--echo Case 2: Multi statement txn. Commit ts needs to be updated at commit time | ||
BEGIN; | ||
INSERT INTO t1 VALUES(3, 'c'); | ||
INSERT INTO t1 VALUES(4, 'd'); | ||
COMMIT; | ||
|
||
SELECT * FROM t1; | ||
|
||
--source include/show_binlog_events.inc | ||
|
||
# Case 3: Turning off binlog_hlc should stop sending hlc in ok packets | ||
--echo Case 3: Turning off binlog_hlc should stop sending hlc in ok packets | ||
# Disable binlog_hlc | ||
SET @@global.enable_binlog_hlc = false; | ||
|
||
# Enable session to track HLC | ||
SET @@session.response_attrs_contain_hlc = true; | ||
INSERT INTO t1 VALUES(5, 'e'); | ||
COMMIT; | ||
|
||
--source include/show_binlog_events.inc | ||
|
||
# Case 4: Turning off response_attrs_contain_hlc should stop sending hlc in ok packets even though binlog_hlc is enabled | ||
--echo Case 4: Turning off response_attrs_contain_hlc should stop sending hlc in ok packets | ||
SET @@global.enable_binlog_hlc = true; | ||
SET @@session.response_attrs_contain_hlc = false; | ||
INSERT INTO t1 VALUES(6, 'f'); | ||
COMMIT; | ||
|
||
--source include/show_binlog_events.inc | ||
|
||
# Cleanup | ||
USE test; | ||
DROP TABLE t1; | ||
--disable_query_log | ||
--eval SET GLOBAL minimum_hlc_ns = $saved_minimum_hlc_ns | ||
--eval SET GLOBAL enable_binlog_hlc = $saved_enable_binlog_hlc | ||
--eval SET SESSION response_attrs_contain_hlc = $saved_response_attrs_contain_hlc | ||
--eval SET SESSION DEBUG="-d,allow_long_hlc_drift_for_tests" | ||
--enable_query_log |
Oops, something went wrong.