~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to plugin/heap/ha_heap.cc

  • Committer: Padraig O'Sullivan
  • Date: 2010-04-17 01:38:47 UTC
  • mfrom: (1237.9.238 bad-staging)
  • Revision ID: osullivan.padraig@gmail.com-20100417013847-ibjioqsfbmf5yg4g
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <drizzled/current_session.h>
21
21
#include <drizzled/field/timestamp.h>
22
22
#include <drizzled/field/varstring.h>
 
23
#include "drizzled/plugin/daemon.h"
23
24
 
24
25
#include "heap.h"
25
26
#include "ha_heap.h"
41
42
class HeapEngine : public plugin::StorageEngine
42
43
{
43
44
public:
44
 
  HeapEngine(string name_arg)
45
 
   : plugin::StorageEngine(name_arg,
46
 
                                     HTON_STATS_RECORDS_IS_EXACT |
47
 
                                     HTON_NULL_IN_KEY |
48
 
                                     HTON_FAST_KEY_READ |
49
 
                                     HTON_NO_BLOBS |
50
 
                                     HTON_HAS_RECORDS |
51
 
                                     HTON_SKIP_STORE_LOCK |
52
 
                                     HTON_TEMPORARY_ONLY)
53
 
  { }
 
45
  explicit HeapEngine(string name_arg) :
 
46
    plugin::StorageEngine(name_arg,
 
47
                          HTON_STATS_RECORDS_IS_EXACT |
 
48
                          HTON_NULL_IN_KEY |
 
49
                          HTON_FAST_KEY_READ |
 
50
                          HTON_NO_BLOBS |
 
51
                          HTON_HAS_RECORDS |
 
52
                          HTON_SKIP_STORE_LOCK |
 
53
                          HTON_TEMPORARY_ONLY)
 
54
  {
 
55
    pthread_mutex_init(&THR_LOCK_heap, MY_MUTEX_INIT_FAST);
 
56
  }
 
57
 
 
58
  virtual ~HeapEngine()
 
59
  {
 
60
    hp_panic(HA_PANIC_CLOSE);
 
61
 
 
62
    pthread_mutex_destroy(&THR_LOCK_heap);
 
63
  }
54
64
 
55
65
  virtual Cursor *create(TableShare &table,
56
66
                          memory::Root *mem_root)
62
72
    return ha_heap_exts;
63
73
  }
64
74
 
65
 
  int doCreateTable(Session *session,
66
 
                    const char *table_name,
67
 
                    Table& table_arg,
 
75
  int doCreateTable(Session &session,
 
76
                    Table &table_arg,
 
77
                    drizzled::TableIdentifier &identifier,
68
78
                    message::Table &create_proto);
69
79
 
70
80
  /* For whatever reason, internal tables can be created by Cursor::open()
78
88
                        message::Table &create_proto,
79
89
                        HP_SHARE **internal_share);
80
90
 
81
 
  int doRenameTable(Session*, const char * from, const char * to);
 
91
  int doRenameTable(Session&, TableIdentifier &from, TableIdentifier &to);
82
92
 
83
 
  int doDropTable(Session&, const string &table_path);
 
93
  int doDropTable(Session&, TableIdentifier &identifier);
84
94
 
85
95
  int doGetTableDefinition(Session& session,
86
 
                           const char* path,
87
 
                           const char *db,
88
 
                           const char *table_name,
89
 
                           const bool is_tmp,
90
 
                           message::Table *table_proto);
 
96
                           TableIdentifier &identifier,
 
97
                           message::Table &table_message);
91
98
 
92
99
  /* Temp only engine, so do not return values. */
93
 
  void doGetTableNames(CachedDirectory &, string& , set<string>&) { };
 
100
  void doGetTableNames(CachedDirectory &, SchemaIdentifier& , set<string>&) { };
94
101
 
95
102
  uint32_t max_supported_keys()          const { return MAX_KEY; }
96
103
  uint32_t max_supported_key_part_length() const { return MAX_KEY_LENGTH; }
106
113
            HA_KEY_SCAN_NOT_ROR);
107
114
  }
108
115
 
 
116
  bool doDoesTableExist(Session& session, TableIdentifier &identifier);
 
117
  void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
 
118
                             drizzled::SchemaIdentifier &schema_identifier,
 
119
                             drizzled::TableIdentifiers &set_of_identifiers);
109
120
};
110
121
 
111
 
int HeapEngine::doGetTableDefinition(Session&,
112
 
                                     const char* path,
113
 
                                     const char *,
114
 
                                     const char *,
115
 
                                     const bool,
116
 
                                     message::Table *table_proto)
117
 
{
118
 
  int error= ENOENT;
119
 
  ProtoCache::iterator iter;
120
 
 
121
 
  pthread_mutex_lock(&proto_cache_mutex);
122
 
  iter= proto_cache.find(path);
123
 
 
124
 
  if (iter!= proto_cache.end())
125
 
  {
126
 
    if (table_proto)
127
 
      table_proto->CopyFrom(((*iter).second));
128
 
    error= EEXIST;
129
 
  }
130
 
  pthread_mutex_unlock(&proto_cache_mutex);
131
 
 
132
 
  return error;
 
122
void HeapEngine::doGetTableIdentifiers(drizzled::CachedDirectory&,
 
123
                                       drizzled::SchemaIdentifier&,
 
124
                                       drizzled::TableIdentifiers&)
 
125
{
 
126
}
 
127
 
 
128
bool HeapEngine::doDoesTableExist(Session& session, TableIdentifier &identifier)
 
129
{
 
130
  return session.doesTableMessageExist(identifier);
 
131
}
 
132
 
 
133
int HeapEngine::doGetTableDefinition(Session &session,
 
134
                                     TableIdentifier &identifier,
 
135
                                     message::Table &table_proto)
 
136
{
 
137
  if (session.getTableMessage(identifier, table_proto))
 
138
    return EEXIST;
 
139
 
 
140
  return ENOENT;
133
141
}
134
142
/*
135
143
  We have to ignore ENOENT entries as the MEMORY table is created on open and
136
144
  not when doing a CREATE on the table.
137
145
*/
138
 
int HeapEngine::doDropTable(Session&, const string &table_path)
 
146
int HeapEngine::doDropTable(Session &session, TableIdentifier &identifier)
139
147
{
140
 
  ProtoCache::iterator iter;
141
 
 
142
 
  pthread_mutex_lock(&proto_cache_mutex);
143
 
  iter= proto_cache.find(table_path.c_str());
144
 
 
145
 
  if (iter!= proto_cache.end())
146
 
    proto_cache.erase(iter);
147
 
  pthread_mutex_unlock(&proto_cache_mutex);
148
 
 
149
 
  return heap_delete_table(table_path.c_str());
 
148
  session.removeTableMessage(identifier);
 
149
 
 
150
  int error= heap_delete_table(identifier.getPath().c_str());
 
151
 
 
152
  if (error == ENOENT)
 
153
    error= 0;
 
154
 
 
155
  return error;
150
156
}
151
157
 
152
158
static HeapEngine *heap_storage_engine= NULL;
153
159
 
154
 
static int heap_init(plugin::Registry &registry)
 
160
static int heap_init(plugin::Context &context)
155
161
{
156
162
  heap_storage_engine= new HeapEngine(engine_name);
157
 
  registry.add(heap_storage_engine);
158
 
  pthread_mutex_init(&THR_LOCK_heap, MY_MUTEX_INIT_FAST);
 
163
  context.add(heap_storage_engine);
159
164
  return 0;
160
165
}
161
166
 
162
 
static int heap_deinit(plugin::Registry &registry)
163
 
{
164
 
  registry.remove(heap_storage_engine);
165
 
  delete heap_storage_engine;
166
 
 
167
 
  int ret= hp_panic(HA_PANIC_CLOSE);
168
 
 
169
 
  pthread_mutex_destroy(&THR_LOCK_heap);
170
 
 
171
 
  return ret;
172
 
}
173
 
 
174
 
 
175
167
 
176
168
/*****************************************************************************
177
169
** MEMORY tables
377
369
  int res;
378
370
  ha_statistic_increment(&system_status_var::ha_delete_count);
379
371
  res= heap_delete(file,buf);
380
 
  if (!res && table->s->tmp_table == STANDARD_TABLE &&
 
372
  if (!res && table->s->tmp_table == message::Table::STANDARD &&
381
373
      ++records_changed*MEMORY_STATS_UPDATE_THRESHOLD > file->s->records)
382
374
  {
383
375
    /*
535
527
int ha_heap::delete_all_rows()
536
528
{
537
529
  heap_clear(file);
538
 
  if (table->s->tmp_table == STANDARD_TABLE)
 
530
  if (table->s->tmp_table == message::Table::STANDARD)
539
531
  {
540
532
    /*
541
533
       We can perform this safely since only one writer at the time is
660
652
}
661
653
 
662
654
 
663
 
int HeapEngine::doRenameTable(Session*,
664
 
                              const char *from, const char *to)
 
655
int HeapEngine::doRenameTable(Session &session, TableIdentifier &from, TableIdentifier &to)
665
656
{
666
 
  return heap_rename(from,to);
 
657
  session.renameTableMessage(from, to);
 
658
  return heap_rename(from.getPath().c_str(), to.getPath().c_str());
667
659
}
668
660
 
669
661
 
689
681
  return key->rec_per_key[key->key_parts-1];
690
682
}
691
683
 
692
 
int HeapEngine::doCreateTable(Session *session,
693
 
                              const char *table_name,
 
684
int HeapEngine::doCreateTable(Session &session,
694
685
                              Table &table_arg,
 
686
                              drizzled::TableIdentifier &identifier,
695
687
                              message::Table& create_proto)
696
688
{
697
689
  int error;
698
690
  HP_SHARE *internal_share;
 
691
  const char *table_name= identifier.getPath().c_str();
699
692
 
700
 
  error= heap_create_table(session, table_name, &table_arg,
 
693
  error= heap_create_table(&session, table_name, &table_arg,
701
694
                           false, 
702
695
                           create_proto,
703
696
                           &internal_share);
704
697
 
705
698
  if (error == 0)
706
699
  {
707
 
    pthread_mutex_lock(&proto_cache_mutex);
708
 
    proto_cache.insert(make_pair(table_name, create_proto));
709
 
    pthread_mutex_unlock(&proto_cache_mutex);
 
700
    session.storeTableMessage(identifier, create_proto);
710
701
  }
711
702
 
712
703
  return error;
937
928
  "Hash based, stored in memory, useful for temporary tables",
938
929
  PLUGIN_LICENSE_GPL,
939
930
  heap_init,
940
 
  heap_deinit,
941
931
  NULL,                       /* system variables                */
942
932
  NULL                        /* config options                  */
943
933
}