~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/handler.h

  • Committer: Brian Aker
  • Date: 2008-10-20 03:40:03 UTC
  • mto: (492.3.21 drizzle-clean-code)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: brian@tangent.org-20081020034003-t2dcnl0ayr2ymm8k
THD -> Session rename

Show diffs side-by-side

added added

removed removed

Lines of Context:
351
351
#define COMPATIBLE_DATA_YES 0
352
352
#define COMPATIBLE_DATA_NO  1
353
353
 
354
 
typedef bool (*qc_engine_callback)(THD *thd, char *table_key,
 
354
typedef bool (*qc_engine_callback)(Session *thd, char *table_key,
355
355
                                      uint32_t key_length,
356
356
                                      uint64_t *engine_data);
357
357
 
442
442
typedef struct st_table_share TABLE_SHARE;
443
443
struct st_foreign_key_info;
444
444
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
445
 
typedef bool (stat_print_fn)(THD *thd, const char *type, uint32_t type_len,
 
445
typedef bool (stat_print_fn)(Session *thd, const char *type, uint32_t type_len,
446
446
                             const char *file, uint32_t file_len,
447
447
                             const char *status, uint32_t status_len);
448
448
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
499
499
     this storage area - set it to something, so that MySQL would know
500
500
     this storage engine was accessed in this connection
501
501
   */
502
 
   int  (*close_connection)(handlerton *hton, THD *thd);
 
502
   int  (*close_connection)(handlerton *hton, Session *thd);
503
503
   /*
504
504
     sv points to an uninitialized storage area of requested size
505
505
     (see savepoint_offset description)
506
506
   */
507
 
   int  (*savepoint_set)(handlerton *hton, THD *thd, void *sv);
 
507
   int  (*savepoint_set)(handlerton *hton, Session *thd, void *sv);
508
508
   /*
509
509
     sv points to a storage area, that was earlier passed
510
510
     to the savepoint_set call
511
511
   */
512
 
   int  (*savepoint_rollback)(handlerton *hton, THD *thd, void *sv);
513
 
   int  (*savepoint_release)(handlerton *hton, THD *thd, void *sv);
 
512
   int  (*savepoint_rollback)(handlerton *hton, Session *thd, void *sv);
 
513
   int  (*savepoint_release)(handlerton *hton, Session *thd, void *sv);
514
514
   /*
515
515
     'all' is true if it's a real commit, that makes persistent changes
516
516
     'all' is false if it's not in fact a commit but an end of the
518
518
     NOTE 'all' is also false in auto-commit mode where 'end of statement'
519
519
     and 'real commit' mean the same event.
520
520
   */
521
 
   int  (*commit)(handlerton *hton, THD *thd, bool all);
522
 
   int  (*rollback)(handlerton *hton, THD *thd, bool all);
523
 
   int  (*prepare)(handlerton *hton, THD *thd, bool all);
 
521
   int  (*commit)(handlerton *hton, Session *thd, bool all);
 
522
   int  (*rollback)(handlerton *hton, Session *thd, bool all);
 
523
   int  (*prepare)(handlerton *hton, Session *thd, bool all);
524
524
   int  (*recover)(handlerton *hton, XID *xid_list, uint32_t len);
525
525
   int  (*commit_by_xid)(handlerton *hton, XID *xid);
526
526
   int  (*rollback_by_xid)(handlerton *hton, XID *xid);
527
 
   void *(*create_cursor_read_view)(handlerton *hton, THD *thd);
528
 
   void (*set_cursor_read_view)(handlerton *hton, THD *thd, void *read_view);
529
 
   void (*close_cursor_read_view)(handlerton *hton, THD *thd, void *read_view);
 
527
   void *(*create_cursor_read_view)(handlerton *hton, Session *thd);
 
528
   void (*set_cursor_read_view)(handlerton *hton, Session *thd, void *read_view);
 
529
   void (*close_cursor_read_view)(handlerton *hton, Session *thd, void *read_view);
530
530
   handler *(*create)(handlerton *hton, TABLE_SHARE *table, MEM_ROOT *mem_root);
531
531
   void (*drop_database)(handlerton *hton, char* path);
532
 
   int (*start_consistent_snapshot)(handlerton *hton, THD *thd);
 
532
   int (*start_consistent_snapshot)(handlerton *hton, Session *thd);
533
533
   bool (*flush_logs)(handlerton *hton);
534
 
   bool (*show_status)(handlerton *hton, THD *thd, stat_print_fn *print, enum ha_stat_type stat);
535
 
   int (*fill_files_table)(handlerton *hton, THD *thd,
 
534
   bool (*show_status)(handlerton *hton, Session *thd, stat_print_fn *print, enum ha_stat_type stat);
 
535
   int (*fill_files_table)(handlerton *hton, Session *thd,
536
536
                           TableList *tables,
537
537
                           class Item *cond);
538
538
   uint32_t flags;                                /* global handler flags */
539
 
   int (*release_temporary_latches)(handlerton *hton, THD *thd);
 
539
   int (*release_temporary_latches)(handlerton *hton, Session *thd);
540
540
 
541
 
   int (*discover)(handlerton *hton, THD* thd, const char *db, 
 
541
   int (*discover)(handlerton *hton, Session* thd, const char *db, 
542
542
                   const char *name,
543
543
                   unsigned char **frmblob, 
544
544
                   size_t *frmlen);
545
 
   int (*table_exists_in_engine)(handlerton *hton, THD* thd, const char *db,
 
545
   int (*table_exists_in_engine)(handlerton *hton, Session* thd, const char *db,
546
546
                                 const char *name);
547
547
   uint32_t license; /* Flag for Engine License */
548
548
   void *data; /* Location for engines to keep personal structures */
563
563
 
564
564
class Ha_trx_info;
565
565
 
566
 
struct THD_TRANS
 
566
struct Session_TRANS
567
567
{
568
568
  /* true is not all entries in the ht[] support 2pc */
569
569
  bool        no_2pc;
573
573
    The purpose of this flag is to keep track of non-transactional
574
574
    tables that were modified in scope of:
575
575
    - transaction, when the variable is a member of
576
 
    THD::transaction.all
 
576
    Session::transaction.all
577
577
    - top-level statement or sub-statement, when the variable is a
578
 
    member of THD::transaction.stmt
 
578
    member of Session::transaction.stmt
579
579
    This member has the following life cycle:
580
580
    * stmt.modified_non_trans_table is used to keep track of
581
581
    modified non-transactional tables of top-level statements. At
624
624
{
625
625
public:
626
626
  /** Register this storage engine in the given transaction context. */
627
 
  void register_ha(THD_TRANS *trans, handlerton *ht_arg)
 
627
  void register_ha(Session_TRANS *trans, handlerton *ht_arg)
628
628
  {
629
629
    assert(m_flags == 0);
630
630
    assert(m_ht == NULL);
1155
1155
    insert id for the current row (*autogenerated*; if not
1156
1156
    autogenerated, it's 0).
1157
1157
    At first successful insertion, this variable is stored into
1158
 
    THD::first_successful_insert_id_in_cur_stmt.
 
1158
    Session::first_successful_insert_id_in_cur_stmt.
1159
1159
  */
1160
1160
  uint64_t insert_id_for_cur_row;
1161
1161
  /**
1231
1231
    interface, see the (private) functions write_row(), update_row(),
1232
1232
    and delete_row() below.
1233
1233
  */
1234
 
  int ha_external_lock(THD *thd, int lock_type);
 
1234
  int ha_external_lock(Session *thd, int lock_type);
1235
1235
  int ha_write_row(unsigned char * buf);
1236
1236
  int ha_update_row(const unsigned char * old_data, unsigned char * new_data);
1237
1237
  int ha_delete_row(const unsigned char * buf);
1239
1239
 
1240
1240
  int ha_check_for_upgrade(HA_CHECK_OPT *check_opt);
1241
1241
  /** to be actually called to get 'check()' functionality*/
1242
 
  int ha_check(THD *thd, HA_CHECK_OPT *check_opt);
1243
 
  int ha_repair(THD* thd, HA_CHECK_OPT* check_opt);
 
1242
  int ha_check(Session *thd, HA_CHECK_OPT *check_opt);
 
1243
  int ha_repair(Session* thd, HA_CHECK_OPT* check_opt);
1244
1244
  void ha_start_bulk_insert(ha_rows rows)
1245
1245
  {
1246
1246
    estimation_rows_to_insert= rows;
1255
1255
                         uint32_t *dup_key_found);
1256
1256
  int ha_delete_all_rows();
1257
1257
  int ha_reset_auto_increment(uint64_t value);
1258
 
  int ha_optimize(THD* thd, HA_CHECK_OPT* check_opt);
1259
 
  int ha_analyze(THD* thd, HA_CHECK_OPT* check_opt);
1260
 
  bool ha_check_and_repair(THD *thd);
 
1258
  int ha_optimize(Session* thd, HA_CHECK_OPT* check_opt);
 
1259
  int ha_analyze(Session* thd, HA_CHECK_OPT* check_opt);
 
1260
  bool ha_check_and_repair(Session *thd);
1261
1261
  int ha_disable_indexes(uint32_t mode);
1262
1262
  int ha_enable_indexes(uint32_t mode);
1263
1263
  int ha_discard_or_import_tablespace(bool discard);
1511
1511
  */
1512
1512
  virtual void try_semi_consistent_read(bool) {}
1513
1513
  virtual void unlock_row(void) {}
1514
 
  virtual int start_stmt(THD *thd __attribute__((unused)),
 
1514
  virtual int start_stmt(Session *thd __attribute__((unused)),
1515
1515
                         thr_lock_type lock_type __attribute__((unused)))
1516
1516
  {return 0;}
1517
1517
  virtual void get_auto_increment(uint64_t offset, uint64_t increment,
1540
1540
 
1541
1541
  virtual void update_create_info(HA_CREATE_INFO *create_info __attribute__((unused))) {}
1542
1542
  int check_old_types(void);
1543
 
  virtual int assign_to_keycache(THD* thd __attribute__((unused)),
 
1543
  virtual int assign_to_keycache(Session* thd __attribute__((unused)),
1544
1544
                                 HA_CHECK_OPT* check_opt __attribute__((unused)))
1545
1545
  { return HA_ADMIN_NOT_IMPLEMENTED; }
1546
1546
  /* end of the list of admin commands */
1567
1567
  /** used in ALTER Table; 1 if changing storage engine is allowed */
1568
1568
  virtual bool can_switch_engines(void) { return 1; }
1569
1569
  /** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
1570
 
  virtual int get_foreign_key_list(THD *thd __attribute__((unused)),
 
1570
  virtual int get_foreign_key_list(Session *thd __attribute__((unused)),
1571
1571
                                   List<FOREIGN_KEY_INFO> *f_key_list __attribute__((unused)))
1572
1572
  { return 0; }
1573
1573
  virtual uint32_t referenced_by_foreign_key() { return 0;}
1658
1658
    than lock_count() claimed. This can happen when the MERGE children
1659
1659
    are not attached when this is called from another thread.
1660
1660
  */
1661
 
  virtual THR_LOCK_DATA **store_lock(THD *thd,
 
1661
  virtual THR_LOCK_DATA **store_lock(Session *thd,
1662
1662
                                     THR_LOCK_DATA **to,
1663
1663
                                     enum thr_lock_type lock_type)=0;
1664
1664
 
1697
1697
  */
1698
1698
 
1699
1699
  virtual bool
1700
 
    register_query_cache_table(THD *thd __attribute__((unused)),
 
1700
    register_query_cache_table(Session *thd __attribute__((unused)),
1701
1701
                               char *table_key __attribute__((unused)),
1702
1702
                               uint32_t key_length __attribute__((unused)),
1703
1703
                               qc_engine_callback *engine_callback,
1819
1819
   @retval   0      OK
1820
1820
   @retval   error  error code passed from storage engine
1821
1821
 */
1822
 
 virtual int alter_table_phase1(THD *thd __attribute__((unused)),
 
1822
 virtual int alter_table_phase1(Session *thd __attribute__((unused)),
1823
1823
                                Table *altered_table __attribute__((unused)),
1824
1824
                                HA_CREATE_INFO *create_info __attribute__((unused)),
1825
1825
                                HA_ALTER_INFO *alter_info __attribute__((unused)),
1845
1845
      this call is to be wrapped with a DDL lock. This is currently NOT
1846
1846
      supported.
1847
1847
 */
1848
 
 virtual int alter_table_phase2(THD *thd  __attribute__((unused)),
 
1848
 virtual int alter_table_phase2(Session *thd  __attribute__((unused)),
1849
1849
                                Table *altered_table  __attribute__((unused)),
1850
1850
                                HA_CREATE_INFO *create_info __attribute__((unused)),
1851
1851
                                HA_ALTER_INFO *alter_info __attribute__((unused)),
1860
1860
    @param    thd               The thread handle
1861
1861
    @param    table             The altered table, re-opened
1862
1862
 */
1863
 
 virtual int alter_table_phase3(THD *thd __attribute__((unused)),
 
1863
 virtual int alter_table_phase3(Session *thd __attribute__((unused)),
1864
1864
                                Table *table __attribute__((unused)))
1865
1865
 {
1866
1866
   return HA_ERR_UNSUPPORTED;
1897
1897
                                      lock conflict with NOWAIT option
1898
1898
    @retval HA_ERR_LOCK_DEADLOCK      Deadlock detected
1899
1899
  */
1900
 
  virtual int lock_table(THD *thd         __attribute__((unused)),
 
1900
  virtual int lock_table(Session *thd         __attribute__((unused)),
1901
1901
                         int lock_type    __attribute__((unused)),
1902
1902
                         int lock_timeout __attribute__((unused)))
1903
1903
  {
1913
1913
protected:
1914
1914
  /* Service methods for use by storage engines. */
1915
1915
  void ha_statistic_increment(ulong SSV::*offset) const;
1916
 
  void **ha_data(THD *) const;
1917
 
  THD *ha_thd(void) const;
 
1916
  void **ha_data(Session *) const;
 
1917
  Session *ha_thd(void) const;
1918
1918
 
1919
1919
  /**
1920
1920
    Default rename_table() and delete_table() rename/delete files with a
1999
1999
    @return  non-0 in case of failure, 0 in case of success.
2000
2000
    When lock_type is F_UNLCK, the return value is ignored.
2001
2001
  */
2002
 
  virtual int external_lock(THD *thd __attribute__((unused)),
 
2002
  virtual int external_lock(Session *thd __attribute__((unused)),
2003
2003
                            int lock_type __attribute__((unused)))
2004
2004
  {
2005
2005
    return 0;
2008
2008
  /** admin commands - called from mysql_admin_table */
2009
2009
  virtual int check_for_upgrade(HA_CHECK_OPT *check_opt __attribute__((unused)))
2010
2010
  { return 0; }
2011
 
  virtual int check(THD* thd __attribute__((unused)),
 
2011
  virtual int check(Session* thd __attribute__((unused)),
2012
2012
                    HA_CHECK_OPT* check_opt __attribute__((unused)))
2013
2013
  { return HA_ADMIN_NOT_IMPLEMENTED; }
2014
2014
 
2017
2017
     to specify CHECK option to use to call check()
2018
2018
     upon the table.
2019
2019
  */
2020
 
  virtual int repair(THD* thd __attribute__((unused)),
 
2020
  virtual int repair(Session* thd __attribute__((unused)),
2021
2021
                     HA_CHECK_OPT* check_opt __attribute__((unused)))
2022
2022
  { return HA_ADMIN_NOT_IMPLEMENTED; }
2023
2023
  virtual void start_bulk_insert(ha_rows rows __attribute__((unused)))
2068
2068
  */
2069
2069
  virtual int reset_auto_increment(uint64_t value __attribute__((unused)))
2070
2070
  { return HA_ERR_WRONG_COMMAND; }
2071
 
  virtual int optimize(THD* thd __attribute__((unused)),
 
2071
  virtual int optimize(Session* thd __attribute__((unused)),
2072
2072
                       HA_CHECK_OPT* check_opt __attribute__((unused)))
2073
2073
  { return HA_ADMIN_NOT_IMPLEMENTED; }
2074
 
  virtual int analyze(THD* thd __attribute__((unused)),
 
2074
  virtual int analyze(Session* thd __attribute__((unused)),
2075
2075
                      HA_CHECK_OPT* check_opt __attribute__((unused)))
2076
2076
  { return HA_ADMIN_NOT_IMPLEMENTED; }
2077
 
  virtual bool check_and_repair(THD *thd __attribute__((unused)))
 
2077
  virtual bool check_and_repair(Session *thd __attribute__((unused)))
2078
2078
  { return true; }
2079
2079
  virtual int disable_indexes(uint32_t mode __attribute__((unused)))
2080
2080
  { return HA_ERR_WRONG_COMMAND; }
2175
2175
#define ha_rollback(thd) (ha_rollback_trans((thd), true))
2176
2176
 
2177
2177
/* lookups */
2178
 
handlerton *ha_default_handlerton(THD *thd);
2179
 
plugin_ref ha_resolve_by_name(THD *thd, const LEX_STRING *name);
2180
 
plugin_ref ha_lock_engine(THD *thd, handlerton *hton);
2181
 
handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type);
 
2178
handlerton *ha_default_handlerton(Session *thd);
 
2179
plugin_ref ha_resolve_by_name(Session *thd, const LEX_STRING *name);
 
2180
plugin_ref ha_lock_engine(Session *thd, handlerton *hton);
 
2181
handlerton *ha_resolve_by_legacy_type(Session *thd, enum legacy_db_type db_type);
2182
2182
handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc,
2183
2183
                         handlerton *db_type);
2184
 
handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type,
 
2184
handlerton *ha_checktype(Session *thd, enum legacy_db_type database_type,
2185
2185
                          bool no_substitute, bool report_error);
2186
2186
 
2187
2187
 
2214
2214
int ha_finalize_handlerton(st_plugin_int *plugin);
2215
2215
 
2216
2216
TYPELIB *ha_known_exts(void);
2217
 
void ha_close_connection(THD* thd);
 
2217
void ha_close_connection(Session* thd);
2218
2218
bool ha_flush_logs(handlerton *db_type);
2219
2219
void ha_drop_database(char* path);
2220
 
int ha_create_table(THD *thd, const char *path,
 
2220
int ha_create_table(Session *thd, const char *path,
2221
2221
                    const char *db, const char *table_name,
2222
2222
                    HA_CREATE_INFO *create_info,
2223
2223
                    bool update_create_info);
2224
 
int ha_delete_table(THD *thd, handlerton *db_type, const char *path,
 
2224
int ha_delete_table(Session *thd, handlerton *db_type, const char *path,
2225
2225
                    const char *db, const char *alias, bool generate_warning);
2226
2226
 
2227
2227
/* statistics and info */
2228
 
bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat);
 
2228
bool ha_show_status(Session *thd, handlerton *db_type, enum ha_stat_type stat);
2229
2229
 
2230
2230
/* discovery */
2231
 
int ha_create_table_from_engine(THD* thd, const char *db, const char *name);
2232
 
int ha_discover(THD* thd, const char* dbname, const char* name,
 
2231
int ha_create_table_from_engine(Session* thd, const char *db, const char *name);
 
2232
int ha_discover(Session* thd, const char* dbname, const char* name,
2233
2233
                unsigned char** frmblob, size_t* frmlen);
2234
 
int ha_find_files(THD *thd,const char *db,const char *path,
 
2234
int ha_find_files(Session *thd,const char *db,const char *path,
2235
2235
                  const char *wild, bool dir, List<LEX_STRING>* files);
2236
 
int ha_table_exists_in_engine(THD* thd, const char* db, const char* name);
 
2236
int ha_table_exists_in_engine(Session* thd, const char* db, const char* name);
2237
2237
 
2238
2238
/* key cache */
2239
2239
extern "C" int ha_init_key_cache(const char *name, KEY_CACHE *key_cache);
2243
2243
int ha_end_key_cache(KEY_CACHE *key_cache);
2244
2244
 
2245
2245
/* report to InnoDB that control passes to the client */
2246
 
int ha_release_temporary_latches(THD *thd);
 
2246
int ha_release_temporary_latches(Session *thd);
2247
2247
 
2248
2248
/* transactions: interface to handlerton functions */
2249
 
int ha_start_consistent_snapshot(THD *thd);
 
2249
int ha_start_consistent_snapshot(Session *thd);
2250
2250
int ha_commit_or_rollback_by_xid(XID *xid, bool commit);
2251
 
int ha_commit_one_phase(THD *thd, bool all);
2252
 
int ha_rollback_trans(THD *thd, bool all);
2253
 
int ha_prepare(THD *thd);
 
2251
int ha_commit_one_phase(Session *thd, bool all);
 
2252
int ha_rollback_trans(Session *thd, bool all);
 
2253
int ha_prepare(Session *thd);
2254
2254
int ha_recover(HASH *commit_list);
2255
2255
 
2256
2256
/* transactions: these functions never call handlerton functions directly */
2257
 
int ha_commit_trans(THD *thd, bool all);
2258
 
int ha_autocommit_or_rollback(THD *thd, int error);
2259
 
int ha_enable_transaction(THD *thd, bool on);
 
2257
int ha_commit_trans(Session *thd, bool all);
 
2258
int ha_autocommit_or_rollback(Session *thd, int error);
 
2259
int ha_enable_transaction(Session *thd, bool on);
2260
2260
 
2261
2261
/* savepoints */
2262
 
int ha_rollback_to_savepoint(THD *thd, SAVEPOINT *sv);
2263
 
int ha_savepoint(THD *thd, SAVEPOINT *sv);
2264
 
int ha_release_savepoint(THD *thd, SAVEPOINT *sv);
 
2262
int ha_rollback_to_savepoint(Session *thd, SAVEPOINT *sv);
 
2263
int ha_savepoint(Session *thd, SAVEPOINT *sv);
 
2264
int ha_release_savepoint(Session *thd, SAVEPOINT *sv);
2265
2265
 
2266
2266
/* these are called by storage engines */
2267
 
void trans_register_ha(THD *thd, bool all, handlerton *ht);
 
2267
void trans_register_ha(Session *thd, bool all, handlerton *ht);
2268
2268
 
2269
2269
/*
2270
2270
  Storage engine has to assume the transaction will end up with 2pc if