~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_iocache.cc

  • Committer: Brian Aker
  • Date: 2009-05-15 17:06:35 UTC
  • mto: This revision was merged to the branch mainline in revision 1023.
  • Revision ID: brian@gaz-20090515170635-croy1u63a3gqdn9n
Dead convert functions for character sets.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
  write buffer to the read buffer before we start to reuse it.
48
48
*/
49
49
 
50
 
#define MAP_TO_USE_RAID
51
 
#include "mysys_priv.h"
 
50
#include "mysys/mysys_priv.h"
52
51
#include <mystrings/m_string.h>
53
52
#ifdef HAVE_AIOWAIT
54
 
#include "mysys_err.h"
 
53
#include "mysys/mysys_err.h"
 
54
#include <mysys/aio_result.h>
55
55
static void my_aiowait(my_aio_result *result);
56
56
#endif
 
57
#include <mysys/iocache.h>
57
58
#include <errno.h>
 
59
#include <drizzled/util/test.h>
 
60
#include <stdlib.h>
58
61
 
59
62
#define lock_append_buffer(info) \
60
63
 pthread_mutex_lock(&(info)->append_buffer_lock)
150
153
                  bool use_async_io, myf cache_myflags)
151
154
{
152
155
  size_t min_cache;
153
 
  my_off_t pos;
 
156
  off_t pos;
154
157
  my_off_t end_of_file= ~(my_off_t) 0;
155
158
 
156
159
  info->file= file;
164
167
 
165
168
  if (file >= 0)
166
169
  {
167
 
    pos= my_tell(file, MYF(0));
168
 
    if ((pos == (my_off_t) -1) && (my_errno == ESPIPE))
 
170
    pos= lseek(file, 0, SEEK_CUR);
 
171
    if ((pos == MY_FILEPOS_ERROR) && (my_errno == ESPIPE))
169
172
    {
170
173
      /*
171
174
         This kind of object doesn't support seek() or tell(). Don't set a
180
183
      assert(seek_offset == 0);
181
184
    }
182
185
    else
183
 
      info->seek_not_done= test(seek_offset != pos);
 
186
      info->seek_not_done= test(seek_offset != (my_off_t)pos);
184
187
  }
185
188
 
186
189
  info->disk_writes= 0;
194
197
    if (!(cache_myflags & MY_DONT_CHECK_FILESIZE))
195
198
    {
196
199
      /* Calculate end of file to avoid allocating oversized buffers */
197
 
      end_of_file=my_seek(file,0L,MY_SEEK_END,MYF(0));
 
200
      end_of_file=lseek(file,0L,SEEK_END);
198
201
      /* Need to reset seek_not_done now that we just did a seek. */
199
202
      info->seek_not_done= end_of_file == seek_offset ? 0 : 1;
200
203
      if (end_of_file < seek_offset)
221
224
      if (type == SEQ_READ_APPEND)
222
225
        buffer_block *= 2;
223
226
      if ((info->buffer=
224
 
           (unsigned char*) my_malloc(buffer_block,
225
 
                             MYF((cache_myflags & ~ MY_WME) |
226
 
                                 (cachesize == min_cache ? MY_WME : 0)))) != 0)
 
227
           (unsigned char*) malloc(buffer_block)) != 0)
227
228
      {
228
229
        info->write_buffer=info->buffer;
229
230
        if (type == SEQ_READ_APPEND)
247
248
    info->write_end = info->write_buffer + info->buffer_length;
248
249
    pthread_mutex_init(&info->append_buffer_lock,MY_MUTEX_INIT_FAST);
249
250
  }
250
 
#if defined(SAFE_MUTEX)
251
 
  else
252
 
  {
253
 
    /* Clear mutex so that safe_mutex will notice that it's not initialized */
254
 
    memset(&info->append_buffer_lock, 0, sizeof(info));
255
 
  }
256
 
#endif
257
251
 
258
252
  if (type == WRITE_CACHE)
259
253
    info->write_end=
313
307
 
314
308
bool reinit_io_cache(IO_CACHE *info, enum cache_type type,
315
309
                        my_off_t seek_offset,
316
 
                        bool use_async_io __attribute__((unused)),
 
310
                        bool use_async_io,
317
311
                        bool clear_cache)
318
312
{
319
313
  /* One can't do reinit with the following types */
395
389
    info->read_function=_my_b_async_read;
396
390
  }
397
391
  info->inited=0;
 
392
#else
 
393
  (void)use_async_io;
398
394
#endif
399
395
  return(0);
400
396
} /* reinit_io_cache */
445
441
  /* pos_in_file always point on where info->buffer was read */
446
442
  pos_in_file=info->pos_in_file+ (size_t) (info->read_end - info->buffer);
447
443
 
448
 
  /* 
 
444
  /*
449
445
    Whenever a function which operates on IO_CACHE flushes/writes
450
446
    some part of the IO_CACHE to disk it will set the property
451
447
    "seek_not_done" to indicate this to other functions operating
453
449
  */
454
450
  if (info->seek_not_done)
455
451
  {
456
 
    if ((my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0)) 
457
 
        != MY_FILEPOS_ERROR))
 
452
    if ((lseek(info->file,pos_in_file,SEEK_SET) != MY_FILEPOS_ERROR))
458
453
    {
459
454
      /* No error, reset seek_not_done flag. */
460
455
      info->seek_not_done= 0;
942
937
        */
943
938
        if (cache->seek_not_done)
944
939
        {
945
 
          if (my_seek(cache->file, pos_in_file, MY_SEEK_SET, MYF(0))
946
 
              == MY_FILEPOS_ERROR)
 
940
          if (lseek(cache->file, pos_in_file, SEEK_SET) == MY_FILEPOS_ERROR)
947
941
          {
948
942
            cache->error= -1;
949
943
            unlock_io_cache(cache);
1025
1019
  while (write_length)
1026
1020
  {
1027
1021
    size_t copy_length= cmin(write_length, write_cache->buffer_length);
1028
 
    int  __attribute__((unused)) rc;
 
1022
    int  rc;
1029
1023
 
1030
1024
    rc= lock_io_cache(write_cache, write_cache->pos_in_file);
1031
1025
    /* The writing thread does always have the lock when it awakes. */
1048
1042
 
1049
1043
/*
1050
1044
  Do sequential read from the SEQ_READ_APPEND cache.
1051
 
  
 
1045
 
1052
1046
  We do this in three stages:
1053
1047
   - first read from info->buffer
1054
1048
   - then if there are still data to read, try the file descriptor
1084
1078
    With read-append cache we must always do a seek before we read,
1085
1079
    because the write could have moved the file pointer astray
1086
1080
  */
1087
 
  if (my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0)) == MY_FILEPOS_ERROR)
 
1081
  if (lseek(info->file,pos_in_file,SEEK_SET) == MY_FILEPOS_ERROR)
1088
1082
  {
1089
1083
   info->error= -1;
1090
1084
   unlock_append_buffer(info);
1304
1298
      info->error=(int) (read_length+left_length);
1305
1299
      return 1;
1306
1300
    }
1307
 
    
1308
 
    if (my_seek(info->file,next_pos_in_file,MY_SEEK_SET,MYF(0))
1309
 
        == MY_FILEPOS_ERROR)
 
1301
 
 
1302
    if (lseek(info->file,next_pos_in_file,SEEK_SET) == MY_FILEPOS_ERROR)
1310
1303
    {
1311
1304
      info->error= -1;
1312
1305
      return (1);
1362
1355
  {
1363
1356
    info->aio_result.result.aio_errno=AIO_INPROGRESS;   /* Marker for test */
1364
1357
    if (aioread(info->file,read_buffer, max_length,
1365
 
                (my_off_t) next_pos_in_file,MY_SEEK_SET,
 
1358
                (my_off_t) next_pos_in_file,SEEK_SET,
1366
1359
                &info->aio_result.result))
1367
1360
    {                                           /* Skip async io */
1368
1361
      my_errno=errno;
1369
1362
      if (info->request_pos != info->buffer)
1370
1363
      {
1371
 
        memcpy(info->buffer, info->request_pos,
1372
 
               (size_t) (info->read_end - info->read_pos));
 
1364
        memmove(info->buffer, info->request_pos,
 
1365
                (size_t) (info->read_end - info->read_pos));
1373
1366
        info->request_pos=info->buffer;
1374
1367
        info->read_pos-=info->read_length;
1375
1368
        info->read_end-=info->read_length;
1400
1393
  return (int) (unsigned char) buff;
1401
1394
}
1402
1395
 
1403
 
/* 
 
1396
/*
1404
1397
   Write a byte buffer to IO_CACHE and flush to disk
1405
1398
   if IO_CACHE is full.
1406
1399
 
1439
1432
        "seek_not_done" to indicate this to other functions operating
1440
1433
        on the IO_CACHE.
1441
1434
      */
1442
 
      if (my_seek(info->file,info->pos_in_file,MY_SEEK_SET,MYF(0)))
 
1435
      if (lseek(info->file,info->pos_in_file,SEEK_SET))
1443
1436
      {
1444
1437
        info->error= -1;
1445
1438
        return (1);
1527
1520
{
1528
1521
  /*
1529
1522
    Sasha: We are not writing this with the ? operator to avoid hitting
1530
 
    a possible compiler bug. At least gcc 2.95 cannot deal with 
 
1523
    a possible compiler bug. At least gcc 2.95 cannot deal with
1531
1524
    several layers of ternary operators that evaluated comma(,) operator
1532
1525
    expressions inside - I do have a test case if somebody wants it
1533
1526
  */
1561
1554
    if (pos + Count <= info->pos_in_file)
1562
1555
      return (pwrite(info->file, Buffer, Count, pos) == 0);
1563
1556
    /* Write the part of the block that is before buffer */
1564
 
    length= (uint) (info->pos_in_file - pos);
 
1557
    length= (uint32_t) (info->pos_in_file - pos);
1565
1558
    if (pwrite(info->file, Buffer, length, pos) == 0)
1566
1559
      info->error= error= -1;
1567
1560
    Buffer+=length;
1639
1632
      */
1640
1633
      if (!append_cache && info->seek_not_done)
1641
1634
      {                                 /* File touched, do seek */
1642
 
        if (my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0)) ==
1643
 
            MY_FILEPOS_ERROR)
 
1635
        if (lseek(info->file,pos_in_file,SEEK_SET) == MY_FILEPOS_ERROR)
1644
1636
        {
1645
1637
          UNLOCK_APPEND_BUFFER;
1646
1638
          return((info->error= -1));
1665
1657
      else
1666
1658
      {
1667
1659
        info->end_of_file+=(info->write_pos-info->append_read_pos);
1668
 
        assert(info->end_of_file == my_tell(info->file,MYF(0)));
 
1660
        my_off_t tell_ret= lseek(info->file, 0, SEEK_CUR);
 
1661
        assert(info->end_of_file == tell_ret);
1669
1662
      }
1670
1663
 
1671
1664
      info->append_read_pos=info->write_pos=info->write_buffer;
1783
1776
  char* block, *block_end;
1784
1777
  MY_INIT(argv[0]);
1785
1778
  max_block = cache_size*3;
1786
 
  if (!(block=(char*)my_malloc(max_block,MYF(MY_WME))))
 
1779
  if (!(block=(char*)malloc(max_block)))
1787
1780
    die("Not enough memory to allocate test block");
1788
1781
  block_end = block + max_block;
1789
1782
  for (p = block,i=0; p < block_end;i++)