~posulliv/drizzle/memcached_applier

« back to all changes in this revision

Viewing changes to plugin/heap/ha_heap.cc

Merged trunk and resolved conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
pthread_mutex_t THR_LOCK_heap= PTHREAD_MUTEX_INITIALIZER;
35
35
 
 
36
static const char *ha_heap_exts[] = {
 
37
  NULL
 
38
};
36
39
 
37
40
class HeapEngine : public StorageEngine
38
41
{
47
50
  {
48
51
    return new (mem_root) ha_heap(this, table);
49
52
  }
 
53
 
 
54
  const char **bas_ext() const {
 
55
    return ha_heap_exts;
 
56
  }
 
57
 
 
58
  int createTableImpl(Session *session, const char *table_name,
 
59
                      Table *table_arg, HA_CREATE_INFO *create_info);
 
60
 
 
61
  /* For whatever reason, internal tables can be created by handler::open()
 
62
     for HEAP.
 
63
     Instead of diving down a rat hole, let's just cry ourselves to sleep
 
64
     at night with this odd hackish workaround.
 
65
   */
 
66
  int heap_create_table(Session *session, const char *table_name,
 
67
                        Table *table_arg, HA_CREATE_INFO *create_info,
 
68
                        bool internal_table,
 
69
                        HP_SHARE **internal_share);
 
70
 
 
71
  int renameTableImpl(Session*, const char * from, const char * to);
 
72
 
 
73
  int deleteTableImpl(Session *, const string table_path);
50
74
};
51
75
 
52
 
static HeapEngine *engine= NULL;
 
76
/*
 
77
  We have to ignore ENOENT entries as the HEAP table is created on open and
 
78
  not when doing a CREATE on the table.
 
79
*/
 
80
int HeapEngine::deleteTableImpl(Session*, const string table_path)
 
81
{
 
82
  return heap_delete_table(table_path.c_str());
 
83
}
 
84
 
 
85
static HeapEngine *heap_storage_engine= NULL;
53
86
int heap_init(PluginRegistry &registry)
54
87
{
55
 
  engine= new HeapEngine(engine_name);
56
 
  registry.add(engine);
 
88
  heap_storage_engine= new HeapEngine(engine_name);
 
89
  registry.add(heap_storage_engine);
57
90
  pthread_mutex_init(&THR_LOCK_heap, MY_MUTEX_INIT_FAST);
58
91
  return 0;
59
92
}
60
93
 
61
94
int heap_deinit(PluginRegistry &registry)
62
95
{
63
 
  registry.remove(engine);
64
 
  delete engine;
 
96
  registry.remove(heap_storage_engine);
 
97
  delete heap_storage_engine;
65
98
 
66
99
  pthread_mutex_destroy(&THR_LOCK_heap);
67
100
 
79
112
  internal_table(0)
80
113
{}
81
114
 
82
 
 
83
 
static const char *ha_heap_exts[] = {
84
 
  NULL
85
 
};
86
 
 
87
 
const char **ha_heap::bas_ext() const
88
 
{
89
 
  return ha_heap_exts;
90
 
}
91
 
 
92
115
/*
93
116
  Hash index statistics is updated (copied from HP_KEYDEF::hash_buckets to
94
117
  rec_per_key) after 1/HEAP_STATS_UPDATE_THRESHOLD fraction of table records
110
133
    internal_table= test(test_if_locked & HA_OPEN_INTERNAL_TABLE);
111
134
    memset(&create_info, 0, sizeof(create_info));
112
135
    file= 0;
113
 
    if (!create(name, table, &create_info))
 
136
    HP_SHARE *internal_share= NULL;
 
137
    if (!heap_storage_engine->heap_create_table(ha_session(), name, table,
 
138
                                                &create_info,
 
139
                                                internal_table,&internal_share))
114
140
    {
115
141
        file= internal_table ?
116
142
          heap_open_from_share(internal_share, mode) :
576
602
  return to;
577
603
}
578
604
 
579
 
/*
580
 
  We have to ignore ENOENT entries as the HEAP table is created on open and
581
 
  not when doing a CREATE on the table.
582
 
*/
583
 
 
584
 
int ha_heap::delete_table(const char *name)
585
 
{
586
 
  return heap_delete_table(name);
587
 
}
588
 
 
589
 
 
590
605
void ha_heap::drop_table(const char *)
591
606
{
592
607
  file->s->delete_on_close= 1;
594
609
}
595
610
 
596
611
 
597
 
int ha_heap::rename_table(const char * from, const char * to)
 
612
int HeapEngine::renameTableImpl(Session*, const char *from, const char *to)
598
613
{
599
614
  return heap_rename(from,to);
600
615
}
622
637
  return key->rec_per_key[key->key_parts-1];
623
638
}
624
639
 
625
 
 
626
 
int ha_heap::create(const char *name, Table *table_arg,
627
 
                    HA_CREATE_INFO *create_info)
 
640
int HeapEngine::createTableImpl(Session *session, const char *table_name,
 
641
                                Table *table_arg,
 
642
                                HA_CREATE_INFO *create_info)
 
643
{
 
644
  HP_SHARE *internal_share;
 
645
  return heap_create_table(session, table_name, table_arg, create_info,
 
646
                           false, &internal_share);
 
647
}
 
648
 
 
649
 
 
650
int HeapEngine::heap_create_table(Session *session, const char *table_name,
 
651
                             Table *table_arg, HA_CREATE_INFO *create_info,
 
652
                             bool internal_table, HP_SHARE **internal_share)
628
653
{
629
654
  uint32_t key, parts, mem_per_row_keys= 0, keys= table_arg->s->keys;
630
655
  uint32_t auto_key= 0, auto_key_type= 0;
785
810
  hp_create_info.auto_key_type= auto_key_type;
786
811
  hp_create_info.auto_increment= (create_info->auto_increment_value ?
787
812
                                  create_info->auto_increment_value - 1 : 0);
788
 
  hp_create_info.max_table_size=current_session->variables.max_heap_table_size;
 
813
  hp_create_info.max_table_size=session->variables.max_heap_table_size;
789
814
  hp_create_info.with_auto_increment= found_real_auto_increment;
790
815
  hp_create_info.internal_table= internal_table;
791
816
  hp_create_info.max_chunk_size= share->block_size;
792
817
  hp_create_info.is_dynamic= (share->row_type == ROW_TYPE_DYNAMIC);
793
 
  error= heap_create(fn_format(buff,name,"","",
 
818
  error= heap_create(fn_format(buff,table_name,"","",
794
819
                               MY_REPLACE_EXT|MY_UNPACK_FILENAME),
795
820
                   keys, keydef,
796
821
         column_count, columndef,
797
822
         max_key_fieldnr, key_part_size,
798
823
         share->reclength, mem_per_row_keys,
799
824
         (uint32_t) share->max_rows, (uint32_t) share->min_rows,
800
 
         &hp_create_info, &internal_share);
 
825
         &hp_create_info, internal_share);
801
826
 
802
827
  free((unsigned char*) keydef);
803
828
  free((void *) columndef);
804
 
  assert(file == 0);
 
829
 
805
830
  return (error);
806
831
}
807
832