~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/mi_extra.cc

  • Committer: Brian Aker
  • Date: 2009-11-18 06:24:48 UTC
  • mfrom: (1220.1.15 staging)
  • Revision ID: brian@gaz-20091118062448-o36lo3yv81sc6u9z
Merge Brian + Stewart

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
16
#include "myisam_priv.h"
17
17
#include <drizzled/util/test.h>
21
21
#include <string.h>
22
22
#include <algorithm>
23
23
 
24
 
using namespace drizzled;
25
24
using namespace std;
26
25
 
27
26
static void mi_extra_keyflag(MI_INFO *info, enum ha_extra_function function);
57
56
                                        /* Next/prev gives first/last */
58
57
    if (info->opt_flag & READ_CACHE_USED)
59
58
    {
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));
 
59
      reinit_io_cache(&info->rec_cache,READ_CACHE,0,
 
60
                      (bool) (info->lock_type != F_UNLCK),
 
61
                      (bool) test(info->update & HA_STATE_ROW_CHANGED)
 
62
                      );
63
63
    }
64
64
    info->update= ((info->update & HA_STATE_CHANGED) | HA_STATE_NEXT_FOUND |
65
65
                   HA_STATE_PREV_FOUND);
69
69
        (share->options & HA_OPTION_PACK_RECORD))
70
70
    {
71
71
      error=1;                  /* Not possibly if not locked */
72
 
      errno=EACCES;
 
72
      my_errno=EACCES;
73
73
      break;
74
74
    }
75
75
    if (info->s->file_map) /* Don't use cache if mmap */
77
77
    if (info->opt_flag & WRITE_CACHE_USED)
78
78
    {
79
79
      info->opt_flag&= ~WRITE_CACHE_USED;
80
 
      if ((error= info->rec_cache.end_io_cache()))
 
80
      if ((error=end_io_cache(&info->rec_cache)))
81
81
        break;
82
82
    }
83
83
    if (!(info->opt_flag &
84
84
          (READ_CACHE_USED | WRITE_CACHE_USED | MEMMAP_USED)))
85
85
    {
86
86
      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))))
 
87
                   my_default_record_cache_size);
 
88
      if (!(init_io_cache(&info->rec_cache,info->dfile,
 
89
                         (uint) min((uint32_t)info->state->data_file_length+1,
 
90
                                    cache_size),
 
91
                          READ_CACHE,0L,(bool) (info->lock_type != F_UNLCK),
 
92
                          MYF(share->write_flag & MY_WAIT_IF_FULL))))
91
93
      {
92
94
        info->opt_flag|=READ_CACHE_USED;
93
95
        info->update&= ~HA_STATE_ROW_CHANGED;
99
101
  case HA_EXTRA_REINIT_CACHE:
100
102
    if (info->opt_flag & READ_CACHE_USED)
101
103
    {
102
 
      info->rec_cache.reinit_io_cache(internal::READ_CACHE,info->nextpos,
 
104
      reinit_io_cache(&info->rec_cache,READ_CACHE,info->nextpos,
103
105
                      (bool) (info->lock_type != F_UNLCK),
104
106
                      (bool) test(info->update & HA_STATE_ROW_CHANGED));
105
107
      info->update&= ~HA_STATE_ROW_CHANGED;
115
117
    }
116
118
 
117
119
    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))))
 
120
                 my_default_record_cache_size);
 
121
    if (!(info->opt_flag &
 
122
          (READ_CACHE_USED | WRITE_CACHE_USED | OPT_NO_ROWS)) &&
 
123
        !share->state.header.uniques)
 
124
      if (!(init_io_cache(&info->rec_cache,info->dfile, cache_size,
 
125
                         WRITE_CACHE,info->state->data_file_length,
 
126
                          (bool) (info->lock_type != F_UNLCK),
 
127
                          MYF(share->write_flag & MY_WAIT_IF_FULL))))
125
128
      {
126
 
        info->opt_flag|=WRITE_CACHE_USED;
127
 
        info->update&= ~(HA_STATE_ROW_CHANGED |
 
129
        info->opt_flag|=WRITE_CACHE_USED;
 
130
        info->update&= ~(HA_STATE_ROW_CHANGED |
128
131
                         HA_STATE_WRITE_AT_END |
129
132
                         HA_STATE_EXTEND_BLOCK);
130
133
      }
131
 
    }
132
134
    break;
133
135
  case HA_EXTRA_PREPARE_FOR_UPDATE:
134
136
    if (info->s->data_file_type != DYNAMIC_RECORD)
138
140
    if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
139
141
    {
140
142
      info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
141
 
      error= info->rec_cache.end_io_cache();
 
143
      error=end_io_cache(&info->rec_cache);
142
144
      /* Sergei will insert full text index caching here */
143
145
    }
144
 
#if !defined(TARGET_OS_SOLARIS)
 
146
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE) && !defined(TARGET_OS_SOLARIS)
145
147
    if (info->opt_flag & MEMMAP_USED)
146
148
      madvise((char*) share->file_map, share->state.state.data_file_length,
147
149
              MADV_RANDOM);
237
239
    }
238
240
    break;
239
241
  case HA_EXTRA_FORCE_REOPEN:
240
 
    THR_LOCK_myisam.lock();
 
242
    pthread_mutex_lock(&THR_LOCK_myisam);
241
243
    share->last_version= 0L;                    /* Impossible version */
242
 
    THR_LOCK_myisam.unlock();
 
244
    pthread_mutex_unlock(&THR_LOCK_myisam);
243
245
    break;
244
246
  case HA_EXTRA_PREPARE_FOR_DROP:
245
 
    THR_LOCK_myisam.lock();
 
247
    pthread_mutex_lock(&THR_LOCK_myisam);
246
248
    share->last_version= 0L;                    /* Impossible version */
247
249
#ifdef __WIN__REMOVE_OBSOLETE_WORKAROUND
248
250
    /* Close the isam and data files as Win32 can't drop an open table */
 
251
    pthread_mutex_lock(&share->intern_lock);
249
252
    if (flush_key_blocks(share->key_cache, share->kfile,
250
253
                         (function == HA_EXTRA_FORCE_REOPEN ?
251
254
                          FLUSH_RELEASE : FLUSH_IGNORE_CHANGED)))
252
255
    {
253
 
      error=errno;
 
256
      error=my_errno;
254
257
      share->changed=1;
255
258
      mi_print_error(info->s, HA_ERR_CRASHED);
256
259
      mi_mark_crashed(info);                    /* Fatal error found */
264
267
    {
265
268
      info->was_locked=info->lock_type;
266
269
      if (mi_lock_database(info,F_UNLCK))
267
 
        error=errno;
 
270
        error=my_errno;
268
271
      info->lock_type = F_UNLCK;
269
272
    }
270
273
    if (share->kfile >= 0)
271
274
      _mi_decrement_open_count(info);
272
 
    if (share->kfile >= 0 && internal::my_close(share->kfile,MYF(0)))
273
 
      error=errno;
 
275
    if (share->kfile >= 0 && my_close(share->kfile,MYF(0)))
 
276
      error=my_errno;
274
277
    {
275
278
      list<MI_INFO *>::iterator it= myisam_open_list.begin();
276
279
      while (it != myisam_open_list.end())
278
281
        MI_INFO *tmpinfo= *it;
279
282
        if (tmpinfo->s == info->s)
280
283
        {
281
 
          if (tmpinfo->dfile >= 0 && internal::my_close(tmpinfo->dfile,MYF(0)))
282
 
            error = errno;
 
284
          if (tmpinfo->dfile >= 0 && my_close(tmpinfo->dfile,MYF(0)))
 
285
            error = my_errno;
283
286
          tmpinfo->dfile= -1;
284
287
        }
285
288
        ++it;
286
289
      }
287
290
    }
288
291
    share->kfile= -1;                           /* Files aren't open anymore */
 
292
    pthread_mutex_unlock(&share->intern_lock);
289
293
#endif
290
 
    THR_LOCK_myisam.unlock();
 
294
    pthread_mutex_unlock(&THR_LOCK_myisam);
291
295
    break;
292
296
  case HA_EXTRA_FLUSH:
293
297
    if (!share->temporary)
294
 
      flush_key_blocks(share->getKeyCache(), share->kfile, FLUSH_KEEP);
 
298
      flush_key_blocks(share->key_cache, share->kfile, FLUSH_KEEP);
295
299
#ifdef HAVE_PWRITE
296
300
    _mi_decrement_open_count(info);
297
301
#endif
298
302
    if (share->not_flushed)
299
303
    {
300
 
      share->not_flushed= false;
 
304
      share->not_flushed=0;
 
305
      if (my_sync(share->kfile, MYF(0)))
 
306
        error= my_errno;
 
307
      if (my_sync(info->dfile, MYF(0)))
 
308
        error= my_errno;
 
309
      if (error)
 
310
      {
 
311
        share->changed=1;
 
312
        mi_print_error(info->s, HA_ERR_CRASHED);
 
313
        mi_mark_crashed(info);                  /* Fatal error found */
 
314
      }
301
315
    }
302
316
    if (share->base.blobs)
303
 
      mi_alloc_rec_buff(info, SIZE_MAX, &info->rec_buff);
 
317
      mi_alloc_rec_buff(info, -1, &info->rec_buff);
304
318
    break;
305
319
  case HA_EXTRA_NORMAL:                         /* Theese isn't in use */
306
320
    info->quick_mode=0;
366
380
  if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
367
381
  {
368
382
    info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
369
 
    error= info->rec_cache.end_io_cache();
 
383
    error= end_io_cache(&info->rec_cache);
370
384
  }
371
385
  if (share->base.blobs)
372
 
    mi_alloc_rec_buff(info, SIZE_MAX, &info->rec_buff);
373
 
#if !defined(TARGET_OS_SOLARIS)
 
386
    mi_alloc_rec_buff(info, -1, &info->rec_buff);
 
387
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE) && !defined(TARGET_OS_SOLARIS)
374
388
  if (info->opt_flag & MEMMAP_USED)
375
389
    madvise((char*) share->file_map, share->state.state.data_file_length,
376
390
            MADV_RANDOM);