1
by brian
clean slate |
1 |
/* Copyright (C) 2000-2004, 2006 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
1
by brian
clean slate |
15 |
|
16 |
/* Read and write key blocks */
|
|
17 |
||
1130.3.28
by Monty Taylor
Moved heapdef.h and myisamdef.h to *_priv.h for easier filtering for include guard check. |
18 |
#include "myisam_priv.h" |
1
by brian
clean slate |
19 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
20 |
using namespace drizzled; |
21 |
||
1
by brian
clean slate |
22 |
/* Fetch a key-page in memory */
|
23 |
||
481
by Brian Aker
Remove all of uchar. |
24 |
unsigned char *_mi_fetch_keypage(register MI_INFO *info, MI_KEYDEF *keyinfo, |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
25 |
internal::my_off_t page, int level, |
481
by Brian Aker
Remove all of uchar. |
26 |
unsigned char *buff, int return_buffer) |
1
by brian
clean slate |
27 |
{
|
481
by Brian Aker
Remove all of uchar. |
28 |
unsigned char *tmp; |
482
by Brian Aker
Remove uint. |
29 |
uint32_t page_size; |
1
by brian
clean slate |
30 |
|
1689.2.15
by Brian Aker
Encapsulate the key cache object in myisam. |
31 |
tmp=(unsigned char*) key_cache_read(info->s->getKeyCache(), |
481
by Brian Aker
Remove all of uchar. |
32 |
info->s->kfile, page, level, (unsigned char*) buff, |
1
by brian
clean slate |
33 |
(uint) keyinfo->block_length, |
34 |
(uint) keyinfo->block_length, |
|
35 |
return_buffer); |
|
36 |
if (tmp == info->buff) |
|
37 |
info->buff_used=1; |
|
38 |
else if (!tmp) |
|
39 |
{
|
|
40 |
info->last_keypage=HA_OFFSET_ERROR; |
|
41 |
mi_print_error(info->s, HA_ERR_CRASHED); |
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
42 |
errno=HA_ERR_CRASHED; |
51.1.105
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
43 |
return(0); |
1
by brian
clean slate |
44 |
}
|
45 |
info->last_keypage=page; |
|
46 |
page_size=mi_getint(tmp); |
|
47 |
if (page_size < 4 || page_size > keyinfo->block_length) |
|
48 |
{
|
|
49 |
info->last_keypage = HA_OFFSET_ERROR; |
|
50 |
mi_print_error(info->s, HA_ERR_CRASHED); |
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
51 |
errno = HA_ERR_CRASHED; |
1
by brian
clean slate |
52 |
tmp = 0; |
53 |
}
|
|
51.1.105
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
54 |
return(tmp); |
1
by brian
clean slate |
55 |
} /* _mi_fetch_keypage */ |
56 |
||
57 |
||
58 |
/* Write a key-page on disk */
|
|
59 |
||
60 |
int _mi_write_keypage(register MI_INFO *info, register MI_KEYDEF *keyinfo, |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
61 |
internal::my_off_t page, int level, unsigned char *buff) |
1
by brian
clean slate |
62 |
{
|
482
by Brian Aker
Remove uint. |
63 |
register uint32_t length; |
1
by brian
clean slate |
64 |
|
65 |
#ifndef FAST /* Safety check */ |
|
66 |
if (page < info->s->base.keystart || |
|
67 |
page+keyinfo->block_length > info->state->key_file_length || |
|
68 |
(page & (MI_MIN_KEY_BLOCK_LENGTH-1))) |
|
69 |
{
|
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
70 |
errno=EINVAL; |
51.1.105
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
71 |
return((-1)); |
1
by brian
clean slate |
72 |
}
|
73 |
#endif
|
|
74 |
||
75 |
if ((length=keyinfo->block_length) > IO_SIZE*2 && |
|
76 |
info->state->key_file_length != page+length) |
|
77 |
length= ((mi_getint(buff)+IO_SIZE-1) & (uint) ~(IO_SIZE-1)); |
|
1859.2.14
by Brian Aker
Add support for --with-valgrind |
78 |
#ifdef HAVE_VALGRIND
|
1
by brian
clean slate |
79 |
{
|
80 |
length=mi_getint(buff); |
|
212.6.12
by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove(). |
81 |
memset(buff+length, 0, keyinfo->block_length-length); |
1
by brian
clean slate |
82 |
length=keyinfo->block_length; |
83 |
}
|
|
84 |
#endif
|
|
1689.2.15
by Brian Aker
Encapsulate the key cache object in myisam. |
85 |
return((key_cache_write(info->s->getKeyCache(), |
481
by Brian Aker
Remove all of uchar. |
86 |
info->s->kfile,page, level, (unsigned char*) buff,length, |
1
by brian
clean slate |
87 |
(uint) keyinfo->block_length, |
88 |
(int) ((info->lock_type != F_UNLCK) || |
|
89 |
info->s->delay_key_write)))); |
|
90 |
} /* mi_write_keypage */ |
|
91 |
||
92 |
||
93 |
/* Remove page from disk */
|
|
94 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
95 |
int _mi_dispose(register MI_INFO *info, MI_KEYDEF *keyinfo, internal::my_off_t pos, |
1
by brian
clean slate |
96 |
int level) |
97 |
{
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
98 |
internal::my_off_t old_link; |
481
by Brian Aker
Remove all of uchar. |
99 |
unsigned char buff[8]; |
1
by brian
clean slate |
100 |
|
101 |
old_link= info->s->state.key_del[keyinfo->block_size_index]; |
|
102 |
info->s->state.key_del[keyinfo->block_size_index]= pos; |
|
103 |
mi_sizestore(buff,old_link); |
|
104 |
info->s->state.changed|= STATE_NOT_SORTED_PAGES; |
|
1689.2.15
by Brian Aker
Encapsulate the key cache object in myisam. |
105 |
return(key_cache_write(info->s->getKeyCache(), |
1
by brian
clean slate |
106 |
info->s->kfile, pos , level, buff, |
107 |
sizeof(buff), |
|
108 |
(uint) keyinfo->block_length, |
|
109 |
(int) (info->lock_type != F_UNLCK))); |
|
110 |
} /* _mi_dispose */ |
|
111 |
||
112 |
||
113 |
/* Make new page on disk */
|
|
114 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
115 |
internal::my_off_t _mi_new(register MI_INFO *info, MI_KEYDEF *keyinfo, int level) |
1
by brian
clean slate |
116 |
{
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
117 |
internal::my_off_t pos; |
481
by Brian Aker
Remove all of uchar. |
118 |
unsigned char buff[8]; |
1
by brian
clean slate |
119 |
|
120 |
if ((pos= info->s->state.key_del[keyinfo->block_size_index]) == |
|
121 |
HA_OFFSET_ERROR) |
|
122 |
{
|
|
123 |
if (info->state->key_file_length >= |
|
124 |
info->s->base.max_key_file_length - keyinfo->block_length) |
|
125 |
{
|
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
126 |
errno=HA_ERR_INDEX_FILE_FULL; |
51.1.105
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
127 |
return(HA_OFFSET_ERROR); |
1
by brian
clean slate |
128 |
}
|
129 |
pos=info->state->key_file_length; |
|
130 |
info->state->key_file_length+= keyinfo->block_length; |
|
131 |
}
|
|
132 |
else
|
|
133 |
{
|
|
1689.2.15
by Brian Aker
Encapsulate the key cache object in myisam. |
134 |
if (!key_cache_read(info->s->getKeyCache(), |
1
by brian
clean slate |
135 |
info->s->kfile, pos, level, |
136 |
buff, |
|
137 |
(uint) sizeof(buff), |
|
138 |
(uint) keyinfo->block_length,0)) |
|
139 |
pos= HA_OFFSET_ERROR; |
|
140 |
else
|
|
141 |
info->s->state.key_del[keyinfo->block_size_index]= mi_sizekorr(buff); |
|
142 |
}
|
|
143 |
info->s->state.changed|= STATE_NOT_SORTED_PAGES; |
|
51.1.105
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
144 |
return(pos); |
1
by brian
clean slate |
145 |
} /* _mi_new */ |