23 #include "myisamdef.h"
25 int mi_close(
register MI_INFO *info)
29 DBUG_ENTER(
"mi_close");
30 DBUG_PRINT(
"enter",(
"base: 0x%lx reopen: %u locks: %u",
31 (
long) info, (uint) share->reopen,
32 (uint) share->tot_locks));
34 if (info->open_list.data)
36 if (info->lock_type == F_EXTRA_LCK)
37 info->lock_type=F_UNLCK;
39 if (info->lock_type != F_UNLCK)
41 if (mi_lock_database(info,F_UNLCK))
46 if (share->options & HA_OPTION_READ_ONLY_DATA)
51 if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
53 if (end_io_cache(&info->rec_cache))
55 info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
57 flag= !--share->reopen;
58 if (info->open_list.data)
59 myisam_open_list= list_delete(myisam_open_list, &info->open_list);
62 my_free(mi_get_rec_buff_ptr(info, info->rec_buff));
65 DBUG_EXECUTE_IF(
"crash_before_flush_keys",
66 if (share->kfile >= 0) abort(););
67 if (share->kfile >= 0 &&
68 flush_key_blocks(share->key_cache, share->kfile,
69 share->temporary ? FLUSH_IGNORE_CHANGED :
72 if (share->kfile >= 0)
80 if (share->mode != O_RDONLY && mi_is_crashed(info))
81 mi_state_info_write(share->kfile, &share->state, 1);
83 _mi_decrement_open_count(info);
90 if (share->options & HA_OPTION_COMPRESS_RECORD)
96 if (share->decode_trees)
98 my_free(share->decode_trees);
99 my_free(share->decode_tables);
101 thr_lock_delete(&share->lock);
105 keys = share->state.header.keys;
107 for(i=0; i<keys; i++) {
113 if (info->open_list.data)
115 if (info->ftparser_param)
117 my_free(info->ftparser_param);
118 info->ftparser_param= 0;
123 myisam_log_command(MI_LOG_CLOSE,info,NULL,0,error);
128 DBUG_RETURN(my_errno=error);