21 #include "my_global.h"
55 int pfs_instr_config_state= PFS_INSTR_CONFIG_NOT_INITIALIZED;
63 PFS_class_type class_type);
71 static volatile uint32 mutex_class_dirty_count= 0;
72 static volatile uint32 mutex_class_allocated_count= 0;
73 static volatile uint32 rwlock_class_dirty_count= 0;
74 static volatile uint32 rwlock_class_allocated_count= 0;
75 static volatile uint32 cond_class_dirty_count= 0;
76 static volatile uint32 cond_class_allocated_count= 0;
125 static volatile uint32 thread_class_dirty_count= 0;
126 static volatile uint32 thread_class_allocated_count= 0;
173 static bool table_share_hash_inited=
false;
175 static volatile uint32 file_class_dirty_count= 0;
176 static volatile uint32 file_class_allocated_count= 0;
180 static volatile uint32 stage_class_dirty_count= 0;
181 static volatile uint32 stage_class_allocated_count= 0;
185 static volatile uint32 statement_class_dirty_count= 0;
186 static volatile uint32 statement_class_allocated_count= 0;
190 static volatile uint32 socket_class_dirty_count= 0;
191 static volatile uint32 socket_class_allocated_count= 0;
195 uint mutex_class_start= 0;
196 uint rwlock_class_start= 0;
197 uint cond_class_start= 0;
198 uint file_class_start= 0;
199 uint wait_class_max= 0;
200 uint socket_class_start= 0;
204 mutex_class_start= 3;
212 void register_global_classes()
216 0, PFS_CLASS_TABLE_IO);
222 0, PFS_CLASS_TABLE_LOCK);
241 uint rwlock_class_sizing,
242 uint cond_class_sizing)
244 mutex_class_dirty_count= mutex_class_allocated_count= 0;
245 rwlock_class_dirty_count= rwlock_class_allocated_count= 0;
246 cond_class_dirty_count= cond_class_allocated_count= 0;
252 mutex_class_array= NULL;
253 rwlock_class_array= NULL;
254 cond_class_array= NULL;
260 if (unlikely(mutex_class_array == NULL))
268 if (unlikely(rwlock_class_array == NULL))
276 if (unlikely(cond_class_array == NULL))
287 mutex_class_array= NULL;
288 mutex_class_dirty_count= mutex_class_allocated_count=
mutex_class_max= 0;
290 rwlock_class_array= NULL;
291 rwlock_class_dirty_count= rwlock_class_allocated_count=
rwlock_class_max= 0;
293 cond_class_array= NULL;
294 cond_class_dirty_count= cond_class_allocated_count=
cond_class_max= 0;
305 thread_class_dirty_count= thread_class_allocated_count= 0;
313 if (unlikely(thread_class_array == NULL))
317 thread_class_array= NULL;
326 thread_class_array= NULL;
327 thread_class_dirty_count= thread_class_allocated_count= 0;
346 if (unlikely(table_share_array == NULL))
350 table_share_array= NULL;
359 table_share_array= NULL;
365 static uchar *table_share_hash_get_key(
const uchar *
entry,
size_t *length,
372 DBUG_ASSERT(typed_entry != NULL);
374 DBUG_ASSERT(share != NULL);
377 return const_cast<uchar*
> (
reinterpret_cast<const uchar*
> (result));
386 lf_hash_init(&table_share_hash,
sizeof(
PFS_table_share*), LF_HASH_UNIQUE,
387 0, 0, table_share_hash_get_key, &my_charset_bin);
389 table_share_hash_inited=
true;
397 if (table_share_hash_inited)
399 lf_hash_destroy(&table_share_hash);
400 table_share_hash_inited=
false;
413 if (! table_share_hash_inited)
431 const char *schema_name, uint schema_name_length,
432 const char *
table_name, uint table_name_length)
434 DBUG_ASSERT(schema_name_length <= NAME_LEN);
435 DBUG_ASSERT(table_name_length <= NAME_LEN);
436 char *saved_schema_name;
437 char *saved_table_name;
440 ptr[0]= (temporary ? OBJECT_TYPE_TEMPORARY_TABLE : OBJECT_TYPE_TABLE);
442 saved_schema_name= ptr;
443 memcpy(ptr, schema_name, schema_name_length);
444 ptr+= schema_name_length;
447 saved_table_name= ptr;
448 memcpy(ptr, table_name, table_name_length);
449 ptr+= table_name_length;
454 if (lower_case_table_names)
456 my_casedn_str(files_charset_info, saved_schema_name);
457 my_casedn_str(files_charset_info, saved_table_name);
461 void PFS_table_share::refresh_setup_object_flags(
PFS_thread *thread)
463 lookup_setup_object(thread,
478 file_class_dirty_count= file_class_allocated_count= 0;
486 if (unlikely(file_class_array == NULL))
490 file_class_array= NULL;
499 file_class_array= NULL;
500 file_class_dirty_count= file_class_allocated_count= 0;
512 stage_class_dirty_count= stage_class_allocated_count= 0;
520 if (unlikely(stage_class_array == NULL))
524 stage_class_array= NULL;
533 stage_class_array= NULL;
534 stage_class_dirty_count= stage_class_allocated_count= 0;
546 statement_class_dirty_count= statement_class_allocated_count= 0;
554 if (unlikely(statement_class_array == NULL))
558 statement_class_array= NULL;
567 statement_class_array= NULL;
568 statement_class_dirty_count= statement_class_allocated_count= 0;
580 socket_class_dirty_count= socket_class_allocated_count= 0;
588 if (unlikely(socket_class_array == NULL))
592 socket_class_array= NULL;
601 socket_class_array= NULL;
602 socket_class_dirty_count= socket_class_allocated_count= 0;
610 PFS_class_type class_type)
614 strncpy(klass->
m_name, name, name_length);
619 klass->
m_type= class_type;
628 uint match_length= 0;
630 for (uint
i= 0;
i < pfs_instr_config_array.elements;
i++)
633 get_dynamic(&pfs_instr_config_array, (uchar*)&e,
i);
643 if (!my_wildcmp(&my_charset_latin1,
645 e->m_name, e->m_name+e->m_name_length,
648 if (e->m_name_length >= match_length)
652 match_length= MY_MAX(e->m_name_length, match_length);
658 #define REGISTER_CLASS_BODY_PART(INDEX, ARRAY, MAX, NAME, NAME_LENGTH) \
659 for (INDEX= 0; INDEX < MAX; INDEX++) \
661 entry= &ARRAY[INDEX]; \
662 if ((entry->m_name_length == NAME_LENGTH) && \
663 (strncmp(entry->m_name, NAME, NAME_LENGTH) == 0)) \
665 DBUG_ASSERT(entry->m_flags == flags); \
666 return (INDEX + 1); \
718 entry= &mutex_class_array[
index];
719 init_instr_class(entry, name, name_length, flags, PFS_CLASS_MUTEX);
727 configure_instr_class(entry);
784 entry= &rwlock_class_array[
index];
785 init_instr_class(entry, name, name_length, flags, PFS_CLASS_RWLOCK);
792 configure_instr_class(entry);
822 entry= &cond_class_array[
index];
823 init_instr_class(entry, name, name_length, flags, PFS_CLASS_COND);
829 configure_instr_class(entry);
838 #define FIND_CLASS_BODY(KEY, COUNT, ARRAY) \
839 if ((KEY == 0) || (KEY > COUNT)) \
841 return &ARRAY[KEY - 1]
850 FIND_CLASS_BODY(key, mutex_class_allocated_count, mutex_class_array);
865 FIND_CLASS_BODY(key, rwlock_class_allocated_count, rwlock_class_array);
880 FIND_CLASS_BODY(key, cond_class_allocated_count, cond_class_array);
904 entry= &thread_class_array[
index];
907 (strncmp(entry->
m_name, name, name_length) == 0))
913 if (index < thread_class_max)
915 entry= &thread_class_array[
index];
917 strncpy(entry->
m_name, name, name_length);
935 FIND_CLASS_BODY(key, thread_class_allocated_count, thread_class_array);
964 entry= &file_class_array[
index];
965 init_instr_class(entry, name, name_length, flags, PFS_CLASS_FILE);
971 configure_instr_class(entry);
1004 entry= &stage_class_array[
index];
1005 init_instr_class(entry, name, name_length, flags, PFS_CLASS_STAGE);
1011 configure_instr_class(entry);
1042 entry= &statement_class_array[
index];
1043 init_instr_class(entry, name, name_length, flags, PFS_CLASS_STATEMENT);
1048 configure_instr_class(entry);
1065 FIND_CLASS_BODY(key, file_class_allocated_count, file_class_array);
1080 FIND_CLASS_BODY(key, stage_class_allocated_count, stage_class_array);
1095 FIND_CLASS_BODY(key, statement_class_allocated_count, statement_class_array);
1124 entry= &socket_class_array[
index];
1125 init_instr_class(entry, name, name_length, flags, PFS_CLASS_SOCKET);
1131 configure_instr_class(entry);
1147 FIND_CLASS_BODY(key, socket_class_allocated_count, socket_class_array);
1189 KEY *key_info= share->key_info;
1194 for ( ; pfs_key < pfs_key_last; pfs_key++, key_info++)
1196 len= strlen(key_info->
name);
1197 memcpy(pfs_key->
m_name, key_info->
name, len);
1201 pfs_key_last= pfs->
m_keys + MAX_INDEXES;
1202 for ( ; pfs_key < pfs_key_last; pfs_key++)
1209 KEY *key_info= share->key_info;
1216 for ( ; pfs_key < pfs_key_last; pfs_key++, key_info++)
1218 len= strlen(key_info->
name);
1222 if (memcmp(pfs_key->
m_name, key_info->
name, len) != 0)
1244 if (unlikely(pins == NULL))
1250 const char *schema_name= share->db.str;
1251 uint schema_name_length= share->db.length;
1252 const char *table_name= share->table_name.str;
1253 uint table_name_length= share->table_name.length;
1255 set_table_share_key(&key, temporary,
1256 schema_name, schema_name_length,
1257 table_name, table_name_length);
1260 uint retry_count= 0;
1261 const uint retry_max= 3;
1264 static uint PFS_ALIGNED table_share_monotonic_index= 0;
1271 (lf_hash_search(&table_share_hash, pins,
1273 if (entry && (entry != MY_ERRPTR))
1276 pfs->inc_refcount() ;
1277 if (compare_keys(pfs, share) != 0)
1279 set_keys(pfs, share);
1283 lf_hash_search_unpin(pins);
1287 lf_hash_search_unpin(pins);
1289 if (retry_count == 0)
1291 lookup_setup_object(thread,
1293 schema_name, schema_name_length,
1294 table_name, table_name_length,
1308 pfs= table_share_array +
index;
1321 pfs->init_refcount();
1323 set_keys(pfs, share);
1326 res= lf_hash_insert(&table_share_hash, pins, &pfs);
1327 if (likely(res == 0))
1338 if (++retry_count > retry_max)
1358 void PFS_table_share::aggregate_io(
void)
1360 uint safe_key_count= sanitize_index_count(
m_key_count);
1367 from_stat_last= from_stat + safe_key_count;
1368 for ( ; from_stat < from_stat_last ; from_stat++)
1369 sum_io.aggregate(from_stat);
1379 void PFS_table_share::aggregate_lock(
void)
1387 DBUG_ASSERT(pfs->get_refcount() > 0);
1388 pfs->dec_refcount();
1402 const char *schema_name, uint schema_name_length,
1403 const char *table_name, uint table_name_length)
1407 if (unlikely(pins == NULL))
1409 set_table_share_key(&key, temporary, schema_name, schema_name_length,
1410 table_name, table_name_length);
1413 (lf_hash_search(&table_share_hash, pins,
1415 if (entry && (entry != MY_ERRPTR))
1418 lf_hash_delete(&table_share_hash, pins,
1423 lf_hash_search_unpin(pins);
1452 for ( ; pfs < pfs_last; pfs++)
1462 for ( ; pfs < pfs_last; pfs++)
1471 for ( ; pfs < pfs_last; pfs++)
1474 pfs->refresh_setup_object_flags(thread);