16
16
#include <drizzled/server_includes.h>
17
17
#include <drizzled/table.h>
18
#include <mysys/my_dir.h>
19
#include <drizzled/error.h>
18
21
#include "ha_blackhole.h"
25
#include <drizzled/message/table.pb.h>
26
#include <google/protobuf/io/zero_copy_stream.h>
27
#include <google/protobuf/io/zero_copy_stream_impl.h>
22
29
using namespace std;
30
using namespace google;
24
32
static const string engine_name("BLACKHOLE");
34
#define BLACKHOLE_EXT ".blk"
27
36
static const char *ha_blackhole_exts[] = {
34
43
BlackholeEngine(const string &name_arg)
35
: drizzled::plugin::StorageEngine(name_arg, HTON_FILE_BASED | HTON_CAN_RECREATE) {}
44
: drizzled::plugin::StorageEngine(name_arg, HTON_FILE_BASED | HTON_HAS_DATA_DICTIONARY | HTON_CAN_RECREATE)
46
table_definition_ext= BLACKHOLE_EXT;
36
49
virtual Cursor *create(TableShare *table,
37
50
MEM_ROOT *mem_root)
43
56
return ha_blackhole_exts;
46
int createTableImplementation(Session*, const char *, Table *,
47
HA_CREATE_INFO *, drizzled::message::Table*);
49
int deleteTableImplementation(Session*, const string table_name);
59
int doCreateTable(Session*, const char *, Table&,
60
HA_CREATE_INFO&, drizzled::message::Table&);
62
int doDropTable(Session&, const string table_name);
64
int doGetTableDefinition(Session& session,
67
const char *table_name,
69
drizzled::message::Table *table_proto);
71
void doGetTableNames(CachedDirectory &directory, string&, set<string>& set_of_names)
73
CachedDirectory::Entries entries= directory.getEntries();
75
for (CachedDirectory::Entries::iterator entry_iter= entries.begin();
76
entry_iter != entries.end(); ++entry_iter)
78
CachedDirectory::Entry *entry= *entry_iter;
79
string *filename= &entry->filename;
81
assert(filename->size());
83
const char *ext= strchr(filename->c_str(), '.');
85
if (ext == NULL || my_strcasecmp(system_charset_info, ext, BLACKHOLE_EXT) ||
86
is_prefix(filename->c_str(), TMP_FILE_PREFIX))
90
char uname[NAME_LEN + 1];
91
uint32_t file_name_len;
93
file_name_len= filename_to_tablename(filename->c_str(), uname, sizeof(uname));
94
// TODO: Remove need for memory copy here
95
uname[file_name_len - sizeof(BLACKHOLE_EXT) + 1]= '\0'; // Subtract ending, place NULL
96
set_of_names.insert(uname);
52
102
/* Static declarations for shared structures */
85
135
int ha_blackhole::close(void)
87
137
free_share(share);
91
int BlackholeEngine::createTableImplementation(Session*, const char *path,
92
Table *, HA_CREATE_INFO *,
93
drizzled::message::Table*)
95
FILE *blackhole_table;
97
/* Create an empty file for the Drizzle core to track whether
98
a blackhole table exists */
99
if ((blackhole_table= fopen(path, "w")) == NULL)
102
/* This file should never have to be reopened */
103
fclose(blackhole_table);
108
int BlackholeEngine::deleteTableImplementation(Session*, const string path)
110
if (unlink(path.c_str()) != 0)
141
int BlackholeEngine::doCreateTable(Session*, const char *path,
142
Table&, HA_CREATE_INFO&,
143
drizzled::message::Table& proto)
145
string serialized_proto;
149
new_path+= BLACKHOLE_EXT;
150
fstream output(new_path.c_str(), ios::out | ios::binary);
156
if (! proto.SerializeToOstream(&output))
159
unlink(new_path.c_str());
167
int BlackholeEngine::doDropTable(Session&, const string path)
172
new_path+= BLACKHOLE_EXT;
174
if (unlink(new_path.c_str()) != 0)
184
int BlackholeEngine::doGetTableDefinition(Session&,
189
drizzled::message::Table *table_proto)
194
new_path+= BLACKHOLE_EXT;
196
int fd= open(new_path.c_str(), O_RDONLY);
203
google::protobuf::io::ZeroCopyInputStream* input=
204
new google::protobuf::io::FileInputStream(fd);
209
if (table_proto && ! table_proto->ParseFromZeroCopyStream(input))
118
220
const char *ha_blackhole::index_type(uint32_t)