~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/heap/ha_heap.cc

  • Committer: Siddharth Prakash Singh
  • Date: 2010-03-26 19:25:23 UTC
  • mfrom: (1410 drizzle)
  • mto: This revision was merged to the branch mainline in revision 1425.
  • Revision ID: spsneo@spsneo-laptop-20100326192523-ibjlbt1p692vobtj
merging with 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_HAS_DATA_DICTIONARY |
 
53
                          HTON_SKIP_STORE_LOCK |
 
54
                          HTON_TEMPORARY_ONLY)
 
55
  {
 
56
    pthread_mutex_init(&THR_LOCK_heap, MY_MUTEX_INIT_FAST);
 
57
  }
 
58
 
 
59
  virtual ~HeapEngine()
 
60
  {
 
61
    hp_panic(HA_PANIC_CLOSE);
 
62
 
 
63
    pthread_mutex_destroy(&THR_LOCK_heap);
 
64
  }
54
65
 
55
66
  virtual Cursor *create(TableShare &table,
56
67
                          memory::Root *mem_root)
78
89
                        message::Table &create_proto,
79
90
                        HP_SHARE **internal_share);
80
91
 
81
 
  int doRenameTable(Session*, const char * from, const char * to);
 
92
  int doRenameTable(Session&, TableIdentifier &from, TableIdentifier &to);
82
93
 
83
94
  int doDropTable(Session&, TableIdentifier &identifier);
84
95
 
103
114
            HA_KEY_SCAN_NOT_ROR);
104
115
  }
105
116
 
 
117
  bool doDoesTableExist(Session& session, TableIdentifier &identifier);
106
118
};
107
119
 
108
 
int HeapEngine::doGetTableDefinition(Session&,
 
120
bool HeapEngine::doDoesTableExist(Session& session, TableIdentifier &identifier)
 
121
{
 
122
  return session.doesTableMessageExist(identifier);
 
123
}
 
124
 
 
125
int HeapEngine::doGetTableDefinition(Session &session,
109
126
                                     TableIdentifier &identifier,
110
127
                                     message::Table &table_proto)
111
128
{
112
 
  int error= ENOENT;
113
 
  ProtoCache::iterator iter;
114
 
 
115
 
  pthread_mutex_lock(&proto_cache_mutex);
116
 
  iter= proto_cache.find(identifier.getPath());
117
 
 
118
 
  if (iter!= proto_cache.end())
119
 
  {
120
 
    table_proto.CopyFrom(((*iter).second));
121
 
    error= EEXIST;
122
 
  }
123
 
  pthread_mutex_unlock(&proto_cache_mutex);
124
 
 
125
 
  return error;
 
129
  if (session.getTableMessage(identifier, table_proto))
 
130
    return EEXIST;
 
131
 
 
132
  return ENOENT;
126
133
}
127
134
/*
128
135
  We have to ignore ENOENT entries as the MEMORY table is created on open and
129
136
  not when doing a CREATE on the table.
130
137
*/
131
 
int HeapEngine::doDropTable(Session&, TableIdentifier &identifier)
 
138
int HeapEngine::doDropTable(Session &session, TableIdentifier &identifier)
132
139
{
133
 
  ProtoCache::iterator iter;
134
 
 
135
 
  pthread_mutex_lock(&proto_cache_mutex);
136
 
  iter= proto_cache.find(identifier.getPath());
137
 
 
138
 
  if (iter!= proto_cache.end())
139
 
    proto_cache.erase(iter);
140
 
  pthread_mutex_unlock(&proto_cache_mutex);
 
140
  session.removeTableMessage(identifier);
141
141
 
142
142
  return heap_delete_table(identifier.getPath().c_str());
143
143
}
144
144
 
145
145
static HeapEngine *heap_storage_engine= NULL;
146
146
 
147
 
static int heap_init(plugin::Registry &registry)
 
147
static int heap_init(plugin::Context &context)
148
148
{
149
149
  heap_storage_engine= new HeapEngine(engine_name);
150
 
  registry.add(heap_storage_engine);
151
 
  pthread_mutex_init(&THR_LOCK_heap, MY_MUTEX_INIT_FAST);
 
150
  context.add(heap_storage_engine);
152
151
  return 0;
153
152
}
154
153
 
155
 
static int heap_deinit(plugin::Registry &registry)
156
 
{
157
 
  registry.remove(heap_storage_engine);
158
 
  delete heap_storage_engine;
159
 
 
160
 
  int ret= hp_panic(HA_PANIC_CLOSE);
161
 
 
162
 
  pthread_mutex_destroy(&THR_LOCK_heap);
163
 
 
164
 
  return ret;
165
 
}
166
 
 
167
 
 
168
154
 
169
155
/*****************************************************************************
170
156
** MEMORY tables
653
639
}
654
640
 
655
641
 
656
 
int HeapEngine::doRenameTable(Session*,
657
 
                              const char *from, const char *to)
 
642
int HeapEngine::doRenameTable(Session &session, TableIdentifier &from, TableIdentifier &to)
658
643
{
659
 
  return heap_rename(from,to);
 
644
  session.renameTableMessage(from, to);
 
645
  return heap_rename(from.getPath().c_str(), to.getPath().c_str());
660
646
}
661
647
 
662
648
 
698
684
 
699
685
  if (error == 0)
700
686
  {
701
 
    pthread_mutex_lock(&proto_cache_mutex);
702
 
    proto_cache.insert(make_pair(table_name, create_proto));
703
 
    pthread_mutex_unlock(&proto_cache_mutex);
 
687
    session->storeTableMessage(identifier, create_proto);
704
688
  }
705
689
 
706
690
  return error;
931
915
  "Hash based, stored in memory, useful for temporary tables",
932
916
  PLUGIN_LICENSE_GPL,
933
917
  heap_init,
934
 
  heap_deinit,
935
918
  NULL,                       /* system variables                */
936
919
  NULL                        /* config options                  */
937
920
}