1 /* Copyright (c) 2000, 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 St, Fifth Floor, Boston, MA 02110-1301  USA */
22 
23 /*
24   Static variables for MyISAM library. All definied here for easy making of
25   a shared library
26 */
27 
28 #ifndef MY_GLOBAL_INCLUDED
29 #include "myisamdef.h"
30 #endif
31 
32 LIST	*myisam_open_list=0;
33 uchar	myisam_file_magic[]=
34 { (uchar) 254, (uchar) 254,'\007', '\001', };
35 uchar	myisam_pack_file_magic[]=
36 { (uchar) 254, (uchar) 254,'\010', '\002', };
37 char * myisam_log_filename=(char*) "myisam.log";
38 File	myisam_log_file= -1;
39 uint	myisam_quick_table_bits=9;
40 ulong	myisam_block_size= MI_KEY_BLOCK_LENGTH;		/* Best by test */
41 my_bool myisam_flush=0, myisam_delay_key_write=0, myisam_single_user=0;
42 /* Assume that we are in a single threaded program by default. */
43 ulong myisam_concurrent_insert= 0;
44 ulonglong myisam_max_temp_length= MAX_FILE_SIZE;
45 ulong    myisam_data_pointer_size=4;
46 ulonglong    myisam_mmap_size= SIZE_T_MAX, myisam_mmap_used= 0;
47 /* Keycache thread state for the main thread or single threaded programs. */
48 st_keycache_thread_var main_thread_keycache_var;
49 /* Key used by myisamchk */
50 thread_local_key_t keycache_tls_key;
51 
always_valid(const char * filename MY_ATTRIBUTE ((unused)))52 static int always_valid(const char *filename MY_ATTRIBUTE((unused)))
53 {
54   return 0;
55 }
56 
57 int (*myisam_test_invalid_symlink)(const char *filename)= always_valid;
58 
59 
60 /*
61   read_vec[] is used for converting between P_READ_KEY.. and SEARCH_
62   Position is , == , >= , <= , > , <
63 */
64 
65 uint myisam_read_vec[]=
66 {
67   SEARCH_FIND, SEARCH_FIND | SEARCH_BIGGER, SEARCH_FIND | SEARCH_SMALLER,
68   SEARCH_NO_FIND | SEARCH_BIGGER, SEARCH_NO_FIND | SEARCH_SMALLER,
69   SEARCH_FIND | SEARCH_PREFIX, SEARCH_LAST, SEARCH_LAST | SEARCH_SMALLER,
70   MBR_CONTAIN, MBR_INTERSECT, MBR_WITHIN, MBR_DISJOINT, MBR_EQUAL
71 };
72 
73 uint myisam_readnext_vec[]=
74 {
75   SEARCH_BIGGER, SEARCH_BIGGER, SEARCH_SMALLER, SEARCH_BIGGER, SEARCH_SMALLER,
76   SEARCH_BIGGER, SEARCH_SMALLER, SEARCH_SMALLER
77 };
78 
79 PSI_memory_key mi_key_memory_MYISAM_SHARE;
80 PSI_memory_key mi_key_memory_MI_INFO;
81 PSI_memory_key mi_key_memory_MI_INFO_ft1_to_ft2;
82 PSI_memory_key mi_key_memory_MI_INFO_bulk_insert;
83 PSI_memory_key mi_key_memory_record_buffer;
84 PSI_memory_key mi_key_memory_FTB;
85 PSI_memory_key mi_key_memory_FT_INFO;
86 PSI_memory_key mi_key_memory_FTPARSER_PARAM;
87 PSI_memory_key mi_key_memory_ft_memroot;
88 PSI_memory_key mi_key_memory_ft_stopwords;
89 PSI_memory_key mi_key_memory_MI_SORT_PARAM;
90 PSI_memory_key mi_key_memory_MI_SORT_PARAM_wordroot;
91 PSI_memory_key mi_key_memory_SORT_FT_BUF;
92 PSI_memory_key mi_key_memory_SORT_KEY_BLOCKS;
93 PSI_memory_key mi_key_memory_filecopy;
94 PSI_memory_key mi_key_memory_SORT_INFO_buffer;
95 PSI_memory_key mi_key_memory_MI_DECODE_TREE;
96 PSI_memory_key mi_key_memory_MYISAM_SHARE_decode_tables;
97 PSI_memory_key mi_key_memory_preload_buffer;
98 PSI_memory_key mi_key_memory_stPageList_pages;
99 PSI_memory_key mi_key_memory_keycache_thread_var;
100 
101 #ifdef HAVE_PSI_INTERFACE
102 PSI_mutex_key mi_key_mutex_MYISAM_SHARE_intern_lock,
103   mi_key_mutex_MI_SORT_INFO_mutex, mi_key_mutex_MI_CHECK_print_msg;
104 
105 static PSI_mutex_info all_myisam_mutexes[]=
106 {
107   { &mi_key_mutex_MI_SORT_INFO_mutex, "MI_SORT_INFO::mutex", 0},
108   { &mi_key_mutex_MYISAM_SHARE_intern_lock, "MYISAM_SHARE::intern_lock", 0},
109   { &mi_key_mutex_MI_CHECK_print_msg, "MI_CHECK::print_msg", 0}
110 };
111 
112 PSI_rwlock_key mi_key_rwlock_MYISAM_SHARE_key_root_lock,
113   mi_key_rwlock_MYISAM_SHARE_mmap_lock;
114 
115 static PSI_rwlock_info all_myisam_rwlocks[]=
116 {
117   { &mi_key_rwlock_MYISAM_SHARE_key_root_lock, "MYISAM_SHARE::key_root_lock", 0},
118   { &mi_key_rwlock_MYISAM_SHARE_mmap_lock, "MYISAM_SHARE::mmap_lock", 0}
119 };
120 
121 PSI_cond_key mi_key_cond_MI_SORT_INFO_cond;
122 PSI_cond_key mi_keycache_thread_var_suspend;
123 
124 static PSI_cond_info all_myisam_conds[]=
125 {
126   { &mi_key_cond_MI_SORT_INFO_cond, "MI_SORT_INFO::cond", 0},
127   { &mi_keycache_thread_var_suspend, "keycache_thread_var::suspend", 0}
128 };
129 
130 PSI_file_key mi_key_file_datatmp, mi_key_file_dfile, mi_key_file_kfile,
131   mi_key_file_log;
132 
133 static PSI_file_info all_myisam_files[]=
134 {
135   { & mi_key_file_datatmp, "data_tmp", 0},
136   { & mi_key_file_dfile, "dfile", 0},
137   { & mi_key_file_kfile, "kfile", 0},
138   { & mi_key_file_log, "log", 0}
139 };
140 
141 PSI_thread_key mi_key_thread_find_all_keys;
142 
143 static PSI_thread_info all_myisam_threads[]=
144 {
145   { &mi_key_thread_find_all_keys, "find_all_keys", 0}
146 };
147 
148 static PSI_memory_info all_myisam_memory[]=
149 {
150   { &mi_key_memory_MYISAM_SHARE, "MYISAM_SHARE", 0},
151   { &mi_key_memory_MI_INFO, "MI_INFO", 0},
152   { &mi_key_memory_MI_INFO_ft1_to_ft2, "MI_INFO::ft1_to_ft2", 0},
153   { &mi_key_memory_MI_INFO_bulk_insert, "MI_INFO::bulk_insert", 0},
154   { &mi_key_memory_record_buffer, "record_buffer", 0},
155   { &mi_key_memory_FTB, "FTB", 0},
156   { &mi_key_memory_FT_INFO, "FT_INFO", 0},
157   { &mi_key_memory_FTPARSER_PARAM, "FTPARSER_PARAM", 0},
158   { &mi_key_memory_ft_memroot, "ft_memroot", 0},
159   { &mi_key_memory_ft_stopwords, "ft_stopwords", 0},
160   { &mi_key_memory_MI_SORT_PARAM, "MI_SORT_PARAM", 0},
161   { &mi_key_memory_MI_SORT_PARAM_wordroot, "MI_SORT_PARAM::wordroot", 0},
162   { &mi_key_memory_SORT_FT_BUF, "SORT_FT_BUF", 0},
163   { &mi_key_memory_SORT_KEY_BLOCKS, "SORT_KEY_BLOCKS", 0},
164   { &mi_key_memory_filecopy, "filecopy", 0},
165   { &mi_key_memory_SORT_INFO_buffer, "SORT_INFO::buffer", 0},
166   { &mi_key_memory_MI_DECODE_TREE, "MI_DECODE_TREE", 0},
167   { &mi_key_memory_MYISAM_SHARE_decode_tables, "MYISAM_SHARE::decode_tables", 0},
168   { &mi_key_memory_preload_buffer, "preload_buffer", 0},
169   { &mi_key_memory_stPageList_pages, "stPageList::pages", 0},
170   { &mi_key_memory_keycache_thread_var, "keycache_thread_var", 0}
171 };
172 
init_myisam_psi_keys()173 void init_myisam_psi_keys()
174 {
175   const char* category= "myisam";
176   int count;
177 
178   count= array_elements(all_myisam_mutexes);
179   mysql_mutex_register(category, all_myisam_mutexes, count);
180 
181   count= array_elements(all_myisam_rwlocks);
182   mysql_rwlock_register(category, all_myisam_rwlocks, count);
183 
184   count= array_elements(all_myisam_conds);
185   mysql_cond_register(category, all_myisam_conds, count);
186 
187   count= array_elements(all_myisam_files);
188   mysql_file_register(category, all_myisam_files, count);
189 
190   count= array_elements(all_myisam_threads);
191   mysql_thread_register(category, all_myisam_threads, count);
192 
193   count= array_elements(all_myisam_memory);
194   mysql_memory_register(category, all_myisam_memory, count);
195 }
196 #endif /* HAVE_PSI_INTERFACE */
197 
198