~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: mordred
  • Date: 2010-04-20 00:00:46 UTC
  • mfrom: (1471.5.3 more-valgrind)
  • mto: This revision was merged to the branch mainline in revision 1498.
  • Revision ID: mordred@orisndriz09-20100420000046-263x5hazl0huw8u3
MergedĀ inĀ more-valgrind.

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