~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Merge Stewart's dead code removal

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., 51 Franklin St, Fifth Floor, Boston, MA    02110-1301      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_AUTO_PART_KEY |
72
 
                                        HTON_HAS_FOREIGN_KEYS |
73
 
                    HTON_HAS_DOES_TRANSACTIONS) 
74
 
        {}
75
 
 
76
 
        void operator delete(void *) {}
77
 
        void operator delete[] (void *) {}
78
 
 
79
 
        /* override */ uint32_t index_flags(enum  ha_key_alg) const;
80
 
        /* override */ int close_connection(Session *);
81
 
        /* override */ int commit(Session *, bool);
82
 
        /* override */ int rollback(Session *, bool);
83
 
        /* override */ Cursor *create(Table&);
84
 
        /* override */ void drop_database(char *);
85
 
        /* override */ bool show_status(Session *, stat_print_fn *, enum ha_stat_type);
86
 
        /* override */ const char **bas_ext() const;
87
 
        /* override */ int doCreateTable(Session& session, Table &table_arg, const TableIdentifier& ident,  drizzled::message::Table &proto);
88
 
        /* override */ int doRenameTable(Session& session, const TableIdentifier& from, const TableIdentifier& to);
89
 
        /* override */ int doDropTable(Session &session, const TableIdentifier& ident);
90
 
 
91
 
        /* override */ int doStartTransaction(Session *session, start_transaction_option_t options);
92
 
        /* override */ int doStartConsistentSnapshot(Session *) { /* obsolete */ return -1; }
93
 
 
94
 
        /* override */ int doSetSavepoint(drizzled::Session* thd, drizzled::NamedSavepoint&);
95
 
        /* override */ int doRollbackToSavepoint(drizzled::Session* thd, drizzled::NamedSavepoint&);
96
 
        /* override */ int doReleaseSavepoint(drizzled::Session* thd, drizzled::NamedSavepoint&);
97
 
 
98
 
        /* override */ int doCommit(drizzled::Session*, bool);
99
 
        /* override */ int doRollback(drizzled::Session*, bool);
100
 
 
101
 
        /* override */ uint32_t max_supported_keys(void) const { return UINT32_MAX; }
102
 
        /* override */ uint32_t max_supported_key_part_length(void) const { return MAX_KEY_LENGTH; }
103
 
 
104
 
        /* override */ void doGetTableIdentifiers(drizzled::CachedDirectory&,
105
 
                                                  const drizzled::SchemaIdentifier&,
106
 
                                                  drizzled::TableIdentifier::vector&) {}
107
 
 
108
 
        /* override */ bool doDoesTableExist(Session&, const TableIdentifier &identifier);
109
 
 
110
 
        virtual void shutdownPlugin();
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
 
        ha_pbxt(plugin::StorageEngine &engine_arg, Table &table_arg);
178
 
        virtual ~ha_pbxt() { }
179
 
 
180
 
        /* The name that will be used for display purposes */
181
 
        const char *table_type() const { return "PBXT"; }
182
 
 
183
 
        /*
184
 
         * The name of the index type that will be used for display
185
 
         * don't implement this method unless you really have indexes.
186
 
         */
187
 
        const char *index_type(uint inx) { (void) inx; return "BTREE"; }
188
 
#ifndef DRIZZLED
189
 
        const char **bas_ext() const;
190
 
#endif
191
 
        MX_UINT8_T table_cache_type();
192
 
 
193
 
        /*
194
 
         * This is a list of flags that says what the storage engine
195
 
         * implements. The current table flags are documented in
196
 
         * handler.h
197
 
         */
198
 
        MX_TABLE_TYPES_T table_flags() const;
199
 
 
200
 
        /*
201
 
         * unireg.cc will call the following to make sure that the storage engine can
202
 
         * handle the data it is about to send.
203
 
         * 
204
 
         * Return *real* limits of your storage engine here. MySQL will do
205
 
         * min(your_limits, MySQL_limits) automatically
206
 
         * 
207
 
         * Theoretically PBXT supports any number of key parts, etc.
208
 
         * Practically this is not true of course.
209
 
         */
210
 
        uint    max_supported_record_length()   const { return UINT_MAX; }
211
 
        uint    max_supported_keys()                    const { return 512; }
212
 
        uint    max_supported_key_parts()               const { return 128; }
213
 
        uint    max_supported_key_length()              const;
214
 
        uint    max_supported_key_part_length() const;
215
 
 
216
 
        double  scan_time();
217
 
 
218
 
        double  read_time(uint index, uint ranges, ha_rows rows);
219
 
 
220
 
        bool    has_transactions()  { return 1; }
221
 
 
222
 
        /*
223
 
         * Everything below are methods that we implement in ha_pbxt.cc.
224
 
         */
225
 
        void    internal_close(THD *thd, struct XTThread *self);
226
 
        int             open(const char *name, int mode, uint test_if_locked);          // required
227
 
        int             reopen(void);
228
 
        int             close(void);                                                                                            // required
229
 
 
230
 
        void    init_auto_increment(xtWord8 min_auto_inc);
231
 
        void    get_auto_increment(MX_ULONGLONG_T offset, MX_ULONGLONG_T increment,
232
 
                                 MX_ULONGLONG_T nb_desired_values,
233
 
                                 MX_ULONGLONG_T *first_value,
234
 
                                 MX_ULONGLONG_T *nb_reserved_values);
235
 
        void    set_auto_increment(Field *nr);
236
 
 
237
 
        int             doInsertRecord(byte * buf);
238
 
        int             doUpdateRecord(const byte * old_data, byte * new_data);
239
 
        int             doDeleteRecord(const byte * buf);
240
 
 
241
 
        /* Index access functions: */
242
 
        int             xt_index_in_range(register XTOpenTablePtr ot, register XTIndexPtr ind, register XTIdxSearchKeyPtr search_key, byte *buf);
243
 
        int             xt_index_next_read(register XTOpenTablePtr ot, register XTIndexPtr ind, xtBool key_only, register XTIdxSearchKeyPtr search_key, byte *buf);
244
 
        int             xt_index_prev_read(XTOpenTablePtr ot, XTIndexPtr ind, xtBool key_only, register XTIdxSearchKeyPtr search_key, byte *buf);
245
 
        int             doStartIndexScan(uint idx, bool sorted);
246
 
        int             doEndIndexScan();
247
 
        int             index_read(byte * buf, const byte * key,
248
 
                                                                 uint key_len, enum ha_rkey_function find_flag);
249
 
        int             index_read_idx(byte * buf, uint idx, const byte * key,
250
 
                                       uint key_len, enum ha_rkey_function find_flag);
251
 
        int             index_read_xt(byte * buf, uint idx, const byte * key,
252
 
                                      uint key_len, enum ha_rkey_function find_flag);
253
 
        int             index_next(byte * buf);
254
 
        int             index_next_same(byte * buf, const byte *key, uint length);
255
 
        int             index_prev(byte * buf);
256
 
        int             index_first(byte * buf);
257
 
        int             index_last(byte * buf);
258
 
        int             index_read_last(byte * buf, const byte * key, uint key_len);
259
 
 
260
 
        /* Sequential scan functions: */
261
 
        int             doStartTableScan(bool scan);                                                            //required
262
 
        int             doEndTableScan();
263
 
        int             rnd_next(byte *buf);                                                            //required
264
 
        int             rnd_pos(byte * buf, byte *pos);                                                                                                  //required
265
 
        void    position(const byte *record);                   //required
266
 
#if MYSQL_VERSION_ID < 50114
267
 
        void    info(uint);
268
 
#else
269
 
        int             info(uint);
270
 
#endif
271
 
 
272
 
        int             extra(enum ha_extra_function operation);
273
 
        int             reset(void);
274
 
        int             external_lock(THD *thd, int lock_type);                                                                  //required
275
 
        int             start_stmt(THD *thd, thr_lock_type lock_type);
276
 
        void    unlock_row();
277
 
        int             delete_all_rows(void);
278
 
        int             repair(THD* thd, HA_CHECK_OPT* check_opt);
279
 
        int             analyze(THD* thd);
280
 
        int             optimize(THD* thd);
281
 
        int             check(THD* thd);
282
 
        ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
283
 
 
284
 
        THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type);          //required
285
 
 
286
 
        /* Foreign key support: */
287
 
        //bool is_fk_defined_on_table_or_index(uint index);
288
 
        char* get_foreign_key_create_info();
289
 
#ifdef DRI_IS
290
 
        int get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list);
291
 
        //bool can_switch_engines();
292
 
        uint referenced_by_foreign_key();
293
 
#endif
294
 
        void free_foreign_key_create_info(char* str);
295
 
 
296
 
        virtual bool get_error_message(int error, String *buf);
297
 
};
298
 
 
299
 
/* From ha_pbxt.cc: */
300
 
#define XT_TAB_NAME_WITH_EXT_SIZE       XT_TABLE_NAME_SIZE+4
301
 
 
302
 
//class THD;
303
 
struct XTThread;
304
 
struct XTDatabase;
305
 
 
306
 
void                    xt_ha_unlock_table(struct XTThread      *self, void *share);
307
 
void                    xt_ha_close_global_database(XTThreadPtr self);
308
 
void                    xt_ha_open_database_of_table(struct XTThread *self, XTPathStrPtr table_path);
309
 
struct XTThread *xt_ha_set_current_thread(THD *thd, XTExceptionPtr e);
310
 
void                    xt_ha_close_connection(THD* thd);
311
 
struct XTThread *xt_ha_thd_to_self(THD* thd);
312
 
int                             xt_ha_pbxt_to_mysql_error(int xt_err);
313
 
int                             xt_ha_pbxt_thread_error_for_mysql(THD *thd, const XTThreadPtr self, int ignore_dup_key);
314
 
void                    xt_ha_all_threads_close_database(XTThreadPtr self, XTDatabase *db);
315
 
void                    ha_set_auto_increment(XTOpenTablePtr ot, Field *nr);
316
 
 
317
 
/*
318
 
 * These hooks are suppossed to only be used by InnoDB:
319
 
 */
320
 
#ifndef DRIZZLED
321
 
#ifdef INNODB_COMPATIBILITY_HOOKS
322
 
extern "C" struct charset_info_st *thd_charset(MYSQL_THD thd);
323
 
extern "C" char **thd_query(MYSQL_THD thd);
324
 
extern "C" int thd_slave_thread(const MYSQL_THD thd);
325
 
extern "C" int thd_binlog_format(const MYSQL_THD thd);
326
 
extern "C" void thd_mark_transaction_to_rollback(MYSQL_THD thd, bool all);
327
 
#else
328
 
#define thd_charset(t)                                          (t)->charset()
329
 
#define thd_query(t)                                            &(t)->query
330
 
#define thd_slave_thread(t)                                     (t)->slave_thread
331
 
#define thd_binlog_format(t)                            (t)->variables.binlog_format
332
 
#endif // INNODB_COMPATIBILITY_HOOKS */
333
 
#endif /* !DRIZZLED */
334
 
 
335
 
/* How to lock MySQL mutexes! */
336
 
#ifdef SAFE_MUTEX
337
 
 
338
 
#if MYSQL_VERSION_ID < 60000
339
 
#if MYSQL_VERSION_ID < 50123
340
 
#define myxt_mutex_lock(x)              safe_mutex_lock(x,__FILE__,__LINE__)
341
 
#else
342
 
#define myxt_mutex_lock(x)              safe_mutex_lock(x,0,__FILE__,__LINE__)
343
 
#endif
344
 
#else
345
 
#if MYSQL_VERSION_ID < 60004
346
 
#define myxt_mutex_lock(x)              safe_mutex_lock(x,__FILE__,__LINE__)
347
 
#else
348
 
#define myxt_mutex_lock(x)              safe_mutex_lock(x,0,__FILE__,__LINE__)
349
 
#endif
350
 
#endif
351
 
 
352
 
#define myxt_mutex_t                    safe_mutex_t
353
 
#define myxt_mutex_unlock(x)    safe_mutex_unlock(x,__FILE__,__LINE__)
354
 
 
355
 
#else // SAFE_MUTEX
356
 
 
357
 
#ifdef MY_PTHREAD_FASTMUTEX
358
 
#define myxt_mutex_lock(x)              my_pthread_fastmutex_lock(x)
359
 
#define myxt_mutex_t                    my_pthread_fastmutex_t
360
 
#define myxt_mutex_unlock(x)    pthread_mutex_unlock(&(x)->mutex)
361
 
#else
362
 
#define myxt_mutex_lock(x)              pthread_mutex_lock(x)
363
 
#define myxt_mutex_t                    pthread_mutex_t
364
 
#define myxt_mutex_unlock(x)    pthread_mutex_unlock(x)
365
 
#endif
366
 
 
367
 
#endif // SAFE_MUTEX
368
 
 
369
 
#endif
370