Skip to content

Commit

Permalink
MDEV-20220: Merge 5.7 P_S replication table 'replication_applier_stat…
Browse files Browse the repository at this point in the history
…us_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                                     |
---------------------------------------------------------------------------
  • Loading branch information
sujatha-s committed Apr 8, 2021
1 parent 94f1d0f commit 036ee61
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 32 deletions.
2 changes: 2 additions & 0 deletions mysql-test/suite/perfschema/r/table_schema.result
Expand Up @@ -872,6 +872,8 @@ def performance_schema replication_applier_status_by_worker LAST_SEEN_TRANSACTIO
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
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
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
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
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
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
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
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
Expand Down
15 changes: 5 additions & 10 deletions mysql-test/suite/rpl/r/rpl_parallel_retry.result
Expand Up @@ -49,8 +49,7 @@ SET @old_dbug= @@GLOBAL.debug_dbug;
SET GLOBAL debug_dbug="+d,rpl_parallel_simulate_temp_err_gtid_0_x_100";
include/start_slave.inc
SET GLOBAL debug_dbug=@old_dbug;
retries
1
include/assert.inc [Performance Schema retries should match with actual retries]
SELECT * FROM t1 ORDER BY a;
a b
1 2
Expand Down Expand Up @@ -82,8 +81,7 @@ SET @old_dbug= @@GLOBAL.debug_dbug;
SET GLOBAL debug_dbug="+d,rpl_parallel_simulate_temp_err_gtid_0_x_100,rpl_parallel_simulate_double_temp_err_gtid_0_x_100";
include/start_slave.inc
SET GLOBAL debug_dbug=@old_dbug;
retries
2
include/assert.inc [Performance Schema retries should match with actual retries]
SELECT * FROM t1 ORDER BY a;
a b
1 3
Expand Down Expand Up @@ -179,8 +177,7 @@ SET @old_dbug= @@GLOBAL.debug_dbug;
SET GLOBAL debug_dbug="+d,rpl_parallel_simulate_temp_err_gtid_0_x_100";
include/start_slave.inc
SET GLOBAL debug_dbug=@old_dbug;
retries
1
include/assert.inc [Performance Schema retries should match with actual retries]
SELECT * FROM t1 WHERE a >= 10 ORDER BY a;
a b
10 4
Expand Down Expand Up @@ -224,8 +221,7 @@ SET @old_dbug= @@GLOBAL.debug_dbug;
SET GLOBAL debug_dbug="+d,rpl_parallel_simulate_temp_err_xid";
include/start_slave.inc
SET GLOBAL debug_dbug=@old_dbug;
retries
1
include/assert.inc [Performance Schema retries should match with actual retries]
SELECT * FROM t1 WHERE a >= 100 ORDER BY a;
a b
100 0
Expand Down Expand Up @@ -323,8 +319,7 @@ SET debug_sync='now WAIT_FOR t3_waiting';
SET debug_sync='now SIGNAL t1_start';
SET GLOBAL debug_dbug=@old_dbug;
SET debug_sync='RESET';
retries
1
include/assert.inc [Performance Schema retries should match with actual retries]
SELECT * FROM t3 ORDER BY a;
a b
1 NULL
Expand Down
Expand Up @@ -28,6 +28,9 @@ include/assert.inc [Value returned by SSS and PS table for Last_Error_Number sho
include/assert.inc [Value returned by SSS and PS table for Last_Error_Message should both be empty.]
include/assert.inc [Value returned by PS table for Last_Error_Timestamp should be 0000-00-00 00:00:00.]
connection master;
connection slave;
include/assert.inc [Value returned by PS table for worker_idle_time should be >= 1]
connection master;
DROP TABLE t1;
connection slave;
STOP SLAVE 'slave1';
Expand Down
46 changes: 31 additions & 15 deletions mysql-test/suite/rpl/t/rpl_parallel_retry.test
Expand Up @@ -68,9 +68,13 @@ let $old_retry= query_get_value(SHOW STATUS LIKE 'Slave_retried_transactions', V
--sync_with_master
SET GLOBAL debug_dbug=@old_dbug;
let $new_retry= query_get_value(SHOW STATUS LIKE 'Slave_retried_transactions', Value, 1);
--disable_query_log
eval SELECT $new_retry - $old_retry AS retries;
--enable_query_log
let $ps_value= query_get_value(select last_trans_retry_count from
performance_schema.replication_applier_status_by_worker where
last_trans_retry_count > 0, last_trans_retry_count, 1);
let $assert_text= Performance Schema retries should match with actual retries;
let $assert_cond= "$ps_value" = $new_retry - $old_retry;
source include/assert.inc;


SELECT * FROM t1 ORDER BY a;

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

SELECT * FROM t1 ORDER BY a;

Expand Down Expand Up @@ -187,9 +194,12 @@ let $old_retry= query_get_value(SHOW STATUS LIKE 'Slave_retried_transactions', V
--sync_with_master
SET GLOBAL debug_dbug=@old_dbug;
let $new_retry= query_get_value(SHOW STATUS LIKE 'Slave_retried_transactions', Value, 1);
--disable_query_log
eval SELECT $new_retry - $old_retry AS retries;
--enable_query_log
let $ps_value= query_get_value(select last_trans_retry_count from
performance_schema.replication_applier_status_by_worker where
last_trans_retry_count > 0, last_trans_retry_count, 1);
let $assert_text= Performance Schema retries should match with actual retries;
let $assert_cond= "$ps_value" = $new_retry - $old_retry;
source include/assert.inc;

SELECT * FROM t1 WHERE a >= 10 ORDER BY a;
SELECT a, LENGTH(b) FROM t2 ORDER BY a;
Expand Down Expand Up @@ -235,9 +245,12 @@ let $old_retry= query_get_value(SHOW STATUS LIKE 'Slave_retried_transactions', V
--sync_with_master
SET GLOBAL debug_dbug=@old_dbug;
let $new_retry= query_get_value(SHOW STATUS LIKE 'Slave_retried_transactions', Value, 1);
--disable_query_log
eval SELECT $new_retry - $old_retry AS retries;
--enable_query_log
let $ps_value= query_get_value(select last_trans_retry_count from
performance_schema.replication_applier_status_by_worker where
last_trans_retry_count > 0, last_trans_retry_count, 1);
let $assert_text= Performance Schema retries should match with actual retries;
let $assert_cond= "$ps_value" = $new_retry - $old_retry;
source include/assert.inc;

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


Expand Down
Expand Up @@ -113,6 +113,14 @@ let $assert_text= Value returned by PS table for Last_Error_Timestamp should be
let $assert_cond= "$ps_value" = "0000-00-00 00:00:00";
source include/assert.inc;

--connection master
sleep 1;
--connection slave
let $ps_value= query_get_value(select worker_idle_time from performance_schema.replication_applier_status_by_worker, worker_idle_time, 1);
let $assert_text= Value returned by PS table for worker_idle_time should be >= 1;
let $assert_cond= "$ps_value" >= "1";
source include/assert.inc;

--connection master
DROP TABLE t1;
--save_master_pos
Expand Down
7 changes: 6 additions & 1 deletion sql/rpl_parallel.cc
Expand Up @@ -799,6 +799,7 @@ retry_event_group(rpl_group_info *rgi, rpl_parallel_thread *rpt,

mysql_mutex_lock(&rli->data_lock);
++rli->retried_trans;
++rpt->last_trans_retry_count;
statistic_increment(slave_retried_transactions, LOCK_status);
mysql_mutex_unlock(&rli->data_lock);

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

rpt->start_time_tracker();
thd->ENTER_COND(&rpt->COND_rpl_thread, &rpt->LOCK_rpl_thread,
&stage_waiting_for_work_from_sql_thread, &old_stage);
/*
Expand All @@ -1148,6 +1150,7 @@ handle_rpl_parallel_thread(void *arg)
}
rpt->dequeue1(events);
thd->EXIT_COND(&old_stage);
rpt->add_to_worker_idle_time_and_reset();

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


rpl_parallel_thread::rpl_parallel_thread()
: channel_name_length(0), last_error_number(0), last_error_timestamp(0)
: channel_name_length(0), last_error_number(0), last_error_timestamp(0),
worker_idle_time(0), last_trans_retry_count(0), start_time(0)
{
}

Expand Down
23 changes: 23 additions & 0 deletions sql/rpl_parallel.h
Expand Up @@ -167,6 +167,29 @@ struct rpl_parallel_thread {
int last_error_number;
char last_error_message[MAX_SLAVE_ERRMSG];
ulonglong last_error_timestamp;
ulonglong worker_idle_time;
ulong last_trans_retry_count;
ulonglong start_time;
void start_time_tracker()
{
start_time= microsecond_interval_timer();
}
ulonglong compute_time_lapsed()
{
return (ulonglong)((microsecond_interval_timer() - start_time) / 1000000.0);
}
void add_to_worker_idle_time_and_reset()
{
worker_idle_time+= compute_time_lapsed();
start_time=0;
}
ulonglong get_worker_idle_time()
{
if (start_time)
return compute_time_lapsed();
else
return worker_idle_time;
}
void enqueue(queued_event *qev)
{
if (last_in_queue)
Expand Down
19 changes: 13 additions & 6 deletions storage/perfschema/table_replication_applier_status_by_worker.cc
Expand Up @@ -58,7 +58,9 @@ table_replication_applier_status_by_worker::m_share=
"LAST_SEEN_TRANSACTION CHAR(57) not null,"
"LAST_ERROR_NUMBER INTEGER not null,"
"LAST_ERROR_MESSAGE VARCHAR(1024) not null,"
"LAST_ERROR_TIMESTAMP TIMESTAMP(0) not null)") },
"LAST_ERROR_TIMESTAMP TIMESTAMP(0) not null,"
"WORKER_IDLE_TIME BIGINT UNSIGNED not null,"
"LAST_TRANS_RETRY_COUNT INTEGER not null)") },
false /* perpetual */
};

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

m_row.thread_id_is_null= true;
if (rpt->running)
{
PSI_thread *psi= thd_get_psi(rpt->thd);
Expand All @@ -162,14 +165,10 @@ void table_replication_applier_status_by_worker::make_row(rpl_parallel_thread *r
m_row.thread_id= pfs->m_thread_internal_id;
m_row.thread_id_is_null= false;
}
else
m_row.thread_id_is_null= true;
}
else
m_row.thread_id_is_null= true;

if ((gtid.seq_no > 0 &&
!rpl_slave_state_tostring_helper(&str, &gtid, &first)))
!rpl_slave_state_tostring_helper(&str, &gtid, &first)))
{
strmake(m_row.last_seen_transaction,str.ptr(), str.length());
m_row.last_seen_transaction_length= str.length();
Expand Down Expand Up @@ -197,6 +196,8 @@ void table_replication_applier_status_by_worker::make_row(rpl_parallel_thread *r
m_row.last_error_timestamp= rpt->last_error_timestamp;
}

m_row.last_trans_retry_count= rpt->last_trans_retry_count;
m_row.worker_idle_time= rpt->get_worker_idle_time();
m_row_exists= true;
}

Expand Down Expand Up @@ -242,6 +243,12 @@ int table_replication_applier_status_by_worker
case 6: /*last_error_timestamp*/
set_field_timestamp(f, m_row.last_error_timestamp);
break;
case 7: /*worker_idle_time*/
set_field_ulonglong(f, m_row.worker_idle_time);
break;
case 8: /*last_trans_retry_count*/
set_field_ulong(f, m_row.last_trans_retry_count);
break;
default:
DBUG_ASSERT(false);
}
Expand Down
Expand Up @@ -68,6 +68,8 @@ struct st_row_worker {
char last_error_message[MAX_SLAVE_ERRMSG];
uint last_error_message_length;
ulonglong last_error_timestamp;
ulonglong worker_idle_time;
ulong last_trans_retry_count;
};

/**
Expand Down

0 comments on commit 036ee61

Please sign in to comment.