Skip to content

Commit 036ee61

Browse files
committed
MDEV-20220: Merge 5.7 P_S replication table 'replication_applier_status_by_worker
Step2: ===== Add two extra columns mentioned below. --------------------------------------------------------------------------- |Column Name: | Description: | |-------------------------------------------------------------------------| | | | |WORKER_IDLE_TIME | Total idle time in seconds that the worker | | | thread has spent waiting for work from | | | co-ordinator thread | | | | |LAST_TRANS_RETRY_COUNT | Total number of retries attempted by last | | | transaction | ---------------------------------------------------------------------------
1 parent 94f1d0f commit 036ee61

9 files changed

+93
-32
lines changed

mysql-test/suite/perfschema/r/table_schema.result

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,8 @@ def performance_schema replication_applier_status_by_worker LAST_SEEN_TRANSACTIO
872872
def performance_schema replication_applier_status_by_worker LAST_ERROR_NUMBER 5 NULL NO int NULL NULL 10 0 NULL NULL NULL int(11) select,insert,update,references NEVER NULL
873873
def performance_schema replication_applier_status_by_worker LAST_ERROR_MESSAGE 6 NULL NO varchar 1024 3072 NULL NULL NULL utf8 utf8_general_ci varchar(1024) select,insert,update,references NEVER NULL
874874
def performance_schema replication_applier_status_by_worker LAST_ERROR_TIMESTAMP 7 current_timestamp() NO timestamp NULL NULL NULL NULL 0 NULL NULL timestamp on update current_timestamp() select,insert,update,references NEVER NULL
875+
def performance_schema replication_applier_status_by_worker WORKER_IDLE_TIME 8 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references NEVER NULL
876+
def performance_schema replication_applier_status_by_worker LAST_TRANS_RETRY_COUNT 9 NULL NO int NULL NULL 10 0 NULL NULL NULL int(11) select,insert,update,references NEVER NULL
875877
def performance_schema replication_connection_configuration CHANNEL_NAME 1 NULL NO char 64 192 NULL NULL NULL utf8 utf8_general_ci char(64) select,insert,update,references NEVER NULL
876878
def performance_schema replication_connection_configuration HOST 2 NULL NO char 60 180 NULL NULL NULL utf8 utf8_bin char(60) select,insert,update,references NEVER NULL
877879
def performance_schema replication_connection_configuration PORT 3 NULL NO int NULL NULL 10 0 NULL NULL NULL int(11) select,insert,update,references NEVER NULL

mysql-test/suite/rpl/r/rpl_parallel_retry.result

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ SET @old_dbug= @@GLOBAL.debug_dbug;
4949
SET GLOBAL debug_dbug="+d,rpl_parallel_simulate_temp_err_gtid_0_x_100";
5050
include/start_slave.inc
5151
SET GLOBAL debug_dbug=@old_dbug;
52-
retries
53-
1
52+
include/assert.inc [Performance Schema retries should match with actual retries]
5453
SELECT * FROM t1 ORDER BY a;
5554
a b
5655
1 2
@@ -82,8 +81,7 @@ SET @old_dbug= @@GLOBAL.debug_dbug;
8281
SET GLOBAL debug_dbug="+d,rpl_parallel_simulate_temp_err_gtid_0_x_100,rpl_parallel_simulate_double_temp_err_gtid_0_x_100";
8382
include/start_slave.inc
8483
SET GLOBAL debug_dbug=@old_dbug;
85-
retries
86-
2
84+
include/assert.inc [Performance Schema retries should match with actual retries]
8785
SELECT * FROM t1 ORDER BY a;
8886
a b
8987
1 3
@@ -179,8 +177,7 @@ SET @old_dbug= @@GLOBAL.debug_dbug;
179177
SET GLOBAL debug_dbug="+d,rpl_parallel_simulate_temp_err_gtid_0_x_100";
180178
include/start_slave.inc
181179
SET GLOBAL debug_dbug=@old_dbug;
182-
retries
183-
1
180+
include/assert.inc [Performance Schema retries should match with actual retries]
184181
SELECT * FROM t1 WHERE a >= 10 ORDER BY a;
185182
a b
186183
10 4
@@ -224,8 +221,7 @@ SET @old_dbug= @@GLOBAL.debug_dbug;
224221
SET GLOBAL debug_dbug="+d,rpl_parallel_simulate_temp_err_xid";
225222
include/start_slave.inc
226223
SET GLOBAL debug_dbug=@old_dbug;
227-
retries
228-
1
224+
include/assert.inc [Performance Schema retries should match with actual retries]
229225
SELECT * FROM t1 WHERE a >= 100 ORDER BY a;
230226
a b
231227
100 0
@@ -323,8 +319,7 @@ SET debug_sync='now WAIT_FOR t3_waiting';
323319
SET debug_sync='now SIGNAL t1_start';
324320
SET GLOBAL debug_dbug=@old_dbug;
325321
SET debug_sync='RESET';
326-
retries
327-
1
322+
include/assert.inc [Performance Schema retries should match with actual retries]
328323
SELECT * FROM t3 ORDER BY a;
329324
a b
330325
1 NULL

mysql-test/suite/rpl/r/rpl_perfschema_applier_status_by_worker.result

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ include/assert.inc [Value returned by SSS and PS table for Last_Error_Number sho
2828
include/assert.inc [Value returned by SSS and PS table for Last_Error_Message should both be empty.]
2929
include/assert.inc [Value returned by PS table for Last_Error_Timestamp should be 0000-00-00 00:00:00.]
3030
connection master;
31+
connection slave;
32+
include/assert.inc [Value returned by PS table for worker_idle_time should be >= 1]
33+
connection master;
3134
DROP TABLE t1;
3235
connection slave;
3336
STOP SLAVE 'slave1';

mysql-test/suite/rpl/t/rpl_parallel_retry.test

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,13 @@ let $old_retry= query_get_value(SHOW STATUS LIKE 'Slave_retried_transactions', V
6868
--sync_with_master
6969
SET GLOBAL debug_dbug=@old_dbug;
7070
let $new_retry= query_get_value(SHOW STATUS LIKE 'Slave_retried_transactions', Value, 1);
71-
--disable_query_log
72-
eval SELECT $new_retry - $old_retry AS retries;
73-
--enable_query_log
71+
let $ps_value= query_get_value(select last_trans_retry_count from
72+
performance_schema.replication_applier_status_by_worker where
73+
last_trans_retry_count > 0, last_trans_retry_count, 1);
74+
let $assert_text= Performance Schema retries should match with actual retries;
75+
let $assert_cond= "$ps_value" = $new_retry - $old_retry;
76+
source include/assert.inc;
77+
7478

7579
SELECT * FROM t1 ORDER BY a;
7680

@@ -100,9 +104,12 @@ let $old_retry= query_get_value(SHOW STATUS LIKE 'Slave_retried_transactions', V
100104
--sync_with_master
101105
SET GLOBAL debug_dbug=@old_dbug;
102106
let $new_retry= query_get_value(SHOW STATUS LIKE 'Slave_retried_transactions', Value, 1);
103-
--disable_query_log
104-
eval SELECT $new_retry - $old_retry AS retries;
105-
--enable_query_log
107+
let $ps_value= query_get_value(select last_trans_retry_count from
108+
performance_schema.replication_applier_status_by_worker where
109+
last_trans_retry_count > 0, last_trans_retry_count, 1);
110+
let $assert_text= Performance Schema retries should match with actual retries;
111+
let $assert_cond= "$ps_value" = $new_retry - $old_retry;
112+
source include/assert.inc;
106113

107114
SELECT * FROM t1 ORDER BY a;
108115

@@ -187,9 +194,12 @@ let $old_retry= query_get_value(SHOW STATUS LIKE 'Slave_retried_transactions', V
187194
--sync_with_master
188195
SET GLOBAL debug_dbug=@old_dbug;
189196
let $new_retry= query_get_value(SHOW STATUS LIKE 'Slave_retried_transactions', Value, 1);
190-
--disable_query_log
191-
eval SELECT $new_retry - $old_retry AS retries;
192-
--enable_query_log
197+
let $ps_value= query_get_value(select last_trans_retry_count from
198+
performance_schema.replication_applier_status_by_worker where
199+
last_trans_retry_count > 0, last_trans_retry_count, 1);
200+
let $assert_text= Performance Schema retries should match with actual retries;
201+
let $assert_cond= "$ps_value" = $new_retry - $old_retry;
202+
source include/assert.inc;
193203

194204
SELECT * FROM t1 WHERE a >= 10 ORDER BY a;
195205
SELECT a, LENGTH(b) FROM t2 ORDER BY a;
@@ -235,9 +245,12 @@ let $old_retry= query_get_value(SHOW STATUS LIKE 'Slave_retried_transactions', V
235245
--sync_with_master
236246
SET GLOBAL debug_dbug=@old_dbug;
237247
let $new_retry= query_get_value(SHOW STATUS LIKE 'Slave_retried_transactions', Value, 1);
238-
--disable_query_log
239-
eval SELECT $new_retry - $old_retry AS retries;
240-
--enable_query_log
248+
let $ps_value= query_get_value(select last_trans_retry_count from
249+
performance_schema.replication_applier_status_by_worker where
250+
last_trans_retry_count > 0, last_trans_retry_count, 1);
251+
let $assert_text= Performance Schema retries should match with actual retries;
252+
let $assert_cond= "$ps_value" = $new_retry - $old_retry;
253+
source include/assert.inc;
241254

242255
SELECT * FROM t1 WHERE a >= 100 ORDER BY a;
243256
# Stop the SQL thread. When the bug was there to give the incorrect relay log
@@ -365,9 +378,12 @@ SET debug_sync='now SIGNAL t1_start';
365378
SET GLOBAL debug_dbug=@old_dbug;
366379
SET debug_sync='RESET';
367380
let $new_retry= query_get_value(SHOW STATUS LIKE 'Slave_retried_transactions', Value, 1);
368-
--disable_query_log
369-
eval SELECT $new_retry - $old_retry >= 1 AS retries;
370-
--enable_query_log
381+
let $ps_value= query_get_value(select last_trans_retry_count from
382+
performance_schema.replication_applier_status_by_worker where
383+
last_trans_retry_count > 0, last_trans_retry_count, 1);
384+
let $assert_text= Performance Schema retries should match with actual retries;
385+
let $assert_cond= "$ps_value" = $new_retry - $old_retry;
386+
source include/assert.inc;
371387
SELECT * FROM t3 ORDER BY a;
372388

373389

mysql-test/suite/rpl/t/rpl_perfschema_applier_status_by_worker.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ let $assert_text= Value returned by PS table for Last_Error_Timestamp should be
113113
let $assert_cond= "$ps_value" = "0000-00-00 00:00:00";
114114
source include/assert.inc;
115115

116+
--connection master
117+
sleep 1;
118+
--connection slave
119+
let $ps_value= query_get_value(select worker_idle_time from performance_schema.replication_applier_status_by_worker, worker_idle_time, 1);
120+
let $assert_text= Value returned by PS table for worker_idle_time should be >= 1;
121+
let $assert_cond= "$ps_value" >= "1";
122+
source include/assert.inc;
123+
116124
--connection master
117125
DROP TABLE t1;
118126
--save_master_pos

sql/rpl_parallel.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ retry_event_group(rpl_group_info *rgi, rpl_parallel_thread *rpt,
799799

800800
mysql_mutex_lock(&rli->data_lock);
801801
++rli->retried_trans;
802+
++rpt->last_trans_retry_count;
802803
statistic_increment(slave_retried_transactions, LOCK_status);
803804
mysql_mutex_unlock(&rli->data_lock);
804805

@@ -1125,6 +1126,7 @@ handle_rpl_parallel_thread(void *arg)
11251126
uint wait_count= 0;
11261127
rpl_parallel_thread::queued_event *qev, *next_qev;
11271128

1129+
rpt->start_time_tracker();
11281130
thd->ENTER_COND(&rpt->COND_rpl_thread, &rpt->LOCK_rpl_thread,
11291131
&stage_waiting_for_work_from_sql_thread, &old_stage);
11301132
/*
@@ -1148,6 +1150,7 @@ handle_rpl_parallel_thread(void *arg)
11481150
}
11491151
rpt->dequeue1(events);
11501152
thd->EXIT_COND(&old_stage);
1153+
rpt->add_to_worker_idle_time_and_reset();
11511154

11521155
more_events:
11531156
for (qev= events; qev; qev= next_qev)
@@ -1193,6 +1196,7 @@ handle_rpl_parallel_thread(void *arg)
11931196
/* Handle a new event group, which will be initiated by a GTID event. */
11941197
if ((event_type= qev->ev->get_type_code()) == GTID_EVENT)
11951198
{
1199+
rpt->last_trans_retry_count= 0;
11961200
rpt->last_seen_gtid= rgi->current_gtid;
11971201
rpt->channel_name_length= (uint)rgi->rli->mi->connection_name.length;
11981202
if (rpt->channel_name_length)
@@ -2015,7 +2019,8 @@ rpl_parallel_thread::loc_free_gco(group_commit_orderer *gco)
20152019

20162020

20172021
rpl_parallel_thread::rpl_parallel_thread()
2018-
: channel_name_length(0), last_error_number(0), last_error_timestamp(0)
2022+
: channel_name_length(0), last_error_number(0), last_error_timestamp(0),
2023+
worker_idle_time(0), last_trans_retry_count(0), start_time(0)
20192024
{
20202025
}
20212026

sql/rpl_parallel.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,29 @@ struct rpl_parallel_thread {
167167
int last_error_number;
168168
char last_error_message[MAX_SLAVE_ERRMSG];
169169
ulonglong last_error_timestamp;
170+
ulonglong worker_idle_time;
171+
ulong last_trans_retry_count;
172+
ulonglong start_time;
173+
void start_time_tracker()
174+
{
175+
start_time= microsecond_interval_timer();
176+
}
177+
ulonglong compute_time_lapsed()
178+
{
179+
return (ulonglong)((microsecond_interval_timer() - start_time) / 1000000.0);
180+
}
181+
void add_to_worker_idle_time_and_reset()
182+
{
183+
worker_idle_time+= compute_time_lapsed();
184+
start_time=0;
185+
}
186+
ulonglong get_worker_idle_time()
187+
{
188+
if (start_time)
189+
return compute_time_lapsed();
190+
else
191+
return worker_idle_time;
192+
}
170193
void enqueue(queued_event *qev)
171194
{
172195
if (last_in_queue)

storage/perfschema/table_replication_applier_status_by_worker.cc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ table_replication_applier_status_by_worker::m_share=
5858
"LAST_SEEN_TRANSACTION CHAR(57) not null,"
5959
"LAST_ERROR_NUMBER INTEGER not null,"
6060
"LAST_ERROR_MESSAGE VARCHAR(1024) not null,"
61-
"LAST_ERROR_TIMESTAMP TIMESTAMP(0) not null)") },
61+
"LAST_ERROR_TIMESTAMP TIMESTAMP(0) not null,"
62+
"WORKER_IDLE_TIME BIGINT UNSIGNED not null,"
63+
"LAST_TRANS_RETRY_COUNT INTEGER not null)") },
6264
false /* perpetual */
6365
};
6466

@@ -153,6 +155,7 @@ void table_replication_applier_status_by_worker::make_row(rpl_parallel_thread *r
153155
if (m_row.channel_name_length)
154156
memcpy(m_row.channel_name, rpt->channel_name, m_row.channel_name_length);
155157

158+
m_row.thread_id_is_null= true;
156159
if (rpt->running)
157160
{
158161
PSI_thread *psi= thd_get_psi(rpt->thd);
@@ -162,14 +165,10 @@ void table_replication_applier_status_by_worker::make_row(rpl_parallel_thread *r
162165
m_row.thread_id= pfs->m_thread_internal_id;
163166
m_row.thread_id_is_null= false;
164167
}
165-
else
166-
m_row.thread_id_is_null= true;
167168
}
168-
else
169-
m_row.thread_id_is_null= true;
170169

171170
if ((gtid.seq_no > 0 &&
172-
!rpl_slave_state_tostring_helper(&str, &gtid, &first)))
171+
!rpl_slave_state_tostring_helper(&str, &gtid, &first)))
173172
{
174173
strmake(m_row.last_seen_transaction,str.ptr(), str.length());
175174
m_row.last_seen_transaction_length= str.length();
@@ -197,6 +196,8 @@ void table_replication_applier_status_by_worker::make_row(rpl_parallel_thread *r
197196
m_row.last_error_timestamp= rpt->last_error_timestamp;
198197
}
199198

199+
m_row.last_trans_retry_count= rpt->last_trans_retry_count;
200+
m_row.worker_idle_time= rpt->get_worker_idle_time();
200201
m_row_exists= true;
201202
}
202203

@@ -242,6 +243,12 @@ int table_replication_applier_status_by_worker
242243
case 6: /*last_error_timestamp*/
243244
set_field_timestamp(f, m_row.last_error_timestamp);
244245
break;
246+
case 7: /*worker_idle_time*/
247+
set_field_ulonglong(f, m_row.worker_idle_time);
248+
break;
249+
case 8: /*last_trans_retry_count*/
250+
set_field_ulong(f, m_row.last_trans_retry_count);
251+
break;
245252
default:
246253
DBUG_ASSERT(false);
247254
}

storage/perfschema/table_replication_applier_status_by_worker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ struct st_row_worker {
6868
char last_error_message[MAX_SLAVE_ERRMSG];
6969
uint last_error_message_length;
7070
ulonglong last_error_timestamp;
71+
ulonglong worker_idle_time;
72+
ulong last_trans_retry_count;
7173
};
7274

7375
/**

0 commit comments

Comments
 (0)