Merge lp:~sergei.glushchenko/percona-server/5.6-BT34411-ps-blueprint-optimize-userstat into lp:percona-server/5.6

Proposed by Sergei Glushchenko
Status: Merged
Approved by: Laurynas Biveinis
Approved revision: no longer in the source branch.
Merged at revision: 513
Proposed branch: lp:~sergei.glushchenko/percona-server/5.6-BT34411-ps-blueprint-optimize-userstat
Merge into: lp:percona-server/5.6
Diff against target: 402 lines (+86/-220)
3 files modified
Percona-Server/sql/handler.cc (+2/-0)
Percona-Server/sql/sql_connect.cc (+80/-172)
Percona-Server/sql/structs.h (+4/-48)
To merge this branch: bzr merge lp:~sergei.glushchenko/percona-server/5.6-BT34411-ps-blueprint-optimize-userstat
Reviewer Review Type Date Requested Status
Laurynas Biveinis (community) Approve
Vlad Lesin (community) g2 Approve
Review via email: mp+190964@code.launchpad.net

Description of the change

Implementation of BP optimize userstats due to lost Jenkins build I've started new one
http://jenkins.percona.com/view/PS%205.6/job/percona-server-5.6-param/374/

To post a comment you must log in.
Revision history for this message
Vlad Lesin (vlad-lesin) wrote :

See 5.5 branch question.

review: Approve (g2)
Revision history for this message
Laurynas Biveinis (laurynas-biveinis) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Percona-Server/sql/handler.cc'
2--- Percona-Server/sql/handler.cc 2013-09-09 15:24:45 +0000
3+++ Percona-Server/sql/handler.cc 2013-10-14 14:01:57 +0000
4@@ -4749,6 +4749,7 @@
5 goto end;
6 }
7 strncpy(table_stats->table, key, sizeof(table_stats->table));
8+ table_stats->table_len= strlen(table_stats->table);
9 table_stats->rows_read= 0;
10 table_stats->rows_changed= 0;
11 table_stats->rows_changed_x_indexes= 0;
12@@ -4810,6 +4811,7 @@
13 goto end;
14 }
15 strncpy(index_stats->index, key, sizeof(index_stats->index));
16+ index_stats->index_len= strlen(index_stats->index);
17 index_stats->rows_read= 0;
18
19 if (my_hash_insert(&global_index_stats, (uchar *) index_stats))
20
21=== modified file 'Percona-Server/sql/sql_connect.cc'
22--- Percona-Server/sql/sql_connect.cc 2013-06-25 13:13:06 +0000
23+++ Percona-Server/sql/sql_connect.cc 2013-10-14 14:01:57 +0000
24@@ -138,7 +138,7 @@
25 extern "C" uchar *get_key_user_stats(USER_STATS *user_stats, size_t *length,
26 my_bool not_used __attribute__((unused)))
27 {
28- *length= strlen(user_stats->user);
29+ *length= user_stats->user_len;
30 return (uchar*) user_stats->user;
31 }
32
33@@ -191,6 +191,9 @@
34 strncpy(user_stats->user, user, sizeof(user_stats->user));
35 strncpy(user_stats->priv_user, priv_user, sizeof(user_stats->priv_user));
36
37+ user_stats->user_len= strlen(user_stats->user);
38+ user_stats->priv_user_len= strlen(user_stats->priv_user);
39+
40 user_stats->total_connections= total_connections;
41 user_stats->total_ssl_connections= total_ssl_connections;
42 user_stats->concurrent_connections= concurrent_connections;
43@@ -269,94 +272,6 @@
44 DBUG_VOID_RETURN;
45 }
46
47-void add_user_stats(USER_STATS *user_stats,
48- uint total_connections,
49- uint concurrent_connections,
50- time_t connected_time,
51- double busy_time,
52- double cpu_time,
53- ulonglong bytes_received,
54- ulonglong bytes_sent,
55- ulonglong binlog_bytes_written,
56- ha_rows rows_fetched,
57- ha_rows rows_updated,
58- ha_rows rows_read,
59- ulonglong select_commands,
60- ulonglong update_commands,
61- ulonglong other_commands,
62- ulonglong commit_trans,
63- ulonglong rollback_trans,
64- ulonglong denied_connections,
65- ulonglong lost_connections,
66- ulonglong access_denied_errors,
67- ulonglong empty_queries)
68-{
69- user_stats->total_connections+= total_connections;
70- user_stats->concurrent_connections+= concurrent_connections;
71- user_stats->connected_time+= connected_time;
72- user_stats->busy_time+= busy_time;
73- user_stats->cpu_time+= cpu_time;
74- user_stats->bytes_received+= bytes_received;
75- user_stats->bytes_sent+= bytes_sent;
76- user_stats->binlog_bytes_written+= binlog_bytes_written;
77- user_stats->rows_fetched+= rows_fetched;
78- user_stats->rows_updated+= rows_updated;
79- user_stats->rows_read+= rows_read;
80- user_stats->select_commands+= select_commands;
81- user_stats->update_commands+= update_commands;
82- user_stats->other_commands+= other_commands;
83- user_stats->commit_trans+= commit_trans;
84- user_stats->rollback_trans+= rollback_trans;
85- user_stats->denied_connections+= denied_connections;
86- user_stats->lost_connections+= lost_connections;
87- user_stats->access_denied_errors+= access_denied_errors;
88- user_stats->empty_queries+= empty_queries;
89-}
90-
91-void add_thread_stats(THREAD_STATS *thread_stats,
92- uint total_connections,
93- uint concurrent_connections,
94- time_t connected_time,
95- double busy_time,
96- double cpu_time,
97- ulonglong bytes_received,
98- ulonglong bytes_sent,
99- ulonglong binlog_bytes_written,
100- ha_rows rows_fetched,
101- ha_rows rows_updated,
102- ha_rows rows_read,
103- ulonglong select_commands,
104- ulonglong update_commands,
105- ulonglong other_commands,
106- ulonglong commit_trans,
107- ulonglong rollback_trans,
108- ulonglong denied_connections,
109- ulonglong lost_connections,
110- ulonglong access_denied_errors,
111- ulonglong empty_queries)
112-{
113- thread_stats->total_connections+= total_connections;
114- thread_stats->concurrent_connections+= concurrent_connections;
115- thread_stats->connected_time+= connected_time;
116- thread_stats->busy_time+= busy_time;
117- thread_stats->cpu_time+= cpu_time;
118- thread_stats->bytes_received+= bytes_received;
119- thread_stats->bytes_sent+= bytes_sent;
120- thread_stats->binlog_bytes_written+= binlog_bytes_written;
121- thread_stats->rows_fetched+= rows_fetched;
122- thread_stats->rows_updated+= rows_updated;
123- thread_stats->rows_read+= rows_read;
124- thread_stats->select_commands+= select_commands;
125- thread_stats->update_commands+= update_commands;
126- thread_stats->other_commands+= other_commands;
127- thread_stats->commit_trans+= commit_trans;
128- thread_stats->rollback_trans+= rollback_trans;
129- thread_stats->denied_connections+= denied_connections;
130- thread_stats->lost_connections+= lost_connections;
131- thread_stats->access_denied_errors+= access_denied_errors;
132- thread_stats->empty_queries+= empty_queries;
133-}
134-
135 void init_global_user_stats(void)
136 {
137 if (my_hash_init(&global_user_stats, system_charset_info, max_connections,
138@@ -391,7 +306,7 @@
139 extern "C" uchar *get_key_table_stats(TABLE_STATS *table_stats, size_t *length,
140 my_bool not_used __attribute__((unused)))
141 {
142- *length= strlen(table_stats->table);
143+ *length= table_stats->table_len;
144 return (uchar*) table_stats->table;
145 }
146
147@@ -413,7 +328,7 @@
148 extern "C" uchar *get_key_index_stats(INDEX_STATS *index_stats, size_t *length,
149 my_bool not_used __attribute__((unused)))
150 {
151- *length= strlen(index_stats->index);
152+ *length= index_stats->index_len;
153 return (uchar*) index_stats->index;
154 }
155
156@@ -655,87 +570,80 @@
157 // Updates the global stats of a user or client
158 void update_global_user_stats(THD* thd, bool create_user, time_t now)
159 {
160- if (opt_userstat)
161- {
162- char* user_string= get_valid_user_string(thd->main_security_ctx.user);
163- const char* client_string= get_client_host(thd);
164-
165- USER_STATS* user_stats;
166- THREAD_STATS* thread_stats;
167-
168- if (acl_is_utility_user(thd->security_ctx->user, thd->security_ctx->host,
169- thd->security_ctx->ip))
170- return;
171-
172- mysql_mutex_lock(&LOCK_global_user_client_stats);
173-
174- // Update by user name
175- if ((user_stats = (USER_STATS *) my_hash_search(&global_user_stats,
176- (uchar *) user_string,
177- strlen(user_string))))
178- {
179- // Found user.
180- update_global_user_stats_with_user(thd, user_stats, now);
181- }
182- else
183- {
184- // Create the entry
185- if (create_user)
186- {
187- increment_count_by_name(user_string, user_string,
188- &global_user_stats, thd);
189- }
190- }
191-
192- // Update by client IP
193- if ((user_stats = (USER_STATS *) my_hash_search(&global_client_stats,
194- (uchar *) client_string,
195- strlen(client_string))))
196- {
197- // Found by client IP
198- update_global_user_stats_with_user(thd, user_stats, now);
199- }
200- else
201- {
202- // Create the entry
203- if (create_user)
204- {
205- increment_count_by_name(client_string,
206- user_string,
207- &global_client_stats, thd);
208- }
209- }
210-
211- if (opt_thread_statistics)
212- {
213- // Update by thread ID
214- if ((thread_stats = (THREAD_STATS *) my_hash_search(&global_thread_stats,
215- (uchar *) &(thd->thread_id),
216- sizeof(my_thread_id))))
217- {
218- // Found by thread ID
219- update_global_thread_stats_with_thread(thd, thread_stats, now);
220- }
221- else
222- {
223- // Create the entry
224- if (create_user)
225- {
226- increment_count_by_id(thd->thread_id,
227- &global_thread_stats, thd);
228- }
229- }
230- }
231-
232- thd->last_global_update_time = now;
233- thd->reset_diff_stats();
234-
235- mysql_mutex_unlock(&LOCK_global_user_client_stats);
236- }
237- else
238- {
239- thd->reset_diff_stats();
240- }
241+ char* user_string= get_valid_user_string(thd->main_security_ctx.user);
242+ const char* client_string= get_client_host(thd);
243+
244+ USER_STATS* user_stats;
245+ THREAD_STATS* thread_stats;
246+
247+ if (acl_is_utility_user(thd->security_ctx->user, thd->security_ctx->host,
248+ thd->security_ctx->ip))
249+ return;
250+
251+ mysql_mutex_lock(&LOCK_global_user_client_stats);
252+
253+ // Update by user name
254+ if ((user_stats = (USER_STATS *) my_hash_search(&global_user_stats,
255+ (uchar *) user_string,
256+ strlen(user_string))))
257+ {
258+ // Found user.
259+ update_global_user_stats_with_user(thd, user_stats, now);
260+ }
261+ else
262+ {
263+ // Create the entry
264+ if (create_user)
265+ {
266+ increment_count_by_name(user_string, user_string,
267+ &global_user_stats, thd);
268+ }
269+ }
270+
271+ // Update by client IP
272+ if ((user_stats = (USER_STATS *) my_hash_search(&global_client_stats,
273+ (uchar *) client_string,
274+ strlen(client_string))))
275+ {
276+ // Found by client IP
277+ update_global_user_stats_with_user(thd, user_stats, now);
278+ }
279+ else
280+ {
281+ // Create the entry
282+ if (create_user)
283+ {
284+ increment_count_by_name(client_string,
285+ user_string,
286+ &global_client_stats, thd);
287+ }
288+ }
289+
290+ if (opt_thread_statistics)
291+ {
292+ // Update by thread ID
293+ if ((thread_stats = (THREAD_STATS *) my_hash_search(&global_thread_stats,
294+ (uchar *) &(thd->thread_id),
295+ sizeof(my_thread_id))))
296+ {
297+ // Found by thread ID
298+ update_global_thread_stats_with_thread(thd, thread_stats, now);
299+ }
300+ else
301+ {
302+ // Create the entry
303+ if (create_user)
304+ {
305+ increment_count_by_id(thd->thread_id,
306+ &global_thread_stats, thd);
307+ }
308+ }
309+ }
310+
311+ thd->last_global_update_time = now;
312+ thd->reset_diff_stats();
313+
314+ mysql_mutex_unlock(&LOCK_global_user_client_stats);
315 }
316
317 /*
318
319=== modified file 'Percona-Server/sql/structs.h'
320--- Percona-Server/sql/structs.h 2013-06-20 15:16:00 +0000
321+++ Percona-Server/sql/structs.h 2013-10-14 14:01:57 +0000
322@@ -250,6 +250,8 @@
323 uint total_connections;
324 uint total_ssl_connections;
325 uint concurrent_connections;
326+ size_t user_len;
327+ size_t priv_user_len;
328 time_t connected_time; // in seconds
329 double busy_time; // in seconds
330 double cpu_time; // in seconds
331@@ -298,30 +300,6 @@
332 ulonglong access_denied_errors,
333 ulonglong empty_queries);
334
335-/* Increment values of an instance of USER_STATS */
336-extern void
337-add_user_stats(USER_STATS *user_stats,
338- uint total_connections,
339- uint concurrent_connections,
340- time_t connected_time,
341- double busy_time,
342- double cpu_time,
343- ulonglong bytes_received,
344- ulonglong bytes_sent,
345- ulonglong binlog_bytes_written,
346- ha_rows rows_fetched,
347- ha_rows rows_updated,
348- ha_rows rows_read,
349- ulonglong select_commands,
350- ulonglong update_commands,
351- ulonglong other_commands,
352- ulonglong commit_trans,
353- ulonglong rollback_trans,
354- ulonglong denied_connections,
355- ulonglong lost_connections,
356- ulonglong access_denied_errors,
357- ulonglong empty_queries);
358-
359 typedef struct st_thread_stats {
360 my_thread_id id;
361 uint total_connections;
362@@ -374,32 +352,9 @@
363 ulonglong access_denied_errors,
364 ulonglong empty_queries);
365
366-/* Increment values of an instance of THREAD_STATS */
367-extern void
368-add_thread_stats(THREAD_STATS *thread_stats,
369- uint total_connections,
370- uint concurrent_connections,
371- time_t connected_time,
372- double busy_time,
373- double cpu_time,
374- ulonglong bytes_received,
375- ulonglong bytes_sent,
376- ulonglong binlog_bytes_written,
377- ha_rows rows_fetched,
378- ha_rows rows_updated,
379- ha_rows rows_read,
380- ulonglong select_commands,
381- ulonglong update_commands,
382- ulonglong other_commands,
383- ulonglong commit_trans,
384- ulonglong rollback_trans,
385- ulonglong denied_connections,
386- ulonglong lost_connections,
387- ulonglong access_denied_errors,
388- ulonglong empty_queries);
389-
390 typedef struct st_table_stats {
391 char table[NAME_LEN * 2 + 2]; // [db] + '.' + [table] + '\0'
392+ size_t table_len;
393 ulonglong rows_read, rows_changed;
394 ulonglong rows_changed_x_indexes;
395 /* Stores enum db_type, but forward declarations cannot be done */
396@@ -408,6 +363,7 @@
397
398 typedef struct st_index_stats {
399 char index[NAME_LEN * 3 + 3]; // [db] + '.' + [table] + '.' + [index] + '\0'
400+ size_t index_len;
401 ulonglong rows_read;
402 } INDEX_STATS;
403

Subscribers

People subscribed via source and target branches