18 #include "myisamdef.h"
24 uchar *buff,
int return_buffer)
28 DBUG_ENTER(
"_mi_fetch_keypage");
29 DBUG_PRINT(
"enter",(
"page: %ld", (
long) page));
31 tmp=(uchar*) key_cache_read(info->s->key_cache,
32 info->s->kfile, page, level, (uchar*) buff,
33 (uint) keyinfo->block_length,
34 (uint) keyinfo->block_length,
36 if (tmp == info->buff)
40 DBUG_PRINT(
"error",(
"Got errno: %d from key_cache_read",my_errno));
41 info->last_keypage=HA_OFFSET_ERROR;
42 mi_print_error(info->s, HA_ERR_CRASHED);
43 my_errno=HA_ERR_CRASHED;
46 info->last_keypage=
page;
47 page_size=mi_getint(tmp);
48 if (page_size < 4 || page_size > keyinfo->block_length)
50 DBUG_PRINT(
"error",(
"page %lu had wrong page length: %u",
51 (ulong) page, page_size));
52 DBUG_DUMP(
"page", tmp, keyinfo->block_length);
53 info->last_keypage = HA_OFFSET_ERROR;
54 mi_print_error(info->s, HA_ERR_CRASHED);
55 my_errno = HA_ERR_CRASHED;
65 my_off_t page,
int level, uchar *buff)
68 DBUG_ENTER(
"_mi_write_keypage");
71 if (page < info->s->base.keystart ||
72 page+keyinfo->block_length > info->state->key_file_length ||
73 (page & (MI_MIN_KEY_BLOCK_LENGTH-1)))
75 DBUG_PRINT(
"error",(
"Trying to write inside key status region: key_start: %lu length: %lu page: %lu",
76 (
long) info->s->base.keystart,
77 (
long) info->state->key_file_length,
82 DBUG_PRINT(
"page",(
"write page at: %lu",(
long) page));
83 DBUG_DUMP(
"buff",(uchar*) buff,mi_getint(buff));
86 if ((length=keyinfo->block_length) > IO_SIZE*2 &&
87 info->state->key_file_length != page+length)
88 length= ((mi_getint(buff)+IO_SIZE-1) & (uint) ~(IO_SIZE-1));
89 DBUG_RETURN((key_cache_write(info->s->key_cache,
90 info->s->kfile,page, level, (uchar*) buff,length,
91 (uint) keyinfo->block_length,
92 (
int) ((info->lock_type != F_UNLCK) ||
93 info->s->delay_key_write))));
104 DBUG_ENTER(
"_mi_dispose");
105 DBUG_PRINT(
"enter",(
"pos: %ld", (
long) pos));
107 old_link= info->s->state.key_del[keyinfo->block_size_index];
108 info->s->state.key_del[keyinfo->block_size_index]= pos;
109 mi_sizestore(buff,old_link);
110 info->s->state.changed|= STATE_NOT_SORTED_PAGES;
111 DBUG_RETURN(key_cache_write(info->s->key_cache,
112 info->s->kfile, pos , level, buff,
114 (uint) keyinfo->block_length,
115 (
int) (info->lock_type != F_UNLCK)));
125 DBUG_ENTER(
"_mi_new");
127 if ((pos= info->s->state.key_del[keyinfo->block_size_index]) ==
130 if (info->state->key_file_length >=
131 info->s->base.max_key_file_length - keyinfo->block_length)
133 my_errno=HA_ERR_INDEX_FILE_FULL;
134 DBUG_RETURN(HA_OFFSET_ERROR);
136 pos=info->state->key_file_length;
137 info->state->key_file_length+= keyinfo->block_length;
141 if (!key_cache_read(info->s->key_cache,
142 info->s->kfile, pos, level,
145 (uint) keyinfo->block_length,0))
146 pos= HA_OFFSET_ERROR;
148 info->s->state.key_del[keyinfo->block_size_index]= mi_sizekorr(buff);
150 info->s->state.changed|= STATE_NOT_SORTED_PAGES;
151 DBUG_PRINT(
"exit",(
"Pos: %ld",(
long) pos));