1 | /* Copyright (c) 2010, 2012, 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_USER_H |
17 | #define PFS_USER_H |
18 | |
19 | /** |
20 | @file storage/perfschema/pfs_user.h |
21 | Performance schema user (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_thread; |
30 | |
31 | /** |
32 | @addtogroup Performance_schema_buffers |
33 | @{ |
34 | */ |
35 | |
36 | struct PFS_user_key |
37 | { |
38 | /** |
39 | Hash search key. |
40 | This has to be a string for LF_HASH, |
41 | the format is "<username><0x00>" |
42 | */ |
43 | char m_hash_key[USERNAME_LENGTH + 1]; |
44 | uint m_key_length; |
45 | }; |
46 | |
47 | struct PFS_ALIGNED PFS_user : public PFS_connection_slice |
48 | { |
49 | public: |
50 | inline void init_refcount(void) |
51 | { |
52 | PFS_atomic::store_32(& m_refcount, 1); |
53 | } |
54 | |
55 | inline int get_refcount(void) |
56 | { |
57 | return PFS_atomic::load_32(& m_refcount); |
58 | } |
59 | |
60 | inline void inc_refcount(void) |
61 | { |
62 | PFS_atomic::add_32(& m_refcount, 1); |
63 | } |
64 | |
65 | inline void dec_refcount(void) |
66 | { |
67 | PFS_atomic::add_32(& m_refcount, -1); |
68 | } |
69 | |
70 | void aggregate(void); |
71 | void aggregate_waits(void); |
72 | void aggregate_stages(void); |
73 | void aggregate_statements(void); |
74 | void aggregate_stats(void); |
75 | void release(void); |
76 | |
77 | /** Internal lock. */ |
78 | pfs_lock m_lock; |
79 | PFS_user_key m_key; |
80 | const char *m_username; |
81 | uint m_username_length; |
82 | |
83 | ulonglong m_disconnected_count; |
84 | |
85 | private: |
86 | int m_refcount; |
87 | }; |
88 | |
89 | int init_user(const PFS_global_param *param); |
90 | void cleanup_user(void); |
91 | int init_user_hash(void); |
92 | void cleanup_user_hash(void); |
93 | |
94 | PFS_user * |
95 | find_or_create_user(PFS_thread *thread, |
96 | const char *username, uint username_length); |
97 | |
98 | PFS_user *sanitize_user(PFS_user *unsafe); |
99 | void purge_all_user(void); |
100 | |
101 | |
102 | /* For iterators and show status. */ |
103 | |
104 | extern ulong user_max; |
105 | extern ulong user_lost; |
106 | |
107 | /* Exposing the data directly, for iterators. */ |
108 | |
109 | extern PFS_user *user_array; |
110 | |
111 | extern LF_HASH user_hash; |
112 | |
113 | /** @} */ |
114 | #endif |
115 | |
116 | |