MySQL 9.0.0
Source Code Documentation
pfs_account.h
Go to the documentation of this file.
1/* Copyright (c) 2010, 2024, Oracle and/or its affiliates.
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, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25#ifndef PFS_ACCOUNT_H
26#define PFS_ACCOUNT_H
27
28/**
29 @file storage/perfschema/pfs_account.h
30 Performance schema account (declarations).
31*/
32
33#include <sys/types.h>
34#include <atomic>
35
36#include "lf.h"
37#include "my_hostname.h" /* HOSTNAME_LENGTH */
38#include "my_inttypes.h"
39#include "mysql_com.h" /* USERNAME_LENGTH */
44
45struct PFS_global_param;
46struct PFS_user;
47struct PFS_host;
48struct PFS_thread;
52
53/**
54 @addtogroup performance_schema_buffers
55 @{
56*/
57
58/** Hash key for an account. */
60 /** User name. */
62 /** Host name. */
64};
65
66/** Per account statistics. */
68 public:
69 inline void init_refcount() { m_refcount.store(1); }
70
71 inline int get_refcount() { return m_refcount.load(); }
72
73 inline void inc_refcount() { ++m_refcount; }
74
75 inline void dec_refcount() { --m_refcount; }
76
77 void aggregate(bool alive, PFS_user *safe_user, PFS_host *safe_host);
78 void aggregate_waits(PFS_user *safe_user, PFS_host *safe_host);
79 void aggregate_stages(PFS_user *safe_user, PFS_host *safe_host);
80 void aggregate_statements(PFS_user *safe_user, PFS_host *safe_host);
81 void aggregate_transactions(PFS_user *safe_user, PFS_host *safe_host);
82 void aggregate_errors(PFS_user *safe_user, PFS_host *safe_host);
83 void aggregate_memory(bool alive, PFS_user *safe_user, PFS_host *safe_host);
84 void aggregate_status(PFS_user *safe_user, PFS_host *safe_host);
85 void aggregate_stats(PFS_user *safe_user, PFS_host *safe_host);
86 void release();
87
88 /** Reset all memory statistics. */
89 void rebase_memory_stats();
90
91 void carry_memory_stat_alloc_delta(PFS_memory_stat_alloc_delta *delta,
92 uint index);
93 void carry_memory_stat_free_delta(PFS_memory_stat_free_delta *delta,
94 uint index);
95
97 m_has_memory_stats = false;
98 m_instr_class_memory_stats = array;
99 }
100
102 if (!m_has_memory_stats) {
103 return nullptr;
104 }
105 return m_instr_class_memory_stats;
106 }
107
109 if (!m_has_memory_stats) {
110 rebase_memory_stats();
111 m_has_memory_stats = true;
112 }
113 return m_instr_class_memory_stats;
114 }
115
116 /** Internal lock. */
119 /** True if this account is enabled, per rules in table SETUP_ACTORS. */
121 /** True if this account has history enabled, per rules in table SETUP_ACTORS.
122 */
126
128 m_disconnected_count = 0;
129 m_max_controlled_memory = 0;
130 m_max_total_memory = 0;
131 }
132
133 void aggregate_disconnect(ulonglong controlled_memory,
134 ulonglong total_memory);
135
139
140 private:
141 std::atomic<int> m_refcount;
142
143 /**
144 Per account memory aggregated statistics.
145 This member holds the data for the table
146 PERFORMANCE_SCHEMA.MEMORY_SUMMARY_BY_ACCOUNT_BY_EVENT_NAME.
147 Immutable, safe to use without internal lock.
148 */
149 PFS_memory_shared_stat *m_instr_class_memory_stats{nullptr};
150};
151
152int init_account(const PFS_global_param *param);
153void cleanup_account();
154int init_account_hash(const PFS_global_param *param);
156
158 const PFS_user_name *user,
159 const PFS_host_name *host);
160
162void purge_all_account();
163
165
166/* For show status. */
167
168extern LF_HASH account_hash;
169
170/** @} */
171#endif
PFS_account * find_or_create_account(PFS_thread *thread, const PFS_user_name *user, const PFS_host_name *host)
Definition: pfs_account.cc:165
LF_HASH account_hash
Definition: pfs_account.cc:52
int init_account(const PFS_global_param *param)
Initialize the user buffers.
Definition: pfs_account.cc:60
void cleanup_account()
Cleanup all the account buffers.
Definition: pfs_account.cc:69
void cleanup_account_hash()
Cleanup the user hash.
Definition: pfs_account.cc:142
int init_account_hash(const PFS_global_param *param)
Initialize the user hash.
Definition: pfs_account.cc:130
void purge_all_account()
Purge non connected accounts, reset stats of connected account.
Definition: pfs_account.cc:720
PFS_account * sanitize_account(PFS_account *unsafe)
Definition: pfs_account.cc:667
void update_accounts_derived_flags(PFS_thread *thread)
Definition: pfs_account.cc:752
Common definition used by mysys, performance schema and server & client.
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
Common definition between mysql server & client.
char * user
Definition: mysqladmin.cc:66
const char * host
Definition: mysqladmin.cc:65
Performance schema connection slice (declarations).
Miscellaneous global dependencies (declarations).
#define PFS_ALIGNED
Definition: pfs_global.h:57
Performance schema internal locks (declarations).
Object names (declarations).
Definition: lf.h:187
Hash key for an account.
Definition: pfs_account.h:59
PFS_user_name m_user_name
User name.
Definition: pfs_account.h:61
PFS_host_name m_host_name
Host name.
Definition: pfs_account.h:63
Per account statistics.
Definition: pfs_account.h:67
pfs_lock m_lock
Internal lock.
Definition: pfs_account.h:117
ulonglong m_max_controlled_memory
Definition: pfs_account.h:137
ulonglong m_max_total_memory
Definition: pfs_account.h:138
bool m_enabled
True if this account is enabled, per rules in table SETUP_ACTORS.
Definition: pfs_account.h:120
PFS_user * m_user
Definition: pfs_account.h:124
const PFS_memory_shared_stat * read_instr_class_memory_stats() const
Definition: pfs_account.h:101
void set_instr_class_memory_stats(PFS_memory_shared_stat *array)
Definition: pfs_account.h:96
void dec_refcount()
Definition: pfs_account.h:75
void init_refcount()
Definition: pfs_account.h:69
ulonglong m_disconnected_count
Definition: pfs_account.h:136
int get_refcount()
Definition: pfs_account.h:71
PFS_host * m_host
Definition: pfs_account.h:125
PFS_memory_shared_stat * write_instr_class_memory_stats()
Definition: pfs_account.h:108
std::atomic< int > m_refcount
Definition: pfs_account.h:141
PFS_account_key m_key
Definition: pfs_account.h:118
void inc_refcount()
Definition: pfs_account.h:73
bool m_history
True if this account has history enabled, per rules in table SETUP_ACTORS.
Definition: pfs_account.h:123
void reset_connections_stats()
Definition: pfs_account.h:127
A connection slice, an arbitrary grouping of several connections.
Definition: pfs_con_slice.h:54
Performance schema global sizing parameters.
Definition: pfs_server.h:120
Definition: pfs_name.h:522
Per host statistics.
Definition: pfs_host.h:64
Definition: pfs_stat.h:937
Definition: pfs_stat.h:883
Definition: pfs_stat.h:888
Instrumented thread implementation.
Definition: pfs_instr.h:375
Definition: pfs_name.h:478
Per user statistics.
Definition: pfs_user.h:63
A 'lock' protecting performance schema internal buffers.
Definition: pfs_lock.h:154
static void alive(server *s)
Definition: xcom_transport.cc:174