~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/mi_extra.cc

  • Committer: Brian Aker
  • Date: 2010-05-27 01:25:56 UTC
  • mfrom: (1567.1.4 new-staging)
  • Revision ID: brian@gaz-20100527012556-5zgkirkl7swbigd6
Merge of Brian, Paul. PBXT compile issue, and test framework cleanup. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include "myisamdef.h"
17
 
#ifdef HAVE_SYS_MMAN_H
 
16
#include "myisam_priv.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>
 
22
#include <algorithm>
 
23
 
 
24
using namespace drizzled;
 
25
using namespace std;
20
26
 
21
27
static void mi_extra_keyflag(MI_INFO *info, enum ha_extra_function function);
22
28
 
51
57
                                        /* Next/prev gives first/last */
52
58
    if (info->opt_flag & READ_CACHE_USED)
53
59
    {
54
 
      reinit_io_cache(&info->rec_cache,READ_CACHE,0,
 
60
      reinit_io_cache(&info->rec_cache, internal::READ_CACHE,0,
55
61
                      (bool) (info->lock_type != F_UNLCK),
56
62
                      (bool) test(info->update & HA_STATE_ROW_CHANGED)
57
63
                      );
64
70
        (share->options & HA_OPTION_PACK_RECORD))
65
71
    {
66
72
      error=1;                  /* Not possibly if not locked */
67
 
      my_errno=EACCES;
 
73
      errno=EACCES;
68
74
      break;
69
75
    }
70
76
    if (info->s->file_map) /* Don't use cache if mmap */
79
85
          (READ_CACHE_USED | WRITE_CACHE_USED | MEMMAP_USED)))
80
86
    {
81
87
      cache_size= (extra_arg ? *(uint32_t*) extra_arg :
82
 
                   my_default_record_cache_size);
 
88
                   internal::my_default_record_cache_size);
83
89
      if (!(init_io_cache(&info->rec_cache,info->dfile,
84
 
                         (uint) min(info->state->data_file_length+1,
 
90
                         (uint) min((uint32_t)info->state->data_file_length+1,
85
91
                                    cache_size),
86
 
                          READ_CACHE,0L,(bool) (info->lock_type != F_UNLCK),
 
92
                          internal::READ_CACHE,0L,(bool) (info->lock_type != F_UNLCK),
87
93
                          MYF(share->write_flag & MY_WAIT_IF_FULL))))
88
94
      {
89
95
        info->opt_flag|=READ_CACHE_USED;
96
102
  case HA_EXTRA_REINIT_CACHE:
97
103
    if (info->opt_flag & READ_CACHE_USED)
98
104
    {
99
 
      reinit_io_cache(&info->rec_cache,READ_CACHE,info->nextpos,
 
105
      reinit_io_cache(&info->rec_cache,internal::READ_CACHE,info->nextpos,
100
106
                      (bool) (info->lock_type != F_UNLCK),
101
107
                      (bool) test(info->update & HA_STATE_ROW_CHANGED));
102
108
      info->update&= ~HA_STATE_ROW_CHANGED;
112
118
    }
113
119
 
114
120
    cache_size= (extra_arg ? *(uint32_t*) extra_arg :
115
 
                 my_default_record_cache_size);
 
121
                 internal::my_default_record_cache_size);
116
122
    if (!(info->opt_flag &
117
123
          (READ_CACHE_USED | WRITE_CACHE_USED | OPT_NO_ROWS)) &&
118
124
        !share->state.header.uniques)
119
125
      if (!(init_io_cache(&info->rec_cache,info->dfile, cache_size,
120
 
                         WRITE_CACHE,info->state->data_file_length,
 
126
                         internal::WRITE_CACHE,info->state->data_file_length,
121
127
                          (bool) (info->lock_type != F_UNLCK),
122
128
                          MYF(share->write_flag & MY_WAIT_IF_FULL))))
123
129
      {
138
144
      error=end_io_cache(&info->rec_cache);
139
145
      /* Sergei will insert full text index caching here */
140
146
    }
141
 
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE)
 
147
#if !defined(TARGET_OS_SOLARIS)
142
148
    if (info->opt_flag & MEMMAP_USED)
143
149
      madvise((char*) share->file_map, share->state.state.data_file_length,
144
150
              MADV_RANDOM);
163
169
  case HA_EXTRA_KEYREAD:                        /* Read only keys to record */
164
170
  case HA_EXTRA_REMEMBER_POS:
165
171
    info->opt_flag |= REMEMBER_OLD_POS;
166
 
    memcpy(info->lastkey+share->base.max_key_length*2,
167
 
           info->lastkey,info->lastkey_length);
 
172
    memmove(info->lastkey+share->base.max_key_length*2,
 
173
            info->lastkey,info->lastkey_length);
168
174
    info->save_update=  info->update;
169
175
    info->save_lastinx= info->lastinx;
170
176
    info->save_lastpos= info->lastpos;
180
186
  case HA_EXTRA_RESTORE_POS:
181
187
    if (info->opt_flag & REMEMBER_OLD_POS)
182
188
    {
183
 
      memcpy(info->lastkey,
184
 
             info->lastkey+share->base.max_key_length*2,
185
 
             info->save_lastkey_length);
 
189
      memmove(info->lastkey,
 
190
              info->lastkey+share->base.max_key_length*2,
 
191
              info->save_lastkey_length);
186
192
      info->update=     info->save_update | HA_STATE_WRITTEN;
187
193
      info->lastinx=    info->save_lastinx;
188
194
      info->lastpos=    info->save_lastpos;
209
215
    if (mi_is_any_key_active(share->state.key_map))
210
216
    {
211
217
      MI_KEYDEF *key=share->keyinfo;
212
 
      uint i;
 
218
      uint32_t i;
213
219
      for (i=0 ; i < share->base.keys ; i++,key++)
214
220
      {
215
221
        if (!(key->flag & HA_NOSAME) && info->s->base.auto_key != i+1)
248
254
                         (function == HA_EXTRA_FORCE_REOPEN ?
249
255
                          FLUSH_RELEASE : FLUSH_IGNORE_CHANGED)))
250
256
    {
251
 
      error=my_errno;
 
257
      error=errno;
252
258
      share->changed=1;
253
259
      mi_print_error(info->s, HA_ERR_CRASHED);
254
260
      mi_mark_crashed(info);                    /* Fatal error found */
262
268
    {
263
269
      info->was_locked=info->lock_type;
264
270
      if (mi_lock_database(info,F_UNLCK))
265
 
        error=my_errno;
 
271
        error=errno;
266
272
      info->lock_type = F_UNLCK;
267
273
    }
268
274
    if (share->kfile >= 0)
269
275
      _mi_decrement_open_count(info);
270
 
    if (share->kfile >= 0 && my_close(share->kfile,MYF(0)))
271
 
      error=my_errno;
 
276
    if (share->kfile >= 0 && internal::my_close(share->kfile,MYF(0)))
 
277
      error=errno;
272
278
    {
273
 
      LIST *list_element ;
274
 
      for (list_element=myisam_open_list ;
275
 
           list_element ;
276
 
           list_element=list_element->next)
 
279
      list<MI_INFO *>::iterator it= myisam_open_list.begin();
 
280
      while (it != myisam_open_list.end())
277
281
      {
278
 
        MI_INFO *tmpinfo=(MI_INFO*) list_element->data;
 
282
        MI_INFO *tmpinfo= *it;
279
283
        if (tmpinfo->s == info->s)
280
284
        {
281
 
          if (tmpinfo->dfile >= 0 && my_close(tmpinfo->dfile,MYF(0)))
282
 
            error = my_errno;
 
285
          if (tmpinfo->dfile >= 0 && internal::my_close(tmpinfo->dfile,MYF(0)))
 
286
            error = errno;
283
287
          tmpinfo->dfile= -1;
284
288
        }
 
289
        ++it;
285
290
      }
286
291
    }
287
292
    share->kfile= -1;                           /* Files aren't open anymore */
298
303
    if (share->not_flushed)
299
304
    {
300
305
      share->not_flushed=0;
301
 
      if (my_sync(share->kfile, MYF(0)))
302
 
        error= my_errno;
303
 
      if (my_sync(info->dfile, MYF(0)))
304
 
        error= my_errno;
 
306
      if (internal::my_sync(share->kfile, MYF(0)))
 
307
        error= errno;
 
308
      if (internal::my_sync(info->dfile, MYF(0)))
 
309
        error= errno;
305
310
      if (error)
306
311
      {
307
312
        share->changed=1;
323
328
      info->opt_flag|= OPT_NO_ROWS;
324
329
    break;
325
330
  case HA_EXTRA_PRELOAD_BUFFER_SIZE:
326
 
    info->preload_buff_size= *((uint32_t *) extra_arg); 
 
331
    info->preload_buff_size= *((uint32_t *) extra_arg);
327
332
    break;
328
333
  case HA_EXTRA_CHANGE_KEY_TO_UNIQUE:
329
334
  case HA_EXTRA_CHANGE_KEY_TO_DUP:
330
335
    mi_extra_keyflag(info, function);
331
336
    break;
332
 
  case HA_EXTRA_MMAP:
333
 
#ifdef HAVE_MMAP
334
 
    pthread_mutex_lock(&share->intern_lock);
335
 
    /*
336
 
      Memory map the data file if it is not already mapped. It is safe
337
 
      to memory map a file while other threads are using file I/O on it.
338
 
      Assigning a new address to a function pointer is an atomic
339
 
      operation. intern_lock prevents that two or more mappings are done
340
 
      at the same time.
341
 
    */
342
 
    if (!share->file_map)
343
 
    {
344
 
      if (mi_dynmap_file(info, share->state.state.data_file_length))
345
 
      {
346
 
        error= my_errno= errno;
347
 
      }
348
 
      else
349
 
      {
350
 
        share->file_read= mi_mmap_pread;
351
 
        share->file_write= mi_mmap_pwrite;
352
 
      }
353
 
    }
354
 
    pthread_mutex_unlock(&share->intern_lock);
355
 
#endif
356
 
    break;
357
337
  case HA_EXTRA_KEY_CACHE:
358
338
  case HA_EXTRA_NO_KEY_CACHE:
359
339
  default:
364
344
} /* mi_extra */
365
345
 
366
346
 
367
 
void mi_set_index_cond_func(MI_INFO *info, index_cond_func_t func,
368
 
                            void *func_arg)
369
 
{
370
 
  info->index_cond_func= func;
371
 
  info->index_cond_func_arg= func_arg;
372
 
}
373
 
 
374
347
/*
375
348
    Start/Stop Inserting Duplicates Into a Table, WL#1648.
376
349
 */
377
350
static void mi_extra_keyflag(MI_INFO *info, enum ha_extra_function function)
378
351
{
379
 
  uint  idx;
 
352
  uint32_t  idx;
380
353
 
381
354
  for (idx= 0; idx< info->s->base.keys; idx++)
382
355
  {
412
385
  }
413
386
  if (share->base.blobs)
414
387
    mi_alloc_rec_buff(info, -1, &info->rec_buff);
415
 
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE)
 
388
#if !defined(TARGET_OS_SOLARIS)
416
389
  if (info->opt_flag & MEMMAP_USED)
417
390
    madvise((char*) share->file_map, share->state.state.data_file_length,
418
391
            MADV_RANDOM);