41
42
class HeapEngine : public plugin::StorageEngine
44
HeapEngine(string name_arg)
45
: plugin::StorageEngine(name_arg,
46
HTON_STATS_RECORDS_IS_EXACT |
51
HTON_SKIP_STORE_LOCK |
45
explicit HeapEngine(string name_arg) :
46
plugin::StorageEngine(name_arg,
47
HTON_STATS_RECORDS_IS_EXACT |
52
HTON_SKIP_STORE_LOCK |
55
pthread_mutex_init(&THR_LOCK_heap, MY_MUTEX_INIT_FAST);
60
hp_panic(HA_PANIC_CLOSE);
62
pthread_mutex_destroy(&THR_LOCK_heap);
55
65
virtual Cursor *create(TableShare &table,
56
66
memory::Root *mem_root)
78
88
message::Table &create_proto,
79
89
HP_SHARE **internal_share);
81
int doRenameTable(Session*, const char * from, const char * to);
91
int doRenameTable(Session&, TableIdentifier &from, TableIdentifier &to);
83
int doDropTable(Session&, const string &table_path);
93
int doDropTable(Session&, TableIdentifier &identifier);
85
95
int doGetTableDefinition(Session& session,
88
const char *table_name,
90
message::Table *table_proto);
96
TableIdentifier &identifier,
97
message::Table &table_message);
92
99
/* Temp only engine, so do not return values. */
93
void doGetTableNames(CachedDirectory &, string& , set<string>&) { };
100
void doGetTableNames(CachedDirectory &, SchemaIdentifier& , set<string>&) { };
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);
116
bool doDoesTableExist(Session& session, TableIdentifier &identifier);
117
void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
118
drizzled::SchemaIdentifier &schema_identifier,
119
drizzled::TableIdentifiers &set_of_identifiers);
111
int HeapEngine::doGetTableDefinition(Session&,
116
message::Table *table_proto)
119
ProtoCache::iterator iter;
121
pthread_mutex_lock(&proto_cache_mutex);
122
iter= proto_cache.find(path);
124
if (iter!= proto_cache.end())
127
table_proto->CopyFrom(((*iter).second));
130
pthread_mutex_unlock(&proto_cache_mutex);
122
void HeapEngine::doGetTableIdentifiers(drizzled::CachedDirectory&,
123
drizzled::SchemaIdentifier&,
124
drizzled::TableIdentifiers&)
128
bool HeapEngine::doDoesTableExist(Session& session, TableIdentifier &identifier)
130
return session.doesTableMessageExist(identifier);
133
int HeapEngine::doGetTableDefinition(Session &session,
134
TableIdentifier &identifier,
135
message::Table &table_proto)
137
if (session.getTableMessage(identifier, table_proto))
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.
138
int HeapEngine::doDropTable(Session&, const string &table_path)
146
int HeapEngine::doDropTable(Session &session, TableIdentifier &identifier)
140
ProtoCache::iterator iter;
142
pthread_mutex_lock(&proto_cache_mutex);
143
iter= proto_cache.find(table_path.c_str());
145
if (iter!= proto_cache.end())
146
proto_cache.erase(iter);
147
pthread_mutex_unlock(&proto_cache_mutex);
149
return heap_delete_table(table_path.c_str());
148
session.removeTableMessage(identifier);
150
int error= heap_delete_table(identifier.getPath().c_str());
152
158
static HeapEngine *heap_storage_engine= NULL;
154
static int heap_init(plugin::Registry ®istry)
160
static int heap_init(plugin::Context &context)
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);
162
static int heap_deinit(plugin::Registry ®istry)
164
registry.remove(heap_storage_engine);
165
delete heap_storage_engine;
167
int ret= hp_panic(HA_PANIC_CLOSE);
169
pthread_mutex_destroy(&THR_LOCK_heap);
176
168
/*****************************************************************************
663
int HeapEngine::doRenameTable(Session*,
664
const char *from, const char *to)
655
int HeapEngine::doRenameTable(Session &session, TableIdentifier &from, TableIdentifier &to)
666
return heap_rename(from,to);
657
session.renameTableMessage(from, to);
658
return heap_rename(from.getPath().c_str(), to.getPath().c_str());
689
681
return key->rec_per_key[key->key_parts-1];
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)
698
690
HP_SHARE *internal_share;
691
const char *table_name= identifier.getPath().c_str();
700
error= heap_create_table(session, table_name, &table_arg,
693
error= heap_create_table(&session, table_name, &table_arg,
703
696
&internal_share);
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);