23#include "myisam_priv.h"
24#include <drizzled/charset.h>
25#include <drizzled/util/test.h>
32int mi_lock_database(MI_INFO *info,
int lock_type)
36 MYISAM_SHARE *share=info->s;
37#if defined(FULL_LOG) || defined(_lint)
42 info->s->in_use=
new list<Session *>;
44 if (lock_type == F_EXTRA_LCK)
48 info->lock_type= lock_type;
49 info->s->in_use->push_front(info->in_use);
52#if defined(FULL_LOG) || defined(_lint)
57 if (share->kfile >= 0)
61 if (info->lock_type == F_RDLCK)
62 count= --share->r_locks;
64 count= --share->w_locks;
66 if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
71 mi_print_error(info->s, HA_ERR_CRASHED);
72 mi_mark_crashed(info);
77 if (share->changed && !share->w_locks)
79 if ((info->s->mmaped_length != info->s->state.state.data_file_length) &&
80 (info->s->nonmmaped_inserts > MAX_NONMAPPED_INSERTS))
82 mi_remap_file(info, info->s->state.state.data_file_length);
83 info->s->nonmmaped_inserts= 0;
85 share->state.process= share->last_process=share->this_process;
86 share->state.unique= info->last_unique= info->this_unique;
87 share->state.update_count= info->last_loop= ++info->this_loop;
88 if (mi_state_info_write(share->kfile, &share->state, 1))
94 mi_print_error(info->s, HA_ERR_CRASHED);
95 mi_mark_crashed(info);
98#if defined(FULL_LOG) || defined(_lint)
99 if (info->lock_type != F_EXTRA_LCK)
105 else if (!share->w_locks)
112 info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
113 info->lock_type= F_UNLCK;
114 info->s->in_use->remove(info->in_use);
117 if (info->lock_type == F_WRLCK)
125#if defined(FULL_LOG) || defined(_lint)
126 if (share->w_locks == 1)
133 info->lock_type=lock_type;
136 if (!share->r_locks && !share->w_locks)
138#if defined(FULL_LOG) || defined(_lint)
141 if (mi_state_info_read_dsk(share->kfile, &share->state, 1))
146 if (mi_state_info_read_dsk(share->kfile, &share->state, 1))
153 _mi_test_if_changed(info);
156 info->lock_type=lock_type;
157 info->s->in_use->push_front(info->in_use);
160 if (info->lock_type == F_RDLCK)
162 if (share->r_locks == 1)
164#if defined(FULL_LOG) || defined(_lint)
169 info->lock_type=lock_type;
173 if (!(share->options & HA_OPTION_READ_ONLY_DATA))
177#if defined(FULL_LOG) || defined(_lint)
182 if (mi_state_info_read_dsk(share->kfile, &share->state, 1))
191 _mi_test_if_changed(info);
193 info->lock_type=lock_type;
196 info->s->in_use->push_front(info->in_use);
202#if defined(FULL_LOG) || defined(_lint)
203 lock_type|=(int) (flag << 8);
204 myisam_log_command(MI_LOG_LOCK,info,(
unsigned char*) &lock_type,
sizeof(lock_type),
215int _mi_readinfo(MI_INFO *info,
int lock_type,
int check_keybuffer)
217 if (info->lock_type == F_UNLCK)
219 MYISAM_SHARE *share=info->s;
220 if (!share->tot_locks)
222 if (mi_state_info_read_dsk(share->kfile, &share->state, 1))
224 int error=errno ? errno : -1;
230 _mi_test_if_changed(info);
232 else if (lock_type == F_WRLCK && info->lock_type == F_RDLCK)
246int _mi_writeinfo(MI_INFO *info, uint32_t operation)
249 MYISAM_SHARE *share=info->s;
252 if (share->tot_locks == 0)
257 share->state.process= share->last_process= share->this_process;
258 share->state.unique= info->last_unique= info->this_unique;
259 share->state.update_count= info->last_loop= ++info->this_loop;
260 if ((error=mi_state_info_write(share->kfile, &share->state, 1)))
274int _mi_test_if_changed(MI_INFO *info)
276 MYISAM_SHARE *share=info->s;
277 if (share->state.process != share->last_process ||
278 share->state.unique != info->last_unique ||
279 share->state.update_count != info->last_loop)
281 share->last_process=share->state.process;
282 info->last_unique= share->state.unique;
283 info->last_loop= share->state.update_count;
284 info->update|= HA_STATE_WRITTEN;
285 info->data_changed= 1;
288 return (!(info->update & HA_STATE_AKTIV) ||
289 (info->update & (HA_STATE_WRITTEN | HA_STATE_DELETED |
290 HA_STATE_KEY_CHANGED)));
311int _mi_mark_file_changed(MI_INFO *info)
313 unsigned char buff[3];
314 MYISAM_SHARE *share=info->s;
316 if (!(share->state.changed & STATE_CHANGED) || ! share->global_changed)
318 share->state.changed|=(STATE_CHANGED | STATE_NOT_ANALYZED |
319 STATE_NOT_OPTIMIZED_KEYS);
320 if (!share->global_changed)
322 share->global_changed=1;
323 share->state.open_count++;
325 if (!share->temporary)
327 mi_int2store(buff,share->state.open_count);
329 return(my_pwrite(share->kfile,buff,
sizeof(buff),
330 sizeof(share->state.header),
343int _mi_decrement_open_count(MI_INFO *info)
345 unsigned char buff[2];
346 MYISAM_SHARE *share=info->s;
347 int lock_error=0,write_error=0;
348 if (share->global_changed)
350 uint32_t old_lock=info->lock_type;
351 share->global_changed=0;
352 lock_error=mi_lock_database(info,F_WRLCK);
354 if (share->state.open_count > 0)
356 share->state.open_count--;
357 mi_int2store(buff,share->state.open_count);
358 write_error=my_pwrite(share->kfile,buff,
sizeof(buff),
359 sizeof(share->state.header),
363 lock_error=mi_lock_database(info,old_lock);
365 return test(lock_error || write_error);
int end_io_cache()
Free an io_cache_st object.
TODO: Rename this file - func.h is stupid.