1
by brian
clean slate |
1 |
/* Copyright (C) 2000-2002, 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 |
/* Functions to handle fixed-length-records */
|
|
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 |
||
481
by Brian Aker
Remove all of uchar. |
22 |
int _mi_write_static_record(MI_INFO *info, const unsigned char *record) |
1
by brian
clean slate |
23 |
{
|
481
by Brian Aker
Remove all of uchar. |
24 |
unsigned char temp[8]; /* max pointer length */ |
1
by brian
clean slate |
25 |
if (info->s->state.dellink != HA_OFFSET_ERROR && |
26 |
!info->append_insert_at_end) |
|
27 |
{
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
28 |
internal::my_off_t filepos=info->s->state.dellink; |
1
by brian
clean slate |
29 |
info->rec_cache.seek_not_done=1; /* We have done a seek */ |
30 |
if (info->s->file_read(info, &temp[0],info->s->base.rec_reflength, |
|
31 |
info->s->state.dellink+1, |
|
32 |
MYF(MY_NABP))) |
|
33 |
goto err; |
|
34 |
info->s->state.dellink= _mi_rec_pos(info->s,temp); |
|
35 |
info->state->del--; |
|
36 |
info->state->empty-=info->s->base.pack_reclength; |
|
37 |
if (info->s->file_write(info, record, info->s->base.reclength, |
|
38 |
filepos, |
|
39 |
MYF(MY_NABP))) |
|
40 |
goto err; |
|
41 |
}
|
|
42 |
else
|
|
43 |
{
|
|
44 |
if (info->state->data_file_length > info->s->base.max_data_file_length- |
|
45 |
info->s->base.pack_reclength) |
|
46 |
{
|
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
47 |
errno=HA_ERR_RECORD_FILE_FULL; |
1
by brian
clean slate |
48 |
return(2); |
49 |
}
|
|
50 |
if (info->opt_flag & WRITE_CACHE_USED) |
|
51 |
{ /* Cash in use */ |
|
2385.3.13
by Olaf van der Spek
Refactor iocache |
52 |
if (info->rec_cache.write(record, info->s->base.reclength)) |
1
by brian
clean slate |
53 |
goto err; |
54 |
if (info->s->base.pack_reclength != info->s->base.reclength) |
|
55 |
{
|
|
482
by Brian Aker
Remove uint. |
56 |
uint32_t length=info->s->base.pack_reclength - info->s->base.reclength; |
212.6.1
by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file. |
57 |
memset(temp, 0, length); |
2385.3.13
by Olaf van der Spek
Refactor iocache |
58 |
if (info->rec_cache.write(temp,length)) |
1
by brian
clean slate |
59 |
goto err; |
60 |
}
|
|
61 |
}
|
|
62 |
else
|
|
63 |
{
|
|
64 |
info->rec_cache.seek_not_done=1; /* We have done a seek */ |
|
65 |
if (info->s->file_write(info, record, info->s->base.reclength, |
|
66 |
info->state->data_file_length, |
|
67 |
info->s->write_flag)) |
|
68 |
goto err; |
|
69 |
if (info->s->base.pack_reclength != info->s->base.reclength) |
|
70 |
{
|
|
482
by Brian Aker
Remove uint. |
71 |
uint32_t length=info->s->base.pack_reclength - info->s->base.reclength; |
212.6.1
by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file. |
72 |
memset(temp, 0, length); |
1
by brian
clean slate |
73 |
if (info->s->file_write(info, temp,length, |
74 |
info->state->data_file_length+ |
|
75 |
info->s->base.reclength, |
|
76 |
info->s->write_flag)) |
|
77 |
goto err; |
|
78 |
}
|
|
79 |
}
|
|
80 |
info->state->data_file_length+=info->s->base.pack_reclength; |
|
81 |
info->s->state.split++; |
|
82 |
}
|
|
83 |
return 0; |
|
84 |
err: |
|
85 |
return 1; |
|
86 |
}
|
|
87 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
88 |
int _mi_update_static_record(MI_INFO *info, internal::my_off_t pos, const unsigned char *record) |
1
by brian
clean slate |
89 |
{
|
90 |
info->rec_cache.seek_not_done=1; /* We have done a seek */ |
|
91 |
return (info->s->file_write(info, |
|
92 |
record, info->s->base.reclength, |
|
93 |
pos, |
|
94 |
MYF(MY_NABP)) != 0); |
|
95 |
}
|
|
96 |
||
97 |
||
98 |
int _mi_delete_static_record(MI_INFO *info) |
|
99 |
{
|
|
481
by Brian Aker
Remove all of uchar. |
100 |
unsigned char temp[9]; /* 1+sizeof(uint32) */ |
1
by brian
clean slate |
101 |
|
102 |
info->state->del++; |
|
103 |
info->state->empty+=info->s->base.pack_reclength; |
|
104 |
temp[0]= '\0'; /* Mark that record is deleted */ |
|
105 |
_mi_dpointer(info,temp+1,info->s->state.dellink); |
|
106 |
info->s->state.dellink = info->lastpos; |
|
107 |
info->rec_cache.seek_not_done=1; |
|
481
by Brian Aker
Remove all of uchar. |
108 |
return (info->s->file_write(info,(unsigned char*) temp, 1+info->s->rec_reflength, |
1
by brian
clean slate |
109 |
info->lastpos, MYF(MY_NABP)) != 0); |
110 |
}
|
|
111 |
||
112 |
||
481
by Brian Aker
Remove all of uchar. |
113 |
int _mi_cmp_static_record(register MI_INFO *info, register const unsigned char *old) |
1
by brian
clean slate |
114 |
{
|
115 |
if (info->opt_flag & WRITE_CACHE_USED) |
|
116 |
{
|
|
2385.3.9
by Olaf van der Spek
Move flush() into iocache |
117 |
if (info->rec_cache.flush()) |
1
by brian
clean slate |
118 |
{
|
51.1.112
by Jay Pipes
Removed DBUG symbols |
119 |
return(-1); |
1
by brian
clean slate |
120 |
}
|
121 |
info->rec_cache.seek_not_done=1; /* We have done a seek */ |
|
122 |
}
|
|
123 |
||
124 |
if ((info->opt_flag & READ_CHECK_USED)) |
|
125 |
{ /* If check isn't disabled */ |
|
126 |
info->rec_cache.seek_not_done=1; /* We have done a seek */ |
|
127 |
if (info->s->file_read(info, info->rec_buff, info->s->base.reclength, |
|
128 |
info->lastpos, |
|
129 |
MYF(MY_NABP))) |
|
51.1.112
by Jay Pipes
Removed DBUG symbols |
130 |
return(-1); |
1
by brian
clean slate |
131 |
if (memcmp(info->rec_buff, old, |
132 |
(uint) info->s->base.reclength)) |
|
133 |
{
|
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
134 |
errno=HA_ERR_RECORD_CHANGED; /* Record have changed */ |
51.1.112
by Jay Pipes
Removed DBUG symbols |
135 |
return(1); |
1
by brian
clean slate |
136 |
}
|
137 |
}
|
|
51.1.112
by Jay Pipes
Removed DBUG symbols |
138 |
return(0); |
1
by brian
clean slate |
139 |
}
|
140 |
||
141 |
||
142 |
int _mi_cmp_static_unique(MI_INFO *info, MI_UNIQUEDEF *def, |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
143 |
const unsigned char *record, internal::my_off_t pos) |
1
by brian
clean slate |
144 |
{
|
145 |
info->rec_cache.seek_not_done=1; /* We have done a seek */ |
|
146 |
if (info->s->file_read(info, info->rec_buff, info->s->base.reclength, |
|
147 |
pos, MYF(MY_NABP))) |
|
51.1.112
by Jay Pipes
Removed DBUG symbols |
148 |
return(-1); |
149 |
return(mi_unique_comp(def, record, info->rec_buff, |
|
1
by brian
clean slate |
150 |
def->null_are_equal)); |
151 |
}
|
|
152 |
||
153 |
||
154 |
/* Read a fixed-length-record */
|
|
155 |
/* Returns 0 if Ok. */
|
|
156 |
/* 1 if record is deleted */
|
|
157 |
/* MY_FILE_ERROR on read-error or locking-error */
|
|
158 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
159 |
int _mi_read_static_record(register MI_INFO *info, register internal::my_off_t pos, |
481
by Brian Aker
Remove all of uchar. |
160 |
register unsigned char *record) |
1
by brian
clean slate |
161 |
{
|
162 |
if (pos != HA_OFFSET_ERROR) |
|
163 |
{
|
|
164 |
if (info->opt_flag & WRITE_CACHE_USED && |
|
165 |
info->rec_cache.pos_in_file <= pos && |
|
2385.3.9
by Olaf van der Spek
Move flush() into iocache |
166 |
info->rec_cache.flush()) |
1
by brian
clean slate |
167 |
return(-1); |
168 |
info->rec_cache.seek_not_done=1; /* We have done a seek */ |
|
169 |
||
2409.2.2
by Olaf van der Spek
cppcheck |
170 |
int error= info->s->file_read(info, record, info->s->base.reclength, pos,MYF(MY_NABP)) != 0; |
1
by brian
clean slate |
171 |
fast_mi_writeinfo(info); |
172 |
if (! error) |
|
173 |
{
|
|
174 |
if (!*record) |
|
175 |
{
|
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
176 |
errno=HA_ERR_RECORD_DELETED; |
1
by brian
clean slate |
177 |
return(1); /* Record is deleted */ |
178 |
}
|
|
179 |
info->update|= HA_STATE_AKTIV; /* Record is read */ |
|
180 |
return(0); |
|
181 |
}
|
|
182 |
return(-1); /* Error on read */ |
|
183 |
}
|
|
184 |
fast_mi_writeinfo(info); /* No such record */ |
|
185 |
return(-1); |
|
186 |
}
|
|
187 |
||
188 |
||
189 |
||
481
by Brian Aker
Remove all of uchar. |
190 |
int _mi_read_rnd_static_record(MI_INFO *info, unsigned char *buf, |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
191 |
register internal::my_off_t filepos, |
281
by Brian Aker
Converted myisam away from my_bool |
192 |
bool skip_deleted_blocks) |
1
by brian
clean slate |
193 |
{
|
194 |
int locked,error,cache_read; |
|
195 |
MYISAM_SHARE *share=info->s; |
|
196 |
||
197 |
cache_read=0; |
|
198 |
if (info->opt_flag & WRITE_CACHE_USED && |
|
199 |
(info->rec_cache.pos_in_file <= filepos || skip_deleted_blocks) && |
|
2385.3.9
by Olaf van der Spek
Move flush() into iocache |
200 |
info->rec_cache.flush()) |
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
201 |
return(errno); |
1
by brian
clean slate |
202 |
if (info->opt_flag & READ_CACHE_USED) |
203 |
{ /* Cache in use */ |
|
2385.3.12
by Olaf van der Spek
Refactor iocache |
204 |
if (filepos == info->rec_cache.tell() && |
1
by brian
clean slate |
205 |
(skip_deleted_blocks || !filepos)) |
206 |
{
|
|
207 |
cache_read=1; /* Read record using cache */ |
|
208 |
}
|
|
209 |
else
|
|
210 |
info->rec_cache.seek_not_done=1; /* Filepos is changed */ |
|
211 |
}
|
|
212 |
locked=0; |
|
213 |
if (info->lock_type == F_UNLCK) |
|
214 |
{
|
|
215 |
if (filepos >= info->state->data_file_length) |
|
216 |
{ /* Test if new records */ |
|
217 |
if (_mi_readinfo(info,F_RDLCK,0)) |
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
218 |
return(errno); |
1
by brian
clean slate |
219 |
locked=1; |
220 |
}
|
|
221 |
else
|
|
222 |
{ /* We don't nead new info */ |
|
223 |
#ifndef UNSAFE_LOCKING
|
|
77.1.96
by Monty Taylor
Removed skip-external-locking. |
224 |
locked=1; |
1
by brian
clean slate |
225 |
#else
|
226 |
info->tmp_lock_type=F_RDLCK; |
|
227 |
#endif
|
|
228 |
}
|
|
229 |
}
|
|
230 |
if (filepos >= info->state->data_file_length) |
|
231 |
{
|
|
232 |
fast_mi_writeinfo(info); |
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
233 |
return(errno=HA_ERR_END_OF_FILE); |
1
by brian
clean slate |
234 |
}
|
235 |
info->lastpos= filepos; |
|
236 |
info->nextpos= filepos+share->base.pack_reclength; |
|
237 |
||
238 |
if (! cache_read) /* No cacheing */ |
|
239 |
{
|
|
240 |
if ((error=_mi_read_static_record(info,filepos,buf))) |
|
241 |
{
|
|
242 |
if (error > 0) |
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
243 |
error=errno=HA_ERR_RECORD_DELETED; |
1
by brian
clean slate |
244 |
else
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
245 |
error=errno; |
1
by brian
clean slate |
246 |
}
|
51.1.112
by Jay Pipes
Removed DBUG symbols |
247 |
return(error); |
1
by brian
clean slate |
248 |
}
|
249 |
||
250 |
/* Read record with cacheing */
|
|
2385.3.13
by Olaf van der Spek
Refactor iocache |
251 |
error= info->rec_cache.read(buf, share->base.reclength); |
1
by brian
clean slate |
252 |
if (info->s->base.pack_reclength != info->s->base.reclength && !error) |
253 |
{
|
|
254 |
char tmp[8]; /* Skill fill bytes */ |
|
2385.3.13
by Olaf van der Spek
Refactor iocache |
255 |
error= info->rec_cache.read(tmp, info->s->base.pack_reclength - info->s->base.reclength); |
1
by brian
clean slate |
256 |
}
|
257 |
if (locked) |
|
398.1.10
by Monty Taylor
Actually removed VOID() this time. |
258 |
_mi_writeinfo(info,0); /* Unlock keyfile */ |
1
by brian
clean slate |
259 |
if (!error) |
260 |
{
|
|
261 |
if (!buf[0]) |
|
262 |
{ /* Record is removed */ |
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
263 |
return(errno=HA_ERR_RECORD_DELETED); |
1
by brian
clean slate |
264 |
}
|
265 |
/* Found and may be updated */
|
|
266 |
info->update|= HA_STATE_AKTIV | HA_STATE_KEY_CHANGED; |
|
51.1.112
by Jay Pipes
Removed DBUG symbols |
267 |
return(0); |
1
by brian
clean slate |
268 |
}
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
269 |
/* errno should be set if rec_cache.error == -1 */
|
270 |
if (info->rec_cache.error != -1 || errno == 0) |
|
271 |
errno=HA_ERR_WRONG_IN_RECORD; |
|
272 |
return(errno); /* Something wrong (EOF?) */ |
|
1
by brian
clean slate |
273 |
}
|