~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_extra.c

  • Committer: Monty Taylor
  • Date: 2009-01-29 19:04:39 UTC
  • mto: (779.3.29 devel)
  • mto: This revision was merged to the branch mainline in revision 823.
  • Revision ID: mordred@inaugust.com-20090129190439-vfr95s6gaudjacm7
Add timegm which is missing on Solaris.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
#include "myisamdef.h"
17
 
#ifdef HAVE_SYS_MMAN_H
 
17
#include <drizzled/util/test.h>
 
18
#include <sys/types.h>
18
19
#include <sys/mman.h>
19
 
#endif
 
20
 
 
21
#include <string.h>
20
22
 
21
23
static void mi_extra_keyflag(MI_INFO *info, enum ha_extra_function function);
22
24
 
28
30
    mi_extra()
29
31
    info        open table
30
32
    function    operation
31
 
    extra_arg   Pointer to extra argument (normally pointer to ulong)
 
33
    extra_arg   Pointer to extra argument (normally pointer to uint32_t)
32
34
                Used when function is one of:
33
35
                HA_EXTRA_WRITE_CACHE
34
36
                HA_EXTRA_CACHE
40
42
int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
41
43
{
42
44
  int error=0;
43
 
  ulong cache_size;
 
45
  uint32_t cache_size;
44
46
  MYISAM_SHARE *share=info->s;
45
 
  DBUG_ENTER("mi_extra");
46
 
  DBUG_PRINT("enter",("function: %d",(int) function));
47
47
 
48
48
  switch (function) {
49
49
  case HA_EXTRA_RESET_STATE:            /* Reset state (don't free buffers) */
54
54
    if (info->opt_flag & READ_CACHE_USED)
55
55
    {
56
56
      reinit_io_cache(&info->rec_cache,READ_CACHE,0,
57
 
                      (pbool) (info->lock_type != F_UNLCK),
58
 
                      (pbool) test(info->update & HA_STATE_ROW_CHANGED)
 
57
                      (bool) (info->lock_type != F_UNLCK),
 
58
                      (bool) test(info->update & HA_STATE_ROW_CHANGED)
59
59
                      );
60
60
    }
61
61
    info->update= ((info->update & HA_STATE_CHANGED) | HA_STATE_NEXT_FOUND |
71
71
    }
72
72
    if (info->s->file_map) /* Don't use cache if mmap */
73
73
      break;
74
 
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE)
75
 
    if ((share->options & HA_OPTION_COMPRESS_RECORD))
76
 
    {
77
 
      pthread_mutex_lock(&share->intern_lock);
78
 
      if (_mi_memmap_file(info))
79
 
      {
80
 
        /* We don't nead MADV_SEQUENTIAL if small file */
81
 
        madvise((char*) share->file_map, share->state.state.data_file_length,
82
 
                share->state.state.data_file_length <= RECORD_CACHE_SIZE*16 ?
83
 
                MADV_RANDOM : MADV_SEQUENTIAL);
84
 
        pthread_mutex_unlock(&share->intern_lock);
85
 
        break;
86
 
      }
87
 
      pthread_mutex_unlock(&share->intern_lock);
88
 
    }
89
 
#endif
90
74
    if (info->opt_flag & WRITE_CACHE_USED)
91
75
    {
92
76
      info->opt_flag&= ~WRITE_CACHE_USED;
96
80
    if (!(info->opt_flag &
97
81
          (READ_CACHE_USED | WRITE_CACHE_USED | MEMMAP_USED)))
98
82
    {
99
 
      cache_size= (extra_arg ? *(ulong*) extra_arg :
 
83
      cache_size= (extra_arg ? *(uint32_t*) extra_arg :
100
84
                   my_default_record_cache_size);
101
85
      if (!(init_io_cache(&info->rec_cache,info->dfile,
102
 
                         (uint) min(info->state->data_file_length+1,
 
86
                         (uint) cmin(info->state->data_file_length+1,
103
87
                                    cache_size),
104
 
                          READ_CACHE,0L,(pbool) (info->lock_type != F_UNLCK),
 
88
                          READ_CACHE,0L,(bool) (info->lock_type != F_UNLCK),
105
89
                          MYF(share->write_flag & MY_WAIT_IF_FULL))))
106
90
      {
107
91
        info->opt_flag|=READ_CACHE_USED;
115
99
    if (info->opt_flag & READ_CACHE_USED)
116
100
    {
117
101
      reinit_io_cache(&info->rec_cache,READ_CACHE,info->nextpos,
118
 
                      (pbool) (info->lock_type != F_UNLCK),
119
 
                      (pbool) test(info->update & HA_STATE_ROW_CHANGED));
 
102
                      (bool) (info->lock_type != F_UNLCK),
 
103
                      (bool) test(info->update & HA_STATE_ROW_CHANGED));
120
104
      info->update&= ~HA_STATE_ROW_CHANGED;
121
105
      if (share->concurrent_insert)
122
106
        info->rec_cache.end_of_file=info->state->data_file_length;
129
113
      break;
130
114
    }
131
115
 
132
 
    cache_size= (extra_arg ? *(ulong*) extra_arg :
 
116
    cache_size= (extra_arg ? *(uint32_t*) extra_arg :
133
117
                 my_default_record_cache_size);
134
118
    if (!(info->opt_flag &
135
119
          (READ_CACHE_USED | WRITE_CACHE_USED | OPT_NO_ROWS)) &&
136
120
        !share->state.header.uniques)
137
121
      if (!(init_io_cache(&info->rec_cache,info->dfile, cache_size,
138
122
                         WRITE_CACHE,info->state->data_file_length,
139
 
                          (pbool) (info->lock_type != F_UNLCK),
 
123
                          (bool) (info->lock_type != F_UNLCK),
140
124
                          MYF(share->write_flag & MY_WAIT_IF_FULL))))
141
125
      {
142
126
        info->opt_flag|=WRITE_CACHE_USED;
156
140
      error=end_io_cache(&info->rec_cache);
157
141
      /* Sergei will insert full text index caching here */
158
142
    }
159
 
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE)
 
143
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE) && !defined(TARGET_OS_SOLARIS)
160
144
    if (info->opt_flag & MEMMAP_USED)
161
145
      madvise((char*) share->file_map, share->state.state.data_file_length,
162
146
              MADV_RANDOM);
181
165
  case HA_EXTRA_KEYREAD:                        /* Read only keys to record */
182
166
  case HA_EXTRA_REMEMBER_POS:
183
167
    info->opt_flag |= REMEMBER_OLD_POS;
184
 
    bmove((uchar*) info->lastkey+share->base.max_key_length*2,
185
 
          (uchar*) info->lastkey,info->lastkey_length);
 
168
    memmove(info->lastkey+share->base.max_key_length*2,
 
169
            info->lastkey,info->lastkey_length);
186
170
    info->save_update=  info->update;
187
171
    info->save_lastinx= info->lastinx;
188
172
    info->save_lastpos= info->lastpos;
198
182
  case HA_EXTRA_RESTORE_POS:
199
183
    if (info->opt_flag & REMEMBER_OLD_POS)
200
184
    {
201
 
      bmove((uchar*) info->lastkey,
202
 
            (uchar*) info->lastkey+share->base.max_key_length*2,
203
 
            info->save_lastkey_length);
 
185
      memmove(info->lastkey,
 
186
              info->lastkey+share->base.max_key_length*2,
 
187
              info->save_lastkey_length);
204
188
      info->update=     info->save_update | HA_STATE_WRITTEN;
205
189
      info->lastinx=    info->save_lastinx;
206
190
      info->lastpos=    info->save_lastpos;
227
211
    if (mi_is_any_key_active(share->state.key_map))
228
212
    {
229
213
      MI_KEYDEF *key=share->keyinfo;
230
 
      uint i;
 
214
      uint32_t i;
231
215
      for (i=0 ; i < share->base.keys ; i++,key++)
232
216
      {
233
217
        if (!(key->flag & HA_NOSAME) && info->s->base.auto_key != i+1)
341
325
      info->opt_flag|= OPT_NO_ROWS;
342
326
    break;
343
327
  case HA_EXTRA_PRELOAD_BUFFER_SIZE:
344
 
    info->preload_buff_size= *((ulong *) extra_arg); 
 
328
    info->preload_buff_size= *((uint32_t *) extra_arg);
345
329
    break;
346
330
  case HA_EXTRA_CHANGE_KEY_TO_UNIQUE:
347
331
  case HA_EXTRA_CHANGE_KEY_TO_DUP:
361
345
    {
362
346
      if (mi_dynmap_file(info, share->state.state.data_file_length))
363
347
      {
364
 
        DBUG_PRINT("warning",("mmap failed: errno: %d",errno));
365
348
        error= my_errno= errno;
366
349
      }
367
350
      else
373
356
    pthread_mutex_unlock(&share->intern_lock);
374
357
#endif
375
358
    break;
376
 
  case HA_EXTRA_MARK_AS_LOG_TABLE:
377
 
    pthread_mutex_lock(&share->intern_lock);
378
 
    share->is_log_table= TRUE;
379
 
    pthread_mutex_unlock(&share->intern_lock);
380
 
    break;
381
359
  case HA_EXTRA_KEY_CACHE:
382
360
  case HA_EXTRA_NO_KEY_CACHE:
383
361
  default:
384
362
    break;
385
363
  }
386
 
  {
387
 
    char tmp[1];
388
 
    tmp[0]=function;
389
 
    myisam_log_command(MI_LOG_EXTRA,info,(uchar*) tmp,1,error);
390
 
  }
391
 
  DBUG_RETURN(error);
 
364
 
 
365
  return(error);
392
366
} /* mi_extra */
393
367
 
394
368
 
404
378
 */
405
379
static void mi_extra_keyflag(MI_INFO *info, enum ha_extra_function function)
406
380
{
407
 
  uint  idx;
 
381
  uint32_t  idx;
408
382
 
409
383
  for (idx= 0; idx< info->s->base.keys; idx++)
410
384
  {
426
400
{
427
401
  int error= 0;
428
402
  MYISAM_SHARE *share=info->s;
429
 
  DBUG_ENTER("mi_reset");
430
403
  /*
431
404
    Free buffers and reset the following flags:
432
405
    EXTRA_CACHE, EXTRA_WRITE_CACHE, EXTRA_KEYREAD, EXTRA_QUICK
441
414
  }
442
415
  if (share->base.blobs)
443
416
    mi_alloc_rec_buff(info, -1, &info->rec_buff);
444
 
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE)
 
417
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE) && !defined(TARGET_OS_SOLARIS)
445
418
  if (info->opt_flag & MEMMAP_USED)
446
419
    madvise((char*) share->file_map, share->state.state.data_file_length,
447
420
            MADV_RANDOM);
453
426
  info->page_changed= 1;
454
427
  info->update= ((info->update & HA_STATE_CHANGED) | HA_STATE_NEXT_FOUND |
455
428
                 HA_STATE_PREV_FOUND);
456
 
  DBUG_RETURN(error);
 
429
  return(error);
457
430
}