1 /* Copyright (c) 2010, 2021, 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 also distributed 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 included with MySQL.
13 
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License, version 2.0, for more details.
18 
19   You should have received a copy of the GNU General Public License
20   along with this program; if not, write to the Free Software
21   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
22 
23 #ifndef PFS_HOST_H
24 #define PFS_HOST_H
25 
26 /**
27   @file storage/perfschema/pfs_host.h
28   Performance schema host (declarations).
29 */
30 
31 #include "pfs_lock.h"
32 #include "lf.h"
33 #include "pfs_con_slice.h"
34 
35 struct PFS_global_param;
36 struct PFS_thread;
37 
38 /**
39   @addtogroup Performance_schema_buffers
40   @{
41 */
42 
43 /** Hash key for a host. */
44 struct PFS_host_key
45 {
46   /**
47     Hash search key.
48     This has to be a string for LF_HASH,
49     the format is "<hostname><0x00>"
50   */
51   char m_hash_key[HOSTNAME_LENGTH + 1];
52   uint m_key_length;
53 };
54 
55 /** Per host statistics. */
56 struct PFS_ALIGNED PFS_host : PFS_connection_slice
57 {
58 public:
init_refcountPFS_host59   inline void init_refcount(void)
60   {
61     PFS_atomic::store_32(& m_refcount, 1);
62   }
63 
get_refcountPFS_host64   inline int get_refcount(void)
65   {
66     return PFS_atomic::load_32(& m_refcount);
67   }
68 
inc_refcountPFS_host69   inline void inc_refcount(void)
70   {
71     PFS_atomic::add_32(& m_refcount, 1);
72   }
73 
dec_refcountPFS_host74   inline void dec_refcount(void)
75   {
76     PFS_atomic::add_32(& m_refcount, -1);
77   }
78 
79   void aggregate(bool alive);
80   void aggregate_waits(void);
81   void aggregate_stages(void);
82   void aggregate_statements(void);
83   void aggregate_transactions(void);
84   void aggregate_memory(bool alive);
85   void aggregate_status(void);
86   void aggregate_stats(void);
87   void release(void);
88 
89   void carry_memory_stat_delta(PFS_memory_stat_delta *delta, uint index);
90 
91   /* Internal lock. */
92   pfs_lock m_lock;
93   PFS_host_key m_key;
94   const char *m_hostname;
95   uint m_hostname_length;
96 
97   ulonglong m_disconnected_count;
98 
99 private:
100   int m_refcount;
101 };
102 
103 int init_host(const PFS_global_param *param);
104 void cleanup_host(void);
105 int init_host_hash(const PFS_global_param *param);
106 void cleanup_host_hash(void);
107 
108 PFS_host *find_or_create_host(PFS_thread *thread,
109                               const char *hostname, uint hostname_length);
110 
111 PFS_host *sanitize_host(PFS_host *unsafe);
112 void purge_all_host(void);
113 
114 /* For show status. */
115 
116 extern LF_HASH host_hash;
117 
118 /** @} */
119 #endif
120 
121