~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.h

  • Committer: patrick crews
  • Date: 2011-06-08 03:02:27 UTC
  • mto: This revision was merged to the branch mainline in revision 2329.
  • Revision ID: gleebix@gmail.com-20110608030227-updkyv2652zvfajc
Initial voodoo worked to give us a crashme mode.  Need docs still

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#ifndef DRIZZLED_PLUGIN_STORAGE_ENGINE_H
21
 
#define DRIZZLED_PLUGIN_STORAGE_ENGINE_H
22
 
 
 
20
#pragma once
23
21
 
24
22
#include <drizzled/definitions.h>
25
 
#include <drizzled/plugin.h>
 
23
#include <drizzled/error_t.h>
26
24
#include <drizzled/handler_structs.h>
27
25
#include <drizzled/message.h>
28
26
#include <drizzled/message/cache.h>
29
 
#include "drizzled/plugin/plugin.h"
30
 
#include "drizzled/sql_string.h"
31
 
#include "drizzled/identifier.h"
32
 
#include "drizzled/cached_directory.h"
33
 
#include "drizzled/plugin/monitored_in_transaction.h"
 
27
#include <drizzled/plugin.h>
 
28
#include <drizzled/plugin/monitored_in_transaction.h>
 
29
#include <drizzled/plugin/plugin.h>
 
30
#include <drizzled/sql_string.h>
34
31
 
35
32
#include <bitset>
36
33
#include <string>
37
34
#include <vector>
38
35
#include <set>
39
36
 
40
 
namespace drizzled
41
 
{
42
 
 
43
 
class TableList;
44
 
class Session;
45
 
class Cursor;
46
 
typedef struct st_hash HASH;
47
 
 
48
 
class TableShare;
49
 
typedef drizzle_lex_string LEX_STRING;
 
37
#include <drizzled/visibility.h>
 
38
 
 
39
namespace drizzled {
 
40
 
 
41
struct HASH;
 
42
 
50
43
typedef bool (stat_print_fn)(Session *session, const char *type, uint32_t type_len,
51
44
                             const char *file, uint32_t file_len,
52
45
                             const char *status, uint32_t status_len);
111
104
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_FOREIGN_KEYS(1 << HTON_BIT_FOREIGN_KEYS);
112
105
 
113
106
 
114
 
class Table;
115
 
class NamedSavepoint;
116
 
 
117
 
namespace plugin
118
 
{
 
107
namespace plugin {
119
108
 
120
109
typedef std::vector<StorageEngine *> EngineVector;
121
110
 
122
111
typedef std::set<std::string> TableNameList;
123
112
 
124
113
extern const std::string UNKNOWN_STRING;
125
 
extern const std::string DEFAULT_DEFINITION_FILE_EXT;
 
114
extern DRIZZLED_API const std::string DEFAULT_DEFINITION_FILE_EXT;
 
115
 
126
116
 
127
117
/*
128
118
  StorageEngine is a singleton structure - one instance per storage engine -
133
123
 
134
124
  static StorageEngine { ... } xxx_engine;
135
125
*/
136
 
class StorageEngine : public Plugin,
137
 
                      public MonitoredInTransaction
 
126
class DRIZZLED_API StorageEngine :
 
127
  public Plugin,
 
128
  public MonitoredInTransaction
138
129
{
 
130
  friend class SEAPITester;
139
131
public:
140
132
  typedef uint64_t Table_flags;
141
133
 
142
134
private:
 
135
  static EngineVector &getSchemaEngines();
143
136
  const std::bitset<HTON_BIT_SIZE> flags; /* global Cursor flags */
144
137
 
145
 
  static EngineVector &getSchemaEngines();
146
138
 
147
139
  virtual void setTransactionReadWrite(Session& session);
148
140
 
199
191
  pthread_mutex_t proto_cache_mutex;
200
192
 
201
193
public:
202
 
 
203
194
  StorageEngine(const std::string name_arg,
204
195
                const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS);
205
196
 
206
197
  virtual ~StorageEngine();
207
198
 
 
199
protected:
208
200
  virtual int doGetTableDefinition(Session &session,
209
 
                                   const drizzled::TableIdentifier &identifier,
 
201
                                   const drizzled::identifier::Table &identifier,
210
202
                                   message::Table &table_message)
211
203
  {
212
204
    (void)session;
217
209
  }
218
210
 
219
211
  /* Old style cursor errors */
220
 
protected:
221
 
  void print_keydup_error(uint32_t key_nr, const char *msg, Table &table);
222
 
  void print_error(int error, myf errflag, Table *table= NULL);
223
 
  virtual bool get_error_message(int error, String *buf);
 
212
  void print_keydup_error(uint32_t key_nr, const char *msg, const Table &table) const;
 
213
  virtual bool get_error_message(int error, String *buf) const;
 
214
 
224
215
public:
225
 
  virtual void print_error(int error, myf errflag, Table& table);
 
216
  virtual void print_error(int error, myf errflag, const Table& table) const;
226
217
 
227
218
  bool is_user_selectable() const
228
219
  {
252
243
  {
253
244
    return 0;
254
245
  }
 
246
 
255
247
  virtual Cursor *create(Table &)= 0;
256
248
  /* args: path */
257
249
  virtual bool flush_logs() { return false; }
276
268
protected:
277
269
  virtual int doCreateTable(Session &session,
278
270
                            Table &table_arg,
279
 
                            const drizzled::TableIdentifier &identifier,
280
 
                            message::Table &message)= 0;
 
271
                            const drizzled::identifier::Table &identifier,
 
272
                            const message::Table &message)= 0;
281
273
 
282
274
  virtual int doRenameTable(Session &session,
283
 
                            const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to)= 0;
284
 
 
285
 
public:
286
 
 
287
 
  int renameTable(Session &session, const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to);
 
275
                            const drizzled::identifier::Table &from, const drizzled::identifier::Table &to)= 0;
 
276
 
 
277
  virtual int doDropTable(Session &session,
 
278
                          const drizzled::identifier::Table &identifier)= 0;
288
279
 
289
280
  virtual void doGetTableIdentifiers(CachedDirectory &directory,
290
 
                                     const drizzled::SchemaIdentifier &schema_identifier,
291
 
                                     TableIdentifier::vector &set_of_identifiers)= 0;
292
 
 
293
 
  virtual int doDropTable(Session &session,
294
 
                          const drizzled::TableIdentifier &identifier)= 0;
 
281
                                     const drizzled::identifier::Schema &schema_identifier,
 
282
                                     identifier::table::vector &set_of_identifiers)= 0;
 
283
 
 
284
  virtual bool doDoesTableExist(Session& session, const drizzled::identifier::Table &identifier);
 
285
 
 
286
  virtual bool doCanCreateTable(const drizzled::identifier::Table &identifier)
 
287
  { (void)identifier;  return true; }
 
288
 
 
289
public:
 
290
 
 
291
  friend class AddSchemaNames;
 
292
  friend class AddTableIdentifier;
 
293
  friend class AlterSchema;
 
294
  friend class CanCreateTable;
 
295
  friend class CreateSchema;
 
296
  friend class DropSchema;
 
297
  friend class DropTable;
 
298
  friend class DropTables;
 
299
  friend class FindEngineByName;
 
300
  friend class Ha_delete_table_error_handler;
 
301
  friend class StorageEngineCloseConnection;
 
302
  friend class StorageEngineDoesTableExist;
 
303
  friend class StorageEngineGetSchemaDefinition;
 
304
  friend class StorageEngineGetTableDefinition;
 
305
  friend class DropTableByIdentifier;
 
306
 
 
307
  int renameTable(Session &session, const drizzled::identifier::Table &from, const drizzled::identifier::Table &to);
295
308
 
296
309
  /* Class Methods for operating on plugin */
297
310
  static bool addPlugin(plugin::StorageEngine *engine);
298
311
  static void removePlugin(plugin::StorageEngine *engine);
299
312
 
300
 
  static int getTableDefinition(Session& session,
301
 
                                const drizzled::TableIdentifier &identifier,
302
 
                                message::table::shared_ptr &table_proto,
303
 
                                bool include_temporary_tables= true);
 
313
  static message::table::shared_ptr getTableMessage(Session& session,
 
314
                                                    const drizzled::identifier::Table &identifier,
 
315
                                                    bool include_temporary_tables= true);
304
316
  static bool doesTableExist(Session &session,
305
 
                             const drizzled::TableIdentifier &identifier,
 
317
                             const drizzled::identifier::Table &identifier,
306
318
                             bool include_temporary_tables= true);
307
319
 
308
 
  virtual bool doDoesTableExist(Session& session, const drizzled::TableIdentifier &identifier);
309
 
 
310
320
  static plugin::StorageEngine *findByName(const std::string &find_str);
311
321
  static plugin::StorageEngine *findByName(Session& session, const std::string &find_str);
312
322
 
313
 
  static void closeConnection(Session* session);
 
323
  static void closeConnection(Session&);
314
324
  static void dropDatabase(char* path);
315
325
  static bool flushLogs(plugin::StorageEngine *db_type);
316
 
  static int dropTable(Session& session,
317
 
                       const drizzled::TableIdentifier &identifier);
318
 
  static int dropTable(Session& session,
319
 
                       StorageEngine &engine,
320
 
                       const drizzled::TableIdentifier &identifier);
 
326
 
 
327
  static bool dropTable(Session& session,
 
328
                        const drizzled::identifier::Table &identifier);
 
329
  static bool dropTable(Session& session,
 
330
                        const drizzled::identifier::Table &identifier,
 
331
                        drizzled::error_t &error);
 
332
 
 
333
  static bool dropTable(Session& session,
 
334
                        StorageEngine &engine,
 
335
                        const identifier::Table& identifier,
 
336
                        drizzled::error_t &error);
 
337
 
321
338
  static void getIdentifiers(Session &session,
322
 
                             const SchemaIdentifier &schema_identifier,
323
 
                             TableIdentifier::vector &set_of_identifiers);
 
339
                             const identifier::Schema &schema_identifier,
 
340
                             identifier::table::vector &set_of_identifiers);
324
341
 
325
342
  // Check to see if any SE objects to creation.
326
 
  static bool canCreateTable(const drizzled::TableIdentifier &identifier);
327
 
  virtual bool doCanCreateTable(const drizzled::TableIdentifier &identifier)
328
 
  { (void)identifier;  return true; }
 
343
  static bool canCreateTable(const drizzled::identifier::Table &identifier);
329
344
 
330
345
  // @note All schema methods defined here
331
 
  static void getIdentifiers(Session &session, SchemaIdentifier::vector &schemas);
332
 
  static bool getSchemaDefinition(const drizzled::TableIdentifier &identifier, message::schema::shared_ptr &proto);
333
 
  static bool getSchemaDefinition(const drizzled::SchemaIdentifier &identifier, message::schema::shared_ptr &proto);
334
 
  static bool doesSchemaExist(const drizzled::SchemaIdentifier &identifier);
335
 
  static const CHARSET_INFO *getSchemaCollation(const drizzled::SchemaIdentifier &identifier);
 
346
  static void getIdentifiers(Session &session, identifier::schema::vector &schemas);
 
347
  static message::schema::shared_ptr getSchemaDefinition(const drizzled::identifier::Table &identifier);
 
348
  static message::schema::shared_ptr getSchemaDefinition(const drizzled::identifier::Schema &identifier);
 
349
  static bool doesSchemaExist(const drizzled::identifier::Schema &identifier);
 
350
  static const charset_info_st *getSchemaCollation(const drizzled::identifier::Schema &identifier);
336
351
  static bool createSchema(const drizzled::message::Schema &schema_message);
337
 
  static bool dropSchema(const drizzled::SchemaIdentifier &identifier);
 
352
  static bool dropSchema(Session &session,
 
353
                         const identifier::Schema& identifier,
 
354
                         message::schema::const_reference schema_message);
338
355
  static bool alterSchema(const drizzled::message::Schema &schema_message);
339
356
 
340
357
  // @note make private/protected
341
 
  virtual void doGetSchemaIdentifiers(SchemaIdentifier::vector&)
 
358
protected:
 
359
  virtual void doGetSchemaIdentifiers(identifier::schema::vector&)
342
360
  { }
343
361
 
344
 
  virtual bool doGetSchemaDefinition(const drizzled::SchemaIdentifier&, drizzled::message::schema::shared_ptr&)
 
362
  virtual drizzled::message::schema::shared_ptr doGetSchemaDefinition(const drizzled::identifier::Schema&)
345
363
  { 
346
 
    return false; 
 
364
    return drizzled::message::schema::shared_ptr(); 
347
365
  }
348
366
 
349
367
  virtual bool doCreateSchema(const drizzled::message::Schema&)
352
370
  virtual bool doAlterSchema(const drizzled::message::Schema&)
353
371
  { return false; }
354
372
 
355
 
  virtual bool doDropSchema(const drizzled::SchemaIdentifier&)
 
373
  virtual bool doDropSchema(const drizzled::identifier::Schema&)
356
374
  { return false; }
357
375
 
 
376
public:
358
377
  static inline const std::string &resolveName(const StorageEngine *engine)
359
378
  {
360
379
    return engine == NULL ? UNKNOWN_STRING : engine->getName();
361
380
  }
362
381
 
363
 
  static int createTable(Session& session,
364
 
                         const drizzled::TableIdentifier &identifier,
365
 
                         message::Table& table_proto);
 
382
  static bool createTable(Session &session,
 
383
                          const identifier::Table &identifier,
 
384
                          message::Table& table_message);
366
385
 
367
386
  static void removeLostTemporaryTables(Session &session, const char *directory);
368
387
 
369
388
  Cursor *getCursor(Table &share);
370
389
 
371
390
  uint32_t max_record_length() const
372
 
  { return std::min((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
 
391
  { return std::min(HA_MAX_REC_LENGTH, max_supported_record_length()); }
373
392
  uint32_t max_keys() const
374
 
  { return std::min((unsigned int)MAX_KEY, max_supported_keys()); }
 
393
  { return std::min(MAX_KEY, max_supported_keys()); }
375
394
  uint32_t max_key_parts() const
376
 
  { return std::min((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
 
395
  { return std::min(MAX_REF_PARTS, max_supported_key_parts()); }
377
396
  uint32_t max_key_length() const
378
 
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
 
397
  { return std::min(MAX_KEY_LENGTH, max_supported_key_length()); }
379
398
  uint32_t max_key_part_length(void) const
380
 
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
 
399
  { return std::min(MAX_KEY_LENGTH, max_supported_key_part_length()); }
381
400
 
382
401
  virtual uint32_t max_supported_record_length(void) const
383
402
  { return HA_MAX_REC_LENGTH; }
387
406
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
388
407
 
389
408
  /* TODO-> Make private */
390
 
  static int deleteDefinitionFromPath(const drizzled::TableIdentifier &identifier);
391
 
  static int renameDefinitionFromPath(const drizzled::TableIdentifier &dest, const drizzled::TableIdentifier &src);
392
 
  static int writeDefinitionFromPath(const drizzled::TableIdentifier &identifier, message::Table &proto);
 
409
protected:
 
410
  static int deleteDefinitionFromPath(const drizzled::identifier::Table &identifier);
 
411
  static int renameDefinitionFromPath(const drizzled::identifier::Table &dest, const drizzled::identifier::Table &src);
 
412
  static int writeDefinitionFromPath(const drizzled::identifier::Table &identifier, const message::Table &proto);
393
413
  static bool readTableFile(const std::string &path, message::Table &table_message);
394
414
 
395
415
public:
427
447
  }
428
448
};
429
449
 
 
450
std::ostream& operator<<(std::ostream& output, const StorageEngine &engine);
 
451
 
430
452
} /* namespace plugin */
431
453
} /* namespace drizzled */
432
454
 
433
 
#endif /* DRIZZLED_PLUGIN_STORAGE_ENGINE_H */