~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbxt/src/ha_pbxt.h

  • Committer: Brian Aker
  • Date: 2010-04-12 07:43:55 UTC
  • mfrom: (1455.3.13 drizzle-pbxt-6)
  • Revision ID: brian@gaz-20100412074355-udi9dwjlcnmz0oz6
Merge PBXT

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2005 PrimeBase Technologies GmbH
 
2
 *
 
3
 * Derived from ha_example.h
 
4
 * Copyright (C) 2003 MySQL AB
 
5
 *
 
6
 * PrimeBase XT
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or
 
11
 * (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA     02111-1307      USA
 
21
 *
 
22
 * 2005-11-10   Paul McCullagh
 
23
 *
 
24
 */
 
25
#ifndef __ha_pbxt_h__
 
26
#define __ha_pbxt_h__
 
27
 
 
28
#ifdef DRIZZLED
 
29
#include <stdint.h>
 
30
#include <drizzled/common.h>
 
31
#include <drizzled/thr_lock.h>
 
32
#include <drizzled/cursor.h>
 
33
#include <drizzled/plugin/transactional_storage_engine.h>
 
34
using namespace drizzled;
 
35
using namespace drizzled::plugin;
 
36
#else
 
37
#include "mysql_priv.h"
 
38
#endif
 
39
 
 
40
#include "xt_defs.h"
 
41
#include "table_xt.h"
 
42
 
 
43
#ifdef USE_PRAGMA_INTERFACE
 
44
#pragma interface                       /* gcc class implementation */
 
45
#endif
 
46
 
 
47
#if MYSQL_VERSION_ID <= 50120
 
48
#define thd_killed(t)           (t)->killed
 
49
#endif
 
50
 
 
51
#if MYSQL_VERSION_ID >= 50120
 
52
#define byte uchar
 
53
#endif
 
54
 
 
55
class ha_pbxt;
 
56
 
 
57
#ifdef DRIZZLED
 
58
 
 
59
class PBXTStorageEngine : public drizzled::plugin::TransactionalStorageEngine 
 
60
{
 
61
 
 
62
        int delete_system_table(const char *table_path);
 
63
        int rename_system_table(const char * from, const char * to);
 
64
 
 
65
public:
 
66
        PBXTStorageEngine(std::string name_arg)
 
67
        : drizzled::plugin::TransactionalStorageEngine(name_arg, 
 
68
                                        HTON_FAST_KEY_READ | 
 
69
                                        HTON_NULL_IN_KEY | 
 
70
                                        HTON_CAN_INDEX_BLOBS |
 
71
                                        HTON_FILE_BASED | 
 
72
                                        HTON_AUTO_PART_KEY) 
 
73
        {}
 
74
 
 
75
        void operator delete(void *) {}
 
76
        void operator delete[] (void *) {}
 
77
 
 
78
        /* override */ int close_connection(Session *);
 
79
        /* override */ int commit(Session *, bool);
 
80
        /* override */ int rollback(Session *, bool);
 
81
        /* override */ Cursor *create(TableShare&, memory::Root *);
 
82
        /* override */ void drop_database(char *);
 
83
        /* override */ bool show_status(Session *, stat_print_fn *, enum ha_stat_type);
 
84
        /* override */ const char **bas_ext() const;
 
85
        /* override */ int doCreateTable(Session& session, Table &table_arg, TableIdentifier& ident,  drizzled::message::Table &proto);
 
86
        /* override */ int doRenameTable(Session& session, TableIdentifier& from, TableIdentifier& to);
 
87
        /* override */ int doDropTable(Session &session, TableIdentifier& ident);
 
88
 
 
89
        /* override */ int doStartTransaction(Session *session, start_transaction_option_t options);
 
90
        /* override */ int doStartConsistentSnapshot(Session *) { /* obsolete */ return -1; }
 
91
 
 
92
        /* override */ int doSetSavepoint(drizzled::Session* thd, drizzled::NamedSavepoint&);
 
93
        /* override */ int doRollbackToSavepoint(drizzled::Session* thd, drizzled::NamedSavepoint&);
 
94
        /* override */ int doReleaseSavepoint(drizzled::Session* thd, drizzled::NamedSavepoint&);
 
95
 
 
96
        /* override */ int doCommit(drizzled::Session*, bool);
 
97
        /* override */ int doRollback(drizzled::Session*, bool);
 
98
 
 
99
        /* override */ uint32_t max_supported_keys(void) const { return -1; }
 
100
        /* override */ uint32_t max_supported_key_part_length(void) const { return MAX_KEY_LENGTH; }
 
101
 
 
102
        /* override */ void doGetTableIdentifiers(drizzled::CachedDirectory&,
 
103
                                           drizzled::SchemaIdentifier&,
 
104
                                           drizzled::TableIdentifiers&) {}
 
105
 
 
106
        /* override */ void doGetTableNames(CachedDirectory&, 
 
107
                                        SchemaIdentifier&, 
 
108
                                        std::set<std::string>&) {}
 
109
 
 
110
        /* override */ bool doDoesTableExist(Session&, TableIdentifier &identifier);
 
111
 
 
112
        ~PBXTStorageEngine();
 
113
};
 
114
 
 
115
typedef PBXTStorageEngine handlerton;
 
116
 
 
117
#endif
 
118
 
 
119
extern handlerton *pbxt_hton;
 
120
 
 
121
/*
 
122
 * XTShareRec is a structure that will be shared amoung all open handlers.
 
123
 */
 
124
typedef struct XTShare {
 
125
        XTPathStrPtr            sh_table_path;
 
126
        uint                            sh_use_count;
 
127
 
 
128
        XTTableHPtr                     sh_table;                               /* This is a XTTableHPtr, a reference to the XT internal table handle. */
 
129
 
 
130
        uint                            sh_dic_key_count;
 
131
        XTIndexPtr                      *sh_dic_keys;                   /* A reference to the XT internal index list. */
 
132
        xtBool                          sh_recalc_selectivity;  /* This is set to TRUE if when have < 100 rows when the table is openned. */
 
133
 
 
134
        /* We use a trick here to get an exclusive lock
 
135
         * on a table. The trick avoids having to use a
 
136
         * semaphore if a thread does not want
 
137
         * exclusive use.
 
138
         */
 
139
        xt_mutex_type           *sh_ex_mutex;
 
140
        xt_cond_type            *sh_ex_cond;
 
141
        xtBool                          sh_table_lock;                  /* Set to TRUE if a lock on the table is held. */
 
142
        ha_pbxt                         *sh_handlers;                   /* Double linked list of handlers for a particular table. */
 
143
        xtWord8                         sh_min_auto_inc;                /* Used to proporgate the current auto-inc over a DELETE FROM
 
144
                                                                                                 * (does not work if the server shuts down in between!).
 
145
                                                                                                 */
 
146
 
 
147
        THR_LOCK                        sh_lock;                                /* MySQL lock */
 
148
} XTShareRec, *XTSharePtr;
 
149
 
 
150
/*
 
151
 * Class definition for the storage engine
 
152
 */
 
153
class ha_pbxt: public handler
 
154
{
 
155
        public:
 
156
        XTSharePtr                      pb_share;                               /* Shared table info */
 
157
 
 
158
        XTOpenTablePtr          pb_open_tab;                    /* This is a XTOpenTablePtr (a reference to the XT internal table handle)! */
 
159
 
 
160
        xtBool                          pb_key_read;                    /* No Need to retrieve the entire row, index values are sufficient. */
 
161
        u_int                           pb_import_row_count;
 
162
        int                                     pb_ignore_dup_key;
 
163
        u_int                           pb_ind_row_count;
 
164
 
 
165
        THR_LOCK_DATA           pb_lock;                                /* MySQL lock */
 
166
 
 
167
        ha_pbxt                         *pb_ex_next;                    /* Double linked list of handlers for a particular table. */
 
168
        ha_pbxt                         *pb_ex_prev;
 
169
 
 
170
        xtBool                          pb_lock_table;                  /* The operation requires a table lock. */
 
171
        int                                     pb_table_locked;                /* TRUE of this handler holds the table lock. */
 
172
        int                                     pb_ex_in_use;                   /* Set to 1 while when the handler is in use. */
 
173
 
 
174
        THD                                     *pb_mysql_thd;                  /* A pointer to the MySQL thread. */
 
175
        xtBool                          pb_in_stat;                             /* TRUE of start_stmt() was issued */
 
176
 
 
177
#ifdef DRIZZLED
 
178
        ha_pbxt(handlerton *hton, TableShare& table_arg);
 
179
#else
 
180
        ha_pbxt(handlerton *hton, TABLE_SHARE *table_arg);
 
181
#endif
 
182
        virtual ~ha_pbxt() { }
 
183
 
 
184
        /* The name that will be used for display purposes */
 
185
        const char *table_type() const { return "PBXT"; }
 
186
 
 
187
        /*
 
188
         * The name of the index type that will be used for display
 
189
         * don't implement this method unless you really have indexes.
 
190
         */
 
191
        const char *index_type(uint inx) { (void) inx; return "BTREE"; }
 
192
#ifndef DRIZZLED
 
193
        const char **bas_ext() const;
 
194
#endif
 
195
        MX_UINT8_T table_cache_type();
 
196
 
 
197
        /*
 
198
         * This is a list of flags that says what the storage engine
 
199
         * implements. The current table flags are documented in
 
200
         * handler.h
 
201
         */
 
202
        MX_TABLE_TYPES_T table_flags() const;
 
203
 
 
204
        /*
 
205
         * part is the key part to check. First key part is 0
 
206
         * If all_parts it's set, MySQL want to know the flags for the combined
 
207
         * index up to and including 'part'.
 
208
         */
 
209
        MX_ULONG_T index_flags(uint inx, uint part, bool all_parts) const;
 
210
 
 
211
        /*
 
212
         * unireg.cc will call the following to make sure that the storage engine can
 
213
         * handle the data it is about to send.
 
214
         * 
 
215
         * Return *real* limits of your storage engine here. MySQL will do
 
216
         * min(your_limits, MySQL_limits) automatically
 
217
         * 
 
218
         * Theoretically PBXT supports any number of key parts, etc.
 
219
         * Practically this is not true of course.
 
220
         */
 
221
        uint    max_supported_record_length()   const { return UINT_MAX; }
 
222
        uint    max_supported_keys()                    const { return 512; }
 
223
        uint    max_supported_key_parts()               const { return 128; }
 
224
        uint    max_supported_key_length()              const;
 
225
        uint    max_supported_key_part_length() const;
 
226
 
 
227
        double  scan_time();
 
228
 
 
229
        double  read_time(uint index, uint ranges, ha_rows rows);
 
230
 
 
231
        bool    has_transactions()  { return 1; }
 
232
 
 
233
        /*
 
234
         * Everything below are methods that we implement in ha_pbxt.cc.
 
235
         */
 
236
        void    internal_close(THD *thd, struct XTThread *self);
 
237
        int             open(const char *name, int mode, uint test_if_locked);          // required
 
238
        int             reopen(void);
 
239
        int             close(void);                                                                                            // required
 
240
 
 
241
        void    init_auto_increment(xtWord8 min_auto_inc);
 
242
        void    get_auto_increment(MX_ULONGLONG_T offset, MX_ULONGLONG_T increment,
 
243
                                 MX_ULONGLONG_T nb_desired_values,
 
244
                                 MX_ULONGLONG_T *first_value,
 
245
                                 MX_ULONGLONG_T *nb_reserved_values);
 
246
        void    set_auto_increment(Field *nr);
 
247
 
 
248
        int             write_row(byte * buf);
 
249
        int             update_row(const byte * old_data, byte * new_data);
 
250
        int             delete_row(const byte * buf);
 
251
 
 
252
        /* Index access functions: */
 
253
        int             xt_index_in_range(register XTOpenTablePtr ot, register XTIndexPtr ind, register XTIdxSearchKeyPtr search_key, byte *buf);
 
254
        int             xt_index_next_read(register XTOpenTablePtr ot, register XTIndexPtr ind, xtBool key_only, register XTIdxSearchKeyPtr search_key, byte *buf);
 
255
        int             xt_index_prev_read(XTOpenTablePtr ot, XTIndexPtr ind, xtBool key_only, register XTIdxSearchKeyPtr search_key, byte *buf);
 
256
        int             index_init(uint idx, bool sorted);
 
257
        int             index_end();
 
258
        int             index_read(byte * buf, const byte * key,
 
259
                                                                 uint key_len, enum ha_rkey_function find_flag);
 
260
        int             index_read_idx(byte * buf, uint idx, const byte * key,
 
261
                                                                                 uint key_len, enum ha_rkey_function find_flag);
 
262
        int             index_read_xt(byte * buf, uint idx, const byte * key,
 
263
                                                                                 uint key_len, enum ha_rkey_function find_flag);
 
264
        int             index_next(byte * buf);
 
265
        int             index_next_same(byte * buf, const byte *key, uint length);
 
266
        int             index_prev(byte * buf);
 
267
        int             index_first(byte * buf);
 
268
        int             index_last(byte * buf);
 
269
        int             index_read_last(byte * buf, const byte * key, uint key_len);
 
270
 
 
271
        /* Sequential scan functions: */
 
272
        int             rnd_init(bool scan);                                                            //required
 
273
        int             rnd_end();
 
274
        int             rnd_next(byte *buf);                                                            //required
 
275
        int             rnd_pos(byte * buf, byte *pos);                                                                                                  //required
 
276
        void    position(const byte *record);                   //required
 
277
#if MYSQL_VERSION_ID < 50114
 
278
        void    info(uint);
 
279
#else
 
280
        int             info(uint);
 
281
#endif
 
282
 
 
283
        int             extra(enum ha_extra_function operation);
 
284
        int             reset(void);
 
285
        int             external_lock(THD *thd, int lock_type);                                                                  //required
 
286
        int             start_stmt(THD *thd, thr_lock_type lock_type);
 
287
        void    unlock_row();
 
288
        int             delete_all_rows(void);
 
289
        int             repair(THD* thd, HA_CHECK_OPT* check_opt);
 
290
        int             analyze(THD* thd, HA_CHECK_OPT* check_opt);
 
291
        int             optimize(THD* thd, HA_CHECK_OPT* check_opt);
 
292
        int             check(THD* thd, HA_CHECK_OPT* check_opt);
 
293
        ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
 
294
#ifndef DRIZZLED
 
295
        int             delete_system_table(const char *table_path);
 
296
        int             delete_table(const char *from);
 
297
        int             rename_system_table(const char * from, const char * to);
 
298
        int             rename_table(const char * from, const char * to);
 
299
        int             create(const char *name, TABLE *form, HA_CREATE_INFO *create_info);                             //required
 
300
#endif
 
301
        void    update_create_info(HA_CREATE_INFO *create_info);
 
302
 
 
303
        THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type);          //required
 
304
 
 
305
        /* Foreign key support: */
 
306
        //bool is_fk_defined_on_table_or_index(uint index);
 
307
        char* get_foreign_key_create_info();
 
308
#ifdef DRI_IS
 
309
        int get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list);
 
310
        //bool can_switch_engines();
 
311
        uint referenced_by_foreign_key();
 
312
#endif
 
313
        void free_foreign_key_create_info(char* str);
 
314
 
 
315
        virtual bool get_error_message(int error, String *buf);
 
316
};
 
317
 
 
318
/* From ha_pbxt.cc: */
 
319
#define XT_TAB_NAME_WITH_EXT_SIZE       XT_TABLE_NAME_SIZE+4
 
320
 
 
321
//class THD;
 
322
struct XTThread;
 
323
struct XTDatabase;
 
324
 
 
325
void                    xt_ha_unlock_table(struct XTThread      *self, void *share);
 
326
void                    xt_ha_close_global_database(XTThreadPtr self);
 
327
void                    xt_ha_open_database_of_table(struct XTThread *self, XTPathStrPtr table_path);
 
328
struct XTThread *xt_ha_set_current_thread(THD *thd, XTExceptionPtr e);
 
329
void                    xt_ha_close_connection(THD* thd);
 
330
struct XTThread *xt_ha_thd_to_self(THD* thd);
 
331
int                             xt_ha_pbxt_to_mysql_error(int xt_err);
 
332
int                             xt_ha_pbxt_thread_error_for_mysql(THD *thd, const XTThreadPtr self, int ignore_dup_key);
 
333
void                    xt_ha_all_threads_close_database(XTThreadPtr self, XTDatabase *db);
 
334
void                    ha_set_auto_increment(XTOpenTablePtr ot, Field *nr);
 
335
 
 
336
/*
 
337
 * These hooks are suppossed to only be used by InnoDB:
 
338
 */
 
339
#ifndef DRIZZLED
 
340
#ifdef INNODB_COMPATIBILITY_HOOKS
 
341
extern "C" struct charset_info_st *thd_charset(MYSQL_THD thd);
 
342
extern "C" char **thd_query(MYSQL_THD thd);
 
343
extern "C" int thd_slave_thread(const MYSQL_THD thd);
 
344
extern "C" int thd_non_transactional_update(const MYSQL_THD thd);
 
345
extern "C" int thd_binlog_format(const MYSQL_THD thd);
 
346
extern "C" void thd_mark_transaction_to_rollback(MYSQL_THD thd, bool all);
 
347
#else
 
348
#define thd_charset(t)                                          (t)->charset()
 
349
#define thd_query(t)                                            &(t)->query
 
350
#define thd_slave_thread(t)                                     (t)->slave_thread
 
351
#define thd_non_transactional_update(t)         (t)->transaction.all.modified_non_trans_table
 
352
#define thd_binlog_format(t)                            (t)->variables.binlog_format
 
353
#define thd_mark_transaction_to_rollback(t)     mark_transaction_to_rollback(t, all)
 
354
#endif // INNODB_COMPATIBILITY_HOOKS */
 
355
#endif /* !DRIZZLED */
 
356
 
 
357
/* How to lock MySQL mutexes! */
 
358
#ifdef SAFE_MUTEX
 
359
 
 
360
#if MYSQL_VERSION_ID < 60000
 
361
#if MYSQL_VERSION_ID < 50123
 
362
#define myxt_mutex_lock(x)              safe_mutex_lock(x,__FILE__,__LINE__)
 
363
#else
 
364
#define myxt_mutex_lock(x)              safe_mutex_lock(x,0,__FILE__,__LINE__)
 
365
#endif
 
366
#else
 
367
#if MYSQL_VERSION_ID < 60004
 
368
#define myxt_mutex_lock(x)              safe_mutex_lock(x,__FILE__,__LINE__)
 
369
#else
 
370
#define myxt_mutex_lock(x)              safe_mutex_lock(x,0,__FILE__,__LINE__)
 
371
#endif
 
372
#endif
 
373
 
 
374
#define myxt_mutex_t                    safe_mutex_t
 
375
#define myxt_mutex_unlock(x)    safe_mutex_unlock(x,__FILE__,__LINE__)
 
376
 
 
377
#else // SAFE_MUTEX
 
378
 
 
379
#ifdef MY_PTHREAD_FASTMUTEX
 
380
#define myxt_mutex_lock(x)              my_pthread_fastmutex_lock(x)
 
381
#define myxt_mutex_t                    my_pthread_fastmutex_t
 
382
#define myxt_mutex_unlock(x)    pthread_mutex_unlock(&(x)->mutex)
 
383
#else
 
384
#define myxt_mutex_lock(x)              pthread_mutex_lock(x)
 
385
#define myxt_mutex_t                    pthread_mutex_t
 
386
#define myxt_mutex_unlock(x)    pthread_mutex_unlock(x)
 
387
#endif
 
388
 
 
389
#endif // SAFE_MUTEX
 
390
 
 
391
#endif
 
392