~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_extra.c

MergingĀ mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#ifdef HAVE_SYS_MMAN_H
18
18
#include <sys/mman.h>
19
19
#endif
20
 
#include <drizzled/util/test.h>
21
20
 
22
21
static void mi_extra_keyflag(MI_INFO *info, enum ha_extra_function function);
23
22
 
29
28
    mi_extra()
30
29
    info        open table
31
30
    function    operation
32
 
    extra_arg   Pointer to extra argument (normally pointer to uint32_t)
 
31
    extra_arg   Pointer to extra argument (normally pointer to ulong)
33
32
                Used when function is one of:
34
33
                HA_EXTRA_WRITE_CACHE
35
34
                HA_EXTRA_CACHE
41
40
int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
42
41
{
43
42
  int error=0;
44
 
  uint32_t cache_size;
 
43
  ulong cache_size;
45
44
  MYISAM_SHARE *share=info->s;
 
45
  DBUG_ENTER("mi_extra");
 
46
  DBUG_PRINT("enter",("function: %d",(int) function));
46
47
 
47
48
  switch (function) {
48
49
  case HA_EXTRA_RESET_STATE:            /* Reset state (don't free buffers) */
53
54
    if (info->opt_flag & READ_CACHE_USED)
54
55
    {
55
56
      reinit_io_cache(&info->rec_cache,READ_CACHE,0,
56
 
                      (bool) (info->lock_type != F_UNLCK),
57
 
                      (bool) test(info->update & HA_STATE_ROW_CHANGED)
 
57
                      (pbool) (info->lock_type != F_UNLCK),
 
58
                      (pbool) test(info->update & HA_STATE_ROW_CHANGED)
58
59
                      );
59
60
    }
60
61
    info->update= ((info->update & HA_STATE_CHANGED) | HA_STATE_NEXT_FOUND |
70
71
    }
71
72
    if (info->s->file_map) /* Don't use cache if mmap */
72
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
73
90
    if (info->opt_flag & WRITE_CACHE_USED)
74
91
    {
75
92
      info->opt_flag&= ~WRITE_CACHE_USED;
79
96
    if (!(info->opt_flag &
80
97
          (READ_CACHE_USED | WRITE_CACHE_USED | MEMMAP_USED)))
81
98
    {
82
 
      cache_size= (extra_arg ? *(uint32_t*) extra_arg :
 
99
      cache_size= (extra_arg ? *(ulong*) extra_arg :
83
100
                   my_default_record_cache_size);
84
101
      if (!(init_io_cache(&info->rec_cache,info->dfile,
85
 
                         (uint) cmin(info->state->data_file_length+1,
 
102
                         (uint) min(info->state->data_file_length+1,
86
103
                                    cache_size),
87
 
                          READ_CACHE,0L,(bool) (info->lock_type != F_UNLCK),
 
104
                          READ_CACHE,0L,(pbool) (info->lock_type != F_UNLCK),
88
105
                          MYF(share->write_flag & MY_WAIT_IF_FULL))))
89
106
      {
90
107
        info->opt_flag|=READ_CACHE_USED;
98
115
    if (info->opt_flag & READ_CACHE_USED)
99
116
    {
100
117
      reinit_io_cache(&info->rec_cache,READ_CACHE,info->nextpos,
101
 
                      (bool) (info->lock_type != F_UNLCK),
102
 
                      (bool) test(info->update & HA_STATE_ROW_CHANGED));
 
118
                      (pbool) (info->lock_type != F_UNLCK),
 
119
                      (pbool) test(info->update & HA_STATE_ROW_CHANGED));
103
120
      info->update&= ~HA_STATE_ROW_CHANGED;
104
121
      if (share->concurrent_insert)
105
122
        info->rec_cache.end_of_file=info->state->data_file_length;
112
129
      break;
113
130
    }
114
131
 
115
 
    cache_size= (extra_arg ? *(uint32_t*) extra_arg :
 
132
    cache_size= (extra_arg ? *(ulong*) extra_arg :
116
133
                 my_default_record_cache_size);
117
134
    if (!(info->opt_flag &
118
135
          (READ_CACHE_USED | WRITE_CACHE_USED | OPT_NO_ROWS)) &&
119
136
        !share->state.header.uniques)
120
137
      if (!(init_io_cache(&info->rec_cache,info->dfile, cache_size,
121
138
                         WRITE_CACHE,info->state->data_file_length,
122
 
                          (bool) (info->lock_type != F_UNLCK),
 
139
                          (pbool) (info->lock_type != F_UNLCK),
123
140
                          MYF(share->write_flag & MY_WAIT_IF_FULL))))
124
141
      {
125
142
        info->opt_flag|=WRITE_CACHE_USED;
164
181
  case HA_EXTRA_KEYREAD:                        /* Read only keys to record */
165
182
  case HA_EXTRA_REMEMBER_POS:
166
183
    info->opt_flag |= REMEMBER_OLD_POS;
167
 
    memcpy(info->lastkey+share->base.max_key_length*2,
168
 
           info->lastkey,info->lastkey_length);
 
184
    bmove((uchar*) info->lastkey+share->base.max_key_length*2,
 
185
          (uchar*) info->lastkey,info->lastkey_length);
169
186
    info->save_update=  info->update;
170
187
    info->save_lastinx= info->lastinx;
171
188
    info->save_lastpos= info->lastpos;
181
198
  case HA_EXTRA_RESTORE_POS:
182
199
    if (info->opt_flag & REMEMBER_OLD_POS)
183
200
    {
184
 
      memcpy(info->lastkey,
185
 
             info->lastkey+share->base.max_key_length*2,
186
 
             info->save_lastkey_length);
 
201
      bmove((uchar*) info->lastkey,
 
202
            (uchar*) info->lastkey+share->base.max_key_length*2,
 
203
            info->save_lastkey_length);
187
204
      info->update=     info->save_update | HA_STATE_WRITTEN;
188
205
      info->lastinx=    info->save_lastinx;
189
206
      info->lastpos=    info->save_lastpos;
210
227
    if (mi_is_any_key_active(share->state.key_map))
211
228
    {
212
229
      MI_KEYDEF *key=share->keyinfo;
213
 
      uint32_t i;
 
230
      uint i;
214
231
      for (i=0 ; i < share->base.keys ; i++,key++)
215
232
      {
216
233
        if (!(key->flag & HA_NOSAME) && info->s->base.auto_key != i+1)
324
341
      info->opt_flag|= OPT_NO_ROWS;
325
342
    break;
326
343
  case HA_EXTRA_PRELOAD_BUFFER_SIZE:
327
 
    info->preload_buff_size= *((uint32_t *) extra_arg); 
 
344
    info->preload_buff_size= *((ulong *) extra_arg); 
328
345
    break;
329
346
  case HA_EXTRA_CHANGE_KEY_TO_UNIQUE:
330
347
  case HA_EXTRA_CHANGE_KEY_TO_DUP:
344
361
    {
345
362
      if (mi_dynmap_file(info, share->state.state.data_file_length))
346
363
      {
 
364
        DBUG_PRINT("warning",("mmap failed: errno: %d",errno));
347
365
        error= my_errno= errno;
348
366
      }
349
367
      else
355
373
    pthread_mutex_unlock(&share->intern_lock);
356
374
#endif
357
375
    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;
358
381
  case HA_EXTRA_KEY_CACHE:
359
382
  case HA_EXTRA_NO_KEY_CACHE:
360
383
  default:
361
384
    break;
362
385
  }
363
 
 
364
 
  return(error);
 
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);
365
392
} /* mi_extra */
366
393
 
367
394
 
377
404
 */
378
405
static void mi_extra_keyflag(MI_INFO *info, enum ha_extra_function function)
379
406
{
380
 
  uint32_t  idx;
 
407
  uint  idx;
381
408
 
382
409
  for (idx= 0; idx< info->s->base.keys; idx++)
383
410
  {
399
426
{
400
427
  int error= 0;
401
428
  MYISAM_SHARE *share=info->s;
 
429
  DBUG_ENTER("mi_reset");
402
430
  /*
403
431
    Free buffers and reset the following flags:
404
432
    EXTRA_CACHE, EXTRA_WRITE_CACHE, EXTRA_KEYREAD, EXTRA_QUICK
425
453
  info->page_changed= 1;
426
454
  info->update= ((info->update & HA_STATE_CHANGED) | HA_STATE_NEXT_FOUND |
427
455
                 HA_STATE_PREV_FOUND);
428
 
  return(error);
 
456
  DBUG_RETURN(error);
429
457
}