~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/mi_open.cc

Merge Joe, plus I updated the tests.

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
/* open a isam-database */
17
17
 
19
19
 
20
20
#include <string.h>
21
21
#include <algorithm>
22
 
#include <memory>
23
 
#include <boost/scoped_ptr.hpp>
24
 
#include <boost/scoped_array.hpp>
25
22
 
26
23
#include "drizzled/charset_info.h"
27
24
#include "drizzled/internal/m_string.h"
79
76
  have an open count of 0.
80
77
******************************************************************************/
81
78
 
82
 
MI_INFO *mi_open(const drizzled::identifier::Table &identifier, int mode, uint32_t open_flags)
 
79
MI_INFO *mi_open(const char *name, int mode, uint32_t open_flags)
83
80
{
84
81
  int lock_error,kfile,open_mode,save_errno,have_rtree=0;
85
82
  uint32_t i,j,len,errpos,head_length,base_pos,offset,info_length,keys,
89
86
  unsigned char *disk_cache= NULL;
90
87
  unsigned char *disk_pos, *end_pos;
91
88
  MI_INFO info,*m_info,*old_info;
92
 
  boost::scoped_ptr<MYISAM_SHARE> share_buff_ap(new MYISAM_SHARE);
93
 
  MYISAM_SHARE &share_buff= *share_buff_ap.get();
94
 
  MYISAM_SHARE *share;
95
 
  boost::scoped_array<ulong> rec_per_key_part_ap(new ulong[HA_MAX_POSSIBLE_KEY*MI_MAX_KEY_SEG]);
96
 
  ulong *rec_per_key_part= rec_per_key_part_ap.get();
 
89
  MYISAM_SHARE share_buff,*share;
 
90
  ulong rec_per_key_part[HA_MAX_POSSIBLE_KEY*MI_MAX_KEY_SEG];
97
91
  internal::my_off_t key_root[HA_MAX_POSSIBLE_KEY],key_del[MI_MAX_KEY_BLOCK_SIZE];
98
92
  uint64_t max_key_file_length, max_data_file_length;
99
93
 
103
97
  head_length=sizeof(share_buff.state.header);
104
98
  memset(&info, 0, sizeof(info));
105
99
 
106
 
  (void)internal::fn_format(org_name,
107
 
                            identifier.getPath().c_str(), 
108
 
                            "",
109
 
                            MI_NAME_IEXT,
110
 
                            MY_UNPACK_FILENAME);
 
100
  (void)internal::fn_format(org_name,name,"",MI_NAME_IEXT, MY_UNPACK_FILENAME);
111
101
  if (!realpath(org_name,rp_buff))
112
102
    internal::my_load_path(rp_buff,org_name, NULL);
113
103
  rp_buff[FN_REFLEN-1]= '\0';
114
104
  strcpy(name_buff,rp_buff);
115
 
  THR_LOCK_myisam.lock();
 
105
  pthread_mutex_lock(&THR_LOCK_myisam);
116
106
  if (!(old_info=test_if_reopen(name_buff)))
117
107
  {
118
108
    share= &share_buff;
120
110
    share_buff.state.rec_per_key_part=rec_per_key_part;
121
111
    share_buff.state.key_root=key_root;
122
112
    share_buff.state.key_del=key_del;
123
 
    share_buff.setKeyCache();
 
113
    share_buff.key_cache= dflt_key_cache;
124
114
 
125
115
    if ((kfile=internal::my_open(name_buff,(open_mode=O_RDWR),MYF(0))) < 0)
126
116
    {
143
133
      goto err;
144
134
    }
145
135
    share->options= mi_uint2korr(share->state.header.options);
146
 
    static const uint64_t OLD_FILE_OPTIONS= HA_OPTION_PACK_RECORD |
147
 
            HA_OPTION_PACK_KEYS |
148
 
            HA_OPTION_COMPRESS_RECORD | HA_OPTION_READ_ONLY_DATA |
149
 
            HA_OPTION_TEMP_COMPRESS_RECORD |
150
 
            HA_OPTION_TMP_TABLE;
151
 
    if (share->options & ~OLD_FILE_OPTIONS)
 
136
    if (share->options &
 
137
        ~(HA_OPTION_PACK_RECORD | HA_OPTION_PACK_KEYS |
 
138
          HA_OPTION_COMPRESS_RECORD | HA_OPTION_READ_ONLY_DATA |
 
139
          HA_OPTION_TEMP_COMPRESS_RECORD |
 
140
          HA_OPTION_TMP_TABLE
 
141
          ))
152
142
    {
153
143
      errno=HA_ERR_OLD_FILE;
154
144
      goto err;
257
247
           &share->state.key_root,keys*sizeof(uint64_t),
258
248
           &share->state.key_del,
259
249
           (share->state.header.max_block_size_index*sizeof(uint64_t)),
 
250
           &share->key_root_lock,sizeof(pthread_rwlock_t)*keys,
 
251
           &share->mmap_lock,sizeof(pthread_rwlock_t),
260
252
           NULL))
261
253
      goto err;
262
254
    errpos=4;
397
389
    disk_cache= NULL;
398
390
    mi_setup_functions(share);
399
391
    share->is_log_table= false;
400
 
    if (myisam_concurrent_insert)
 
392
    thr_lock_init(&share->lock);
 
393
    pthread_mutex_init(&share->intern_lock,MY_MUTEX_INIT_FAST);
 
394
    for (i=0; i<keys; i++)
 
395
      pthread_rwlock_init(&share->key_root_lock[i], NULL);
 
396
    pthread_rwlock_init(&share->mmap_lock, NULL);
 
397
    if (!thr_lock_inited)
 
398
    {
 
399
      /* Probably a single threaded program; Don't use concurrent inserts */
 
400
      myisam_concurrent_insert=0;
 
401
    }
 
402
    else if (myisam_concurrent_insert)
401
403
    {
402
404
      share->concurrent_insert=
403
405
        ((share->options & (HA_OPTION_READ_ONLY_DATA | HA_OPTION_TMP_TABLE |
406
408
         (open_flags & HA_OPEN_TMP_TABLE) || have_rtree) ? 0 : 1;
407
409
      if (share->concurrent_insert)
408
410
      {
409
 
        assert(0);
 
411
        share->lock.get_status= mi_get_status;
 
412
        share->lock.copy_status= mi_copy_status;
 
413
        share->lock.update_status= mi_update_status;
 
414
        share->lock.restore_status= mi_restore_status;
 
415
        share->lock.check_status= mi_check_status;
410
416
      }
411
417
    }
412
418
  }
432
438
                     share->base.max_key_length),
433
439
         &info.lastkey,share->base.max_key_length*3+1,
434
440
         &info.first_mbr_key, share->base.max_key_length,
435
 
         &info.filename, identifier.getPath().length()+1,
 
441
         &info.filename,strlen(name)+1,
436
442
         &info.rtree_recursion_state,have_rtree ? 1024 : 0,
437
443
         NULL))
438
444
    goto err;
441
447
  if (!have_rtree)
442
448
    info.rtree_recursion_state= NULL;
443
449
 
444
 
  strcpy(info.filename, identifier.getPath().c_str());
 
450
  strcpy(info.filename,name);
445
451
  memcpy(info.blobs,share->blobs,sizeof(MI_BLOB)*share->base.blobs);
446
452
  info.lastkey2=info.lastkey+share->base.max_key_length;
447
453
 
462
468
  info.bulk_insert=0;
463
469
  info.errkey= -1;
464
470
  info.page_changed=1;
 
471
  pthread_mutex_lock(&share->intern_lock);
465
472
  info.read_record=share->read_record;
466
473
  share->reopen++;
467
474
  share->write_flag=MYF(MY_NABP | MY_WAIT_IF_FULL);
491
498
 
492
499
  share->delay_key_write= 1;
493
500
  info.state= &share->state.state;      /* Change global values by default */
 
501
  pthread_mutex_unlock(&share->intern_lock);
494
502
 
495
503
  /* Allocate buffer for one record */
496
504
 
497
505
  /* prerequisites: memset(info, 0) && info->s=share; are met. */
498
 
  if (!mi_alloc_rec_buff(&info, SIZE_MAX, &info.rec_buff))
 
506
  if (!mi_alloc_rec_buff(&info, -1, &info.rec_buff))
499
507
    goto err;
500
508
  memset(info.rec_buff, 0, mi_get_rec_buff_len(&info, info.rec_buff));
501
509
 
502
510
  *m_info=info;
 
511
  thr_lock_data_init(&share->lock,&m_info->lock,(void*) m_info);
503
512
  myisam_open_list.push_front(m_info);
504
513
 
505
 
  THR_LOCK_myisam.unlock();
 
514
  pthread_mutex_unlock(&THR_LOCK_myisam);
506
515
  return(m_info);
507
516
 
508
517
err:
512
521
  if ((save_errno == HA_ERR_CRASHED) ||
513
522
      (save_errno == HA_ERR_CRASHED_ON_USAGE) ||
514
523
      (save_errno == HA_ERR_CRASHED_ON_REPAIR))
515
 
    mi_report_error(save_errno, identifier.getPath().c_str());
 
524
    mi_report_error(save_errno, name);
516
525
  switch (errpos) {
517
526
  case 6:
518
527
    free((unsigned char*) m_info);
534
543
  default:
535
544
    break;
536
545
  }
537
 
  THR_LOCK_myisam.unlock();
 
546
  pthread_mutex_unlock(&THR_LOCK_myisam);
538
547
  errno=save_errno;
539
548
  return (NULL);
540
549
} /* mi_open */
550
559
    unsigned char *newptr = *buf;
551
560
 
552
561
    /* to simplify initial init of info->rec_buf in mi_open and mi_extra */
553
 
    if (length == SIZE_MAX)
 
562
    if (length == (ulong) -1)
554
563
    {
555
564
      if (info->s->options & HA_OPTION_COMPRESS_RECORD)
556
565
        length= max(info->s->base.pack_reclength, info->s->max_pack_length);