~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_dynrec.c

  • Committer: Monty Taylor
  • Date: 2009-03-04 02:16:28 UTC
  • mto: (917.1.2 mordred)
  • mto: This revision was merged to the branch mainline in revision 912.
  • Revision ID: mordred@inaugust.com-20090304021628-rfq0b16uoi09g8tx
Fix to make VPATH builds work again.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/*
17
17
  Functions to handle space-packed-records and blobs
18
 
 
 
18
 
19
19
  A row may be stored in one or more linked blocks.
20
20
  The block size is between MI_MIN_BLOCK_LENGTH and MI_MAX_BLOCK_LENGTH.
21
21
  Each block is aligned on MI_DYN_ALIGN_SIZE.
31
31
#ifdef HAVE_SYS_MMAN_H
32
32
#include <sys/mman.h>
33
33
#endif
 
34
#include <drizzled/util/test.h>
34
35
 
35
36
/* Enough for comparing if number is zero */
36
37
static char zero_string[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
46
47
static int _mi_cmp_buffer(File file, const unsigned char *buff, my_off_t filepos,
47
48
                          uint32_t length);
48
49
 
49
 
/* Play it safe; We have a small stack when using threads */
50
 
#undef my_alloca
51
 
#undef my_afree
52
 
#define my_alloca(A) malloc((A))
53
 
#define my_afree(A) free((A))
54
 
 
55
50
        /* Interface function from MI_INFO */
56
51
 
57
52
#ifdef HAVE_MMAP
93
88
    info->s->file_map= NULL;
94
89
    return(1);
95
90
  }
96
 
#if defined(HAVE_MADVISE)
 
91
/* per krow we should look at removing the following code */
 
92
#if defined(HAVE_MADVISE) && !defined(TARGET_OS_SOLARIS)
97
93
  madvise((char*) info->s->file_map, size, MADV_RANDOM);
98
94
#endif
99
95
  info->s->mmaped_length= size;
132
128
    Buffer              Input buffer
133
129
    Count               Count of bytes for read
134
130
    offset              Start position
135
 
    MyFlags             
 
131
    MyFlags
136
132
 
137
133
  RETURN
138
134
    0  ok
142
138
                    size_t Count, my_off_t offset, myf MyFlags)
143
139
{
144
140
  if (info->s->concurrent_insert)
145
 
    rw_rdlock(&info->s->mmap_lock);
 
141
    pthread_rwlock_rdlock(&info->s->mmap_lock);
146
142
 
147
143
  /*
148
144
    The following test may fail in the following cases:
155
151
  {
156
152
    memcpy(Buffer, info->s->file_map + offset, Count);
157
153
    if (info->s->concurrent_insert)
158
 
      rw_unlock(&info->s->mmap_lock);
 
154
      pthread_rwlock_unlock(&info->s->mmap_lock);
159
155
    return 0;
160
156
  }
161
157
  else
162
158
  {
163
159
    if (info->s->concurrent_insert)
164
 
      rw_unlock(&info->s->mmap_lock);
 
160
      pthread_rwlock_unlock(&info->s->mmap_lock);
165
161
    return my_pread(info->dfile, Buffer, Count, offset, MyFlags);
166
162
  }
167
163
}
185
181
    Buffer              Output buffer
186
182
    Count               Count of bytes for write
187
183
    offset              Start position
188
 
    MyFlags             
 
184
    MyFlags
189
185
 
190
186
  RETURN
191
187
    0  ok
196
192
                      size_t Count, my_off_t offset, myf MyFlags)
197
193
{
198
194
  if (info->s->concurrent_insert)
199
 
    rw_rdlock(&info->s->mmap_lock);
 
195
    pthread_rwlock_rdlock(&info->s->mmap_lock);
200
196
 
201
197
  /*
202
198
    The following test may fail in the following cases:
207
203
 
208
204
  if (info->s->mmaped_length >= offset + Count)
209
205
  {
210
 
    memcpy(info->s->file_map + offset, Buffer, Count); 
 
206
    memcpy(info->s->file_map + offset, Buffer, Count);
211
207
    if (info->s->concurrent_insert)
212
 
      rw_unlock(&info->s->mmap_lock);
 
208
      pthread_rwlock_unlock(&info->s->mmap_lock);
213
209
    return 0;
214
210
  }
215
211
  else
216
212
  {
217
213
    info->s->nonmmaped_inserts++;
218
214
    if (info->s->concurrent_insert)
219
 
      rw_unlock(&info->s->mmap_lock);
 
215
      pthread_rwlock_unlock(&info->s->mmap_lock);
220
216
    return my_pwrite(info->dfile, Buffer, Count, offset, MyFlags);
221
217
  }
222
218
 
261
257
    return -1;
262
258
  }
263
259
#endif
264
 
  if (!(rec_buff=(unsigned char*) my_alloca(reclength)))
 
260
  if (!(rec_buff=(unsigned char*) malloc(reclength)))
265
261
  {
266
262
    my_errno= HA_ERR_OUT_OF_MEM; /* purecov: inspected */
267
263
    return(-1);
271
267
  assert(reclength2 <= reclength);
272
268
  error=write_dynamic_record(info,rec_buff+ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER),
273
269
                             reclength2);
274
 
  my_afree(rec_buff);
 
270
  free(rec_buff);
275
271
  return(error);
276
272
}
277
273
 
293
289
    return -1;
294
290
  }
295
291
#endif
296
 
  if (!(rec_buff=(unsigned char*) my_alloca(reclength)))
 
292
  if (!(rec_buff=(unsigned char*) malloc(reclength)))
297
293
  {
298
294
    my_errno= HA_ERR_OUT_OF_MEM; /* purecov: inspected */
299
295
    return(-1);
303
299
  error=update_dynamic_record(info,pos,
304
300
                              rec_buff+ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER),
305
301
                              reclength);
306
 
  my_afree(rec_buff);
 
302
  free(rec_buff);
307
303
  return(error);
308
304
}
309
305
 
687
683
        /* Make a long block for one write */
688
684
  record_end= *record+length-head_length;
689
685
  del_length=(res_length ? MI_DYN_DELETE_BLOCK_HEADER : 0);
690
 
  memcpy(*record - head_length, temp, head_length);
 
686
  memmove(*record - head_length, temp, head_length);
691
687
  memcpy(temp,record_end,(size_t) (extra_length+del_length));
692
688
  memset(record_end, 0, extra_length);
693
689
 
1506
1502
  unsigned char *rec_buff,*old_record;
1507
1503
  int error;
1508
1504
 
1509
 
  if (!(old_record=my_alloca(info->s->base.reclength)))
 
1505
  if (!(old_record=malloc(info->s->base.reclength)))
1510
1506
    return(1);
1511
1507
 
1512
1508
  /* Don't let the compare destroy blobs that may be in use */
1523
1519
      free(rec_buff_ptr);
1524
1520
    info->rec_buff=rec_buff;
1525
1521
  }
1526
 
  my_afree(old_record);
 
1522
  free(old_record);
1527
1523
  return(error);
1528
1524
}
1529
1525
 
1552
1548
  {                                             /* If check isn't disabled  */
1553
1549
    if (info->s->base.blobs)
1554
1550
    {
1555
 
      if (!(buffer=(unsigned char*) my_alloca(info->s->base.pack_reclength+
 
1551
      if (!(buffer=(unsigned char*) malloc(info->s->base.pack_reclength+
1556
1552
                                     _my_calc_total_blob_length(info,record))))
1557
1553
        return(-1);
1558
1554
    }
1600
1596
  my_errno=0;
1601
1597
err:
1602
1598
  if (buffer != info->rec_buff)
1603
 
    my_afree((unsigned char*) buffer);
 
1599
    free((unsigned char*) buffer);
1604
1600
  return(my_errno);
1605
1601
}
1606
1602
 
1796
1792
            block_info.filepos + block_info.data_len &&
1797
1793
            flush_io_cache(&info->rec_cache))
1798
1794
          goto err;
1799
 
        /* my_seek(info->dfile,filepos,MY_SEEK_SET,MYF(0)); */
 
1795
        /* lseek(info->dfile,filepos,SEEK_SET); */
1800
1796
        if (my_read(info->dfile,(unsigned char*) to,block_info.data_len,MYF(MY_NABP)))
1801
1797
        {
1802
1798
          if (my_errno == -1)
1849
1845
      pointer set to the end of the header after this function.
1850
1846
      my_pread() may leave the file pointer untouched.
1851
1847
    */
1852
 
    my_seek(file,filepos,MY_SEEK_SET,MYF(0));
 
1848
    lseek(file,filepos,SEEK_SET);
1853
1849
    if (my_read(file, header, sizeof(info->header),MYF(0)) !=
1854
1850
        sizeof(info->header))
1855
1851
      goto err;