~drizzle-trunk/drizzle/development

575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19
968.2.29 by Monty Taylor
First steps towards new plugin reg.
20
#ifndef DRIZZLED_PLUGIN_STORAGE_ENGINE_H
21
#define DRIZZLED_PLUGIN_STORAGE_ENGINE_H
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
22
575.4.7 by Monty Taylor
More header cleanup.
23
575.1.5 by Monty Taylor
Moved stuff to handlerton.cc
24
#include <drizzled/definitions.h>
25
#include <drizzled/sql_plugin.h>
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
26
960.2.40 by Monty Taylor
Made name private. Wow, we just don't use it for anything do we.
27
#include <bitset>
28
#include <string>
971.1.25 by Monty Taylor
Moved StorageEngine onto drizzled::Registry.
29
#include <vector>
960.2.40 by Monty Taylor
Made name private. Wow, we just don't use it for anything do we.
30
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
31
class TableList;
575.1.5 by Monty Taylor
Moved stuff to handlerton.cc
32
class Session;
33
class XID;
34
class handler;
35
796 by Brian Aker
Test case fixes + TABLE_CACHE to class (will rename in manner which is NOT
36
class TABLE_SHARE;
575.1.5 by Monty Taylor
Moved stuff to handlerton.cc
37
typedef struct st_mysql_lex_string LEX_STRING;
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
38
typedef bool (stat_print_fn)(Session *session, const char *type, uint32_t type_len,
39
                             const char *file, uint32_t file_len,
40
                             const char *status, uint32_t status_len);
41
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
42
960.2.24 by Monty Taylor
Changed handlerton to StorageEngine.
43
/* Possible flags of a StorageEngine (there can be 32 of them) */
960.2.27 by Monty Taylor
Reworked transformed handlerton into class StorageEngine.
44
enum engine_flag_bits {
631.1.2 by Yoshinori Sano
Move hton_flag_bits and HTON_* to handlerton.h. Remove TODOs previously added.
45
  HTON_BIT_CLOSE_CURSORS_AT_COMMIT,
46
  HTON_BIT_ALTER_NOT_SUPPORTED,       // Engine does not support alter
47
  HTON_BIT_CAN_RECREATE,              // Delete all is used for truncate
48
  HTON_BIT_HIDDEN,                    // Engine does not appear in lists
49
  HTON_BIT_FLUSH_AFTER_RENAME,
50
  HTON_BIT_NOT_USER_SELECTABLE,
51
  HTON_BIT_TEMPORARY_NOT_SUPPORTED,   // Having temporary tables not supported
52
  HTON_BIT_SUPPORT_LOG_TABLES,        // Engine supports log tables
53
  HTON_BIT_NO_PARTITION,              // You can not partition these tables
54
  HTON_BIT_SIZE
55
};
56
57
static const std::bitset<HTON_BIT_SIZE> HTON_NO_FLAGS(0);
58
static const std::bitset<HTON_BIT_SIZE> HTON_CLOSE_CURSORS_AT_COMMIT(1 <<  HTON_BIT_CLOSE_CURSORS_AT_COMMIT);
59
static const std::bitset<HTON_BIT_SIZE> HTON_ALTER_NOT_SUPPORTED(1 << HTON_BIT_ALTER_NOT_SUPPORTED);
60
static const std::bitset<HTON_BIT_SIZE> HTON_CAN_RECREATE(1 << HTON_BIT_CAN_RECREATE);
61
static const std::bitset<HTON_BIT_SIZE> HTON_HIDDEN(1 << HTON_BIT_HIDDEN);
62
static const std::bitset<HTON_BIT_SIZE> HTON_FLUSH_AFTER_RENAME(1 << HTON_BIT_FLUSH_AFTER_RENAME);
63
static const std::bitset<HTON_BIT_SIZE> HTON_NOT_USER_SELECTABLE(1 << HTON_BIT_NOT_USER_SELECTABLE);
64
static const std::bitset<HTON_BIT_SIZE> HTON_TEMPORARY_NOT_SUPPORTED(1 << HTON_BIT_TEMPORARY_NOT_SUPPORTED);
65
static const std::bitset<HTON_BIT_SIZE> HTON_SUPPORT_LOG_TABLES(1 << HTON_BIT_SUPPORT_LOG_TABLES);
66
static const std::bitset<HTON_BIT_SIZE> HTON_NO_PARTITION(1 << HTON_BIT_NO_PARTITION);
67
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
68
/*
960.2.24 by Monty Taylor
Changed handlerton to StorageEngine.
69
  StorageEngine is a singleton structure - one instance per storage engine -
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
70
  to provide access to storage engine functionality that works on the
71
  "global" level (unlike handler class that works on a per-table basis)
72
960.2.24 by Monty Taylor
Changed handlerton to StorageEngine.
73
  usually StorageEngine instance is defined statically in ha_xxx.cc as
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
74
960.2.25 by Monty Taylor
First step of hton rename.
75
  static StorageEngine { ... } xxx_engine;
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
76
77
  savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
78
*/
960.2.27 by Monty Taylor
Reworked transformed handlerton into class StorageEngine.
79
class StorageEngine
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
80
{
960.2.41 by Monty Taylor
Made StorageEngine name private. Added constructor param and accessor method.
81
  /*
82
    Name used for storage engine.
83
  */
84
  const std::string name;
964.1.5 by Monty Taylor
Removed license field from StorageEngine. It was not used. Also added a const specifier.
85
  const bool two_phase_commit;
964.1.3 by Monty Taylor
Refactored state into is_enabled() call.
86
  bool enabled;
964.1.5 by Monty Taylor
Removed license field from StorageEngine. It was not used. Also added a const specifier.
87
  const std::bitset<HTON_BIT_SIZE> flags; /* global handler flags */
964.1.6 by Monty Taylor
Moved savepoint stuff to protected virtual methods, moved the offset to private, and moved the logic about adding the offset to the passed-in pointer and adding the offset to the global offset inside of the class.
88
  /*
89
    to store per-savepoint data storage engine is provided with an area
90
    of a requested size (0 is ok here).
91
    savepoint_offset must be initialized statically to the size of
92
    the needed memory to store per-savepoint information.
93
    After xxx_init it is changed to be an offset to savepoint storage
94
    area and need not be used by storage engine.
95
    see binlog_engine and binlog_savepoint_set/rollback for an example.
96
  */
97
  size_t savepoint_offset;
98
  size_t orig_savepoint_offset;
971.1.25 by Monty Taylor
Moved StorageEngine onto drizzled::Registry.
99
  std::vector<std::string> aliases;
964.1.6 by Monty Taylor
Moved savepoint stuff to protected virtual methods, moved the offset to private, and moved the logic about adding the offset to the passed-in pointer and adding the offset to the global offset inside of the class.
100
101
protected:
102
103
  /**
104
   * Implementing classes should override these to provide savepoint
105
   * functionality.
106
   */
107
  virtual int savepoint_set_hook(Session *, void *) { return 0; }
108
109
  virtual int savepoint_rollback_hook(Session *, void *) { return 0; }
110
111
  virtual int savepoint_release_hook(Session *, void *) { return 0; }
960.2.41 by Monty Taylor
Made StorageEngine name private. Added constructor param and accessor method.
112
960.2.27 by Monty Taylor
Reworked transformed handlerton into class StorageEngine.
113
public:
960.2.40 by Monty Taylor
Made name private. Wow, we just don't use it for anything do we.
114
584.2.5 by Stewart Smith
store a protobuf tabledefinition along with FRM
115
  /*
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
116
    each storage engine has it's own memory area (actually a pointer)
117
    in the session, for storing per-connection information.
118
    It is accessed as
119
960.2.25 by Monty Taylor
First step of hton rename.
120
      session->ha_data[xxx_engine.slot]
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
121
122
   slot number is initialized by MySQL after xxx_init() is called.
964.1.2 by Monty Taylor
Removed extra space.
123
  */
124
  uint32_t slot;
964.1.4 by Monty Taylor
Moved flags into private area.
125
971.1.14 by Monty Taylor
Slurp around strings rather than char* for storage engine name.
126
  StorageEngine(const std::string name_arg,
964.1.6 by Monty Taylor
Moved savepoint stuff to protected virtual methods, moved the offset to private, and moved the logic about adding the offset to the passed-in pointer and adding the offset to the global offset inside of the class.
127
                const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS,
968.2.29 by Monty Taylor
First steps towards new plugin reg.
128
                size_t savepoint_offset_arg= 0,
964.1.6 by Monty Taylor
Moved savepoint stuff to protected virtual methods, moved the offset to private, and moved the logic about adding the offset to the passed-in pointer and adding the offset to the global offset inside of the class.
129
                bool support_2pc= false);
130
131
  virtual ~StorageEngine();
960.2.45 by Monty Taylor
How about let's initialize savepoint_offset.
132
971.1.25 by Monty Taylor
Moved StorageEngine onto drizzled::Registry.
133
  const std::vector<std::string>& getAliases()
134
  {
135
    return aliases;
136
  }
137
138
  void addAlias(std::string alias)
139
  {
140
    aliases.push_back(alias);
141
  }
142
960.2.45 by Monty Taylor
How about let's initialize savepoint_offset.
143
  bool has_2pc()
144
  {
964.1.1 by Monty Taylor
Renamed _2pc to two_phase_commit.
145
    return two_phase_commit;
960.2.45 by Monty Taylor
How about let's initialize savepoint_offset.
146
  }
147
148
964.1.2 by Monty Taylor
Removed extra space.
149
  bool is_enabled() const
150
  {
964.1.3 by Monty Taylor
Refactored state into is_enabled() call.
151
    return enabled;
964.1.2 by Monty Taylor
Removed extra space.
152
  }
153
964.1.4 by Monty Taylor
Moved flags into private area.
154
  bool is_user_selectable() const
155
  {
156
    return not flags.test(HTON_BIT_NOT_USER_SELECTABLE);
157
  }
158
159
  bool check_flag(const engine_flag_bits flag) const
160
  {
161
    return flags.test(flag);
162
  }
163
964.1.3 by Monty Taylor
Refactored state into is_enabled() call.
164
  void enable() { enabled= true; }
165
  void disable() { enabled= false; }
166
971.1.14 by Monty Taylor
Slurp around strings rather than char* for storage engine name.
167
  std::string getName() const { return name; }
964.1.2 by Monty Taylor
Removed extra space.
168
169
  /*
170
    StorageEngine methods:
171
172
    close_connection is only called if
173
    session->ha_data[xxx_engine.slot] is non-zero, so even if you don't need
174
    this storage area - set it to something, so that MySQL would know
175
    this storage engine was accessed in this connection
176
  */
177
  virtual int close_connection(Session  *)
178
  {
179
    return 0;
180
  }
181
  /*
182
    'all' is true if it's a real commit, that makes persistent changes
183
    'all' is false if it's not in fact a commit but an end of the
184
    statement that is part of the transaction.
185
    NOTE 'all' is also false in auto-commit mode where 'end of statement'
186
    and 'real commit' mean the same event.
187
  */
188
  virtual int  commit(Session *, bool)
189
  {
190
    return 0;
191
  }
192
193
  virtual int  rollback(Session *, bool)
194
  {
195
    return 0;
196
  }
197
964.1.6 by Monty Taylor
Moved savepoint stuff to protected virtual methods, moved the offset to private, and moved the logic about adding the offset to the passed-in pointer and adding the offset to the global offset inside of the class.
198
  /*
199
    The void * points to an uninitialized storage area of requested size
200
    (see savepoint_offset description)
201
  */
202
  int savepoint_set(Session *session, void *sp)
203
  {
204
    return savepoint_set_hook(session, (unsigned char *)sp+savepoint_offset);
205
  }
206
207
  /*
208
    The void * points to a storage area, that was earlier passed
209
    to the savepoint_set call
210
  */
211
  int savepoint_rollback(Session *session, void *sp)
212
  {
213
     return savepoint_rollback_hook(session,
214
                                    (unsigned char *)sp+savepoint_offset);
215
  }
216
217
  int savepoint_release(Session *session, void *sp)
218
  {
219
    return savepoint_release_hook(session,
220
                                  (unsigned char *)sp+savepoint_offset);
221
  }
222
964.1.2 by Monty Taylor
Removed extra space.
223
  virtual int  prepare(Session *, bool) { return 0; }
224
  virtual int  recover(XID *, uint32_t) { return 0; }
225
  virtual int  commit_by_xid(XID *) { return 0; }
226
  virtual int  rollback_by_xid(XID *) { return 0; }
227
  virtual handler *create(TABLE_SHARE *, MEM_ROOT *)= 0;
228
  /* args: path */
229
  virtual void drop_database(char*) { }
230
  virtual int start_consistent_snapshot(Session *) { return 0; }
231
  virtual bool flush_logs() { return false; }
232
  virtual bool show_status(Session *, stat_print_fn *, enum ha_stat_type)
233
  {
234
    return false;
235
  }
236
237
  /* args: current_session, tables, cond */
238
  virtual int fill_files_table(Session *, TableList *,
239
                               Item *) { return 0; }
240
  virtual int release_temporary_latches(Session *) { return false; }
241
242
  /* args: current_session, db, name */
243
  virtual int table_exists_in_engine(Session*, const char *, const char *);
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
244
};
245
575.1.5 by Monty Taylor
Moved stuff to handlerton.cc
246
/* lookups */
960.2.39 by Monty Taylor
Removed more handlerton naming references.
247
StorageEngine *ha_default_storage_engine(Session *session);
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
248
StorageEngine *ha_resolve_by_name(Session *session, const LEX_STRING *name);
575.1.5 by Monty Taylor
Moved stuff to handlerton.cc
249
handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc,
960.2.24 by Monty Taylor
Changed handlerton to StorageEngine.
250
                         StorageEngine *db_type);
971.1.14 by Monty Taylor
Slurp around strings rather than char* for storage engine name.
251
const std::string ha_resolve_storage_engine_name(const StorageEngine *db_type);
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
252
968.2.29 by Monty Taylor
First steps towards new plugin reg.
253
#endif /* DRIZZLED_PLUGIN_STORAGE_ENGINE_H */