#include "ha0ha.h"#include "buf0buf.h"Include dependency graph for ha0ha.c:

Go to the source code of this file.
Functions | |
| hash_table_t * | ha_create (ibool in_btr_search, ulint n, ulint n_mutexes, ulint mutex_level) |
| ibool | ha_insert_for_fold (hash_table_t *table, ulint fold, void *data) |
| void | ha_delete_hash_node (hash_table_t *table, ha_node_t *del_node) |
| void | ha_delete (hash_table_t *table, ulint fold, void *data) |
| void | ha_search_and_update_if_found (hash_table_t *table, ulint fold, void *data, void *new_data) |
| void | ha_remove_all_nodes_to_page (hash_table_t *table, ulint fold, page_t *page) |
| ibool | ha_validate (hash_table_t *table, ulint start_index, ulint end_index) |
| void | ha_print_info (FILE *file, hash_table_t *table) |
| hash_table_t* ha_create | ( | ibool | in_btr_search, | |
| ulint | n, | |||
| ulint | n_mutexes, | |||
| ulint | mutex_level | |||
| ) |
Definition at line 21 of file ha0ha.c.
References hash_table_struct::adaptive, FALSE, hash_create(), hash_create_mutexes(), hash_table_struct::heap, hash_table_struct::heaps, mem_alloc, mem_heap_create_in_btr_search, mem_heap_create_in_buffer, TRUE, and ut_a.
Referenced by btr_search_sys_create().
00023 : created table */ 00024 ibool in_btr_search, /* in: TRUE if the hash table is used in 00025 the btr_search module */ 00026 ulint n, /* in: number of array cells */ 00027 ulint n_mutexes, /* in: number of mutexes to protect the 00028 hash table: must be a power of 2, or 0 */ 00029 ulint mutex_level) /* in: level of the mutexes in the latching 00030 order: this is used in the debug version */ 00031 { 00032 hash_table_t* table; 00033 ulint i; 00034 00035 table = hash_create(n); 00036 00037 if (in_btr_search) { 00038 table->adaptive = TRUE; 00039 } else { 00040 table->adaptive = FALSE; 00041 } 00042 00043 /* Creating MEM_HEAP_BTR_SEARCH type heaps can potentially fail, 00044 but in practise it never should in this case, hence the asserts. */ 00045 00046 if (n_mutexes == 0) { 00047 if (in_btr_search) { 00048 table->heap = mem_heap_create_in_btr_search(4096); 00049 ut_a(table->heap); 00050 } else { 00051 table->heap = mem_heap_create_in_buffer(4096); 00052 } 00053 00054 return(table); 00055 } 00056 00057 hash_create_mutexes(table, n_mutexes, mutex_level); 00058 00059 table->heaps = mem_alloc(n_mutexes * sizeof(void*)); 00060 00061 for (i = 0; i < n_mutexes; i++) { 00062 if (in_btr_search) { 00063 table->heaps[i] = mem_heap_create_in_btr_search(4096); 00064 ut_a(table->heaps[i]); 00065 } else { 00066 table->heaps[i] = mem_heap_create_in_buffer(4096); 00067 } 00068 } 00069 00070 return(table); 00071 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void ha_delete | ( | hash_table_t * | table, | |
| ulint | fold, | |||
| void * | data | |||
| ) |
Definition at line 186 of file ha0ha.c.
References ha_delete_hash_node(), hash_get_mutex(), hash_table_struct::mutexes, ut_a, and ut_ad.
00188 : hash table */ 00189 ulint fold, /* in: folded value of data */ 00190 void* data) /* in: data, must not be NULL and must exist 00191 in the hash table */ 00192 { 00193 ha_node_t* node; 00194 00195 #ifdef UNIV_SYNC_DEBUG 00196 ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold))); 00197 #endif /* UNIV_SYNC_DEBUG */ 00198 node = ha_search_with_data(table, fold, data); 00199 00200 ut_a(node); 00201 00202 ha_delete_hash_node(table, node); 00203 }
Here is the call graph for this function:

| void ha_delete_hash_node | ( | hash_table_t * | table, | |
| ha_node_t * | del_node | |||
| ) |
Definition at line 169 of file ha0ha.c.
References hash_table_struct::adaptive, buf_block_align(), ha_node_struct::data, HASH_DELETE_AND_COMPACT, buf_block_struct::n_pointers, and ut_a.
Referenced by ha_delete(), and ha_remove_all_nodes_to_page().
00171 : hash table */ 00172 ha_node_t* del_node) /* in: node to be deleted */ 00173 { 00174 if (table->adaptive) { 00175 ut_a(buf_block_align(del_node->data)->n_pointers > 0); 00176 buf_block_align(del_node->data)->n_pointers--; 00177 } 00178 00179 HASH_DELETE_AND_COMPACT(ha_node_t, next, table, del_node); 00180 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ibool ha_insert_for_fold | ( | hash_table_t * | table, | |
| ulint | fold, | |||
| void * | data | |||
| ) |
Definition at line 79 of file ha0ha.c.
References hash_table_struct::adaptive, buf_block_align(), ha_node_struct::data, FALSE, ha_node_struct::fold, hash(), hash_calc_hash(), hash_get_heap(), hash_get_mutex(), hash_get_nth_cell(), mem_heap_alloc(), MEM_HEAP_BTR_SEARCH, hash_table_struct::mutexes, buf_block_struct::n_pointers, ha_node_struct::next, hash_cell_struct::node, NULL, TRUE, ut_a, and ut_ad.
Referenced by btr_search_build_page_hash_index(), btr_search_update_hash_on_insert(), and btr_search_update_hash_ref().
00081 : TRUE if succeed, FALSE if no more 00082 memory could be allocated */ 00083 hash_table_t* table, /* in: hash table */ 00084 ulint fold, /* in: folded value of data; if a node with 00085 the same fold value already exists, it is 00086 updated to point to the same data, and no new 00087 node is created! */ 00088 void* data) /* in: data, must not be NULL */ 00089 { 00090 hash_cell_t* cell; 00091 ha_node_t* node; 00092 ha_node_t* prev_node; 00093 buf_block_t* prev_block; 00094 ulint hash; 00095 00096 ut_ad(table && data); 00097 #ifdef UNIV_SYNC_DEBUG 00098 ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold))); 00099 #endif /* UNIV_SYNC_DEBUG */ 00100 hash = hash_calc_hash(fold, table); 00101 00102 cell = hash_get_nth_cell(table, hash); 00103 00104 prev_node = cell->node; 00105 00106 while (prev_node != NULL) { 00107 if (prev_node->fold == fold) { 00108 if (table->adaptive) { 00109 prev_block = buf_block_align(prev_node->data); 00110 ut_a(prev_block->n_pointers > 0); 00111 prev_block->n_pointers--; 00112 buf_block_align(data)->n_pointers++; 00113 } 00114 00115 prev_node->data = data; 00116 00117 return(TRUE); 00118 } 00119 00120 prev_node = prev_node->next; 00121 } 00122 00123 /* We have to allocate a new chain node */ 00124 00125 node = mem_heap_alloc(hash_get_heap(table, fold), sizeof(ha_node_t)); 00126 00127 if (node == NULL) { 00128 /* It was a btr search type memory heap and at the moment 00129 no more memory could be allocated: return */ 00130 00131 ut_ad(hash_get_heap(table, fold)->type & MEM_HEAP_BTR_SEARCH); 00132 00133 return(FALSE); 00134 } 00135 00136 ha_node_set_data(node, data); 00137 00138 if (table->adaptive) { 00139 buf_block_align(data)->n_pointers++; 00140 } 00141 00142 node->fold = fold; 00143 00144 node->next = NULL; 00145 00146 prev_node = cell->node; 00147 00148 if (prev_node == NULL) { 00149 00150 cell->node = node; 00151 00152 return(TRUE); 00153 } 00154 00155 while (prev_node->next != NULL) { 00156 00157 prev_node = prev_node->next; 00158 } 00159 00160 prev_node->next = node; 00161 00162 return(TRUE); 00163 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void ha_print_info | ( | FILE * | file, | |
| hash_table_t * | table | |||
| ) |
Definition at line 331 of file ha0ha.c.
References hash_get_n_cells(), hash_get_nth_cell(), hash_cell_struct::node, NULL, and UT_LIST_GET_LEN.
Referenced by srv_printf_innodb_monitor().
00333 : file where to print */ 00334 hash_table_t* table) /* in: hash table */ 00335 { 00336 hash_cell_t* cell; 00337 ulint cells = 0; 00338 ulint n_bufs; 00339 ulint i; 00340 00341 for (i = 0; i < hash_get_n_cells(table); i++) { 00342 00343 cell = hash_get_nth_cell(table, i); 00344 00345 if (cell->node) { 00346 00347 cells++; 00348 } 00349 } 00350 00351 fprintf(file, 00352 "Hash table size %lu, used cells %lu", 00353 (ulong) hash_get_n_cells(table), (ulong) cells); 00354 00355 if (table->heaps == NULL && table->heap != NULL) { 00356 00357 /* This calculation is intended for the adaptive hash 00358 index: how many buffer frames we have reserved? */ 00359 00360 n_bufs = UT_LIST_GET_LEN(table->heap->base) - 1; 00361 00362 if (table->heap->free_block) { 00363 n_bufs++; 00364 } 00365 00366 fprintf(file, ", node heap has %lu buffer(s)\n", (ulong) n_bufs); 00367 } 00368 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void ha_remove_all_nodes_to_page | ( | hash_table_t * | table, | |
| ulint | fold, | |||
| page_t * | page | |||
| ) |
Definition at line 241 of file ha0ha.c.
References buf_frame_align(), ha_delete_hash_node(), hash_get_mutex(), hash_table_struct::mutexes, ut_a, and ut_ad.
Referenced by btr_search_drop_page_hash_index().
00243 : hash table */ 00244 ulint fold, /* in: fold value */ 00245 page_t* page) /* in: buffer page */ 00246 { 00247 ha_node_t* node; 00248 00249 #ifdef UNIV_SYNC_DEBUG 00250 ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold))); 00251 #endif /* UNIV_SYNC_DEBUG */ 00252 node = ha_chain_get_first(table, fold); 00253 00254 while (node) { 00255 if (buf_frame_align(ha_node_get_data(node)) == page) { 00256 00257 /* Remove the hash node */ 00258 00259 ha_delete_hash_node(table, node); 00260 00261 /* Start again from the first node in the chain 00262 because the deletion may compact the heap of 00263 nodes and move other nodes! */ 00264 00265 node = ha_chain_get_first(table, fold); 00266 } else { 00267 node = ha_chain_get_next(node); 00268 } 00269 } 00270 #ifdef UNIV_DEBUG 00271 /* Check that all nodes really got deleted */ 00272 00273 node = ha_chain_get_first(table, fold); 00274 00275 while (node) { 00276 ut_a(buf_frame_align(ha_node_get_data(node)) != page); 00277 00278 node = ha_chain_get_next(node); 00279 } 00280 #endif 00281 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void ha_search_and_update_if_found | ( | hash_table_t * | table, | |
| ulint | fold, | |||
| void * | data, | |||
| void * | new_data | |||
| ) |
Definition at line 210 of file ha0ha.c.
References hash_table_struct::adaptive, buf_block_align(), ha_node_struct::data, hash_get_mutex(), hash_table_struct::mutexes, buf_block_struct::n_pointers, ut_a, and ut_ad.
Referenced by btr_search_update_hash_node_on_insert().
00212 : hash table */ 00213 ulint fold, /* in: folded value of the searched data */ 00214 void* data, /* in: pointer to the data */ 00215 void* new_data)/* in: new pointer to the data */ 00216 { 00217 ha_node_t* node; 00218 00219 #ifdef UNIV_SYNC_DEBUG 00220 ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold))); 00221 #endif /* UNIV_SYNC_DEBUG */ 00222 00223 node = ha_search_with_data(table, fold, data); 00224 00225 if (node) { 00226 if (table->adaptive) { 00227 ut_a(buf_block_align(node->data)->n_pointers > 0); 00228 buf_block_align(node->data)->n_pointers--; 00229 buf_block_align(new_data)->n_pointers++; 00230 } 00231 00232 node->data = new_data; 00233 } 00234 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ibool ha_validate | ( | hash_table_t * | table, | |
| ulint | start_index, | |||
| ulint | end_index | |||
| ) |
Definition at line 287 of file ha0ha.c.
References FALSE, ha_node_struct::fold, hash_calc_hash(), hash_get_n_cells(), hash_get_nth_cell(), ha_node_struct::next, hash_cell_struct::node, ok(), TRUE, ut_a, and ut_print_timestamp().
Referenced by btr_search_validate().
00289 : TRUE if ok */ 00290 hash_table_t* table, /* in: hash table */ 00291 ulint start_index, /* in: start index */ 00292 ulint end_index) /* in: end index */ 00293 { 00294 hash_cell_t* cell; 00295 ha_node_t* node; 00296 ibool ok = TRUE; 00297 ulint i; 00298 00299 ut_a(start_index <= end_index); 00300 ut_a(start_index < hash_get_n_cells(table)); 00301 ut_a(end_index < hash_get_n_cells(table)); 00302 00303 for (i = start_index; i <= end_index; i++) { 00304 00305 cell = hash_get_nth_cell(table, i); 00306 00307 node = cell->node; 00308 00309 while (node) { 00310 if (hash_calc_hash(node->fold, table) != i) { 00311 ut_print_timestamp(stderr); 00312 fprintf(stderr, 00313 "InnoDB: Error: hash table node fold value %lu does not\n" 00314 "InnoDB: match with the cell number %lu.\n", 00315 (ulong) node->fold, (ulong) i); 00316 00317 ok = FALSE; 00318 } 00319 00320 node = node->next; 00321 } 00322 } 00323 00324 return(ok); 00325 }
Here is the call graph for this function:

Here is the caller graph for this function:

1.4.7

