Skip to content

Commit

Permalink
Merge pull request #1295 from robgolebiowski/5.7-ps-bug995624
Browse files Browse the repository at this point in the history
5.7 ps bug995624
  • Loading branch information
robgolebiowski committed Jan 27, 2017
2 parents a917aec + 8e924f1 commit a727250
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 4 deletions.
55 changes: 55 additions & 0 deletions mysql-test/suite/rpl/r/rpl_percona_userstat.result
@@ -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 master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
[connection master]
#
# Bug 995624 RBR events are not reflected in userstat's
# Rows_updated
#
STOP SLAVE SQL_THREAD;
CHANGE REPLICATION FILTER
REPLICATE_DO_TABLE= (test.t1, test.t2);
START SLAVE SQL_THREAD;
SET @slave_userstat_saved= @@global.userstat;
SET GLOBAL userstat=ON;
include/assert.inc [Rows updated on slave should be equal to 0]
SET @master_userstat_saved= @@global.userstat;
SET GLOBAL userstat=ON;
include/assert.inc [Rows updated on master should be equal to 0]
CREATE TABLE t1 (m INT);
3 "updates" to rows
INSERT INTO t1 VALUES(15),(16),(17);
1 "update" to rows (4 in total)
UPDATE t1 SET m=20 WHERE m=16;
1 "update" to rows (5 in total)
DELETE FROM t1 WHERE m=17;
CREATE TABLE t2 (n INT);
2 "updates" to rows (7 in total)
INSERT INTO t2 VALUES(30),(30);
2 "updates" to rows (9 in total)
UPDATE t2 SET n=10 WHERE n=30;
2 "updates" to rows (11 in total)
DELETE FROM t2 WHERE n=10;
2 "updates" to rows (13 in total)
INSERT INTO t2 (n)
SELECT t1.m
FROM t1;
include/assert.inc [Rows updated on master should be equal to 13]
t3 is not replicated. Let us make some updates
and check if they do not affect userstat
CREATE TABLE t3(x INT);
INSERT INTO t3 VALUE(1),(2),(3);
UPDATE t3 SET x=1 WHERE x=2;
DELETE FROM t3 WHERE x=1;
include/sync_slave_sql_with_master.inc
include/assert.inc [Rows updated on slave should be equal to 13 (i.e. Number of RBR rows updates replicated from master)]
SET GLOBAL userstat=@slave_userstat_saved;
SELECT * FROM t1 ORDER BY m;
m
15
20
SET GLOBAL userstat=@master_userstat_saved;
DROP TABLE t1, t2;
DROP TABLE t3;
include/rpl_end.inc
76 changes: 76 additions & 0 deletions mysql-test/suite/rpl/t/rpl_percona_userstat.test
@@ -0,0 +1,76 @@
--source include/not_embedded.inc
--source include/master-slave.inc

--echo #
--echo # Bug 995624 RBR events are not reflected in userstat's
--echo # Rows_updated
--echo #

connection slave;

STOP SLAVE SQL_THREAD;
CHANGE REPLICATION FILTER
REPLICATE_DO_TABLE= (test.t1, test.t2);
START SLAVE SQL_THREAD;

SET @slave_userstat_saved= @@global.userstat;
SET GLOBAL userstat=ON;

--let $assert_text= Rows updated on slave should be equal to 0
--let $assert_cond= [SELECT ROWS_UPDATED FROM information_schema.client_statistics] = 0
--source include/assert.inc

connection master;
SET @master_userstat_saved= @@global.userstat;
SET GLOBAL userstat=ON;

--let $assert_text= Rows updated on master should be equal to 0
--let $assert_cond= [SELECT ROWS_UPDATED FROM information_schema.client_statistics] = 0
--source include/assert.inc

CREATE TABLE t1 (m INT);
--echo 3 "updates" to rows
INSERT INTO t1 VALUES(15),(16),(17);
--echo 1 "update" to rows (4 in total)
UPDATE t1 SET m=20 WHERE m=16;
--echo 1 "update" to rows (5 in total)
DELETE FROM t1 WHERE m=17;
CREATE TABLE t2 (n INT);
--echo 2 "updates" to rows (7 in total)
INSERT INTO t2 VALUES(30),(30);
--echo 2 "updates" to rows (9 in total)
UPDATE t2 SET n=10 WHERE n=30;
--echo 2 "updates" to rows (11 in total)
DELETE FROM t2 WHERE n=10;

--echo 2 "updates" to rows (13 in total)
INSERT INTO t2 (n)
SELECT t1.m
FROM t1;

--let $assert_text= Rows updated on master should be equal to 13
--let $assert_cond= [SELECT ROWS_UPDATED FROM information_schema.client_statistics] = 13
--source include/assert.inc

--echo t3 is not replicated. Let us make some updates
--echo and check if they do not affect userstat
CREATE TABLE t3(x INT);
INSERT INTO t3 VALUE(1),(2),(3);
UPDATE t3 SET x=1 WHERE x=2;
DELETE FROM t3 WHERE x=1;

--source include/sync_slave_sql_with_master.inc

--let $assert_text= Rows updated on slave should be equal to 13 (i.e. Number of RBR rows updates replicated from master)
--let $assert_cond= [SELECT ROWS_UPDATED FROM information_schema.client_statistics WHERE CLIENT != \'localhost\'] = 13
--source include/assert.inc

SET GLOBAL userstat=@slave_userstat_saved;

SELECT * FROM t1 ORDER BY m;

connection master;
SET GLOBAL userstat=@master_userstat_saved;
DROP TABLE t1, t2;
DROP TABLE t3;
--source include/rpl_end.inc
15 changes: 15 additions & 0 deletions sql/log_event.cc
Expand Up @@ -69,6 +69,10 @@ PSI_memory_key key_memory_log_event;
PSI_memory_key key_memory_Incident_log_event_message;
PSI_memory_key key_memory_Rows_query_log_event_rows_query;

#ifndef EMBEDDED_LIBRARY
#include "sql_connect.h" //update_global_user_stats
#endif

using std::min;
using std::max;

Expand Down Expand Up @@ -11018,6 +11022,9 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli)

error= (this->*do_apply_row_ptr)(rli);

if (!error)
thd->updated_row_count++;

if (handle_idempotent_and_ignored_errors(rli, &error))
break;

Expand All @@ -11026,6 +11033,14 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli)

} while (!error && (m_curr_row != m_rows_end));

if (unlikely(opt_userstat))
{
thd->update_stats(false);
#ifndef EMBEDDED_LIBRARY
update_global_user_stats(thd, true, time(NULL));
#endif
}

AFTER_MAIN_EXEC_ROW_LOOP:

if (saved_m_curr_row != m_curr_row && !table->file->has_transactions())
Expand Down
1 change: 1 addition & 0 deletions sql/sql_connect.h
Expand Up @@ -141,6 +141,7 @@ void end_connection(THD *thd);
int get_or_create_user_conn(THD *thd, const char *user,
const char *host, const USER_RESOURCES *mqh);
int check_for_max_user_connections(THD *thd, const USER_CONN *uc);
// Uses the THD to update the global stats by user name and client IP
void update_global_user_stats(THD* thd, bool create_user, time_t now);

#endif /* SQL_CONNECT_INCLUDED */
2 changes: 0 additions & 2 deletions sql/sql_parse.cc
Expand Up @@ -134,8 +134,6 @@ using std::max;
static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables);
static void sql_kill(THD *thd, my_thread_id id, bool only_kill_query);

// Uses the THD to update the global stats by user name and client IP
void update_global_user_stats(THD* thd, bool create_user, time_t now);

const LEX_STRING command_name[]={
{ C_STRING_WITH_LEN("Sleep") },
Expand Down
3 changes: 1 addition & 2 deletions sql/sql_prepare.cc
Expand Up @@ -114,6 +114,7 @@ When one supplies long data for a placeholder:
#include <mysql.h>
#else
#include <mysql_com.h>
#include "sql_connect.h" //update_global_user_stats
#endif
#include "sql_query_rewrite.h"

Expand All @@ -123,8 +124,6 @@ When one supplies long data for a placeholder:
using std::max;
using std::min;

// Uses the THD to update the global stats by user name and client IP
void update_global_user_stats(THD* thd, bool create_user, time_t now);

/****************************************************************************/

Expand Down

0 comments on commit a727250

Please sign in to comment.