~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.h

Added code necessary for building plugins dynamically.
Merged in changes from lifeless to allow autoreconf to work.
Touching plugin.ini files now triggers a rebuid - so config/autorun.sh is no
longer required to be run after touching those.
Removed the duplicate plugin names - also removed the issue that getting them
different would silently fail weirdly later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "drizzled/plugin/plugin.h"
29
29
#include <drizzled/name_map.h>
30
30
 
 
31
#include "mysys/cached_directory.h"
 
32
 
31
33
#include <bitset>
32
34
#include <string>
33
35
#include <vector>
54
56
  HTON_BIT_TEMPORARY_ONLY,
55
57
  HTON_BIT_FILE_BASED, // use for check_lowercase_names
56
58
  HTON_BIT_HAS_DATA_DICTIONARY,
 
59
  HTON_BIT_DOES_TRANSACTIONS,
57
60
  HTON_BIT_SIZE
58
61
};
59
62
 
67
70
static const std::bitset<HTON_BIT_SIZE> HTON_TEMPORARY_ONLY(1 << HTON_BIT_TEMPORARY_ONLY);
68
71
static const std::bitset<HTON_BIT_SIZE> HTON_FILE_BASED(1 << HTON_BIT_FILE_BASED);
69
72
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_DATA_DICTIONARY(1 << HTON_BIT_HAS_DATA_DICTIONARY);
 
73
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_DOES_TRANSACTIONS(1 << HTON_BIT_DOES_TRANSACTIONS);
70
74
 
71
75
class Table;
72
76
 
76
80
{
77
81
 
78
82
const std::string UNKNOWN_STRING("UNKNOWN");
 
83
const std::string DEFAULT_DEFINITION_FILE_EXT(".dfe");
 
84
const unsigned int MAX_STORAGE_ENGINE_FILE_EXT= 4;
 
85
    
79
86
 
80
 
class TableNameIteratorImplementation;
81
87
/*
82
88
  StorageEngine is a singleton structure - one instance per storage engine -
83
89
  to provide access to storage engine functionality that works on the
110
116
  size_t savepoint_offset;
111
117
  size_t orig_savepoint_offset;
112
118
 
113
 
  void setTransactionReadWrite(Session* session);
114
 
 
115
 
protected:
 
119
  void setTransactionReadWrite(Session& session);
 
120
 
 
121
protected:
 
122
  std::string table_definition_ext;
 
123
 
 
124
public:
 
125
  const std::string& getTableDefinitionExt()
 
126
  {
 
127
    return table_definition_ext;
 
128
  }
 
129
 
 
130
protected:
 
131
 
 
132
  /**
 
133
    @brief
 
134
    Used as a protobuf storage currently by TEMP only engines.
 
135
  */
 
136
  typedef std::map <std::string, drizzled::message::Table> ProtoCache;
 
137
  ProtoCache proto_cache;
 
138
  pthread_mutex_t proto_cache_mutex;
116
139
 
117
140
  /**
118
141
   * Implementing classes should override these to provide savepoint
133
156
 
134
157
  virtual ~StorageEngine();
135
158
 
136
 
  virtual int getTableProtoImplementation(const char* path,
137
 
                                          drizzled::message::Table *table_proto)
138
 
    {
139
 
      (void)path;
140
 
      (void)table_proto;
141
 
      return ENOENT;
142
 
    }
 
159
  virtual int doGetTableDefinition(Session& session,
 
160
                                   const char *path,
 
161
                                   const char *db,
 
162
                                   const char *table_name,
 
163
                                   const bool is_tmp,
 
164
                                   drizzled::message::Table *table_proto)
 
165
  {
 
166
    (void)session;
 
167
    (void)path;
 
168
    (void)db;
 
169
    (void)table_name;
 
170
    (void)is_tmp;
 
171
    (void)table_proto;
 
172
 
 
173
    return ENOENT;
 
174
  }
143
175
 
144
176
  /*
145
177
    each storage engine has it's own memory area (actually a pointer)
266
298
  virtual const char **bas_ext() const =0;
267
299
 
268
300
protected:
269
 
  virtual int createTableImplementation(Session *session,
270
 
                                        const char *table_name,
271
 
                                        Table *table_arg,
272
 
                                        HA_CREATE_INFO *create_info,
273
 
                                        drizzled::message::Table* proto)= 0;
274
 
 
275
 
  virtual int renameTableImplementation(Session* session,
276
 
                                        const char *from, const char *to);
277
 
 
278
 
  virtual int deleteTableImplementation(Session* session,
279
 
                                        const std::string table_path);
 
301
  virtual int doCreateTable(Session *session,
 
302
                            const char *table_name,
 
303
                            Table& table_arg,
 
304
                            HA_CREATE_INFO& create_info,
 
305
                            drizzled::message::Table& proto)= 0;
 
306
 
 
307
  virtual int doRenameTable(Session* session,
 
308
                            const char *from, const char *to);
 
309
 
280
310
 
281
311
public:
282
 
  int doCreateTable(Session *session, const char *path, 
283
 
                  Table *table_arg,
284
 
                  HA_CREATE_INFO *create_info,
285
 
                  drizzled::message::Table *proto) 
286
 
  {
287
 
    char name_buff[FN_REFLEN];
288
 
    const char *table_name;
289
 
 
290
 
    table_name= checkLowercaseNames(path, name_buff);
291
 
 
292
 
    setTransactionReadWrite(session);
293
 
 
294
 
    return createTableImplementation(session, table_name, table_arg,
295
 
                                     create_info, proto);
296
 
  }
297
312
 
298
313
  int renameTable(Session *session, const char *from, const char *to) 
299
314
  {
300
 
    setTransactionReadWrite(session);
301
 
 
302
 
    return renameTableImplementation(session, from, to);
303
 
  }
304
 
 
305
 
  int doDeleteTable(Session* session, const std::string table_path) 
306
 
  {
307
 
    setTransactionReadWrite(session);
308
 
 
309
 
    return deleteTableImplementation(session, table_path);
310
 
  }
 
315
    setTransactionReadWrite(*session);
 
316
 
 
317
    return doRenameTable(session, from, to);
 
318
  }
 
319
 
 
320
  // TODO: move these to protected
 
321
  virtual void doGetTableNames(CachedDirectory &directory, std::string& db_name, std::set<std::string>& set_of_names);
 
322
  virtual int doDropTable(Session& session,
 
323
                          const std::string table_path)= 0;
311
324
 
312
325
  const char *checkLowercaseNames(const char *path, char *tmp_path);
313
326
 
314
 
  virtual TableNameIteratorImplementation* tableNameIterator(const std::string &database)
315
 
  {
316
 
    (void)database;
317
 
    return NULL;
318
 
  }
319
 
 
320
 
 
321
327
  /* Class Methods for operating on plugin */
322
328
  static bool addPlugin(plugin::StorageEngine *engine);
323
329
  static void removePlugin(plugin::StorageEngine *engine);
324
330
 
325
 
  static int getTableProto(const char* path, message::Table *table_proto);
 
331
  static int getTableDefinition(Session& session,
 
332
                                const char* path, 
 
333
                                const char *db,
 
334
                                const char *table_name,
 
335
                                const bool is_tmp,
 
336
                                message::Table *table_proto= NULL);
326
337
 
327
 
  static plugin::StorageEngine *findByName(Session *session,
 
338
  static plugin::StorageEngine *findByName(std::string find_str);
 
339
  static plugin::StorageEngine *findByName(Session& session,
328
340
                                           std::string find_str);
329
341
  static void closeConnection(Session* session);
330
342
  static void dropDatabase(char* path);
333
345
  static bool flushLogs(plugin::StorageEngine *db_type);
334
346
  static int recover(HASH *commit_list);
335
347
  static int startConsistentSnapshot(Session *session);
336
 
  static int deleteTable(Session *session, const char *path, const char *db,
337
 
                         const char *alias, bool generate_warning);
 
348
  static int dropTable(Session& session, const char *path, const char *db,
 
349
                       const char *alias, bool generate_warning);
 
350
  static void getTableNames(std::string& db_name, std::set<std::string> &set_of_names);
 
351
 
338
352
  static inline const std::string &resolveName(const StorageEngine *engine)
339
353
  {
340
354
    return engine == NULL ? UNKNOWN_STRING : engine->getName();
341
355
  }
342
356
 
343
 
  /**
344
 
   * Return the default storage engine plugin::StorageEngine for thread
345
 
   *
346
 
   * defaultStorageEngine(session)
347
 
   * @param session         current thread
348
 
   *
349
 
   * @return
350
 
   *   pointer to plugin::StorageEngine
351
 
   */
352
 
  static StorageEngine *defaultStorageEngine(Session *session);
353
 
 
354
 
  static int createTable(Session *session, const char *path,
 
357
  static int createTable(Session& session, const char *path,
355
358
                         const char *db, const char *table_name,
356
 
                         HA_CREATE_INFO *create_info,
 
359
                         HA_CREATE_INFO& create_info,
357
360
                         bool update_create_info,
358
 
                         drizzled::message::Table *table_proto);
 
361
                         drizzled::message::Table& table_proto,
 
362
                         bool used= true);
359
363
 
360
364
  Cursor *getCursor(TableShare *share, MEM_ROOT *alloc);
361
365
};
362
366
 
363
 
class TableNameIteratorImplementation
364
 
{
365
 
protected:
366
 
  std::string db;
367
 
public:
368
 
  TableNameIteratorImplementation(const std::string &database) : db(database)
369
 
    {};
370
 
  virtual ~TableNameIteratorImplementation() {};
371
 
 
372
 
  virtual int next(std::string *name)= 0;
373
 
 
374
 
};
375
 
 
376
 
class TableNameIterator
377
 
{
378
 
private:
379
 
  NameMap<plugin::StorageEngine *>::iterator engine_iter;
380
 
  plugin::TableNameIteratorImplementation *current_implementation;
381
 
  plugin::TableNameIteratorImplementation *default_implementation;
382
 
  std::string database;
383
 
public:
384
 
  TableNameIterator(const std::string &db);
385
 
  ~TableNameIterator();
386
 
 
387
 
  int next(std::string *name);
388
 
};
389
 
 
390
 
 
391
367
} /* namespace plugin */
392
368
} /* namespace drizzled */
393
369