diff options
54 files changed, 1489 insertions, 684 deletions
diff --git a/config/ac-macros/storage.m4 b/config/ac-macros/storage.m4 index 83024c9fd74..cfca6f97a0c 100644 --- a/config/ac-macros/storage.m4 +++ b/config/ac-macros/storage.m4 @@ -34,11 +34,14 @@ AC_CACHE_CHECK([whether to use $2], [mysql_cv_use_]m4_bpatsubst([$3], -, _), [mysql_cv_use_]m4_bpatsubst([$3], -, _)=[$with_]m4_bpatsubst([$3], -, _)) AH_TEMPLATE([$5], [Build $2]) if test "[$mysql_cv_use_]m4_bpatsubst([$3], -, _)" != no; then -AC_DEFINE([$5]) -mysql_se_decls="${mysql_se_decls},$6" -mysql_se_htons="${mysql_se_htons},&$6" +if test "$6" != "no" +then + AC_DEFINE([$5]) + mysql_se_decls="${mysql_se_decls},$6" + mysql_se_htons="${mysql_se_htons},&$6" + mysql_se_objs="$mysql_se_objs $8" +fi mysql_se_dirs="$mysql_se_dirs $7" -mysql_se_objs="$mysql_se_objs $8" mysql_se_libs="$mysql_se_libs $9" $10 fi diff --git a/configure.in b/configure.in index 9dd52af0a11..9b9939fecc0 100644 --- a/configure.in +++ b/configure.in @@ -2432,9 +2432,14 @@ MYSQL_STORAGE_ENGINE(innobase,,innodb,,,,storage/innobase,ha_innodb.o,[ dnl MYSQL_STORAGE_ENGINE(berkeley,,berkeley-db,,,,storage/bdb,,,[ MYSQL_SETUP_BERKELEY_DB ]) -MYSQL_STORAGE_ENGINE(example) +MYSQL_STORAGE_ENGINE(example,,,,,no,storage/example,,,[ + AC_CONFIG_FILES(storage/example/Makefile) +]) MYSQL_STORAGE_ENGINE(archive) -MYSQL_STORAGE_ENGINE(csv,,,,,tina_hton,,ha_tina.o) +dnl MYSQL_STORAGE_ENGINE(csv,,,,,tina_hton,,ha_tina.o) +MYSQL_STORAGE_ENGINE(csv,,,,,no,storage/csv,,,[ + AC_CONFIG_FILES(storage/csv/Makefile) +]) MYSQL_STORAGE_ENGINE(blackhole) MYSQL_STORAGE_ENGINE(federated) MYSQL_STORAGE_ENGINE(ndbcluster,,ndbcluster,,,,storage/ndb,,,[ diff --git a/include/plugin.h b/include/plugin.h index 038fefce21e..6f204106048 100644 --- a/include/plugin.h +++ b/include/plugin.h @@ -51,6 +51,7 @@ struct st_mysql_plugin int type; /* the plugin type (a MYSQL_XXX_PLUGIN value) */ void *info; /* pointer to type-specific plugin descriptor */ const char *name; /* plugin name */ + uint version; /* plugin version */ const char *author; /* plugin author (for SHOW PLUGINS) */ const char *descr; /* general descriptive text (for SHOW PLUGINS ) */ int (*init)(void); /* the function to invoke when plugin is loaded */ diff --git a/mysql-test/r/bdb.result b/mysql-test/r/bdb.result index a564fd1045c..9be2723ef96 100644 --- a/mysql-test/r/bdb.result +++ b/mysql-test/r/bdb.result @@ -285,6 +285,40 @@ n 4 5 6 +set autocommit=0; +begin; +savepoint `my_savepoint`; +insert into t1 values (7); +savepoint `savept2`; +insert into t1 values (3); +select n from t1; +n +3 +4 +5 +6 +7 +savepoint savept3; +rollback to savepoint savept2; +rollback to savepoint savept3; +ERROR 42000: SAVEPOINT savept3 does not exist +rollback to savepoint savept2; +release savepoint `my_savepoint`; +select n from t1; +n +4 +5 +6 +7 +rollback to savepoint `my_savepoint`; +ERROR 42000: SAVEPOINT my_savepoint does not exist +rollback to savepoint savept2; +ERROR 42000: SAVEPOINT savept2 does not exist +insert into t1 values (8); +savepoint sv; +commit; +savepoint sv; +set autocommit=1; rollback; drop table t1; create table t1 ( id int NOT NULL PRIMARY KEY, nom varchar(64)) engine=BDB; diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index c7c3de9451a..6b7be14a531 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -42,6 +42,7 @@ COLLATION_CHARACTER_SET_APPLICABILITY COLUMNS COLUMN_PRIVILEGES KEY_COLUMN_USAGE +PLUGINS ROUTINES SCHEMATA SCHEMA_PRIVILEGES @@ -723,7 +724,7 @@ CREATE TABLE t_crashme ( f1 BIGINT); CREATE VIEW a1 (t_CRASHME) AS SELECT f1 FROM t_crashme GROUP BY f1; CREATE VIEW a2 AS SELECT t_CRASHME FROM a1; count(*) -102 +103 drop view a2, a1; drop table t_crashme; select table_schema,table_name, column_name from @@ -731,6 +732,7 @@ information_schema.columns where data_type = 'longtext'; table_schema table_name column_name information_schema COLUMNS COLUMN_TYPE +information_schema PLUGINS PLUGIN_DESCRIPTION information_schema ROUTINES ROUTINE_DEFINITION information_schema ROUTINES SQL_MODE information_schema TRIGGERS ACTION_CONDITION @@ -793,7 +795,7 @@ delete from mysql.db where user='mysqltest_4'; flush privileges; SELECT table_schema, count(*) FROM information_schema.TABLES GROUP BY TABLE_SCHEMA; table_schema count(*) -information_schema 16 +information_schema 17 mysql 18 create table t1 (i int, j int); create trigger trg1 before insert on t1 for each row diff --git a/mysql-test/r/information_schema_db.result b/mysql-test/r/information_schema_db.result index d3ff310b812..092c03064ba 100644 --- a/mysql-test/r/information_schema_db.result +++ b/mysql-test/r/information_schema_db.result @@ -7,6 +7,7 @@ COLLATION_CHARACTER_SET_APPLICABILITY COLUMNS COLUMN_PRIVILEGES KEY_COLUMN_USAGE +PLUGINS ROUTINES SCHEMATA SCHEMA_PRIVILEGES diff --git a/mysql-test/t/bdb.test b/mysql-test/t/bdb.test index d3068b29e28..1bb8fa4d55d 100644 --- a/mysql-test/t/bdb.test +++ b/mysql-test/t/bdb.test @@ -147,6 +147,32 @@ insert into t1 values (6); -- error 1062 insert into t1 values (4); select n from t1; +set autocommit=0; +# +# savepoints +# +begin; +savepoint `my_savepoint`; +insert into t1 values (7); +savepoint `savept2`; +insert into t1 values (3); +select n from t1; +savepoint savept3; +rollback to savepoint savept2; +--error 1305 +rollback to savepoint savept3; +rollback to savepoint savept2; +release savepoint `my_savepoint`; +select n from t1; +-- error 1305 +rollback to savepoint `my_savepoint`; +--error 1305 +rollback to savepoint savept2; +insert into t1 values (8); +savepoint sv; +commit; +savepoint sv; +set autocommit=1; # nop rollback; drop table t1; diff --git a/sql/Makefile.am b/sql/Makefile.am index f3363cc445e..a4f761fdc16 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -102,9 +102,7 @@ EXTRA_mysqld_SOURCES = ha_innodb.cc ha_berkeley.cc ha_archive.cc \ ha_innodb.h ha_berkeley.h ha_archive.h \ ha_blackhole.cc ha_federated.cc ha_ndbcluster.cc \ ha_blackhole.h ha_federated.h ha_ndbcluster.h \ - ha_partition.cc ha_partition.h \ - examples/ha_tina.cc examples/ha_example.cc \ - examples/ha_tina.h examples/ha_example.h + ha_partition.cc ha_partition.h mysqld_DEPENDENCIES = @mysql_se_objs@ gen_lex_hash_SOURCES = gen_lex_hash.cc gen_lex_hash_LDADD = $(LDADD) $(CXXLDFLAGS) diff --git a/sql/authors.h b/sql/authors.h index 1c6e1d468c4..fde1806f4be 100644 --- a/sql/authors.h +++ b/sql/authors.h @@ -62,7 +62,8 @@ struct show_table_authors_st show_table_authors[]= { { "Albert Chin-A-Young", "", "Tru64 port, large file support, better TCP wrappers support" }, { "Jorge del Conde", "Mexico City, Mexico", "Windows development" }, - { "Antony T. Curtis", "Norwalk, CA, USA", "Parser, port to OS/2" }, + { "Antony T. Curtis", "Norwalk, CA, USA", + "Parser, port to OS/2, storage engines and some random stuff" }, { "Yuri Dario", "", "OS/2 port" }, { "Sergei Golubchik", "Kerpen, Germany", "Full-text search, precision math" }, diff --git a/sql/ha_archive.cc b/sql/ha_archive.cc index b5c2f2a6555..e5f93ea063c 100644 --- a/sql/ha_archive.cc +++ b/sql/ha_archive.cc @@ -140,6 +140,7 @@ static handler *archive_create_handler(TABLE_SHARE *table); /* dummy handlerton - only to have something to return from archive_db_init */ handlerton archive_hton = { + MYSQL_HANDLERTON_INTERFACE_VERSION, "ARCHIVE", SHOW_OPTION_YES, "Archive storage engine", @@ -163,12 +164,9 @@ handlerton archive_hton = { archive_create_handler, /* Create a new handler */ NULL, /* Drop a database */ archive_db_end, /* Panic call */ - NULL, /* Release temporary latches */ - NULL, /* Update Statistics */ NULL, /* Start Consistent Snapshot */ NULL, /* Flush logs */ NULL, /* Show status */ - NULL, /* Replication Report Sent Binlog */ HTON_NO_FLAGS }; diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc index 9e58305371f..900372a2204 100644 --- a/sql/ha_berkeley.cc +++ b/sql/ha_berkeley.cc @@ -116,20 +116,24 @@ static void update_status(BDB_SHARE *share, TABLE *table); static int berkeley_close_connection(THD *thd); static int berkeley_commit(THD *thd, bool all); static int berkeley_rollback(THD *thd, bool all); +static int berkeley_rollback_to_savepoint(THD* thd, void *savepoint); +static int berkeley_savepoint(THD* thd, void *savepoint); +static int berkeley_release_savepoint(THD* thd, void *savepoint); static handler *berkeley_create_handler(TABLE_SHARE *table); handlerton berkeley_hton = { + MYSQL_HANDLERTON_INTERFACE_VERSION, "BerkeleyDB", SHOW_OPTION_YES, "Supports transactions and page-level locking", DB_TYPE_BERKELEY_DB, berkeley_init, 0, /* slot */ - 0, /* savepoint size */ + sizeof(DB_TXN *), /* savepoint size */ berkeley_close_connection, - NULL, /* savepoint_set */ - NULL, /* savepoint_rollback */ - NULL, /* savepoint_release */ + berkeley_savepoint, /* savepoint_set */ + berkeley_rollback_to_savepoint, /* savepoint_rollback */ + berkeley_release_savepoint, /* savepoint_release */ berkeley_commit, berkeley_rollback, NULL, /* prepare */ @@ -142,12 +146,9 @@ handlerton berkeley_hton = { berkeley_create_handler, /* Create a new handler */ NULL, /* Drop a database */ berkeley_end, /* Panic call */ - NULL, /* Release temporary latches */ - NULL, /* Update Statistics */ NULL, /* Start Consistent Snapshot */ berkeley_flush_logs, /* Flush logs */ berkeley_show_status, /* Show status */ - NULL, /* Replication Report Sent Binlog */ HTON_CLOSE_CURSORS_AT_COMMIT | HTON_FLUSH_AFTER_RENAME }; @@ -159,6 +160,7 @@ handler *berkeley_create_handler(TABLE_SHARE *table) typedef struct st_berkeley_trx_data { DB_TXN *all; DB_TXN *stmt; + DB_TXN *sp_level; uint bdb_lock_count; } berkeley_trx_data; @@ -310,10 +312,53 @@ static int berkeley_rollback(THD *thd, bool all) DBUG_RETURN(error); } +static int berkeley_savepoint(THD* thd, void *savepoint) +{ + int error; + DB_TXN **save_txn= (DB_TXN**) savepoint; + DBUG_ENTER("berkeley_savepoint"); + berkeley_trx_data *trx=(berkeley_trx_data *)thd->ha_data[berkeley_hton.slot]; + if (!(error= db_env->txn_begin(db_env, trx->sp_level, save_txn, 0))) + { + trx->sp_level= *save_txn; + } + DBUG_RETURN(error); +} + +static int berkeley_rollback_to_savepoint(THD* thd, void *savepoint) +{ + int error; + DB_TXN *parent, **save_txn= (DB_TXN**) savepoint; + DBUG_ENTER("berkeley_rollback_to_savepoint"); + berkeley_trx_data *trx=(berkeley_trx_data *)thd->ha_data[berkeley_hton.slot]; + parent= (*save_txn)->parent; + if (!(error= (*save_txn)->abort(*save_txn))) + { + trx->sp_level= parent; + error= berkeley_savepoint(thd, savepoint); + } + DBUG_RETURN(error); +} + +static int berkeley_release_savepoint(THD* thd, void *savepoint) +{ + int error; + DB_TXN *parent, **save_txn= (DB_TXN**) savepoint; + DBUG_ENTER("berkeley_release_savepoint"); + berkeley_trx_data *trx=(berkeley_trx_data *)thd->ha_data[berkeley_hton.slot]; + parent= (*save_txn)->parent; + if (!(error= (*save_txn)->commit(*save_txn,0))) + { + trx->sp_level= parent; + *save_txn= 0; + } + DBUG_RETURN(error); +} static bool berkeley_show_logs(THD *thd, stat_print_fn *stat_print) { char **all_logs, **free_logs, **a, **f; + uint hton_name_len= strlen(berkeley_hton.name); int error=1; MEM_ROOT **root_ptr= my_pthread_getspecific_ptr(MEM_ROOT**,THR_MALLOC); MEM_ROOT show_logs_root, *old_mem_root= *root_ptr; @@ -338,19 +383,20 @@ static bool berkeley_show_logs(THD *thd, stat_print_fn *stat_print) { for (a = all_logs, f = free_logs; *a; ++a) { - const char *status; if (f && *f && strcmp(*a, *f) == 0) { f++; - status= SHOW_LOG_STATUS_FREE; + if ((error= stat_print(thd, berkeley_hton.name, hton_name_len, + *a, strlen(*a), + STRING_WITH_LEN(SHOW_LOG_STATUS_FREE)))) + break; } else - status= SHOW_LOG_STATUS_INUSE; - - if (stat_print(thd, berkeley_hton.name, *a, status)) { - error=1; - goto err; + if ((error= stat_print(thd, berkeley_hton.name, hton_name_len, + *a, strlen(*a), + STRING_WITH_LEN(SHOW_LOG_STATUS_INUSE)))) + break; } } } @@ -1872,6 +1918,8 @@ int ha_berkeley::external_lock(THD *thd, int lock_type) if (!trx) DBUG_RETURN(1); } + if (trx->all == 0) + trx->sp_level= 0; if (lock_type != F_UNLCK) { if (!trx->bdb_lock_count++) @@ -1890,12 +1938,13 @@ int ha_berkeley::external_lock(THD *thd, int lock_type) trx->bdb_lock_count--; // We didn't get the lock DBUG_RETURN(error); } + trx->sp_level= trx->all; trans_register_ha(thd, TRUE, &berkeley_hton); if (thd->in_lock_tables) DBUG_RETURN(0); // Don't create stmt trans } DBUG_PRINT("trans",("starting transaction stmt")); - if ((error= db_env->txn_begin(db_env, trx->all, &trx->stmt, 0))) + if ((error= db_env->txn_begin(db_env, trx->sp_level, &trx->stmt, 0))) { /* We leave the possible master transaction open */ trx->bdb_lock_count--; // We didn't get the lock @@ -1949,7 +1998,7 @@ int ha_berkeley::start_stmt(THD *thd, thr_lock_type lock_type) if (!trx->stmt) { DBUG_PRINT("trans",("starting transaction stmt")); - error= db_env->txn_begin(db_env, trx->all, &trx->stmt, 0); + error= db_env->txn_begin(db_env, trx->sp_level, &trx->stmt, 0); trans_register_ha(thd, FALSE, &berkeley_hton); } transaction= trx->stmt; diff --git a/sql/ha_blackhole.cc b/sql/ha_blackhole.cc index e2b0fc29d86..615836b9867 100644 --- a/sql/ha_blackhole.cc +++ b/sql/ha_blackhole.cc @@ -30,6 +30,7 @@ static handler *blackhole_create_handler(TABLE_SHARE *table); /* Blackhole storage engine handlerton */ handlerton blackhole_hton= { + MYSQL_HANDLERTON_INTERFACE_VERSION, "BLACKHOLE", SHOW_OPTION_YES, "/dev/null storage engine (anything you write to it disappears)", @@ -53,12 +54,9 @@ handlerton blackhole_hton= { blackhole_create_handler, /* Create a new handler */ NULL, /* Drop a database */ NULL, /* Panic call */ - NULL, /* Release temporary latches */ - NULL, /* Update Statistics */ NULL, /* Start Consistent Snapshot */ NULL, /* Flush logs */ NULL, /* Show status */ - NULL, /* Replication Report Sent Binlog */ HTON_CAN_RECREATE }; diff --git a/sql/ha_federated.cc b/sql/ha_federated.cc index 6e4d6c4b7bb..944333496ae 100644 --- a/sql/ha_federated.cc +++ b/sql/ha_federated.cc @@ -367,6 +367,7 @@ static int federated_rollback(THD *thd, bool all); /* Federated storage engine handlerton */ handlerton federated_hton= { + MYSQL_HANDLERTON_INTERFACE_VERSION, "FEDERATED", SHOW_OPTION_YES, "Federated MySQL storage engine", @@ -390,12 +391,9 @@ handlerton federated_hton= { federated_create_handler, /* Create a new handler */ NULL, /* Drop a database */ federated_db_end, /* Panic call */ - NULL, /* Release temporary latches */ - NULL, /* Update Statistics */ NULL, /* Start Consistent Snapshot */ NULL, /* Flush logs */ NULL, /* Show status */ - NULL, /* Replication Report Sent Binlog */ HTON_ALTER_NOT_SUPPORTED }; diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc index ddc6c1bfb8f..a83a95ac863 100644 --- a/sql/ha_heap.cc +++ b/sql/ha_heap.cc @@ -27,6 +27,7 @@ static handler *heap_create_handler(TABLE_SHARE *table); handlerton heap_hton= { + MYSQL_HANDLERTON_INTERFACE_VERSION, "MEMORY", SHOW_OPTION_YES, "Hash based, stored in memory, useful for temporary tables", @@ -50,12 +51,9 @@ handlerton heap_hton= { heap_create_handler, /* Create a new handler */ NULL, /* Drop a database */ heap_panic, /* Panic call */ - NULL, /* Release temporary latches */ - NULL, /* Update Statistics */ NULL, /* Start Consistent Snapshot */ NULL, /* Flush logs */ NULL, /* Show status */ - NULL, /* Replication Report Sent Binlog */ HTON_CAN_RECREATE }; diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index d1536f9d282..8b0cbe87562 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -208,6 +208,7 @@ static int innobase_release_savepoint(THD* thd, void *savepoint); static handler *innobase_create_handler(TABLE_SHARE *table); handlerton innobase_hton = { + MYSQL_HANDLERTON_INTERFACE_VERSION, "InnoDB", SHOW_OPTION_YES, "Supports transactions, row-level locking, and foreign keys", @@ -231,16 +232,9 @@ handlerton innobase_hton = { innobase_create_handler, /* Create a new handler */ innobase_drop_database, /* Drop a database */ innobase_end, /* Panic call */ - innobase_release_temporary_latches, /* Release temporary latches */ - innodb_export_status, /* Update Statistics */ innobase_start_trx_and_assign_read_view, /* Start Consistent Snapshot */ innobase_flush_logs, /* Flush logs */ innobase_show_status, /* Show status */ -#ifdef HAVE_REPLICATION - innobase_repl_report_sent_binlog, /* Replication Report Sent Binlog */ -#else - NULL, -#endif HTON_NO_FLAGS }; @@ -1977,6 +1971,11 @@ innobase_repl_report_sent_binlog( int cmp; ibool can_release_threads = 0; + if (!innodb_inited) { + + return 0; + } + /* If synchronous replication is not switched on, or this thd is sending binlog to a slave where we do not need synchronous replication, then return immediately */ @@ -6481,10 +6480,11 @@ ha_innobase::transactional_table_lock( Here we export InnoDB status variables to MySQL. */ int -innodb_export_status(void) +innodb_export_status() /*======================*/ { - srv_export_innodb_status(); + if (innodb_inited) + srv_export_innodb_status(); return 0; } @@ -6571,7 +6571,8 @@ innodb_show_status( bool result = FALSE; - if (stat_print(thd, innobase_hton.name, "", str)) { + if (stat_print(thd, innobase_hton.name, strlen(innobase_hton.name), + STRING_WITH_LEN(""), str, flen)) { result= TRUE; } my_free(str, MYF(0)); @@ -6596,6 +6597,7 @@ innodb_mutex_show_status( ulint rw_lock_count_os_wait= 0; ulint rw_lock_count_os_yield= 0; ulonglong rw_lock_wait_time= 0; + uint hton_name_len= strlen(innobase_hton.name), buf1len, buf2len; DBUG_ENTER("innodb_mutex_show_status"); #ifdef MUTEX_PROTECT_TO_BE_ADDED_LATER @@ -6610,16 +6612,17 @@ innodb_mutex_show_status( { if (mutex->count_using > 0) { - my_snprintf(buf1, sizeof(buf1), "%s:%s", - mutex->cmutex_name, mutex->cfile_name); - my_snprintf(buf2, sizeof(buf2), - "count=%lu, spin_waits=%lu, spin_rounds=%lu, " - "os_waits=%lu, os_yields=%lu, os_wait_times=%lu", - mutex->count_using, mutex->count_spin_loop, - mutex->count_spin_rounds, - mutex->count_os_wait, mutex->count_os_yield, - mutex->lspent_time/1000); - if (stat_print(thd, innobase_hton.name, buf1, buf2)) + buf1len= my_snprintf(buf1, sizeof(buf1), "%s:%s", + mutex->cmutex_name, mutex->cfile_name); + buf2len= my_snprintf(buf2, sizeof(buf2), + "count=%lu, spin_waits=%lu, spin_rounds=%lu, " + "os_waits=%lu, os_yields=%lu, os_wait_times=%lu", + mutex->count_using, mutex->count_spin_loop, + mutex->count_spin_rounds, + mutex->count_os_wait, mutex->count_os_yield, + mutex->lspent_time/1000); + if (stat_print(thd, innobase_hton.name, hton_name_len, + buf1, buf1len, buf2, buf2len)) { #ifdef MUTEX_PROTECT_TO_BE_ADDED_LATER mutex_exit(&mutex_list_mutex); @@ -6641,15 +6644,16 @@ innodb_mutex_show_status( mutex = UT_LIST_GET_NEXT(list, mutex); } - my_snprintf(buf2, sizeof(buf2), - "count=%lu, spin_waits=%lu, spin_rounds=%lu, " - "os_waits=%lu, os_yields=%lu, os_wait_times=%lu", - rw_lock_count, rw_lock_count_spin_loop, - rw_lock_count_spin_rounds, - rw_lock_count_os_wait, rw_lock_count_os_yield, - rw_lock_wait_time/1000); + buf2len= my_snprintf(buf2, sizeof(buf2), + "count=%lu, spin_waits=%lu, spin_rounds=%lu, " + "os_waits=%lu, os_yields=%lu, os_wait_times=%lu", + rw_lock_count, rw_lock_count_spin_loop, + rw_lock_count_spin_rounds, + rw_lock_count_os_wait, rw_lock_count_os_yield, + rw_lock_wait_time/1000); - if (stat_print(thd, innobase_hton.name, "rw_lock_mutexes", buf2)) + if (stat_print(thd, innobase_hton.name, hton_name_len, + STRING_WITH_LEN("rw_lock_mutexes"), buf2, buf2len)) { DBUG_RETURN(1); } diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index dfd8fb23cf4..a2a58de9171 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -55,6 +55,7 @@ static handler *myisam_create_handler(TABLE_SHARE *table); /* MyISAM handlerton */ handlerton myisam_hton= { + MYSQL_HANDLERTON_INTERFACE_VERSION, "MyISAM", SHOW_OPTION_YES, "Default engine as of MySQL 3.23 with great performance", @@ -82,12 +83,9 @@ handlerton myisam_hton= { myisam_create_handler, /* Create a new handler */ NULL, /* Drop a database */ mi_panic,/* Panic call */ - NULL, /* Release temporary latches */ - NULL, /* Update Statistics */ NULL, /* Start Consistent Snapshot */ NULL, /* Flush logs */ NULL, /* Show status */ - NULL, /* Replication Report Sent Binlog */ HTON_CAN_RECREATE }; diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc index 37dfe34b40c..1be4fb62fa1 100644 --- a/sql/ha_myisammrg.cc +++ b/sql/ha_myisammrg.cc @@ -37,6 +37,7 @@ static handler *myisammrg_create_handler(TABLE_SHARE *table); /* MyISAM MERGE handlerton */ handlerton myisammrg_hton= { + MYSQL_HANDLERTON_INTERFACE_VERSION, "MRG_MYISAM", SHOW_OPTION_YES, "Collection of identical MyISAM tables", @@ -60,12 +61,9 @@ handlerton myisammrg_hton= { myisammrg_create_handler, /* Create a new handler */ NULL, /* Drop a database */ myrg_panic, /* Panic call */ - NULL, /* Release temporary latches */ - NULL, /* Update Statistics */ NULL, /* Start Consistent Snapshot */ NULL, /* Flush logs */ NULL, /* Show status */ - NULL, /* Replication Report Sent Binlog */ HTON_CAN_RECREATE }; diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 050a6ea8af8..80d2ea2d8b1 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -59,6 +59,7 @@ static int ndbcluster_rollback(THD *thd, bool all); static handler* ndbcluster_create_handler(TABLE_SHARE *table); handlerton ndbcluster_hton = { + MYSQL_HANDLERTON_INTERFACE_VERSION, "ndbcluster", SHOW_OPTION_YES, "Clustered, fault-tolerant, memory-based tables", @@ -82,12 +83,9 @@ handlerton ndbcluster_hton = { ndbcluster_create_handler, /* Create a new handler */ ndbcluster_drop_database, /* Drop a database */ ndbcluster_end, /* Panic call */ - NULL, /* Release temporary latches */ - NULL, /* Update Statistics */ NULL, /* Start Consistent Snapshot */ NULL, /* Flush logs */ ndbcluster_show_status, /* Show status */ - NULL, /* Replication Report Sent Binlog */ HTON_NO_FLAGS }; @@ -8078,10 +8076,12 @@ ndbcluster_show_status(THD* thd, stat_print_fn *stat_print, Ndb::Free_list_usage tmp; tmp.m_name= 0; while (ndb->get_free_list_usage(&tmp)) { - my_snprintf(buf, sizeof(buf), + uint buflen= + my_snprintf(buf, sizeof(buf), "created=%u, free=%u, sizeof=%u", tmp.m_created, tmp.m_free, tmp.m_sizeof); - if (stat_print(thd, ndbcluster_hton.name, tmp.m_name, buf)) + if (stat_print(thd, ndbcluster_hton.name, strlen(ndbcluster_hton.name), + tmp.m_name, strlen(tmp.m_name), buf, buflen)) DBUG_RETURN(TRUE); } } diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index b0b4ac3fdcd..8b4e0d9cfee 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -69,6 +69,7 @@ static PARTITION_SHARE *get_share(const char *table_name, TABLE * table); static handler *partition_create_handler(TABLE_SHARE *share); handlerton partition_hton = { + MYSQL_HANDLERTON_INTERFACE_VERSION, "partition", SHOW_OPTION_YES, "Partition Storage Engine Helper", /* A comment used by SHOW to describe an engine */ @@ -92,12 +93,9 @@ handlerton partition_hton = { partition_create_handler, /* Create a new handler */ NULL, /* Drop a database */ NULL, /* Panic call */ - NULL, /* Release temporary latches */ - NULL, /* Update Statistics */ NULL, /* Start Consistent Snapshot */ NULL, /* Flush logs */ NULL, /* Show status */ - NULL, /* Replication Report Sent Binlog */ HTON_NOT_USER_SELECTABLE }; @@ -697,6 +695,7 @@ bool ha_partition::create_handler_file(const char *name) void ha_partition::clear_handler_file() { my_free((char*) m_file_buffer, MYF(MY_ALLOW_ZERO_PTR)); + my_free((char*) m_engine_array, MYF(MY_ALLOW_ZERO_PTR)); m_file_buffer= NULL; m_name_buffer_ptr= NULL; m_engine_array= NULL; @@ -715,18 +714,19 @@ bool ha_partition::create_handlers() for (i= 0; i < m_tot_parts; i++) { if (!(m_file[i]= get_new_handler(table_share, current_thd->mem_root, - (enum db_type) m_engine_array[i]))) + m_engine_array[i]))) DBUG_RETURN(TRUE); DBUG_PRINT("info", ("engine_type: %u", m_engine_array[i])); } m_file[m_tot_parts]= 0; /* For the moment we only support partition over the same table engine */ - if (m_engine_array[0] == (uchar) DB_TYPE_MYISAM) + if (m_engine_array[0] == &myisam_hton) { DBUG_PRINT("info", ("MyISAM")); m_myisam= TRUE; } - else if (m_engine_array[0] == (uchar) DB_TYPE_INNODB) + /* INNODB may not be compiled in... */ + else if (ha_legacy_type(m_engine_array[0]) == DB_TYPE_INNODB) { DBUG_PRINT("info", ("InnoDB")); m_innodb= TRUE; @@ -761,7 +761,7 @@ bool ha_partition::new_handlers_from_part_info() if (!(m_file[i]= get_new_handler(table_share, thd->mem_root, part_elem->engine_type))) goto error; - DBUG_PRINT("info", ("engine_type: %u", (uint) part_elem->engine_type)); + DBUG_PRINT("info", ("engine_type: %u", (uint) ha_legacy_type(part_elem->engine_type))); if (m_is_sub_partitioned) { for (j= 0; j < m_part_info->no_subparts; j++) @@ -769,11 +769,11 @@ bool ha_partition::new_handlers_from_part_info() if (!(m_file[i]= get_new_handler(table_share, thd->mem_root, part_elem->engine_type))) goto error; - DBUG_PRINT("info", ("engine_type: %u", (uint) part_elem->engine_type)); + DBUG_PRINT("info", ("engine_type: %u", (uint) ha_legacy_type(part_elem->engine_type))); } } } while (++i < m_part_info->no_parts); - if (part_elem->engine_type == DB_TYPE_MYISAM) + if (part_elem->engine_type == &myisam_hton) { DBUG_PRINT("info", ("MyISAM")); m_myisam= TRUE; @@ -795,7 +795,7 @@ bool ha_partition::get_from_handler_file(const char *name) char buff[FN_REFLEN], *address_tot_name_len; File file; char *file_buffer, *name_buffer_ptr; - uchar *engine_array; + handlerton **engine_array; uint i, len_bytes, len_words, tot_partition_words, tot_name_words, chksum; DBUG_ENTER("ha_partition::get_from_handler_file"); DBUG_PRINT("enter", ("table name: '%s'", name)); @@ -824,7 +824,11 @@ bool ha_partition::get_from_handler_file(const char *name) goto err2; m_tot_parts= uint4korr((file_buffer) + 8); tot_partition_words= (m_tot_parts + 3) / 4; - engine_array= (uchar *) ((file_buffer) + 12); + if (!(engine_array= (handlerton **) my_malloc(m_tot_parts * sizeof(handlerton*),MYF(0)))) + goto err2; + for (i= 0; i < m_tot_parts; i++) + engine_array[i]= ha_resolve_by_legacy_type(current_thd, + (enum legacy_db_type) *(uchar *) ((file_buffer) + 12 + i)); address_tot_name_len= file_buffer + 12 + 4 * tot_partition_words; tot_name_words= (uint4korr(address_tot_name_len) + 3) / 4; if (len_words != (tot_partition_words + tot_name_words + 4)) diff --git a/sql/ha_partition.h b/sql/ha_partition.h index a727a278103..760f99ad8aa 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -46,7 +46,7 @@ private: /* Data for the partition handler */ char *m_file_buffer; // Buffer with names char *m_name_buffer_ptr; // Pointer to first partition name - uchar *m_engine_array; // Array of types of the handlers + handlerton **m_engine_array; // Array of types of the handlers handler **m_file; // Array of references to handler inst. partition_info *m_part_info; // local reference to partition byte *m_start_key_ref; // Reference of start key in current diff --git a/sql/handler.cc b/sql/handler.cc index 7f825ffda35..1a6122aebbd 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -37,11 +37,32 @@ #ifdef WITH_PARTITION_STORAGE_ENGINE #include "ha_partition.h" #endif +#ifdef WITH_INNOBASE_STORAGE_ENGINE +#include "ha_innodb.h" +#endif extern handlerton *sys_table_types[]; - + /* static functions defined in this file */ +static handler *create_default(TABLE_SHARE *table); + +const handlerton default_hton = +{ + MYSQL_HANDLERTON_INTERFACE_VERSION, + "DEFAULT", + SHOW_OPTION_YES, + NULL, + DB_TYPE_DEFAULT, + NULL, + 0, 0, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, + create_default, + NULL, NULL, NULL, NULL, NULL, + HTON_NO_FLAGS +}; + static SHOW_COMP_OPTION have_yes= SHOW_OPTION_YES; /* number of entries in handlertons[] */ @@ -53,12 +74,12 @@ ulong savepoint_alloc_size; struct show_table_alias_st sys_table_aliases[]= { - {"INNOBASE", "InnoDB"}, - {"NDB", "NDBCLUSTER"}, - {"BDB", "BERKELEYDB"}, - {"HEAP", "MEMORY"}, - {"MERGE", "MRG_MYISAM"}, - {NullS, NullS} + {"INNOBASE", DB_TYPE_INNODB}, + {"NDB", DB_TYPE_NDBCLUSTER}, + {"BDB", DB_TYPE_BERKELEY_DB}, + {"HEAP", DB_TYPE_HEAP}, + {"MERGE", DB_TYPE_MRG_MYISAM}, + {NullS, DB_TYPE_UNKNOWN} }; const char *ha_row_type[] = { @@ -74,26 +95,22 @@ TYPELIB tx_isolation_typelib= {array_elements(tx_isolation_names)-1,"", static TYPELIB known_extensions= {0,"known_exts", NULL, NULL}; uint known_extensions_id= 0; -enum db_type ha_resolve_by_name(const char *name, uint namelen) +handlerton *ha_resolve_by_name(THD *thd, LEX_STRING *name) { - THD *thd= current_thd; show_table_alias_st *table_alias; - handlerton **types; + st_plugin_int *plugin; if (thd && !my_strnncoll(&my_charset_latin1, - (const uchar *)name, namelen, + (const uchar *)name->str, name->length, (const uchar *)"DEFAULT", 7)) - return (enum db_type) thd->variables.table_type; + return ha_resolve_by_legacy_type(thd, DB_TYPE_DEFAULT); -retest: - for (types= sys_table_types; *types; types++) + if ((plugin= plugin_lock(name, MYSQL_STORAGE_ENGINE_PLUGIN))) { - if ((!my_strnncoll(&my_charset_latin1, - (const uchar *)name, namelen, - (const uchar *)(*types)->name, - strlen((*types)->name))) && - !((*types)->flags & HTON_NOT_USER_SELECTABLE)) - return (enum db_type) (*types)->db_type; + handlerton *hton= (handlerton *) plugin->plugin->info; + if (!(hton->flags & HTON_NOT_USER_SELECTABLE)) + return hton; + plugin_unlock(plugin); } /* @@ -102,63 +119,99 @@ retest: for (table_alias= sys_table_aliases; table_alias->type; table_alias++) { if (!my_strnncoll(&my_charset_latin1, - (const uchar *)name, namelen, + (const uchar *)name->str, name->length, (const uchar *)table_alias->alias, strlen(table_alias->alias))) - { - name= table_alias->type; - namelen= strlen(name); - goto retest; - } + return ha_resolve_by_legacy_type(thd, table_alias->type); } - return DB_TYPE_UNKNOWN; + return NULL; } -const char *ha_get_storage_engine(enum db_type db_type) +struct plugin_find_dbtype_st { - handlerton **types; - for (types= sys_table_types; *types; types++) + enum legacy_db_type db_type; + handlerton *hton; +}; + + +static my_bool plugin_find_dbtype(THD *unused, st_plugin_int *plugin, + void *arg) +{ + handlerton *types= (handlerton *) plugin->plugin->info; + if (types->db_type == ((struct plugin_find_dbtype_st *)arg)->db_type) { - if (db_type == (*types)->db_type) - return (*types)->name; + ((struct plugin_find_dbtype_st *)arg)->hton= types; + return TRUE; } - return "*NONE*"; + return FALSE; } -bool ha_check_storage_engine_flag(enum db_type db_type, uint32 flag) +const char *ha_get_storage_engine(enum legacy_db_type db_type) { - handlerton **types; - for (types= sys_table_types; *types; types++) + struct plugin_find_dbtype_st info; + + switch (db_type) { - if (db_type == (*types)->db_type) - return test((*types)->flags & flag); + case DB_TYPE_DEFAULT: + return "DEFAULT"; + case DB_TYPE_UNKNOWN: + return "UNKNOWN"; + default: + info.db_type= db_type; + + if (!plugin_foreach(NULL, plugin_find_dbtype, + MYSQL_STORAGE_ENGINE_PLUGIN, &info)) + return "*NONE*"; + + return info.hton->name; } - return FALSE; // No matching engine } -my_bool ha_storage_engine_is_enabled(enum db_type database_type) +static handler *create_default(TABLE_SHARE *table) { - handlerton **types; - for (types= sys_table_types; *types; types++) + handlerton *hton=ha_resolve_by_legacy_type(current_thd, DB_TYPE_DEFAULT); + return (hton && hton != &default_hton && hton->create) ? + hton->create(table) : NULL; +} + + +handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type) +{ + struct plugin_find_dbtype_st info; + + switch (db_type) { - if (database_type == (*types)->db_type) - return ((*types)->state == SHOW_OPTION_YES) ? TRUE : FALSE; + case DB_TYPE_DEFAULT: + return (thd->variables.table_type != NULL) ? + thd->variables.table_type : + (global_system_variables.table_type != NULL ? + global_system_variables.table_type : &myisam_hton); + case DB_TYPE_UNKNOWN: + return NULL; + default: + info.db_type= db_type; + if (!plugin_foreach(NULL, plugin_find_dbtype, + MYSQL_STORAGE_ENGINE_PLUGIN, &info)) + return NULL; + + return info.hton; } - return FALSE; } /* Use other database handler if databasehandler is not compiled in */ -enum db_type ha_checktype(THD *thd, enum db_type database_type, +handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type, bool no_substitute, bool report_error) { - if (ha_storage_engine_is_enabled(database_type)) - return database_type; + handlerton *hton= ha_resolve_by_legacy_type(thd, database_type); + if (ha_storage_engine_is_enabled(hton)) + return hton; + if (no_substitute) { if (report_error) @@ -166,34 +219,28 @@ enum db_type ha_checktype(THD *thd, enum db_type database_type, const char *engine_name= ha_get_storage_engine(database_type); my_error(ER_FEATURE_DISABLED,MYF(0),engine_name,engine_name); } - return DB_TYPE_UNKNOWN; + return NULL; } switch (database_type) { #ifndef NO_HASH case DB_TYPE_HASH: - return (database_type); + return ha_resolve_by_legacy_type(thd, DB_TYPE_HASH); #endif case DB_TYPE_MRG_ISAM: - return (DB_TYPE_MRG_MYISAM); + return ha_resolve_by_legacy_type(thd, DB_TYPE_MRG_MYISAM); default: break; } - - return ((enum db_type) thd->variables.table_type != DB_TYPE_UNKNOWN ? - (enum db_type) thd->variables.table_type : - ((enum db_type) global_system_variables.table_type != - DB_TYPE_UNKNOWN ? - (enum db_type) global_system_variables.table_type : DB_TYPE_MYISAM) - ); + + return ha_resolve_by_legacy_type(thd, DB_TYPE_DEFAULT); } /* ha_checktype */ handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc, - enum db_type db_type) + handlerton *db_type) { handler *file= NULL; - handlerton **types; /* handlers are allocated with new in the handlerton create() function we need to set the thd mem_root for these to be allocated correctly @@ -201,20 +248,15 @@ handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc, THD *thd= current_thd; MEM_ROOT *thd_save_mem_root= thd->mem_root; thd->mem_root= alloc; - for (types= sys_table_types; *types; types++) - { - if (db_type == (*types)->db_type && (*types)->create) - { - file= ((*types)->state == SHOW_OPTION_YES) ? - (*types)->create(share) : NULL; - break; - } - } + + if (db_type != NULL && db_type->state == SHOW_OPTION_YES && db_type->create) + file= db_type->create(share); + thd->mem_root= thd_save_mem_root; if (!file) { - enum db_type def=(enum db_type) current_thd->variables.table_type; + handlerton *def= current_thd->variables.table_type; /* Try first with 'default table type' */ if (db_type != def) return get_new_handler(share, alloc, def); @@ -341,16 +383,72 @@ static int ha_finish_errors(void) } -static inline void ha_was_inited_ok(handlerton **ht) +static void ha_was_inited_ok(handlerton *ht) { - uint tmp= (*ht)->savepoint_offset; - (*ht)->savepoint_offset= savepoint_alloc_size; + uint tmp= ht->savepoint_offset; + ht->savepoint_offset= savepoint_alloc_size; savepoint_alloc_size+= tmp; - (*ht)->slot= total_ha++; - if ((*ht)->prepare) + ht->slot= total_ha++; + if (ht->prepare) total_ha_2pc++; } + +int ha_initialize_handlerton(handlerton *hton) +{ + DBUG_ENTER("ha_initialize_handlerton"); + + if (hton == NULL) + DBUG_RETURN(1); + + /* check major version */ + if ((hton->interface_version>>24) != (MYSQL_HANDLERTON_INTERFACE_VERSION>>24)) + { + sql_print_error("handlerton major version incompatible"); + DBUG_PRINT("warning", ("handlerton major version incompatible")); + DBUG_RETURN(1); + } + + /* check minor version */ + if ((hton->interface_version>>16)&0xff < + (MYSQL_HANDLERTON_INTERFACE_VERSION>>16)&0xff) + { + sql_print_error("handlerton minor version incompatible"); + DBUG_PRINT("warning", ("handlerton minor version incompatible")); + DBUG_RETURN(1); + } + + switch (hton->state) + { + case SHOW_OPTION_NO: + break; + case SHOW_OPTION_YES: + if (!hton->init || !hton->init()) + { + ha_was_inited_ok(hton); + break; + } + /* fall through */ + default: + hton->state= SHOW_OPTION_DISABLED; + break; + } + DBUG_RETURN(0); +} + + +static my_bool init_handlerton(THD *unused1, st_plugin_int *plugin, + void *unused2) +{ + if (plugin->state == PLUGIN_IS_UNINITIALIZED) + { + ha_initialize_handlerton((handlerton *) plugin->plugin->info); + plugin->state= PLUGIN_IS_READY; + } + return FALSE; +} + + int ha_init() { int error= 0; @@ -361,16 +459,8 @@ int ha_init() if (ha_init_errors()) return 1; - /* - We now initialize everything here. - */ - for (types= sys_table_types; *types; types++) - { - if (!(*types)->init || !(*types)->init()) - ha_was_inited_ok(types); - else - (*types)->state= SHOW_OPTION_DISABLED; - } + if (plugin_foreach(NULL, init_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, 0)) + return 1; DBUG_ASSERT(total_ha < MAX_HA); /* @@ -383,43 +473,97 @@ int ha_init() return error; } + +int ha_register_builtin_plugins() +{ + handlerton **hton; + uint size= 0; + struct st_mysql_plugin *plugin; + DBUG_ENTER("ha_register_builtin_plugins"); + + for (hton= sys_table_types; *hton; hton++) + size+= sizeof(struct st_mysql_plugin); + + if (!(plugin= (struct st_mysql_plugin *) + my_once_alloc(size, MYF(MY_WME | MY_ZEROFILL)))) + DBUG_RETURN(1); + + for (hton= sys_table_types; *hton; hton++, plugin++) + { + plugin->type= MYSQL_STORAGE_ENGINE_PLUGIN; + plugin->info= *hton; + plugin->version= 0; + plugin->name= (*hton)->name; + plugin->author= NULL; + plugin->descr= (*hton)->comment; + + if (plugin_register_builtin(plugin)) + DBUG_RETURN(1); + } + DBUG_RETURN(0); +} + + + + /* close, flush or restart databases */ /* Ignore this for other databases than ours */ -int ha_panic(enum ha_panic_function flag) +static my_bool panic_handlerton(THD *unused1, st_plugin_int *plugin, + void *arg) { - int error=0; - handlerton **types; + handlerton *hton= (handlerton *) plugin->plugin->info; + if (hton->state == SHOW_OPTION_YES && hton->panic) + ((int*)arg)[0]|= hton->panic((enum ha_panic_function)((int*)arg)[1]); + return FALSE; +} - for (types= sys_table_types; *types; types++) - { - if ((*types)->state == SHOW_OPTION_YES && (*types)->panic) - error|= (*types)->panic(flag); - } - if (ha_finish_errors()) - error= 1; - return error; + +int ha_panic(enum ha_panic_function flag) +{ + int error[2]; + + error[0]= 0; error[1]= (int)flag; + plugin_foreach(NULL, panic_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, error); + + if (flag == HA_PANIC_CLOSE && ha_finish_errors()) + error[0]= 1; + return error[0]; } /* ha_panic */ +static my_bool dropdb_handlerton(THD *unused1, st_plugin_int *plugin, + void *path) +{ + handlerton *hton= (handlerton *) plugin->plugin->info; + if (hton->state == SHOW_OPTION_YES && hton->drop_database) + hton->drop_database((char *)path); + return FALSE; +} + + void ha_drop_database(char* path) { - handlerton **types; + plugin_foreach(NULL, dropdb_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, path); +} - for (types= sys_table_types; *types; types++) - { - if ((*types)->state == SHOW_OPTION_YES && (*types)->drop_database) - (*types)->drop_database(path); - } + +static my_bool closecon_handlerton(THD *thd, st_plugin_int *plugin, + void *unused) +{ + handlerton *hton= (handlerton *) plugin->plugin->info; + /* there's no need to rollback here as all transactions must + be rolled back already */ + if (hton->state == SHOW_OPTION_YES && hton->close_connection && + thd->ha_data[hton->slot]) + hton->close_connection(thd); + return FALSE; } + /* don't bother to rollback here, it's done already */ void ha_close_connection(THD* thd) { - handlerton **types; - for (types= sys_table_types; *types; types++) - /* XXX Maybe do a rollback if close_connection == NULL ? */ - if (thd->ha_data[(*types)->slot] && (*types)->close_connection) - (*types)->close_connection(thd); + plugin_foreach(thd, closecon_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, 0); } /* ======================================================================== @@ -729,21 +873,46 @@ int ha_autocommit_or_rollback(THD *thd, int error) } -int ha_commit_or_rollback_by_xid(XID *xid, bool commit) +struct xahton_st { + XID *xid; + int result; +}; + +static my_bool xacommit_handlerton(THD *unused1, st_plugin_int *plugin, + void *arg) { - handlerton **types; - int res= 1; + handlerton *hton= (handlerton *) plugin->plugin->info; + if (hton->state == SHOW_OPTION_YES && hton->recover) + { + hton->commit_by_xid(((struct xahton_st *)arg)->xid); + ((struct xahton_st *)arg)->result= 0; + } + return FALSE; +} - for (types= sys_table_types; *types; types++) +static my_bool xarollback_handlerton(THD *unused1, st_plugin_int *plugin, + void *arg) +{ + handlerton *hton= (handlerton *) plugin->plugin->info; + if (hton->state == SHOW_OPTION_YES && hton->recover) { - if ((*types)->state == SHOW_OPTION_YES && (*types)->recover) - { - if ((*(commit ? (*types)->commit_by_xid : - (*types)->rollback_by_xid))(xid)); - res= 0; - } + hton->rollback_by_xid(((struct xahton_st *)arg)->xid); + ((struct xahton_st *)arg)->result= 0; } - return res; + return FALSE; +} + + +int ha_commit_or_rollback_by_xid(XID *xid, bool commit) +{ + struct xahton_st xaop; + xaop.xid= xid; + xaop.result= 1; + + plugin_foreach(NULL, commit ? xacommit_handlerton : xarollback_handlerton, + MYSQL_STORAGE_ENGINE_PLUGIN, &xaop); + + return xaop.result; } @@ -819,99 +988,123 @@ static char* xid_to_str(char *buf, XID *xid) in this case commit_list==0, tc_heuristic_recover == 0 there should be no prepared transactions in this case. */ -int ha_recover(HASH *commit_list) -{ - int len, got, found_foreign_xids=0, found_my_xids=0; - handlerton **types; - XID *list=0; - bool dry_run=(commit_list==0 && tc_heuristic_recover==0); - DBUG_ENTER("ha_recover"); - /* commit_list and tc_heuristic_recover cannot be set both */ - DBUG_ASSERT(commit_list==0 || tc_heuristic_recover==0); - /* if either is set, total_ha_2pc must be set too */ - DBUG_ASSERT(dry_run || total_ha_2pc>(ulong)opt_bin_log); - - if (total_ha_2pc <= (ulong)opt_bin_log) - DBUG_RETURN(0); - - if (commit_list) - sql_print_information("Starting crash recovery..."); - -#ifndef WILL_BE_DELETED_LATER - /* - for now, only InnoDB supports 2pc. It means we can always safely - rollback all pending transactions, without risking inconsistent data - */ - DBUG_ASSERT(total_ha_2pc == (ulong) opt_bin_log+1); // only InnoDB and binlog - tc_heuristic_recover= TC_HEURISTIC_RECOVER_ROLLBACK; // forcing ROLLBACK - dry_run=FALSE; -#endif - - for (len= MAX_XID_LIST_SIZE ; list==0 && len > MIN_XID_LIST_SIZE; len/=2) - { - list=(XID *)my_malloc(len*sizeof(XID), MYF(0)); - } - if (!list) - { - sql_print_error(ER(ER_OUTOFMEMORY), len*sizeof(XID)); - DBUG_RETURN(1); - } +struct xarecover_st +{ + int len, found_foreign_xids, found_my_xids; + XID *list; + HASH *commit_list; + bool dry_run; +}; - for (types= sys_table_types; *types; types++) +static my_bool xarecover_handlerton(THD *unused, st_plugin_int *plugin, + void *arg) +{ + handlerton *hton= (handlerton *) plugin->plugin->info; + struct xarecover_st *info= (struct xarecover_st *) arg; + int got; + + if (hton->state == SHOW_OPTION_YES && hton->recover) { - if ((*types)->state != SHOW_OPTION_YES || !(*types)->recover) - continue; - while ((got=(*(*types)->recover)(list, len)) > 0 ) + while ((got= hton->recover(info->list, info->len)) > 0 ) { sql_print_information("Found %d prepared transaction(s) in %s", - got, (*types)->name); + got, hton->name); for (int i=0; i < got; i ++) { - my_xid x=list[i].get_my_xid(); + my_xid x=info->list[i].get_my_xid(); if (!x) // not "mine" - that is generated by external TM { #ifndef DBUG_OFF char buf[XIDDATASIZE*4+6]; // see xid_to_str - sql_print_information("ignore xid %s", xid_to_str(buf, list+i)); + sql_print_information("ignore xid %s", xid_to_str(buf, info->list+i)); #endif - xid_cache_insert(list+i, XA_PREPARED); - found_foreign_xids++; + xid_cache_insert(info->list+i, XA_PREPARED); + info->found_foreign_xids++; continue; } - if (dry_run) + if (info->dry_run) { - found_my_xids++; + info->found_my_xids++; continue; } // recovery mode - if (commit_list ? - hash_search(commit_list, (byte *)&x, sizeof(x)) != 0 : + if (info->commit_list ? + hash_search(info->commit_list, (byte *)&x, sizeof(x)) != 0 : tc_heuristic_recover == TC_HEURISTIC_RECOVER_COMMIT) { #ifndef DBUG_OFF char buf[XIDDATASIZE*4+6]; // see xid_to_str - sql_print_information("commit xid %s", xid_to_str(buf, list+i)); + sql_print_information("commit xid %s", xid_to_str(buf, info->list+i)); #endif - (*(*types)->commit_by_xid)(list+i); + hton->commit_by_xid(info->list+i); } else { #ifndef DBUG_OFF char buf[XIDDATASIZE*4+6]; // see xid_to_str - sql_print_information("rollback xid %s", xid_to_str(buf, list+i)); + sql_print_information("rollback xid %s", + xid_to_str(buf, info->list+i)); #endif - (*(*types)->rollback_by_xid)(list+i); + hton->rollback_by_xid(info->list+i); } } - if (got < len) + if (got < info->len) break; } } - my_free((gptr)list, MYF(0)); - if (found_foreign_xids) - sql_print_warning("Found %d prepared XA transactions", found_foreign_xids); - if (dry_run && found_my_xids) + return FALSE; +} + +int ha_recover(HASH *commit_list) +{ + struct xarecover_st info; + DBUG_ENTER("ha_recover"); + info.found_foreign_xids= info.found_my_xids= 0; + info.commit_list= commit_list; + info.dry_run= (info.commit_list==0 && tc_heuristic_recover==0); + info.list= NULL; + + /* commit_list and tc_heuristic_recover cannot be set both */ + DBUG_ASSERT(info.commit_list==0 || tc_heuristic_recover==0); + /* if either is set, total_ha_2pc must be set too */ + DBUG_ASSERT(info.dry_run || total_ha_2pc>(ulong)opt_bin_log); + + if (total_ha_2pc <= (ulong)opt_bin_log) + DBUG_RETURN(0); + + if (info.commit_list) + sql_print_information("Starting crash recovery..."); + +#ifndef WILL_BE_DELETED_LATER + /* + for now, only InnoDB supports 2pc. It means we can always safely + rollback all pending transactions, without risking inconsistent data + */ + DBUG_ASSERT(total_ha_2pc == (ulong) opt_bin_log+1); // only InnoDB and binlog + tc_heuristic_recover= TC_HEURISTIC_RECOVER_ROLLBACK; // forcing ROLLBACK + info.dry_run=FALSE; +#endif + + for (info.len= MAX_XID_LIST_SIZE ; + info.list==0 && info.len > MIN_XID_LIST_SIZE; info.len/=2) + { + info.list=(XID *)my_malloc(info.len*sizeof(XID), MYF(0)); + } + if (!info.list) + { + sql_print_error(ER(ER_OUTOFMEMORY), info.len*sizeof(XID)); + DBUG_RETURN(1); + } + + plugin_foreach(NULL, xarecover_handlerton, + MYSQL_STORAGE_ENGINE_PLUGIN, &info); + + my_free((gptr)info.list, MYF(0)); + if (info.found_foreign_xids) + sql_print_warning("Found %d prepared XA transactions", + info.found_foreign_xids); + if (info.dry_run && info.found_my_xids) { sql_print_error("Found %d prepared transactions! It means that mysqld was " "not shut down properly last time and critical recovery " @@ -919,10 +1112,10 @@ int ha_recover(HASH *commit_list) "after a crash. You have to start mysqld with " "--tc-heuristic-recover switch to commit or rollback " "pending transactions.", - found_my_xids, opt_tc_log_file); + info.found_my_xids, opt_tc_log_file); DBUG_RETURN(1); } - if (commit_list) + if (info.commit_list) sql_print_information("Crash recovery finished."); DBUG_RETURN(0); } @@ -995,32 +1188,17 @@ bool mysql_xa_recover(THD *thd) int ha_release_temporary_latches(THD *thd) { - handlerton **types; - - for (types= sys_table_types; *types; types++) - { - if ((*types)->state == SHOW_OPTION_YES && - (*types)->release_temporary_latches) - (*types)->release_temporary_latches(thd); - } - return 0; +#ifdef WITH_INNOBASE_STORAGE_ENGINE + innobase_release_temporary_latches(thd); +#endif } -/* - Export statistics for different engines. Currently we use it only for - InnoDB. -*/ - int ha_update_statistics() { - handlerton **types; - - for (types= sys_table_types; *types; types++) - { - if ((*types)->state == SHOW_OPTION_YES && (*types)->update_statistics) - (*types)->update_statistics(); - } +#ifdef WITH_INNOBASE_STORAGE_ENGINE + innodb_export_status(); +#endif return 0; } @@ -1129,20 +1307,25 @@ int ha_release_savepoint(THD *thd, SAVEPOINT *sv) } +static my_bool snapshot_handlerton(THD *thd, st_plugin_int *plugin, + void *arg) +{ + handlerton *hton= (handlerton *) plugin->plugin->info; + if (hton->state == SHOW_OPTION_YES && + hton->start_consistent_snapshot) + { + hton->start_consistent_snapshot(thd); + *((bool *)arg)= false; + } + return FALSE; +} + int ha_start_consistent_snapshot(THD *thd) { bool warn= true; - handlerton **types; - for (types= sys_table_types; *types; types++) - { - if ((*types)->state == SHOW_OPTION_YES && - (*types)->start_consistent_snapshot) - { - (*types)->start_consistent_snapshot(thd); - warn= false; /* hope user is using engine */ - } - } + plugin_foreach(thd, snapshot_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, &warn); + /* Same idea as when one wants to CREATE TABLE in one engine which does not exist: @@ -1155,22 +1338,31 @@ int ha_start_consistent_snapshot(THD *thd) } -bool ha_flush_logs(enum db_type db_type) +static my_bool flush_handlerton(THD *thd, st_plugin_int *plugin, + void *arg) { - bool result=0; - handlerton **types; + handlerton *hton= (handlerton *) plugin->plugin->info; + if (hton->state == SHOW_OPTION_YES && hton->flush_logs && hton->flush_logs()) + return TRUE; + return FALSE; +} + - for (types= sys_table_types; *types; types++) +bool ha_flush_logs(handlerton *db_type) +{ + if (db_type == NULL) { - if ((*types)->state == SHOW_OPTION_YES && - (db_type == DB_TYPE_DEFAULT || db_type == (*types)->db_type) && - (*types)->flush_logs) - { - if ((*types)->flush_logs()) - result= 1; - } + if (plugin_foreach(NULL, flush_handlerton, + MYSQL_STORAGE_ENGINE_PLUGIN, 0)) + return TRUE; } - return result; + else + { + if (db_type->state != SHOW_OPTION_YES || + (db_type->flush_logs && db_type->flush_logs())) + return TRUE; + } + return FALSE; } /* @@ -1178,7 +1370,7 @@ bool ha_flush_logs(enum db_type db_type) The .frm file will be deleted only if we return 0 or ENOENT */ -int ha_delete_table(THD *thd, enum db_type table_type, const char *path, +int ha_delete_table(THD *thd, handlerton *table_type, const char *path, const char *db, const char *alias, bool generate_warning) { handler *file; @@ -1193,7 +1385,7 @@ int ha_delete_table(THD *thd, enum db_type table_type, const char *path, dummy_table.s= &dummy_share; /* DB_TYPE_UNKNOWN is used in ALTER TABLE when renaming only .frm files */ - if (table_type == DB_TYPE_UNKNOWN || + if (table_type == NULL || ! (file=get_new_handler(&dummy_share, thd->mem_root, table_type))) DBUG_RETURN(ENOENT); @@ -2486,40 +2678,50 @@ int handler::index_read_idx(byte * buf, uint index, const byte * key, pointer pointer to TYPELIB structure */ +static my_bool exts_handlerton(THD *unused, st_plugin_int *plugin, + void *arg) +{ + List<char> *found_exts= (List<char> *) arg; + handlerton *hton= (handlerton *) plugin->plugin->info; + handler *file; + if (hton->state == SHOW_OPTION_YES && hton->create && + (file= hton->create((TABLE_SHARE*) 0))) + { + List_iterator_fast<char> it(*found_exts); + const char **ext, *old_ext; + + for (ext= file->bas_ext(); *ext; ext++) + { + while ((old_ext= it++)) + { + if (!strcmp(old_ext, *ext)) + break; + } + if (!old_ext) + found_exts->push_back((char *) *ext); + + it.rewind(); + } + delete file; + } + return FALSE; +} + TYPELIB *ha_known_exts(void) { MEM_ROOT *mem_root= current_thd->mem_root; if (!known_extensions.type_names || mysys_usage_id != known_extensions_id) { - handlerton **types; List<char> found_exts; - List_iterator_fast<char> it(found_exts); const char **ext, *old_ext; known_extensions_id= mysys_usage_id; found_exts.push_back((char*) triggers_file_ext); found_exts.push_back((char*) trigname_file_ext); - for (types= sys_table_types; *types; types++) - { - if ((*types)->state == SHOW_OPTION_YES) - { - handler *file= get_new_handler((TABLE_SHARE*) 0, mem_root, - (enum db_type) (*types)->db_type); - for (ext= file->bas_ext(); *ext; ext++) - { - while ((old_ext= it++)) - { - if (!strcmp(old_ext, *ext)) - break; - } - if (!old_ext) - found_exts.push_back((char *) *ext); - - it.rewind(); - } - delete file; - } - } + + plugin_foreach(NULL, exts_handlerton, + MYSQL_STORAGE_ENGINE_PLUGIN, &found_exts); + ext= (const char **) my_once_alloc(sizeof(char *)* (found_exts.elements+1), MYF(MY_WME | MY_FAE)); @@ -2528,6 +2730,7 @@ TYPELIB *ha_known_exts(void) known_extensions.count= found_exts.elements; known_extensions.type_names= ext; + List_iterator_fast<char> it(found_exts); while ((old_ext= it++)) *ext++= old_ext; *ext= 0; @@ -2535,24 +2738,37 @@ TYPELIB *ha_known_exts(void) return &known_extensions; } -static bool stat_print(THD *thd, const char *type, const char *file, - const char *status) +static bool stat_print(THD *thd, const char *type, uint type_len, + const char *file, uint file_len, + const char *status, uint status_len) { Protocol *protocol= thd->protocol; protocol->prepare_for_resend(); - protocol->store(type, system_charset_info); - protocol->store(file, system_charset_info); - protocol->store(status, system_charset_info); + protocol->store(type, type_len, system_charset_info); + protocol->store(file, file_len, system_charset_info); + protocol->store(status, status_len, system_charset_info); if (protocol->write()) return TRUE; return FALSE; } -bool ha_show_status(THD *thd, enum db_type db_type, enum ha_stat_type stat) + +static my_bool showstat_handlerton(THD *thd, st_plugin_int *plugin, + void *arg) +{ + enum ha_stat_type stat= *(enum ha_stat_type *) arg; + handlerton *hton= (handlerton *) plugin->plugin->info; + if (hton->state == SHOW_OPTION_YES && hton->show_status && + hton->show_status(thd, stat_print, stat)) + return TRUE; + return FALSE; +} + +bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat) { - handlerton **types; List<Item> field_list; Protocol *protocol= thd->protocol; + bool result; field_list.push_back(new Item_empty_string("Type",10)); field_list.push_back(new Item_empty_string("Name",FN_REFLEN)); @@ -2562,25 +2778,24 @@ bool ha_show_status(THD *thd, enum db_type db_type, enum ha_stat_type stat) Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) return TRUE; - for (types= sys_table_types; *types; types++) + if (db_type == NULL) { - if ((*types)->state == SHOW_OPTION_YES && - (db_type == DB_TYPE_DEFAULT || db_type == (*types)->db_type) && - (*types)->show_status) - { - if ((*types)->show_status(thd, stat_print, stat)) - return TRUE; - } - else if (db_type == (*types)->db_type && - (*types)->state != SHOW_OPTION_YES) - { - if (stat_print(thd, (*types)->name, "", "DISABLED")) - return TRUE; - } + result= plugin_foreach(thd, showstat_handlerton, + MYSQL_STORAGE_ENGINE_PLUGIN, &stat); + } + else + { + if (db_type->state != SHOW_OPTION_YES) + result= stat_print(thd, db_type->name, strlen(db_type->name), + "", 0, "DISABLED", 8) ? 1 : 0; + else + result= db_type->show_status && + db_type->show_status(thd, stat_print, stat) ? 1 : 0; } - send_eof(thd); - return FALSE; + if (!result) + send_eof(thd); + return result; } @@ -2606,19 +2821,10 @@ bool ha_show_status(THD *thd, enum db_type db_type, enum ha_stat_type stat) int ha_repl_report_sent_binlog(THD *thd, char *log_file_name, my_off_t end_offset) { - int result= 0; - handlerton **types; - - for (types= sys_table_types; *types; types++) - { - if ((*types)->state == SHOW_OPTION_YES && - (*types)->repl_report_sent_binlog) - { - (*types)->repl_report_sent_binlog(thd,log_file_name,end_offset); - result= 0; - } - } - return result; +#ifdef WITH_INNOBASE_STORAGE_ENGINE + innobase_repl_report_sent_binlog(thd, log_file_name, end_offset); +#endif + return 0; } @@ -2643,3 +2849,4 @@ int ha_repl_report_replication_stop(THD *thd) return 0; } #endif /* HAVE_REPLICATION */ + diff --git a/sql/handler.h b/sql/handler.h index 5674698487c..69f5f0a7efc 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -178,7 +178,7 @@ /* Options of START TRANSACTION statement (and later of SET TRANSACTION stmt) */ #define MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT 1 -enum db_type +enum legacy_db_type { DB_TYPE_UNKNOWN=0,DB_TYPE_DIAB_ISAM=1, DB_TYPE_HASH,DB_TYPE_MISAM,DB_TYPE_PISAM, @@ -191,7 +191,7 @@ enum db_type DB_TYPE_BLACKHOLE_DB, DB_TYPE_PARTITION_DB, DB_TYPE_BINLOG, - DB_TYPE_DEFAULT // Must be last + DB_TYPE_DEFAULT=127 // Must be last }; enum row_type { ROW_TYPE_NOT_USED=-1, ROW_TYPE_DEFAULT, ROW_TYPE_FIXED, @@ -315,8 +315,9 @@ typedef struct st_table TABLE; typedef struct st_table_share TABLE_SHARE; struct st_foreign_key_info; typedef struct st_foreign_key_info FOREIGN_KEY_INFO; -typedef bool (stat_print_fn)(THD *thd, const char *type, const char *file, - const char *status); +typedef bool (stat_print_fn)(THD *thd, const char *type, uint type_len, + const char *file, uint file_len, + const char *status, uint status_len); enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX }; /* @@ -333,6 +334,13 @@ enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX }; typedef struct { /* + handlerton structure version + */ + const int interface_version; +#define MYSQL_HANDLERTON_INTERFACE_VERSION 0x00000000 + + + /* storage engine name as it should be printed to a user */ const char *name; @@ -351,7 +359,7 @@ typedef struct Historical number used for frm file to determine the correct storage engine. This is going away and new engines will just use "name" for this. */ - enum db_type db_type; + enum legacy_db_type db_type; /* Method that initizlizes a storage engine */ @@ -416,19 +424,17 @@ typedef struct handler *(*create)(TABLE_SHARE *table); void (*drop_database)(char* path); int (*panic)(enum ha_panic_function flag); - int (*release_temporary_latches)(THD *thd); - int (*update_statistics)(); int (*start_consistent_snapshot)(THD *thd); bool (*flush_logs)(); bool (*show_status)(THD *thd, stat_print_fn *print, enum ha_stat_type stat); - int (*repl_report_sent_binlog)(THD *thd, char *log_file_name, - my_off_t end_offset); uint32 flags; /* global handler flags */ } handlerton; +extern const handlerton default_hton; + struct show_table_alias_st { const char *alias; - const char *type; + enum legacy_db_type type; }; /* Possible flags of a handlerton */ @@ -496,7 +502,7 @@ public: char* part_comment; char* data_file_name; char* index_file_name; - enum db_type engine_type; + handlerton *engine_type; enum partition_state part_state; uint16 nodegroup_id; @@ -504,7 +510,7 @@ public: : part_max_rows(0), part_min_rows(0), partition_name(NULL), tablespace_name(NULL), range_value(0), part_comment(NULL), data_file_name(NULL), index_file_name(NULL), - engine_type(DB_TYPE_UNKNOWN),part_state(PART_NORMAL), + engine_type(NULL),part_state(PART_NORMAL), nodegroup_id(UNDEF_NODEGROUP) { subpartitions.empty(); @@ -567,7 +573,7 @@ public: key_map all_fields_in_PF, all_fields_in_PPF, all_fields_in_SPF; key_map some_fields_in_PF; - enum db_type default_engine_type; + handlerton *default_engine_type; Item_result part_result_type; partition_type part_type; partition_type subpart_type; @@ -608,7 +614,7 @@ public: part_info_string(NULL), part_func_string(NULL), subpart_func_string(NULL), curr_part_elem(NULL), current_partition(NULL), - default_engine_type(DB_TYPE_UNKNOWN), + default_engine_type(NULL), part_result_type(INT_RESULT), part_type(NOT_A_PARTITION), subpart_type(NOT_A_PARTITION), part_info_len(0), part_func_len(0), subpart_func_len(0), @@ -683,7 +689,7 @@ typedef struct st_ha_create_information ulong raid_chunksize; ulong used_fields; SQL_LIST merge_list; - enum db_type db_type; + handlerton *db_type; enum row_type row_type; uint null_bits; /* NULL bits at start of record */ uint options; /* OR of HA_CREATE_ options */ @@ -730,7 +736,7 @@ int get_parts_for_update(const byte *old_data, byte *new_data, uint32 *old_part_id, uint32 *new_part_id); int get_part_for_delete(const byte *buf, const byte *rec0, partition_info *part_info, uint32 *part_id); -bool check_partition_info(partition_info *part_info,enum db_type eng_type, +bool check_partition_info(partition_info *part_info,handlerton *eng_type, handler *file, ulonglong max_rows); bool fix_partition_func(THD *thd, const char *name, TABLE *table); char *generate_partition_syntax(partition_info *part_info, @@ -746,7 +752,7 @@ void get_full_part_id_from_key(const TABLE *table, byte *buf, part_id_range *part_spec); bool mysql_unpack_partition(THD *thd, const uchar *part_buf, uint part_info_len, TABLE *table, - enum db_type default_db_type); + handlerton *default_db_type); #endif @@ -1416,32 +1422,56 @@ extern ulong total_ha, total_ha_2pc; #define ha_rollback(thd) (ha_rollback_trans((thd), TRUE)) /* lookups */ -enum db_type ha_resolve_by_name(const char *name, uint namelen); -const char *ha_get_storage_engine(enum db_type db_type); +handlerton *ha_resolve_by_name(THD *thd, LEX_STRING *name); +handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type); +const char *ha_get_storage_engine(enum legacy_db_type db_type); handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc, - enum db_type db_type); -enum db_type ha_checktype(THD *thd, enum db_type database_type, + handlerton *db_type); +handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type, bool no_substitute, bool report_error); -bool ha_check_storage_engine_flag(enum db_type db_type, uint32 flag); + + +inline enum legacy_db_type ha_legacy_type(const handlerton *db_type) +{ + return (db_type == NULL) ? DB_TYPE_UNKNOWN : db_type->db_type; +} + +inline const char *ha_resolve_storage_engine_name(const handlerton *db_type) +{ + return db_type == NULL ? "UNKNOWN" : db_type->name; +} + +inline bool ha_check_storage_engine_flag(const handlerton *db_type, uint32 flag) +{ + return db_type == NULL ? FALSE : test(db_type->flags & flag); +} + +inline bool ha_storage_engine_is_enabled(const handlerton *db_type) +{ + return (db_type && db_type->create) ? + (db_type->state == SHOW_OPTION_YES) : FALSE; +} /* basic stuff */ int ha_init(void); +int ha_register_builtin_plugins(); +int ha_initialize_handlerton(handlerton *hton); + TYPELIB *ha_known_exts(void); int ha_panic(enum ha_panic_function flag); int ha_update_statistics(); void ha_close_connection(THD* thd); -my_bool ha_storage_engine_is_enabled(enum db_type database_type); -bool ha_flush_logs(enum db_type db_type=DB_TYPE_DEFAULT); +bool ha_flush_logs(handlerton *db_type); void ha_drop_database(char* path); int ha_create_table(THD *thd, const char *path, const char *db, const char *table_name, HA_CREATE_INFO *create_info, bool update_create_info); -int ha_delete_table(THD *thd, enum db_type db_type, const char *path, +int ha_delete_table(THD *thd, handlerton *db_type, const char *path, const char *db, const char *alias, bool generate_warning); /* statistics and info */ -bool ha_show_status(THD *thd, enum db_type db_type, enum ha_stat_type stat); +bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat); /* discovery */ int ha_create_table_from_engine(THD* thd, const char *db, const char *name); diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 7a421691775..a8163a1758d 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -2547,7 +2547,7 @@ bool Item_sum_count_distinct::setup(THD *thd) table->file->extra(HA_EXTRA_NO_ROWS); // Don't update rows table->no_rows=1; - if (table->s->db_type == DB_TYPE_HEAP) + if (table->s->db_type == &heap_hton) { /* No blobs, otherwise it would have been MyISAM: set up a compare diff --git a/sql/log.cc b/sql/log.cc index 1fc7ba1f1fd..d30cf3266f9 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -48,6 +48,7 @@ static int binlog_rollback(THD *thd, bool all); static int binlog_prepare(THD *thd, bool all); handlerton binlog_hton = { + MYSQL_HANDLERTON_INTERFACE_VERSION, "binlog", SHOW_OPTION_YES, "This is a meta storage engine to represent the binlog in a transaction", @@ -71,12 +72,9 @@ handlerton binlog_hton = { NULL, /* Create a new handler */ NULL, /* Drop a database */ NULL, /* Panic call */ - NULL, /* Release temporary latches */ - NULL, /* Update Statistics */ NULL, /* Start Consistent Snapshot */ NULL, /* Flush logs */ NULL, /* Show status */ - NULL, /* Replication Report Sent Binlog */ HTON_NOT_USER_SELECTABLE | HTON_HIDDEN }; diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 652fc235b7e..f18447de71c 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -607,7 +607,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, int mysql_rm_table_part2_with_lock(THD *thd, TABLE_LIST *tables, bool if_exists, bool drop_temporary, bool log_query); -bool quick_rm_table(enum db_type base,const char *db, +bool quick_rm_table(handlerton *base,const char *db, const char *table_name); void close_cached_table(THD *thd, TABLE *table); bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list); @@ -754,7 +754,7 @@ bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool do_send_ok); bool mysql_create_like_table(THD *thd, TABLE_LIST *table, HA_CREATE_INFO *create_info, Table_ident *src_table); -bool mysql_rename_table(enum db_type base, +bool mysql_rename_table(handlerton *base, const char *old_db, const char * old_name, const char *new_db, @@ -1005,7 +1005,7 @@ bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags); int lock_tables(THD *thd, TABLE_LIST *tables, uint counter, bool *need_reopen); TABLE *open_temporary_table(THD *thd, const char *path, const char *db, const char *table_name, bool link_in_list); -bool rm_temporary_table(enum db_type base, char *path); +bool rm_temporary_table(handlerton *base, char *path); void free_io_cache(TABLE *entry); void intern_close_table(TABLE *entry); bool close_thread_table(THD *thd, TABLE **table_ptr); @@ -1333,6 +1333,10 @@ extern handlerton partition_hton; extern SHOW_COMP_OPTION have_partition_db; #endif +extern handlerton myisam_hton; +extern handlerton myisammrg_hton; +extern handlerton heap_hton; + extern SHOW_COMP_OPTION have_isam; extern SHOW_COMP_OPTION have_raid, have_openssl, have_symlink; extern SHOW_COMP_OPTION have_query_cache; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 6951c722558..20d09ae0228 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2624,6 +2624,18 @@ static int init_common_variables(const char *conf_file_name, int argc, strmake(pidfile_name, glob_hostname, sizeof(pidfile_name)-5); strmov(fn_ext(pidfile_name),".pid"); // Add proper extension + if (plugin_init()) + { + sql_print_error("Failed to init plugins."); + return 1; + } + + if (ha_register_builtin_plugins()) + { + sql_print_error("Failed to register built-in storage engines."); + return 1; + } + load_defaults(conf_file_name, groups, &argc, &argv); defaults_argv=argv; get_options(argc,argv); @@ -3107,17 +3119,15 @@ server."); /* Check that the default storage engine is actually available. */ - if (!ha_storage_engine_is_enabled((enum db_type) - global_system_variables.table_type)) + if (!ha_storage_engine_is_enabled(global_system_variables.table_type)) { if (!opt_bootstrap) { sql_print_error("Default storage engine (%s) is not available", - ha_get_storage_engine((enum db_type) - global_system_variables.table_type)); + global_system_variables.table_type->name); unireg_abort(1); } - global_system_variables.table_type= DB_TYPE_MYISAM; + global_system_variables.table_type= &myisam_hton; } tc_log= (total_ha_2pc > 1 ? (opt_bin_log ? @@ -3472,7 +3482,7 @@ we force server id to 2, but this MySQL server will not act as a slave."); if (!opt_noacl) { - plugin_init(); + plugin_load(); #ifdef HAVE_DLOPEN udf_init(); #endif @@ -6117,6 +6127,7 @@ struct show_var_st status_vars[]= { {"Com_show_master_status", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_MASTER_STAT]), SHOW_LONG_STATUS}, {"Com_show_new_master", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_NEW_MASTER]), SHOW_LONG_STATUS}, {"Com_show_open_tables", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_OPEN_TABLES]), SHOW_LONG_STATUS}, + {"Com_show_plugins", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_PLUGINS]), SHOW_LONG_STATUS}, {"Com_show_privileges", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_PRIVILEGES]), SHOW_LONG_STATUS}, {"Com_show_processlist", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_PROCESSLIST]), SHOW_LONG_STATUS}, {"Com_show_slave_hosts", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_SLAVE_HOSTS]), SHOW_LONG_STATUS}, @@ -6427,7 +6438,7 @@ static void mysql_init_variables(void) /* Set default values for some option variables */ - global_system_variables.table_type= DB_TYPE_MYISAM; + global_system_variables.table_type= &myisam_hton; global_system_variables.tx_isolation= ISO_REPEATABLE_READ; global_system_variables.select_limit= (ulonglong) HA_POS_ERROR; max_system_variables.select_limit= (ulonglong) HA_POS_ERROR; @@ -6820,9 +6831,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), break; case OPT_STORAGE_ENGINE: { - if ((enum db_type)((global_system_variables.table_type= - ha_resolve_by_name(argument, strlen(argument)))) == - DB_TYPE_UNKNOWN) + LEX_STRING name= { argument, strlen(argument) }; + if ((global_system_variables.table_type= + ha_resolve_by_name(current_thd, &name)) == NULL) { fprintf(stderr,"Unknown/unsupported table type: %s\n",argument); exit(1); diff --git a/sql/set_var.cc b/sql/set_var.cc index 6b53be4e479..990d8047009 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -3037,11 +3037,12 @@ bool sys_var_thd_storage_engine::check(THD *thd, set_var *var) if (var->value->result_type() == STRING_RESULT) { - enum db_type db_type; + LEX_STRING name; + handlerton *db_type; if (!(res=var->value->val_str(&str)) || - !(var->save_result.ulong_value= - (ulong) (db_type= ha_resolve_by_name(res->ptr(), res->length()))) || - ha_checktype(thd, db_type, 1, 0) != db_type) + !(name.str= (char *)res->ptr()) || !(name.length= res->length()) || + !(var->save_result.hton= db_type= ha_resolve_by_name(thd, &name)) || + ha_checktype(thd, ha_legacy_type(db_type), 1, 0) != db_type) { value= res ? res->c_ptr() : "NULL"; goto err; @@ -3059,29 +3060,28 @@ err: byte *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type, LEX_STRING *base) { - ulong val; - val= ((type == OPT_GLOBAL) ? global_system_variables.*offset : - thd->variables.*offset); - const char *table_type= ha_get_storage_engine((enum db_type)val); - return (byte *) table_type; + handlerton *val; + val= (type == OPT_GLOBAL) ? global_system_variables.*offset : + thd->variables.*offset; + return (byte *) val->name; } void sys_var_thd_storage_engine::set_default(THD *thd, enum_var_type type) { if (type == OPT_GLOBAL) - global_system_variables.*offset= (ulong) DB_TYPE_MYISAM; + global_system_variables.*offset= &myisam_hton; else - thd->variables.*offset= (ulong) (global_system_variables.*offset); + thd->variables.*offset= global_system_variables.*offset; } bool sys_var_thd_storage_engine::update(THD *thd, set_var *var) { - if (var->type == OPT_GLOBAL) - global_system_variables.*offset= var->save_result.ulong_value; - else - thd->variables.*offset= var->save_result.ulong_value; + handlerton **value= &(global_system_variables.*offset); + if (var->type != OPT_GLOBAL) + value= &(thd->variables.*offset); + *value= var->save_result.hton; return 0; } diff --git a/sql/set_var.h b/sql/set_var.h index 14059f7e9b7..838037b6e20 100644 --- a/sql/set_var.h +++ b/sql/set_var.h @@ -379,9 +379,9 @@ public: class sys_var_thd_storage_engine :public sys_var_thd { protected: - ulong SV::*offset; + handlerton *SV::*offset; public: - sys_var_thd_storage_engine(const char *name_arg, ulong SV::*offset_arg) + sys_var_thd_storage_engine(const char *name_arg, handlerton *SV::*offset_arg) :sys_var_thd(name_arg), offset(offset_arg) {} bool check(THD *thd, set_var *var); @@ -398,7 +398,7 @@ SHOW_TYPE type() { return SHOW_CHAR; } class sys_var_thd_table_type :public sys_var_thd_storage_engine { public: - sys_var_thd_table_type(const char *name_arg, ulong SV::*offset_arg) + sys_var_thd_table_type(const char *name_arg, handlerton *SV::*offset_arg) :sys_var_thd_storage_engine(name_arg, offset_arg) {} void warn_deprecated(THD *thd); @@ -812,6 +812,7 @@ public: CHARSET_INFO *charset; ulong ulong_value; ulonglong ulonglong_value; + handlerton *hton; DATE_TIME_FORMAT *date_time_format; Time_zone *time_zone; } save_result; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 23091248442..8f0f0d779e4 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1433,7 +1433,7 @@ void close_temporary_table(THD *thd, TABLE *table, void close_temporary(TABLE *table, bool free_share, bool delete_table) { - db_type table_type= table->s->db_type; + handlerton *table_type= table->s->db_type; DBUG_ENTER("close_temporary"); free_io_cache(table); @@ -1802,7 +1802,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, */ { char path[FN_REFLEN]; - db_type not_used; + enum legacy_db_type not_used; strxnmov(path, FN_REFLEN-1, mysql_data_home, "/", table_list->db, "/", table_list->table_name, reg_ext, NullS); (void) unpack_filename(path, path); @@ -3308,7 +3308,7 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db, } -bool rm_temporary_table(enum db_type base, char *path) +bool rm_temporary_table(handlerton *base, char *path) { bool error=0; handler *file; diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index de74581cf16..674c22b9300 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -2243,7 +2243,7 @@ Query_cache::register_tables_from_list(TABLE_LIST *tables_used, tables_used->engine_data)) DBUG_RETURN(0); - if (tables_used->table->s->db_type == DB_TYPE_MRG_MYISAM) + if (tables_used->table->s->db_type == &myisammrg_hton) { ha_myisammrg *handler = (ha_myisammrg *) tables_used->table->file; MYRG_INFO *file = handler->myrg_info(); @@ -2871,7 +2871,7 @@ static TABLE_COUNTER_TYPE process_and_count_tables(TABLE_LIST *tables_used, "other non-cacheable table(s)")); DBUG_RETURN(0); } - if (tables_used->table->s->db_type == DB_TYPE_MRG_MYISAM) + if (tables_used->table->s->db_type == &myisammrg_hton) { ha_myisammrg *handler = (ha_myisammrg *)tables_used->table->file; MYRG_INFO *file = handler->myrg_info(); diff --git a/sql/sql_class.h b/sql/sql_class.h index 7541829c4fa..60dc9a4cbad 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -526,7 +526,7 @@ struct system_variables ulong read_rnd_buff_size; ulong div_precincrement; ulong sortbuff_size; - ulong table_type; + handlerton *table_type; ulong tmp_table_size; ulong tx_isolation; ulong completion_type; diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index ffb9b1df18a..a9c3504250e 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -822,7 +822,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) /* If it is a temporary table, close and regenerate it */ if (!dont_send_ok && (table= find_temporary_table(thd, table_list))) { - db_type table_type= table->s->db_type; + handlerton *table_type= table->s->db_type; TABLE_SHARE *share= table->s; if (!ha_check_storage_engine_flag(table_type, HTON_CAN_RECREATE)) goto trunc_by_del; @@ -852,7 +852,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) if (!dont_send_ok) { - db_type table_type; + enum legacy_db_type table_type; mysql_frm_type(thd, path, &table_type); if (table_type == DB_TYPE_UNKNOWN) { @@ -860,7 +860,8 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) table_list->db, table_list->table_name); DBUG_RETURN(TRUE); } - if (!ha_check_storage_engine_flag(table_type, HTON_CAN_RECREATE) + if (!ha_check_storage_engine_flag(ha_resolve_by_legacy_type(thd, table_type), + HTON_CAN_RECREATE) || thd->lex->sphead) goto trunc_by_del; if (lock_and_wait_for_table_name(thd, table_list)) diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index a72f87f3fb7..72a2f4a4f91 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2527,7 +2527,7 @@ void select_create::abort() if (table) { table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); - enum db_type table_type=table->s->db_type; + handlerton *table_type=table->s->db_type; if (!table->s->tmp_table) { ulong version= table->s->version; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 06a101a1c5c..303245b38bd 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -93,7 +93,7 @@ enum enum_sql_command { SQLCOM_XA_COMMIT, SQLCOM_XA_ROLLBACK, SQLCOM_XA_RECOVER, SQLCOM_SHOW_PROC_CODE, SQLCOM_SHOW_FUNC_CODE, SQLCOM_INSTALL_PLUGIN, SQLCOM_UNINSTALL_PLUGIN, - SQLCOM_SHOW_AUTHORS, + SQLCOM_SHOW_AUTHORS, SQLCOM_SHOW_PLUGINS, /* This should be the last !!! */ SQLCOM_END diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 986e87c7d01..cf098f1b414 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -6477,7 +6477,7 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables, rotate_relay_log(active_mi); pthread_mutex_unlock(&LOCK_active_mi); #endif - if (ha_flush_logs()) + if (ha_flush_logs(NULL)) result=1; if (flush_error_log()) result=1; @@ -6793,7 +6793,7 @@ bool mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys) HA_CREATE_INFO create_info; DBUG_ENTER("mysql_create_index"); bzero((char*) &create_info,sizeof(create_info)); - create_info.db_type=DB_TYPE_DEFAULT; + create_info.db_type= (handlerton*) &default_hton; create_info.default_table_charset= thd->variables.collation_database; DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->table_name, &create_info, table_list, @@ -6809,7 +6809,7 @@ bool mysql_drop_index(THD *thd, TABLE_LIST *table_list, ALTER_INFO *alter_info) HA_CREATE_INFO create_info; DBUG_ENTER("mysql_drop_index"); bzero((char*) &create_info,sizeof(create_info)); - create_info.db_type=DB_TYPE_DEFAULT; + create_info.db_type= (handlerton*) &default_hton; create_info.default_table_charset= thd->variables.collation_database; alter_info->clear(); alter_info->flags= ALTER_DROP_INDEX; diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 8571e39d9b8..e294a43c774 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -654,7 +654,7 @@ static bool set_up_default_partitions(partition_info *part_info, partition_element *part_elem= new partition_element(); if (likely(part_elem != 0)) { - part_elem->engine_type= DB_TYPE_UNKNOWN; + part_elem->engine_type= NULL; part_elem->partition_name= default_name; default_name+=MAX_PART_NAME_SIZE; part_info->partitions.push_back(part_elem); @@ -726,7 +726,7 @@ static bool set_up_default_subpartitions(partition_info *part_info, partition_element *subpart_elem= new partition_element(); if (likely(subpart_elem != 0)) { - subpart_elem->engine_type= DB_TYPE_UNKNOWN; + subpart_elem->engine_type= NULL; subpart_elem->partition_name= name_ptr; name_ptr+= MAX_PART_NAME_SIZE; part_elem->subpartitions.push_back(subpart_elem); @@ -786,7 +786,7 @@ bool set_up_defaults_for_partitioning(partition_info *part_info, FALSE Ok, no mixed engines */ -static bool check_engine_mix(u_char *engine_array, uint no_parts) +static bool check_engine_mix(handlerton **engine_array, uint no_parts) { /* Current check verifies only that all handlers are the same. @@ -827,10 +827,10 @@ static bool check_engine_mix(u_char *engine_array, uint no_parts) This code is used early in the CREATE TABLE and ALTER TABLE process. */ -bool check_partition_info(partition_info *part_info,enum db_type eng_type, +bool check_partition_info(partition_info *part_info,handlerton *eng_type, handler *file, ulonglong max_rows) { - u_char *engine_array= NULL; + handlerton **engine_array= NULL; uint part_count= 0, i, no_parts, tot_partitions; bool result= TRUE; List_iterator<partition_element> part_it(part_info->partitions); @@ -858,7 +858,8 @@ bool check_partition_info(partition_info *part_info,enum db_type eng_type, my_error(ER_SAME_NAME_PARTITION, MYF(0)); goto end; } - engine_array= (u_char*)my_malloc(tot_partitions, MYF(MY_WME)); + engine_array= (handlerton**)my_malloc(tot_partitions * sizeof(handlerton *), + MYF(MY_WME)); if (unlikely(!engine_array)) goto end; i= 0; @@ -868,10 +869,10 @@ bool check_partition_info(partition_info *part_info,enum db_type eng_type, partition_element *part_elem= part_it++; if (!is_sub_partitioned(part_info)) { - if (part_elem->engine_type == DB_TYPE_UNKNOWN) + if (part_elem->engine_type == NULL) part_elem->engine_type= eng_type; - DBUG_PRINT("info", ("engine = %u",(uint)part_elem->engine_type)); - engine_array[part_count++]= (u_char)part_elem->engine_type; + DBUG_PRINT("info", ("engine = %s", part_elem->engine_type->name)); + engine_array[part_count++]= part_elem->engine_type; } else { @@ -880,10 +881,10 @@ bool check_partition_info(partition_info *part_info,enum db_type eng_type, do { part_elem= sub_it++; - if (part_elem->engine_type == DB_TYPE_UNKNOWN) + if (part_elem->engine_type == NULL) part_elem->engine_type= eng_type; - DBUG_PRINT("info", ("engine = %u",(uint)part_elem->engine_type)); - engine_array[part_count++]= (u_char)part_elem->engine_type; + DBUG_PRINT("info", ("engine = %s", part_elem->engine_type->name)); + engine_array[part_count++]= part_elem->engine_type; } while (++j < no_subparts); } } while (++i < part_info->no_parts); @@ -1950,9 +1951,9 @@ static int add_keyword_int(File fptr, const char *keyword, longlong num) return err + add_space(fptr); } -static int add_engine(File fptr, enum db_type engine_type) +static int add_engine(File fptr, handlerton *engine_type) { - const char *engine_str= ha_get_storage_engine(engine_type); + const char *engine_str= engine_type->name; int err= add_string(fptr, "ENGINE = "); return err + add_string(fptr, engine_str); return err; @@ -3147,7 +3148,7 @@ void get_partition_set(const TABLE *table, byte *buf, const uint index, bool mysql_unpack_partition(THD *thd, const uchar *part_buf, uint part_info_len, TABLE* table, - enum db_type default_db_type) + handlerton *default_db_type) { Item *thd_free_list= thd->free_list; bool result= TRUE; @@ -3184,7 +3185,7 @@ bool mysql_unpack_partition(THD *thd, const uchar *part_buf, part_info= lex.part_info; table->part_info= part_info; table->file->set_part_info(part_info); - if (part_info->default_engine_type == DB_TYPE_UNKNOWN) + if (part_info->default_engine_type == NULL) part_info->default_engine_type= default_db_type; else { diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 7e78b58e6cf..591289f6ee1 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -33,7 +33,6 @@ static HASH plugin_hash[MYSQL_MAX_PLUGIN_TYPE_NUM]; static rw_lock_t THR_LOCK_plugin; static bool initialized= 0; - static struct st_plugin_dl *plugin_dl_find(LEX_STRING *dl) { uint i; @@ -348,6 +347,43 @@ void plugin_unlock(struct st_plugin_int *plugin) } +static int plugin_initialize(struct st_plugin_int *plugin) +{ + DBUG_ENTER("plugin_initialize"); + + if (plugin->plugin->init) + { + if (plugin->plugin->init()) + { + sql_print_error("Plugin '%s' init function returned error.", + plugin->name.str); + DBUG_PRINT("warning", ("Plugin '%s' init function returned error.", + plugin->name.str)) + goto err; + } + } + + switch (plugin->plugin->type) + { + case MYSQL_STORAGE_ENGINE_PLUGIN: + if (ha_initialize_handlerton((handlerton*) plugin->plugin->info)) + { + sql_print_error("Plugin '%s' handlerton init returned error.", + plugin->name.str); + DBUG_PRINT("warning", ("Plugin '%s' handlerton init returned error.", + plugin->name.str)) + goto err; + } + break; + default: + break; + } + + DBUG_RETURN(0); +err: + DBUG_RETURN(1); +} + static void plugin_call_initializer(void) { uint i; @@ -356,20 +392,13 @@ static void plugin_call_initializer(void) { struct st_plugin_int *tmp= dynamic_element(&plugin_array, i, struct st_plugin_int *); - if (tmp->state == PLUGIN_IS_UNINITIALIZED && tmp->plugin->init) + if (tmp->state == PLUGIN_IS_UNINITIALIZED) { - DBUG_PRINT("info", ("Initializing plugin: '%s'", tmp->name.str)); - if (tmp->plugin->init()) - { - sql_print_error("Plugin '%s' init function returned error.", - tmp->name.str); - DBUG_PRINT("warning", ("Plugin '%s' init function returned error.", - tmp->name.str)) + if (plugin_initialize(tmp)) plugin_del(&tmp->name); - } + else + tmp->state= PLUGIN_IS_READY; } - if (tmp->state == PLUGIN_IS_UNINITIALIZED) - tmp->state= PLUGIN_IS_READY; } DBUG_VOID_RETURN; } @@ -410,42 +439,84 @@ static byte *get_hash_key(const byte *buff, uint *length, } -void plugin_init(void) +int plugin_init(void) +{ + int i; + DBUG_ENTER("plugin_init"); + + if (initialized) + DBUG_RETURN(0); + + my_rwlock_init(&THR_LOCK_plugin, NULL); + + if (my_init_dynamic_array(&plugin_dl_array, + sizeof(struct st_plugin_dl),16,16) || + my_init_dynamic_array(&plugin_array, + sizeof(struct st_plugin_int),16,16)) + goto err; + + for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++) + { + if (hash_init(&plugin_hash[i], system_charset_info, 16, 0, 0, + get_hash_key, NULL, 0)) + goto err; + } + + initialized= 1; + + DBUG_RETURN(0); + +err: + DBUG_RETURN(1); +} + + +my_bool plugin_register_builtin(struct st_mysql_plugin *plugin) +{ + struct st_plugin_int tmp; + DBUG_ENTER("plugin_register_builtin"); + + tmp.plugin= plugin; + tmp.name.str= (char *)plugin->name; + tmp.name.length= strlen(plugin->name); + tmp.state= PLUGIN_IS_UNINITIALIZED; + + /* Cannot be unloaded */ + tmp.ref_count= 1; + tmp.plugin_dl= 0; + + if (insert_dynamic(&plugin_array, (gptr)&tmp)) + DBUG_RETURN(1); + + if (my_hash_insert(&plugin_hash[plugin->type], + (byte*)dynamic_element(&plugin_array, + plugin_array.elements - 1, + struct st_plugin_int *))) + DBUG_RETURN(1); + + DBUG_RETURN(0); +} + + +void plugin_load(void) { TABLE_LIST tables; TABLE *table; READ_RECORD read_record_info; int error, i; MEM_ROOT mem; - DBUG_ENTER("plugin_init"); - if (initialized) - DBUG_VOID_RETURN; - my_rwlock_init(&THR_LOCK_plugin, NULL); - THD *new_thd = new THD; - if (!new_thd || - my_init_dynamic_array(&plugin_dl_array,sizeof(struct st_plugin_dl),16,16) || - my_init_dynamic_array(&plugin_array,sizeof(struct st_plugin_int),16,16)) + THD *new_thd; + DBUG_ENTER("plugin_load"); + + DBUG_ASSERT(initialized); + + if (!(new_thd= new THD)) { sql_print_error("Can't allocate memory for plugin structures"); delete new_thd; - delete_dynamic(&plugin_dl_array); - delete_dynamic(&plugin_array); DBUG_VOID_RETURN; } - for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++) - { - if (hash_init(&plugin_hash[i], system_charset_info, 16, 0, 0, - get_hash_key, NULL, 0)) - { - sql_print_error("Can't allocate memory for plugin structures"); - delete new_thd; - delete_dynamic(&plugin_dl_array); - delete_dynamic(&plugin_array); - DBUG_VOID_RETURN; - } - } init_sql_alloc(&mem, 1024, 0); - initialized= 1; new_thd->thread_stack= (char*) &tables; new_thd->store_globals(); new_thd->db= my_strdup("mysql", MYF(0)); @@ -458,10 +529,6 @@ void plugin_init(void) { DBUG_PRINT("error",("Can't open plugin table")); sql_print_error("Can't open the mysql.plugin table. Please run the mysql_install_db script to create it."); - delete_dynamic(&plugin_dl_array); - delete_dynamic(&plugin_array); - for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++) - hash_free(&plugin_hash[i]); goto end; } table= tables.table; @@ -530,27 +597,31 @@ my_bool mysql_install_plugin(THD *thd, LEX_STRING *name, LEX_STRING *dl) int error; struct st_plugin_int *tmp; DBUG_ENTER("mysql_install_plugin"); + bzero(&tables, sizeof(tables)); tables.db= (char *)"mysql"; tables.table_name= tables.alias= (char *)"plugin"; if (check_table_access(thd, INSERT_ACL, &tables, 0)) DBUG_RETURN(TRUE); + + /* need to open before acquiring THR_LOCK_plugin or it will deadlock */ + if (! (table = open_ltable(thd, &tables, TL_WRITE))) + DBUG_RETURN(TRUE); + rw_wrlock(&THR_LOCK_plugin); if (plugin_add(name, dl, REPORT_TO_USER)) goto err; tmp= plugin_find_internal(name, MYSQL_ANY_PLUGIN); - if (tmp->plugin->init) + + if (plugin_initialize(tmp)) { - if (tmp->plugin->init()) - { - my_error(ER_CANT_INITIALIZE_UDF, MYF(0), name->str, - "Plugin initialization function failed."); - goto err; - } - tmp->state= PLUGIN_IS_READY; + my_error(ER_CANT_INITIALIZE_UDF, MYF(0), name->str, + "Plugin initialization function failed."); + goto err; } - if (! (table = open_ltable(thd, &tables, TL_WRITE))) - goto deinit; + + tmp->state= PLUGIN_IS_READY; + restore_record(table, s->default_values); table->field[0]->store(name->str, name->length, system_charset_info); table->field[1]->store(dl->str, dl->length, files_charset_info); @@ -560,6 +631,7 @@ my_bool mysql_install_plugin(THD *thd, LEX_STRING *name, LEX_STRING *dl) table->file->print_error(error, MYF(0)); goto deinit; } + rw_unlock(&THR_LOCK_plugin); DBUG_RETURN(FALSE); deinit: @@ -578,12 +650,29 @@ my_bool mysql_uninstall_plugin(THD *thd, LEX_STRING *name) TABLE_LIST tables; struct st_plugin_int *plugin; DBUG_ENTER("mysql_uninstall_plugin"); + + bzero(&tables, sizeof(tables)); + tables.db= (char *)"mysql"; + tables.table_name= tables.alias= (char *)"plugin"; + + /* need to open before acquiring THR_LOCK_plugin or it will deadlock */ + if (! (table= open_ltable(thd, &tables, TL_WRITE))) + DBUG_RETURN(TRUE); + rw_wrlock(&THR_LOCK_plugin); - if (! (plugin= plugin_find_internal(name, MYSQL_ANY_PLUGIN))) + if (!(plugin= plugin_find_internal(name, MYSQL_ANY_PLUGIN))) { my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "PLUGIN", name->str); goto err; } + if (!plugin->plugin_dl) + { + push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, + "Built-in plugins cannot be deleted,."); + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "PLUGIN", name->str); + goto err; + } + if (plugin->ref_count) { plugin->state= PLUGIN_IS_DELETED; @@ -596,11 +685,7 @@ my_bool mysql_uninstall_plugin(THD *thd, LEX_STRING *name) plugin->plugin->deinit(); plugin_del(name); } - bzero(&tables, sizeof(tables)); - tables.db= (char *)"mysql"; - tables.table_name= tables.alias= (char *)"plugin"; - if (! (table= open_ltable(thd, &tables, TL_WRITE))) - goto err; + table->field[0]->store(name->str, name->length, system_charset_info); table->file->extra(HA_EXTRA_RETRIEVE_ALL_COLS); if (! table->file->index_read_idx(table->record[0], 0, @@ -621,3 +706,44 @@ err: rw_unlock(&THR_LOCK_plugin); DBUG_RETURN(TRUE); } + + +my_bool plugin_foreach(THD *thd, plugin_foreach_func *func, + int type, void *arg) +{ + uint idx; + struct st_plugin_int *plugin; + DBUG_ENTER("mysql_uninstall_plugin"); + rw_rdlock(&THR_LOCK_plugin); + + if (type == MYSQL_ANY_PLUGIN) + { + for (idx= 0; idx < plugin_array.elements; idx++) + { + plugin= dynamic_element(&plugin_array, idx, struct st_plugin_int *); + + /* FREED records may have garbage pointers */ + if ((plugin->state != PLUGIN_IS_FREED) && + func(thd, plugin, arg)) + goto err; + } + } + else + { + HASH *hash= &plugin_hash[type]; + for (idx= 0; idx < hash->records; idx++) + { + plugin= (struct st_plugin_int *) hash_element(hash, idx); + if ((plugin->state != PLUGIN_IS_FREED) && + (plugin->state != PLUGIN_IS_DELETED) && + func(thd, plugin, arg)) + goto err; + } + } + + rw_unlock(&THR_LOCK_plugin); + DBUG_RETURN(FALSE); +err: + rw_unlock(&THR_LOCK_plugin); + DBUG_RETURN(TRUE); +} diff --git a/sql/sql_plugin.h b/sql/sql_plugin.h index 8fb186b62de..24ba02367f5 100644 --- a/sql/sql_plugin.h +++ b/sql/sql_plugin.h @@ -53,11 +53,20 @@ struct st_plugin_int extern char *opt_plugin_dir_ptr; extern char opt_plugin_dir[FN_REFLEN]; -extern void plugin_init(void); +extern int plugin_init(void); +extern void plugin_load(void); extern void plugin_free(void); extern my_bool plugin_is_ready(LEX_STRING *name, int type); extern st_plugin_int *plugin_lock(LEX_STRING *name, int type); extern void plugin_unlock(struct st_plugin_int *plugin); extern my_bool mysql_install_plugin(THD *thd, LEX_STRING *name, LEX_STRING *dl); extern my_bool mysql_uninstall_plugin(THD *thd, LEX_STRING *name); + +extern my_bool plugin_register_builtin(struct st_mysql_plugin *plugin); + +typedef my_bool (plugin_foreach_func)(THD *thd, + st_plugin_int *plugin, + void *arg); +extern my_bool plugin_foreach(THD *thd, plugin_foreach_func *func, + int type, void *arg); #endif diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc index 80fcb973028..2c8c732fe86 100644 --- a/sql/sql_rename.cc +++ b/sql/sql_rename.cc @@ -134,7 +134,7 @@ rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error) { TABLE_LIST *ren_table,*new_table; frm_type_enum frm_type; - db_type table_type; + enum legacy_db_type table_type; DBUG_ENTER("rename_tables"); @@ -176,7 +176,8 @@ rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error) if (table_type == DB_TYPE_UNKNOWN) my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno); else - rc= mysql_rename_table(table_type, ren_table->db, old_alias, + rc= mysql_rename_table(ha_resolve_by_legacy_type(thd, table_type), + ren_table->db, old_alias, new_table->db, new_alias); break; } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 9c3fd90b6b9..7b12069b8ec 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -8637,7 +8637,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, OPTION_BIG_TABLES || (select_options & TMP_TABLE_FORCE_MYISAM)) { table->file= get_new_handler(share, &table->mem_root, - share->db_type= DB_TYPE_MYISAM); + share->db_type= &myisam_hton); if (group && (param->group_parts > table->file->max_key_parts() || param->group_length > table->file->max_key_length())) @@ -8646,7 +8646,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, else { table->file= get_new_handler(share, &table->mem_root, - share->db_type= DB_TYPE_HEAP); + share->db_type= &heap_hton); } if (!table->file) goto err; @@ -8776,7 +8776,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, if (thd->variables.tmp_table_size == ~(ulong) 0) // No limit share->max_rows= ~(ha_rows) 0; else - share->max_rows= (((share->db_type == DB_TYPE_HEAP) ? + share->max_rows= (((share->db_type == &heap_hton) ? min(thd->variables.tmp_table_size, thd->variables.max_heap_table_size) : thd->variables.tmp_table_size)/ share->reclength); @@ -8916,7 +8916,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, if (thd->is_fatal_error) // If end of memory goto err; /* purecov: inspected */ share->db_record_offset= 1; - if (share->db_type == DB_TYPE_MYISAM) + if (share->db_type == &myisam_hton) { if (create_myisam_tmp_table(table,param,select_options)) goto err; @@ -9236,7 +9236,8 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param, int write_err; DBUG_ENTER("create_myisam_from_heap"); - if (table->s->db_type != DB_TYPE_HEAP || error != HA_ERR_RECORD_FILE_FULL) + if (table->s->db_type != &heap_hton || + error != HA_ERR_RECORD_FILE_FULL) { table->file->print_error(error,MYF(0)); DBUG_RETURN(1); @@ -9244,9 +9245,9 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param, new_table= *table; share= *table->s; new_table.s= &share; - new_table.s->db_type= DB_TYPE_MYISAM; + new_table.s->db_type= &myisam_hton; if (!(new_table.file= get_new_handler(&share, &new_table.mem_root, - DB_TYPE_MYISAM))) + &myisam_hton))) DBUG_RETURN(1); // End of memory save_proc_info=thd->proc_info; @@ -11685,7 +11686,7 @@ remove_duplicates(JOIN *join, TABLE *entry,List<Item> &fields, Item *having) free_io_cache(entry); // Safety entry->file->info(HA_STATUS_VARIABLE); - if (entry->s->db_type == DB_TYPE_HEAP || + if (entry->s->db_type == &heap_hton || (!entry->s->blob_fields && ((ALIGN_SIZE(reclength) + HASH_OVERHEAD) * entry->file->records < thd->variables.sortbuff_size))) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index badc15f2ab5..63728e0f32c 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -48,6 +48,32 @@ static bool schema_table_store_record(THD *thd, TABLE *table); ** List all table types supported ***************************************************************************/ +static my_bool show_handlerton(THD *thd, st_plugin_int *plugin, + void *arg) +{ + handlerton *default_type= (handlerton *) arg; + Protocol *protocol= thd->protocol; + handlerton *hton= (handlerton *) plugin->plugin->info; + + if (!(hton->flags & HTON_HIDDEN)) + { + protocol->prepare_for_resend(); + protocol->store(hton->name, system_charset_info); + const char *option_name= show_comp_option_name[(int) hton->state]; + + if (hton->state == SHOW_OPTION_YES && default_type == hton) + option_name= "DEFAULT"; + protocol->store(option_name, system_charset_info); + protocol->store(hton->comment, system_charset_info); + protocol->store(hton->commit ? "YES" : "NO", system_charset_info); + protocol->store(hton->prepare ? "YES" : "NO", system_charset_info); + protocol->store(hton->savepoint_set ? "YES" : "NO", system_charset_info); + + return protocol->write() ? 1 : 0; + } + return 0; +} + bool mysqld_show_storage_engines(THD *thd) { List<Item> field_list; @@ -65,34 +91,126 @@ bool mysqld_show_storage_engines(THD *thd) Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) DBUG_RETURN(TRUE); - const char *default_type_name= - ha_get_storage_engine((enum db_type)thd->variables.table_type); + if (plugin_foreach(thd, show_handlerton, + MYSQL_STORAGE_ENGINE_PLUGIN, thd->variables.table_type)) + DBUG_RETURN(TRUE); - handlerton **types; - for (types= sys_table_types; *types; types++) - { - if (!((*types)->flags & HTON_HIDDEN)) - { - protocol->prepare_for_resend(); - protocol->store((*types)->name, system_charset_info); - const char *option_name= show_comp_option_name[(int) (*types)->state]; - - if ((*types)->state == SHOW_OPTION_YES && - !my_strcasecmp(system_charset_info, default_type_name, (*types)->name)) - option_name= "DEFAULT"; - protocol->store(option_name, system_charset_info); - protocol->store((*types)->comment, system_charset_info); - protocol->store((*types)->commit ? "YES" : "NO", system_charset_info); - protocol->store((*types)->prepare ? "YES" : "NO", system_charset_info); - protocol->store((*types)->savepoint_set ? "YES" : "NO", system_charset_info); - if (protocol->write()) - DBUG_RETURN(TRUE); - } - } send_eof(thd); DBUG_RETURN(FALSE); } +static int make_version_string(char *buf, int buf_length, uint version) +{ + return my_snprintf(buf, buf_length, "%d.%d.%d", + (version>>24)&0xff, (version>>16)&0xff,version&0xffff); +} + +static my_bool show_plugins(THD *thd, st_plugin_int *plugin, + void *arg) +{ + TABLE *table= (TABLE*) arg; + struct st_mysql_plugin *plug= plugin->plugin; + Protocol *protocol= thd->protocol; + CHARSET_INFO *cs= system_charset_info; + char version_buf[20]; + + restore_record(table, s->default_values); + + table->field[0]->store(plugin->name.str, plugin->name.length, cs); + + switch (plugin->state) + { + /* case PLUGIN_IS_FREED: does not happen */ + case PLUGIN_IS_DELETED: + table->field[1]->store(STRING_WITH_LEN("DELETED"), cs); + break; + case PLUGIN_IS_UNINITIALIZED: + table->field[1]->store(STRING_WITH_LEN("INACTIVE"), cs); + break; + case PLUGIN_IS_READY: + table->field[1]->store(STRING_WITH_LEN("ACTIVE"), cs); + break; + default: + DBUG_ASSERT(0); + } + + switch (plug->type) + { + case MYSQL_UDF_PLUGIN: + table->field[2]->store(STRING_WITH_LEN("UDF"), cs); + break; + case MYSQL_STORAGE_ENGINE_PLUGIN: + table->field[2]->store(STRING_WITH_LEN("STORAGE"), cs); + break; + case MYSQL_FTPARSER_PLUGIN: + table->field[2]->store(STRING_WITH_LEN("FTPARSER"), cs); + break; + default: + table->field[2]->store(STRING_WITH_LEN("UNKNOWN"), cs); + break; + } + + if (plug->version) + { + table->field[3]->store(version_buf, + make_version_string(version_buf, sizeof(version_buf), plug->version), + cs); + table->field[3]->set_notnull(); + } + else + table->field[3]->set_null(); + + if (plug->info) + { + table->field[4]->store(version_buf, + make_version_string(version_buf, sizeof(version_buf), + *(uint *)plug->info), cs); + table->field[4]->set_notnull(); + } + else + table->field[4]->set_null(); + + if (plugin->plugin_dl) + { + table->field[5]->store(plugin->plugin_dl->dl.str, + plugin->plugin_dl->dl.length, cs); + table->field[5]->set_notnull(); + } + else + table->field[5]->set_null(); + + if (plug->author) + { + table->field[6]->store(plug->author, strlen(plug->author), cs); + table->field[6]->set_notnull(); + } + else + table->field[6]->set_null(); + + if (plug->descr) + { + table->field[7]->store(plug->descr, strlen(plug->descr), cs); + table->field[7]->set_notnull(); + } + else + table->field[7]->set_null(); + + return schema_table_store_record(thd, table); +} + + +int fill_plugins(THD *thd, TABLE_LIST *tables, COND *cond) +{ + DBUG_ENTER("fill_plugins"); + TABLE *table= tables->table; + + if (plugin_foreach(thd, show_plugins, MYSQL_ANY_PLUGIN, table)) + DBUG_RETURN(1); + + DBUG_RETURN(0); +} + + /*************************************************************************** ** List all Authors. ** If you can update it, you get to be in it :) @@ -999,8 +1117,8 @@ store_create_info(THD *thd, TABLE_LIST *table_list, String *packet) packet->append(STRING_WITH_LEN(" ENGINE=")); #ifdef WITH_PARTITION_STORAGE_ENGINE if (table->part_info) - packet->append(ha_get_storage_engine(table->part_info-> - default_engine_type)); + packet->append(ha_resolve_storage_engine_name( + table->part_info->default_engine_type)); else packet->append(file->table_type()); #else @@ -2084,7 +2202,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) Security_context *sctx= thd->security_ctx; uint derived_tables= lex->derived_tables; int error= 1; - db_type not_used; + enum legacy_db_type not_used; Open_tables_state open_tables_state_backup; DBUG_ENTER("get_all_tables"); @@ -4172,6 +4290,20 @@ ST_FIELD_INFO variables_fields_info[]= }; +ST_FIELD_INFO plugin_fields_info[]= +{ + {"PLUGIN_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Name"}, + {"PLUGIN_STATUS", 10, MYSQL_TYPE_STRING, 0, 0, "Status"}, + {"PLUGIN_TYPE", 10, MYSQL_TYPE_STRING, 0, 0, "Type"}, + {"PLUGIN_VERSION", 20, MYSQL_TYPE_STRING, 0, 1, 0}, + {"PLUGIN_TYPE_VERSION", 20, MYSQL_TYPE_STRING, 0, 1, 0}, + {"PLUGIN_LIBRARY", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, "Library"}, + {"PLUGIN_AUTHOR", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 0}, + {"PLUGIN_DESCRIPTION", 65535, MYSQL_TYPE_STRING, 0, 1, 0}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0} +}; + + /* Description of ST_FIELD_INFO in table.h */ @@ -4192,6 +4324,8 @@ ST_SCHEMA_TABLE schema_tables[]= get_all_tables, 0, get_schema_key_column_usage_record, 4, 5, 0}, {"OPEN_TABLES", open_tables_fields_info, create_schema_table, fill_open_tables, make_old_format, 0, -1, -1, 1}, + {"PLUGINS", plugin_fields_info, create_schema_table, + fill_plugins, make_old_format, 0, -1, -1, 0}, {"ROUTINES", proc_fields_info, create_schema_table, fill_schema_proc, make_proc_old_format, 0, -1, -1, 0}, {"SCHEMATA", schema_fields_info, create_schema_table, diff --git a/sql/sql_table.cc b/sql/sql_table.cc index a74a550679f..0e811d63b36 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -27,7 +27,6 @@ #include <io.h> #endif - const char *primary_key_name="PRIMARY"; static bool check_if_keyname_exists(const char *name,KEY *start, KEY *end); @@ -40,7 +39,7 @@ static int copy_data_between_tables(TABLE *from,TABLE *to, ha_rows *copied,ha_rows *deleted); static bool prepare_blob_field(THD *thd, create_field *sql_field); static bool check_engine(THD *thd, const char *table_name, - enum db_type *new_engine); + handlerton **new_engine); /* SYNOPSIS @@ -290,7 +289,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, for (table= tables; table; table= table->next_local) { TABLE_SHARE *share; - table->db_type= DB_TYPE_UNKNOWN; + table->db_type= NULL; if ((share= get_cached_table_share(table->db, table->table_name))) table->db_type= share->db_type; } @@ -304,7 +303,8 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, for (table= tables; table; table= table->next_local) { char *db=table->db; - db_type table_type; + handlerton *table_type; + enum legacy_db_type frm_db_type; mysql_ha_flush(thd, table, MYSQL_HA_CLOSE_FINAL, TRUE); if (!close_temporary_table(thd, table)) @@ -331,12 +331,12 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, /* remove .frm file and engine files */ build_table_path(path, sizeof(path), db, alias, reg_ext); } - if (table_type == DB_TYPE_UNKNOWN && + if (table_type == NULL && (drop_temporary || (access(path, F_OK) && ha_create_table_from_engine(thd, db, alias)) || (!drop_view && - mysql_frm_type(thd, path, &table_type) != FRMTYPE_TABLE))) + mysql_frm_type(thd, path, &frm_db_type) != FRMTYPE_TABLE))) { // Table was not found on disk and table can't be created from engine if (if_exists) @@ -349,13 +349,16 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, else { char *end; - if (table_type == DB_TYPE_UNKNOWN) - mysql_frm_type(thd, path, &table_type); + if (table_type == NULL) + { + mysql_frm_type(thd, path, &frm_db_type); + table_type= ha_resolve_by_legacy_type(thd, frm_db_type); + } *(end=fn_ext(path))=0; // Remove extension for delete error= ha_delete_table(thd, table_type, path, db, table->table_name, !dont_log_query); if ((error == ENOENT || error == HA_ERR_NO_SUCH_TABLE) && - (if_exists || table_type == DB_TYPE_UNKNOWN)) + (if_exists || table_type == NULL)) error= 0; if (error == HA_ERR_ROW_IS_REFERENCED) { @@ -413,7 +416,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, } -bool quick_rm_table(enum db_type base,const char *db, +bool quick_rm_table(handlerton *base,const char *db, const char *table_name) { char path[FN_REFLEN]; @@ -1670,10 +1673,10 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, this information in the default_db_type variable, it is either DB_TYPE_DEFAULT or the engine set in the ALTER TABLE command. */ - enum db_type part_engine_type= create_info->db_type; + handlerton *part_engine_type= create_info->db_type; char *part_syntax_buf; uint syntax_len; - if (part_engine_type == DB_TYPE_PARTITION_DB) + if (part_engine_type == &partition_hton) { /* This only happens at ALTER TABLE. @@ -1681,7 +1684,7 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, TABLE command. */ part_engine_type= ha_checktype(thd, - part_info->default_engine_type, 0, 0); + ha_legacy_type(part_info->default_engine_type), 0, 0); } else { @@ -1702,7 +1705,7 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, part_info->part_info_string= part_syntax_buf; part_info->part_info_len= syntax_len; if ((!(file->partition_flags() & HA_CAN_PARTITION)) || - create_info->db_type == DB_TYPE_PARTITION_DB) + create_info->db_type == &partition_hton) { /* The handler assigned to the table cannot handle partitioning. @@ -1711,7 +1714,7 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, DBUG_PRINT("info", ("db_type: %d part_flag: %d", create_info->db_type,file->partition_flags())); delete file; - create_info->db_type= DB_TYPE_PARTITION_DB; + create_info->db_type= &partition_hton; if (!(file= get_ha_partition(part_info))) { DBUG_RETURN(TRUE); @@ -1928,8 +1931,9 @@ TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, tmp_table.s->db_create_options=0; tmp_table.s->blob_ptr_size= portable_sizeof_char_ptr; - tmp_table.s->db_low_byte_first= test(create_info->db_type == DB_TYPE_MYISAM || - create_info->db_type == DB_TYPE_HEAP); + tmp_table.s->db_low_byte_first= + test(create_info->db_type == &myisam_hton || + create_info->db_type == &heap_hton); tmp_table.null_row=tmp_table.maybe_null=0; while ((item=it++)) @@ -2006,7 +2010,7 @@ TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, ****************************************************************************/ bool -mysql_rename_table(enum db_type base, +mysql_rename_table(handlerton *base, const char *old_db, const char *old_name, const char *new_db, @@ -2020,7 +2024,7 @@ mysql_rename_table(enum db_type base, int error=0; DBUG_ENTER("mysql_rename_table"); - file= (base == DB_TYPE_UNKNOWN ? 0 : + file= (base == NULL ? 0 : get_new_handler((TABLE_SHARE*) 0, thd->mem_root, base)); build_table_path(from, sizeof(from), old_db, old_name, ""); @@ -2861,7 +2865,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, char *src_table= table_ident->table.str; int err; bool res= TRUE; - db_type not_used; + enum legacy_db_type not_used; TABLE_LIST src_tables_list; DBUG_ENTER("mysql_create_like_table"); @@ -3149,7 +3153,7 @@ int mysql_create_indexes(THD *thd, TABLE_LIST *table_list, List<Key> &keys) fields.push_back(c_fld); } bzero((char*) &create_info,sizeof(create_info)); - create_info.db_type=DB_TYPE_DEFAULT; + create_info.db_type= (handlerton*) &default_hton; create_info.default_table_charset= thd->variables.collation_database; db_options= 0; if (mysql_prepare_table(thd, &create_info, &fields, @@ -3173,7 +3177,7 @@ int mysql_create_indexes(THD *thd, TABLE_LIST *table_list, List<Key> &keys) { /* Re-initialize the create_info, which was changed by prepare table. */ bzero((char*) &create_info,sizeof(create_info)); - create_info.db_type=DB_TYPE_DEFAULT; + create_info.db_type= (handlerton*) &default_hton; create_info.default_table_charset= thd->variables.collation_database; /* Cleanup the fields list. We do not want to create existing fields. */ fields.delete_elements(); @@ -3268,7 +3272,7 @@ int mysql_drop_indexes(THD *thd, TABLE_LIST *table_list, } bzero((char*) &create_info,sizeof(create_info)); - create_info.db_type=DB_TYPE_DEFAULT; + create_info.db_type= (handlerton*) &default_hton; create_info.default_table_charset= thd->variables.collation_database; if ((drop_key)|| (drop.elements<= 0)) @@ -3484,13 +3488,13 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, ha_rows copied,deleted; ulonglong next_insert_id; uint db_create_options, used_fields; - enum db_type old_db_type,new_db_type; + handlerton *old_db_type, *new_db_type; uint need_copy_table= 0; #ifdef WITH_PARTITION_STORAGE_ENGINE bool online_add_empty_partition= FALSE; bool online_drop_partition= FALSE; bool partition_changed= FALSE; - enum db_type default_engine_type; + handlerton *default_engine_type; #endif DBUG_ENTER("mysql_alter_table"); @@ -3567,7 +3571,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, } old_db_type= table->s->db_type; - if (create_info->db_type == DB_TYPE_DEFAULT) + if (create_info->db_type == (handlerton*) &default_hton) create_info->db_type= old_db_type; #ifdef WITH_PARTITION_STORAGE_ENGINE @@ -3671,7 +3675,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, DBUG_RETURN(TRUE); } } - create_info->db_type= DB_TYPE_PARTITION_DB; + create_info->db_type= &partition_hton; thd->lex->part_info= tab_part_info; if (table->file->alter_table_flags() & HA_ONLINE_ADD_EMPTY_PARTITION && (tab_part_info->part_type == RANGE_PARTITION || @@ -3903,7 +3907,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, } partition_changed= TRUE; tab_part_info->no_parts= tab_part_info->partitions.elements; - create_info->db_type= DB_TYPE_PARTITION_DB; + create_info->db_type= &partition_hton; thd->lex->part_info= tab_part_info; if (alter_info->flags == ALTER_ADD_PARTITION || alter_info->flags == ALTER_REORGANISE_PARTITION) @@ -3974,9 +3978,9 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, */ if (thd->lex->part_info != table->part_info) partition_changed= TRUE; - if (create_info->db_type != DB_TYPE_PARTITION_DB) + if (create_info->db_type != &partition_hton) thd->lex->part_info->default_engine_type= create_info->db_type; - create_info->db_type= DB_TYPE_PARTITION_DB; + create_info->db_type= &partition_hton; } } #endif @@ -4667,7 +4671,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, error=0; if (!need_copy_table) - new_db_type=old_db_type=DB_TYPE_UNKNOWN; // this type cannot happen in regular ALTER + new_db_type=old_db_type= NULL; // this type cannot happen in regular ALTER if (mysql_rename_table(old_db_type,db,table_name,db,old_name)) { error=1; @@ -4997,7 +5001,7 @@ bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list, lex->col_list.empty(); lex->alter_info.reset(); bzero((char*) &create_info,sizeof(create_info)); - create_info.db_type=DB_TYPE_DEFAULT; + create_info.db_type= (handlerton*) &default_hton; create_info.row_type=ROW_TYPE_NOT_USED; create_info.default_table_charset=default_charset_info; /* Force alter table to recreate table */ @@ -5129,21 +5133,21 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt) } static bool check_engine(THD *thd, const char *table_name, - enum db_type *new_engine) + handlerton **new_engine) { - enum db_type req_engine= *new_engine; + handlerton *req_engine= *new_engine; bool no_substitution= test(thd->variables.sql_mode & MODE_NO_ENGINE_SUBSTITUTION); - if ((*new_engine= - ha_checktype(thd, req_engine, no_substitution, 1)) == DB_TYPE_UNKNOWN) + if (!(*new_engine= ha_checktype(thd, ha_legacy_type(req_engine), + no_substitution, 1))) return TRUE; - if (req_engine != *new_engine) + if (req_engine != (handlerton*) &default_hton && req_engine != *new_engine) { push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_USING_OTHER_HANDLER, ER(ER_WARN_USING_OTHER_HANDLER), - ha_get_storage_engine(*new_engine), + ha_resolve_storage_engine_name(*new_engine), table_name); } return FALSE; diff --git a/sql/sql_view.cc b/sql/sql_view.cc index e5e0603c640..aea07be1eda 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -1177,7 +1177,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) { char path[FN_REFLEN]; TABLE_LIST *view; - db_type not_used; + enum legacy_db_type not_used; DBUG_ENTER("mysql_drop_view"); for (view= views; view; view= view->next_local) @@ -1250,7 +1250,7 @@ err: FRMTYPE_VIEW view */ -frm_type_enum mysql_frm_type(THD *thd, char *path, db_type *dbt) +frm_type_enum mysql_frm_type(THD *thd, char *path, enum legacy_db_type *dbt) { File file; uchar header[10]; //"TYPE=VIEW\n" it is 10 characters @@ -1279,7 +1279,7 @@ frm_type_enum mysql_frm_type(THD *thd, char *path, db_type *dbt) (header[2] < FRM_VER+3 || header[2] > FRM_VER+4))) DBUG_RETURN(FRMTYPE_TABLE); - *dbt= ha_checktype(thd, (enum db_type) (uint) *(header + 3), 0, 0); + *dbt= (enum legacy_db_type) (uint) *(header + 3); DBUG_RETURN(FRMTYPE_TABLE); // Is probably a .frm table } diff --git a/sql/sql_view.h b/sql/sql_view.h index cd61d7e9e71..1e3e5f4aa73 100644 --- a/sql/sql_view.h +++ b/sql/sql_view.h @@ -27,7 +27,7 @@ bool check_key_in_view(THD *thd, TABLE_LIST * view); bool insert_view_fields(THD *thd, List<Item> *list, TABLE_LIST *view); -frm_type_enum mysql_frm_type(THD *thd, char *path, db_type *dbt); +frm_type_enum mysql_frm_type(THD *thd, char *path, enum legacy_db_type *dbt); int view_checksum(THD *thd, TABLE_LIST *view); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 01dfd9f2f5a..4518f9e8de1 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -92,7 +92,7 @@ inline Item *is_truth_value(Item *A, bool v1, bool v2) enum enum_var_type var_type; Key::Keytype key_type; enum ha_key_alg key_alg; - enum db_type db_type; + handlerton *db_type; enum row_type row_type; enum ha_rkey_function ha_rkey_mode; enum enum_tx_isolation tx_isolation; @@ -1174,7 +1174,7 @@ create: lex->change=NullS; bzero((char*) &lex->create_info,sizeof(lex->create_info)); lex->create_info.options=$2 | $4; - lex->create_info.db_type= (enum db_type) lex->thd->variables.table_type; + lex->create_info.db_type= lex->thd->variables.table_type; lex->create_info.default_table_charset= NULL; lex->name=0; } @@ -2822,7 +2822,7 @@ part_definition: part_info->current_partition= p_elem; part_info->use_default_partitions= FALSE; part_info->partitions.push_back(p_elem); - p_elem->engine_type= DB_TYPE_UNKNOWN; + p_elem->engine_type= NULL; part_info->count_curr_parts++; } part_name {} @@ -3005,7 +3005,7 @@ sub_part_definition: part_info->current_partition->subpartitions.push_back(p_elem); part_info->use_default_subpartitions= FALSE; part_info->count_curr_subparts++; - p_elem->engine_type= DB_TYPE_UNKNOWN; + p_elem->engine_type= NULL; } sub_name opt_part_options {} ; @@ -3234,8 +3234,8 @@ default_collation: storage_engines: ident_or_text { - $$ = ha_resolve_by_name($1.str,$1.length); - if ($$ == DB_TYPE_UNKNOWN && + $$ = ha_resolve_by_name(YYTHD, &$1); + if ($$ == NULL && test(YYTHD->variables.sql_mode & MODE_NO_ENGINE_SUBSTITUTION)) { my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str); @@ -3886,7 +3886,7 @@ alter: lex->select_lex.init_order(); lex->select_lex.db=lex->name=0; bzero((char*) &lex->create_info,sizeof(lex->create_info)); - lex->create_info.db_type= DB_TYPE_DEFAULT; + lex->create_info.db_type= (handlerton*) &default_hton; lex->create_info.default_table_charset= NULL; lex->create_info.row_type= ROW_TYPE_NOT_USED; lex->alter_info.reset(); @@ -7034,11 +7034,19 @@ show_param: if (prepare_schema_table(YYTHD, lex, 0, SCH_OPEN_TABLES)) YYABORT; } + | PLUGIN_SYM + { + LEX *lex= Lex; + lex->sql_command= SQLCOM_SELECT; + lex->orig_sql_command= SQLCOM_SHOW_PLUGINS; + if (prepare_schema_table(YYTHD, lex, 0, SCH_PLUGINS)) + YYABORT; + } | ENGINE_SYM storage_engines { Lex->create_info.db_type= $2; } show_engine_param | ENGINE_SYM ALL - { Lex->create_info.db_type= DB_TYPE_DEFAULT; } + { Lex->create_info.db_type= NULL; } show_engine_param | opt_full COLUMNS from_or_in table_ident opt_db wild_and_where { @@ -7130,14 +7138,24 @@ show_param: { LEX *lex= Lex; lex->sql_command = SQLCOM_SHOW_ENGINE_STATUS; - lex->create_info.db_type= DB_TYPE_INNODB; + if (!(lex->create_info.db_type= + ha_resolve_by_legacy_type(YYTHD, DB_TYPE_INNODB))) + { + my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), "InnoDB"); + YYABORT; + } WARN_DEPRECATED("SHOW INNODB STATUS", "SHOW ENGINE INNODB STATUS"); } | MUTEX_SYM STATUS_SYM { LEX *lex= Lex; lex->sql_command = SQLCOM_SHOW_ENGINE_MUTEX; - lex->create_info.db_type= DB_TYPE_INNODB; + if (!(lex->create_info.db_type= + ha_resolve_by_legacy_type(YYTHD, DB_TYPE_INNODB))) + { + my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), "InnoDB"); + YYABORT; + } WARN_DEPRECATED("SHOW MUTEX STATUS", "SHOW ENGINE INNODB MUTEX"); } | opt_full PROCESSLIST_SYM @@ -7171,14 +7189,24 @@ show_param: { LEX *lex= Lex; lex->sql_command= SQLCOM_SHOW_ENGINE_LOGS; - lex->create_info.db_type= DB_TYPE_BERKELEY_DB; + if (!(lex->create_info.db_type= + ha_resolve_by_legacy_type(YYTHD, DB_TYPE_BERKELEY_DB))) + { + my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), "BerkeleyDB"); + YYABORT; + } WARN_DEPRECATED("SHOW BDB LOGS", "SHOW ENGINE BDB LOGS"); } | LOGS_SYM { LEX *lex= Lex; lex->sql_command= SQLCOM_SHOW_ENGINE_LOGS; - lex->create_info.db_type= DB_TYPE_BERKELEY_DB; + if (!(lex->create_info.db_type= + ha_resolve_by_legacy_type(YYTHD, DB_TYPE_BERKELEY_DB))) + { + my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), "BerkeleyDB"); + YYABORT; + } WARN_DEPRECATED("SHOW LOGS", "SHOW ENGINE BDB LOGS"); } | GRANTS @@ -9863,7 +9891,7 @@ opt_migrate: ; install: - INSTALL_SYM PLUGIN_SYM IDENT_sys SONAME_SYM TEXT_STRING_sys + INSTALL_SYM PLUGIN_SYM ident SONAME_SYM TEXT_STRING_sys { LEX *lex= Lex; lex->sql_command= SQLCOM_INSTALL_PLUGIN; @@ -9872,7 +9900,7 @@ install: }; uninstall: - UNINSTALL_SYM PLUGIN_SYM IDENT_sys + UNINSTALL_SYM PLUGIN_SYM ident { LEX *lex= Lex; lex->sql_command= SQLCOM_UNINSTALL_PLUGIN; diff --git a/sql/table.cc b/sql/table.cc index 6cbb913de11..f9c6344e88f 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -327,6 +327,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, SQL_CRYPT *crypted=0; Field **field_ptr, *reg_field; const char **interval_array; + enum legacy_db_type legacy_db_type; DBUG_ENTER("open_binary_frm"); new_field_pack_flag= head[27]; @@ -349,11 +350,11 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, share->frm_version= FRM_VER_TRUE_VARCHAR; #ifdef WITH_PARTITION_STORAGE_ENGINE - share->default_part_db_type= ha_checktype(thd, - (enum db_type) (uint) *(head+61),0, - 0); + share->default_part_db_type= + ha_checktype(thd, (enum legacy_db_type) (uint) *(head+61), 0, 0); #endif - share->db_type= ha_checktype(thd, (enum db_type) (uint) *(head+3),0,0); + legacy_db_type= (enum legacy_db_type) (uint) *(head+3); + share->db_type= ha_checktype(thd, legacy_db_type, 0, 0); share->db_create_options= db_create_options= uint2korr(head+30); share->db_options_in_use= share->db_create_options; share->mysql_version= uint4korr(head+51); @@ -385,7 +386,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, if (db_create_options & HA_OPTION_LONG_BLOB_PTR) share->blob_ptr_size= portable_sizeof_char_ptr; /* Set temporarily a good value for db_low_byte_first */ - share->db_low_byte_first= test(share->db_type != DB_TYPE_ISAM); + share->db_low_byte_first= test(legacy_db_type != DB_TYPE_ISAM); error=4; share->max_rows= uint4korr(head+18); share->min_rows= uint4korr(head+22); @@ -513,14 +514,14 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, if (next_chunk + 2 < buff_end) { uint str_db_type_length= uint2korr(next_chunk); - enum db_type tmp_db_type= ha_resolve_by_name(next_chunk + 2, - str_db_type_length); - if (tmp_db_type != DB_TYPE_UNKNOWN) + LEX_STRING name= { next_chunk + 2, str_db_type_length }; + handlerton *tmp_db_type= ha_resolve_by_name(thd, &name); + if (tmp_db_type != NULL) { share->db_type= tmp_db_type; DBUG_PRINT("info", ("setting dbtype to '%.*s' (%d)", str_db_type_length, next_chunk + 2, - share->db_type)); + ha_legacy_type(share->db_type))); } #ifdef WITH_PARTITION_STORAGE_ENGINE else @@ -528,10 +529,10 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, if (!strncmp(next_chunk + 2, "partition", str_db_type_length)) { /* Use partition handler */ - share->db_type= DB_TYPE_PARTITION_DB; + share->db_type= &partition_hton; DBUG_PRINT("info", ("setting dbtype to '%.*s' (%d)", str_db_type_length, next_chunk + 2, - share->db_type)); + ha_legacy_type(share->db_type))); } } #endif @@ -1634,7 +1635,7 @@ void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg) handler *file= 0; const char *datext= ""; - if (share->db_type != DB_TYPE_UNKNOWN) + if (share->db_type != NULL) { if ((file= get_new_handler(share, current_thd->mem_root, share->db_type))) @@ -1899,7 +1900,8 @@ File create_frm(THD *thd, const char *name, const char *db, fileinfo[1]= 1; fileinfo[2]= FRM_VER+3+ test(create_info->varchar); - fileinfo[3]= (uchar) ha_checktype(thd,create_info->db_type,0,0); + fileinfo[3]= (uchar) ha_legacy_type( + ha_checktype(thd,ha_legacy_type(create_info->db_type),0,0)); fileinfo[4]=1; int2store(fileinfo+6,IO_SIZE); /* Next block starts here */ key_length=keys*(7+NAME_LEN+MAX_REF_PARTS*9)+16; diff --git a/sql/table.h b/sql/table.h index c4e99ed2a0d..d81eb6afe91 100644 --- a/sql/table.h +++ b/sql/table.h @@ -153,7 +153,7 @@ typedef struct st_table_share ulong timestamp_offset; /* Set to offset+1 of record */ ulong reclength; /* Recordlength */ - enum db_type db_type; /* table_type for handler */ + handlerton *db_type; /* table_type for handler */ enum row_type row_type; /* How rows are stored */ enum tmp_table_type tmp_table; @@ -200,7 +200,7 @@ typedef struct st_table_share #ifdef WITH_PARTITION_STORAGE_ENGINE const uchar *partition_info; uint partition_info_len; - enum db_type default_part_db_type; + handlerton *default_part_db_type; #endif } TABLE_SHARE; @@ -324,6 +324,7 @@ enum enum_schema_tables SCH_COLUMN_PRIVILEGES, SCH_KEY_COLUMN_USAGE, SCH_OPEN_TABLES, + SCH_PLUGINS, SCH_PROCEDURES, SCH_SCHEMATA, SCH_SCHEMA_PRIVILEGES, @@ -639,7 +640,7 @@ typedef struct st_table_list bool where_processed; /* FRMTYPE_ERROR if any type is acceptable */ enum frm_type_enum required_type; - enum db_type db_type; /* table_type for handler */ + handlerton *db_type; /* table_type for handler */ char timestamp_buffer[20]; /* buffer for timestamp (19+1) */ /* This TABLE_LIST object is just placeholder for prelocking, it will be diff --git a/sql/unireg.cc b/sql/unireg.cc index ebbf1177953..66be20736e8 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -35,7 +35,7 @@ static uchar * pack_screens(List<create_field> &create_fields, uint *info_length, uint *screens, bool small_file); static uint pack_keys(uchar *keybuff,uint key_count, KEY *key_info, ulong data_offset); -static bool pack_header(uchar *forminfo,enum db_type table_type, +static bool pack_header(uchar *forminfo,enum legacy_db_type table_type, List<create_field> &create_fields, uint info_length, uint screens, uint table_options, ulong data_offset, handler *file); @@ -43,7 +43,7 @@ static uint get_interval_id(uint *int_count,List<create_field> &create_fields, create_field *last_field); static bool pack_fields(File file, List<create_field> &create_fields, ulong data_offset); -static bool make_empty_rec(THD *thd, int file, enum db_type table_type, +static bool make_empty_rec(THD *thd, int file, enum legacy_db_type table_type, uint table_options, List<create_field> &create_fields, uint reclength, ulong data_offset, @@ -103,7 +103,8 @@ bool mysql_create_frm(THD *thd, const char *file_name, create_info->null_bits++; data_offset= (create_info->null_bits + 7) / 8; - if (pack_header(forminfo, create_info->db_type,create_fields,info_length, + if (pack_header(forminfo, ha_legacy_type(create_info->db_type), + create_fields,info_length, screens, create_info->table_options, data_offset, db_file)) { @@ -115,7 +116,8 @@ bool mysql_create_frm(THD *thd, const char *file_name, thd->net.last_error[0]=0; if (!(screen_buff=pack_screens(create_fields,&info_length,&screens,1))) DBUG_RETURN(1); - if (pack_header(forminfo, create_info->db_type, create_fields,info_length, + if (pack_header(forminfo, ha_legacy_type(create_info->db_type), + create_fields,info_length, screens, create_info->table_options, data_offset, db_file)) { my_free((gptr) screen_buff,MYF(0)); @@ -125,7 +127,7 @@ bool mysql_create_frm(THD *thd, const char *file_name, reclength=uint2korr(forminfo+266); /* Calculate extra data segment length */ - str_db_type.str= (char *) ha_get_storage_engine(create_info->db_type); + str_db_type.str= (char *) ha_resolve_storage_engine_name(create_info->db_type); str_db_type.length= strlen(str_db_type.str); /* str_db_type */ create_info->extra_size= (2 + str_db_type.length + @@ -168,7 +170,7 @@ bool mysql_create_frm(THD *thd, const char *file_name, #ifdef WITH_PARTITION_STORAGE_ENGINE if (part_info) - fileinfo[61]= (uchar) part_info->default_engine_type; + fileinfo[61]= (uchar) ha_legacy_type(part_info->default_engine_type); #endif int2store(fileinfo+59,db_file->extra_rec_buf_length()); if (my_pwrite(file,(byte*) fileinfo,64,0L,MYF_RW) || @@ -178,7 +180,8 @@ bool mysql_create_frm(THD *thd, const char *file_name, VOID(my_seek(file, (ulong) uint2korr(fileinfo+6)+ (ulong) key_buff_length, MY_SEEK_SET,MYF(0))); - if (make_empty_rec(thd,file,create_info->db_type,create_info->table_options, + if (make_empty_rec(thd,file,ha_legacy_type(create_info->db_type), + create_info->table_options, create_fields,reclength, data_offset, db_file)) goto err; @@ -480,7 +483,7 @@ static uint pack_keys(uchar *keybuff, uint key_count, KEY *keyinfo, /* Make formheader */ -static bool pack_header(uchar *forminfo, enum db_type table_type, +static bool pack_header(uchar *forminfo, enum legacy_db_type table_type, List<create_field> &create_fields, uint info_length, uint screens, uint table_options, ulong data_offset, handler *file) @@ -739,7 +742,7 @@ static bool pack_fields(File file, List<create_field> &create_fields, /* save an empty record on start of formfile */ -static bool make_empty_rec(THD *thd, File file,enum db_type table_type, +static bool make_empty_rec(THD *thd, File file,enum legacy_db_type table_type, uint table_options, List<create_field> &create_fields, uint reclength, diff --git a/storage/csv/Makefile.am b/storage/csv/Makefile.am new file mode 100644 index 00000000000..1d3c47bd650 --- /dev/null +++ b/storage/csv/Makefile.am @@ -0,0 +1,39 @@ +# Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#called from the top level Makefile + +MYSQLDATAdir = $(localstatedir) +MYSQLSHAREdir = $(pkgdatadir) +MYSQLBASEdir= $(prefix) +MYSQLLIBdir= $(pkglibdir) +INCLUDES = -I$(top_srcdir)/include \ + -I$(top_srcdir)/regex \ + -I$(top_srcdir)/sql \ + -I$(srcdir) +WRAPLIBS= + +pkglib_LTLIBRARIES = ha_csv.la + +ha_csv_la_LDFLAGS = -module +ha_csv_la_SOURCES = ha_tina.cc + +LDADD = + +DEFS = -DMYSQL_SERVER @DEFS@ + +# Don't update the files from bitkeeper +%::SCCS/s.% diff --git a/sql/examples/ha_tina.cc b/storage/csv/ha_tina.cc index 4f2dc0b5cac..7bb68d4502b 100644 --- a/sql/examples/ha_tina.cc +++ b/storage/csv/ha_tina.cc @@ -51,18 +51,22 @@ TODO: #include "ha_tina.h" #include <sys/mman.h> +#include <plugin.h> + /* Stuff for shares */ pthread_mutex_t tina_mutex; static HASH tina_open_tables; static int tina_init= 0; static handler *tina_create_handler(TABLE_SHARE *table); +static int tina_init_func(); handlerton tina_hton= { + MYSQL_HANDLERTON_INTERFACE_VERSION, "CSV", SHOW_OPTION_YES, "CSV storage engine", DB_TYPE_CSV_DB, - NULL, /* One needs to be written! */ + (bool (*)()) tina_init_func, 0, /* slot */ 0, /* savepoint size. */ NULL, /* close_connection */ @@ -81,12 +85,9 @@ handlerton tina_hton= { tina_create_handler, /* Create a new handler */ NULL, /* Drop a database */ tina_end, /* Panic call */ - NULL, /* Release temporary latches */ - NULL, /* Update Statistics */ NULL, /* Start Consistent Snapshot */ NULL, /* Flush logs */ NULL, /* Show status */ - NULL, /* Replication Report Sent Binlog */ HTON_CAN_RECREATE }; @@ -155,6 +156,35 @@ int get_mmap(TINA_SHARE *share, int write) DBUG_RETURN(0); } + +static int tina_init_func() +{ + if (!tina_init) + { + tina_init++; + VOID(pthread_mutex_init(&tina_mutex,MY_MUTEX_INIT_FAST)); + (void) hash_init(&tina_open_tables,system_charset_info,32,0,0, + (hash_get_key) tina_get_key,0,0); + } + return 0; +} + +static int tina_done_func() +{ + if (tina_init) + { + if (tina_open_tables.records) + { + return 1; + } + hash_free(&tina_open_tables); + pthread_mutex_destroy(&tina_mutex); + tina_init--; + } + return 0; +} + + /* Simple lock controls. */ @@ -164,19 +194,6 @@ static TINA_SHARE *get_share(const char *table_name, TABLE *table) char *tmp_name; uint length; - if (!tina_init) - { - /* Hijack a mutex for init'ing the storage engine */ - pthread_mutex_lock(&LOCK_mysql_create_db); - if (!tina_init) - { - tina_init++; - VOID(pthread_mutex_init(&tina_mutex,MY_MUTEX_INIT_FAST)); - (void) hash_init(&tina_open_tables,system_charset_info,32,0,0, - (hash_get_key) tina_get_key,0,0); - } - pthread_mutex_unlock(&LOCK_mysql_create_db); - } pthread_mutex_lock(&tina_mutex); length=(uint) strlen(table_name); if (!(share=(TINA_SHARE*) hash_search(&tina_open_tables, @@ -262,13 +279,7 @@ static int free_share(TINA_SHARE *share) int tina_end(ha_panic_function type) { - if (tina_init) - { - hash_free(&tina_open_tables); - VOID(pthread_mutex_destroy(&tina_mutex)); - } - tina_init= 0; - return 0; + return tina_done_func(); } /* @@ -933,3 +944,16 @@ int ha_tina::create(const char *name, TABLE *table_arg, DBUG_RETURN(0); } +mysql_declare_plugin +{ + MYSQL_STORAGE_ENGINE_PLUGIN, + &tina_hton, + tina_hton.name, + 0x00010000 /* 0.1.0 */, + "Brian Aker, MySQL AB", + "CSV Storage Engine", + tina_init_func, /* Plugin Init */ + tina_done_func /* Plugin Deinit */ +} +mysql_declare_plugin_end; + diff --git a/sql/examples/ha_tina.h b/storage/csv/ha_tina.h index c46750fb703..c46750fb703 100644 --- a/sql/examples/ha_tina.h +++ b/storage/csv/ha_tina.h diff --git a/storage/example/Makefile.am b/storage/example/Makefile.am new file mode 100644 index 00000000000..d5896946c5b --- /dev/null +++ b/storage/example/Makefile.am @@ -0,0 +1,39 @@ +# Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#called from the top level Makefile + +MYSQLDATAdir = $(localstatedir) +MYSQLSHAREdir = $(pkgdatadir) +MYSQLBASEdir= $(prefix) +MYSQLLIBdir= $(pkglibdir) +INCLUDES = -I$(top_srcdir)/include \ + -I$(top_srcdir)/regex \ + -I$(top_srcdir)/sql \ + -I$(srcdir) +WRAPLIBS= + +pkglib_LTLIBRARIES = ha_example.la + +ha_example_la_LDFLAGS = -module +ha_example_la_SOURCES = ha_example.cc + +LDADD = + +DEFS = -DMYSQL_SERVER @DEFS@ + +# Don't update the files from bitkeeper +%::SCCS/s.% diff --git a/sql/examples/ha_example.cc b/storage/example/ha_example.cc index 5b32b549e8d..74f25d1411d 100644 --- a/sql/examples/ha_example.cc +++ b/storage/example/ha_example.cc @@ -68,17 +68,20 @@ #endif #include "../mysql_priv.h" +#include <plugin.h> #include "ha_example.h" static handler* example_create_handler(TABLE_SHARE *table); +static int example_init_func(); handlerton example_hton= { + MYSQL_HANDLERTON_INTERFACE_VERSION, "EXAMPLE", SHOW_OPTION_YES, "Example storage engine", DB_TYPE_EXAMPLE_DB, - NULL, /* We do need to write one! */ + (bool (*)()) example_init_func, 0, /* slot */ 0, /* savepoint size. */ NULL, /* close_connection */ @@ -123,6 +126,34 @@ static byte* example_get_key(EXAMPLE_SHARE *share,uint *length, } +static int example_init_func() +{ + if (!example_init) + { + example_init++; + VOID(pthread_mutex_init(&example_mutex,MY_MUTEX_INIT_FAST)); + (void) hash_init(&example_open_tables,system_charset_info,32,0,0, + (hash_get_key) example_get_key,0,0); + } + return 0; +} + +static int example_done_func() +{ + if (example_init) + { + if (example_open_tables.records) + { + return 1; + } + hash_free(&example_open_tables); + pthread_mutex_destroy(&example_mutex); + example_init--; + } + return 0; +} + + /* Example of simple lock controls. The "share" it creates is structure we will pass to each example handler. Do you have to have one of these? Well, you have @@ -134,25 +165,6 @@ static EXAMPLE_SHARE *get_share(const char *table_name, TABLE *table) uint length; char *tmp_name; - /* - So why does this exist? There is no way currently to init a storage engine. - Innodb and BDB both have modifications to the server to allow them to - do this. Since you will not want to do this, this is probably the next - best method. - */ - if (!example_init) - { - /* Hijack a mutex for init'ing the storage engine */ - pthread_mutex_lock(&LOCK_mysql_create_db); - if (!example_init) - { - example_init++; - VOID(pthread_mutex_init(&example_mutex,MY_MUTEX_INIT_FAST)); - (void) hash_init(&example_open_tables,system_charset_info,32,0,0, - (hash_get_key) example_get_key,0,0); - } - pthread_mutex_unlock(&LOCK_mysql_create_db); - } pthread_mutex_lock(&example_mutex); length=(uint) strlen(table_name); @@ -186,7 +198,6 @@ static EXAMPLE_SHARE *get_share(const char *table_name, TABLE *table) error: pthread_mutex_destroy(&share->mutex); - pthread_mutex_unlock(&example_mutex); my_free((gptr) share, MYF(0)); return NULL; @@ -713,3 +724,17 @@ int ha_example::create(const char *name, TABLE *table_arg, /* This is not implemented but we want someone to be able that it works. */ DBUG_RETURN(0); } + +mysql_declare_plugin +{ + MYSQL_STORAGE_ENGINE_PLUGIN, + &example_hton, + example_hton.name, + 0x01000000 /* 1.0.0 */, + "Brian Aker, MySQL AB", + "Example Storage Engine", + tina_init_func, /* Plugin Init */ + tina_done_func /* Plugin Deinit */ +} +mysql_declare_plugin_end; + diff --git a/sql/examples/ha_example.h b/storage/example/ha_example.h index 139a50a3281..139a50a3281 100644 --- a/sql/examples/ha_example.h +++ b/storage/example/ha_example.h |