1 | /* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | |
3 | This program is free software; you can redistribute it and/or modify |
4 | it under the terms of the GNU General Public License as published by |
5 | the Free Software Foundation; version 2 of the License. |
6 | |
7 | This program is distributed in the hope that it will be useful, |
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | GNU General Public License for more details. |
11 | |
12 | You should have received a copy of the GNU General Public License |
13 | along with this program; if not, write to the Free Software |
14 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ |
15 | |
16 | #ifndef PFS_ACCOUNT_H |
17 | #define PFS_ACCOUNT_H |
18 | |
19 | /** |
20 | @file storage/perfschema/pfs_account.h |
21 | Performance schema user@host (declarations). |
22 | */ |
23 | |
24 | #include "pfs_lock.h" |
25 | #include "lf.h" |
26 | #include "pfs_con_slice.h" |
27 | |
28 | struct PFS_global_param; |
29 | struct PFS_user; |
30 | struct PFS_host; |
31 | struct PFS_thread; |
32 | |
33 | /** |
34 | @addtogroup Performance_schema_buffers |
35 | @{ |
36 | */ |
37 | |
38 | struct PFS_account_key |
39 | { |
40 | /** |
41 | Hash search key. |
42 | This has to be a string for LF_HASH, |
43 | the format is "<username><0x00><hostname><0x00>" |
44 | */ |
45 | char m_hash_key[USERNAME_LENGTH + 1 + HOSTNAME_LENGTH + 1]; |
46 | uint m_key_length; |
47 | }; |
48 | |
49 | struct PFS_ALIGNED PFS_account : PFS_connection_slice |
50 | { |
51 | public: |
52 | inline void init_refcount(void) |
53 | { |
54 | PFS_atomic::store_32(& m_refcount, 1); |
55 | } |
56 | |
57 | inline int get_refcount(void) |
58 | { |
59 | return PFS_atomic::load_32(& m_refcount); |
60 | } |
61 | |
62 | inline void inc_refcount(void) |
63 | { |
64 | PFS_atomic::add_32(& m_refcount, 1); |
65 | } |
66 | |
67 | inline void dec_refcount(void) |
68 | { |
69 | PFS_atomic::add_32(& m_refcount, -1); |
70 | } |
71 | |
72 | void aggregate(PFS_user *safe_user, PFS_host *safe_host); |
73 | void aggregate_waits(PFS_user *safe_user, PFS_host *safe_host); |
74 | void aggregate_stages(PFS_user *safe_user, PFS_host *safe_host); |
75 | void aggregate_statements(PFS_user *safe_user, PFS_host *safe_host); |
76 | void aggregate_stats(PFS_user *safe_user, PFS_host *safe_host); |
77 | void release(void); |
78 | |
79 | /** Internal lock. */ |
80 | pfs_lock m_lock; |
81 | PFS_account_key m_key; |
82 | const char *m_username; |
83 | uint m_username_length; |
84 | const char *m_hostname; |
85 | uint m_hostname_length; |
86 | PFS_user *m_user; |
87 | PFS_host *m_host; |
88 | |
89 | ulonglong m_disconnected_count; |
90 | |
91 | private: |
92 | int m_refcount; |
93 | }; |
94 | |
95 | int init_account(const PFS_global_param *param); |
96 | void cleanup_account(void); |
97 | int init_account_hash(void); |
98 | void cleanup_account_hash(void); |
99 | |
100 | PFS_account * |
101 | find_or_create_account(PFS_thread *thread, |
102 | const char *username, uint username_length, |
103 | const char *hostname, uint hostname_length); |
104 | |
105 | PFS_account *sanitize_account(PFS_account *unsafe); |
106 | void purge_all_account(void); |
107 | |
108 | |
109 | /* For iterators and show status. */ |
110 | |
111 | extern ulong account_max; |
112 | extern ulong account_lost; |
113 | |
114 | /* Exposing the data directly, for iterators. */ |
115 | |
116 | extern PFS_account *account_array; |
117 | |
118 | extern LF_HASH account_hash; |
119 | |
120 | /** @} */ |
121 | #endif |
122 | |
123 | |