~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_extra.c

  • Committer: Mark Atwood
  • Date: 2008-07-12 07:25:25 UTC
  • mto: This revision was merged to the branch mainline in revision 139.
  • Revision ID: me@mark.atwood.name-20080712072525-s1dq9mtwo5td7af7
more hackery to get plugin UDFs working

Show diffs side-by-side

added added

removed removed

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