~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.h

Moved the last of the libdrizzleclient calls into Protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
20
#ifndef DRIZZLED_HANDLERTON_H
 
21
#define DRIZZLED_HANDLERTON_H
 
22
 
 
23
 
 
24
#include <drizzled/definitions.h>
 
25
#include <drizzled/sql_plugin.h>
 
26
 
 
27
#include <bitset>
 
28
#include <string>
 
29
 
 
30
class TableList;
 
31
class Session;
 
32
class XID;
 
33
class handler;
 
34
 
 
35
class TABLE_SHARE;
 
36
typedef struct st_mysql_lex_string LEX_STRING;
 
37
typedef bool (stat_print_fn)(Session *session, const char *type, uint32_t type_len,
 
38
                             const char *file, uint32_t file_len,
 
39
                             const char *status, uint32_t status_len);
 
40
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
 
41
 
 
42
/* Possible flags of a StorageEngine (there can be 32 of them) */
 
43
enum engine_flag_bits {
 
44
  HTON_BIT_CLOSE_CURSORS_AT_COMMIT,
 
45
  HTON_BIT_ALTER_NOT_SUPPORTED,       // Engine does not support alter
 
46
  HTON_BIT_CAN_RECREATE,              // Delete all is used for truncate
 
47
  HTON_BIT_HIDDEN,                    // Engine does not appear in lists
 
48
  HTON_BIT_FLUSH_AFTER_RENAME,
 
49
  HTON_BIT_NOT_USER_SELECTABLE,
 
50
  HTON_BIT_TEMPORARY_NOT_SUPPORTED,   // Having temporary tables not supported
 
51
  HTON_BIT_SUPPORT_LOG_TABLES,        // Engine supports log tables
 
52
  HTON_BIT_NO_PARTITION,              // You can not partition these tables
 
53
  HTON_BIT_SIZE
 
54
};
 
55
 
 
56
static const std::bitset<HTON_BIT_SIZE> HTON_NO_FLAGS(0);
 
57
static const std::bitset<HTON_BIT_SIZE> HTON_CLOSE_CURSORS_AT_COMMIT(1 <<  HTON_BIT_CLOSE_CURSORS_AT_COMMIT);
 
58
static const std::bitset<HTON_BIT_SIZE> HTON_ALTER_NOT_SUPPORTED(1 << HTON_BIT_ALTER_NOT_SUPPORTED);
 
59
static const std::bitset<HTON_BIT_SIZE> HTON_CAN_RECREATE(1 << HTON_BIT_CAN_RECREATE);
 
60
static const std::bitset<HTON_BIT_SIZE> HTON_HIDDEN(1 << HTON_BIT_HIDDEN);
 
61
static const std::bitset<HTON_BIT_SIZE> HTON_FLUSH_AFTER_RENAME(1 << HTON_BIT_FLUSH_AFTER_RENAME);
 
62
static const std::bitset<HTON_BIT_SIZE> HTON_NOT_USER_SELECTABLE(1 << HTON_BIT_NOT_USER_SELECTABLE);
 
63
static const std::bitset<HTON_BIT_SIZE> HTON_TEMPORARY_NOT_SUPPORTED(1 << HTON_BIT_TEMPORARY_NOT_SUPPORTED);
 
64
static const std::bitset<HTON_BIT_SIZE> HTON_SUPPORT_LOG_TABLES(1 << HTON_BIT_SUPPORT_LOG_TABLES);
 
65
static const std::bitset<HTON_BIT_SIZE> HTON_NO_PARTITION(1 << HTON_BIT_NO_PARTITION);
 
66
 
 
67
/*
 
68
  StorageEngine is a singleton structure - one instance per storage engine -
 
69
  to provide access to storage engine functionality that works on the
 
70
  "global" level (unlike handler class that works on a per-table basis)
 
71
 
 
72
  usually StorageEngine instance is defined statically in ha_xxx.cc as
 
73
 
 
74
  static StorageEngine { ... } xxx_engine;
 
75
 
 
76
  savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
 
77
*/
 
78
class StorageEngine
 
79
{
 
80
  /*
 
81
    Name used for storage engine.
 
82
  */
 
83
  const std::string name;
 
84
  const bool two_phase_commit;
 
85
  bool enabled;
 
86
  const std::bitset<HTON_BIT_SIZE> flags; /* global handler flags */
 
87
  /*
 
88
    to store per-savepoint data storage engine is provided with an area
 
89
    of a requested size (0 is ok here).
 
90
    savepoint_offset must be initialized statically to the size of
 
91
    the needed memory to store per-savepoint information.
 
92
    After xxx_init it is changed to be an offset to savepoint storage
 
93
    area and need not be used by storage engine.
 
94
    see binlog_engine and binlog_savepoint_set/rollback for an example.
 
95
  */
 
96
  size_t savepoint_offset;
 
97
  size_t orig_savepoint_offset;
 
98
 
 
99
protected:
 
100
 
 
101
  /**
 
102
   * Implementing classes should override these to provide savepoint
 
103
   * functionality.
 
104
   */
 
105
  virtual int savepoint_set_hook(Session *, void *) { return 0; }
 
106
 
 
107
  virtual int savepoint_rollback_hook(Session *, void *) { return 0; }
 
108
 
 
109
  virtual int savepoint_release_hook(Session *, void *) { return 0; }
 
110
 
 
111
public:
 
112
 
 
113
  /*
 
114
    each storage engine has it's own memory area (actually a pointer)
 
115
    in the session, for storing per-connection information.
 
116
    It is accessed as
 
117
 
 
118
      session->ha_data[xxx_engine.slot]
 
119
 
 
120
   slot number is initialized by MySQL after xxx_init() is called.
 
121
  */
 
122
  uint32_t slot;
 
123
 
 
124
  StorageEngine(const std::string &name_arg,
 
125
                const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS,
 
126
                size_t savepoint_offset_arg= 0,                         
 
127
                bool support_2pc= false);
 
128
 
 
129
  virtual ~StorageEngine();
 
130
 
 
131
  bool has_2pc()
 
132
  {
 
133
    return two_phase_commit;
 
134
  }
 
135
 
 
136
 
 
137
  bool is_enabled() const
 
138
  {
 
139
    return enabled;
 
140
  }
 
141
 
 
142
  bool is_user_selectable() const
 
143
  {
 
144
    return not flags.test(HTON_BIT_NOT_USER_SELECTABLE);
 
145
  }
 
146
 
 
147
  bool check_flag(const engine_flag_bits flag) const
 
148
  {
 
149
    return flags.test(flag);
 
150
  }
 
151
 
 
152
  void enable() { enabled= true; }
 
153
  void disable() { enabled= false; }
 
154
 
 
155
  std::string get_name() { return name; }
 
156
 
 
157
  /*
 
158
    StorageEngine methods:
 
159
 
 
160
    close_connection is only called if
 
161
    session->ha_data[xxx_engine.slot] is non-zero, so even if you don't need
 
162
    this storage area - set it to something, so that MySQL would know
 
163
    this storage engine was accessed in this connection
 
164
  */
 
165
  virtual int close_connection(Session  *)
 
166
  {
 
167
    return 0;
 
168
  }
 
169
  /*
 
170
    'all' is true if it's a real commit, that makes persistent changes
 
171
    'all' is false if it's not in fact a commit but an end of the
 
172
    statement that is part of the transaction.
 
173
    NOTE 'all' is also false in auto-commit mode where 'end of statement'
 
174
    and 'real commit' mean the same event.
 
175
  */
 
176
  virtual int  commit(Session *, bool)
 
177
  {
 
178
    return 0;
 
179
  }
 
180
 
 
181
  virtual int  rollback(Session *, bool)
 
182
  {
 
183
    return 0;
 
184
  }
 
185
 
 
186
  /*
 
187
    The void * points to an uninitialized storage area of requested size
 
188
    (see savepoint_offset description)
 
189
  */
 
190
  int savepoint_set(Session *session, void *sp)
 
191
  {
 
192
    return savepoint_set_hook(session, (unsigned char *)sp+savepoint_offset);
 
193
  }
 
194
 
 
195
  /*
 
196
    The void * points to a storage area, that was earlier passed
 
197
    to the savepoint_set call
 
198
  */
 
199
  int savepoint_rollback(Session *session, void *sp)
 
200
  {
 
201
     return savepoint_rollback_hook(session,
 
202
                                    (unsigned char *)sp+savepoint_offset);
 
203
  }
 
204
 
 
205
  int savepoint_release(Session *session, void *sp)
 
206
  {
 
207
    return savepoint_release_hook(session,
 
208
                                  (unsigned char *)sp+savepoint_offset);
 
209
  }
 
210
 
 
211
  virtual int  prepare(Session *, bool) { return 0; }
 
212
  virtual int  recover(XID *, uint32_t) { return 0; }
 
213
  virtual int  commit_by_xid(XID *) { return 0; }
 
214
  virtual int  rollback_by_xid(XID *) { return 0; }
 
215
  virtual handler *create(TABLE_SHARE *, MEM_ROOT *)= 0;
 
216
  /* args: path */
 
217
  virtual void drop_database(char*) { }
 
218
  virtual int start_consistent_snapshot(Session *) { return 0; }
 
219
  virtual bool flush_logs() { return false; }
 
220
  virtual bool show_status(Session *, stat_print_fn *, enum ha_stat_type)
 
221
  {
 
222
    return false;
 
223
  }
 
224
 
 
225
  /* args: current_session, tables, cond */
 
226
  virtual int fill_files_table(Session *, TableList *,
 
227
                               Item *) { return 0; }
 
228
  virtual int release_temporary_latches(Session *) { return false; }
 
229
 
 
230
  /* args: current_session, db, name */
 
231
  virtual int table_exists_in_engine(Session*, const char *, const char *);
 
232
};
 
233
 
 
234
/* lookups */
 
235
StorageEngine *ha_default_storage_engine(Session *session);
 
236
plugin_ref ha_resolve_by_name(Session *session, const LEX_STRING *name);
 
237
plugin_ref ha_lock_engine(Session *session, StorageEngine *engine);
 
238
handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc,
 
239
                         StorageEngine *db_type);
 
240
const char *ha_resolve_storage_engine_name(const StorageEngine *db_type);
 
241
LEX_STRING *ha_storage_engine_name(const StorageEngine *engine);
 
242
 
 
243
#endif /* DRIZZLED_HANDLERTON_H */