~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.h

Merged in plugin-registration.  handlerton now == StorageEngine.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
                             const char *status, uint32_t status_len);
39
39
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
40
40
 
41
 
/* Possible flags of a handlerton (there can be 32 of them) */
42
 
enum hton_flag_bits {
 
41
/* Possible flags of a StorageEngine (there can be 32 of them) */
 
42
enum engine_flag_bits {
43
43
  HTON_BIT_CLOSE_CURSORS_AT_COMMIT,
44
44
  HTON_BIT_ALTER_NOT_SUPPORTED,       // Engine does not support alter
45
45
  HTON_BIT_CAN_RECREATE,              // Delete all is used for truncate
64
64
static const std::bitset<HTON_BIT_SIZE> HTON_NO_PARTITION(1 << HTON_BIT_NO_PARTITION);
65
65
 
66
66
/*
67
 
  handlerton is a singleton structure - one instance per storage engine -
 
67
  StorageEngine is a singleton structure - one instance per storage engine -
68
68
  to provide access to storage engine functionality that works on the
69
69
  "global" level (unlike handler class that works on a per-table basis)
70
70
 
71
 
  usually handlerton instance is defined statically in ha_xxx.cc as
 
71
  usually StorageEngine instance is defined statically in ha_xxx.cc as
72
72
 
73
 
  static handlerton { ... } xxx_hton;
 
73
  static StorageEngine { ... } xxx_engine;
74
74
 
75
75
  savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
76
76
*/
77
 
struct handlerton
 
77
class StorageEngine
78
78
{
 
79
  bool _2pc;
 
80
public:
 
81
  StorageEngine(): _2pc(false) {}
 
82
  StorageEngine(bool support_2pc): _2pc(support_2pc) {}
 
83
  virtual ~StorageEngine() {}
 
84
 
 
85
  bool has_2pc()
 
86
  {
 
87
    return _2pc;
 
88
  }
 
89
 
79
90
  /*
80
91
    Name used for storage engine.
 
92
    @todo change to std::string
81
93
  */
82
94
  const char *name;
83
95
 
96
108
    in the session, for storing per-connection information.
97
109
    It is accessed as
98
110
 
99
 
      session->ha_data[xxx_hton.slot]
 
111
      session->ha_data[xxx_engine.slot]
100
112
 
101
113
   slot number is initialized by MySQL after xxx_init() is called.
102
114
   */
103
115
   uint32_t slot;
 
116
   std::bitset<HTON_BIT_SIZE> flags; /* global handler flags */
104
117
   /*
105
118
     to store per-savepoint data storage engine is provided with an area
106
119
     of a requested size (0 is ok here).
108
121
     the needed memory to store per-savepoint information.
109
122
     After xxx_init it is changed to be an offset to savepoint storage
110
123
     area and need not be used by storage engine.
111
 
     see binlog_hton and binlog_savepoint_set/rollback for an example.
 
124
     see binlog_engine and binlog_savepoint_set/rollback for an example.
112
125
   */
113
126
   uint32_t savepoint_offset;
 
127
   uint32_t license; /* Flag for Engine License */
 
128
   void *data; /* Location for engines to keep personal structures */
 
129
 
114
130
   /*
115
 
     handlerton methods:
 
131
     StorageEngine methods:
116
132
 
117
133
     close_connection is only called if
118
 
     session->ha_data[xxx_hton.slot] is non-zero, so even if you don't need
 
134
     session->ha_data[xxx_engine.slot] is non-zero, so even if you don't need
119
135
     this storage area - set it to something, so that MySQL would know
120
136
     this storage engine was accessed in this connection
121
137
   */
122
 
   int  (*close_connection)(handlerton *hton, Session *session);
 
138
   virtual int close_connection(Session  *)
 
139
   {
 
140
     return 0;
 
141
   }
123
142
   /*
124
 
     sv points to an uninitialized storage area of requested size
 
143
     The void * points to an uninitialized storage area of requested size
125
144
     (see savepoint_offset description)
126
145
   */
127
 
   int  (*savepoint_set)(handlerton *hton, Session *session, void *sv);
 
146
   virtual int savepoint_set(Session *, void *)
 
147
   {
 
148
     return 0;
 
149
   }
 
150
 
128
151
   /*
129
 
     sv points to a storage area, that was earlier passed
 
152
     The void * points to a storage area, that was earlier passed
130
153
     to the savepoint_set call
131
154
   */
132
 
   int  (*savepoint_rollback)(handlerton *hton, Session *session, void *sv);
133
 
   int  (*savepoint_release)(handlerton *hton, Session *session, void *sv);
 
155
   virtual int savepoint_rollback(Session *, void *)
 
156
   {
 
157
     return 0;
 
158
   }
 
159
 
 
160
   virtual int savepoint_release(Session *, void *)
 
161
   {
 
162
     return 0;
 
163
   }
 
164
 
134
165
   /*
135
166
     'all' is true if it's a real commit, that makes persistent changes
136
167
     'all' is false if it's not in fact a commit but an end of the
138
169
     NOTE 'all' is also false in auto-commit mode where 'end of statement'
139
170
     and 'real commit' mean the same event.
140
171
   */
141
 
   int  (*commit)(handlerton *hton, Session *session, bool all);
142
 
   int  (*rollback)(handlerton *hton, Session *session, bool all);
143
 
   int  (*prepare)(handlerton *hton, Session *session, bool all);
144
 
   int  (*recover)(handlerton *hton, XID *xid_list, uint32_t len);
145
 
   int  (*commit_by_xid)(handlerton *hton, XID *xid);
146
 
   int  (*rollback_by_xid)(handlerton *hton, XID *xid);
147
 
   handler *(*create)(handlerton *hton, TABLE_SHARE *table, MEM_ROOT *mem_root);
148
 
   void (*drop_database)(handlerton *hton, char* path);
149
 
   int (*start_consistent_snapshot)(handlerton *hton, Session *session);
150
 
   bool (*flush_logs)(handlerton *hton);
151
 
   bool (*show_status)(handlerton *hton, Session *session, stat_print_fn *print, enum ha_stat_type stat);
152
 
   int (*fill_files_table)(handlerton *hton, Session *session,
153
 
                           TableList *tables,
154
 
                           class Item *cond);
155
 
   std::bitset<HTON_BIT_SIZE> flags; /* global handler flags */
156
 
   int (*release_temporary_latches)(handlerton *hton, Session *session);
157
 
 
158
 
   int (*table_exists_in_engine)(handlerton *hton, Session* session, const char *db,
159
 
                                 const char *name);
160
 
   uint32_t license; /* Flag for Engine License */
161
 
   void *data; /* Location for engines to keep personal structures */
 
172
   virtual int  commit(Session *, bool)
 
173
   {
 
174
     return 0;
 
175
   }
 
176
 
 
177
   virtual int  rollback(Session *, bool)
 
178
   {
 
179
     return 0;
 
180
   }
 
181
 
 
182
   virtual int  prepare(Session *, bool) { return 0; }
 
183
   virtual int  recover(XID *, uint32_t) { return 0; }
 
184
   virtual int  commit_by_xid(XID *) { return 0; }
 
185
   virtual int  rollback_by_xid(XID *) { return 0; }
 
186
   virtual handler *create(TABLE_SHARE *, MEM_ROOT *)= 0;
 
187
   /* args: path */
 
188
   virtual void drop_database(char*) { }
 
189
   virtual int start_consistent_snapshot(Session *) { return 0; }
 
190
   virtual bool flush_logs() { return false; }
 
191
   virtual bool show_status(Session *, stat_print_fn *, enum ha_stat_type)
 
192
   {
 
193
     return false;
 
194
   }
 
195
 
 
196
   /* args: current_session, tables, cond */
 
197
   virtual int fill_files_table(Session *, TableList *,
 
198
                                Item *) { return 0; }
 
199
   virtual int release_temporary_latches(Session *) { return false; }
 
200
 
 
201
   /* args: current_session, db, name */
 
202
   virtual int table_exists_in_engine(Session*, const char *, const char *);
162
203
};
163
204
 
164
205
 
165
206
/* lookups */
166
 
handlerton *ha_default_handlerton(Session *session);
 
207
StorageEngine *ha_default_storage_engine(Session *session);
167
208
plugin_ref ha_resolve_by_name(Session *session, const LEX_STRING *name);
168
 
plugin_ref ha_lock_engine(Session *session, handlerton *hton);
169
 
handlerton *ha_resolve_by_legacy_type(Session *session,
 
209
plugin_ref ha_lock_engine(Session *session, StorageEngine *engine);
 
210
StorageEngine *ha_resolve_by_legacy_type(Session *session,
170
211
                                      enum legacy_db_type db_type);
171
212
handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc,
172
 
                         handlerton *db_type);
173
 
handlerton *ha_checktype(Session *session, enum legacy_db_type database_type,
 
213
                         StorageEngine *db_type);
 
214
StorageEngine *ha_checktype(Session *session, enum legacy_db_type database_type,
174
215
                         bool no_substitute, bool report_error);
175
216
 
176
 
enum legacy_db_type ha_legacy_type(const handlerton *db_type);
177
 
const char *ha_resolve_storage_engine_name(const handlerton *db_type);
178
 
bool ha_check_storage_engine_flag(const handlerton *db_type, const hton_flag_bits flag);
179
 
bool ha_storage_engine_is_enabled(const handlerton *db_type);
180
 
LEX_STRING *ha_storage_engine_name(const handlerton *hton);
 
217
enum legacy_db_type ha_legacy_type(const StorageEngine *db_type);
 
218
const char *ha_resolve_storage_engine_name(const StorageEngine *db_type);
 
219
bool ha_check_storage_engine_flag(const StorageEngine *db_type, const engine_flag_bits flag);
 
220
bool ha_storage_engine_is_enabled(const StorageEngine *db_type);
 
221
LEX_STRING *ha_storage_engine_name(const StorageEngine *engine);
181
222
 
182
223
#endif /* DRIZZLED_HANDLERTON_H */