~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.h

  • Committer: Brian Aker
  • Date: 2009-04-01 01:25:04 UTC
  • mfrom: (968.2.27 mordred)
  • Revision ID: brian@tangent.org-20090401012504-mq9sxcmph5jc1fh6
Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
    Name used for storage engine.
82
82
  */
83
83
  const std::string name;
84
 
  bool _2pc;
 
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; }
85
110
 
86
111
public:
87
112
 
88
113
  /*
89
 
    Historical marker for if the engine is available of not
90
 
  */
91
 
  SHOW_COMP_OPTION state;
92
 
 
93
 
  /*
94
114
    each storage engine has it's own memory area (actually a pointer)
95
115
    in the session, for storing per-connection information.
96
116
    It is accessed as
98
118
      session->ha_data[xxx_engine.slot]
99
119
 
100
120
   slot number is initialized by MySQL after xxx_init() is called.
101
 
   */
102
 
   uint32_t slot;
103
 
   std::bitset<HTON_BIT_SIZE> flags; /* global handler flags */
104
 
   /*
105
 
     to store per-savepoint data storage engine is provided with an area
106
 
     of a requested size (0 is ok here).
107
 
     savepoint_offset must be initialized statically to the size of
108
 
     the needed memory to store per-savepoint information.
109
 
     After xxx_init it is changed to be an offset to savepoint storage
110
 
     area and need not be used by storage engine.
111
 
     see binlog_engine and binlog_savepoint_set/rollback for an example.
112
 
   */
113
 
   uint32_t savepoint_offset;
114
 
   uint32_t license; /* Flag for Engine License */
115
 
 
116
 
  StorageEngine(const std::string &name_arg, bool support_2pc= false)
117
 
    : name(name_arg), _2pc(support_2pc), savepoint_offset(0)  {}
118
 
  virtual ~StorageEngine() {}
 
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();
119
130
 
120
131
  bool has_2pc()
121
132
  {
122
 
    return _2pc;
123
 
  }
124
 
 
125
 
 
126
 
 
127
 
   bool is_enabled() const
128
 
   {
129
 
     return (state == SHOW_OPTION_YES);
130
 
   }
131
 
 
132
 
   std::string get_name() { return name; }
133
 
 
134
 
   /*
135
 
     StorageEngine methods:
136
 
 
137
 
     close_connection is only called if
138
 
     session->ha_data[xxx_engine.slot] is non-zero, so even if you don't need
139
 
     this storage area - set it to something, so that MySQL would know
140
 
     this storage engine was accessed in this connection
141
 
   */
142
 
   virtual int close_connection(Session  *)
143
 
   {
144
 
     return 0;
145
 
   }
146
 
   /*
147
 
     The void * points to an uninitialized storage area of requested size
148
 
     (see savepoint_offset description)
149
 
   */
150
 
   virtual int savepoint_set(Session *, void *)
151
 
   {
152
 
     return 0;
153
 
   }
154
 
 
155
 
   /*
156
 
     The void * points to a storage area, that was earlier passed
157
 
     to the savepoint_set call
158
 
   */
159
 
   virtual int savepoint_rollback(Session *, void *)
160
 
   {
161
 
     return 0;
162
 
   }
163
 
 
164
 
   virtual int savepoint_release(Session *, void *)
165
 
   {
166
 
     return 0;
167
 
   }
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
 
   virtual int  prepare(Session *, bool) { return 0; }
187
 
   virtual int  recover(XID *, uint32_t) { return 0; }
188
 
   virtual int  commit_by_xid(XID *) { return 0; }
189
 
   virtual int  rollback_by_xid(XID *) { return 0; }
190
 
   virtual handler *create(TABLE_SHARE *, MEM_ROOT *)= 0;
191
 
   /* args: path */
192
 
   virtual void drop_database(char*) { }
193
 
   virtual int start_consistent_snapshot(Session *) { return 0; }
194
 
   virtual bool flush_logs() { return false; }
195
 
   virtual bool show_status(Session *, stat_print_fn *, enum ha_stat_type)
196
 
   {
197
 
     return false;
198
 
   }
199
 
 
200
 
   /* args: current_session, tables, cond */
201
 
   virtual int fill_files_table(Session *, TableList *,
202
 
                                Item *) { return 0; }
203
 
   virtual int release_temporary_latches(Session *) { return false; }
204
 
 
205
 
   /* args: current_session, db, name */
206
 
   virtual int table_exists_in_engine(Session*, const char *, const char *);
 
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 *);
207
232
};
208
233
 
209
 
 
210
234
/* lookups */
211
235
StorageEngine *ha_default_storage_engine(Session *session);
212
236
plugin_ref ha_resolve_by_name(Session *session, const LEX_STRING *name);
214
238
handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc,
215
239
                         StorageEngine *db_type);
216
240
const char *ha_resolve_storage_engine_name(const StorageEngine *db_type);
217
 
bool ha_check_storage_engine_flag(const StorageEngine *db_type, const engine_flag_bits flag);
218
241
LEX_STRING *ha_storage_engine_name(const StorageEngine *engine);
219
242
 
220
243
#endif /* DRIZZLED_HANDLERTON_H */