~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/mi_statrec.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 01:03:01 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913010301-tcvvezipx1124acy
Added calls to the dtrace delete begin/end probes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
 
 
16
 
        /* Functions to handle fixed-length-records */
17
 
 
18
 
#include "myisam_priv.h"
19
 
 
20
 
using namespace drizzled;
21
 
 
22
 
int _mi_write_static_record(MI_INFO *info, const unsigned char *record)
23
 
{
24
 
  unsigned char temp[8];                                /* max pointer length */
25
 
  if (info->s->state.dellink != HA_OFFSET_ERROR &&
26
 
      !info->append_insert_at_end)
27
 
  {
28
 
    internal::my_off_t filepos=info->s->state.dellink;
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
 
    {
47
 
      errno=HA_ERR_RECORD_FILE_FULL;
48
 
      return(2);
49
 
    }
50
 
    if (info->opt_flag & WRITE_CACHE_USED)
51
 
    {                           /* Cash in use */
52
 
      if (my_b_write(&info->rec_cache, record,
53
 
                     info->s->base.reclength))
54
 
        goto err;
55
 
      if (info->s->base.pack_reclength != info->s->base.reclength)
56
 
      {
57
 
        uint32_t length=info->s->base.pack_reclength - info->s->base.reclength;
58
 
        memset(temp, 0, length);
59
 
        if (my_b_write(&info->rec_cache, temp,length))
60
 
          goto err;
61
 
      }
62
 
    }
63
 
    else
64
 
    {
65
 
      info->rec_cache.seek_not_done=1;          /* We have done a seek */
66
 
      if (info->s->file_write(info, record, info->s->base.reclength,
67
 
                    info->state->data_file_length,
68
 
                    info->s->write_flag))
69
 
        goto err;
70
 
      if (info->s->base.pack_reclength != info->s->base.reclength)
71
 
      {
72
 
        uint32_t length=info->s->base.pack_reclength - info->s->base.reclength;
73
 
        memset(temp, 0, length);
74
 
        if (info->s->file_write(info, temp,length,
75
 
                      info->state->data_file_length+
76
 
                      info->s->base.reclength,
77
 
                      info->s->write_flag))
78
 
    goto err;
79
 
      }
80
 
    }
81
 
    info->state->data_file_length+=info->s->base.pack_reclength;
82
 
    info->s->state.split++;
83
 
  }
84
 
  return 0;
85
 
 err:
86
 
  return 1;
87
 
}
88
 
 
89
 
int _mi_update_static_record(MI_INFO *info, internal::my_off_t pos, const unsigned char *record)
90
 
{
91
 
  info->rec_cache.seek_not_done=1;              /* We have done a seek */
92
 
  return (info->s->file_write(info,
93
 
                              record, info->s->base.reclength,
94
 
                              pos,
95
 
                              MYF(MY_NABP)) != 0);
96
 
}
97
 
 
98
 
 
99
 
int _mi_delete_static_record(MI_INFO *info)
100
 
{
101
 
  unsigned char temp[9];                                /* 1+sizeof(uint32) */
102
 
 
103
 
  info->state->del++;
104
 
  info->state->empty+=info->s->base.pack_reclength;
105
 
  temp[0]= '\0';                        /* Mark that record is deleted */
106
 
  _mi_dpointer(info,temp+1,info->s->state.dellink);
107
 
  info->s->state.dellink = info->lastpos;
108
 
  info->rec_cache.seek_not_done=1;
109
 
  return (info->s->file_write(info,(unsigned char*) temp, 1+info->s->rec_reflength,
110
 
                    info->lastpos, MYF(MY_NABP)) != 0);
111
 
}
112
 
 
113
 
 
114
 
int _mi_cmp_static_record(register MI_INFO *info, register const unsigned char *old)
115
 
{
116
 
  if (info->opt_flag & WRITE_CACHE_USED)
117
 
  {
118
 
    if (flush_io_cache(&info->rec_cache))
119
 
    {
120
 
      return(-1);
121
 
    }
122
 
    info->rec_cache.seek_not_done=1;            /* We have done a seek */
123
 
  }
124
 
 
125
 
  if ((info->opt_flag & READ_CHECK_USED))
126
 
  {                                             /* If check isn't disabled  */
127
 
    info->rec_cache.seek_not_done=1;            /* We have done a seek */
128
 
    if (info->s->file_read(info, info->rec_buff, info->s->base.reclength,
129
 
                 info->lastpos,
130
 
                 MYF(MY_NABP)))
131
 
      return(-1);
132
 
    if (memcmp(info->rec_buff, old,
133
 
               (uint) info->s->base.reclength))
134
 
    {
135
 
      errno=HA_ERR_RECORD_CHANGED;              /* Record have changed */
136
 
      return(1);
137
 
    }
138
 
  }
139
 
  return(0);
140
 
}
141
 
 
142
 
 
143
 
int _mi_cmp_static_unique(MI_INFO *info, MI_UNIQUEDEF *def,
144
 
                          const unsigned char *record, internal::my_off_t pos)
145
 
{
146
 
  info->rec_cache.seek_not_done=1;              /* We have done a seek */
147
 
  if (info->s->file_read(info, info->rec_buff, info->s->base.reclength,
148
 
               pos, MYF(MY_NABP)))
149
 
    return(-1);
150
 
  return(mi_unique_comp(def, record, info->rec_buff,
151
 
                             def->null_are_equal));
152
 
}
153
 
 
154
 
 
155
 
        /* Read a fixed-length-record */
156
 
        /* Returns 0 if Ok. */
157
 
        /*         1 if record is deleted */
158
 
        /*        MY_FILE_ERROR on read-error or locking-error */
159
 
 
160
 
int _mi_read_static_record(register MI_INFO *info, register internal::my_off_t pos,
161
 
                           register unsigned char *record)
162
 
{
163
 
  int error;
164
 
 
165
 
  if (pos != HA_OFFSET_ERROR)
166
 
  {
167
 
    if (info->opt_flag & WRITE_CACHE_USED &&
168
 
        info->rec_cache.pos_in_file <= pos &&
169
 
        flush_io_cache(&info->rec_cache))
170
 
      return(-1);
171
 
    info->rec_cache.seek_not_done=1;            /* We have done a seek */
172
 
 
173
 
    error=info->s->file_read(info, record, info->s->base.reclength,
174
 
                   pos,MYF(MY_NABP)) != 0;
175
 
    fast_mi_writeinfo(info);
176
 
    if (! error)
177
 
    {
178
 
      if (!*record)
179
 
      {
180
 
        errno=HA_ERR_RECORD_DELETED;
181
 
        return(1);                              /* Record is deleted */
182
 
      }
183
 
      info->update|= HA_STATE_AKTIV;            /* Record is read */
184
 
      return(0);
185
 
    }
186
 
    return(-1);                                 /* Error on read */
187
 
  }
188
 
  fast_mi_writeinfo(info);                      /* No such record */
189
 
  return(-1);
190
 
}
191
 
 
192
 
 
193
 
 
194
 
int _mi_read_rnd_static_record(MI_INFO *info, unsigned char *buf,
195
 
                               register internal::my_off_t filepos,
196
 
                               bool skip_deleted_blocks)
197
 
{
198
 
  int locked,error,cache_read;
199
 
  uint32_t cache_length;
200
 
  MYISAM_SHARE *share=info->s;
201
 
 
202
 
  cache_read=0;
203
 
  cache_length=0;
204
 
  if (info->opt_flag & WRITE_CACHE_USED &&
205
 
      (info->rec_cache.pos_in_file <= filepos || skip_deleted_blocks) &&
206
 
      flush_io_cache(&info->rec_cache))
207
 
    return(errno);
208
 
  if (info->opt_flag & READ_CACHE_USED)
209
 
  {                                             /* Cache in use */
210
 
    if (filepos == my_b_tell(&info->rec_cache) &&
211
 
        (skip_deleted_blocks || !filepos))
212
 
    {
213
 
      cache_read=1;                             /* Read record using cache */
214
 
      cache_length=(uint) (info->rec_cache.read_end - info->rec_cache.read_pos);
215
 
    }
216
 
    else
217
 
      info->rec_cache.seek_not_done=1;          /* Filepos is changed */
218
 
  }
219
 
  locked=0;
220
 
  if (info->lock_type == F_UNLCK)
221
 
  {
222
 
    if (filepos >= info->state->data_file_length)
223
 
    {                                           /* Test if new records */
224
 
      if (_mi_readinfo(info,F_RDLCK,0))
225
 
        return(errno);
226
 
      locked=1;
227
 
    }
228
 
    else
229
 
    {                                           /* We don't nead new info */
230
 
#ifndef UNSAFE_LOCKING
231
 
      locked=1;
232
 
#else
233
 
      info->tmp_lock_type=F_RDLCK;
234
 
#endif
235
 
    }
236
 
  }
237
 
  if (filepos >= info->state->data_file_length)
238
 
  {
239
 
    fast_mi_writeinfo(info);
240
 
    return(errno=HA_ERR_END_OF_FILE);
241
 
  }
242
 
  info->lastpos= filepos;
243
 
  info->nextpos= filepos+share->base.pack_reclength;
244
 
 
245
 
  if (! cache_read)                     /* No cacheing */
246
 
  {
247
 
    if ((error=_mi_read_static_record(info,filepos,buf)))
248
 
    {
249
 
      if (error > 0)
250
 
        error=errno=HA_ERR_RECORD_DELETED;
251
 
      else
252
 
        error=errno;
253
 
    }
254
 
    return(error);
255
 
  }
256
 
 
257
 
        /* Read record with cacheing */
258
 
  error=my_b_read(&info->rec_cache,(unsigned char*) buf,share->base.reclength);
259
 
  if (info->s->base.pack_reclength != info->s->base.reclength && !error)
260
 
  {
261
 
    char tmp[8];                                /* Skill fill bytes */
262
 
    error=my_b_read(&info->rec_cache,(unsigned char*) tmp,
263
 
                    info->s->base.pack_reclength - info->s->base.reclength);
264
 
  }
265
 
  if (locked)
266
 
    _mi_writeinfo(info,0);              /* Unlock keyfile */
267
 
  if (!error)
268
 
  {
269
 
    if (!buf[0])
270
 
    {                                           /* Record is removed */
271
 
      return(errno=HA_ERR_RECORD_DELETED);
272
 
    }
273
 
                                                /* Found and may be updated */
274
 
    info->update|= HA_STATE_AKTIV | HA_STATE_KEY_CHANGED;
275
 
    return(0);
276
 
  }
277
 
  /* errno should be set if rec_cache.error == -1 */
278
 
  if (info->rec_cache.error != -1 || errno == 0)
279
 
    errno=HA_ERR_WRONG_IN_RECORD;
280
 
  return(errno);                        /* Something wrong (EOF?) */
281
 
}