21 #include "my_global.h"
24 #include "sql_string.h"
36 uint setup_objects_version= 0;
38 ulong setup_object_max;
43 static bool setup_object_hash_inited=
false;
54 setup_object_array= NULL;
56 if (setup_object_max > 0)
60 if (unlikely(setup_object_array == NULL))
71 setup_object_array= NULL;
76 static uchar *setup_object_hash_get_key(
const uchar *
entry,
size_t *length,
83 DBUG_ASSERT(typed_entry != NULL);
84 setup_object= *typed_entry;
85 DBUG_ASSERT(setup_object != NULL);
86 *length= setup_object->
m_key.m_key_length;
88 return const_cast<uchar*
> (
reinterpret_cast<const uchar*
> (result));
98 if ((! setup_object_hash_inited) && (setup_object_max > 0))
101 0, 0, setup_object_hash_get_key, &my_charset_bin);
102 setup_object_hash.size= setup_object_max;
103 setup_object_hash_inited=
true;
111 if (setup_object_hash_inited)
113 lf_hash_destroy(&setup_object_hash);
114 setup_object_hash_inited=
false;
122 if (! setup_object_hash_inited)
131 const char *schema, uint schema_length,
132 const char *
object, uint object_length)
134 DBUG_ASSERT(schema_length <= NAME_LEN);
135 DBUG_ASSERT(object_length <= NAME_LEN);
138 ptr[0]= (char) object_type;
140 memcpy(ptr, schema, schema_length);
144 memcpy(ptr,
object, object_length);
152 const String *
object,
bool enabled,
bool timed)
154 if (setup_object_max == 0)
155 return HA_ERR_RECORD_FILE_FULL;
157 PFS_thread *thread= PFS_thread::get_current_thread();
158 if (unlikely(thread == NULL))
159 return HA_ERR_OUT_OF_MEM;
161 LF_PINS* pins= get_setup_object_hash_pins(thread);
162 if (unlikely(pins == NULL))
163 return HA_ERR_OUT_OF_MEM;
165 static uint PFS_ALIGNED setup_object_monotonic_index= 0;
170 while (++attempts <= setup_object_max)
174 pfs= setup_object_array +
index;
180 set_setup_object_key(&pfs->
m_key, object_type,
181 schema->ptr(), schema->length(),
182 object->ptr(),
object->length());
191 res= lf_hash_insert(&setup_object_hash, pins, &pfs);
192 if (likely(res == 0))
195 setup_objects_version++;
201 return HA_ERR_FOUND_DUPP_KEY;
203 return HA_ERR_OUT_OF_MEM;
208 return HA_ERR_RECORD_FILE_FULL;
214 PFS_thread *thread= PFS_thread::get_current_thread();
215 if (unlikely(thread == NULL))
216 return HA_ERR_OUT_OF_MEM;
218 LF_PINS* pins= get_setup_object_hash_pins(thread);
219 if (unlikely(pins == NULL))
220 return HA_ERR_OUT_OF_MEM;
223 set_setup_object_key(&key, object_type,
224 schema->ptr(), schema->length(),
225 object->ptr(),
object->length());
229 (lf_hash_search(&setup_object_hash, pins, key.
m_hash_key, key.m_key_length));
231 if (entry && (entry != MY_ERRPTR))
234 lf_hash_delete(&setup_object_hash, pins, key.
m_hash_key, key.m_key_length);
238 lf_hash_search_unpin(pins);
240 setup_objects_version++;
244 int reset_setup_object()
246 PFS_thread *thread= PFS_thread::get_current_thread();
247 if (unlikely(thread == NULL))
248 return HA_ERR_OUT_OF_MEM;
250 LF_PINS* pins= get_setup_object_hash_pins(thread);
251 if (unlikely(pins == NULL))
252 return HA_ERR_OUT_OF_MEM;
257 for ( ; pfs < pfs_last; pfs++)
261 lf_hash_delete(&setup_object_hash, pins,
267 setup_objects_version++;
271 long setup_object_count()
273 return setup_object_hash.count;
278 const char *schema_name,
int schema_name_length,
279 const char *object_name,
int object_name_length,
280 bool *enabled,
bool *timed)
294 DBUG_ASSERT(object_type != OBJECT_TYPE_TEMPORARY_TABLE);
296 LF_PINS* pins= get_setup_object_hash_pins(thread);
297 if (unlikely(pins == NULL))
304 for (i= 1; i<=3; i++)
310 set_setup_object_key(&key,
312 schema_name, schema_name_length,
313 object_name, object_name_length);
317 set_setup_object_key(&key,
319 schema_name, schema_name_length,
"%", 1);
323 set_setup_object_key(&key, object_type,
"%", 1,
"%", 1);
327 (lf_hash_search(&setup_object_hash, pins, key.
m_hash_key, key.m_key_length));
329 if (entry && (entry != MY_ERRPTR))
334 lf_hash_search_unpin(pins);
338 lf_hash_search_unpin(pins);