~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-18 01:49:40 UTC
  • Revision ID: brian@gir-3.local-20090118014940-co9651fk7hla6gqg
Removed unused session param from list_open_tables()

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
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
 
      info->rec_cache.reinit_io_cache(internal::READ_CACHE,0,
61
 
                                      (bool) (info->lock_type != F_UNLCK),
62
 
                                      (bool) test(info->update & HA_STATE_ROW_CHANGED));
 
56
      reinit_io_cache(&info->rec_cache,READ_CACHE,0,
 
57
                      (bool) (info->lock_type != F_UNLCK),
 
58
                      (bool) test(info->update & HA_STATE_ROW_CHANGED)
 
59
                      );
63
60
    }
64
61
    info->update= ((info->update & HA_STATE_CHANGED) | HA_STATE_NEXT_FOUND |
65
62
                   HA_STATE_PREV_FOUND);
69
66
        (share->options & HA_OPTION_PACK_RECORD))
70
67
    {
71
68
      error=1;                  /* Not possibly if not locked */
72
 
      errno=EACCES;
 
69
      my_errno=EACCES;
73
70
      break;
74
71
    }
75
72
    if (info->s->file_map) /* Don't use cache if mmap */
77
74
    if (info->opt_flag & WRITE_CACHE_USED)
78
75
    {
79
76
      info->opt_flag&= ~WRITE_CACHE_USED;
80
 
      if ((error= info->rec_cache.end_io_cache()))
 
77
      if ((error=end_io_cache(&info->rec_cache)))
81
78
        break;
82
79
    }
83
80
    if (!(info->opt_flag &
84
81
          (READ_CACHE_USED | WRITE_CACHE_USED | MEMMAP_USED)))
85
82
    {
86
83
      cache_size= (extra_arg ? *(uint32_t*) extra_arg :
87
 
                   internal::my_default_record_cache_size);
88
 
      if (!(info->rec_cache.init_io_cache(info->dfile, (uint) min((uint32_t)info->state->data_file_length+1, cache_size),
89
 
                                          internal::READ_CACHE,0L,(bool) (info->lock_type != F_UNLCK),
90
 
                                          MYF(share->write_flag & MY_WAIT_IF_FULL))))
 
84
                   my_default_record_cache_size);
 
85
      if (!(init_io_cache(&info->rec_cache,info->dfile,
 
86
                         (uint) cmin(info->state->data_file_length+1,
 
87
                                    cache_size),
 
88
                          READ_CACHE,0L,(bool) (info->lock_type != F_UNLCK),
 
89
                          MYF(share->write_flag & MY_WAIT_IF_FULL))))
91
90
      {
92
91
        info->opt_flag|=READ_CACHE_USED;
93
92
        info->update&= ~HA_STATE_ROW_CHANGED;
99
98
  case HA_EXTRA_REINIT_CACHE:
100
99
    if (info->opt_flag & READ_CACHE_USED)
101
100
    {
102
 
      info->rec_cache.reinit_io_cache(internal::READ_CACHE,info->nextpos,
 
101
      reinit_io_cache(&info->rec_cache,READ_CACHE,info->nextpos,
103
102
                      (bool) (info->lock_type != F_UNLCK),
104
103
                      (bool) test(info->update & HA_STATE_ROW_CHANGED));
105
104
      info->update&= ~HA_STATE_ROW_CHANGED;
115
114
    }
116
115
 
117
116
    cache_size= (extra_arg ? *(uint32_t*) extra_arg :
118
 
                 internal::my_default_record_cache_size);
119
 
    if (not (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED | OPT_NO_ROWS)) && !share->state.header.uniques)
120
 
    {
121
 
      if (not (info->rec_cache.init_io_cache(info->dfile, cache_size,
122
 
                                             internal::WRITE_CACHE,info->state->data_file_length,
123
 
                                             (bool) (info->lock_type != F_UNLCK),
124
 
                                             MYF(share->write_flag & MY_WAIT_IF_FULL))))
 
117
                 my_default_record_cache_size);
 
118
    if (!(info->opt_flag &
 
119
          (READ_CACHE_USED | WRITE_CACHE_USED | OPT_NO_ROWS)) &&
 
120
        !share->state.header.uniques)
 
121
      if (!(init_io_cache(&info->rec_cache,info->dfile, cache_size,
 
122
                         WRITE_CACHE,info->state->data_file_length,
 
123
                          (bool) (info->lock_type != F_UNLCK),
 
124
                          MYF(share->write_flag & MY_WAIT_IF_FULL))))
125
125
      {
126
 
        info->opt_flag|=WRITE_CACHE_USED;
127
 
        info->update&= ~(HA_STATE_ROW_CHANGED |
 
126
        info->opt_flag|=WRITE_CACHE_USED;
 
127
        info->update&= ~(HA_STATE_ROW_CHANGED |
128
128
                         HA_STATE_WRITE_AT_END |
129
129
                         HA_STATE_EXTEND_BLOCK);
130
130
      }
131
 
    }
132
131
    break;
133
132
  case HA_EXTRA_PREPARE_FOR_UPDATE:
134
133
    if (info->s->data_file_type != DYNAMIC_RECORD)
138
137
    if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
139
138
    {
140
139
      info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
141
 
      error= info->rec_cache.end_io_cache();
 
140
      error=end_io_cache(&info->rec_cache);
142
141
      /* Sergei will insert full text index caching here */
143
142
    }
144
 
#if !defined(TARGET_OS_SOLARIS)
 
143
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE) && !defined(TARGET_OS_SOLARIS)
145
144
    if (info->opt_flag & MEMMAP_USED)
146
145
      madvise((char*) share->file_map, share->state.state.data_file_length,
147
146
              MADV_RANDOM);
237
236
    }
238
237
    break;
239
238
  case HA_EXTRA_FORCE_REOPEN:
240
 
    THR_LOCK_myisam.lock();
 
239
    pthread_mutex_lock(&THR_LOCK_myisam);
241
240
    share->last_version= 0L;                    /* Impossible version */
242
 
    THR_LOCK_myisam.unlock();
 
241
    pthread_mutex_unlock(&THR_LOCK_myisam);
243
242
    break;
244
243
  case HA_EXTRA_PREPARE_FOR_DROP:
245
 
    THR_LOCK_myisam.lock();
 
244
    pthread_mutex_lock(&THR_LOCK_myisam);
246
245
    share->last_version= 0L;                    /* Impossible version */
247
246
#ifdef __WIN__REMOVE_OBSOLETE_WORKAROUND
248
247
    /* Close the isam and data files as Win32 can't drop an open table */
 
248
    pthread_mutex_lock(&share->intern_lock);
249
249
    if (flush_key_blocks(share->key_cache, share->kfile,
250
250
                         (function == HA_EXTRA_FORCE_REOPEN ?
251
251
                          FLUSH_RELEASE : FLUSH_IGNORE_CHANGED)))
252
252
    {
253
 
      error=errno;
 
253
      error=my_errno;
254
254
      share->changed=1;
255
255
      mi_print_error(info->s, HA_ERR_CRASHED);
256
256
      mi_mark_crashed(info);                    /* Fatal error found */
264
264
    {
265
265
      info->was_locked=info->lock_type;
266
266
      if (mi_lock_database(info,F_UNLCK))
267
 
        error=errno;
 
267
        error=my_errno;
268
268
      info->lock_type = F_UNLCK;
269
269
    }
270
270
    if (share->kfile >= 0)
271
271
      _mi_decrement_open_count(info);
272
 
    if (share->kfile >= 0 && internal::my_close(share->kfile,MYF(0)))
273
 
      error=errno;
 
272
    if (share->kfile >= 0 && my_close(share->kfile,MYF(0)))
 
273
      error=my_errno;
274
274
    {
275
 
      list<MI_INFO *>::iterator it= myisam_open_list.begin();
276
 
      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)
277
279
      {
278
 
        MI_INFO *tmpinfo= *it;
 
280
        MI_INFO *tmpinfo=(MI_INFO*) list_element->data;
279
281
        if (tmpinfo->s == info->s)
280
282
        {
281
 
          if (tmpinfo->dfile >= 0 && internal::my_close(tmpinfo->dfile,MYF(0)))
282
 
            error = errno;
 
283
          if (tmpinfo->dfile >= 0 && my_close(tmpinfo->dfile,MYF(0)))
 
284
            error = my_errno;
283
285
          tmpinfo->dfile= -1;
284
286
        }
285
 
        ++it;
286
287
      }
287
288
    }
288
289
    share->kfile= -1;                           /* Files aren't open anymore */
 
290
    pthread_mutex_unlock(&share->intern_lock);
289
291
#endif
290
 
    THR_LOCK_myisam.unlock();
 
292
    pthread_mutex_unlock(&THR_LOCK_myisam);
291
293
    break;
292
294
  case HA_EXTRA_FLUSH:
293
295
    if (!share->temporary)
294
 
      flush_key_blocks(share->getKeyCache(), share->kfile, FLUSH_KEEP);
 
296
      flush_key_blocks(share->key_cache, share->kfile, FLUSH_KEEP);
295
297
#ifdef HAVE_PWRITE
296
298
    _mi_decrement_open_count(info);
297
299
#endif
298
300
    if (share->not_flushed)
299
301
    {
300
 
      share->not_flushed= false;
 
302
      share->not_flushed=0;
 
303
      if (my_sync(share->kfile, MYF(0)))
 
304
        error= my_errno;
 
305
      if (my_sync(info->dfile, MYF(0)))
 
306
        error= my_errno;
 
307
      if (error)
 
308
      {
 
309
        share->changed=1;
 
310
        mi_print_error(info->s, HA_ERR_CRASHED);
 
311
        mi_mark_crashed(info);                  /* Fatal error found */
 
312
      }
301
313
    }
302
314
    if (share->base.blobs)
303
 
      mi_alloc_rec_buff(info, SIZE_MAX, &info->rec_buff);
 
315
      mi_alloc_rec_buff(info, -1, &info->rec_buff);
304
316
    break;
305
317
  case HA_EXTRA_NORMAL:                         /* Theese isn't in use */
306
318
    info->quick_mode=0;
319
331
  case HA_EXTRA_CHANGE_KEY_TO_DUP:
320
332
    mi_extra_keyflag(info, function);
321
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;
322
359
  case HA_EXTRA_KEY_CACHE:
323
360
  case HA_EXTRA_NO_KEY_CACHE:
324
361
  default:
329
366
} /* mi_extra */
330
367
 
331
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
 
332
376
/*
333
377
    Start/Stop Inserting Duplicates Into a Table, WL#1648.
334
378
 */
366
410
  if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
367
411
  {
368
412
    info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
369
 
    error= info->rec_cache.end_io_cache();
 
413
    error= end_io_cache(&info->rec_cache);
370
414
  }
371
415
  if (share->base.blobs)
372
 
    mi_alloc_rec_buff(info, SIZE_MAX, &info->rec_buff);
373
 
#if !defined(TARGET_OS_SOLARIS)
 
416
    mi_alloc_rec_buff(info, -1, &info->rec_buff);
 
417
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE) && !defined(TARGET_OS_SOLARIS)
374
418
  if (info->opt_flag & MEMMAP_USED)
375
419
    madvise((char*) share->file_map, share->state.state.data_file_length,
376
420
            MADV_RANDOM);