~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_iocache2.c

  • Committer: Brian Aker
  • Date: 2008-07-14 22:40:46 UTC
  • Revision ID: brian@tangent.org-20080714224046-x183907w9wp1txwv
Removed sql_manager. Ever heard of just setting up the OS to sync when you
want it to?

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
  More functions to be used with IO_CACHE files
18
18
*/
19
19
 
 
20
#define MAP_TO_USE_RAID
20
21
#include "mysys_priv.h"
21
 
#include <mystrings/m_string.h>
 
22
#include <m_string.h>
22
23
#include <stdarg.h>
23
 
#include <mystrings/m_ctype.h>
24
 
#include <mysys/iocache.h>
 
24
#include <m_ctype.h>
25
25
 
26
26
/*
27
27
  Copy contents of an IO_CACHE to a file.
51
51
my_b_copy_to_file(IO_CACHE *cache, FILE *file)
52
52
{
53
53
  size_t bytes_in_cache;
 
54
  DBUG_ENTER("my_b_copy_to_file");
54
55
 
55
56
  /* Reinit the cache to read from the beginning of the cache */
56
 
  if (reinit_io_cache(cache, READ_CACHE, 0L, false, false))
57
 
    return(1);
 
57
  if (reinit_io_cache(cache, READ_CACHE, 0L, FALSE, FALSE))
 
58
    DBUG_RETURN(1);
58
59
  bytes_in_cache= my_b_bytes_in_cache(cache);
59
60
  do
60
61
  {
61
62
    if (my_fwrite(file, cache->read_pos, bytes_in_cache,
62
63
                  MYF(MY_WME | MY_NABP)) == (size_t) -1)
63
 
      return(1);
 
64
      DBUG_RETURN(1);
64
65
    cache->read_pos= cache->read_end;
65
66
  } while ((bytes_in_cache= my_b_fill(cache)));
66
 
  return(0);
 
67
  DBUG_RETURN(0);
67
68
}
68
69
 
69
70
 
73
74
    Prevent optimizer from putting res in a register when debugging
74
75
    we need this to be able to see the value of res when the assert fails
75
76
  */
76
 
  volatile my_off_t res; 
 
77
  dbug_volatile my_off_t res; 
77
78
 
78
79
  /*
79
80
    We need to lock the append buffer mutex to keep flush_io_cache()
81
82
    answer to the question.
82
83
  */
83
84
  pthread_mutex_lock(&info->append_buffer_lock);
 
85
#ifndef DBUG_OFF
 
86
  /*
 
87
    Make sure EOF is where we think it is. Note that we cannot just use
 
88
    my_tell() because we have a reader thread that could have left the
 
89
    file offset in a non-EOF location
 
90
  */
 
91
  {
 
92
    volatile my_off_t save_pos;
 
93
    save_pos = my_tell(info->file,MYF(0));
 
94
    my_seek(info->file,(my_off_t)0,MY_SEEK_END,MYF(0));
 
95
    /*
 
96
      Save the value of my_tell in res so we can see it when studying coredump
 
97
    */
 
98
    DBUG_ASSERT(info->end_of_file - (info->append_read_pos-info->write_buffer)
 
99
                == (res=my_tell(info->file,MYF(0))));
 
100
    my_seek(info->file,save_pos,MY_SEEK_SET,MYF(0));
 
101
  }
 
102
#endif  
84
103
  res = info->end_of_file + (info->write_pos-info->append_read_pos);
85
104
  pthread_mutex_unlock(&info->append_buffer_lock);
86
105
  return res;
101
120
void my_b_seek(IO_CACHE *info,my_off_t pos)
102
121
{
103
122
  my_off_t offset;
 
123
  DBUG_ENTER("my_b_seek");
 
124
  DBUG_PRINT("enter",("pos: %lu", (ulong) pos));
104
125
 
105
126
  /*
106
127
    TODO:
110
131
     b) see if there is a better way to make it work
111
132
  */
112
133
  if (info->type == SEQ_READ_APPEND)
113
 
    flush_io_cache(info);
 
134
    VOID(flush_io_cache(info));
114
135
 
115
136
  offset=(pos - info->pos_in_file);
116
137
 
121
142
    {
122
143
      /* The read is in the current buffer; Reuse it */
123
144
      info->read_pos = info->buffer + offset;
124
 
      return;
 
145
      DBUG_VOID_RETURN;
125
146
    }
126
147
    else
127
148
    {
136
157
        (uint64_t) (info->write_end - info->write_buffer))
137
158
    {
138
159
      info->write_pos = info->write_buffer + offset;
139
 
      return;
 
160
      DBUG_VOID_RETURN;
140
161
    }
141
 
    flush_io_cache(info);
 
162
    VOID(flush_io_cache(info));
142
163
    /* Correct buffer end so that we write in increments of IO_SIZE */
143
164
    info->write_end=(info->write_buffer+info->buffer_length-
144
165
                     (pos & (IO_SIZE-1)));
145
166
  }
146
167
  info->pos_in_file=pos;
147
168
  info->seek_not_done=1;
148
 
  return;
 
169
  DBUG_VOID_RETURN;
149
170
}
150
171
 
151
172
 
221
242
 
222
243
  for (;;)
223
244
  {
224
 
    unsigned char *pos, *end;
 
245
    uchar *pos, *end;
225
246
    if (length > max_length)
226
247
      length=max_length;
227
248
    for (pos=info->read_pos,end=pos+length ; pos < end ;)
276
297
size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list args)
277
298
{
278
299
  size_t out_length= 0;
279
 
  uint32_t minimum_width; /* as yet unimplemented */
280
 
  uint32_t minimum_width_sign;
281
 
  uint32_t precision; /* as yet unimplemented for anything but %b */
 
300
  uint minimum_width; /* as yet unimplemented */
 
301
  uint minimum_width_sign;
 
302
  uint precision; /* as yet unimplemented for anything but %b */
282
303
  bool is_zero_padded;
283
304
 
284
305
  /*
299
320
 
300
321
    length= (size_t) (fmt - start);
301
322
    out_length+=length;
302
 
    if (my_b_write(info, (const unsigned char*) start, length))
 
323
    if (my_b_write(info, (const uchar*) start, length))
303
324
      goto err;
304
325
 
305
326
    if (*fmt == '\0')                           /* End of format */
309
330
      By this point, *fmt must be a percent;  Keep track of this location and
310
331
      skip over the percent character. 
311
332
    */
312
 
    assert(*fmt == '%');
 
333
    DBUG_ASSERT(*fmt == '%');
313
334
    backtrack= fmt;
314
335
    fmt++;
315
336
 
316
 
    is_zero_padded= false;
 
337
    is_zero_padded= FALSE;
317
338
    minimum_width_sign= 1;
318
339
    minimum_width= 0;
319
340
    precision= 0;
325
346
      case '-': 
326
347
        minimum_width_sign= -1; fmt++; goto process_flags;
327
348
      case '0':
328
 
        is_zero_padded= true; fmt++; goto process_flags;
 
349
        is_zero_padded= TRUE; fmt++; goto process_flags;
329
350
      case '#':
330
351
        /** @todo Implement "#" conversion flag. */  fmt++; goto process_flags;
331
352
      case ' ':
341
362
    }
342
363
    else
343
364
    {
344
 
      while (my_isdigit(&my_charset_utf8_general_ci, *fmt)) {
 
365
      while (my_isdigit(&my_charset_latin1, *fmt)) {
345
366
        minimum_width=(minimum_width * 10) + (*fmt - '0');
346
367
        fmt++;
347
368
      }
357
378
      }
358
379
      else
359
380
      {
360
 
        while (my_isdigit(&my_charset_utf8_general_ci, *fmt)) {
 
381
        while (my_isdigit(&my_charset_latin1, *fmt)) {
361
382
          precision=(precision * 10) + (*fmt - '0');
362
383
          fmt++;
363
384
        }
370
391
      size_t length2 = strlen(par);
371
392
      /* TODO: implement precision */
372
393
      out_length+= length2;
373
 
      if (my_b_write(info, (const unsigned char*) par, length2))
 
394
      if (my_b_write(info, (uchar*) par, length2))
374
395
        goto err;
375
396
    }
376
397
    else if (*fmt == 'b')                       /* Sized buffer parameter, only precision makes sense */
377
398
    {
378
399
      char *par = va_arg(args, char *);
379
400
      out_length+= precision;
380
 
      if (my_b_write(info, (const unsigned char*) par, precision))
 
401
      if (my_b_write(info, (uchar*) par, precision))
381
402
        goto err;
382
403
    }
383
404
    else if (*fmt == 'd' || *fmt == 'u')        /* Integer parameter */
395
416
      /* minimum width padding */
396
417
      if (minimum_width > length2) 
397
418
      {
398
 
        const size_t buflen = minimum_width - length2;
399
 
        unsigned char *buffz= my_alloca(buflen);
400
 
        memset(buffz, is_zero_padded ? '0' : ' ', buflen);
401
 
        my_b_write(info, buffz, buflen);
 
419
        uchar *buffz;
 
420
                    
 
421
        buffz= my_alloca(minimum_width - length2);
 
422
        if (is_zero_padded)
 
423
          memset(buffz, '0', minimum_width - length2);
 
424
        else
 
425
          memset(buffz, ' ', minimum_width - length2);
 
426
        my_b_write(info, buffz, minimum_width - length2);
402
427
        my_afree(buffz);
403
428
      }
404
429
 
405
430
      out_length+= length2;
406
 
      if (my_b_write(info, (const unsigned char *)buff, length2))
 
431
      if (my_b_write(info, (uchar*) buff, length2))
407
432
        goto err;
408
433
    }
409
434
    else if ((*fmt == 'l' && fmt[1] == 'd') || fmt[1] == 'u')
419
444
      else
420
445
        length2= (size_t) (int10_to_str(iarg,buff,10)- buff);
421
446
      out_length+= length2;
422
 
      if (my_b_write(info, (unsigned char*) buff, length2))
 
447
      if (my_b_write(info, (uchar*) buff, length2))
423
448
        goto err;
424
449
    }
425
450
    else
426
451
    {
427
452
      /* %% or unknown code */
428
 
      if (my_b_write(info, (const unsigned char*) backtrack, (size_t) (fmt-backtrack)))
 
453
      if (my_b_write(info, (uchar*) backtrack, (size_t) (fmt-backtrack)))
429
454
        goto err;
430
455
      out_length+= fmt-backtrack;
431
456
    }