51
54
BlackholeEngine(const string &name_arg)
52
: drizzled::plugin::StorageEngine(name_arg, HTON_FILE_BASED |
55
: drizzled::plugin::StorageEngine(name_arg,
54
57
HTON_CAN_INDEX_BLOBS |
55
58
HTON_SKIP_STORE_LOCK |
57
HTON_HAS_DATA_DICTIONARY),
58
60
blackhole_open_tables()
60
62
table_definition_ext= BLACKHOLE_EXT;
65
virtual ~BlackholeEngine()
67
pthread_mutex_destroy(&blackhole_mutex);
63
70
virtual Cursor *create(TableShare &table,
64
71
drizzled::memory::Root *mem_root)
70
77
return ha_blackhole_exts;
73
int doCreateTable(Session*,
80
int doCreateTable(Session&,
82
drizzled::TableIdentifier &identifier,
76
83
drizzled::message::Table&);
78
int doDropTable(Session&, const string &table_name);
85
int doDropTable(Session&, TableIdentifier &identifier);
80
87
BlackholeShare *findOpenTable(const string table_name);
81
88
void addOpenTable(const string &table_name, BlackholeShare *);
82
89
void deleteOpenTable(const string &table_name);
84
91
int doGetTableDefinition(Session& session,
87
const char *table_name,
89
drizzled::message::Table *table_proto);
92
TableIdentifier &identifier,
93
drizzled::message::Table &table_message);
91
95
void doGetTableNames(drizzled::CachedDirectory &directory,
92
string&, set<string>& set_of_names)
97
set<string>& set_of_names)
94
99
drizzled::CachedDirectory::Entries entries= directory.getEntries();
133
138
HA_KEYREAD_ONLY);
141
bool doDoesTableExist(Session& session, TableIdentifier &identifier);
142
int doRenameTable(Session&, TableIdentifier &from, TableIdentifier &to);
143
void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
144
drizzled::SchemaIdentifier &schema_identifier,
145
drizzled::TableIdentifiers &set_of_identifiers);
149
void BlackholeEngine::doGetTableIdentifiers(drizzled::CachedDirectory &directory,
150
drizzled::SchemaIdentifier &schema_identifier,
151
drizzled::TableIdentifiers &set_of_identifiers)
153
drizzled::CachedDirectory::Entries entries= directory.getEntries();
155
for (drizzled::CachedDirectory::Entries::iterator entry_iter= entries.begin();
156
entry_iter != entries.end(); ++entry_iter)
158
drizzled::CachedDirectory::Entry *entry= *entry_iter;
159
const string *filename= &entry->filename;
161
assert(filename->size());
163
const char *ext= strchr(filename->c_str(), '.');
165
if (ext == NULL || my_strcasecmp(system_charset_info, ext, BLACKHOLE_EXT) ||
166
(filename->compare(0, strlen(TMP_FILE_PREFIX), TMP_FILE_PREFIX) == 0))
170
char uname[NAME_LEN + 1];
171
uint32_t file_name_len;
173
file_name_len= filename_to_tablename(filename->c_str(), uname, sizeof(uname));
174
// TODO: Remove need for memory copy here
175
uname[file_name_len - sizeof(BLACKHOLE_EXT) + 1]= '\0'; // Subtract ending, place NULL
177
set_of_identifiers.push_back(TableIdentifier(schema_identifier, uname));
182
int BlackholeEngine::doRenameTable(Session&, TableIdentifier &from, TableIdentifier &to)
186
for (const char **ext= bas_ext(); *ext ; ext++)
188
if (rename_file_ext(from.getPath().c_str(), to.getPath().c_str(), *ext))
190
if ((error=errno) != ENOENT)
139
198
BlackholeShare *BlackholeEngine::findOpenTable(const string table_name)
141
200
BlackholeMap::iterator find_iter=
190
int BlackholeEngine::doCreateTable(Session*, const char *path,
245
int BlackholeEngine::doCreateTable(Session&,
247
drizzled::TableIdentifier &identifier,
192
248
drizzled::message::Table& proto)
194
250
string serialized_proto;
253
new_path= identifier.getPath();
198
254
new_path+= BLACKHOLE_EXT;
199
255
fstream output(new_path.c_str(), ios::out | ios::binary);
216
int BlackholeEngine::doDropTable(Session&, const string &path)
272
int BlackholeEngine::doDropTable(Session&,
273
TableIdentifier &identifier)
218
string new_path(path);
275
string new_path(identifier.getPath());
220
277
new_path+= BLACKHOLE_EXT;
290
bool BlackholeEngine::doDoesTableExist(Session&,
291
TableIdentifier &identifier)
293
string proto_path(identifier.getPath());
294
proto_path.append(BLACKHOLE_EXT);
296
if (access(proto_path.c_str(), F_OK))
233
305
int BlackholeEngine::doGetTableDefinition(Session&,
238
drizzled::message::Table *table_proto)
306
TableIdentifier &identifier,
307
drizzled::message::Table &table_proto)
311
new_path= identifier.getPath();
243
312
new_path+= BLACKHOLE_EXT;
245
314
int fd= open(new_path.c_str(), O_RDONLY);
252
321
google::protobuf::io::ZeroCopyInputStream* input=
253
322
new google::protobuf::io::FileInputStream(fd);
256
325
return HA_ERR_CRASHED_ON_USAGE;
258
if (table_proto && ! table_proto->ParseFromZeroCopyStream(input))
327
if (not table_proto.ParseFromZeroCopyStream(input))
262
if (! table_proto->IsInitialized())
331
if (not table_proto.IsInitialized())
264
333
my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
265
table_proto->InitializationErrorString().c_str());
334
table_proto.InitializationErrorString().c_str());
266
335
return ER_CORRUPT_TABLE_DEFINITION;
413
483
static drizzled::plugin::StorageEngine *blackhole_engine= NULL;
415
static int blackhole_init(drizzled::plugin::Registry ®istry)
485
static int blackhole_init(drizzled::plugin::Context &context)
418
488
blackhole_engine= new BlackholeEngine("BLACKHOLE");
419
registry.add(blackhole_engine);
489
context.add(blackhole_engine);
421
491
pthread_mutex_init(&blackhole_mutex, MY_MUTEX_INIT_FAST);
426
static int blackhole_fini(drizzled::plugin::Registry ®istry)
428
registry.remove(blackhole_engine);
429
delete blackhole_engine;
431
pthread_mutex_destroy(&blackhole_mutex);
436
497
DRIZZLE_DECLARE_PLUGIN
442
503
"/dev/null storage engine (anything you write to it disappears)",
443
504
PLUGIN_LICENSE_GPL,
444
505
blackhole_init, /* Plugin Init */
445
blackhole_fini, /* Plugin Deinit */
446
506
NULL, /* system variables */
447
507
NULL /* config options */