21 #include "my_global.h"
46 static bool host_hash_inited=
false;
60 host_instr_class_waits_array= NULL;
61 host_instr_class_stages_array= NULL;
62 host_instr_class_statements_array= NULL;
63 uint waits_sizing= host_max * wait_class_max;
71 if (unlikely(host_array == NULL))
77 host_instr_class_waits_array=
79 if (unlikely(host_instr_class_waits_array == NULL))
83 if (stages_sizing > 0)
85 host_instr_class_stages_array=
87 if (unlikely(host_instr_class_stages_array == NULL))
91 if (statements_sizing > 0)
93 host_instr_class_statements_array=
95 if (unlikely(host_instr_class_statements_array == NULL))
99 for (index= 0; index < host_max; index++)
102 &host_instr_class_waits_array[index * wait_class_max];
117 pfs_free(host_instr_class_waits_array);
118 host_instr_class_waits_array= NULL;
119 pfs_free(host_instr_class_stages_array);
120 host_instr_class_stages_array= NULL;
121 pfs_free(host_instr_class_statements_array);
122 host_instr_class_statements_array= NULL;
127 static uchar *host_hash_get_key(
const uchar *
entry,
size_t *length,
130 const PFS_host *
const *typed_entry;
133 typed_entry=
reinterpret_cast<const PFS_host*
const *
> (
entry);
134 DBUG_ASSERT(typed_entry != NULL);
136 DBUG_ASSERT(host != NULL);
137 *length= host->m_key.m_key_length;
139 return const_cast<uchar*
> (
reinterpret_cast<const uchar*
> (result));
149 if ((! host_hash_inited) && (host_max > 0))
151 lf_hash_init(&host_hash,
sizeof(
PFS_host*), LF_HASH_UNIQUE,
152 0, 0, host_hash_get_key, &my_charset_bin);
153 host_hash.size= host_max;
154 host_hash_inited=
true;
162 if (host_hash_inited)
164 lf_hash_destroy(&host_hash);
165 host_hash_inited=
false;
173 if (! host_hash_inited)
181 const char *host, uint host_length)
183 DBUG_ASSERT(host_length <= HOSTNAME_LENGTH);
188 memcpy(ptr, host, host_length);
197 const char *hostname, uint hostname_length)
205 LF_PINS *pins= get_host_hash_pins(thread);
206 if (unlikely(pins == NULL))
213 set_host_key(&key, hostname, hostname_length);
217 const uint retry_max= 3;
221 (lf_hash_search(&host_hash, pins,
223 if (entry && (entry != MY_ERRPTR))
228 lf_hash_search_unpin(pins);
232 lf_hash_search_unpin(pins);
237 for (scan.
init(random, host_max);
243 for ( ; pfs < pfs_last; pfs++)
250 if (hostname_length > 0)
253 pfs->m_hostname= NULL;
254 pfs->m_hostname_length= hostname_length;
256 pfs->init_refcount();
258 pfs->m_disconnected_count= 0;
261 res= lf_hash_insert(&host_hash, pins, &pfs);
262 if (likely(res == 0))
272 if (++retry_count > retry_max)
291 void PFS_host::aggregate()
295 aggregate_statements();
299 void PFS_host::aggregate_waits()
305 void PFS_host::aggregate_stages()
312 global_instr_class_stages_array);
315 void PFS_host::aggregate_statements()
322 global_instr_class_statements_array);
325 void PFS_host::aggregate_stats()
328 m_disconnected_count= 0;
331 void PFS_host::release()
338 if ((&host_array[0] <= unsafe) &&
339 (unsafe < &host_array[host_max]))
346 LF_PINS *pins= get_host_hash_pins(thread);
347 if (unlikely(pins == NULL))
352 (lf_hash_search(&host_hash, pins,
353 host->m_key.
m_hash_key, host->m_key.m_key_length));
354 if (entry && (entry != MY_ERRPTR))
358 DBUG_ASSERT(pfs == host);
359 if (host->get_refcount() == 0)
361 lf_hash_delete(&host_hash, pins,
362 host->m_key.
m_hash_key, host->m_key.m_key_length);
367 lf_hash_search_unpin(pins);
373 PFS_thread *thread= PFS_thread::get_current_thread();
374 if (unlikely(thread == NULL))
378 PFS_host *pfs_last= host_array + host_max;
380 for ( ; pfs < pfs_last; pfs++)
385 if (pfs->get_refcount() == 0)
386 purge_host(thread, pfs);