~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_extra.c

  • Committer: Brian Aker
  • Date: 2009-01-24 09:43:35 UTC
  • Revision ID: brian@gir-3.local-20090124094335-6qdtvc35gl5fvivz
Adding in an example singe thread scheduler

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 "myisam_priv.h"
 
16
#include "myisamdef.h"
17
17
#include <drizzled/util/test.h>
18
18
#include <sys/types.h>
19
19
#include <sys/mman.h>
20
20
 
21
21
#include <string.h>
22
 
#include <algorithm>
23
 
 
24
 
using namespace drizzled;
25
 
using namespace std;
26
22
 
27
23
static void mi_extra_keyflag(MI_INFO *info, enum ha_extra_function function);
28
24
 
57
53
                                        /* Next/prev gives first/last */
58
54
    if (info->opt_flag & READ_CACHE_USED)
59
55
    {
60
 
      reinit_io_cache(&info->rec_cache, internal::READ_CACHE,0,
 
56
      reinit_io_cache(&info->rec_cache,READ_CACHE,0,
61
57
                      (bool) (info->lock_type != F_UNLCK),
62
58
                      (bool) test(info->update & HA_STATE_ROW_CHANGED)
63
59
                      );
70
66
        (share->options & HA_OPTION_PACK_RECORD))
71
67
    {
72
68
      error=1;                  /* Not possibly if not locked */
73
 
      errno=EACCES;
 
69
      my_errno=EACCES;
74
70
      break;
75
71
    }
76
72
    if (info->s->file_map) /* Don't use cache if mmap */
85
81
          (READ_CACHE_USED | WRITE_CACHE_USED | MEMMAP_USED)))
86
82
    {
87
83
      cache_size= (extra_arg ? *(uint32_t*) extra_arg :
88
 
                   internal::my_default_record_cache_size);
 
84
                   my_default_record_cache_size);
89
85
      if (!(init_io_cache(&info->rec_cache,info->dfile,
90
 
                         (uint) min((uint32_t)info->state->data_file_length+1,
 
86
                         (uint) cmin(info->state->data_file_length+1,
91
87
                                    cache_size),
92
 
                          internal::READ_CACHE,0L,(bool) (info->lock_type != F_UNLCK),
 
88
                          READ_CACHE,0L,(bool) (info->lock_type != F_UNLCK),
93
89
                          MYF(share->write_flag & MY_WAIT_IF_FULL))))
94
90
      {
95
91
        info->opt_flag|=READ_CACHE_USED;
102
98
  case HA_EXTRA_REINIT_CACHE:
103
99
    if (info->opt_flag & READ_CACHE_USED)
104
100
    {
105
 
      reinit_io_cache(&info->rec_cache,internal::READ_CACHE,info->nextpos,
 
101
      reinit_io_cache(&info->rec_cache,READ_CACHE,info->nextpos,
106
102
                      (bool) (info->lock_type != F_UNLCK),
107
103
                      (bool) test(info->update & HA_STATE_ROW_CHANGED));
108
104
      info->update&= ~HA_STATE_ROW_CHANGED;
118
114
    }
119
115
 
120
116
    cache_size= (extra_arg ? *(uint32_t*) extra_arg :
121
 
                 internal::my_default_record_cache_size);
 
117
                 my_default_record_cache_size);
122
118
    if (!(info->opt_flag &
123
119
          (READ_CACHE_USED | WRITE_CACHE_USED | OPT_NO_ROWS)) &&
124
120
        !share->state.header.uniques)
125
121
      if (!(init_io_cache(&info->rec_cache,info->dfile, cache_size,
126
 
                         internal::WRITE_CACHE,info->state->data_file_length,
 
122
                         WRITE_CACHE,info->state->data_file_length,
127
123
                          (bool) (info->lock_type != F_UNLCK),
128
124
                          MYF(share->write_flag & MY_WAIT_IF_FULL))))
129
125
      {
144
140
      error=end_io_cache(&info->rec_cache);
145
141
      /* Sergei will insert full text index caching here */
146
142
    }
147
 
#if !defined(TARGET_OS_SOLARIS)
 
143
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE) && !defined(TARGET_OS_SOLARIS)
148
144
    if (info->opt_flag & MEMMAP_USED)
149
145
      madvise((char*) share->file_map, share->state.state.data_file_length,
150
146
              MADV_RANDOM);
254
250
                         (function == HA_EXTRA_FORCE_REOPEN ?
255
251
                          FLUSH_RELEASE : FLUSH_IGNORE_CHANGED)))
256
252
    {
257
 
      error=errno;
 
253
      error=my_errno;
258
254
      share->changed=1;
259
255
      mi_print_error(info->s, HA_ERR_CRASHED);
260
256
      mi_mark_crashed(info);                    /* Fatal error found */
268
264
    {
269
265
      info->was_locked=info->lock_type;
270
266
      if (mi_lock_database(info,F_UNLCK))
271
 
        error=errno;
 
267
        error=my_errno;
272
268
      info->lock_type = F_UNLCK;
273
269
    }
274
270
    if (share->kfile >= 0)
275
271
      _mi_decrement_open_count(info);
276
 
    if (share->kfile >= 0 && internal::my_close(share->kfile,MYF(0)))
277
 
      error=errno;
 
272
    if (share->kfile >= 0 && my_close(share->kfile,MYF(0)))
 
273
      error=my_errno;
278
274
    {
279
 
      list<MI_INFO *>::iterator it= myisam_open_list.begin();
280
 
      while (it != myisam_open_list.end())
 
275
      LIST *list_element ;
 
276
      for (list_element=myisam_open_list ;
 
277
           list_element ;
 
278
           list_element=list_element->next)
281
279
      {
282
 
        MI_INFO *tmpinfo= *it;
 
280
        MI_INFO *tmpinfo=(MI_INFO*) list_element->data;
283
281
        if (tmpinfo->s == info->s)
284
282
        {
285
 
          if (tmpinfo->dfile >= 0 && internal::my_close(tmpinfo->dfile,MYF(0)))
286
 
            error = errno;
 
283
          if (tmpinfo->dfile >= 0 && my_close(tmpinfo->dfile,MYF(0)))
 
284
            error = my_errno;
287
285
          tmpinfo->dfile= -1;
288
286
        }
289
 
        ++it;
290
287
      }
291
288
    }
292
289
    share->kfile= -1;                           /* Files aren't open anymore */
303
300
    if (share->not_flushed)
304
301
    {
305
302
      share->not_flushed=0;
306
 
      if (internal::my_sync(share->kfile, MYF(0)))
307
 
        error= errno;
308
 
      if (internal::my_sync(info->dfile, MYF(0)))
309
 
        error= errno;
 
303
      if (my_sync(share->kfile, MYF(0)))
 
304
        error= my_errno;
 
305
      if (my_sync(info->dfile, MYF(0)))
 
306
        error= my_errno;
310
307
      if (error)
311
308
      {
312
309
        share->changed=1;
334
331
  case HA_EXTRA_CHANGE_KEY_TO_DUP:
335
332
    mi_extra_keyflag(info, function);
336
333
    break;
 
334
  case HA_EXTRA_MMAP:
 
335
#ifdef HAVE_MMAP
 
336
    pthread_mutex_lock(&share->intern_lock);
 
337
    /*
 
338
      Memory map the data file if it is not already mapped. It is safe
 
339
      to memory map a file while other threads are using file I/O on it.
 
340
      Assigning a new address to a function pointer is an atomic
 
341
      operation. intern_lock prevents that two or more mappings are done
 
342
      at the same time.
 
343
    */
 
344
    if (!share->file_map)
 
345
    {
 
346
      if (mi_dynmap_file(info, share->state.state.data_file_length))
 
347
      {
 
348
        error= my_errno= errno;
 
349
      }
 
350
      else
 
351
      {
 
352
        share->file_read= mi_mmap_pread;
 
353
        share->file_write= mi_mmap_pwrite;
 
354
      }
 
355
    }
 
356
    pthread_mutex_unlock(&share->intern_lock);
 
357
#endif
 
358
    break;
337
359
  case HA_EXTRA_KEY_CACHE:
338
360
  case HA_EXTRA_NO_KEY_CACHE:
339
361
  default:
344
366
} /* mi_extra */
345
367
 
346
368
 
 
369
void mi_set_index_cond_func(MI_INFO *info, index_cond_func_t func,
 
370
                            void *func_arg)
 
371
{
 
372
  info->index_cond_func= func;
 
373
  info->index_cond_func_arg= func_arg;
 
374
}
 
375
 
347
376
/*
348
377
    Start/Stop Inserting Duplicates Into a Table, WL#1648.
349
378
 */
385
414
  }
386
415
  if (share->base.blobs)
387
416
    mi_alloc_rec_buff(info, -1, &info->rec_buff);
388
 
#if !defined(TARGET_OS_SOLARIS)
 
417
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE) && !defined(TARGET_OS_SOLARIS)
389
418
  if (info->opt_flag & MEMMAP_USED)
390
419
    madvise((char*) share->file_map, share->state.state.data_file_length,
391
420
            MADV_RANDOM);