~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.h

  • Committer: Lee Bieber
  • Date: 2011-03-13 16:37:38 UTC
  • mfrom: (2227.4.18 session2)
  • Revision ID: kalebral@gmail.com-20110313163738-7ti21zk40o2xi3ew
Merge Olaf - Refactor Session

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
21
21
#define DRIZZLED_PLUGIN_STORAGE_ENGINE_H
22
22
 
23
23
 
 
24
#include <drizzled/cached_directory.h>
24
25
#include <drizzled/definitions.h>
25
 
#include <drizzled/plugin.h>
 
26
#include <drizzled/error_t.h>
26
27
#include <drizzled/handler_structs.h>
 
28
#include <drizzled/identifier.h>
27
29
#include <drizzled/message.h>
28
30
#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"
 
31
#include <drizzled/plugin.h>
 
32
#include <drizzled/plugin/monitored_in_transaction.h>
 
33
#include <drizzled/plugin/plugin.h>
 
34
#include <drizzled/sql_string.h>
34
35
 
35
36
#include <bitset>
36
37
#include <string>
37
38
#include <vector>
38
39
#include <set>
39
40
 
 
41
#include <drizzled/visibility.h>
 
42
 
40
43
namespace drizzled
41
44
{
42
45
 
43
46
class TableList;
44
47
class Session;
45
48
class Cursor;
46
 
typedef struct st_hash HASH;
 
49
struct HASH;
47
50
 
48
51
class TableShare;
49
 
typedef drizzle_lex_string LEX_STRING;
50
52
typedef bool (stat_print_fn)(Session *session, const char *type, uint32_t type_len,
51
53
                             const char *file, uint32_t file_len,
52
54
                             const char *status, uint32_t status_len);
122
124
typedef std::set<std::string> TableNameList;
123
125
 
124
126
extern const std::string UNKNOWN_STRING;
125
 
extern const std::string DEFAULT_DEFINITION_FILE_EXT;
 
127
extern DRIZZLED_API const std::string DEFAULT_DEFINITION_FILE_EXT;
 
128
 
126
129
 
127
130
/*
128
131
  StorageEngine is a singleton structure - one instance per storage engine -
133
136
 
134
137
  static StorageEngine { ... } xxx_engine;
135
138
*/
136
 
class StorageEngine : public Plugin,
137
 
                      public MonitoredInTransaction
 
139
class DRIZZLED_API StorageEngine :
 
140
  public Plugin,
 
141
  public MonitoredInTransaction
138
142
{
 
143
  friend class SEAPITester;
139
144
public:
140
145
  typedef uint64_t Table_flags;
141
146
 
142
147
private:
 
148
  static EngineVector &getSchemaEngines();
143
149
  const std::bitset<HTON_BIT_SIZE> flags; /* global Cursor flags */
144
150
 
145
 
  static EngineVector &getSchemaEngines();
146
151
 
147
152
  virtual void setTransactionReadWrite(Session& session);
148
153
 
199
204
  pthread_mutex_t proto_cache_mutex;
200
205
 
201
206
public:
202
 
 
203
207
  StorageEngine(const std::string name_arg,
204
208
                const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS);
205
209
 
206
210
  virtual ~StorageEngine();
207
211
 
 
212
protected:
208
213
  virtual int doGetTableDefinition(Session &session,
209
 
                                   const drizzled::TableIdentifier &identifier,
 
214
                                   const drizzled::identifier::Table &identifier,
210
215
                                   message::Table &table_message)
211
216
  {
212
217
    (void)session;
217
222
  }
218
223
 
219
224
  /* 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);
 
225
  void print_keydup_error(uint32_t key_nr, const char *msg, const Table &table) const;
 
226
  virtual bool get_error_message(int error, String *buf) const;
 
227
 
224
228
public:
225
 
  virtual void print_error(int error, myf errflag, Table& table);
 
229
  virtual void print_error(int error, myf errflag, const Table& table) const;
226
230
 
227
231
  bool is_user_selectable() const
228
232
  {
252
256
  {
253
257
    return 0;
254
258
  }
 
259
 
255
260
  virtual Cursor *create(Table &)= 0;
256
261
  /* args: path */
257
262
  virtual bool flush_logs() { return false; }
276
281
protected:
277
282
  virtual int doCreateTable(Session &session,
278
283
                            Table &table_arg,
279
 
                            const drizzled::TableIdentifier &identifier,
280
 
                            message::Table &message)= 0;
 
284
                            const drizzled::identifier::Table &identifier,
 
285
                            const message::Table &message)= 0;
281
286
 
282
287
  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);
 
288
                            const drizzled::identifier::Table &from, const drizzled::identifier::Table &to)= 0;
 
289
 
 
290
  virtual int doDropTable(Session &session,
 
291
                          const drizzled::identifier::Table &identifier)= 0;
288
292
 
289
293
  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;
 
294
                                     const drizzled::identifier::Schema &schema_identifier,
 
295
                                     identifier::Table::vector &set_of_identifiers)= 0;
 
296
 
 
297
  virtual bool doDoesTableExist(Session& session, const drizzled::identifier::Table &identifier);
 
298
 
 
299
  virtual bool doCanCreateTable(const drizzled::identifier::Table &identifier)
 
300
  { (void)identifier;  return true; }
 
301
 
 
302
public:
 
303
 
 
304
  friend class AddSchemaNames;
 
305
  friend class AddTableIdentifier;
 
306
  friend class AlterSchema;
 
307
  friend class CanCreateTable;
 
308
  friend class CreateSchema;
 
309
  friend class DropSchema;
 
310
  friend class DropTable;
 
311
  friend class DropTables;
 
312
  friend class FindEngineByName;
 
313
  friend class Ha_delete_table_error_handler;
 
314
  friend class StorageEngineCloseConnection;
 
315
  friend class StorageEngineDoesTableExist;
 
316
  friend class StorageEngineGetSchemaDefinition;
 
317
  friend class StorageEngineGetTableDefinition;
 
318
  friend class DropTableByIdentifier;
 
319
 
 
320
  int renameTable(Session &session, const drizzled::identifier::Table &from, const drizzled::identifier::Table &to);
295
321
 
296
322
  /* Class Methods for operating on plugin */
297
323
  static bool addPlugin(plugin::StorageEngine *engine);
298
324
  static void removePlugin(plugin::StorageEngine *engine);
299
325
 
300
 
  static int getTableDefinition(Session& session,
301
 
                                const drizzled::TableIdentifier &identifier,
302
 
                                message::table::shared_ptr &table_proto,
303
 
                                bool include_temporary_tables= true);
 
326
  static message::table::shared_ptr getTableMessage(Session& session,
 
327
                                                    const drizzled::identifier::Table &identifier,
 
328
                                                    bool include_temporary_tables= true);
304
329
  static bool doesTableExist(Session &session,
305
 
                             const drizzled::TableIdentifier &identifier,
 
330
                             const drizzled::identifier::Table &identifier,
306
331
                             bool include_temporary_tables= true);
307
332
 
308
 
  virtual bool doDoesTableExist(Session& session, const drizzled::TableIdentifier &identifier);
309
 
 
310
333
  static plugin::StorageEngine *findByName(const std::string &find_str);
311
334
  static plugin::StorageEngine *findByName(Session& session, const std::string &find_str);
312
335
 
313
336
  static void closeConnection(Session* session);
314
337
  static void dropDatabase(char* path);
315
338
  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);
 
339
 
 
340
  static bool dropTable(Session& session,
 
341
                        const drizzled::identifier::Table &identifier);
 
342
  static bool dropTable(Session& session,
 
343
                        const drizzled::identifier::Table &identifier,
 
344
                        drizzled::error_t &error);
 
345
 
 
346
  static bool dropTable(Session& session,
 
347
                        StorageEngine &engine,
 
348
                        identifier::Table::const_reference identifier,
 
349
                        drizzled::error_t &error);
 
350
 
321
351
  static void getIdentifiers(Session &session,
322
 
                             const SchemaIdentifier &schema_identifier,
323
 
                             TableIdentifier::vector &set_of_identifiers);
 
352
                             const identifier::Schema &schema_identifier,
 
353
                             identifier::Table::vector &set_of_identifiers);
324
354
 
325
355
  // 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; }
 
356
  static bool canCreateTable(const drizzled::identifier::Table &identifier);
329
357
 
330
358
  // @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);
 
359
  static void getIdentifiers(Session &session, identifier::Schema::vector &schemas);
 
360
  static message::schema::shared_ptr getSchemaDefinition(const drizzled::identifier::Table &identifier);
 
361
  static message::schema::shared_ptr getSchemaDefinition(const drizzled::identifier::Schema &identifier);
 
362
  static bool doesSchemaExist(const drizzled::identifier::Schema &identifier);
 
363
  static const CHARSET_INFO *getSchemaCollation(const drizzled::identifier::Schema &identifier);
336
364
  static bool createSchema(const drizzled::message::Schema &schema_message);
337
 
  static bool dropSchema(const drizzled::SchemaIdentifier &identifier);
 
365
  static bool dropSchema(Session &session,
 
366
                         identifier::Schema::const_reference identifier,
 
367
                         message::schema::const_reference schema_message);
338
368
  static bool alterSchema(const drizzled::message::Schema &schema_message);
339
369
 
340
370
  // @note make private/protected
341
 
  virtual void doGetSchemaIdentifiers(SchemaIdentifier::vector&)
 
371
protected:
 
372
  virtual void doGetSchemaIdentifiers(identifier::Schema::vector&)
342
373
  { }
343
374
 
344
 
  virtual bool doGetSchemaDefinition(const drizzled::SchemaIdentifier&, drizzled::message::schema::shared_ptr&)
 
375
  virtual drizzled::message::schema::shared_ptr doGetSchemaDefinition(const drizzled::identifier::Schema&)
345
376
  { 
346
 
    return false; 
 
377
    return drizzled::message::schema::shared_ptr(); 
347
378
  }
348
379
 
349
380
  virtual bool doCreateSchema(const drizzled::message::Schema&)
352
383
  virtual bool doAlterSchema(const drizzled::message::Schema&)
353
384
  { return false; }
354
385
 
355
 
  virtual bool doDropSchema(const drizzled::SchemaIdentifier&)
 
386
  virtual bool doDropSchema(const drizzled::identifier::Schema&)
356
387
  { return false; }
357
388
 
 
389
public:
358
390
  static inline const std::string &resolveName(const StorageEngine *engine)
359
391
  {
360
392
    return engine == NULL ? UNKNOWN_STRING : engine->getName();
361
393
  }
362
394
 
363
 
  static int createTable(Session& session,
364
 
                         const drizzled::TableIdentifier &identifier,
365
 
                         message::Table& table_proto);
 
395
  static bool createTable(Session &session,
 
396
                          const identifier::Table &identifier,
 
397
                          message::Table& table_message);
366
398
 
367
399
  static void removeLostTemporaryTables(Session &session, const char *directory);
368
400
 
369
401
  Cursor *getCursor(Table &share);
370
402
 
371
403
  uint32_t max_record_length() const
372
 
  { return std::min((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
 
404
  { return std::min(HA_MAX_REC_LENGTH, max_supported_record_length()); }
373
405
  uint32_t max_keys() const
374
 
  { return std::min((unsigned int)MAX_KEY, max_supported_keys()); }
 
406
  { return std::min(MAX_KEY, max_supported_keys()); }
375
407
  uint32_t max_key_parts() const
376
 
  { return std::min((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
 
408
  { return std::min(MAX_REF_PARTS, max_supported_key_parts()); }
377
409
  uint32_t max_key_length() const
378
 
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
 
410
  { return std::min(MAX_KEY_LENGTH, max_supported_key_length()); }
379
411
  uint32_t max_key_part_length(void) const
380
 
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
 
412
  { return std::min(MAX_KEY_LENGTH, max_supported_key_part_length()); }
381
413
 
382
414
  virtual uint32_t max_supported_record_length(void) const
383
415
  { return HA_MAX_REC_LENGTH; }
387
419
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
388
420
 
389
421
  /* 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);
 
422
protected:
 
423
  static int deleteDefinitionFromPath(const drizzled::identifier::Table &identifier);
 
424
  static int renameDefinitionFromPath(const drizzled::identifier::Table &dest, const drizzled::identifier::Table &src);
 
425
  static int writeDefinitionFromPath(const drizzled::identifier::Table &identifier, const message::Table &proto);
393
426
  static bool readTableFile(const std::string &path, message::Table &table_message);
394
427
 
395
428
public:
427
460
  }
428
461
};
429
462
 
 
463
std::ostream& operator<<(std::ostream& output, const StorageEngine &engine);
 
464
 
430
465
} /* namespace plugin */
431
466
} /* namespace drizzled */
432
467