~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.h

  • Committer: Mark Atwood
  • Date: 2010-06-24 03:15:21 UTC
  • mto: (1637.2.4 build)
  • mto: This revision was merged to the branch mainline in revision 1639.
  • Revision ID: me@mark.atwood.name-20100624031521-gafmppfbf5afm68w
new syslog module, with plugins for query log, error message, and SYSLOG() function

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