diff options
660 files changed, 24777 insertions, 13564 deletions
diff --git a/.bzrignore b/.bzrignore index f176efe0e0a..835e4b2c357 100644 --- a/.bzrignore +++ b/.bzrignore @@ -1,3 +1,4 @@ +*-t *.a *.bb *.bbg @@ -458,6 +459,7 @@ libmysqld/emb_qcache.cpp libmysqld/errmsg.c libmysqld/event.cc libmysqld/event_executor.cc +libmysqld/event_scheduler.cc libmysqld/event_timed.cc libmysqld/examples/client_test.c libmysqld/examples/client_test.cc @@ -788,6 +790,8 @@ mysys/main.cc mysys/my_new.cpp mysys/raid.cpp mysys/ste5KbMa +mysys/test_atomic +mysys/test_bitmap mysys/test_charset mysys/test_dir mysys/test_gethwaddr @@ -1770,4 +1774,3 @@ vio/viotest-sslconnect.cpp vio/viotest.cpp zlib/*.ds? zlib/*.vcproj -mysys/test_bitmap diff --git a/BUILD/SETUP.sh b/BUILD/SETUP.sh index 589e609beeb..02d160158b3 100755 --- a/BUILD/SETUP.sh +++ b/BUILD/SETUP.sh @@ -82,8 +82,11 @@ path=`dirname $0` export AM_MAKEFLAGS AM_MAKEFLAGS="-j 4" -# SSL library to use. -SSL_LIBRARY=--with-yassl +# SSL library to use.--with-ssl will select our bundled yaSSL +# implementation of SSL. To use openSSl you will nee too point out +# the location of openSSL headers and lbs on your system. +# Ex --with-ssl=/usr +SSL_LIBRARY=--with-ssl if [ "x$warning_mode" != "xpedantic" ]; then # Both C and C++ warnings diff --git a/BUILD/autorun.sh b/BUILD/autorun.sh index 63bab3565c6..9ffe61b250a 100755 --- a/BUILD/autorun.sh +++ b/BUILD/autorun.sh @@ -3,19 +3,25 @@ die() { echo "$@"; exit 1; } +# Added glibtoolize reference to make native OSX autotools work +if [ -f /usr/bin/glibtoolize ] + then + LIBTOOLIZE=glibtoolize + else + LIBTOOLIZE=libtoolize +fi + +(cd storage/bdb/dist && sh s_all) +(cd storage/innobase && aclocal && autoheader && \ + $LIBTOOLIZE --automake --force --copy && \ + automake --force --add-missing --copy && autoconf) + aclocal || die "Can't execute aclocal" autoheader || die "Can't execute autoheader" # --force means overwrite ltmain.sh script if it already exists -# Added glibtoolize reference to make native OSX autotools work -if test -f /usr/bin/glibtoolize ; then - glibtoolize --automake --force || die "Can't execute glibtoolize" -else - libtoolize --automake --force || die "Can't execute libtoolize" -fi +$LIBTOOLIZE --automake --force || die "Can't execute libtoolize" # --add-missing instructs automake to install missing auxiliary files # and --force to overwrite them if they already exist automake --add-missing --force || die "Can't execute automake" autoconf || die "Can't execute autoconf" -(cd storage/bdb/dist && sh s_all) -(cd storage/innobase && aclocal && autoheader && aclocal && automake && autoconf) diff --git a/BUILD/compile-dist b/BUILD/compile-dist index dea29d4612b..326de19da13 100755 --- a/BUILD/compile-dist +++ b/BUILD/compile-dist @@ -7,13 +7,15 @@ # package" that is used as the basis for all other binary builds. # make distclean +(cd storage/bdb/dist && sh s_all) +(cd storage/innobase && aclocal && autoheader && \ + libtoolize --automake --force --copy && \ + automake --force --add-missing --copy && autoconf) aclocal autoheader libtoolize --automake --force --copy automake --force --add-missing --copy autoconf -(cd storage/bdb/dist && sh s_all) -(cd storage/innobase && aclocal && autoheader && aclocal && automake && autoconf) # Default to gcc for CC and CXX if test -z "$CXX" ; then @@ -52,7 +54,7 @@ fi --with-federated-storage-engine \ --with-berkeley-db \ --with-innodb \ - --with-yassl \ + --with-ssl \ --enable-thread-safe-client \ --with-extra-charsets=complex \ --with-ndbcluster \ diff --git a/BUILD/compile-pentium-debug-openssl b/BUILD/compile-pentium-debug-openssl index 91c3b448c7e..2e24dbfd2f1 100755 --- a/BUILD/compile-pentium-debug-openssl +++ b/BUILD/compile-pentium-debug-openssl @@ -6,6 +6,6 @@ path=`dirname $0` extra_flags="$pentium_cflags $debug_cflags" extra_configs="$pentium_configs $debug_configs" -extra_configs="$extra_configs --with-debug=full --with-openssl" +extra_configs="$extra_configs --with-debug=full --with-ssl=/usr" . "$path/FINISH.sh" diff --git a/BUILD/compile-pentium-debug-yassl b/BUILD/compile-pentium-debug-yassl index 84ca489903d..61ad2937c4a 100755 --- a/BUILD/compile-pentium-debug-yassl +++ b/BUILD/compile-pentium-debug-yassl @@ -6,6 +6,6 @@ path=`dirname $0` extra_flags="$pentium_cflags $debug_cflags" extra_configs="$pentium_configs $debug_configs" -extra_configs="$extra_configs --with-debug=full --with-yassl" +extra_configs="$extra_configs --with-debug=full --with-ssl" . "$path/FINISH.sh" diff --git a/BUILD/compile-pentium-gcov b/BUILD/compile-pentium-gcov index 05cb0bb0d78..b024bba49bf 100755 --- a/BUILD/compile-pentium-gcov +++ b/BUILD/compile-pentium-gcov @@ -3,8 +3,19 @@ path=`dirname $0` . "$path/SETUP.sh" -extra_flags="$pentium_cflags -fprofile-arcs -ftest-coverage" +# Need to disable ccache, or we loose the gcov-needed compiler output files. +CCACHE_DISABLE=1 +export CCACHE_DISABLE + +# GCC4 needs -fprofile-arcs -ftest-coverage on the linker command line (as well +# as on the compiler command line), and this requires setting LDFLAGS for BDB. +export LDFLAGS="-fprofile-arcs -ftest-coverage" + +# The -fprofile-arcs and -ftest-coverage options cause GCC to instrument the +# code with profiling information used by gcov. +# the -DDISABLE_TAO_ASM is needed to avoid build failures in Yassl. +extra_flags="$pentium_cflags -fprofile-arcs -ftest-coverage -DDISABLE_TAO_ASM" extra_configs="$pentium_configs $debug_configs --disable-shared $static_link" -extra_configs="$extra_configs --with-innodb --with-berkeley-db" +extra_configs="$extra_configs $max_configs" . "$path/FINISH.sh" diff --git a/cmakelists.txt b/CMakeLists.txt index 5edc33b9f5a..5edc33b9f5a 100644 --- a/cmakelists.txt +++ b/CMakeLists.txt diff --git a/Makefile.am b/Makefile.am index 8709fca34c3..dfa6c7f0f07 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,7 +20,7 @@ AUTOMAKE_OPTIONS = foreign # These are built from source in the Docs directory EXTRA_DIST = INSTALL-SOURCE INSTALL-WIN-SOURCE \ - README COPYING EXCEPTIONS-CLIENT cmakelists.txt + README COPYING EXCEPTIONS-CLIENT CMakeLists.txt SUBDIRS = . include @docs_dirs@ @zlib_dir@ \ @readline_topdir@ sql-common \ @thread_dirs@ pstack \ diff --git a/client/cmakelists.txt b/client/CMakeLists.txt index 26cc36c7f6f..26cc36c7f6f 100644 --- a/client/cmakelists.txt +++ b/client/CMakeLists.txt diff --git a/client/Makefile.am b/client/Makefile.am index 0531d741764..be2888367a6 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -77,19 +77,19 @@ strings_src=decimal.c DEFS = -DUNDEF_THREADS_HACK \ -DDEFAULT_MYSQL_HOME="\"$(prefix)\"" \ -DDATADIR="\"$(localstatedir)\"" -EXTRA_DIST = get_password.c cmakelists.txt +EXTRA_DIST = get_password.c CMakeLists.txt link_sources: for f in $(sql_src) ; do \ rm -f $$f; \ @LN_CP_F@ $(top_srcdir)/sql/$$f $$f; \ - done; \ - for f in $(strings_src) ; do \ - rm -f $(srcdir)/$$f; \ - @LN_CP_F@ $(top_srcdir)/strings/$$f $$f; \ - done; \ - rm -f $(srcdir)/my_user.c; \ - @LN_CP_F@ $(top_srcdir)/sql-common/my_user.c my_user.c + done; + for f in $(strings_src) ; do \ + rm -f $(srcdir)/$$f; \ + @LN_CP_F@ $(top_srcdir)/strings/$$f $$f; \ + done; + -rm -f $(srcdir)/my_user.c; + @LN_CP_F@ $(top_srcdir)/sql-common/my_user.c my_user.c # Don't update the files from bitkeeper diff --git a/client/client_priv.h b/client/client_priv.h index 625fbf24fa6..bcaa74d3228 100644 --- a/client/client_priv.h +++ b/client/client_priv.h @@ -58,5 +58,5 @@ enum options_client OPT_IGNORE_TABLE,OPT_INSERT_IGNORE,OPT_SHOW_WARNINGS,OPT_DROP_DATABASE, OPT_TZ_UTC, OPT_AUTO_CLOSE, OPT_CREATE_SLAP_SCHEMA, OPT_MYSQL_REPLACE_INTO, OPT_BASE64_OUTPUT, OPT_SERVER_ID, - OPT_FIX_TABLE_NAMES, OPT_FIX_DB_NAMES + OPT_FIX_TABLE_NAMES, OPT_FIX_DB_NAMES, OPT_SSL_VERIFY_SERVER_CERT }; diff --git a/client/get_password.c b/client/get_password.c index 1b7b4e65a9f..b643b760718 100644 --- a/client/get_password.c +++ b/client/get_password.c @@ -64,7 +64,7 @@ /* were just going to fake it here and get input from the keyboard */ -char *get_tty_password(char *opt_message) +char *get_tty_password(const char *opt_message) { char to[80]; char *pos=to,*end=to+sizeof(to)-1; @@ -150,7 +150,7 @@ static void get_password(char *to,uint length,int fd,bool echo) #endif /* ! HAVE_GETPASS */ -char *get_tty_password(char *opt_message) +char *get_tty_password(const char *opt_message) { #ifdef HAVE_GETPASS char *passbuff; diff --git a/client/mysql.cc b/client/mysql.cc index 1557d5cae2a..96df1fafc3b 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -448,6 +448,14 @@ int main(int argc,char *argv[]) MYF(MY_WME)); if (histfile) sprintf(histfile,"%s/.mysql_history",getenv("HOME")); + char link_name[FN_REFLEN]; + if (my_readlink(link_name, histfile, 0) == 0 && + strncmp(link_name, "/dev/null", 10) == 0) + { + /* The .mysql_history file is a symlink to /dev/null, don't use it */ + my_free(histfile, MYF(MY_ALLOW_ZERO_PTR)); + histfile= 0; + } } if (histfile) { @@ -484,7 +492,7 @@ sig_handler mysql_end(int sig) { mysql_close(&mysql); #ifdef HAVE_READLINE - if (!status.batch && !quick && !opt_html && !opt_xml) + if (!status.batch && !quick && !opt_html && !opt_xml && histfile) { /* write-history */ if (verbose) @@ -2338,8 +2346,7 @@ print_table_data(MYSQL_RES *result) uint visible_length; uint extra_padding; - /* If this column may have a null value, use "NULL" for empty. */ - if (! not_null_flag[off] && (lengths[off] == 0)) + if (! not_null_flag[off] && (cur[off] == NULL)) { buffer= "NULL"; data_length= 4; @@ -3144,6 +3151,8 @@ sql_real_connect(char *host,char *database,char *user,char *password, if (opt_use_ssl) mysql_ssl_set(&mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca, opt_ssl_capath, opt_ssl_cipher); + mysql_options(&mysql,MYSQL_OPT_SSL_VERIFY_SERVER_CERT, + (char*)&opt_ssl_verify_server_cert); #endif if (opt_protocol) mysql_options(&mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol); diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc index 5b52d524f8e..57ab4e071fb 100644 --- a/client/mysqladmin.cc +++ b/client/mysqladmin.cc @@ -340,6 +340,8 @@ int main(int argc,char *argv[]) if (opt_use_ssl) mysql_ssl_set(&mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca, opt_ssl_capath, opt_ssl_cipher); + mysql_options(&mysql,MYSQL_OPT_SSL_VERIFY_SERVER_CERT, + (char*)&opt_ssl_verify_server_cert); #endif if (opt_protocol) mysql_options(&mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol); diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 490a74e6035..81ad74466eb 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -72,6 +72,7 @@ static int port= 0; static const char* sock= 0; static const char* user = 0; static char* pass = 0; +static char *charset= 0; static ulonglong start_position, stop_position; #define start_position_mot ((my_off_t)start_position) @@ -733,6 +734,9 @@ static struct my_option my_long_options[] = "Extract only binlog entries created by the server having the given id.", (gptr*) &server_id, (gptr*) &server_id, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"set-charset", OPT_SET_CHARSET, + "Add 'SET NAMES character_set' to the output.", (gptr*) &charset, + (gptr*) &charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"short-form", 's', "Just show the queries, no extra info.", (gptr*) &short_form, (gptr*) &short_form, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -815,7 +819,8 @@ static void die(const char* fmt, ...) fprintf(stderr, "\n"); va_end(args); cleanup(); - my_end(0); + /* We cannot free DBUG, it is used in global destructors after exit(). */ + my_end(MY_DONT_FREE_DBUG); exit(1); } @@ -1456,6 +1461,13 @@ int main(int argc, char** argv) "/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE," "COMPLETION_TYPE=0*/;\n"); + if (charset) + fprintf(result_file, + "\n/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;" + "\n/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;" + "\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;" + "\n/*!40101 SET NAMES %s */;\n", charset); + for (save_stop_position= stop_position, stop_position= ~(my_off_t)0 ; (--argc >= 0) && !stop_passed ; ) { @@ -1480,6 +1492,12 @@ int main(int argc, char** argv) if (disable_log_bin) fprintf(result_file, "/*!32316 SET SQL_LOG_BIN=@OLD_SQL_LOG_BIN*/;\n"); + if (charset) + fprintf(result_file, + "/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n" + "/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n" + "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n"); + if (tmpdir.list) free_tmpdir(&tmpdir); if (result_file != stdout) @@ -1487,7 +1505,8 @@ int main(int argc, char** argv) cleanup(); free_defaults(defaults_argv); my_free_open_file_info(); - my_end(0); + /* We cannot free DBUG, it is used in global destructors after exit(). */ + my_end(MY_DONT_FREE_DBUG); exit(exit_value); DBUG_RETURN(exit_value); // Keep compilers happy } diff --git a/client/mysqldump.c b/client/mysqldump.c index 82da5d990b9..e257e3734a1 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -918,6 +918,8 @@ static int dbConnect(char *host, char *user,char *passwd) if (opt_use_ssl) mysql_ssl_set(&mysql_connection, opt_ssl_key, opt_ssl_cert, opt_ssl_ca, opt_ssl_capath, opt_ssl_cipher); + mysql_options(&mysql_connection,MYSQL_OPT_SSL_VERIFY_SERVER_CERT, + (char*)&opt_ssl_verify_server_cert); #endif if (opt_protocol) mysql_options(&mysql_connection,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol); @@ -3061,14 +3063,13 @@ static my_bool dump_all_views_in_db(char *database) different case (e.g. T1 vs t1) RETURN - int - 0 if a tablename was retrieved. 1 if not + pointer to the table name + 0 if error */ -static int get_actual_table_name(const char *old_table_name, - char *new_table_name, - int buf_size) +static char *get_actual_table_name(const char *old_table_name, MEM_ROOT *root) { - int retval; + char *name= 0; MYSQL_RES *table_res; MYSQL_ROW row; char query[50 + 2*NAME_LEN]; @@ -3085,66 +3086,55 @@ static int get_actual_table_name(const char *old_table_name, safe_exit(EX_MYSQLERR); } - retval = 1; - if ((table_res= mysql_store_result(sock))) { my_ulonglong num_rows= mysql_num_rows(table_res); if (num_rows > 0) { + ulong *lengths; /* Return first row TODO: Return all matching rows */ row= mysql_fetch_row(table_res); - strmake(new_table_name, row[0], buf_size-1); - retval= 0; + lengths= mysql_fetch_lengths(table_res); + name= strmake_root(root, row[0], lengths[0]); } mysql_free_result(table_res); } - DBUG_RETURN(retval); + DBUG_PRINT("exit", ("new_table_name: %s", name)); + DBUG_RETURN(name); } static int dump_selected_tables(char *db, char **table_names, int tables) { - uint i; char table_buff[NAME_LEN*+3]; - char new_table_name[NAME_LEN]; DYNAMIC_STRING lock_tables_query; - HASH dump_tables; - char *table_name; + MEM_ROOT root; + char **dump_tables, **pos, **end; DBUG_ENTER("dump_selected_tables"); if (init_dumping(db)) DBUG_RETURN(1); - /* Init hash table for storing the actual name of tables to dump */ - if (hash_init(&dump_tables, charset_info, 16, 0, 0, - (hash_get_key) get_table_key, (hash_free_key) free_table_ent, - 0)) + init_alloc_root(&root, 8192, 0); + if (!(dump_tables= pos= (char**) alloc_root(&root, tables * sizeof(char *)))) exit(EX_EOM); init_dynamic_string(&lock_tables_query, "LOCK TABLES ", 256, 1024); for (; tables > 0 ; tables-- , table_names++) { /* the table name passed on commandline may be wrong case */ - if (!get_actual_table_name(*table_names, - new_table_name, sizeof(new_table_name))) + if ((*pos= get_actual_table_name(*table_names, &root))) { /* Add found table name to lock_tables_query */ if (lock_tables) { - dynstr_append(&lock_tables_query, - quote_name(new_table_name, table_buff, 1)); + dynstr_append(&lock_tables_query, quote_name(*pos, table_buff, 1)); dynstr_append(&lock_tables_query, " READ /*!32311 LOCAL */,"); } - - /* Add found table name to dump_tables list */ - if (my_hash_insert(&dump_tables, - (byte*)my_strdup(new_table_name, MYF(0)))) - exit(EX_EOM); - + pos++; } else { @@ -3154,6 +3144,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables) /* We shall countinue here, if --force was given */ } } + end= pos; if (lock_tables) { @@ -3173,24 +3164,20 @@ static int dump_selected_tables(char *db, char **table_names, int tables) print_xml_tag1(md_result_file, "", "database name=", db, "\n"); /* Dump each selected table */ - for (i= 0; i < dump_tables.records; i++) + for (pos= dump_tables; pos < end; pos++) { - table_name= hash_element(&dump_tables, i); - DBUG_PRINT("info",("Dumping table %s", table_name)); - dump_table(table_name,db); + DBUG_PRINT("info",("Dumping table %s", *pos)); + dump_table(*pos, db); if (opt_dump_triggers && mysql_get_server_version(sock) >= 50009) - dump_triggers_for_table(table_name, db); + dump_triggers_for_table(*pos, db); } /* Dump each selected view */ if (was_views) { - for(i=0; i < dump_tables.records; i++) - { - table_name= hash_element(&dump_tables, i); - get_view_structure(table_name, db); - } + for (pos= dump_tables; pos < end; pos++) + get_view_structure(*pos, db); } if (opt_events && !opt_xml && mysql_get_server_version(sock) >= 50106) @@ -3205,7 +3192,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables) DBUG_PRINT("info", ("Dumping routines for database %s", db)); dump_routines_for_db(db); } - hash_free(&dump_tables); + free_root(&root, MYF(0)); my_free(order_by, MYF(MY_ALLOW_ZERO_PTR)); order_by= 0; if (opt_xml) diff --git a/client/mysqlimport.c b/client/mysqlimport.c index 42d521a1412..ccd6932e25b 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -406,6 +406,8 @@ static MYSQL *db_connect(char *host, char *database, if (opt_use_ssl) mysql_ssl_set(mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca, opt_ssl_capath, opt_ssl_cipher); + mysql_options(mysql,MYSQL_OPT_SSL_VERIFY_SERVER_CERT, + (char*)&opt_ssl_verify_server_cert); #endif if (opt_protocol) mysql_options(mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol); diff --git a/client/mysqlshow.c b/client/mysqlshow.c index 504f0d9844b..d090495ff81 100644 --- a/client/mysqlshow.c +++ b/client/mysqlshow.c @@ -109,6 +109,8 @@ int main(int argc, char **argv) if (opt_use_ssl) mysql_ssl_set(&mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca, opt_ssl_capath, opt_ssl_cipher); + mysql_options(&mysql,MYSQL_OPT_SSL_VERIFY_SERVER_CERT, + (char*)&opt_ssl_verify_server_cert); #endif if (opt_protocol) mysql_options(&mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol); diff --git a/client/mysqltest.c b/client/mysqltest.c index ce876708fbc..774cbac6e3f 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -87,14 +87,6 @@ #endif #define MAX_SERVER_ARGS 64 -/* - Sometimes in a test the client starts before - the server - to solve the problem, we try again - after some sleep if connection fails the first - time -*/ -#define CON_RETRY_SLEEP 2 -#define MAX_CON_TRIES 5 #define SLAVE_POLL_INTERVAL 300000 /* 0.3 of a sec */ #define DEFAULT_DELIMITER ";" @@ -108,7 +100,7 @@ enum {OPT_MANAGER_USER=256,OPT_MANAGER_HOST,OPT_MANAGER_PASSWD, OPT_MANAGER_PORT,OPT_MANAGER_WAIT_TIMEOUT, OPT_SKIP_SAFEMALLOC, OPT_SSL_SSL, OPT_SSL_KEY, OPT_SSL_CERT, OPT_SSL_CA, OPT_SSL_CAPATH, OPT_SSL_CIPHER,OPT_PS_PROTOCOL,OPT_SP_PROTOCOL,OPT_CURSOR_PROTOCOL, - OPT_VIEW_PROTOCOL}; + OPT_VIEW_PROTOCOL, OPT_SSL_VERIFY_SERVER_CERT, OPT_MAX_CONNECT_RETRIES}; /* ************************************************************************ */ /* @@ -158,6 +150,7 @@ static char *db = 0, *pass=0; const char *user = 0, *host = 0, *unix_sock = 0, *opt_basedir="./"; const char *opt_include= 0; static int port = 0; +static int opt_max_connect_retries; static my_bool opt_big_test= 0, opt_compress= 0, silent= 0, verbose = 0; static my_bool tty_password= 0; static my_bool ps_protocol= 0, ps_protocol_enabled= 0; @@ -2501,9 +2494,16 @@ void init_manager() db, port, sock NOTE - This function will try to connect to the given server MAX_CON_TRIES - times and sleep CON_RETRY_SLEEP seconds between attempts before - finally giving up. This helps in situation when the client starts + + Sometimes in a test the client starts before + the server - to solve the problem, we try again + after some sleep if connection fails the first + time + + This function will try to connect to the given server + "opt_max_connect_retries" times and sleep "connection_retry_sleep" + seconds between attempts before finally giving up. + This helps in situation when the client starts before the server (which happens sometimes). It will ignore any errors during these retries. One should use connect_n_handle_errors() if he expects a connection error and wants @@ -2518,8 +2518,9 @@ int safe_connect(MYSQL* mysql, const char *host, const char *user, { int con_error= 1; my_bool reconnect= 1; + static int connection_retry_sleep= 2; /* Seconds */ int i; - for (i= 0; i < MAX_CON_TRIES; ++i) + for (i= 0; i < opt_max_connect_retries; i++) { if (mysql_real_connect(mysql, host,user, pass, db, port, sock, CLIENT_MULTI_STATEMENTS | CLIENT_REMEMBER_OPTIONS)) @@ -2527,7 +2528,7 @@ int safe_connect(MYSQL* mysql, const char *host, const char *user, con_error= 0; break; } - sleep(CON_RETRY_SLEEP); + sleep(connection_retry_sleep); } /* TODO: change this to 0 in future versions, but the 'kill' test relies on @@ -2755,8 +2756,12 @@ int do_connect(struct st_query *q) #ifdef HAVE_OPENSSL if (opt_use_ssl || con_ssl) + { mysql_ssl_set(&next_con->mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca, opt_ssl_capath, opt_ssl_cipher); + mysql_options(&next_con->mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, + &opt_ssl_verify_server_cert); + } #endif if (con_sock && !free_con_sock && *con_sock && *con_sock != FN_LIBCHAR) con_sock=fn_format(buff, con_sock, TMPDIR, "",0); @@ -3290,6 +3295,10 @@ static struct my_option my_long_options[] = {"manager-wait-timeout", OPT_MANAGER_WAIT_TIMEOUT, "Undocumented: Used for debugging.", (gptr*) &manager_wait_timeout, (gptr*) &manager_wait_timeout, 0, GET_INT, REQUIRED_ARG, 3, 0, 0, 0, 0, 0}, + {"max-connect-retries", OPT_MAX_CONNECT_RETRIES, + "Max number of connection attempts when connecting to server", + (gptr*) &opt_max_connect_retries, (gptr*) &opt_max_connect_retries, 0, + GET_INT, REQUIRED_ARG, 5, 1, 10, 0, 0, 0}, {"password", 'p', "Password to use when connecting to server.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, {"port", 'P', "Port number to use for connection.", (gptr*) &port, @@ -5207,9 +5216,14 @@ int main(int argc, char **argv) mysql_options(&cur_con->mysql, MYSQL_SET_CHARSET_NAME, charset_name); #ifdef HAVE_OPENSSL + opt_ssl_verify_server_cert= TRUE; /* Always on in mysqltest */ if (opt_use_ssl) + { mysql_ssl_set(&cur_con->mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca, opt_ssl_capath, opt_ssl_cipher); + mysql_options(&cur_con->mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, + &opt_ssl_verify_server_cert); + } #endif if (!(cur_con->name = my_strdup("default", MYF(MY_WME)))) diff --git a/config/ac-macros/ha_ndbcluster.m4 b/config/ac-macros/ha_ndbcluster.m4 index aee445f8d58..505d000c196 100644 --- a/config/ac-macros/ha_ndbcluster.m4 +++ b/config/ac-macros/ha_ndbcluster.m4 @@ -237,7 +237,7 @@ AC_DEFUN([MYSQL_SETUP_NDBCLUSTER], [ if test X"$have_ndb_binlog" = Xyes then - AC_DEFINE([HAVE_NDB_BINLOG], [1], + AC_DEFINE([WITH_NDB_BINLOG], [1], [Including Ndb Cluster Binlog]) AC_MSG_RESULT([Including Ndb Cluster Binlog]) else diff --git a/config/ac-macros/misc.m4 b/config/ac-macros/misc.m4 index a2f70071e2d..3ed64b5625b 100644 --- a/config/ac-macros/misc.m4 +++ b/config/ac-macros/misc.m4 @@ -155,84 +155,6 @@ fi ]) -#---START: Used in for client configure -AC_DEFUN([MYSQL_CHECK_ULONG], -[AC_MSG_CHECKING(for type ulong) -AC_CACHE_VAL(ac_cv_ulong, -[AC_TRY_RUN([#include <stdio.h> -#include <sys/types.h> -main() -{ - ulong foo; - foo++; - exit(0); -}], ac_cv_ulong=yes, ac_cv_ulong=no, ac_cv_ulong=no)]) -AC_MSG_RESULT($ac_cv_ulong) -if test "$ac_cv_ulong" = "yes" -then - AC_DEFINE([HAVE_ULONG], [1], [system headers define ulong]) -fi -]) - -AC_DEFUN([MYSQL_CHECK_UCHAR], -[AC_MSG_CHECKING(for type uchar) -AC_CACHE_VAL(ac_cv_uchar, -[AC_TRY_RUN([#include <stdio.h> -#include <sys/types.h> -main() -{ - uchar foo; - foo++; - exit(0); -}], ac_cv_uchar=yes, ac_cv_uchar=no, ac_cv_uchar=no)]) -AC_MSG_RESULT($ac_cv_uchar) -if test "$ac_cv_uchar" = "yes" -then - AC_DEFINE([HAVE_UCHAR], [1], [system headers define uchar]) -fi -]) - -AC_DEFUN([MYSQL_CHECK_UINT], -[AC_MSG_CHECKING(for type uint) -AC_CACHE_VAL(ac_cv_uint, -[AC_TRY_RUN([#include <stdio.h> -#include <sys/types.h> -main() -{ - uint foo; - foo++; - exit(0); -}], ac_cv_uint=yes, ac_cv_uint=no, ac_cv_uint=no)]) -AC_MSG_RESULT($ac_cv_uint) -if test "$ac_cv_uint" = "yes" -then - AC_DEFINE([HAVE_UINT], [1], [system headers define uint]) -fi -]) - - -AC_DEFUN([MYSQL_CHECK_IN_ADDR_T], -[AC_MSG_CHECKING(for type in_addr_t) -AC_CACHE_VAL(ac_cv_in_addr_t, -[AC_TRY_RUN([#include <stdio.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> - -int main(int argc, char **argv) -{ - in_addr_t foo; - exit(0); -}], ac_cv_in_addr_t=yes, ac_cv_in_addr_t=no, ac_cv_in_addr_t=no)]) -AC_MSG_RESULT($ac_cv_in_addr_t) -if test "$ac_cv_in_addr_t" = "yes" -then - AC_DEFINE([HAVE_IN_ADDR_T], [1], [system headers define in_addr_t]) -fi -]) - - AC_DEFUN([MYSQL_PTHREAD_YIELD], [AC_CACHE_CHECK([if pthread_yield takes zero arguments], ac_cv_pthread_yield_zero_arg, [AC_TRY_LINK([#define _GNU_SOURCE @@ -272,25 +194,6 @@ fi #---END: -AC_DEFUN([MYSQL_CHECK_FP_EXCEPT], -[AC_MSG_CHECKING(for type fp_except) -AC_CACHE_VAL(ac_cv_fp_except, -[AC_TRY_RUN([#include <stdio.h> -#include <sys/types.h> -#include <ieeefp.h> -main() -{ - fp_except foo; - foo++; - exit(0); -}], ac_cv_fp_except=yes, ac_cv_fp_except=no, ac_cv_fp_except=no)]) -AC_MSG_RESULT($ac_cv_fp_except) -if test "$ac_cv_fp_except" = "yes" -then - AC_DEFINE([HAVE_FP_EXCEPT], [1], [fp_except from ieeefp.h]) -fi -]) - # From fileutils-3.14/aclocal.m4 # @defmac AC_PROG_CC_STDC diff --git a/config/ac-macros/openssl.m4 b/config/ac-macros/openssl.m4 deleted file mode 100644 index a23c46eed00..00000000000 --- a/config/ac-macros/openssl.m4 +++ /dev/null @@ -1,136 +0,0 @@ -AC_DEFUN([MYSQL_FIND_OPENSSL], [ - incs="$1" - libs="$2" - eval shrexts=\"$shrext_cmds\" - case "$incs---$libs" in - ---) - for d in /usr/ssl/include /usr/local/ssl/include /usr/include \ -/usr/include/ssl /opt/ssl/include /opt/openssl/include \ -/usr/local/ssl/include /usr/local/include /usr/freeware/include ; do - if test -f $d/openssl/ssl.h ; then - OPENSSL_INCLUDE=-I$d - fi - done - - for d in /usr/ssl/lib /usr/local/ssl/lib /usr/lib/openssl \ -/usr/lib /usr/lib64 /opt/ssl/lib /opt/openssl/lib \ -/usr/freeware/lib32 /usr/local/lib/ ; do - # Just to be safe, we test for ".so" anyway - if test -f $d/libssl.a || test -f $d/libssl.so || test -f $d/libssl$shrext ; then - OPENSSL_LIB=$d - fi - done - ;; - ---* | *---) - AC_MSG_ERROR([if either 'includes' or 'libs' is specified, both must be specified]) - ;; - * ) - if test -f $incs/openssl/ssl.h ; then - OPENSSL_INCLUDE=-I$incs - fi - # Just to be safe, we test for ".so" anyway - if test -f $libs/libssl.a || test -f $libs/libssl.so || test -f $libs/libssl$shrext ; then - OPENSSL_LIB=$libs - fi - ;; - esac - - # On RedHat 9 we need kerberos to compile openssl - for d in /usr/kerberos/include - do - if test -f $d/krb5.h ; then - OPENSSL_KERBEROS_INCLUDE="$d" - fi - done - - - if test -z "$OPENSSL_LIB" -o -z "$OPENSSL_INCLUDE" ; then - echo "Could not find an installation of OpenSSL" - if test -n "$OPENSSL_LIB" ; then - if test "$TARGET_LINUX" = "true"; then - echo "Looks like you've forgotten to install OpenSSL development RPM" - fi - fi - exit 1 - fi - -]) - -AC_DEFUN([MYSQL_CHECK_OPENSSL], [ -AC_MSG_CHECKING(for OpenSSL) - AC_ARG_WITH([openssl], - [ --with-openssl[=DIR] Include the OpenSSL support], - [openssl="$withval"], - [openssl=no]) - - AC_ARG_WITH([openssl-includes], - [ - --with-openssl-includes=DIR - Find OpenSSL headers in DIR], - [openssl_includes="$withval"], - [openssl_includes=""]) - - AC_ARG_WITH([openssl-libs], - [ - --with-openssl-libs=DIR - Find OpenSSL libraries in DIR], - [openssl_libs="$withval"], - [openssl_libs=""]) - - if test "$openssl" != "no" - then - if test "$openssl" != "yes" - then - if test -z "$openssl_includes" - then - openssl_includes="$openssl/include" - fi - if test -z "$openssl_libs" - then - openssl_libs="$openssl/lib" - fi - fi - MYSQL_FIND_OPENSSL([$openssl_includes], [$openssl_libs]) - #force VIO use - AC_MSG_RESULT(yes) - openssl_libs="-L$OPENSSL_LIB -lssl -lcrypto" - # Don't set openssl_includes to /usr/include as this gives us a lot of - # compiler warnings when using gcc 3.x - openssl_includes="" - if test "$OPENSSL_INCLUDE" != "-I/usr/include" - then - openssl_includes="$OPENSSL_INCLUDE" - fi - if test "$OPENSSL_KERBEROS_INCLUDE" - then - openssl_includes="$openssl_includes -I$OPENSSL_KERBEROS_INCLUDE" - fi - AC_DEFINE([HAVE_OPENSSL], [1], [OpenSSL]) - - # openssl-devel-0.9.6 requires dlopen() and we can't link staticly - # on many platforms (We should actually test this here, but it's quite - # hard) to do as we are doing libtool for linking. - using_static="" - case "$CLIENT_EXTRA_LDFLAGS $MYSQLD_EXTRA_LDFLAGS" in - *-all-static*) using_static="yes" ;; - esac - if test "$using_static" = "yes" - then - echo "You can't use the --all-static link option when using openssl." - exit 1 - fi - NON_THREADED_CLIENT_LIBS="$NON_THREADED_CLIENT_LIBS $openssl_libs" - else - AC_MSG_RESULT(no) - if test ! -z "$openssl_includes" - then - AC_MSG_ERROR(Can't have --with-openssl-includes without --with-openssl); - fi - if test ! -z "$openssl_libs" - then - AC_MSG_ERROR(Can't have --with-openssl-libs without --with-openssl); - fi - fi - AC_SUBST(openssl_libs) - AC_SUBST(openssl_includes) -]) diff --git a/config/ac-macros/plugins.m4 b/config/ac-macros/plugins.m4 index aa28a611e9e..4bf9292547d 100644 --- a/config/ac-macros/plugins.m4 +++ b/config/ac-macros/plugins.m4 @@ -39,6 +39,10 @@ AC_DEFUN([_MYSQL_PLUGIN],[ m4_define([MYSQL_PLUGIN_NAME_]AS_TR_CPP([$1]), [$3]) m4_define([MYSQL_PLUGIN_DESC_]AS_TR_CPP([$1]), [$4]) _MYSQL_PLUGAPPEND_META([$1], $5) + ifelse(m4_bregexp(__mysql_include__,[/plug\.in$]),-1,[],[ + MYSQL_PLUGIN_DIRECTORY([$1], + m4_bregexp(__mysql_include__,[^\(.*\)/plug\.in$],[\1])) + ]) ]) ]) @@ -249,7 +253,6 @@ AC_DEFUN([MYSQL_PLUGIN_ACTIONS],[ ]) ]) - dnl --------------------------------------------------------------------------- dnl Macro: MYSQL_CONFIGURE_PLUGINS dnl @@ -267,6 +270,10 @@ AC_DEFUN([MYSQL_CONFIGURE_PLUGINS],[ AC_FATAL([cannot use [MYSQL_CONFIGURE_PLUGINS] multiple times]) ],[ m4_define([__mysql_plugin_configured__],[done]) + _MYSQL_INCLUDE_LIST( + m4_bpatsubst(m4_esyscmd([ls plugin/*/plug.in storage/*/plug.in 2>/dev/null]), +[[ +]],[,])) m4_ifdef([__mysql_plugin_list__],[ _MYSQL_CHECK_PLUGIN_ARGS([$1]) _MYSQL_CONFIGURE_PLUGINS(m4_bpatsubst(__mysql_plugin_list__, :, [,])) @@ -397,11 +404,11 @@ dnl Although this is "pretty", it breaks libmysqld build m4_ifdef([$6],[ if test -n "$mysql_use_plugin_dir" ; then mysql_plugin_dirs="$mysql_plugin_dirs $6" - if test -f "$srcdir/$6/configure" ; then - other_configures="$other_configures $6/configure" - else - AC_CONFIG_FILES($6/Makefile) - fi + m4_syscmd(test -f "$6/configure") + ifelse(m4_sysval, 0, + [other_configures="$other_configures $6/configure"], + [AC_CONFIG_FILES($6/Makefile)] + ) ifelse(m4_substr($6, 0, 8), [storage/], [mysql_se_dirs="$mysql_se_dirs ]m4_substr($6, 8)", m4_substr($6, 0, 7), [plugin/], @@ -730,4 +737,26 @@ _MYSQL_EMIT_PLUGINS(m4_bpatsubst(__mysql_plugin_list__, :, [,])) _MYSQL_EMIT_PLUGIN_DEPENDS(m4_bpatsubst(__mysql_plugin_list__, :, [,])) ]) +dnl --------------------------------------------------------------------------- +dnl Macro: _MYSQL_INCLUDE_LIST +dnl +dnl SYNOPSIS +dnl _MYSQL_INCLUDE_LIST([filename,filename...]) +dnl +dnl DESCRIPTION +dnl includes all files from the list +dnl +dnl --------------------------------------------------------------------------- +AC_DEFUN([_MYSQL_INCLUDE_LIST],[ + ifelse([$1], [], [], [ + m4_define([__mysql_include__],[$1]) + dnl We have to use builtin(), because sinclude would generate an error + dnl "file $1 does not exists" in aclocal-1.8 - which is a bug, clearly + dnl violating m4 specs, and which is fixed in aclocal-1.9 + builtin([include],$1) + m4_undefine([__mysql_include__]) + _MYSQL_INCLUDE_LIST(m4_shift($@)) + ]) +]) + dnl =========================================================================== diff --git a/config/ac-macros/replication.m4 b/config/ac-macros/replication.m4 index 3a0c83d6498..babfa000a82 100644 --- a/config/ac-macros/replication.m4 +++ b/config/ac-macros/replication.m4 @@ -15,7 +15,7 @@ AC_DEFUN([MYSQL_CHECK_REPLICATION], [ case "$row_based" in yes ) - AC_DEFINE([HAVE_ROW_BASED_REPLICATION], [1], [Define to have row-based replication]) + AC_DEFINE([WITH_ROW_BASED_REPLICATION], [1], [Define to have row-based replication]) AC_MSG_RESULT([-- including row-based replication]) [have_row_based=yes] ;; diff --git a/config/ac-macros/ssl.m4 b/config/ac-macros/ssl.m4 new file mode 100644 index 00000000000..0f2f207c36f --- /dev/null +++ b/config/ac-macros/ssl.m4 @@ -0,0 +1,210 @@ +dnl =========================================================================== +dnl Support for SSL +dnl =========================================================================== +dnl +dnl + +dnl --------------------------------------------------------------------------- +dnl Macro: MYSQL_USE_BUNDLED_YASSL +dnl +dnl SYNOPSIS +dnl MYSQL_USE_BUNDLED_YASSL() +dnl +dnl DESCRIPTION +dnl Add defines so yassl is built and linked with +dnl --------------------------------------------------------------------------- +AC_DEFUN([MYSQL_USE_BUNDLED_YASSL], [ + + AC_CONFIG_FILES(extra/yassl/Makefile dnl + extra/yassl/taocrypt/Makefile dnl + extra/yassl/taocrypt/benchmark/Makefile dnl + extra/yassl/taocrypt/src/Makefile dnl + extra/yassl/taocrypt/test/Makefile dnl + extra/yassl/src/Makefile dnl + extra/yassl/testsuite/Makefile) + + with_bundled_yassl="yes" + + yassl_dir="yassl" + AC_SUBST([yassl_dir]) + + yassl_libs="-L\$(top_srcdir)/extra/yassl/src -lyassl -L\$(top_srcdir)/extra/yassl/taocrypt/src -ltaocrypt" + AC_SUBST(yassl_libs) + yassl_includes="-I\$(top_srcdir)/extra/yassl/include" + AC_SUBST(yassl_includes) + + AC_DEFINE([HAVE_OPENSSL], [1], [Defined by configure. Using yaSSL for SSL.]) + AC_DEFINE([HAVE_YASSL], [1], [Defined by configure. Using yaSSL for SSL.]) + + # System specific checks + yassl_integer_extra_cxxflags="" + case $host_cpu--$CXX_VERSION in + sparc*--*Sun*C++*5.6*) + # Disable inlining when compiling taocrypt/src/ + yassl_taocrypt_extra_cxxflags="+d" + AC_MSG_NOTICE([disabling inlining for yassl/taocrypt/src/]) + ;; + esac + AC_SUBST([yassl_taocrypt_extra_cxxflags]) + + # Link extra/yassl/include/openssl subdir to include/ + yassl_h_ln_cmd="\$(LN) -s \$(top_srcdir)/extra/yassl/include/openssl openssl" + AC_SUBST(yassl_h_ln_cmd) + + AC_MSG_RESULT([using bundled yaSSL]) +]) + + +dnl --------------------------------------------------------------------------- +dnl Macro: MYSQL_CHECK_SSL_DIR +dnl +dnl SYNOPSIS +dnl MYSQL_CHECK_SSL_DIR(includes, libs) +dnl +dnl DESCRIPTION +dnl Auxiliary macro to check for ssl at given path +dnl +dnl --------------------------------------------------------------------------- + +AC_DEFUN([MYSQL_CHECK_SSL_DIR], [ +ssl_incs="$1" +ssl_libs="$2" +save_CPPFLAGS="$CPPFLAGS" +save_LIBS="$LIBS" +CPPFLAGS="$ssl_incs $CPPFLAGS" +LIBS="$LIBS $ssl_libs" +AC_TRY_LINK([#include <openssl/ssl.h>], + [return SSL_library_init();], + [mysql_ssl_found="yes"], + [mysql_ssl_found="no"]) +CPPFLAGS="$save_CPPFLAGS" +LIBS="$save_LIBS" +]) + + +dnl --------------------------------------------------------------------------- +dnl Macro: MYSQL_FIND_OPENSSL +dnl +dnl SYNOPSIS +dnl MYSQL_FIND_OPENSSL(location) +dnl +dnl DESCRIPTION +dnl Search the location for OpenSSL support +dnl +dnl --------------------------------------------------------------------------- +AC_DEFUN([MYSQL_FIND_OPENSSL], [ + location="$1" + + # + # Set include paths + # + openssl_include="$location/include" + openssl_includes="" + + # Don't set ssl_includes to /usr/include as this gives us a lot of + # compiler warnings when using gcc 3.x + if test "$openssl_include" != "/usr/include" + then + openssl_includes="-I$ssl_include" + fi + + # + # Try to link with openSSL libs in <location> + # + openssl_libs="-L$location/lib/ -lssl -lcrypto" + MYSQL_CHECK_SSL_DIR([$openssl_includes], [$openssl_libs]) + + if test "$mysql_ssl_found" == "no" + then + # + # BUG 764: Compile failure with OpenSSL on Red Hat Linux (krb5.h missing) + # Try to link with include paths to kerberos set + # + openssl_includes="$openssl_includes -I/usr/kerberos/include" + MYSQL_CHECK_SSL_DIR([$openssl_includes], [$openssl_libs]) + fi + + if test "$mysql_ssl_found" == "no" + then + AC_MSG_ERROR([Could not link with SSL libs at $location]) + fi + + # openssl-devel-0.9.6 requires dlopen() and we can't link staticly + # on many platforms (We should actually test this here, but it's quite + # hard to do as we are doing libtool for linking.) + case "$CLIENT_EXTRA_LDFLAGS $MYSQLD_EXTRA_LDFLAGS" in + *-all-static*) + AC_MSG_ERROR([You can't use the --all-static link option when using openssl.]) + ;; + esac + + AC_SUBST(openssl_includes) + AC_SUBST(openssl_libs) + + NON_THREADED_CLIENT_LIBS="$NON_THREADED_CLIENT_LIBS $openssl_libs" + + AC_DEFINE([HAVE_OPENSSL], [1], [OpenSSL]) + AC_MSG_RESULT([using openSSL from $location]) +]) + + + +dnl ------------------------------------------------------------------------ +dnl Macro: MYSQL_CHECK_SSL +dnl +dnl SYNOPSIS +dnl MYSQL_CHECK_SSL +dnl +dnl Provides the following configure options: +dnl --with-ssl=DIR +dnl Possible DIR values are: +dnl - no - the macro will disable use of ssl +dnl - bundled, empty or not specified - means use ssl lib +dnl bundled along with MySQL sources +dnl - ssl location prefix - given location prefix, the macro expects +dnl to find the header files in $prefix/include/, and libraries in +dnl $prefix/lib. If headers or libraries weren't found at $prefix, the +dnl macro bails out with error. +dnl +dnl ------------------------------------------------------------------------ +AC_DEFUN([MYSQL_CHECK_SSL], [ +AC_MSG_CHECKING(for SSL) + AC_ARG_WITH([ssl], + [ --with-ssl[=DIR] Include SSL support], + [mysql_ssl_dir="$withval"], + [mysql_ssl_dir=no]) + + if test "$with_yassl" + then + AC_MSG_ERROR([The flag --with-yassl is deprecated, use --with-ssl]) + fi + + if test "$with_openssl" + then + AC_MSG_ERROR([The flag --with-openssl is deprecated, use --with-ssl]) + fi + + case "$mysql_ssl_dir" in + "no") + # + # Don't include SSL support + # + AC_MSG_RESULT([disabled]) + ;; + + "bundled"|"yes") + # + # Use the bundled SSL implementation (yaSSL) + # + MYSQL_USE_BUNDLED_YASSL + ;; + + *) + # + # A location where to search for OpenSSL was specified + # + MYSQL_FIND_OPENSSL([$mysql_ssl_dir]) + ;; + esac + AM_CONDITIONAL([HAVE_YASSL], [ test "$with_bundled_yassl" = "yes" ]) +]) diff --git a/config/ac-macros/yassl.m4 b/config/ac-macros/yassl.m4 deleted file mode 100644 index f6eee32ff84..00000000000 --- a/config/ac-macros/yassl.m4 +++ /dev/null @@ -1,45 +0,0 @@ -AC_DEFUN([MYSQL_CHECK_YASSL], [ - AC_MSG_CHECKING(for yaSSL) - AC_ARG_WITH([yassl], [ --with-yassl Include the yaSSL support],,) - - if test "$with_yassl" = "yes" - then - if test "$openssl" != "no" - then - AC_MSG_ERROR([Cannot configure MySQL to use yaSSL and OpenSSL simultaneously.]) - fi - AC_MSG_RESULT([using bundled yaSSL]) - AC_CONFIG_FILES(extra/yassl/Makefile dnl - extra/yassl/taocrypt/Makefile dnl - extra/yassl/taocrypt/benchmark/Makefile dnl - extra/yassl/taocrypt/src/Makefile dnl - extra/yassl/taocrypt/test/Makefile dnl - extra/yassl/src/Makefile dnl - extra/yassl/testsuite/Makefile) - yassl_dir="yassl" - yassl_libs="-L\$(top_srcdir)/extra/yassl/src -lyassl -L\$(top_srcdir)/extra/yassl/taocrypt/src -ltaocrypt" - yassl_includes="-I\$(top_srcdir)/extra/yassl/include" - AC_DEFINE([HAVE_OPENSSL], [1], [Defined by configure. Using yaSSL for OpenSSL emulation.]) - AC_DEFINE([HAVE_YASSL], [1], [Defined by configure. Using yaSSL for OpenSSL emulation.]) - # System specific checks - yassl_integer_extra_cxxflags="" - case $host_cpu--$CXX_VERSION in - sparc*--*Sun*C++*5.6*) - # Disable inlining when compiling taocrypt/src/ - yassl_taocrypt_extra_cxxflags="+d" - AC_MSG_NOTICE([disabling inlining for yassl/taocrypt/src/]) - ;; - esac - AC_SUBST([yassl_taocrypt_extra_cxxflags]) - # Link extra/yassl/include/openssl subdir to include/ - yassl_h_ln_cmd="\$(LN) -s \$(top_srcdir)/extra/yassl/include/openssl openssl" - AC_SUBST(yassl_h_ln_cmd) - else - yassl_dir="" - AC_MSG_RESULT(no) - fi - AC_SUBST(yassl_libs) - AC_SUBST(yassl_includes) - AC_SUBST(yassl_dir) - AM_CONDITIONAL([HAVE_YASSL], [ test "$with_yassl" = "yes" ]) -]) diff --git a/config/ac-macros/zlib.m4 b/config/ac-macros/zlib.m4 index 713e7072c6f..17b951d4723 100644 --- a/config/ac-macros/zlib.m4 +++ b/config/ac-macros/zlib.m4 @@ -89,10 +89,11 @@ case $SYSTEM_TYPE in fi ;; *) - # Just to be safe, we test for ".so" anyway - eval shrexts=\"$shrext_cmds\" - if test \( -f "$mysql_zlib_dir/lib/libz.a" -o -f "$mysql_zlib_dir/lib/libz.so" -o \ - -f "$mysql_zlib_dir/lib/libz$shrext" \) \ + # Test for libz using all known library file endings + if test \( -f "$mysql_zlib_dir/lib/libz.a" -o \ + -f "$mysql_zlib_dir/lib/libz.so" -o \ + -f "$mysql_zlib_dir/lib/libz.sl" -o \ + -f "$mysql_zlib_dir/lib/libz.dylib" \) \ -a -f "$mysql_zlib_dir/include/zlib.h"; then ZLIB_INCLUDES="-I$mysql_zlib_dir/include" ZLIB_LIBS="-L$mysql_zlib_dir/lib -lz" diff --git a/configure.in b/configure.in index e159a5803f1..be6f3c8eaec 100644 --- a/configure.in +++ b/configure.in @@ -7,7 +7,7 @@ AC_INIT(sql/mysqld.cc) AC_CANONICAL_SYSTEM # The Docs Makefile.am parses this line! # remember to also change ndb version below and update version.c in ndb -AM_INIT_AUTOMAKE(mysql, 5.1.10-beta) +AM_INIT_AUTOMAKE(mysql, 5.1.12-beta) AM_CONFIG_HEADER(config.h) PROTOCOL_VERSION=10 @@ -36,10 +36,9 @@ sinclude(config/ac-macros/ha_berkeley.m4) sinclude(config/ac-macros/ha_ndbcluster.m4) sinclude(config/ac-macros/large_file.m4) sinclude(config/ac-macros/misc.m4) -sinclude(config/ac-macros/openssl.m4) sinclude(config/ac-macros/readline.m4) sinclude(config/ac-macros/replication.m4) -sinclude(config/ac-macros/yassl.m4) +sinclude(config/ac-macros/ssl.m4) sinclude(config/ac-macros/zlib.m4) # Remember to add a directory sql/share/LANGUAGE @@ -779,48 +778,6 @@ struct request_info *req; AC_SUBST(WRAPLIBS) if test "$TARGET_LINUX" = "true"; then - AC_MSG_CHECKING([for atomic operations]) - - AC_LANG_SAVE - AC_LANG_CPLUSPLUS - - atom_ops= - AC_TRY_RUN([ -#include <asm/atomic.h> -int main() -{ - atomic_t v; - - atomic_set(&v, 23); - atomic_add(5, &v); - return atomic_read(&v) == 28 ? 0 : -1; -} - ], - [AC_DEFINE([HAVE_ATOMIC_ADD], [1], - [atomic_add() from <asm/atomic.h> (Linux only)]) - atom_ops="${atom_ops}atomic_add "], - ) - AC_TRY_RUN([ -#include <asm/atomic.h> -int main() -{ - atomic_t v; - - atomic_set(&v, 23); - atomic_sub(5, &v); - return atomic_read(&v) == 18 ? 0 : -1; -} - ], - [AC_DEFINE([HAVE_ATOMIC_SUB], [1], - [atomic_sub() from <asm/atomic.h> (Linux only)]) - atom_ops="${atom_ops}atomic_sub "], - ) - - if test -z "$atom_ops"; then atom_ops="no"; fi - AC_MSG_RESULT($atom_ops) - - AC_LANG_RESTORE - AC_ARG_WITH(pstack, [ --with-pstack Use the pstack backtrace library], [ USE_PSTACK=$withval ], @@ -872,38 +829,20 @@ fi # Later in this script LIBS will be augmented with a threads library. NON_THREADED_LIBS="$LIBS" -AC_MSG_CHECKING([for int8]) -case $SYSTEM_TYPE in - *netware) - AC_MSG_RESULT([no]) - ;; - *) -AC_TRY_RUN([ -#ifdef HAVE_STDLIB_H -#include <stdlib.h> -#endif - -#ifdef HAVE_STDDEF_H -#include <stddef.h> -#endif - -#ifdef HAVE_SYS_TYPES_H +AC_CHECK_TYPES([int8, uint8, int16, uint16, int32, uint32, int64, uint64, + uchar, uint, ulong],[],[], [ #include <sys/types.h> -#endif - -int main() -{ - int8 i; - return 0; -} -], -[AC_DEFINE([HAVE_INT_8_16_32], [1], - [whether int8, int16 and int32 types exist]) -AC_MSG_RESULT([yes])], -[AC_MSG_RESULT([no])] -) - ;; -esac +]) +AC_CHECK_TYPES([in_addr_t], [], [], [ +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +]) +AC_CHECK_TYPES([fp_except], [], [], [ +#include <sys/types.h> +#include <ieeefp.h> +]) # # Some system specific hacks @@ -1088,7 +1027,7 @@ dnl Is this the right match for DEC OSF on alpha? # Edit Makefile.in files. # echo -n "configuring Makefile.in files for NetWare... " - for file in sql/Makefile.in libmysql/Makefile.in libmysql_r/Makefile.in sql/share/Makefile.in strings/Makefile.in client/Makefile.in + for file in sql/Makefile.in extra/Makefile.in client/Makefile.in do # echo "#### $file ####" filedir="`dirname $file`" @@ -1109,32 +1048,13 @@ dnl Is this the right match for DEC OSF on alpha? # Add library dependencies to mysqld_DEPENDENCIES lib_DEPENDENCIES="\$(pstack_libs) \$(openssl_libs) \$(yassl_libs)" cat > $filesed << EOF -s,\(^.*\$(MAKE) gen_lex_hash\)\$(EXEEXT),#\1, s,\(\./gen_lex_hash\)\$(EXEEXT),\1.linux, -s%\(mysqld_DEPENDENCIES = \) %\1$lib_DEPENDENCIES % +s%\(mysqld_DEPENDENCIES = \)%\1$lib_DEPENDENCIES % EOF ;; - sql/share/Makefile.in) + extra/Makefile.in) cat > $filesed << EOF -s,\(extra/comp_err\),\1.linux, -EOF - ;; - libmysql/Makefile.in) - cat > $filesed << EOF -s,\(\./conf_to_src\)\( \$(top_srcdir)\),\1.linux\2, -s,\(: conf_to_src\),\1.linux, -EOF - ;; - libmysql_r/Makefile.in) - cat > $filesed << EOF -s,\(\./conf_to_src\)\( \$(top_srcdir)\),\1.linux\2, -s,\(: conf_to_src\),\1.linux, -EOF - ;; - strings/Makefile.in) - cat > $filesed << EOF -s,\(\./conf_to_src\)\( \$(top_srcdir)\),\1.linux\2, -s,\(: conf_to_src\),\1.linux, +s,\(extra/comp_err\)\$(EXEEXT),\1.linux, EOF ;; client/Makefile.in) @@ -1651,6 +1571,20 @@ then fi fi +AC_ARG_WITH([atomic-ops], + AC_HELP_STRING([--with-atomic-ops=rwlocks|smp|up], + [Implement atomic operations using pthread rwlocks or atomic CPU + instructions for multi-processor (default) or uniprocessor + configuration]), , [with_atomic_ops=smp]) +case "$with_atomic_ops" in + "up") AC_DEFINE([MY_ATOMIC_MODE_DUMMY], [1], + [Assume single-CPU mode, no concurrency]) ;; + "rwlocks") AC_DEFINE([MY_ATOMIC_MODE_RWLOCKS], [1], + [Use pthread rwlocks for atomic ops]) ;; + "smp") ;; + *) AC_MSG_ERROR(["$with_atomic_ops" is not a valid value for --with-atomic-ops]) ;; +esac + # Force static compilation to avoid linking problems/get more speed AC_ARG_WITH(mysqld-ldflags, [ --with-mysqld-ldflags Extra linking arguments for mysqld], @@ -1782,16 +1716,6 @@ MYSQL_FUNC_ALLOCA MYSQL_TIMESPEC_TS # Do we have the tzname variable MYSQL_TZNAME -# Do the system files define ulong -MYSQL_CHECK_ULONG -# Do the system files define uchar -MYSQL_CHECK_UCHAR -# Do the system files define uint -MYSQL_CHECK_UINT -# Check for fp_except in ieeefp.h -MYSQL_CHECK_FP_EXCEPT -# Check for IN_ADDR_T -MYSQL_CHECK_IN_ADDR_T # Do the c++ compiler have a bool type MYSQL_CXX_BOOL # Check some common bugs with gcc 2.8.# on sparc @@ -2203,8 +2127,7 @@ MYSQL_CHECK_BIG_TABLES MYSQL_CHECK_MAX_INDEXES MYSQL_CHECK_REPLICATION MYSQL_CHECK_VIO -MYSQL_CHECK_OPENSSL -MYSQL_CHECK_YASSL +MYSQL_CHECK_SSL #-------------------------------------------------------------------- # Declare our plugin modules @@ -2212,12 +2135,6 @@ MYSQL_CHECK_YASSL # functions tested above #-------------------------------------------------------------------- -MYSQL_STORAGE_ENGINE(archive,, [Archive Storage Engine], - [Archive Storage Engine], [max,max-no-ndb]) -MYSQL_PLUGIN_DIRECTORY(archive, [storage/archive]) -MYSQL_PLUGIN_STATIC(archive, [libarchive.a]) -MYSQL_PLUGIN_DYNAMIC(archive, [ha_archive.la]) - MYSQL_STORAGE_ENGINE(berkeley, berkeley-db, [BerkeleyDB Storage Engine], [Transactional Tables using BerkeleyDB], [max,max-no-ndb]) MYSQL_PLUGIN_DIRECTORY(berkeley,[storage/bdb]) @@ -2236,12 +2153,6 @@ MYSQL_PLUGIN_DIRECTORY(csv, [storage/csv]) MYSQL_PLUGIN_STATIC(csv, [libcsv.a]) MYSQL_PLUGIN_MANDATORY(csv) dnl Used for logging -MYSQL_STORAGE_ENGINE(example,, [Example Storage Engine], - [Skeleton for Storage Engines for developers], [max,max-no-ndb]) -MYSQL_PLUGIN_DIRECTORY(example, [storage/example]) -MYSQL_PLUGIN_STATIC(example, [libexample.a]) -MYSQL_PLUGIN_DYNAMIC(example, [ha_example.la]) - MYSQL_STORAGE_ENGINE(federated,,[Federated Storage Engine], [Connects to tables on remote MySQL servers], [max,max-no-ndb]) diff --git a/dbug/cmakelists.txt b/dbug/CMakeLists.txt index fe20fdd3db6..fe20fdd3db6 100644 --- a/dbug/cmakelists.txt +++ b/dbug/CMakeLists.txt diff --git a/dbug/Makefile.am b/dbug/Makefile.am index b0c8862bede..60a95a82be5 100644 --- a/dbug/Makefile.am +++ b/dbug/Makefile.am @@ -20,7 +20,7 @@ LDADD = libdbug.a ../mysys/libmysys.a ../strings/libmystrings.a pkglib_LIBRARIES = libdbug.a noinst_HEADERS = dbug_long.h libdbug_a_SOURCES = dbug.c sanity.c -EXTRA_DIST = cmakelists.txt example1.c example2.c example3.c \ +EXTRA_DIST = CMakeLists.txt example1.c example2.c example3.c \ user.r monty.doc dbug_add_tags.pl \ my_main.c main.c factorial.c dbug_analyze.c NROFF_INC = example1.r example2.r example3.r main.r \ diff --git a/dbug/dbug.c b/dbug/dbug.c index 52de4b4a92d..07f72a3e758 100644 --- a/dbug/dbug.c +++ b/dbug/dbug.c @@ -255,6 +255,8 @@ static void DBUGOpenFile(CODE_STATE *,const char *, const char *, int); static void DBUGCloseFile(CODE_STATE *cs, FILE *fp); /* Push current debug settings */ static void PushState(CODE_STATE *cs); + /* Free memory associated with debug state. */ +static void FreeState (CODE_STATE *cs, struct settings *state); /* Test for tracing enabled */ static BOOLEAN DoTrace(CODE_STATE *cs); @@ -742,19 +744,7 @@ void _db_pop_() if (discard->next != NULL) { cs->stack= discard->next; - if (!is_shared(discard, keywords)) - FreeList(discard->keywords); - if (!is_shared(discard, functions)) - FreeList(discard->functions); - if (!is_shared(discard, processes)) - FreeList(discard->processes); - if (!is_shared(discard, p_functions)) - FreeList(discard->p_functions); - if (!is_shared(discard, out_file)) - DBUGCloseFile(cs, discard->out_file); - if (discard->prof_file) - DBUGCloseFile(cs, discard->prof_file); - free((char *) discard); + FreeState(cs, discard); } } @@ -1425,6 +1415,74 @@ static void PushState(CODE_STATE *cs) cs->stack= new_malloc; } +/* + * FUNCTION + * + * FreeState Free memory associated with a struct state. + * + * SYNOPSIS + * + * static void FreeState (state) + * struct state *state; + * + * DESCRIPTION + * + * Deallocates the memory allocated for various information in a + * state. + * + */ +static void FreeState ( +CODE_STATE *cs, +struct settings *state) +{ + if (!is_shared(state, keywords)) + FreeList(state->keywords); + if (!is_shared(state, functions)) + FreeList(state->functions); + if (!is_shared(state, processes)) + FreeList(state->processes); + if (!is_shared(state, p_functions)) + FreeList(state->p_functions); + if (!is_shared(state, out_file)) + DBUGCloseFile(cs, state->out_file); + if (state->prof_file) + DBUGCloseFile(cs, state->prof_file); + free((char *) state); +} + + +/* + * FUNCTION + * + * _db_end_ End debugging, freeing state stack memory. + * + * SYNOPSIS + * + * static VOID _db_end_ () + * + * DESCRIPTION + * + * Ends debugging, de-allocating the memory allocated to the + * state stack. + * + * To be called at the very end of the program. + * + */ +void _db_end_ () +{ + struct settings *discard; + CODE_STATE *cs=0; + + get_code_state_or_return; + + while((discard= cs->stack) != NULL) { + if(discard == &init_settings) + break; + cs->stack= discard->next; + FreeState (cs, discard); + } +} + /* * FUNCTION diff --git a/extra/cmakelists.txt b/extra/CMakeLists.txt index 50e0f04eb14..50e0f04eb14 100644 --- a/extra/cmakelists.txt +++ b/extra/CMakeLists.txt diff --git a/extra/Makefile.am b/extra/Makefile.am index 4b483128439..de8e519e641 100644 --- a/extra/Makefile.am +++ b/extra/Makefile.am @@ -40,7 +40,7 @@ $(top_builddir)/include/sql_state.h: $(top_builddir)/include/mysqld_error.h bin_PROGRAMS = replace comp_err perror resolveip my_print_defaults \ resolve_stack_dump mysql_waitpid innochecksum noinst_PROGRAMS = charset2html -EXTRA_DIST = cmakelists.txt +EXTRA_DIST = CMakeLists.txt perror.o: perror.c $(COMPILE) @ndbcluster_includes@ $(LM_CFLAGS) -c $< diff --git a/extra/yassl/cmakelists.txt b/extra/yassl/CMakeLists.txt index cafa3011e94..cafa3011e94 100644 --- a/extra/yassl/cmakelists.txt +++ b/extra/yassl/CMakeLists.txt diff --git a/extra/yassl/Makefile.am b/extra/yassl/Makefile.am index 60868f82add..e4a81019cd1 100644 --- a/extra/yassl/Makefile.am +++ b/extra/yassl/Makefile.am @@ -1,3 +1,3 @@ SUBDIRS = taocrypt src testsuite EXTRA_DIST = yassl.dsp yassl.dsw yassl.vcproj $(wildcard mySTL/*.hpp) \ - cmakelists.txt + CMakeLists.txt diff --git a/extra/yassl/README b/extra/yassl/README index ad59fe3965e..62209723f66 100644 --- a/extra/yassl/README +++ b/extra/yassl/README @@ -1,4 +1,37 @@ -yaSSL Release notes, version 1.2.2 (03/27/06) +yaSSL Release notes, version 1.3.0 (04/26/06) + + + This release of yaSSL contains minor bug fixes, portability enhancements, + and libcurl support. + +See normal build instructions below under 1.0.6. + + +--To build for libcurl on Linux, Solaris, *BSD, Mac OS X, or Cygwin: + + To build for libcurl the library needs to be built without C++ globals since + the linker will be called in a C context, also libcurl configure will expect + OpenSSL library names so some symbolic links are created. + + ./configure --enable-pure-c + make + make openssl-links + + (then go to your libcurl home and tell libcurl about yaSSL) + ./configure --with-ssl=/yaSSL-HomeDir + make + + +--To build for libcurl on Win32: + + Simply add the yaSSL project as a dependency to libcurl, add + yaSSL-Home\include and yaSSL-Home\include\openssl to the include list, and + define USE_SSLEAY and USE_OPENSSL + + please email todd@yassl.com if you have any questions. + + +*******************yaSSL Release notes, version 1.2.2 (03/27/06) This release of yaSSL contains minor bug fixes and portability enhancements. diff --git a/extra/yassl/certs/ca-cert.pem b/extra/yassl/certs/ca-cert.pem new file mode 100644 index 00000000000..981dd004fc6 --- /dev/null +++ b/extra/yassl/certs/ca-cert.pem @@ -0,0 +1,53 @@ +Certificate: + Data: + Version: 3 (0x2) + Serial Number: 0 (0x0) + Signature Algorithm: md5WithRSAEncryption + Issuer: C=US, ST=Oregon, L=Portland, O=sawtooth, CN=www.sawtooth-consulting.com/emailAddress=info@yassl.com + Validity + Not Before: Jan 18 20:12:32 2005 GMT + Not After : Oct 15 20:12:32 2007 GMT + Subject: C=US, ST=Oregon, L=Portland, O=sawtooth, CN=www.sawtooth-consulting.com/emailAddress=info@yassl.com + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public Key: (512 bit) + Modulus (512 bit): + 00:cf:2b:14:00:b0:3c:df:6f:9e:91:40:ec:c8:f6: + 90:b2:5b:b4:70:80:a5:a4:0a:73:c7:44:f3:2a:26: + c4:2f:f1:3a:f1:c3:c4:ac:fc:c3:d2:c3:bf:f5:d7: + 6a:38:42:ad:22:ab:c8:c4:4b:4c:1d:16:af:05:34: + 7d:79:97:5e:e1 + Exponent: 65537 (0x10001) + X509v3 extensions: + X509v3 Subject Key Identifier: + CB:0F:1F:E9:A2:76:71:C9:E6:E8:23:A6:C1:18:B7:CC:44:CF:B9:84 + X509v3 Authority Key Identifier: + keyid:CB:0F:1F:E9:A2:76:71:C9:E6:E8:23:A6:C1:18:B7:CC:44:CF:B9:84 + DirName:/C=US/ST=Oregon/L=Portland/O=sawtooth/CN=www.sawtooth-consulting.com/emailAddress=info@yassl.com + serial:00 + + X509v3 Basic Constraints: + CA:TRUE + Signature Algorithm: md5WithRSAEncryption + 27:f7:3d:fb:39:6f:73:a4:86:f3:a0:48:22:60:84:e9:5c:3d: + 28:36:05:16:44:98:07:87:e1:5d:b5:f3:a7:bc:33:5f:f4:29: + a9:5f:87:33:df:e6:8e:bd:e2:f3:0a:c8:00:69:ae:3d:41:47: + 03:ea:0b:4c:67:45:4b:ab:f3:39 +-----BEGIN CERTIFICATE----- +MIIC7zCCApmgAwIBAgIBADANBgkqhkiG9w0BAQQFADCBiTELMAkGA1UEBhMCVVMx +DzANBgNVBAgTBk9yZWdvbjERMA8GA1UEBxMIUG9ydGxhbmQxETAPBgNVBAoTCHNh +d3Rvb3RoMSQwIgYDVQQDExt3d3cuc2F3dG9vdGgtY29uc3VsdGluZy5jb20xHTAb +BgkqhkiG9w0BCQEWDmluZm9AeWFzc2wuY29tMB4XDTA1MDExODIwMTIzMloXDTA3 +MTAxNTIwMTIzMlowgYkxCzAJBgNVBAYTAlVTMQ8wDQYDVQQIEwZPcmVnb24xETAP +BgNVBAcTCFBvcnRsYW5kMREwDwYDVQQKEwhzYXd0b290aDEkMCIGA1UEAxMbd3d3 +LnNhd3Rvb3RoLWNvbnN1bHRpbmcuY29tMR0wGwYJKoZIhvcNAQkBFg5pbmZvQHlh +c3NsLmNvbTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDPKxQAsDzfb56RQOzI9pCy +W7RwgKWkCnPHRPMqJsQv8Trxw8Ss/MPSw7/112o4Qq0iq8jES0wdFq8FNH15l17h +AgMBAAGjgekwgeYwHQYDVR0OBBYEFMsPH+midnHJ5ugjpsEYt8xEz7mEMIG2BgNV +HSMEga4wgauAFMsPH+midnHJ5ugjpsEYt8xEz7mEoYGPpIGMMIGJMQswCQYDVQQG +EwJVUzEPMA0GA1UECBMGT3JlZ29uMREwDwYDVQQHEwhQb3J0bGFuZDERMA8GA1UE +ChMIc2F3dG9vdGgxJDAiBgNVBAMTG3d3dy5zYXd0b290aC1jb25zdWx0aW5nLmNv +bTEdMBsGCSqGSIb3DQEJARYOaW5mb0B5YXNzbC5jb22CAQAwDAYDVR0TBAUwAwEB +/zANBgkqhkiG9w0BAQQFAANBACf3Pfs5b3OkhvOgSCJghOlcPSg2BRZEmAeH4V21 +86e8M1/0KalfhzPf5o694vMKyABprj1BRwPqC0xnRUur8zk= +-----END CERTIFICATE----- diff --git a/extra/yassl/certs/client-cert.der b/extra/yassl/certs/client-cert.der Binary files differnew file mode 100644 index 00000000000..b28e2753376 --- /dev/null +++ b/extra/yassl/certs/client-cert.der diff --git a/extra/yassl/certs/client-cert.pem b/extra/yassl/certs/client-cert.pem new file mode 100644 index 00000000000..81110f17252 --- /dev/null +++ b/extra/yassl/certs/client-cert.pem @@ -0,0 +1,52 @@ +Certificate: + Data: + Version: 3 (0x2) + Serial Number: 0 (0x0) + Signature Algorithm: md5WithRSAEncryption + Issuer: C=US, ST=Oregon, L=Portland, O=yaSSL, CN=www.yassl.com/emailAddress=info@yassl.com + Validity + Not Before: Jan 18 19:33:15 2005 GMT + Not After : Oct 15 19:33:15 2007 GMT + Subject: C=US, ST=Oregon, L=Portland, O=yaSSL, CN=www.yassl.com/emailAddress=info@yassl.com + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public Key: (512 bit) + Modulus (512 bit): + 00:cd:1f:78:47:f8:b8:d6:08:bf:bd:7c:23:61:86: + 36:28:ac:ee:3c:a8:9a:94:e6:d5:26:e8:71:50:b2: + 26:8b:1c:1e:3f:75:b2:d3:b3:67:95:0c:fd:76:28: + 65:d5:ce:12:82:9e:06:00:a2:09:dd:ce:3a:26:dd: + 46:2a:a0:45:71 + Exponent: 65537 (0x10001) + X509v3 extensions: + X509v3 Subject Key Identifier: + AE:25:5E:FA:4D:A3:5B:2B:87:DE:F1:2A:F5:42:C0:FF:CE:B5:B4:AD + X509v3 Authority Key Identifier: + keyid:AE:25:5E:FA:4D:A3:5B:2B:87:DE:F1:2A:F5:42:C0:FF:CE:B5:B4:AD + DirName:/C=US/ST=Oregon/L=Portland/O=yaSSL/CN=www.yassl.com/emailAddress=info@yassl.com + serial:00 + + X509v3 Basic Constraints: + CA:TRUE + Signature Algorithm: md5WithRSAEncryption + c5:82:26:0c:1f:61:01:14:b0:ce:18:99:64:91:0e:f1:f8:90: + 3e:a3:0e:be:38:7c:97:ba:05:c9:2a:dc:dd:62:2d:12:61:79: + 7a:86:b1:97:5d:1e:e8:f7:e8:32:34:f7:8f:b1:08:3d:13:71: + a6:3c:15:91:85:12:35:6e:78:87 +-----BEGIN CERTIFICATE----- +MIICtzCCAmGgAwIBAgIBADANBgkqhkiG9w0BAQQFADB4MQswCQYDVQQGEwJVUzEP +MA0GA1UECBMGT3JlZ29uMREwDwYDVQQHEwhQb3J0bGFuZDEOMAwGA1UEChMFeWFT +U0wxFjAUBgNVBAMTDXd3dy55YXNzbC5jb20xHTAbBgkqhkiG9w0BCQEWDmluZm9A +eWFzc2wuY29tMB4XDTA1MDExODE5MzMxNVoXDTA3MTAxNTE5MzMxNVoweDELMAkG +A1UEBhMCVVMxDzANBgNVBAgTBk9yZWdvbjERMA8GA1UEBxMIUG9ydGxhbmQxDjAM +BgNVBAoTBXlhU1NMMRYwFAYDVQQDEw13d3cueWFzc2wuY29tMR0wGwYJKoZIhvcN +AQkBFg5pbmZvQHlhc3NsLmNvbTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDNH3hH ++LjWCL+9fCNhhjYorO48qJqU5tUm6HFQsiaLHB4/dbLTs2eVDP12KGXVzhKCngYA +ogndzjom3UYqoEVxAgMBAAGjgdUwgdIwHQYDVR0OBBYEFK4lXvpNo1srh97xKvVC +wP/OtbStMIGiBgNVHSMEgZowgZeAFK4lXvpNo1srh97xKvVCwP/OtbStoXykejB4 +MQswCQYDVQQGEwJVUzEPMA0GA1UECBMGT3JlZ29uMREwDwYDVQQHEwhQb3J0bGFu +ZDEOMAwGA1UEChMFeWFTU0wxFjAUBgNVBAMTDXd3dy55YXNzbC5jb20xHTAbBgkq +hkiG9w0BCQEWDmluZm9AeWFzc2wuY29tggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZI +hvcNAQEEBQADQQDFgiYMH2EBFLDOGJlkkQ7x+JA+ow6+OHyXugXJKtzdYi0SYXl6 +hrGXXR7o9+gyNPePsQg9E3GmPBWRhRI1bniH +-----END CERTIFICATE----- diff --git a/extra/yassl/certs/client-key.der b/extra/yassl/certs/client-key.der Binary files differnew file mode 100644 index 00000000000..6e8b432a07c --- /dev/null +++ b/extra/yassl/certs/client-key.der diff --git a/extra/yassl/certs/client-key.pem b/extra/yassl/certs/client-key.pem new file mode 100644 index 00000000000..6898b2796fa --- /dev/null +++ b/extra/yassl/certs/client-key.pem @@ -0,0 +1,9 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIBOgIBAAJBAM0feEf4uNYIv718I2GGNiis7jyompTm1SbocVCyJoscHj91stOz +Z5UM/XYoZdXOEoKeBgCiCd3OOibdRiqgRXECAwEAAQJAXwa6OVVvg7Bv63+MAI0l +n/hlMfLGEj9R9gFvJXwywPSEQhijOZmedpHALufFPNHtwba9dmbqMkBAw9JDaAgg +QQIhAO+mBaSmoG5AYVKYQZiASe/2wMZjaQSN+zFLyF97OX8ZAiEA2x5iRmXUkbOT +8Td/vx8R9mq9W5CJu+cN+SWGwTYhPBkCIGZFM6NQeKaUUvQshdHO7b66Twpa4jZP +YSNoc9pLe/4BAiB+jIvBkKo2A/rbg2waG32qTXdTXKTPiuA9Fnk/OV30cQIhANuA +uMdo+T+rYcNGJ1hCYKDe9JWBpNfSQ+H/A7sWuW8L +-----END RSA PRIVATE KEY----- diff --git a/extra/yassl/certs/dh1024.dat b/extra/yassl/certs/dh1024.dat new file mode 100644 index 00000000000..86a95518278 --- /dev/null +++ b/extra/yassl/certs/dh1024.dat @@ -0,0 +1 @@ +30818702818100DA9A18547FF03B385CC16508C173A7EF4EB61CB40EF8FEF3B31F145051676166BCDC3FE6B799FC394D08C26385F9413F896E09117E46209D6923602683CEA100924A6EE695281775C619DAA94EA8CB3691B4275B0183F1D39639EBC92995FE645D6C1BC28D409E585549BBD2C5DCDD6C208B04EADD8B7A6D997F72CBAD88390F020102
\ No newline at end of file diff --git a/extra/yassl/certs/dsa-cert.pem b/extra/yassl/certs/dsa-cert.pem new file mode 100644 index 00000000000..ecca18dae82 --- /dev/null +++ b/extra/yassl/certs/dsa-cert.pem @@ -0,0 +1,68 @@ +Certificate: + Data: + Version: 3 (0x2) + Serial Number: 0 (0x0) + Signature Algorithm: dsaWithSHA1 + Issuer: C=US, ST=Oregon, L=Portland, O=yaSSL DSA, CN=yaSSL DSA/emailAddress=info@yassl.com + Validity + Not Before: Jan 23 22:54:51 2005 GMT + Not After : Oct 20 22:54:51 2007 GMT + Subject: C=US, ST=Oregon, L=Portland, O=yaSSL DSA, CN=yaSSL DSA/emailAddress=info@yassl.com + Subject Public Key Info: + Public Key Algorithm: dsaEncryption + DSA Public Key: + pub: + 04:84:a0:26:31:72:0c:e8:4f:5d:53:17:62:b1:80: + ca:c0:16:5f:c3:1e:ea:c5:d9:98:38:f9:be:56:53: + 47:68:ce:08:22:57:1c:bb:0d:77:91:cf:5b:36:ed: + f3:24:82:90:8a:cd:90:7c:db:77:f9:17:2d:73:73: + ef:bb:b9:82 + P: + 00:99:29:69:80:c9:3c:98:68:45:a9:82:fe:67:eb: + 95:88:c5:b4:0c:d6:26:45:95:19:2c:a0:20:5b:7e: + df:69:e9:dc:c3:0f:f3:61:0a:25:9b:f2:21:01:6a: + cd:aa:8c:37:e7:ca:66:db:56:f4:0f:7d:7a:d1:18: + b9:42:fd:1b:11 + Q: + 00:ad:25:29:ab:0a:9f:09:1c:c1:ad:03:20:76:7f: + a6:b7:dd:4d:03:09 + G: + 12:88:99:da:e7:d0:0b:93:9b:e6:ee:3c:21:7f:9c: + b3:b4:8d:a5:8c:e2:37:80:3f:17:d1:81:4f:bd:f0: + 71:b6:32:08:54:dd:bf:01:e2:b3:77:06:64:75:8a: + 04:d6:79:39:b1:02:03:03:c6:06:74:e5:90:05:0a: + 10:46:19:31 + X509v3 extensions: + X509v3 Subject Key Identifier: + BE:F9:8C:5D:D6:1C:B4:EE:81:DD:36:56:0A:21:E4:61:44:73:E9:E2 + X509v3 Authority Key Identifier: + keyid:BE:F9:8C:5D:D6:1C:B4:EE:81:DD:36:56:0A:21:E4:61:44:73:E9:E2 + DirName:/C=US/ST=Oregon/L=Portland/O=yaSSL DSA/CN=yaSSL DSA/emailAddress=info@yassl.com + serial:00 + + X509v3 Basic Constraints: + CA:TRUE + Signature Algorithm: dsaWithSHA1 + 30:2b:02:14:74:46:9f:91:7b:24:17:3b:ee:0f:10:e3:76:62: + f4:dc:81:e6:fd:fe:02:13:08:f4:87:0a:ab:ba:9c:de:3a:69: + 72:59:b8:ec:e9:57:f4:bf:37 +-----BEGIN CERTIFICATE----- +MIIDMTCCAvKgAwIBAgIBADAJBgcqhkjOOAQDMHgxCzAJBgNVBAYTAlVTMQ8wDQYD +VQQIEwZPcmVnb24xETAPBgNVBAcTCFBvcnRsYW5kMRIwEAYDVQQKEwl5YVNTTCBE +U0ExEjAQBgNVBAMTCXlhU1NMIERTQTEdMBsGCSqGSIb3DQEJARYOaW5mb0B5YXNz +bC5jb20wHhcNMDUwMTIzMjI1NDUxWhcNMDcxMDIwMjI1NDUxWjB4MQswCQYDVQQG +EwJVUzEPMA0GA1UECBMGT3JlZ29uMREwDwYDVQQHEwhQb3J0bGFuZDESMBAGA1UE +ChMJeWFTU0wgRFNBMRIwEAYDVQQDEwl5YVNTTCBEU0ExHTAbBgkqhkiG9w0BCQEW +DmluZm9AeWFzc2wuY29tMIHwMIGoBgcqhkjOOAQBMIGcAkEAmSlpgMk8mGhFqYL+ +Z+uViMW0DNYmRZUZLKAgW37faencww/zYQolm/IhAWrNqow358pm21b0D3160Ri5 +Qv0bEQIVAK0lKasKnwkcwa0DIHZ/prfdTQMJAkASiJna59ALk5vm7jwhf5yztI2l +jOI3gD8X0YFPvfBxtjIIVN2/AeKzdwZkdYoE1nk5sQIDA8YGdOWQBQoQRhkxA0MA +AkAEhKAmMXIM6E9dUxdisYDKwBZfwx7qxdmYOPm+VlNHaM4IIlccuw13kc9bNu3z +JIKQis2QfNt3+Rctc3Pvu7mCo4HVMIHSMB0GA1UdDgQWBBS++Yxd1hy07oHdNlYK +IeRhRHPp4jCBogYDVR0jBIGaMIGXgBS++Yxd1hy07oHdNlYKIeRhRHPp4qF8pHow +eDELMAkGA1UEBhMCVVMxDzANBgNVBAgTBk9yZWdvbjERMA8GA1UEBxMIUG9ydGxh +bmQxEjAQBgNVBAoTCXlhU1NMIERTQTESMBAGA1UEAxMJeWFTU0wgRFNBMR0wGwYJ +KoZIhvcNAQkBFg5pbmZvQHlhc3NsLmNvbYIBADAMBgNVHRMEBTADAQH/MAkGByqG +SM44BAMDLgAwKwIUdEafkXskFzvuDxDjdmL03IHm/f4CEwj0hwqrupzeOmlyWbjs +6Vf0vzc= +-----END CERTIFICATE----- diff --git a/extra/yassl/certs/dsa512.der b/extra/yassl/certs/dsa512.der Binary files differnew file mode 100644 index 00000000000..fe79ccb612b --- /dev/null +++ b/extra/yassl/certs/dsa512.der diff --git a/extra/yassl/certs/dsa512.pem b/extra/yassl/certs/dsa512.pem new file mode 100644 index 00000000000..04a3dd94a77 --- /dev/null +++ b/extra/yassl/certs/dsa512.pem @@ -0,0 +1,8 @@ +-----BEGIN DSA PRIVATE KEY----- +MIH3AgEAAkEAmSlpgMk8mGhFqYL+Z+uViMW0DNYmRZUZLKAgW37faencww/zYQol +m/IhAWrNqow358pm21b0D3160Ri5Qv0bEQIVAK0lKasKnwkcwa0DIHZ/prfdTQMJ +AkASiJna59ALk5vm7jwhf5yztI2ljOI3gD8X0YFPvfBxtjIIVN2/AeKzdwZkdYoE +1nk5sQIDA8YGdOWQBQoQRhkxAkAEhKAmMXIM6E9dUxdisYDKwBZfwx7qxdmYOPm+ +VlNHaM4IIlccuw13kc9bNu3zJIKQis2QfNt3+Rctc3Pvu7mCAhQjg+e+aqykxwwc +E2V27tjDFY02uA== +-----END DSA PRIVATE KEY----- diff --git a/extra/yassl/certs/server-cert.pem b/extra/yassl/certs/server-cert.pem new file mode 100644 index 00000000000..403dabdf5fa --- /dev/null +++ b/extra/yassl/certs/server-cert.pem @@ -0,0 +1,38 @@ +Certificate: + Data: + Version: 1 (0x0) + Serial Number: 1 (0x1) + Signature Algorithm: md5WithRSAEncryption + Issuer: C=US, ST=Oregon, L=Portland, O=sawtooth, CN=www.sawtooth-consulting.com/emailAddress=info@yassl.com + Validity + Not Before: Jan 18 20:50:59 2005 GMT + Not After : Oct 15 20:50:59 2007 GMT + Subject: C=US, ST=Oregon, L=Portland, O=taoSoftDev, CN=www.taosoftdev.com/emailAddress=info@yassl.com + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public Key: (512 bit) + Modulus (512 bit): + 00:a4:68:bb:bc:b7:27:5f:3c:f5:78:c6:1a:af:b9: + 95:fc:7e:61:1f:a8:81:0a:ca:43:88:9a:03:e0:d0: + a6:79:70:16:34:b9:7c:75:54:ca:70:19:66:38:be: + 6e:28:7e:a5:ff:6b:3c:83:2f:39:42:c3:15:f3:bd: + f2:25:93:22:e7 + Exponent: 65537 (0x10001) + Signature Algorithm: md5WithRSAEncryption + 08:36:07:8c:3a:7f:f9:91:0a:82:d1:6a:c1:34:be:bc:2d:b2: + 20:98:dc:45:50:53:9c:66:e6:26:71:bd:fa:d2:b4:91:d3:53: + c0:20:05:c0:b6:84:9a:5f:3f:61:75:f5:fd:c6:ec:e2:f6:9f: + a2:13:17:a9:b7:83:60:cc:cb:eb +-----BEGIN CERTIFICATE----- +MIIB9zCCAaECAQEwDQYJKoZIhvcNAQEEBQAwgYkxCzAJBgNVBAYTAlVTMQ8wDQYD +VQQIEwZPcmVnb24xETAPBgNVBAcTCFBvcnRsYW5kMREwDwYDVQQKEwhzYXd0b290 +aDEkMCIGA1UEAxMbd3d3LnNhd3Rvb3RoLWNvbnN1bHRpbmcuY29tMR0wGwYJKoZI +hvcNAQkBFg5pbmZvQHlhc3NsLmNvbTAeFw0wNTAxMTgyMDUwNTlaFw0wNzEwMTUy +MDUwNTlaMIGCMQswCQYDVQQGEwJVUzEPMA0GA1UECBMGT3JlZ29uMREwDwYDVQQH +EwhQb3J0bGFuZDETMBEGA1UEChMKdGFvU29mdERldjEbMBkGA1UEAxMSd3d3LnRh +b3NvZnRkZXYuY29tMR0wGwYJKoZIhvcNAQkBFg5pbmZvQHlhc3NsLmNvbTBcMA0G +CSqGSIb3DQEBAQUAA0sAMEgCQQCkaLu8tydfPPV4xhqvuZX8fmEfqIEKykOImgPg +0KZ5cBY0uXx1VMpwGWY4vm4ofqX/azyDLzlCwxXzvfIlkyLnAgMBAAEwDQYJKoZI +hvcNAQEEBQADQQAINgeMOn/5kQqC0WrBNL68LbIgmNxFUFOcZuYmcb360rSR01PA +IAXAtoSaXz9hdfX9xuzi9p+iExept4NgzMvr +-----END CERTIFICATE----- diff --git a/extra/yassl/certs/server-key.pem b/extra/yassl/certs/server-key.pem new file mode 100644 index 00000000000..d6055c4cfd8 --- /dev/null +++ b/extra/yassl/certs/server-key.pem @@ -0,0 +1,9 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIBOQIBAAJBAKRou7y3J1889XjGGq+5lfx+YR+ogQrKQ4iaA+DQpnlwFjS5fHVU +ynAZZji+bih+pf9rPIMvOULDFfO98iWTIucCAwEAAQJABLVvMw931DV1vljGKORC +1HF2LKbx0zJJzt7CX6z6J54vcE79K3NYXdU6o7/j1WTtfD47tFG+4ljGvSYPmrCI +2QIhANfiY6is6JUJGGgeMxyWeQRPXfaE9Yrk6OhxHhpYf5CTAiEAwvWraeLPy/NE +B+0w80mh8tCv2tpuKaYMOG53XpYX3N0CIDy/Bj3rUZLGOWjqvoUXzjupPY5lgVYw +7Vyin87YAiUjAiAgM8X5em5KSMc+6+2+8bWfTtsNMjEqDfRMyepLpE0SvQIgTSYL +WWfcZoRUPDM9GEuQ40nifVNjobzvjTW4aYyHCEI= +-----END RSA PRIVATE KEY----- diff --git a/extra/yassl/certs/taoCert.txt b/extra/yassl/certs/taoCert.txt new file mode 100644 index 00000000000..585293e4f2b --- /dev/null +++ b/extra/yassl/certs/taoCert.txt @@ -0,0 +1,50 @@ + +***** Create a self signed cert ************ + +1) openssl genrsa 512 > client-key.pem + +2) openssl req -new -x509 -nodes -md5 -days 1000 -key client-key.pem > client-cert.pem + +-- adding metadata to beginning + +3) openssl x509 -in client-cert.pem -text > tmp.pem + +4) mv tmp.pem client-cert.pem + + +***** Create a CA, signing authority ********** + +same as self signed, use ca prefix instead of client + + +***** Create a cert signed by CA ************** + +1) openssl req -newkey rsa:512 -md5 -days 1000 -nodes -keyout server-key.pem > server-req.pem + +2) copy ca-key.pem ca-cert.srl (why ????) + +3) openssl x509 -req -in server-req.pem -days 1000 -md5 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 > server-cert.pem + + + +***** To create a dsa cert ******************** + +1) openssl dsaparam 512 > dsa512.param # creates group params + +2) openssl gendsa dsa512.param > dsa512.pem # creates private key + +3) openssl req -new -x509 -nodes -days 1000 -key dsa512.pem > dsa-cert.pem + + + + +***** To convert from PEM to DER ************** + +a) openssl x509 -in cert.pem -inform PEM -out cert.der -outform DER + +to convert rsa private PEM to DER : + +b) openssl rsa -in key.pem -outform DER -out key.der + + + diff --git a/extra/yassl/examples/client/client.cpp b/extra/yassl/examples/client/client.cpp index 704a8e76637..94bf753210b 100644 --- a/extra/yassl/examples/client/client.cpp +++ b/extra/yassl/examples/client/client.cpp @@ -33,10 +33,10 @@ void client_test(void* args) const char* cipher = 0; int index = 0; char list[1024]; - strcpy(list, "cipherlist"); + strncpy(list, "cipherlist", 11); while ( (cipher = SSL_get_cipher_list(ssl, index++)) ) { - strcat(list, ":"); - strcat(list, cipher); + strncat(list, ":", 2); + strncat(list, cipher, strlen(cipher) + 1); } printf("%s\n", list); printf("Using Cipher Suite %s\n", SSL_get_cipher(ssl)); @@ -89,6 +89,8 @@ void client_test(void* args) args.argv = argv; client_test(&args); + yaSSL_CleanUp(); + return args.return_code; } diff --git a/extra/yassl/examples/echoclient/echoclient.cpp b/extra/yassl/examples/echoclient/echoclient.cpp index ca557cca8af..fd3f7dd48a3 100644 --- a/extra/yassl/examples/echoclient/echoclient.cpp +++ b/extra/yassl/examples/echoclient/echoclient.cpp @@ -82,6 +82,7 @@ void echoclient_test(void* args) args.argv = argv; echoclient_test(&args); + yaSSL_CleanUp(); return args.return_code; } diff --git a/extra/yassl/examples/echoserver/echoserver.cpp b/extra/yassl/examples/echoserver/echoserver.cpp index 14a37a7e175..8e23ead20ab 100644 --- a/extra/yassl/examples/echoserver/echoserver.cpp +++ b/extra/yassl/examples/echoserver/echoserver.cpp @@ -15,6 +15,8 @@ args.argv = argv; echoserver_test(&args); + yaSSL_CleanUp(); + return args.return_code; } @@ -63,7 +65,8 @@ THREAD_RETURN YASSL_API echoserver_test(void* args) while (!shutdown) { sockaddr_in client; socklen_t client_len = sizeof(client); - int clientfd = accept(sockfd, (sockaddr*)&client, &client_len); + int clientfd = accept(sockfd, (sockaddr*)&client, + (ACCEPT_THIRD_T)&client_len); if (clientfd == -1) err_sys("tcp accept failed"); SSL* ssl = SSL_new(ctx); diff --git a/extra/yassl/examples/server/server.cpp b/extra/yassl/examples/server/server.cpp index 4d3f121cf2c..73cff19e371 100644 --- a/extra/yassl/examples/server/server.cpp +++ b/extra/yassl/examples/server/server.cpp @@ -67,6 +67,8 @@ THREAD_RETURN YASSL_API server_test(void* args) args.argv = argv; server_test(&args); + yaSSL_CleanUp(); + return args.return_code; } diff --git a/extra/yassl/include/openssl/err.h b/extra/yassl/include/openssl/err.h index 054d0940509..45ac1ca2469 100644 --- a/extra/yassl/include/openssl/err.h +++ b/extra/yassl/include/openssl/err.h @@ -1,6 +1,6 @@ /* err.h for openssl */ -#ifndef ysSSL_err_h__ +#ifndef yaSSL_err_h__ #define yaSSL_err_h__ diff --git a/extra/yassl/include/openssl/md4.h b/extra/yassl/include/openssl/md4.h new file mode 100644 index 00000000000..2e99f977fca --- /dev/null +++ b/extra/yassl/include/openssl/md4.h @@ -0,0 +1 @@ +/* md4.h for libcurl */ diff --git a/extra/yassl/include/openssl/md5.h b/extra/yassl/include/openssl/md5.h index a1025b92782..dfaf9799c44 100644 --- a/extra/yassl/include/openssl/md5.h +++ b/extra/yassl/include/openssl/md5.h @@ -1 +1,4 @@ /* md5.h for openssl */ + +#include "ssl.h" /* in there for now */ + diff --git a/extra/yassl/include/openssl/pem.h b/extra/yassl/include/openssl/pem.h new file mode 100644 index 00000000000..b4c63d56a4d --- /dev/null +++ b/extra/yassl/include/openssl/pem.h @@ -0,0 +1 @@ +/* pem.h for libcurl */ diff --git a/extra/yassl/include/openssl/ssl.h b/extra/yassl/include/openssl/ssl.h index b6840d006df..23e48d2011f 100644 --- a/extra/yassl/include/openssl/ssl.h +++ b/extra/yassl/include/openssl/ssl.h @@ -29,8 +29,22 @@ #define yaSSL_openssl_h__ #include <stdio.h> /* ERR_print fp */ +#include "opensslv.h" /* for version number */ #include "rsa.h" +#if defined(__cplusplus) +extern "C" { +#endif + + void yaSSL_CleanUp(); /* call once at end of application use to + free static singleton memory holders, + not a leak per se, but helpful when + looking for them */ + +#if defined(__cplusplus) +} // extern +#endif + #if defined(__cplusplus) && !defined(YASSL_MYSQL_COMPATIBLE) namespace yaSSL { extern "C" { @@ -102,7 +116,6 @@ void X509_free(X509*); typedef struct BIO BIO; /* ASN stuff */ -typedef struct ASN1_TIME ASN1_TIME; @@ -260,6 +273,7 @@ int SSL_pending(SSL*); enum { /* ssl Constants */ + SSL_WOULD_BLOCK = -8, SSL_BAD_STAT = -7, SSL_BAD_PATH = -6, SSL_BAD_FILETYPE = -5, @@ -345,8 +359,8 @@ long SSL_CTX_sess_set_cache_size(SSL_CTX*, long); long SSL_CTX_set_tmp_dh(SSL_CTX*, DH*); void OpenSSL_add_all_algorithms(void); -void SSL_library_init(); -void SSLeay_add_ssl_algorithms(void); +int SSL_library_init(); +int SSLeay_add_ssl_algorithms(void); SSL_CIPHER* SSL_get_current_cipher(SSL*); @@ -371,6 +385,10 @@ typedef unsigned char DES_cblock[8]; typedef const DES_cblock const_DES_cblock; typedef DES_cblock DES_key_schedule; +enum { + DES_ENCRYPT = 1, + DES_DECRYPT = 0 +}; const EVP_MD* EVP_md5(void); const EVP_CIPHER* EVP_des_ede3_cbc(void); @@ -392,6 +410,108 @@ int RAND_write_file(const char*); int RAND_load_file(const char*, long); +/* for libcurl */ +int RAND_status(void); + +int DES_set_key(const_DES_cblock*, DES_key_schedule*); +void DES_set_odd_parity(DES_cblock*); +void DES_ecb_encrypt(DES_cblock*, DES_cblock*, DES_key_schedule*, int); + +void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX*, void* userdata); +void SSL_SESSION_free(SSL_SESSION* session); + +X509* SSL_get_certificate(SSL* ssl); +EVP_PKEY* SSL_get_privatekey(SSL* ssl); +EVP_PKEY* X509_get_pubkey(X509* x); + +int EVP_PKEY_copy_parameters(EVP_PKEY* to, const EVP_PKEY* from); +void EVP_PKEY_free(EVP_PKEY* pkey); +void ERR_error_string_n(unsigned long e, char *buf, size_t len); +void ERR_free_strings(void); +void EVP_cleanup(void); + +void* X509_get_ext_d2i(X509* x, int nid, int* crit, int* idx); + +#define GEN_IPADD 7 +#define NID_subject_alt_name 85 +#define STACK_OF(x) x + + +/* defined here because libcurl dereferences */ +typedef struct ASN1_STRING { + int type; + int length; + unsigned char* data; +} ASN1_STRING; + + +typedef struct GENERAL_NAME { + int type; + union { + ASN1_STRING* ia5; + } d; +} GENERAL_NAME; + +void GENERAL_NAMES_free(STACK_OF(GENERAL_NAME) *x); + +int sk_GENERAL_NAME_num(STACK_OF(GENERAL_NAME) *x); +GENERAL_NAME* sk_GENERAL_NAME_value(STACK_OF(GENERAL_NAME) *x, int i); + + +unsigned char* ASN1_STRING_data(ASN1_STRING* x); +int ASN1_STRING_length(ASN1_STRING* x); +int ASN1_STRING_type(ASN1_STRING *x); + +typedef ASN1_STRING X509_NAME_ENTRY; + +int X509_NAME_get_index_by_NID(X509_NAME* name,int nid, int lastpos); + +ASN1_STRING* X509_NAME_ENTRY_get_data(X509_NAME_ENTRY* ne); +X509_NAME_ENTRY* X509_NAME_get_entry(X509_NAME* name, int loc); + +#define OPENSSL_malloc(x) malloc(x) +#define OPENSSL_free(x) free(x) + +int ASN1_STRING_to_UTF8(unsigned char** out, ASN1_STRING* in); + +SSL_METHOD* SSLv23_client_method(void); /* doesn't actually roll back */ +SSL_METHOD* SSLv2_client_method(void); /* will never work, no v 2 */ + + +SSL_SESSION* SSL_get1_session(SSL* ssl); /* what's ref count */ + + +#define CRYPTO_free(x) free(x) +#define ASN1_TIME ASN1_STRING + +ASN1_TIME* X509_get_notBefore(X509* x); +ASN1_TIME* X509_get_notAfter(X509* x); + + +#define ASN1_UTCTIME ASN1_STRING +#define NID_commonName 13 +#define V_ASN1_UTF8STRING 12 +#define GEN_DNS 2 + + +typedef struct MD4_CTX { + int buffer[32]; /* big enough to hold, check size in Init */ +} MD4_CTX; + +void MD4_Init(MD4_CTX*); +void MD4_Update(MD4_CTX*, const void*, unsigned long); +void MD4_Final(unsigned char*, MD4_CTX*); + + +typedef struct MD5_CTX { + int buffer[32]; /* big enough to hold, check size in Init */ +} MD5_CTX; + +void MD5_Init(MD5_CTX*); +void MD5_Update(MD5_CTX*, const void*, unsigned long); +void MD5_Final(unsigned char*, MD5_CTX*); + + #define SSL_DEFAULT_CIPHER_LIST "" /* default all */ diff --git a/extra/yassl/include/openssl/x509.h b/extra/yassl/include/openssl/x509.h new file mode 100644 index 00000000000..dcd847c0337 --- /dev/null +++ b/extra/yassl/include/openssl/x509.h @@ -0,0 +1 @@ +/* x509.h for libcurl */ diff --git a/extra/yassl/include/openssl/x509v3.h b/extra/yassl/include/openssl/x509v3.h new file mode 100644 index 00000000000..adf94af8f48 --- /dev/null +++ b/extra/yassl/include/openssl/x509v3.h @@ -0,0 +1 @@ +/* x509v3.h for libcurl */ diff --git a/extra/yassl/include/socket_wrapper.hpp b/extra/yassl/include/socket_wrapper.hpp index d2258a93723..16db142b3a2 100644 --- a/extra/yassl/include/socket_wrapper.hpp +++ b/extra/yassl/include/socket_wrapper.hpp @@ -66,6 +66,7 @@ typedef unsigned char byte; // Wraps Windows Sockets and BSD Sockets class Socket { socket_t socket_; // underlying socket descriptor + bool wouldBlock_; // for non-blocking data public: explicit Socket(socket_t s = INVALID_SOCKET); ~Socket(); @@ -75,9 +76,10 @@ public: socket_t get_fd() const; uint send(const byte* buf, unsigned int len, int flags = 0) const; - uint receive(byte* buf, unsigned int len, int flags = 0) const; + uint receive(byte* buf, unsigned int len, int flags = 0); - bool wait() const; + bool wait(); + bool WouldBlock() const; void closeSocket(); void shutDown(int how = SD_SEND); diff --git a/extra/yassl/include/yassl_error.hpp b/extra/yassl/include/yassl_error.hpp index 9c12b06e34a..2f35fecb59b 100644 --- a/extra/yassl/include/yassl_error.hpp +++ b/extra/yassl/include/yassl_error.hpp @@ -26,7 +26,6 @@ #ifndef yaSSL_ERROR_HPP #define yaSSL_ERROR_HPP -#include "stdexcept.hpp" namespace yaSSL { @@ -63,7 +62,7 @@ enum { MAX_ERROR_SZ = 80 }; void SetErrorString(YasslError, char*); - +/* remove for now, if go back to exceptions use this wrapper // Base class for all yaSSL exceptions class Error : public mySTL::runtime_error { YasslError error_; @@ -75,6 +74,7 @@ public: YasslError get_number() const; Library get_lib() const; }; +*/ } // naemspace diff --git a/extra/yassl/include/yassl_int.hpp b/extra/yassl/include/yassl_int.hpp index 935bae582ea..97ae468d2f9 100644 --- a/extra/yassl/include/yassl_int.hpp +++ b/extra/yassl/include/yassl_int.hpp @@ -34,6 +34,7 @@ #include "cert_wrapper.hpp" #include "log.hpp" #include "lock.hpp" +#include "openssl/ssl.h" // ASN1_STRING and DH namespace yaSSL { @@ -126,32 +127,70 @@ private: }; +// hold add crypt references provided to callers +class CryptProvider { + mySTL::list<Digest*> digestList_; + mySTL::list<BulkCipher*> cipherList_; + CryptProvider() {} // only GetCryptProvider creates +public: + ~CryptProvider(); + + Digest* NewMd5(); + BulkCipher* NewDesEde(); + + friend CryptProvider& GetCryptProvider(); +private: + CryptProvider(const CryptProvider&); // hide copy + CryptProvider& operator=(const CryptProvider&); // and assign +}; + +CryptProvider& GetCryptProvider(); + #undef X509_NAME // wincrypt.h clash // openSSL X509 names class X509_NAME { char* name_; + size_t sz_; + ASN1_STRING entry_; public: X509_NAME(const char*, size_t sz); ~X509_NAME(); char* GetName(); + ASN1_STRING* GetEntry(int i); private: X509_NAME(const X509_NAME&); // hide copy X509_NAME& operator=(const X509_NAME&); // and assign }; +class StringHolder { + ASN1_STRING asnString_; +public: + StringHolder(const char* str, int sz); + ~StringHolder(); + + ASN1_STRING* GetString(); +}; + + // openSSL X509 class X509 { X509_NAME issuer_; X509_NAME subject_; + StringHolder beforeDate_; // not valid before + StringHolder afterDate_; // not valid after public: - X509(const char* i, size_t, const char* s, size_t); + X509(const char* i, size_t, const char* s, size_t, + const char* b, int, const char* a, int); ~X509() {} X509_NAME* GetIssuer(); X509_NAME* GetSubject(); + + ASN1_STRING* GetBefore(); + ASN1_STRING* GetAfter(); private: X509(const X509&); // hide copy X509& operator=(const X509&); // and assign diff --git a/extra/yassl/include/yassl_types.hpp b/extra/yassl/include/yassl_types.hpp index bfb6467182b..76c807cd05f 100644 --- a/extra/yassl/include/yassl_types.hpp +++ b/extra/yassl/include/yassl_types.hpp @@ -35,10 +35,6 @@ namespace yaSSL { -// Delete static singleton memory holders -void CleanUp(); - - #ifdef YASSL_PURE_C // library allocation diff --git a/extra/yassl/lib/dummy b/extra/yassl/lib/dummy new file mode 100644 index 00000000000..85c1efd587f --- /dev/null +++ b/extra/yassl/lib/dummy @@ -0,0 +1 @@ +// this is a dummy file diff --git a/extra/yassl/mySTL/helpers.hpp b/extra/yassl/mySTL/helpers.hpp index 5aa14d838b1..df79025197a 100644 --- a/extra/yassl/mySTL/helpers.hpp +++ b/extra/yassl/mySTL/helpers.hpp @@ -44,6 +44,11 @@ return static_cast<void*>(d); } + // for compilers that want matching delete + inline void operator delete(void* ptr, Dummy* d) + { + } + typedef Dummy* yassl_pointer; namespace mySTL { diff --git a/extra/yassl/src/cert_wrapper.cpp b/extra/yassl/src/cert_wrapper.cpp index b98c7faf1d0..ae609b510ba 100644 --- a/extra/yassl/src/cert_wrapper.cpp +++ b/extra/yassl/src/cert_wrapper.cpp @@ -271,10 +271,13 @@ int CertManager::Validate() else peerKeyType_ = dsa_sa_algo; - int iSz = cert.GetIssuer() ? strlen(cert.GetIssuer()) + 1 : 0; - int sSz = cert.GetCommonName() ? strlen(cert.GetCommonName()) + 1 : 0; + int iSz = strlen(cert.GetIssuer()) + 1; + int sSz = strlen(cert.GetCommonName()) + 1; + int bSz = strlen(cert.GetBeforeDate()) + 1; + int aSz = strlen(cert.GetAfterDate()) + 1; peerX509_ = NEW_YS X509(cert.GetIssuer(), iSz, cert.GetCommonName(), - sSz); + sSz, cert.GetBeforeDate(), bSz, + cert.GetAfterDate(), aSz); } return 0; } diff --git a/extra/yassl/src/handshake.cpp b/extra/yassl/src/handshake.cpp index 2603365e41a..2b099af930c 100644 --- a/extra/yassl/src/handshake.cpp +++ b/extra/yassl/src/handshake.cpp @@ -656,7 +656,7 @@ mySTL::auto_ptr<input_buffer> DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered) { // wait for input if blocking - if (!ssl.getSocket().wait()) { + if (!ssl.useSocket().wait()) { ssl.SetError(receive_error); buffered.reset(0); return buffered; @@ -673,7 +673,7 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered) } // add new data - uint read = ssl.getSocket().receive(buffer.get_buffer() + buffSz, ready); + uint read = ssl.useSocket().receive(buffer.get_buffer() + buffSz, ready); buffer.add_size(read); uint offset = 0; const MessageFactory& mf = ssl.getFactory().getMessage(); @@ -858,6 +858,9 @@ void sendFinished(SSL& ssl, ConnectionEnd side, BufferOutput buffer) // send data int sendData(SSL& ssl, const void* buffer, int sz) { + if (ssl.GetError() == YasslError(SSL_ERROR_WANT_READ)) + ssl.SetError(no_error); + ssl.verfiyHandShakeComplete(); if (ssl.GetError()) return 0; int sent = 0; @@ -893,6 +896,9 @@ int sendAlert(SSL& ssl, const Alert& alert) // process input data int receiveData(SSL& ssl, Data& data) { + if (ssl.GetError() == YasslError(SSL_ERROR_WANT_READ)) + ssl.SetError(no_error); + ssl.verfiyHandShakeComplete(); if (ssl.GetError()) return 0; @@ -902,6 +908,11 @@ int receiveData(SSL& ssl, Data& data) ssl.useLog().ShowData(data.get_length()); if (ssl.GetError()) return 0; + + if (data.get_length() == 0 && ssl.getSocket().WouldBlock()) { + ssl.SetError(YasslError(SSL_ERROR_WANT_READ)); + return SSL_WOULD_BLOCK; + } return data.get_length(); } diff --git a/extra/yassl/src/make.bat b/extra/yassl/src/make.bat index 4c79a9c6406..148427a6f41 100644 --- a/extra/yassl/src/make.bat +++ b/extra/yassl/src/make.bat @@ -1,4 +1,4 @@ -# quick and dirty build file for testing different MSDEVs +REM quick and dirty build file for testing different MSDEVs setlocal set myFLAGS= /I../include /I../mySTL /I../taocrypt/include /W3 /c /ZI diff --git a/extra/yassl/src/socket_wrapper.cpp b/extra/yassl/src/socket_wrapper.cpp index c6611803421..803f4b01249 100644 --- a/extra/yassl/src/socket_wrapper.cpp +++ b/extra/yassl/src/socket_wrapper.cpp @@ -58,7 +58,7 @@ namespace yaSSL { Socket::Socket(socket_t s) - : socket_(s) + : socket_(s), wouldBlock_(false) {} @@ -123,17 +123,21 @@ uint Socket::send(const byte* buf, unsigned int sz, int flags) const } -uint Socket::receive(byte* buf, unsigned int sz, int flags) const +uint Socket::receive(byte* buf, unsigned int sz, int flags) { assert(socket_ != INVALID_SOCKET); + wouldBlock_ = false; + int recvd = ::recv(socket_, reinterpret_cast<char *>(buf), sz, flags); // idea to seperate error from would block by arnetheduck@gmail.com if (recvd == -1) { if (get_lastError() == SOCKET_EWOULDBLOCK || - get_lastError() == SOCKET_EAGAIN) + get_lastError() == SOCKET_EAGAIN) { + wouldBlock_ = true; return 0; } + } else if (recvd == 0) return static_cast<uint>(-1); @@ -142,7 +146,7 @@ uint Socket::receive(byte* buf, unsigned int sz, int flags) const // wait if blocking for input, return false for error -bool Socket::wait() const +bool Socket::wait() { byte b; return receive(&b, 1, MSG_PEEK) != static_cast<uint>(-1); @@ -166,6 +170,12 @@ int Socket::get_lastError() } +bool Socket::WouldBlock() const +{ + return wouldBlock_; +} + + void Socket::set_lastError(int errorCode) { #ifdef _WIN32 diff --git a/extra/yassl/src/ssl.cpp b/extra/yassl/src/ssl.cpp index 1aab14009d3..747305730df 100644 --- a/extra/yassl/src/ssl.cpp +++ b/extra/yassl/src/ssl.cpp @@ -1,4 +1,4 @@ -/* ssl.cpp + /* ssl.cpp * * Copyright (C) 2003 Sawtooth Consulting Ltd. * @@ -36,6 +36,8 @@ #include "openssl/ssl.h" #include "handshake.hpp" #include "yassl_int.hpp" +#include "md5.hpp" // for TaoCrypt MD5 size assert +#include "md4.hpp" // for TaoCrypt MD4 size assert #include <stdio.h> #ifdef _WIN32 @@ -52,6 +54,53 @@ namespace yaSSL { using mySTL::min; +int read_file(SSL_CTX* ctx, const char* file, int format, CertType type) +{ + if (format != SSL_FILETYPE_ASN1 && format != SSL_FILETYPE_PEM) + return SSL_BAD_FILETYPE; + + FILE* input = fopen(file, "rb"); + if (!input) + return SSL_BAD_FILE; + + if (type == CA) { + x509* ptr = PemToDer(file, Cert); + if (!ptr) { + fclose(input); + return SSL_BAD_FILE; + } + ctx->AddCA(ptr); // takes ownership + } + else { + x509*& x = (type == Cert) ? ctx->certificate_ : ctx->privateKey_; + + if (format == SSL_FILETYPE_ASN1) { + fseek(input, 0, SEEK_END); + long sz = ftell(input); + rewind(input); + x = NEW_YS x509(sz); // takes ownership + size_t bytes = fread(x->use_buffer(), sz, 1, input); + if (bytes != 1) { + fclose(input); + return SSL_BAD_FILE; + } + } + else { + x = PemToDer(file, type); + if (!x) { + fclose(input); + return SSL_BAD_FILE; + } + } + } + fclose(input); + return SSL_SUCCESS; +} + + +extern "C" { + + SSL_METHOD* SSLv3_method() { return SSLv3_client_method(); @@ -448,50 +497,6 @@ long SSL_CTX_set_tmp_dh(SSL_CTX* ctx, DH* dh) } -int read_file(SSL_CTX* ctx, const char* file, int format, CertType type) -{ - if (format != SSL_FILETYPE_ASN1 && format != SSL_FILETYPE_PEM) - return SSL_BAD_FILETYPE; - - FILE* input = fopen(file, "rb"); - if (!input) - return SSL_BAD_FILE; - - if (type == CA) { - x509* ptr = PemToDer(file, Cert); - if (!ptr) { - fclose(input); - return SSL_BAD_FILE; - } - ctx->AddCA(ptr); // takes ownership - } - else { - x509*& x = (type == Cert) ? ctx->certificate_ : ctx->privateKey_; - - if (format == SSL_FILETYPE_ASN1) { - fseek(input, 0, SEEK_END); - long sz = ftell(input); - rewind(input); - x = NEW_YS x509(sz); // takes ownership - size_t bytes = fread(x->use_buffer(), sz, 1, input); - if (bytes != 1) { - fclose(input); - return SSL_BAD_FILE; - } - } - else { - x = PemToDer(file, type); - if (!x) { - fclose(input); - return SSL_BAD_FILE; - } - } - } - fclose(input); - return SSL_SUCCESS; -} - - int SSL_CTX_use_certificate_file(SSL_CTX* ctx, const char* file, int format) { return read_file(ctx, file, format, Cert); @@ -723,8 +728,10 @@ void OpenSSL_add_all_algorithms() // compatibility only {} -void SSL_library_init() // compatiblity only -{} +int SSL_library_init() // compatiblity only +{ + return 1; +} DH* DH_new(void) @@ -804,15 +811,13 @@ const char* X509_verify_cert_error_string(long /* error */) const EVP_MD* EVP_md5(void) { - // TODO: FIX add to some list for destruction - return NEW_YS MD5; + return GetCryptProvider().NewMd5(); } const EVP_CIPHER* EVP_des_ede3_cbc(void) { - // TODO: FIX add to some list for destruction - return NEW_YS DES_EDE; + return GetCryptProvider().NewDesEde(); } @@ -897,6 +902,284 @@ void DES_ede3_cbc_encrypt(const byte* input, byte* output, long sz, } +// functions for libcurl +int RAND_status() +{ + return 1; /* TaoCrypt provides enough seed */ +} + + +int DES_set_key(const_DES_cblock* key, DES_key_schedule* schedule) +{ + memcpy(schedule, key, sizeof(const_DES_cblock)); + return 1; +} + + +void DES_set_odd_parity(DES_cblock* key) +{ + // not needed now for TaoCrypt +} + + +void DES_ecb_encrypt(DES_cblock* input, DES_cblock* output, + DES_key_schedule* key, int enc) +{ + DES des; + + if (enc) { + des.set_encryptKey(*key, 0); + des.encrypt(*output, *input, DES_BLOCK); + } + else { + des.set_decryptKey(*key, 0); + des.decrypt(*output, *input, DES_BLOCK); + } +} + + +void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX*, void* userdata) +{ + // yaSSL doesn't support yet, unencrypt your PEM file with userdata + // before handing off to yaSSL +} + + +X509* SSL_get_certificate(SSL* ssl) +{ + // only used to pass to get_privatekey which isn't used + return 0; +} + + +EVP_PKEY* SSL_get_privatekey(SSL* ssl) +{ + // only called, not used + return 0; +} + + +void SSL_SESSION_free(SSL_SESSION* session) +{ + // managed by singleton +} + + + +EVP_PKEY* X509_get_pubkey(X509* x) +{ + // called, not used though + return 0; +} + + +int EVP_PKEY_copy_parameters(EVP_PKEY* to, const EVP_PKEY* from) +{ + // called, not used though + return 0; +} + + +void EVP_PKEY_free(EVP_PKEY* pkey) +{ + // never allocated from above +} + + +void ERR_error_string_n(unsigned long e, char *buf, size_t len) +{ + if (len) ERR_error_string(e, buf); +} + + +void ERR_free_strings(void) +{ + // handled internally +} + + +void EVP_cleanup(void) +{ + // nothing to do yet +} + + +ASN1_TIME* X509_get_notBefore(X509* x) +{ + if (x) return x->GetBefore(); + return 0; +} + + +ASN1_TIME* X509_get_notAfter(X509* x) +{ + if (x) return x->GetAfter(); + return 0; +} + + +SSL_METHOD* SSLv23_client_method(void) /* doesn't actually roll back */ +{ + return SSLv3_client_method(); +} + + +SSL_METHOD* SSLv2_client_method(void) /* will never work, no v 2 */ +{ + return 0; +} + + +SSL_SESSION* SSL_get1_session(SSL* ssl) /* what's ref count */ +{ + return SSL_get_session(ssl); +} + + +void GENERAL_NAMES_free(STACK_OF(GENERAL_NAME) *x) +{ + // no extension names supported yet +} + + +int sk_GENERAL_NAME_num(STACK_OF(GENERAL_NAME) *x) +{ + // no extension names supported yet + return 0; +} + + +GENERAL_NAME* sk_GENERAL_NAME_value(STACK_OF(GENERAL_NAME) *x, int i) +{ + // no extension names supported yet + return 0; +} + + +unsigned char* ASN1_STRING_data(ASN1_STRING* x) +{ + if (x) return x->data; + return 0; +} + + +int ASN1_STRING_length(ASN1_STRING* x) +{ + if (x) return x->length; + return 0; +} + + +int ASN1_STRING_type(ASN1_STRING *x) +{ + if (x) return x->type; + return 0; +} + + +int X509_NAME_get_index_by_NID(X509_NAME* name,int nid, int lastpos) +{ + int idx = -1; // not found + const char* start = &name->GetName()[lastpos + 1]; + + switch (nid) { + case NID_commonName: + const char* found = strstr(start, "/CN="); + if (found) { + found += 4; // advance to str + idx = found - start + lastpos + 1; + } + break; + } + + return idx; +} + + +ASN1_STRING* X509_NAME_ENTRY_get_data(X509_NAME_ENTRY* ne) +{ + // the same in yaSSL + return ne; +} + + +X509_NAME_ENTRY* X509_NAME_get_entry(X509_NAME* name, int loc) +{ + return name->GetEntry(loc); +} + + +// already formatted, caller responsible for freeing *out +int ASN1_STRING_to_UTF8(unsigned char** out, ASN1_STRING* in) +{ + if (!in) return 0; + + *out = (unsigned char*)malloc(in->length + 1); + if (*out) { + memcpy(*out, in->data, in->length); + (*out)[in->length] = 0; + } + return in->length; +} + + +void* X509_get_ext_d2i(X509* x, int nid, int* crit, int* idx) +{ + // no extensions supported yet + return 0; +} + + +void MD4_Init(MD4_CTX* md4) +{ + // make sure we have a big enough buffer + typedef char ok[sizeof(md4->buffer) >= sizeof(TaoCrypt::MD4) ? 1 : -1]; + (void) sizeof(ok); + + // using TaoCrypt since no dynamic memory allocated + // and no destructor will be called + new (reinterpret_cast<yassl_pointer>(md4->buffer)) TaoCrypt::MD4(); +} + + +void MD4_Update(MD4_CTX* md4, const void* data, unsigned long sz) +{ + reinterpret_cast<TaoCrypt::MD4*>(md4->buffer)->Update( + static_cast<const byte*>(data), static_cast<unsigned int>(sz)); +} + + +void MD4_Final(unsigned char* hash, MD4_CTX* md4) +{ + reinterpret_cast<TaoCrypt::MD4*>(md4->buffer)->Final(hash); +} + + +void MD5_Init(MD5_CTX* md5) +{ + // make sure we have a big enough buffer + typedef char ok[sizeof(md5->buffer) >= sizeof(TaoCrypt::MD5) ? 1 : -1]; + (void) sizeof(ok); + + // using TaoCrypt since no dynamic memory allocated + // and no destructor will be called + new (reinterpret_cast<yassl_pointer>(md5->buffer)) TaoCrypt::MD5(); +} + + +void MD5_Update(MD5_CTX* md5, const void* data, unsigned long sz) +{ + reinterpret_cast<TaoCrypt::MD5*>(md5->buffer)->Update( + static_cast<const byte*>(data), static_cast<unsigned int>(sz)); +} + + +void MD5_Final(unsigned char* hash, MD5_CTX* md5) +{ + reinterpret_cast<TaoCrypt::MD5*>(md5->buffer)->Final(hash); +} + + // functions for stunnel void RAND_screen() @@ -1098,8 +1381,10 @@ void DES_ede3_cbc_encrypt(const byte* input, byte* output, long sz, } - void SSLeay_add_ssl_algorithms() // compatibility only - {} + int SSLeay_add_ssl_algorithms() // compatibility only + { + return 1; + } void ERR_remove_state(unsigned long) @@ -1129,4 +1414,5 @@ void DES_ede3_cbc_encrypt(const byte* input, byte* output, long sz, // end stunnel needs +} // extern "C" } // namespace diff --git a/extra/yassl/src/template_instnt.cpp b/extra/yassl/src/template_instnt.cpp index 5782df213ea..134deb00c75 100644 --- a/extra/yassl/src/template_instnt.cpp +++ b/extra/yassl/src/template_instnt.cpp @@ -51,12 +51,16 @@ template class list<yaSSL::SSL_SESSION*>; template class list<yaSSL::input_buffer*>; template class list<yaSSL::output_buffer*>; template class list<yaSSL::x509*>; +template class list<yaSSL::Digest*>; +template class list<yaSSL::BulkCipher*>; template void destroy<mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>*>(mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>*, mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>*); template yaSSL::del_ptr_zero for_each<mySTL::list<TaoCrypt::Signer*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<TaoCrypt::Signer*>::iterator, mySTL::list<TaoCrypt::Signer*>::iterator, yaSSL::del_ptr_zero); template yaSSL::del_ptr_zero for_each<mySTL::list<yaSSL::SSL_SESSION*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::SSL_SESSION*>::iterator, mySTL::list<yaSSL::SSL_SESSION*>::iterator, yaSSL::del_ptr_zero); template yaSSL::del_ptr_zero for_each<mySTL::list<yaSSL::input_buffer*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::input_buffer*>::iterator, mySTL::list<yaSSL::input_buffer*>::iterator, yaSSL::del_ptr_zero); template yaSSL::del_ptr_zero for_each<mySTL::list<yaSSL::output_buffer*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::output_buffer*>::iterator, mySTL::list<yaSSL::output_buffer*>::iterator, yaSSL::del_ptr_zero); template yaSSL::del_ptr_zero for_each<mySTL::list<yaSSL::x509*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::x509*>::iterator, mySTL::list<yaSSL::x509*>::iterator, yaSSL::del_ptr_zero); +template yaSSL::del_ptr_zero for_each<mySTL::list<yaSSL::Digest*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::Digest*>::iterator, mySTL::list<yaSSL::Digest*>::iterator, yaSSL::del_ptr_zero); +template yaSSL::del_ptr_zero for_each<mySTL::list<yaSSL::BulkCipher*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::BulkCipher*>::iterator, mySTL::list<yaSSL::BulkCipher*>::iterator, yaSSL::del_ptr_zero); } namespace yaSSL { @@ -82,6 +86,7 @@ template void ysDelete<X509>(X509*); template void ysDelete<Message>(Message*); template void ysDelete<sslFactory>(sslFactory*); template void ysDelete<Sessions>(Sessions*); +template void ysDelete<CryptProvider>(CryptProvider*); template void ysArrayDelete<unsigned char>(unsigned char*); template void ysArrayDelete<char>(char*); } diff --git a/extra/yassl/src/timer.cpp b/extra/yassl/src/timer.cpp index 4fe0d3aa4f9..8b7d2d17a84 100644 --- a/extra/yassl/src/timer.cpp +++ b/extra/yassl/src/timer.cpp @@ -26,13 +26,17 @@ #include "runtime.hpp" #include "timer.hpp" +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#else +#include <sys/time.h> +#endif + namespace yaSSL { #ifdef _WIN32 - #define WIN32_LEAN_AND_MEAN - #include <windows.h> - timer_d timer() { static bool init(false); @@ -57,8 +61,6 @@ namespace yaSSL { #else // _WIN32 - #include <sys/time.h> - timer_d timer() { struct timeval tv; diff --git a/extra/yassl/src/yassl_error.cpp b/extra/yassl/src/yassl_error.cpp index 59113d7438c..72b8e459241 100644 --- a/extra/yassl/src/yassl_error.cpp +++ b/extra/yassl/src/yassl_error.cpp @@ -26,10 +26,13 @@ #include "runtime.hpp" #include "yassl_error.hpp" #include "error.hpp" // TaoCrypt error numbers +#include "openssl/ssl.h" // SSL_ERROR_WANT_READ +#include <string.h> // strncpy namespace yaSSL { +/* may bring back in future Error::Error(const char* s, YasslError e, Library l) : mySTL::runtime_error(s), error_(e), lib_(l) { @@ -47,6 +50,7 @@ Library Error::get_lib() const return lib_; } +*/ void SetErrorString(YasslError error, char* buffer) @@ -117,6 +121,11 @@ void SetErrorString(YasslError error, char* buffer) strncpy(buffer, "unable to proccess cerificate", max); break; + // openssl errors + case SSL_ERROR_WANT_READ : + strncpy(buffer, "the read operation would block", max); + break; + // TaoCrypt errors case NO_ERROR : strncpy(buffer, "not in error state", max); diff --git a/extra/yassl/src/yassl_imp.cpp b/extra/yassl/src/yassl_imp.cpp index 1d2d5396ea0..4d6d1fc7aff 100644 --- a/extra/yassl/src/yassl_imp.cpp +++ b/extra/yassl/src/yassl_imp.cpp @@ -1975,7 +1975,9 @@ Connection::Connection(ProtocolVersion v, RandomPool& ran) : pre_master_secret_(0), sequence_number_(0), peer_sequence_number_(0), pre_secret_len_(0), send_server_key_(false), master_clean_(false), TLS_(v.major_ >= 3 && v.minor_ >= 1), version_(v), random_(ran) -{} +{ + memset(sessionID_, 0, sizeof(sessionID_)); +} Connection::~Connection() diff --git a/extra/yassl/src/yassl_int.cpp b/extra/yassl/src/yassl_int.cpp index 396461a6ed5..842bcd5fb5d 100644 --- a/extra/yassl/src/yassl_int.cpp +++ b/extra/yassl/src/yassl_int.cpp @@ -28,7 +28,6 @@ #include "yassl_int.hpp" #include "handshake.hpp" #include "timer.hpp" -#include "openssl/ssl.h" // for DH #ifdef YASSL_PURE_C @@ -1375,18 +1374,44 @@ Sessions& GetSessions() static sslFactory* sslFactoryInstance = 0; -sslFactory& GetSSL_Factory(){ +sslFactory& GetSSL_Factory() +{ if (!sslFactoryInstance) sslFactoryInstance = NEW_YS sslFactory; return *sslFactoryInstance; } -void CleanUp() +static CryptProvider* cryptProviderInstance = 0; + +CryptProvider& GetCryptProvider() { - TaoCrypt::CleanUp(); - ysDelete(sslFactoryInstance); - ysDelete(sessionsInstance); + if (!cryptProviderInstance) + cryptProviderInstance = NEW_YS CryptProvider; + return *cryptProviderInstance; +} + + +CryptProvider::~CryptProvider() +{ + mySTL::for_each(digestList_.begin(), digestList_.end(), del_ptr_zero()); + mySTL::for_each(cipherList_.begin(), cipherList_.end(), del_ptr_zero()); +} + + +Digest* CryptProvider::NewMd5() +{ + Digest* ptr = NEW_YS MD5(); + digestList_.push_back(ptr); + return ptr; +} + + +BulkCipher* CryptProvider::NewDesEde() +{ + BulkCipher* ptr = NEW_YS DES_EDE(); + cipherList_.push_back(ptr); + return ptr; } @@ -1978,18 +2003,20 @@ void Security::set_resuming(bool b) X509_NAME::X509_NAME(const char* n, size_t sz) - : name_(0) + : name_(0), sz_(sz) { if (sz) { name_ = NEW_YS char[sz]; memcpy(name_, n, sz); } + entry_.data = 0; } X509_NAME::~X509_NAME() { ysArrayDelete(name_); + ysArrayDelete(entry_.data); } @@ -1999,8 +2026,10 @@ char* X509_NAME::GetName() } -X509::X509(const char* i, size_t iSz, const char* s, size_t sSz) - : issuer_(i, iSz), subject_(s, sSz) +X509::X509(const char* i, size_t iSz, const char* s, size_t sSz, + const char* b, int bSz, const char* a, int aSz) + : issuer_(i, iSz), subject_(s, sSz), + beforeDate_(b, bSz), afterDate_(a, aSz) {} @@ -2016,9 +2045,78 @@ X509_NAME* X509::GetSubject() } +ASN1_STRING* X509::GetBefore() +{ + return beforeDate_.GetString(); +} + + +ASN1_STRING* X509::GetAfter() +{ + return afterDate_.GetString(); +} + + +ASN1_STRING* X509_NAME::GetEntry(int i) +{ + if (i < 0 || i >= int(sz_)) + return 0; + + if (entry_.data) + ysArrayDelete(entry_.data); + entry_.data = NEW_YS byte[sz_]; // max size; + + memcpy(entry_.data, &name_[i], sz_ - i); + if (entry_.data[sz_ -i - 1]) { + entry_.data[sz_ - i] = 0; + entry_.length = sz_ - i; + } + else + entry_.length = sz_ - i - 1; + entry_.type = 0; + + return &entry_; +} + + +StringHolder::StringHolder(const char* str, int sz) +{ + asnString_.length = sz; + asnString_.data = NEW_YS byte[sz + 1]; + memcpy(asnString_.data, str, sz); + asnString_.type = 0; // not used for now +} + + +StringHolder::~StringHolder() +{ + ysArrayDelete(asnString_.data); +} + + +ASN1_STRING* StringHolder::GetString() +{ + return &asnString_; +} + } // namespace + +extern "C" void yaSSL_CleanUp() +{ + TaoCrypt::CleanUp(); + yaSSL::ysDelete(yaSSL::cryptProviderInstance); + yaSSL::ysDelete(yaSSL::sslFactoryInstance); + yaSSL::ysDelete(yaSSL::sessionsInstance); + + // In case user calls more than once, prevent seg fault + yaSSL::cryptProviderInstance = 0; + yaSSL::sslFactoryInstance = 0; + yaSSL::sessionsInstance = 0; +} + + #ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION namespace mySTL { template yaSSL::yassl_int_cpp_local1::SumData for_each<mySTL::list<yaSSL::input_buffer*>::iterator, yaSSL::yassl_int_cpp_local1::SumData>(mySTL::list<yaSSL::input_buffer*>::iterator, mySTL::list<yaSSL::input_buffer*>::iterator, yaSSL::yassl_int_cpp_local1::SumData); diff --git a/extra/yassl/taocrypt/cmakelists.txt b/extra/yassl/taocrypt/CMakeLists.txt index 3ad9195b372..0af0a242e5d 100644 --- a/extra/yassl/taocrypt/cmakelists.txt +++ b/extra/yassl/taocrypt/CMakeLists.txt @@ -2,7 +2,7 @@ INCLUDE_DIRECTORIES(../mySTL include) ADD_LIBRARY(taocrypt src/aes.cpp src/aestables.cpp src/algebra.cpp src/arc4.cpp src/asn.cpp src/coding.cpp src/des.cpp src/dh.cpp src/dsa.cpp src/file.cpp src/hash.cpp src/integer.cpp src/md2.cpp - src/md5.cpp src/misc.cpp src/random.cpp src/ripemd.cpp src/rsa.cpp src/sha.cpp + src/md4.cpp src/md5.cpp src/misc.cpp src/random.cpp src/ripemd.cpp src/rsa.cpp src/sha.cpp include/aes.hpp include/algebra.hpp include/arc4.hpp include/asn.hpp include/block.hpp include/coding.hpp include/des.hpp include/dh.hpp include/dsa.hpp include/dsa.hpp include/error.hpp include/file.hpp include/hash.hpp include/hmac.hpp include/integer.hpp diff --git a/extra/yassl/taocrypt/Makefile.am b/extra/yassl/taocrypt/Makefile.am index 859c704e9d5..c242696b82f 100644 --- a/extra/yassl/taocrypt/Makefile.am +++ b/extra/yassl/taocrypt/Makefile.am @@ -1,2 +1,2 @@ SUBDIRS = src test benchmark -EXTRA_DIST = taocrypt.dsw taocrypt.dsp taocrypt.vcproj cmakelists.txt +EXTRA_DIST = taocrypt.dsw taocrypt.dsp taocrypt.vcproj CMakeLists.txt diff --git a/extra/yassl/taocrypt/benchmark/make.bat b/extra/yassl/taocrypt/benchmark/make.bat index 63391578cfa..4ebe4b32417 100644 --- a/extra/yassl/taocrypt/benchmark/make.bat +++ b/extra/yassl/taocrypt/benchmark/make.bat @@ -1,10 +1,9 @@ -# quick and dirty build file for testing different MSDEVs +REM quick and dirty build file for testing different MSDEVs setlocal set myFLAGS= /I../include /I../../mySTL /c /W3 /G6 /O2 -#set myFLAGS= /I../include /I../../mySTL /c /W3 cl %myFLAGS% benchmark.cpp -link.exe /out:benchmark.exe ../src/taocrypt.lib benchmark.obj +link.exe /out:benchmark.exe ../src/taocrypt.lib benchmark.obj advapi32.lib diff --git a/extra/yassl/taocrypt/include/asn.hpp b/extra/yassl/taocrypt/include/asn.hpp index 6a1163fbb1c..da4c0ce1349 100644 --- a/extra/yassl/taocrypt/include/asn.hpp +++ b/extra/yassl/taocrypt/include/asn.hpp @@ -79,20 +79,27 @@ enum ASNIdFlag enum DNTags { - COMMON_NAME = 0x03 + COMMON_NAME = 0x03, // CN + SUR_NAME = 0x04, // SN + COUNTRY_NAME = 0x06, // C + LOCALITY_NAME = 0x07, // L + STATE_NAME = 0x08, // ST + ORG_NAME = 0x0a, // O + ORGUNIT_NAME = 0x0b // OU }; enum Constants { MIN_DATE_SZ = 13, - MAX_DATE_SZ = 15, + MAX_DATE_SZ = 16, MAX_ALGO_SZ = 16, MAX_LENGTH_SZ = 5, MAX_SEQ_SZ = 5, // enum(seq|con) + length(4) MAX_ALGO_SIZE = 9, MAX_DIGEST_SZ = 25, // SHA + enum(Bit or Octet) + length(4) - DSA_SIG_SZ = 40 + DSA_SIG_SZ = 40, + NAME_MAX = 512 // max total of all included names }; @@ -205,14 +212,14 @@ enum { SHA_SIZE = 20 }; // A Signing Authority class Signer { PublicKey key_; - char* name_; + char name_[NAME_MAX]; byte hash_[SHA_SIZE]; public: Signer(const byte* k, word32 kSz, const char* n, const byte* h); ~Signer(); const PublicKey& GetPublicKey() const { return key_; } - const char* GetCommonName() const { return name_; } + const char* GetName() const { return name_; } const byte* GetHash() const { return hash_; } private: @@ -245,6 +252,8 @@ public: const char* GetIssuer() const { return issuer_; } const char* GetCommonName() const { return subject_; } const byte* GetHash() const { return subjectHash_; } + const char* GetBeforeDate() const { return beforeDate_; } + const char* GetAfterDate() const { return afterDate_; } void DecodeToKey(); private: @@ -257,8 +266,10 @@ private: byte subjectHash_[SHA_SIZE]; // hash of all Names byte issuerHash_[SHA_SIZE]; // hash of all Names byte* signature_; - char* issuer_; // CommonName - char* subject_; // CommonName + char issuer_[NAME_MAX]; // Names + char subject_[NAME_MAX]; // Names + char beforeDate_[MAX_DATE_SZ]; // valid before date + char afterDate_[MAX_DATE_SZ]; // valid after date bool verify_; // Default to yes, but could be off void ReadHeader(); diff --git a/extra/yassl/taocrypt/include/block.hpp b/extra/yassl/taocrypt/include/block.hpp index 4c262e1a540..76836615ce6 100644 --- a/extra/yassl/taocrypt/include/block.hpp +++ b/extra/yassl/taocrypt/include/block.hpp @@ -96,7 +96,7 @@ public: pointer allocate(size_type n, const void* = 0) { - CheckSize(n); + this->CheckSize(n); if (n == 0) return 0; return NEW_TC T[n]; diff --git a/extra/yassl/taocrypt/include/md4.hpp b/extra/yassl/taocrypt/include/md4.hpp new file mode 100644 index 00000000000..aac930d7498 --- /dev/null +++ b/extra/yassl/taocrypt/include/md4.hpp @@ -0,0 +1,65 @@ +/* md4.hpp + * + * Copyright (C) 2003 Sawtooth Consulting Ltd. + * + * This file is part of yaSSL. + * + * yaSSL 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. + * + * yaSSL 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 + */ + +/* md4.hpp provides MD4 digest support + * WANRING: MD4 is considered insecure, only use if you have to, e.g., yaSSL + * libcurl supports needs this for NTLM authentication +*/ + +#ifndef TAO_CRYPT_MD4_HPP +#define TAO_CRYPT_MD4_HPP + +#include "hash.hpp" + +namespace TaoCrypt { + + +// MD4 digest +class MD4 : public HASHwithTransform { +public: + enum { BLOCK_SIZE = 64, DIGEST_SIZE = 16, PAD_SIZE = 56, + TAO_BYTE_ORDER = LittleEndianOrder }; // in Bytes + MD4() : HASHwithTransform(DIGEST_SIZE / sizeof(word32), BLOCK_SIZE) + { Init(); } + ByteOrder getByteOrder() const { return ByteOrder(TAO_BYTE_ORDER); } + word32 getBlockSize() const { return BLOCK_SIZE; } + word32 getDigestSize() const { return DIGEST_SIZE; } + word32 getPadSize() const { return PAD_SIZE; } + + MD4(const MD4&); + MD4& operator= (const MD4&); + + void Init(); + void Swap(MD4&); +private: + void Transform(); +}; + +inline void swap(MD4& a, MD4& b) +{ + a.Swap(b); +} + + +} // namespace + +#endif // TAO_CRYPT_MD4_HPP + diff --git a/extra/yassl/taocrypt/src/Makefile.am b/extra/yassl/taocrypt/src/Makefile.am index d3e72346110..1110ed335b8 100644 --- a/extra/yassl/taocrypt/src/Makefile.am +++ b/extra/yassl/taocrypt/src/Makefile.am @@ -4,7 +4,7 @@ noinst_LTLIBRARIES = libtaocrypt.la libtaocrypt_la_SOURCES = aes.cpp aestables.cpp algebra.cpp arc4.cpp \ asn.cpp bftables.cpp blowfish.cpp coding.cpp des.cpp dh.cpp \ - dsa.cpp file.cpp hash.cpp integer.cpp md2.cpp md5.cpp misc.cpp \ + dsa.cpp file.cpp hash.cpp integer.cpp md2.cpp md4.cpp md5.cpp misc.cpp \ random.cpp ripemd.cpp rsa.cpp sha.cpp template_instnt.cpp \ tftables.cpp twofish.cpp diff --git a/extra/yassl/taocrypt/src/asn.cpp b/extra/yassl/taocrypt/src/asn.cpp index 3efc26ab168..383fe65dea6 100644 --- a/extra/yassl/taocrypt/src/asn.cpp +++ b/extra/yassl/taocrypt/src/asn.cpp @@ -213,21 +213,17 @@ void PublicKey::AddToEnd(const byte* data, word32 len) Signer::Signer(const byte* k, word32 kSz, const char* n, const byte* h) - : key_(k, kSz), name_(0) + : key_(k, kSz) { - if (n) { int sz = strlen(n); - name_ = NEW_TC char[sz + 1]; memcpy(name_, n, sz); name_[sz] = 0; - } memcpy(hash_, h, SHA::DIGEST_SIZE); } Signer::~Signer() { - tcArrayDelete(name_); } @@ -424,17 +420,19 @@ void DH_Decoder::Decode(DH& key) CertDecoder::CertDecoder(Source& s, bool decode, SignerList* signers, bool noVerify, CertType ct) : BER_Decoder(s), certBegin_(0), sigIndex_(0), sigLength_(0), - signature_(0), issuer_(0), subject_(0), verify_(!noVerify) + signature_(0), verify_(!noVerify) { + issuer_[0] = 0; + subject_[0] = 0; + if (decode) Decode(signers, ct); + } CertDecoder::~CertDecoder() { - tcArrayDelete(subject_); - tcArrayDelete(issuer_); tcArrayDelete(signature_); } @@ -672,8 +670,12 @@ void CertDecoder::GetName(NameType nt) SHA sha; word32 length = GetSequence(); // length of all distinguished names + assert (length < NAME_MAX); length += source_.get_index(); + char* ptr = (nt == ISSUER) ? issuer_ : subject_; + word32 idx = 0; + while (source_.get_index() < length) { GetSet(); GetSequence(); @@ -694,13 +696,49 @@ void CertDecoder::GetName(NameType nt) byte id = source_.next(); b = source_.next(); // strType word32 strLen = GetLength(source_); + bool copy = false; if (id == COMMON_NAME) { - char*& ptr = (nt == ISSUER) ? issuer_ : subject_; - ptr = NEW_TC char[strLen + 1]; - memcpy(ptr, source_.get_current(), strLen); - ptr[strLen] = 0; + memcpy(&ptr[idx], "/CN=", 4); + idx += 4; + copy = true; + } + else if (id == SUR_NAME) { + memcpy(&ptr[idx], "/SN=", 4); + idx += 4; + copy = true; + } + else if (id == COUNTRY_NAME) { + memcpy(&ptr[idx], "/C=", 3); + idx += 3; + copy = true; + } + else if (id == LOCALITY_NAME) { + memcpy(&ptr[idx], "/L=", 3); + idx += 3; + copy = true; + } + else if (id == STATE_NAME) { + memcpy(&ptr[idx], "/ST=", 4); + idx += 4; + copy = true; } + else if (id == ORG_NAME) { + memcpy(&ptr[idx], "/O=", 3); + idx += 3; + copy = true; + } + else if (id == ORGUNIT_NAME) { + memcpy(&ptr[idx], "/OU=", 4); + idx += 4; + copy = true; + } + + if (copy) { + memcpy(&ptr[idx], source_.get_current(), strLen); + idx += strLen; + } + sha.Update(source_.get_current(), strLen); source_.advance(strLen); } @@ -711,6 +749,8 @@ void CertDecoder::GetName(NameType nt) source_.advance(length); } } + ptr[idx++] = 0; + if (nt == ISSUER) sha.Final(issuerHash_); else @@ -744,6 +784,16 @@ void CertDecoder::GetDate(DateType dt) source_.SetError(BEFORE_DATE_E); else source_.SetError(AFTER_DATE_E); + + // save for later use + if (dt == BEFORE) { + memcpy(beforeDate_, date, length); + beforeDate_[length] = 0; + } + else { // after + memcpy(afterDate_, date, length); + afterDate_[length] = 0; + } } diff --git a/extra/yassl/taocrypt/src/integer.cpp b/extra/yassl/taocrypt/src/integer.cpp index 82a248ff7da..a296e122985 100644 --- a/extra/yassl/taocrypt/src/integer.cpp +++ b/extra/yassl/taocrypt/src/integer.cpp @@ -2428,7 +2428,7 @@ void PositiveMultiply(Integer& product, const Integer& a, const Integer& b) product.reg_.CleanNew(RoundupSize(aSize + bSize)); product.sign_ = Integer::POSITIVE; - WordBlock workspace(aSize + bSize); + AlignedWordBlock workspace(aSize + bSize); AsymmetricMultiply(product.reg_.get_buffer(), workspace.get_buffer(), a.reg_.get_buffer(), aSize, b.reg_.get_buffer(), bSize); } @@ -2735,8 +2735,11 @@ void CleanUp() { tcDelete(one); tcDelete(zero); -} + // In case user calls more than once, prevent seg fault + one = 0; + zero = 0; +} Integer::Integer(RandomNumberGenerator& rng, const Integer& min, const Integer& max) @@ -3375,7 +3378,7 @@ void PositiveDivide(Integer& remainder, Integer& quotient, quotient.reg_.CleanNew(RoundupSize(aSize-bSize+2)); quotient.sign_ = Integer::POSITIVE; - WordBlock T(aSize+2*bSize+4); + AlignedWordBlock T(aSize+2*bSize+4); Divide(remainder.reg_.get_buffer(), quotient.reg_.get_buffer(), T.get_buffer(), a.reg_.get_buffer(), aSize, b.reg_.get_buffer(), bSize); @@ -3595,7 +3598,7 @@ Integer Integer::InverseMod(const Integer &m) const return !u ? Zero() : (m*(*this-u)+1)/(*this); } - WordBlock T(m.reg_.size() * 4); + AlignedWordBlock T(m.reg_.size() * 4); Integer r((word)0, m.reg_.size()); unsigned k = AlmostInverse(r.reg_.get_buffer(), T.get_buffer(), reg_.get_buffer(), reg_.size(), diff --git a/extra/yassl/taocrypt/src/make.bat b/extra/yassl/taocrypt/src/make.bat index 5a2ae580b76..ecf7e8f8469 100644 --- a/extra/yassl/taocrypt/src/make.bat +++ b/extra/yassl/taocrypt/src/make.bat @@ -1,8 +1,7 @@ -# quick and dirty build file for testing different MSDEVs +REM quick and dirty build file for testing different MSDEVs setlocal set myFLAGS= /I../include /I../../mySTL /c /W3 /G6 /O2 -#set myFLAGS= /I../include /I../../mySTL /c /W3 /O1 cl %myFLAGS% aes.cpp cl %myFLAGS% aestables.cpp diff --git a/extra/yassl/taocrypt/src/md4.cpp b/extra/yassl/taocrypt/src/md4.cpp new file mode 100644 index 00000000000..dfc2b079141 --- /dev/null +++ b/extra/yassl/taocrypt/src/md4.cpp @@ -0,0 +1,154 @@ +/* md4.cpp + * + * Copyright (C) 2003 Sawtooth Consulting Ltd. + * + * This file is part of yaSSL. + * + * yaSSL 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. + * + * yaSSL 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 + */ + + +/* based on Wei Dai's md4.cpp from CryptoPP */ + +#include "runtime.hpp" +#include "md4.hpp" +#include "algorithm.hpp" // mySTL::swap + + + +namespace TaoCrypt { + +void MD4::Init() +{ + digest_[0] = 0x67452301L; + digest_[1] = 0xefcdab89L; + digest_[2] = 0x98badcfeL; + digest_[3] = 0x10325476L; + + buffLen_ = 0; + loLen_ = 0; + hiLen_ = 0; +} + + +MD4::MD4(const MD4& that) : HASHwithTransform(DIGEST_SIZE / sizeof(word32), + BLOCK_SIZE) +{ + buffLen_ = that.buffLen_; + loLen_ = that.loLen_; + hiLen_ = that.hiLen_; + + memcpy(digest_, that.digest_, DIGEST_SIZE); + memcpy(buffer_, that.buffer_, BLOCK_SIZE); +} + +MD4& MD4::operator= (const MD4& that) +{ + MD4 tmp(that); + Swap(tmp); + + return *this; +} + + +void MD4::Swap(MD4& other) +{ + mySTL::swap(loLen_, other.loLen_); + mySTL::swap(hiLen_, other.hiLen_); + mySTL::swap(buffLen_, other.buffLen_); + + memcpy(digest_, other.digest_, DIGEST_SIZE); + memcpy(buffer_, other.buffer_, BLOCK_SIZE); +} + + +void MD4::Transform() +{ +#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) +#define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z))) +#define H(x, y, z) ((x) ^ (y) ^ (z)) + + word32 A, B, C, D; + + A = digest_[0]; + B = digest_[1]; + C = digest_[2]; + D = digest_[3]; + +#define function(a,b,c,d,k,s) a=rotlFixed(a+F(b,c,d)+buffer_[k],s); + function(A,B,C,D, 0, 3); + function(D,A,B,C, 1, 7); + function(C,D,A,B, 2,11); + function(B,C,D,A, 3,19); + function(A,B,C,D, 4, 3); + function(D,A,B,C, 5, 7); + function(C,D,A,B, 6,11); + function(B,C,D,A, 7,19); + function(A,B,C,D, 8, 3); + function(D,A,B,C, 9, 7); + function(C,D,A,B,10,11); + function(B,C,D,A,11,19); + function(A,B,C,D,12, 3); + function(D,A,B,C,13, 7); + function(C,D,A,B,14,11); + function(B,C,D,A,15,19); + +#undef function +#define function(a,b,c,d,k,s) a=rotlFixed(a+G(b,c,d)+buffer_[k]+0x5a827999,s); + function(A,B,C,D, 0, 3); + function(D,A,B,C, 4, 5); + function(C,D,A,B, 8, 9); + function(B,C,D,A,12,13); + function(A,B,C,D, 1, 3); + function(D,A,B,C, 5, 5); + function(C,D,A,B, 9, 9); + function(B,C,D,A,13,13); + function(A,B,C,D, 2, 3); + function(D,A,B,C, 6, 5); + function(C,D,A,B,10, 9); + function(B,C,D,A,14,13); + function(A,B,C,D, 3, 3); + function(D,A,B,C, 7, 5); + function(C,D,A,B,11, 9); + function(B,C,D,A,15,13); + +#undef function +#define function(a,b,c,d,k,s) a=rotlFixed(a+H(b,c,d)+buffer_[k]+0x6ed9eba1,s); + function(A,B,C,D, 0, 3); + function(D,A,B,C, 8, 9); + function(C,D,A,B, 4,11); + function(B,C,D,A,12,15); + function(A,B,C,D, 2, 3); + function(D,A,B,C,10, 9); + function(C,D,A,B, 6,11); + function(B,C,D,A,14,15); + function(A,B,C,D, 1, 3); + function(D,A,B,C, 9, 9); + function(C,D,A,B, 5,11); + function(B,C,D,A,13,15); + function(A,B,C,D, 3, 3); + function(D,A,B,C,11, 9); + function(C,D,A,B, 7,11); + function(B,C,D,A,15,15); + + digest_[0] += A; + digest_[1] += B; + digest_[2] += C; + digest_[3] += D; +} + + +} // namespace + diff --git a/extra/yassl/taocrypt/src/misc.cpp b/extra/yassl/taocrypt/src/misc.cpp index 3d0539187a7..2869df71c8a 100644 --- a/extra/yassl/taocrypt/src/misc.cpp +++ b/extra/yassl/taocrypt/src/misc.cpp @@ -25,6 +25,15 @@ #include "runtime.hpp" #include "misc.hpp" + +extern "C" { + + // for libcurl configure test, these are the signatures they use + // locking handled internally by library + char CRYPTO_lock() { return 0;} + char CRYPTO_add_lock() { return 0;} +} // extern "C" + #ifdef YASSL_PURE_C void* operator new(size_t sz, TaoCrypt::new_t) @@ -72,6 +81,19 @@ } +#if defined(__ICC) || defined(__INTEL_COMPILER) + +extern "C" { + + int __cxa_pure_virtual() { + assert("Pure virtual method called." == "Aborted"); + return 0; + } + +} // extern "C" + +#endif + #endif // YASSL_PURE_C diff --git a/extra/yassl/taocrypt/taocrypt.dsp b/extra/yassl/taocrypt/taocrypt.dsp index 13b9a07419b..19edf7b2f22 100644 --- a/extra/yassl/taocrypt/taocrypt.dsp +++ b/extra/yassl/taocrypt/taocrypt.dsp @@ -64,7 +64,8 @@ LIB32=link.exe -lib # PROP Intermediate_Dir "Debug" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /I "include" /I "..\mySTL" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /I "include" /I "..\mySTL" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# SUBTRACT CPP /Fr # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe @@ -145,6 +146,10 @@ SOURCE=.\src\md2.cpp # End Source File # Begin Source File +SOURCE=.\src\md4.cpp +# End Source File +# Begin Source File + SOURCE=.\src\md5.cpp # End Source File # Begin Source File @@ -245,6 +250,10 @@ SOURCE=.\include\md2.hpp # End Source File # Begin Source File +SOURCE=.\include\md4.hpp +# End Source File +# Begin Source File + SOURCE=.\include\md5.hpp # End Source File # Begin Source File diff --git a/extra/yassl/taocrypt/taocrypt.vcproj b/extra/yassl/taocrypt/taocrypt.vcproj index 603fafd4090..7eef7b82db7 100755 --- a/extra/yassl/taocrypt/taocrypt.vcproj +++ b/extra/yassl/taocrypt/taocrypt.vcproj @@ -397,6 +397,27 @@ </FileConfiguration> </File> <File + RelativePath="src\md4.cpp"> + <FileConfiguration + Name="Debug|Win32"> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="" + PreprocessorDefinitions="" + BasicRuntimeChecks="3" + BrowseInformation="1"/> + </FileConfiguration> + <FileConfiguration + Name="Release|Win32"> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + AdditionalIncludeDirectories="" + PreprocessorDefinitions=""/> + </FileConfiguration> + </File> + <File RelativePath="src\md5.cpp"> <FileConfiguration Name="Debug|Win32"> @@ -572,6 +593,9 @@ RelativePath="include\md2.hpp"> </File> <File + RelativePath="include\md4.hpp"> + </File> + <File RelativePath="include\md5.hpp"> </File> <File diff --git a/extra/yassl/taocrypt/test/make.bat b/extra/yassl/taocrypt/test/make.bat index e1a4cbce7cd..5f01db68d0d 100644 --- a/extra/yassl/taocrypt/test/make.bat +++ b/extra/yassl/taocrypt/test/make.bat @@ -1,4 +1,4 @@ -# quick and dirty build file for testing different MSDEVs +REM quick and dirty build file for testing different MSDEVs setlocal set myFLAGS= /I../include /I../../mySTL /c /W3 /G6 /O2 diff --git a/extra/yassl/taocrypt/test/test.cpp b/extra/yassl/taocrypt/test/test.cpp index b8618b18d47..28ef73dfac8 100644 --- a/extra/yassl/taocrypt/test/test.cpp +++ b/extra/yassl/taocrypt/test/test.cpp @@ -8,6 +8,7 @@ #include "sha.hpp" #include "md5.hpp" #include "md2.hpp" +#include "md4.hpp" #include "ripemd.hpp" #include "hmac.hpp" #include "arc4.hpp" @@ -30,6 +31,7 @@ using TaoCrypt::word32; using TaoCrypt::SHA; using TaoCrypt::MD5; using TaoCrypt::MD2; +using TaoCrypt::MD4; using TaoCrypt::RIPEMD160; using TaoCrypt::HMAC; using TaoCrypt::ARC4; @@ -89,6 +91,7 @@ void file_test(int, char**); int sha_test(); int md5_test(); int md2_test(); +int md4_test(); int ripemd_test(); int hmac_test(); int arc4_test(); @@ -165,6 +168,11 @@ void taocrypt_test(void* args) else printf( "MD2 test passed!\n"); + if ( (ret = md4_test()) ) + err_sys("MD4 test failed!\n", ret); + else + printf( "MD4 test passed!\n"); + if ( (ret = ripemd_test()) ) err_sys("RIPEMD test failed!\n", ret); else @@ -348,6 +356,51 @@ int md5_test() } +int md4_test() +{ + MD4 md4; + byte hash[MD4::DIGEST_SIZE]; + + testVector test_md4[] = + { + testVector("", + "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31\xb7\x3c\x59\xd7\xe0\xc0\x89" + "\xc0"), + testVector("a", + "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46\x24\x5e\x05\xfb\xdb\xd6\xfb" + "\x24"), + testVector("abc", + "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72" + "\x9d"), + testVector("message digest", + "\xd9\x13\x0a\x81\x64\x54\x9f\xe8\x18\x87\x48\x06\xe1\xc7\x01" + "\x4b"), + testVector("abcdefghijklmnopqrstuvwxyz", + "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd\xee\xa8\xed\x63\xdf\x41\x2d" + "\xa9"), + testVector("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345" + "6789", + "\x04\x3f\x85\x82\xf2\x41\xdb\x35\x1c\xe6\x27\xe1\x53\xe7\xf0" + "\xe4"), + testVector("1234567890123456789012345678901234567890123456789012345678" + "9012345678901234567890", + "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f\xcc\x05" + "\x36") + }; + + int times( sizeof(test_md4) / sizeof(testVector) ); + for (int i = 0; i < times; ++i) { + md4.Update(test_md4[i].input_, test_md4[i].inLen_); + md4.Final(hash); + + if (memcmp(hash, test_md4[i].output_, MD4::DIGEST_SIZE) != 0) + return -5 - i; + } + + return 0; +} + + int md2_test() { MD2 md5; diff --git a/extra/yassl/testsuite/make.bat b/extra/yassl/testsuite/make.bat index d8a55b0d3af..1bc7ce0513d 100644 --- a/extra/yassl/testsuite/make.bat +++ b/extra/yassl/testsuite/make.bat @@ -1,4 +1,4 @@ -# quick and dirty build file for testing different MSDEVs +REM quick and dirty build file for testing different MSDEVs setlocal set myFLAGS= /I../include /I../taocrypt/include /I../mySTL /c /W3 /G6 /O2 /MT /D"WIN32" /D"NO_MAIN_DRIVER" diff --git a/extra/yassl/testsuite/test.hpp b/extra/yassl/testsuite/test.hpp index 79d02b63558..c80e3ad23da 100644 --- a/extra/yassl/testsuite/test.hpp +++ b/extra/yassl/testsuite/test.hpp @@ -27,16 +27,22 @@ #endif /* _WIN32 */ -#if defined(__MACH__) || defined(_WIN32) +#if !defined(_SOCKLEN_T) && (defined(__MACH__) || defined(_WIN32)) typedef int socklen_t; #endif // HPUX doesn't use socklent_t for third parameter to accept -#if !defined(__hpux__) +#if !defined(__hpux) typedef socklen_t* ACCEPT_THIRD_T; #else typedef int* ACCEPT_THIRD_T; + +// HPUX does not define _POSIX_THREADS as it's not _fully_ implemented +#ifndef _POSIX_THREADS +#define _POSIX_THREADS +#endif + #endif @@ -305,8 +311,8 @@ inline void showPeer(SSL* ssl) char* subject = X509_NAME_oneline(X509_get_subject_name(peer), 0, 0); printf("peer's cert info:\n"); - printf("issuer is: %s\n", issuer); - printf("subject is: %s\n", subject); + printf("issuer : %s\n", issuer); + printf("subject: %s\n", subject); free(subject); free(issuer); diff --git a/extra/yassl/testsuite/testsuite.cpp b/extra/yassl/testsuite/testsuite.cpp index af988432a86..1cf6a78ebe7 100644 --- a/extra/yassl/testsuite/testsuite.cpp +++ b/extra/yassl/testsuite/testsuite.cpp @@ -91,6 +91,7 @@ int main(int argc, char** argv) assert(memcmp(input, output, sizeof(input)) == 0); printf("\nAll tests passed!\n"); + yaSSL_CleanUp(); return 0; } @@ -146,10 +147,10 @@ int test_openSSL_des() (byte*)key, iv); byte cipher[16]; - DES_ede3_cbc_encrypt((byte*)data, cipher, dataSz, &key[0], &key[8], - &key[16], &iv, true); + DES_ede3_cbc_encrypt((byte*)data, cipher, dataSz, &key[0], &key[1], + &key[2], &iv, true); byte plain[16]; - DES_ede3_cbc_encrypt(cipher, plain, 16, &key[0], &key[8], &key[16], + DES_ede3_cbc_encrypt(cipher, plain, 16, &key[0], &key[1], &key[2], &iv, false); return 0; } diff --git a/extra/yassl/testsuite/testsuite.dsp b/extra/yassl/testsuite/testsuite.dsp index f896aa7f020..24c325fa878 100644 --- a/extra/yassl/testsuite/testsuite.dsp +++ b/extra/yassl/testsuite/testsuite.dsp @@ -42,7 +42,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX- /O2 /I "../taocrypt/include" /I "../include" /I "../mySTL" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "NO_MAIN_DRIVER" /YX /FD /c +# ADD CPP /nologo /MT /W3 /O2 /I "../taocrypt/include" /I "../include" /I "../mySTL" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "NO_MAIN_DRIVER" /YX /FD /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe @@ -67,7 +67,7 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GX- /ZI /Od /I "../taocrypt/include" /I "../include" /I "../mySTL" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "NO_MAIN_DRIVER" /FR /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /I "../taocrypt/include" /I "../include" /I "../mySTL" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "NO_MAIN_DRIVER" /FR /YX /FD /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe diff --git a/include/Makefile.am b/include/Makefile.am index e1ddadb933a..27b359bb6a3 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -31,7 +31,8 @@ noinst_HEADERS = config-win.h config-netware.h \ my_aes.h my_tree.h my_trie.h hash.h thr_alarm.h \ thr_lock.h t_ctype.h violite.h md5.h base64.h \ mysql_version.h.in my_handler.h my_time.h decimal.h \ - my_vle.h my_user.h + my_vle.h my_user.h my_atomic.h atomic/nolock.h \ + atomic/rwlock.h atomic/x86-gcc.h atomic/x86-msvc.h # mysql_version.h are generated CLEANFILES = mysql_version.h my_config.h readline openssl diff --git a/include/atomic/nolock.h b/include/atomic/nolock.h new file mode 100644 index 00000000000..cf21a94c7de --- /dev/null +++ b/include/atomic/nolock.h @@ -0,0 +1,169 @@ +/* Copyright (C) 2006 MySQL 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 */ + +#if defined(__i386__) || defined(_M_IX86) +#ifdef MY_ATOMIC_MODE_DUMMY +# define LOCK "" +#else +# define LOCK "lock " +#endif +#ifdef __GNUC__ +#include "x86-gcc.h" +#elif defined(_MSC_VER) +#include "x86-msvc.h" +#endif +#endif + +#ifdef make_atomic_add_body8 + +#ifdef HAVE_INLINE + +#define make_atomic_add(S) \ +static inline uint ## S _my_atomic_add ## S( \ + my_atomic_ ## S ## _t *a, uint ## S v) \ +{ \ + make_atomic_add_body ## S; \ + return v; \ +} + +#define make_atomic_swap(S) \ +static inline uint ## S _my_atomic_swap ## S( \ + my_atomic_ ## S ## _t *a, uint ## S v) \ +{ \ + make_atomic_swap_body ## S; \ + return v; \ +} + +#define make_atomic_cas(S) \ +static inline uint _my_atomic_cas ## S(my_atomic_ ## S ## _t *a,\ + uint ## S *cmp, uint ## S set) \ +{ \ + uint8 ret; \ + make_atomic_cas_body ## S; \ + return ret; \ +} + +#define make_atomic_load(S) \ +static inline uint ## S _my_atomic_load ## S( \ + my_atomic_ ## S ## _t *a) \ +{ \ + uint ## S ret; \ + make_atomic_load_body ## S; \ + return ret; \ +} + +#define make_atomic_store(S) \ +static inline void _my_atomic_store ## S( \ + my_atomic_ ## S ## _t *a, uint ## S v) \ +{ \ + make_atomic_store_body ## S; \ +} + +#else /* no inline functions */ + +#define make_atomic_add(S) \ +extern uint ## S _my_atomic_add ## S( \ + my_atomic_ ## S ## _t *a, uint ## S v); + +#define make_atomic_swap(S) \ +extern uint ## S _my_atomic_swap ## S( \ + my_atomic_ ## S ## _t *a, uint ## S v); + +#define make_atomic_cas(S) \ +extern uint _my_atomic_cas ## S(my_atomic_ ## S ## _t *a, \ + uint ## S *cmp, uint ## S set); + +#define make_atomic_load(S) \ +extern uint ## S _my_atomic_load ## S( \ + my_atomic_ ## S ## _t *a); + +#define make_atomic_store(S) \ +extern void _my_atomic_store ## S( \ + my_atomic_ ## S ## _t *a, uint ## S v); + +#endif + +make_atomic_add( 8) +make_atomic_add(16) +make_atomic_add(32) + +make_atomic_cas( 8) +make_atomic_cas(16) +make_atomic_cas(32) + +make_atomic_load( 8) +make_atomic_load(16) +make_atomic_load(32) + +make_atomic_store( 8) +make_atomic_store(16) +make_atomic_store(32) + +make_atomic_swap( 8) +make_atomic_swap(16) +make_atomic_swap(32) + +#undef make_atomic_add_body8 +#undef make_atomic_cas_body8 +#undef make_atomic_load_body8 +#undef make_atomic_store_body8 +#undef make_atomic_swap_body8 +#undef make_atomic_add_body16 +#undef make_atomic_cas_body16 +#undef make_atomic_load_body16 +#undef make_atomic_store_body16 +#undef make_atomic_swap_body16 +#undef make_atomic_add_body32 +#undef make_atomic_cas_body32 +#undef make_atomic_load_body32 +#undef make_atomic_store_body32 +#undef make_atomic_swap_body32 +#undef make_atomic_add +#undef make_atomic_cas +#undef make_atomic_load +#undef make_atomic_store +#undef make_atomic_swap + +#define my_atomic_add8(a,v,L) _my_atomic_add8(a,v) +#define my_atomic_add16(a,v,L) _my_atomic_add16(a,v) +#define my_atomic_add32(a,v,L) _my_atomic_add32(a,v) + +#define my_atomic_cas8(a,c,v,L) _my_atomic_cas8(a,c,v) +#define my_atomic_cas16(a,c,v,L) _my_atomic_cas16(a,c,v) +#define my_atomic_cas32(a,c,v,L) _my_atomic_cas32(a,c,v) + +#define my_atomic_load8(a,L) _my_atomic_load8(a) +#define my_atomic_load16(a,L) _my_atomic_load16(a) +#define my_atomic_load32(a,L) _my_atomic_load32(a) + +#define my_atomic_store8(a,v,L) _my_atomic_store8(a,v) +#define my_atomic_store16(a,v,L) _my_atomic_store16(a,v) +#define my_atomic_store32(a,v,L) _my_atomic_store32(a,v) + +#define my_atomic_swap8(a,v,L) _my_atomic_swap8(a,v) +#define my_atomic_swap16(a,v,L) _my_atomic_swap16(a,v) +#define my_atomic_swap32(a,v,L) _my_atomic_swap32(a,v) + +#define my_atomic_rwlock_t typedef int +#define my_atomic_rwlock_destroy(name) +#define my_atomic_rwlock_init(name) +#define my_atomic_rwlock_rdlock(name) +#define my_atomic_rwlock_wrlock(name) +#define my_atomic_rwlock_rdunlock(name) +#define my_atomic_rwlock_wrunlock(name) + +#endif + diff --git a/include/atomic/rwlock.h b/include/atomic/rwlock.h new file mode 100644 index 00000000000..ca5be29ab9b --- /dev/null +++ b/include/atomic/rwlock.h @@ -0,0 +1,161 @@ +/* Copyright (C) 2006 MySQL 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 */ + +typedef struct {pthread_rwlock_t rw;} my_atomic_rwlock_t; + +#ifdef MY_ATOMIC_EXTRA_DEBUG +#define CHECK_RW if (rw) if (a->rw) assert(rw == a->rw); else a->rw=rw; +#else +#define CHECK_RW +#endif + +#ifdef MY_ATOMIC_MODE_DUMMY +/* + the following can never be enabled by ./configure, one need to put #define in + a source to trigger the following warning. The resulting code will be broken, + it only makes sense to do it to see now test_atomic detects broken + implementations (another way is to run a UP build on an SMP box). +*/ +#warning MY_ATOMIC_MODE_DUMMY and MY_ATOMIC_MODE_RWLOCKS are incompatible +#define my_atomic_rwlock_destroy(name) +#define my_atomic_rwlock_init(name) +#define my_atomic_rwlock_rdlock(name) +#define my_atomic_rwlock_wrlock(name) +#define my_atomic_rwlock_rdunlock(name) +#define my_atomic_rwlock_wrunlock(name) +#else +#define my_atomic_rwlock_destroy(name) pthread_rwlock_destroy(& (name)->rw) +#define my_atomic_rwlock_init(name) pthread_rwlock_init(& (name)->rw, 0) +#define my_atomic_rwlock_rdlock(name) pthread_rwlock_rdlock(& (name)->rw) +#define my_atomic_rwlock_wrlock(name) pthread_rwlock_wrlock(& (name)->rw) +#define my_atomic_rwlock_rdunlock(name) pthread_rwlock_unlock(& (name)->rw) +#define my_atomic_rwlock_wrunlock(name) pthread_rwlock_unlock(& (name)->rw) +#endif + +#ifdef HAVE_INLINE + +#define make_atomic_add(S) \ +static inline uint ## S my_atomic_add ## S( \ + my_atomic_ ## S ## _t *a, uint ## S v, my_atomic_rwlock_t *rw) \ +{ \ + uint ## S ret; \ + CHECK_RW; \ + if (rw) my_atomic_rwlock_wrlock(rw); \ + ret= a->val; \ + a->val+= v; \ + if (rw) my_atomic_rwlock_wrunlock(rw); \ + return ret; \ +} + +#define make_atomic_swap(S) \ +static inline uint ## S my_atomic_swap ## S( \ + my_atomic_ ## S ## _t *a, uint ## S v, my_atomic_rwlock_t *rw) \ +{ \ + uint ## S ret; \ + CHECK_RW; \ + if (rw) my_atomic_rwlock_wrlock(rw); \ + ret= a->val; \ + a->val= v; \ + if (rw) my_atomic_rwlock_wrunlock(rw); \ + return ret; \ +} + +#define make_atomic_cas(S) \ +static inline uint my_atomic_cas ## S(my_atomic_ ## S ## _t *a, \ + uint ## S *cmp, uint ## S set, my_atomic_rwlock_t *rw) \ +{ \ + uint ret; \ + CHECK_RW; \ + if (rw) my_atomic_rwlock_wrlock(rw); \ + if (ret= (a->val == *cmp)) a->val= set; else *cmp=a->val; \ + if (rw) my_atomic_rwlock_wrunlock(rw); \ + return ret; \ +} + +#define make_atomic_load(S) \ +static inline uint ## S my_atomic_load ## S( \ + my_atomic_ ## S ## _t *a, my_atomic_rwlock_t *rw) \ +{ \ + uint ## S ret; \ + CHECK_RW; \ + if (rw) my_atomic_rwlock_wrlock(rw); \ + ret= a->val; \ + if (rw) my_atomic_rwlock_wrunlock(rw); \ + return ret; \ +} + +#define make_atomic_store(S) \ +static inline void my_atomic_store ## S( \ + my_atomic_ ## S ## _t *a, uint ## S v, my_atomic_rwlock_t *rw) \ +{ \ + CHECK_RW; \ + if (rw) my_atomic_rwlock_rdlock(rw); \ + (a)->val= (v); \ + if (rw) my_atomic_rwlock_rdunlock(rw); \ +} + +#else /* no inline functions */ + +#define make_atomic_add(S) \ +extern uint ## S my_atomic_add ## S( \ + my_atomic_ ## S ## _t *a, uint ## S v, my_atomic_rwlock_t *rw); + +#define make_atomic_swap(S) \ +extern uint ## S my_atomic_swap ## S( \ + my_atomic_ ## S ## _t *a, uint ## S v, my_atomic_rwlock_t *rw); + +#define make_atomic_cas(S) \ +extern uint my_atomic_cas ## S(my_atomic_ ## S ## _t *a, \ + uint ## S *cmp, uint ## S set, my_atomic_rwlock_t *rw); + +#define make_atomic_load(S) \ +extern uint ## S my_atomic_load ## S( \ + my_atomic_ ## S ## _t *a, my_atomic_rwlock_t *rw); + +#define make_atomic_store(S) \ +extern void my_atomic_store ## S( \ + my_atomic_ ## S ## _t *a, uint ## S v, my_atomic_rwlock_t *rw); + +#endif + +make_atomic_add( 8) +make_atomic_add(16) +make_atomic_add(32) +make_atomic_add(64) +make_atomic_cas( 8) +make_atomic_cas(16) +make_atomic_cas(32) +make_atomic_cas(64) +make_atomic_load( 8) +make_atomic_load(16) +make_atomic_load(32) +make_atomic_load(64) +make_atomic_store( 8) +make_atomic_store(16) +make_atomic_store(32) +make_atomic_store(64) +make_atomic_swap( 8) +make_atomic_swap(16) +make_atomic_swap(32) +make_atomic_swap(64) +#undef make_atomic_add +#undef make_atomic_cas +#undef make_atomic_load +#undef make_atomic_store +#undef make_atomic_swap +#undef CHECK_RW + + diff --git a/include/atomic/x86-gcc.h b/include/atomic/x86-gcc.h new file mode 100644 index 00000000000..7576db54d69 --- /dev/null +++ b/include/atomic/x86-gcc.h @@ -0,0 +1,59 @@ +/* Copyright (C) 2006 MySQL 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 */ + +/* + XXX 64-bit atomic operations can be implemented using + cmpxchg8b, if necessary +*/ + +/* fix -ansi errors while maintaining readability */ +#define asm __asm__ + +#define make_atomic_add_body8 \ + asm volatile (LOCK "xadd %0, %1;" : "+r" (v) , "+m" (a->val)) +#define make_atomic_swap_body8 \ + asm volatile ("xchg %0, %1;" : "+r" (v) , "+m" (a->val)) +#define make_atomic_cas_body8 \ + asm volatile (LOCK "cmpxchg %3, %0; setz %2;" \ + : "+m" (a->val), "+a" (*cmp), "=q" (ret): "r" (set)) + +#ifdef MY_ATOMIC_MODE_DUMMY +#define make_atomic_load_body8 ret=a->val +#define make_atomic_store_body8 a->val=v +#else +/* + Actually 32-bit reads/writes are always atomic on x86 + But we add LOCK here anyway to force memory barriers +*/ +#define make_atomic_load_body8 \ + ret=0; \ + asm volatile (LOCK "cmpxchg %2, %0" \ + : "+m" (a->val), "+a" (ret): "r" (ret)) +#define make_atomic_store_body8 \ + asm volatile ("xchg %0, %1;" : "+m" (a->val) : "r" (v)) +#endif + +#define make_atomic_add_body16 make_atomic_add_body8 +#define make_atomic_add_body32 make_atomic_add_body8 +#define make_atomic_cas_body16 make_atomic_cas_body8 +#define make_atomic_cas_body32 make_atomic_cas_body8 +#define make_atomic_load_body16 make_atomic_load_body8 +#define make_atomic_load_body32 make_atomic_load_body8 +#define make_atomic_store_body16 make_atomic_store_body8 +#define make_atomic_store_body32 make_atomic_store_body8 +#define make_atomic_swap_body16 make_atomic_swap_body8 +#define make_atomic_swap_body32 make_atomic_swap_body8 + diff --git a/include/atomic/x86-msvc.h b/include/atomic/x86-msvc.h new file mode 100644 index 00000000000..19645551196 --- /dev/null +++ b/include/atomic/x86-msvc.h @@ -0,0 +1,85 @@ +/* Copyright (C) 2006 MySQL 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 */ + +/* + XXX 64-bit atomic operations can be implemented using + cmpxchg8b, if necessary +*/ + +// Would it be better to use intrinsics ? +// (InterlockedCompareExchange, InterlockedCompareExchange16 +// InterlockedExchangeAdd, InterlockedExchange) + +#define make_atomic_add_body(REG) \ + _asm { \ + _asm mov REG, v \ + _asm LOCK xadd a->val, REG \ + _asm movzx v, REG \ + } +#define make_atomic_cas_body(AREG,REG2) \ + _asm { \ + _asm mov AREG, *cmp \ + _asm mov REG2, set \ + _asm LOCK cmpxchg a->val, REG2 \ + _asm mov *cmp, AREG \ + _asm setz al \ + _asm movzx ret, al \ + } +#define make_atomic_swap_body(REG) \ + _asm { \ + _asm mov REG, v \ + _asm xchg a->val, REG \ + _asm mov v, REG \ + } + +#ifdef MY_ATOMIC_MODE_DUMMY +#define make_atomic_load_body(AREG,REG) ret=a->val +#define make_atomic_store_body(REG) a->val=v +#else +/* + Actually 32-bit reads/writes are always atomic on x86 + But we add LOCK here anyway to force memory barriers +*/ +#define make_atomic_load_body(AREG,REG2) \ + _asm { \ + _asm mov AREG, 0 \ + _asm mov REG2, AREG \ + _asm LOCK cmpxchg a->val, REG2 \ + _asm mov ret, AREG \ + } +#define make_atomic_store_body(REG) \ + _asm { \ + _asm mov REG, v \ + _asm xchg a->val, REG \ + } +#endif + +#define make_atomic_add_body8 make_atomic_add_body(al) +#define make_atomic_add_body16 make_atomic_add_body(ax) +#define make_atomic_add_body32 make_atomic_add_body(eax) +#define make_atomic_cas_body8 make_atomic_cas_body(al, bl) +#define make_atomic_cas_body16 make_atomic_cas_body(ax, bx) +#define make_atomic_cas_body32 make_atomic_cas_body(eax, ebx) +#define make_atomic_load_body8 make_atomic_load_body(al, bl) +#define make_atomic_load_body16 make_atomic_load_body(ax, bx) +#define make_atomic_load_body32 make_atomic_load_body(eax, ebx) +#define make_atomic_store_body8 make_atomic_store_body(al) +#define make_atomic_store_body16 make_atomic_store_body(ax) +#define make_atomic_store_body32 make_atomic_store_body(eax) +#define make_atomic_swap_body8 make_atomic_swap_body(al) +#define make_atomic_swap_body16 make_atomic_swap_body(ax) +#define make_atomic_swap_body32 make_atomic_swap_body(eax) + diff --git a/include/config-win.h b/include/config-win.h index 6d0f40adbd3..aa372762191 100644 --- a/include/config-win.h +++ b/include/config-win.h @@ -25,6 +25,7 @@ functions */ #if defined(_MSC_VER) && _MSC_VER >= 1400 /* Avoid endless warnings about sprintf() etc. being unsafe. */ #define _CRT_SECURE_NO_DEPRECATE 1 +#define _USE_32BIT_TIME_T 1 /* force time_t to be 32 bit */ #endif #include <sys/locking.h> @@ -95,7 +96,7 @@ functions */ #define O_SHORT_LIVED 0 #define SH_DENYNO _SH_DENYNO #else -#define O_BINARY _O_BINARY /* compability with MSDOS */ +#define O_BINARY _O_BINARY /* compability with older style names */ #define FILE_BINARY _O_BINARY /* my_fopen in binary mode */ #define O_TEMPORARY _O_TEMPORARY #define O_SHORT_LIVED _O_SHORT_LIVED diff --git a/include/heap.h b/include/heap.h index bf956184d3c..985b20f9dc9 100644 --- a/include/heap.h +++ b/include/heap.h @@ -111,7 +111,7 @@ struct st_heap_info; /* For referense */ typedef struct st_hp_keydef /* Key definition with open */ { - uint flag; /* HA_NOSAME | HA_NULL_PART_KEY */ + uint flag; /* HA_NOSAME | HA_NULL_PART_KEY */ uint keysegs; /* Number of key-segment */ uint length; /* Length of key (automatic) */ uint8 algorithm; /* HASH / BTREE */ diff --git a/include/m_string.h b/include/m_string.h index e73f5c11487..9f7ec220f2c 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -106,12 +106,6 @@ extern char NEAR _dig_vec_lower[]; #define memcpy_fixed(A,B,C) memcpy((A),(B),(C)) #endif -#ifdef MSDOS -#undef bmove_align -#define bmove512(A,B,C) bmove_align(A,B,C) -extern void bmove_align(gptr dst,const gptr src,uint len); -#endif - #if (!defined(USE_BMOVE512) || defined(HAVE_purify)) && !defined(bmove512) #define bmove512(A,B,C) memcpy(A,B,C) #endif @@ -246,4 +240,22 @@ extern int my_snprintf(char* to, size_t n, const char* fmt, ...); #if defined(__cplusplus) } #endif + +/* + LEX_STRING -- a pair of a C-string and its length. + + NOTE: this exactly form of declaration is required for some C-compilers + (for one, Sun C 5.7 2005/01/07). Unfortunatelt with such declaration + LEX_STRING can not be forward declared. +*/ + +typedef struct +{ + char *str; + uint length; +} LEX_STRING; + +#define STRING_WITH_LEN(X) (X), ((uint) (sizeof(X) - 1)) +#define C_STRING_WITH_SIZE(X) ((char *) (X)), ((uint) (sizeof(X) - 1)) + #endif diff --git a/include/my_atomic.h b/include/my_atomic.h new file mode 100644 index 00000000000..091edc0f57b --- /dev/null +++ b/include/my_atomic.h @@ -0,0 +1,46 @@ +/* Copyright (C) 2006 MySQL 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 */ + +#ifndef atomic_rwlock_init + +#ifdef MY_ATOMIC_EXTRA_DEBUG +#ifndef MY_ATOMIC_MODE_RWLOCKS +#error MY_ATOMIC_EXTRA_DEBUG can be only used with MY_ATOMIC_MODE_RWLOCKS +#endif +#define LOCK_PTR void *rw; +#else +#define LOCK_PTR +#endif + +typedef volatile struct {uint8 val; LOCK_PTR} my_atomic_8_t; +typedef volatile struct {uint16 val; LOCK_PTR} my_atomic_16_t; +typedef volatile struct {uint32 val; LOCK_PTR} my_atomic_32_t; +typedef volatile struct {uint64 val; LOCK_PTR} my_atomic_64_t; + +#ifndef MY_ATOMIC_MODE_RWLOCKS +#include "atomic/nolock.h" +#endif + +#ifndef my_atomic_rwlock_init +#include "atomic/rwlock.h" +#endif + +#define MY_ATOMIC_OK 0 +#define MY_ATOMIC_NOT_1CPU 1 +extern int my_atomic_initialize(); + +#endif + diff --git a/include/my_base.h b/include/my_base.h index d663fac153b..728b2ab2a1b 100644 --- a/include/my_base.h +++ b/include/my_base.h @@ -33,9 +33,6 @@ #define EOVERFLOW 84 #endif -#ifdef MSDOS -#include <share.h> /* Neaded for sopen() */ -#endif #if !defined(USE_MY_FUNC) && !defined(THREAD) #include <my_nosys.h> /* For faster code, after test */ #endif /* USE_MY_FUNC */ @@ -331,7 +328,7 @@ enum ha_base_keytype { #define HA_ERR_WRONG_COMMAND 131 /* Command not supported */ #define HA_ERR_OLD_FILE 132 /* old databasfile */ #define HA_ERR_NO_ACTIVE_RECORD 133 /* No record read in update() */ -#define HA_ERR_RECORD_DELETED 134 /* Intern error-code */ +#define HA_ERR_RECORD_DELETED 134 /* A record is not there */ #define HA_ERR_RECORD_FILE_FULL 135 /* No more room in file */ #define HA_ERR_INDEX_FILE_FULL 136 /* No more room in file */ #define HA_ERR_END_OF_FILE 137 /* end in next/prev/first/last */ diff --git a/include/my_dbug.h b/include/my_dbug.h index 65bb7b55d0d..a397861c1af 100644 --- a/include/my_dbug.h +++ b/include/my_dbug.h @@ -42,6 +42,7 @@ extern void _db_pargs_(uint _line_,const char *keyword); extern void _db_doprnt_ _VARARGS((const char *format,...)); extern void _db_dump_(uint _line_,const char *keyword,const char *memory, uint length); +extern void _db_end_(void); extern void _db_lock_file_(void); extern void _db_unlock_file_(void); extern FILE *_db_fp_(void); @@ -73,6 +74,7 @@ extern FILE *_db_fp_(void); #define DBUG_SETJMP(a1) (_db_setjmp_ (), setjmp (a1)) #define DBUG_LONGJMP(a1,a2) (_db_longjmp_ (), longjmp (a1, a2)) #define DBUG_DUMP(keyword,a1,a2) _db_dump_(__LINE__,keyword,a1,a2) +#define DBUG_END() _db_end_ () #define DBUG_LOCK_FILE _db_lock_file_() #define DBUG_UNLOCK_FILE _db_unlock_file_() #define DBUG_ASSERT(A) assert(A) @@ -97,6 +99,7 @@ extern FILE *_db_fp_(void); #define DBUG_SETJMP(a1) setjmp(a1) #define DBUG_LONGJMP(a1) longjmp(a1) #define DBUG_DUMP(keyword,a1,a2) +#define DBUG_END() #define DBUG_ASSERT(A) #define DBUG_LOCK_FILE #define DBUG_FILE (stderr) diff --git a/include/my_global.h b/include/my_global.h index 0fb11738758..f2ad3af0b6f 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -78,6 +78,15 @@ #endif #endif /* _WIN32... */ +#ifndef EMBEDDED_LIBRARY +#ifdef WITH_ROW_BASED_REPLICATION +#define HAVE_ROW_BASED_REPLICATION 1 +#endif +#ifdef WITH_NDB_BINLOG +#define HAVE_NDB_BINLOG 1 +#endif +#endif /* !EMBEDDED_LIBRARY */ + /* Some defines to avoid ifdefs in the code */ #ifndef NETWARE_YIELD #define NETWARE_YIELD @@ -172,6 +181,17 @@ #define HOT_DATA #endif +/* + now let's figure out if inline functions are supported + autoconf defines 'inline' to be empty, if not +*/ +#define inline_test_1(X) X ## 1 +#define inline_test_2(X) inline_test_1(X) +#if inline_test_2(inline) != 1 +#define HAVE_INLINE +#endif +#undef inline_test_2 +#undef inline_test_1 /* The following macros are used to control inlining a bit more than @@ -844,26 +864,36 @@ typedef void *gptr; /* Generic pointer */ #else typedef char *gptr; /* Generic pointer */ #endif -#ifndef HAVE_INT_8_16_32 -typedef signed char int8; /* Signed integer >= 8 bits */ -typedef short int16; /* Signed integer >= 16 bits */ -#endif #ifndef HAVE_UCHAR typedef unsigned char uchar; /* Short for unsigned char */ #endif -typedef unsigned char uint8; /* Short for unsigned integer >= 8 bits */ -typedef unsigned short uint16; /* Short for unsigned integer >= 16 bits */ +#ifndef HAVE_INT8 +typedef signed char int8; /* Signed integer >= 8 bits */ +#endif +#ifndef HAVE_UINT8 +typedef unsigned char uint8; /* Unsigned integer >= 8 bits */ +#endif +#ifndef HAVE_INT16 +typedef short int16; +#endif +#ifndef HAVE_UINT16 +typedef unsigned short uint16; +#endif #if SIZEOF_INT == 4 -#ifndef HAVE_INT_8_16_32 -typedef int int32; +#ifndef HAVE_INT32 +typedef int int32; +#endif +#ifndef HAVE_UINT32 +typedef unsigned int uint32; #endif -typedef unsigned int uint32; /* Short for unsigned integer >= 32 bits */ #elif SIZEOF_LONG == 4 -#ifndef HAVE_INT_8_16_32 -typedef long int32; +#ifndef HAVE_INT32 +typedef long int32; +#endif +#ifndef HAVE_UINT32 +typedef unsigned long uint32; #endif -typedef unsigned long uint32; /* Short for unsigned integer >= 32 bits */ #else #error "Neither int or long is of 4 bytes width" #endif @@ -880,6 +910,12 @@ typedef unsigned long ulonglong; /* ulong or unsigned long long */ typedef long longlong; #endif #endif +#ifndef HAVE_INT64 +typedef longlong int64; +#endif +#ifndef HAVE_UINT64 +typedef ulonglong uint64; +#endif #if defined(NO_CLIENT_LONG_LONG) typedef unsigned long my_ulonglong; diff --git a/include/my_net.h b/include/my_net.h index f953a832e6b..b26e525016b 100644 --- a/include/my_net.h +++ b/include/my_net.h @@ -44,7 +44,7 @@ C_MODE_START #include <sys/ioctl.h> #endif -#if !defined(MSDOS) && !defined(__WIN__) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__) && !defined(__NETWARE__) +#if !defined(__WIN__) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__) && !defined(__NETWARE__) #include <netinet/in_systm.h> #include <netinet/in.h> #include <netinet/ip.h> @@ -53,7 +53,7 @@ C_MODE_START #endif #endif -#if defined(MSDOS) || defined(__WIN__) +#if defined(__WIN__) #define O_NONBLOCK 1 /* For emulation of fcntl() */ #endif diff --git a/include/my_nosys.h b/include/my_nosys.h index 605906f0e07..41b919c1a72 100644 --- a/include/my_nosys.h +++ b/include/my_nosys.h @@ -27,9 +27,6 @@ extern "C" { #ifndef __MY_NOSYS__ #define __MY_NOSYS__ -#ifdef MSDOS -#include <io.h> /* Get prototypes for read()... */ -#endif #ifndef HAVE_STDLIB_H #include <malloc.h> #endif diff --git a/include/my_pthread.h b/include/my_pthread.h index acd1d2b558b..0cb38d29be8 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -226,12 +226,14 @@ int sigwait(sigset_t *setp, int *sigp); /* Use our implemention */ we want to make sure that no such flags are set. */ #if defined(HAVE_SIGACTION) && !defined(my_sigset) -#define my_sigset(A,B) do { struct sigaction s; sigset_t set; \ +#define my_sigset(A,B) do { struct sigaction s; sigset_t set; int rc; \ + DBUG_ASSERT((A) != 0); \ sigemptyset(&set); \ s.sa_handler = (B); \ s.sa_mask = set; \ s.sa_flags = 0; \ - sigaction((A), &s, (struct sigaction *) NULL); \ + rc= sigaction((A), &s, (struct sigaction *) NULL);\ + DBUG_ASSERT(rc == 0); \ } while (0) #elif defined(HAVE_SIGSET) && !defined(my_sigset) #define my_sigset(A,B) sigset((A),(B)) diff --git a/include/my_sys.h b/include/my_sys.h index 1540d820777..4ea7cecf0a1 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -75,6 +75,11 @@ extern int NEAR my_errno; /* Last error in mysys */ #define MY_CHECK_ERROR 1 /* Params to my_end; Check open-close */ #define MY_GIVE_INFO 2 /* Give time info about process*/ +#define MY_DONT_FREE_DBUG 4 /* Do not call DBUG_END() in my_end() */ + +#define MY_REMOVE_NONE 0 /* Params for modify_defaults_file */ +#define MY_REMOVE_OPTION 1 +#define MY_REMOVE_SECTION 2 #define ME_HIGHBYTE 8 /* Shift for colours */ #define ME_NOCUR 1 /* Don't use curses message */ @@ -196,22 +201,6 @@ extern void my_large_free(gptr ptr, myf my_flags); #define my_afree(PTR) my_free(PTR,MYF(MY_WME)) #endif /* HAVE_ALLOCA */ -#ifdef MSDOS -#ifdef __ZTC__ -void * __CDECL halloc(long count,size_t length); -void __CDECL hfree(void *ptr); -#endif -#if defined(USE_HALLOC) -#if defined(_VCM_) || defined(M_IC80386) -#undef USE_HALLOC -#endif -#endif -#ifdef USE_HALLOC -#define malloc(a) halloc((long) (a),1) -#define free(a) hfree(a) -#endif -#endif /* MSDOS */ - #ifndef errno /* did we already get it? */ #ifdef HAVE_ERRNO_AS_DEFINE #include <errno.h> /* errno is a define */ @@ -832,8 +821,9 @@ extern ulong crc32(ulong crc, const uchar *buf, uint len); extern uint my_set_max_open_files(uint files); void my_free_open_file_info(void); -ulonglong my_getsystime(void); -my_bool my_gethwaddr(uchar *to); +extern ulonglong my_getsystime(void); +extern my_bool my_gethwaddr(uchar *to); +extern int my_getncpus(); #ifdef HAVE_SYS_MMAN_H #include <sys/mman.h> diff --git a/include/my_time.h b/include/my_time.h index 2b0dc4ac6ff..df500dc501b 100644 --- a/include/my_time.h +++ b/include/my_time.h @@ -38,7 +38,10 @@ typedef long my_time_t; #define MY_TIME_T_MAX LONG_MAX #define MY_TIME_T_MIN LONG_MIN +/* two-digit years < this are 20..; >= this are 19.. */ #define YY_PART_YEAR 70 +/* apply above magic to years < this */ +#define YY_MAGIC_BELOW 200 /* Flags to str_to_datetime */ #define TIME_FUZZY_DATE 1 diff --git a/include/my_tree.h b/include/my_tree.h index 03dc9d5c829..e9746ca1b2c 100644 --- a/include/my_tree.h +++ b/include/my_tree.h @@ -40,19 +40,11 @@ typedef int (*tree_walk_action)(void *,element_count,void *); typedef enum { free_init, free_free, free_end } TREE_FREE; typedef void (*tree_element_free)(void*, TREE_FREE, void *); -#ifdef MSDOS -typedef struct st_tree_element { - struct st_tree_element *left,*right; - unsigned long count; - uchar colour; /* black is marked as 1 */ -} TREE_ELEMENT; -#else typedef struct st_tree_element { struct st_tree_element *left,*right; uint32 count:31, colour:1; /* black is marked as 1 */ } TREE_ELEMENT; -#endif /* MSDOS */ #define ELEMENT_CHILD(element, offs) (*(TREE_ELEMENT**)((char*)element + offs)) diff --git a/include/mysql.h b/include/mysql.h index 6217ce631b5..3a71e47f414 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -149,7 +149,8 @@ enum mysql_option MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT, MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION, MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, - MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT + MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, + MYSQL_OPT_SSL_VERIFY_SERVER_CERT }; struct st_mysql_options { @@ -164,6 +165,7 @@ struct st_mysql_options { char *ssl_ca; /* PEM CA file */ char *ssl_capath; /* PEM directory of CA-s? */ char *ssl_cipher; /* cipher to use */ + my_bool ssl_verify_server_cert; /* if to verify server cert */ char *shared_memory_base_name; unsigned long max_allowed_packet; my_bool use_ssl; /* if to use SSL or not */ diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h index ab5ca6e7be4..0cee54bffde 100644 --- a/include/mysql/plugin.h +++ b/include/mysql/plugin.h @@ -28,7 +28,7 @@ */ #define MYSQL_UDF_PLUGIN 0 /* User-defined function */ #define MYSQL_STORAGE_ENGINE_PLUGIN 1 /* Storage Engine */ -#define MYSQL_FTPARSER_PLUGIN 2 /* Full-text [pre]parser */ +#define MYSQL_FTPARSER_PLUGIN 2 /* Full-text parser plugin */ #define MYSQL_MAX_PLUGIN_TYPE_NUM 3 /* The number of plugin types */ /* @@ -95,12 +95,14 @@ struct st_mysql_plugin }; /************************************************************************* - API for Full-text [pre]parser plugin. (MYSQL_FTPARSER_PLUGIN) + API for Full-text parser plugin. (MYSQL_FTPARSER_PLUGIN) */ -#define MYSQL_FTPARSER_INTERFACE_VERSION 0x0000 +#define MYSQL_FTPARSER_INTERFACE_VERSION 0x0100 /* Parsing modes. Set in MYSQL_FTPARSER_PARAM::mode */ +enum enum_ftparser_mode +{ /* Fast and simple mode. This mode is used for indexing, and natural language queries. @@ -109,7 +111,7 @@ struct st_mysql_plugin index. Stopwords or too short/long words should not be returned. The 'boolean_info' argument of mysql_add_word() does not have to be set. */ -#define MYSQL_FTPARSER_SIMPLE_MODE 0 + MYSQL_FTPARSER_SIMPLE_MODE= 0, /* Parse with stopwords mode. This mode is used in boolean searches for @@ -120,7 +122,7 @@ struct st_mysql_plugin or long. The 'boolean_info' argument of mysql_add_word() does not have to be set. */ -#define MYSQL_FTPARSER_WITH_STOPWORDS 1 + MYSQL_FTPARSER_WITH_STOPWORDS= 1, /* Parse in boolean mode. This mode is used to parse a boolean query string. @@ -133,7 +135,8 @@ struct st_mysql_plugin MYSQL_FTPARSER_WITH_STOPWORDS mode, no word should be ignored. Instead, use FT_TOKEN_STOPWORD for the token type of such a word. */ -#define MYSQL_FTPARSER_FULL_BOOLEAN_INFO 2 + MYSQL_FTPARSER_FULL_BOOLEAN_INFO= 2 +}; /* Token types for boolean mode searching (used for the type member of @@ -198,6 +201,17 @@ typedef struct st_mysql_ftparser_boolean_info char *quot; } MYSQL_FTPARSER_BOOLEAN_INFO; +/* + The following flag means that buffer with a string (document, word) + may be overwritten by the caller before the end of the parsing (that is + before st_mysql_ftparser::deinit() call). If one needs the string + to survive between two successive calls of the parsing function, she + needs to save a copy of it. The flag may be set by MySQL before calling + st_mysql_ftparser::parse(), or it may be set by a plugin before calling + st_mysql_ftparser_param::mysql_parse() or + st_mysql_ftparser_param::mysql_add_word(). +*/ +#define MYSQL_FTFLAGS_NEED_COPY 1 /* An argument of the full-text parser plugin. This structure is @@ -209,22 +223,20 @@ typedef struct st_mysql_ftparser_boolean_info to invoke the MySQL default parser. If plugin's role is to extract textual data from .doc, .pdf or .xml content, it might extract plaintext from the content, and then pass the text to the default - MySQL parser to be parsed. When mysql_parser is called, its param - argument should be given as the mysql_ftparam value. + MySQL parser to be parsed. mysql_add_word: A server callback to add a new word. When parsing a document, the server sets this to point at a function that adds the word to MySQL full-text index. When parsing a search query, this function will add the new word to the list of words to search - for. When mysql_add_word is called, its param argument should be - given as the mysql_ftparam value. boolean_info can be NULL for all - cases except when mode is MYSQL_FTPARSER_FULL_BOOLEAN_INFO. + for. The boolean_info argument can be NULL for all cases except + when mode is MYSQL_FTPARSER_FULL_BOOLEAN_INFO. ftparser_state: A generic pointer. The plugin can set it to point to information to be used internally for its own purposes. - mysql_ftparam: This is set by the server. It is passed as the first - argument to the mysql_parse or mysql_add_word callback. The plugin + mysql_ftparam: This is set by the server. It is used by MySQL functions + called via mysql_parse() and mysql_add_word() callback. The plugin should not modify it. cs: Information about the character set of the document or query string. @@ -233,21 +245,26 @@ typedef struct st_mysql_ftparser_boolean_info length: Length of the document or query string, in bytes. + flags: See MYSQL_FTFLAGS_* constants above. + mode: The parsing mode. With boolean operators, with stopwords, or - nothing. See MYSQL_FTPARSER_* constants above. + nothing. See enum_ftparser_mode above. */ typedef struct st_mysql_ftparser_param { - int (*mysql_parse)(void *param, char *doc, int doc_len); - int (*mysql_add_word)(void *param, char *word, int word_len, + int (*mysql_parse)(struct st_mysql_ftparser_param *, + char *doc, int doc_len); + int (*mysql_add_word)(struct st_mysql_ftparser_param *, + char *word, int word_len, MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info); void *ftparser_state; void *mysql_ftparam; struct charset_info_st *cs; char *doc; int length; - int mode; + int flags; + enum enum_ftparser_mode mode; } MYSQL_FTPARSER_PARAM; /* @@ -265,5 +282,25 @@ struct st_mysql_ftparser int (*init)(MYSQL_FTPARSER_PARAM *param); int (*deinit)(MYSQL_FTPARSER_PARAM *param); }; + +/************************************************************************* + API for Storage Engine plugin. (MYSQL_STORAGE_ENGINE_PLUGIN) +*/ + +/* handlertons of different MySQL releases are incompatible */ +#define MYSQL_HANDLERTON_INTERFACE_VERSION (MYSQL_VERSION_ID << 8) + +/* + The real API is in the sql/handler.h + Here we define only the descriptor structure, that is referred from + st_mysql_plugin. +*/ + +struct st_mysql_storage_engine +{ + int interface_version; + struct handlerton *handlerton; +}; + #endif diff --git a/include/mysql_com.h b/include/mysql_com.h index 5a64e5ad68d..623aaf43783 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -424,17 +424,11 @@ char *octet2hex(char *to, const char *str, unsigned int len); /* end of password.c */ -char *get_tty_password(char *opt_message); +char *get_tty_password(const char *opt_message); const char *mysql_errno_to_sqlstate(unsigned int mysql_errno); /* Some other useful functions */ -my_bool my_init(void); -extern int modify_defaults_file(const char *file_location, const char *option, - const char *option_value, - const char *section_name, int remove_option); -int load_defaults(const char *conf_file, const char **groups, - int *argc, char ***argv); my_bool my_thread_init(void); void my_thread_end(void); diff --git a/include/sslopt-longopts.h b/include/sslopt-longopts.h index dc3b0922327..0435ddb815a 100644 --- a/include/sslopt-longopts.h +++ b/include/sslopt-longopts.h @@ -20,12 +20,6 @@ "Enable SSL for connection (automatically enabled with other flags). Disable with --skip-ssl.", (gptr*) &opt_use_ssl, (gptr*) &opt_use_ssl, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"ssl-key", OPT_SSL_KEY, "X509 key in PEM format (implies --ssl).", - (gptr*) &opt_ssl_key, (gptr*) &opt_ssl_key, 0, GET_STR, REQUIRED_ARG, - 0, 0, 0, 0, 0, 0}, - {"ssl-cert", OPT_SSL_CERT, "X509 cert in PEM format (implies --ssl).", - (gptr*) &opt_ssl_cert, (gptr*) &opt_ssl_cert, 0, GET_STR, REQUIRED_ARG, - 0, 0, 0, 0, 0, 0}, {"ssl-ca", OPT_SSL_CA, "CA file in PEM format (check OpenSSL docs, implies --ssl).", (gptr*) &opt_ssl_ca, (gptr*) &opt_ssl_ca, 0, GET_STR, REQUIRED_ARG, @@ -34,8 +28,19 @@ "CA directory (check OpenSSL docs, implies --ssl).", (gptr*) &opt_ssl_capath, (gptr*) &opt_ssl_capath, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"ssl-cert", OPT_SSL_CERT, "X509 cert in PEM format (implies --ssl).", + (gptr*) &opt_ssl_cert, (gptr*) &opt_ssl_cert, 0, GET_STR, REQUIRED_ARG, + 0, 0, 0, 0, 0, 0}, {"ssl-cipher", OPT_SSL_CIPHER, "SSL cipher to use (implies --ssl).", (gptr*) &opt_ssl_cipher, (gptr*) &opt_ssl_cipher, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - + {"ssl-key", OPT_SSL_KEY, "X509 key in PEM format (implies --ssl).", + (gptr*) &opt_ssl_key, (gptr*) &opt_ssl_key, 0, GET_STR, REQUIRED_ARG, + 0, 0, 0, 0, 0, 0}, +#ifdef MYSQL_CLIENT + {"ssl-verify-server-cert", OPT_SSL_VERIFY_SERVER_CERT, + "Verify server's \"Common Name\" in its cert against hostname used when connecting. This option is disabled by default.", + (gptr*) &opt_ssl_verify_server_cert, (gptr*) &opt_ssl_verify_server_cert, + 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, +#endif #endif /* HAVE_OPENSSL */ diff --git a/include/sslopt-vars.h b/include/sslopt-vars.h index 164cf541381..7204145fc28 100644 --- a/include/sslopt-vars.h +++ b/include/sslopt-vars.h @@ -15,10 +15,18 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifdef HAVE_OPENSSL -static my_bool opt_use_ssl = 0; -static char *opt_ssl_key = 0; -static char *opt_ssl_cert = 0; -static char *opt_ssl_ca = 0; -static char *opt_ssl_capath = 0; -static char *opt_ssl_cipher = 0; +#ifdef SSL_VARS_NOT_STATIC +#define SSL_STATIC +#else +#define SSL_STATIC static +#endif +SSL_STATIC my_bool opt_use_ssl = 0; +SSL_STATIC char *opt_ssl_ca = 0; +SSL_STATIC char *opt_ssl_capath = 0; +SSL_STATIC char *opt_ssl_cert = 0; +SSL_STATIC char *opt_ssl_cipher = 0; +SSL_STATIC char *opt_ssl_key = 0; +#ifdef MYSQL_CLIENT +SSL_STATIC my_bool opt_ssl_verify_server_cert= 0; +#endif #endif diff --git a/include/violite.h b/include/violite.h index de2ae5386c0..4837ade64b4 100644 --- a/include/violite.h +++ b/include/violite.h @@ -105,34 +105,23 @@ void vio_timeout(Vio *vio,uint which, uint timeout); #include <openssl/ssl.h> #include <openssl/err.h> -struct st_VioSSLAcceptorFd +struct st_VioSSLFd { SSL_CTX *ssl_context; - SSL_METHOD *ssl_method; - struct st_VioSSLAcceptorFd *session_id_context; }; -/* One copy for client */ -struct st_VioSSLConnectorFd -{ - SSL_CTX *ssl_context; - /* function pointers which are only once for SSL client */ - SSL_METHOD *ssl_method; -}; - -int sslaccept(struct st_VioSSLAcceptorFd*, Vio *, long timeout); -int sslconnect(struct st_VioSSLConnectorFd*, Vio *, long timeout); +int sslaccept(struct st_VioSSLFd*, Vio *, long timeout); +int sslconnect(struct st_VioSSLFd*, Vio *, long timeout); -struct st_VioSSLConnectorFd +struct st_VioSSLFd *new_VioSSLConnectorFd(const char *key_file, const char *cert_file, const char *ca_file, const char *ca_path, const char *cipher); -struct st_VioSSLAcceptorFd +struct st_VioSSLFd *new_VioSSLAcceptorFd(const char *key_file, const char *cert_file, const char *ca_file,const char *ca_path, const char *cipher); -Vio *new_VioSSL(struct st_VioSSLAcceptorFd *fd, Vio *sd, int state); -void free_vio_ssl_acceptor_fd(struct st_VioSSLAcceptorFd *fd); +void free_vio_ssl_acceptor_fd(struct st_VioSSLFd *fd); #endif /* HAVE_OPENSSL */ #ifdef HAVE_SMEM @@ -141,6 +130,8 @@ int vio_write_shared_memory(Vio *vio, const gptr buf, int size); int vio_close_shared_memory(Vio * vio); #endif +void vio_end(void); + #ifdef __cplusplus } #endif @@ -205,7 +196,9 @@ struct st_vio my_bool (*was_interrupted)(Vio*); int (*vioclose)(Vio*); void (*timeout)(Vio*, unsigned int which, unsigned int timeout); +#ifdef HAVE_OPENSSL void *ssl_arg; +#endif #ifdef HAVE_SMEM HANDLE handle_file_map; char *handle_map; diff --git a/libmysql/cmakelists.txt b/libmysql/CMakeLists.txt index 35795102082..35795102082 100644 --- a/libmysql/cmakelists.txt +++ b/libmysql/CMakeLists.txt diff --git a/libmysql/Makefile.am b/libmysql/Makefile.am index 9a6f418fa49..787ffc51de7 100644 --- a/libmysql/Makefile.am +++ b/libmysql/Makefile.am @@ -31,7 +31,7 @@ include $(srcdir)/Makefile.shared libmysqlclient_la_SOURCES = $(target_sources) libmysqlclient_la_LIBADD = $(target_libadd) $(yassl_las) libmysqlclient_la_LDFLAGS = $(target_ldflags) -EXTRA_DIST = Makefile.shared libmysql.def dll.c mytest.c cmakelists.txt +EXTRA_DIST = Makefile.shared libmysql.def dll.c mytest.c CMakeLists.txt noinst_HEADERS = client_settings.h # This is called from the toplevel makefile diff --git a/libmysql/get_password.c b/libmysql/get_password.c index a48cb6d7a6e..4c251677a66 100644 --- a/libmysql/get_password.c +++ b/libmysql/get_password.c @@ -75,7 +75,7 @@ #define _cputs(A) putstring(A) #endif -char *get_tty_password(char *opt_message) +char *get_tty_password(const char *opt_message) { char to[80]; char *pos=to,*end=to+sizeof(to)-1; @@ -159,7 +159,7 @@ static void get_password(char *to,uint length,int fd,bool echo) #endif /* ! HAVE_GETPASS */ -char *get_tty_password(char *opt_message) +char *get_tty_password(const char *opt_message) { #ifdef HAVE_GETPASS char *passbuff; diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index b750e9cc4b2..225b3926aa7 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -178,7 +178,7 @@ void STDCALL mysql_server_end() /* If library called my_init(), free memory allocated by it */ if (!org_my_init_done) { - my_end(0); + my_end(MY_DONT_FREE_DBUG); /* Remove TRACING, if enabled by mysql_debug() */ DBUG_POP(); } @@ -186,6 +186,7 @@ void STDCALL mysql_server_end() mysql_thread_end(); finish_client_errs(); free_charsets(); + vio_end(); mysql_client_init= org_my_init_done= 0; #ifdef EMBEDDED_SERVER if (stderror_file) diff --git a/libmysqld/cmakelists.txt b/libmysqld/CMakeLists.txt index 8bd0e0baa32..ff8ceda5c5b 100644 --- a/libmysqld/cmakelists.txt +++ b/libmysqld/CMakeLists.txt @@ -33,7 +33,7 @@ ADD_LIBRARY(mysqldemb emb_qcache.cc libmysqld.c lib_sql.cc ../sql/field_conv.cc ../sql/field.cc ../sql/filesort.cc ../sql/gstream.cc ../sql/ha_heap.cc ../sql/ha_myisam.cc ../sql/ha_myisammrg.cc ${mysql_se_ha_src} - ../sql/handler.cc ../sql/handlerton-win.cc ../sql/hash_filo.cc + ../sql/handler.cc ../sql/hash_filo.cc ../sql/hostname.cc ../sql/init.cc ../sql/item_buff.cc ../sql/item_cmpfunc.cc ../sql/item.cc ../sql/item_create.cc ../sql/item_func.cc ../sql/item_geofunc.cc ../sql/item_row.cc diff --git a/libmysqld/Makefile.am b/libmysqld/Makefile.am index 09176097be0..a3af2d43bd5 100644 --- a/libmysqld/Makefile.am +++ b/libmysqld/Makefile.am @@ -68,7 +68,7 @@ sqlsources = derror.cc field.cc field_conv.cc strfunc.cc filesort.cc \ spatial.cc gstream.cc sql_help.cc tztime.cc sql_cursor.cc \ sp_head.cc sp_pcontext.cc sp.cc sp_cache.cc sp_rcontext.cc \ parse_file.cc sql_view.cc sql_trigger.cc my_decimal.cc \ - event_executor.cc event.cc event_timed.cc \ + event_scheduler.cc event.cc event_timed.cc \ rpl_filter.cc sql_partition.cc sql_builtin.cc sql_plugin.cc \ sql_tablespace.cc \ rpl_injector.cc my_user.c partition_info.cc @@ -88,11 +88,11 @@ INC_LIB= $(top_builddir)/regex/libregex.a \ $(top_builddir)/dbug/libdbug.a \ $(top_builddir)/vio/libvio.a \ @mysql_plugin_libs@ \ - $(yassl_las) + $(yassl_inc_libs) if HAVE_YASSL -yassl_las = $(top_srcdir)/extra/yassl/src/libyassl.la \ - $(top_srcdir)/extra/yassl/taocrypt/src/libtaocrypt.la +yassl_inc_libs= $(top_srcdir)/extra/yassl/src/.libs/libyassl.a \ + $(top_srcdir)/extra/yassl/taocrypt/src/.libs/libtaocrypt.a endif # Storage engine specific compilation options @@ -135,12 +135,12 @@ else (for arc in ./libmysqld_int.a $(INC_LIB); do \ arpath=`echo $$arc|sed 's|[^/]*$$||'|sed 's|\.libs/$$||'`; \ artmp=`echo $$arc|sed 's|^.*/|tmp/lib-|'`; \ - for F in `$(AR) t $$arc`; do \ + for F in `$(AR) t $$arc | grep -v SYMDEF`; do \ if test -e "$$arpath/$$F" ; then echo "$$arpath/$$F"; else \ mkdir $$artmp; cd $$artmp > /dev/null; \ $(AR) x ../../$$arc; \ cd $$current_dir > /dev/null; \ - ls $$artmp/*; \ + ls $$artmp/* | grep -v SYMDEF; \ continue 2; fi; done; \ done; echo $(libmysqld_a_DEPENDENCIES) ) | sort -u | xargs $(AR) cq libmysqld.a ; \ $(RANLIB) libmysqld.a ; \ @@ -167,10 +167,13 @@ link_sources: rm -f $$f; \ @LN_CP_F@ $(top_srcdir)/libmysql/$$f $$f; \ done; \ - for f in $(sqlstoragesources); do \ - rm -f $$f; \ - @LN_CP_F@ `find $(srcdir)/../sql -name $$f` $$f; \ - done; \ + if test -n "$(sqlstoragesources)" ; \ + then \ + for f in "$(sqlstoragesources)"; do \ + rm -f "$$f"; \ + @LN_CP_F@ `find $(srcdir)/../sql -name "$$f"` "$$f"; \ + done; \ + fi; \ rm -f client_settings.h; \ @LN_CP_F@ $(top_srcdir)/libmysql/client_settings.h client_settings.h diff --git a/libmysqld/examples/cmakelists.txt b/libmysqld/examples/CMakeLists.txt index 5c58264a7e7..5c58264a7e7 100644 --- a/libmysqld/examples/cmakelists.txt +++ b/libmysqld/examples/CMakeLists.txt diff --git a/mysql-test/extra/binlog_tests/binlog.test b/mysql-test/extra/binlog_tests/binlog.test index ff43debf967..6f7990893f0 100644 --- a/mysql-test/extra/binlog_tests/binlog.test +++ b/mysql-test/extra/binlog_tests/binlog.test @@ -22,7 +22,7 @@ insert t2 values (5); commit; # first COMMIT must be Query_log_event, second - Xid_log_event --replace_column 2 # 5 # ---replace_regex /table_id: [0-9]+/table_id: #/ +--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\// show binlog events from 102; drop table t1,t2; @@ -44,8 +44,8 @@ while ($1) commit; drop table t1; --replace_column 2 # 5 # ---replace_regex /table_id: [0-9]+/table_id: #/ +--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\// show binlog events in 'master-bin.000001' from 102; --replace_column 2 # 5 # ---replace_regex /table_id: [0-9]+/table_id: #/ +--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\// show binlog events in 'master-bin.000002' from 102; diff --git a/mysql-test/extra/binlog_tests/blackhole.test b/mysql-test/extra/binlog_tests/blackhole.test index 71aec90e9a0..97243015aba 100644 --- a/mysql-test/extra/binlog_tests/blackhole.test +++ b/mysql-test/extra/binlog_tests/blackhole.test @@ -147,3 +147,15 @@ set autocommit=1; --replace_column 2 # 5 # --replace_regex /table_id: [0-9]+/table_id: #/ show binlog events; + +# +# BUG#10952 - alter table ... lost data without errors and warnings +# +drop table if exists t1; +create table t1 (c char(20)) engine=MyISAM; +insert into t1 values ("Monty"),("WAX"),("Walrus"); +--error 1031 +alter table t1 engine=blackhole; +drop table t1; + +# End of 5.0 tests diff --git a/mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test b/mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test index 47e1ffb23c7..de488e1e3e4 100644 --- a/mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test +++ b/mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test @@ -30,7 +30,7 @@ insert into t2 select * from t1; commit; --replace_column 5 # ---replace_regex /table_id: [0-9]+/table_id: #/ +--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\// show binlog events from 102; delete from t1; @@ -44,7 +44,7 @@ insert into t2 select * from t1; rollback; --replace_column 5 # ---replace_regex /table_id: [0-9]+/table_id: #/ +--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\// show binlog events from 102; delete from t1; @@ -60,7 +60,7 @@ rollback to savepoint my_savepoint; commit; --replace_column 5 # ---replace_regex /table_id: [0-9]+/table_id: #/ +--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\// show binlog events from 102; delete from t1; @@ -78,7 +78,7 @@ commit; select a from t1 order by a; # check that savepoints work :) --replace_column 5 # ---replace_regex /table_id: [0-9]+/table_id: #/ +--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\// show binlog events from 102; # and when ROLLBACK is not explicit? @@ -100,7 +100,7 @@ connection con2; # logging has been done, we use a user lock. select get_lock("a",10); --replace_column 5 # ---replace_regex /table_id: [0-9]+/table_id: #/ +--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\// show binlog events from 102; # and when not in a transact1on? @@ -112,7 +112,7 @@ insert into t1 values(9); insert into t2 select * from t1; --replace_column 5 # ---replace_regex /table_id: [0-9]+/table_id: #/ +--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\// show binlog events from 102; # Check that when the query updat1ng the MyISAM table is the first in the @@ -125,13 +125,13 @@ insert into t1 values(10); # first make t1 non-empty begin; insert into t2 select * from t1; --replace_column 5 # ---replace_regex /table_id: [0-9]+/table_id: #/ +--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\// show binlog events from 102; insert into t1 values(11); commit; --replace_column 5 # ---replace_regex /table_id: [0-9]+/table_id: #/ +--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\// show binlog events from 102; @@ -150,7 +150,7 @@ insert into t2 select * from t1; commit; --replace_column 5 # ---replace_regex /table_id: [0-9]+/table_id: #/ +--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\// show binlog events from 102; delete from t1; @@ -163,7 +163,7 @@ insert into t2 select * from t1; rollback; --replace_column 5 # ---replace_regex /table_id: [0-9]+/table_id: #/ +--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\// show binlog events from 102; delete from t1; @@ -179,7 +179,7 @@ rollback to savepoint my_savepoint; commit; --replace_column 5 # ---replace_regex /table_id: [0-9]+/table_id: #/ +--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\// show binlog events from 102; delete from t1; @@ -197,7 +197,7 @@ commit; select a from t1 order by a; # check that savepoints work :) --replace_column 5 # ---replace_regex /table_id: [0-9]+/table_id: #/ +--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\// show binlog events from 102; # Test for BUG#5714, where a MyISAM update in the transaction used to @@ -258,7 +258,7 @@ disconnect con2; connection con3; select get_lock("lock1",60); --replace_column 5 # ---replace_regex /table_id: [0-9]+/table_id: #/ +--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\// show binlog events from 102; do release_lock("lock1"); drop table t0,t2; diff --git a/mysql-test/extra/rpl_tests/rpl_flsh_tbls.test b/mysql-test/extra/rpl_tests/rpl_flsh_tbls.test index cfa943228fa..7a097fd1eae 100644 --- a/mysql-test/extra/rpl_tests/rpl_flsh_tbls.test +++ b/mysql-test/extra/rpl_tests/rpl_flsh_tbls.test @@ -3,6 +3,8 @@ # RENAME TABLE work with MERGE tables on the slave. # Test of FLUSH NO_WRITE_TO_BINLOG by the way. # + + -- source include/master-slave.inc create table t1 (a int); diff --git a/mysql-test/extra/rpl_tests/rpl_insert_id.test b/mysql-test/extra/rpl_tests/rpl_insert_id.test index 304fade7e1d..68e39c54381 100644 --- a/mysql-test/extra/rpl_tests/rpl_insert_id.test +++ b/mysql-test/extra/rpl_tests/rpl_insert_id.test @@ -156,3 +156,5 @@ drop function bug15728_insert; drop table t1, t2; # End of 5.0 tests + +sync_slave_with_master; diff --git a/mysql-test/extra/rpl_tests/rpl_log.test b/mysql-test/extra/rpl_tests/rpl_log.test index 116bdd1028e..20ee7cd0d8f 100644 --- a/mysql-test/extra/rpl_tests/rpl_log.test +++ b/mysql-test/extra/rpl_tests/rpl_log.test @@ -77,11 +77,8 @@ connection slave; # to go into the relay log (the master always sends a fake one when replication # starts). start slave; -# -# This is timing out in pushbuild and should be changed to use -# wait_slave_status.inc -# -sleep 2; +let $result_pattern= '%127.0.0.1%root%master-bin.000002%slave-relay-bin.000005%Yes%Yes%0%0%None%'; +--source include/wait_slave_status.inc sync_with_master; flush logs; stop slave; diff --git a/mysql-test/lib/init_db.sql b/mysql-test/lib/init_db.sql index a7079b0ac33..a5736ed4b9b 100644 --- a/mysql-test/lib/init_db.sql +++ b/mysql-test/lib/init_db.sql @@ -631,7 +631,7 @@ CREATE TABLE event ( 'HIGH_NOT_PRECEDENCE' ) DEFAULT '' NOT NULL, comment char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', - PRIMARY KEY (definer, db, name) + PRIMARY KEY (db, name) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT 'Events'; CREATE DATABASE IF NOT EXISTS cluster; diff --git a/mysql-test/lib/mtr_misc.pl b/mysql-test/lib/mtr_misc.pl index b5a2e5a4a68..bc44c440c32 100644 --- a/mysql-test/lib/mtr_misc.pl +++ b/mysql-test/lib/mtr_misc.pl @@ -108,7 +108,14 @@ sub mtr_exe_exists (@) { map {$_.= ".exe"} @path if $::glob_win32; foreach my $path ( @path ) { - return $path if -x $path; + if($::glob_win32) + { + return $path if -f $path; + } + else + { + return $path if -x $path; + } } if ( @path == 1 ) { diff --git a/mysql-test/lib/mtr_process.pl b/mysql-test/lib/mtr_process.pl index a3fb7ec0183..d6fb9382b90 100644 --- a/mysql-test/lib/mtr_process.pl +++ b/mysql-test/lib/mtr_process.pl @@ -20,6 +20,7 @@ sub mtr_record_dead_children (); sub mtr_exit ($); sub sleep_until_file_created ($$$); sub mtr_kill_processes ($); +sub mtr_kill_process ($$$$); # static in C sub spawn_impl ($$$$$$$$); @@ -875,6 +876,25 @@ sub mtr_kill_processes ($) { } } + +sub mtr_kill_process ($$$$) { + my $pid= shift; + my $signal= shift; + my $retries= shift; + my $timeout= shift; + + while (1) + { + kill($signal, $pid); + + last unless kill (0, $pid) and $retries--; + + mtr_debug("Sleep $timeout second waiting for processes to die"); + + sleep($timeout); + } +} + ############################################################################## # # When we exit, we kill off all children diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 120ae00ca86..7e5d6947b43 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -134,7 +134,6 @@ our $glob_win32= 0; # OS and native Win32 executables our $glob_win32_perl= 0; # ActiveState Win32 Perl our $glob_cygwin_perl= 0; # Cygwin Perl our $glob_cygwin_shell= undef; -our $glob_use_libtool= 1; our $glob_mysql_test_dir= undef; our $glob_mysql_bench_dir= undef; our $glob_hostname= undef; @@ -192,6 +191,7 @@ our $exe_slave_mysqld; our $exe_im; our $exe_my_print_defaults; our $lib_udf_example; +our $exe_libtool; our $opt_bench= 0; our $opt_small_bench= 0; @@ -390,7 +390,6 @@ sub main () { check_ndbcluster_support(); # We check whether to actually use it later check_ssl_support(); - check_running_as_root(); environment_setup(); signal_setup(); @@ -458,12 +457,6 @@ sub initial_setup () { $glob_cygwin_perl= ($^O eq "cygwin"); $glob_win32= ($glob_win32_perl or $glob_cygwin_perl); - # Use libtool on all platforms except windows - if ( $glob_win32 ) - { - $glob_use_libtool= 0; - } - # We require that we are in the "mysql-test" directory # to run mysql-test-run @@ -936,6 +929,7 @@ sub command_line_setup () { path_err => "$opt_vardir/log/im.err", path_log => "$opt_vardir/log/im.log", path_pid => "$opt_vardir/run/im.pid", + path_angel_pid => "$opt_vardir/run/im.angel.pid", path_sock => "$sockdir/im.sock", port => $im_port, start_timeout => $master->[0]->{'start_timeout'}, @@ -1013,6 +1007,21 @@ sub snapshot_setup () { sub executable_setup () { + # + # Check if libtool is available in this distribution/clone + # we need it when valgrinding or debugging non installed binary + # Otherwise valgrind will valgrind the libtool wrapper or bash + # and gdb will not find the real executable to debug + # + if ( -x "../libtool") + { + $exe_libtool= "../libtool"; + if ($opt_valgrind or $glob_debugger) + { + mtr_report("Using \"$exe_libtool\" when running valgrind or debugger"); + } + } + if ( $opt_source_dist ) { if ( $glob_win32 ) @@ -1163,6 +1172,8 @@ sub executable_setup () { sub environment_setup () { + umask(022); + # -------------------------------------------------------------------------- # We might not use a standard installation directory, like /usr/lib. # Set LD_LIBRARY_PATH to make sure we find our installed libraries. @@ -1211,8 +1222,12 @@ sub environment_setup () { $ENV{'NDBCLUSTER_PORT_SLAVE'}=$opt_ndbcluster_port_slave; $ENV{'NDB_STATUS_OK'}= "YES"; + $ENV{'IM_EXE'}= $exe_im; $ENV{'IM_PATH_PID'}= $instance_manager->{path_pid}; + $ENV{'IM_PATH_ANGEL_PID'}= $instance_manager->{path_angel_pid}; $ENV{'IM_PORT'}= $instance_manager->{port}; + $ENV{'IM_DEFAULTS_PATH'}= $instance_manager->{defaults_file}; + $ENV{'IM_PASSWORD_PATH'}= $instance_manager->{password_file}; $ENV{'IM_MYSQLD1_SOCK'}= $instance_manager->{instances}->[0]->{path_sock}; $ENV{'IM_MYSQLD1_PORT'}= $instance_manager->{instances}->[0]->{port}; @@ -1375,7 +1390,7 @@ sub kill_and_cleanup () { sub check_running_as_root () { # Check if running as root # i.e a file can be read regardless what mode we set it to - my $test_file= "test_running_as_root.txt"; + my $test_file= "$opt_vardir/test_running_as_root.txt"; mtr_tofile($test_file, "MySQL"); chmod(oct("0000"), $test_file); @@ -1821,6 +1836,7 @@ sub initialize_servers () { save_installed_db(); } } + check_running_as_root(); } } @@ -1991,6 +2007,7 @@ sub im_create_defaults_file($) { [manager] pid-file = $instance_manager->{path_pid} +angel-pid-file = $instance_manager->{path_angel_pid} socket = $instance_manager->{path_sock} port = $instance_manager->{port} password-file = $instance_manager->{password_file} @@ -2015,7 +2032,7 @@ log-slow-queries = $instance->{path_datadir}/mysqld$server_id.slow.log language = $path_language character-sets-dir = $path_charsetsdir basedir = $path_my_basedir -server_id =$server_id +server_id = $server_id skip-stack-trace skip-innodb skip-bdb @@ -2589,7 +2606,6 @@ sub mysqld_arguments ($$$$$$) { mtr_add_arg($args, "%s--character-sets-dir=%s", $prefix, $path_charsetsdir); mtr_add_arg($args, "%s--core", $prefix); mtr_add_arg($args, "%s--log-bin-trust-function-creators", $prefix); - mtr_add_arg($args, "%s--loose-binlog-show-xid=0", $prefix); mtr_add_arg($args, "%s--default-character-set=latin1", $prefix); mtr_add_arg($args, "%s--language=%s", $prefix, $path_language); mtr_add_arg($args, "%s--tmpdir=$opt_tmpdir", $prefix); @@ -2735,7 +2751,6 @@ sub mysqld_arguments ($$$$$$) { mtr_add_arg($args, "%s--sort_buffer=256K", $prefix); mtr_add_arg($args, "%s--max_heap_table_size=1M", $prefix); mtr_add_arg($args, "%s--log-bin-trust-function-creators", $prefix); - mtr_add_arg($args, "%s--loose-binlog-show-xid=0", $prefix); if ( $opt_ssl_supported ) { @@ -2870,6 +2885,15 @@ sub mysqld_start ($$$$$) { $exe= undef; } + if ($exe_libtool and $opt_valgrind) + { + # Add "libtool --mode-execute" + # if running in valgrind(to avoid valgrinding bash) + unshift(@$args, "--mode=execute", $exe); + $exe= $exe_libtool; + } + + if ( $type eq 'master' ) { if ( ! defined $exe or @@ -3044,6 +3068,18 @@ sub im_start($$) { sub im_stop($) { my $instance_manager = shift; + # Obtain mysqld-process pids before we start stopping IM (it can delete pid + # files). + + my @mysqld_pids = (); + my $instances = $instance_manager->{'instances'}; + + push(@mysqld_pids, mtr_get_pid_from_file($instances->[0]->{'path_pid'})) + if -r $instances->[0]->{'path_pid'}; + + push(@mysqld_pids, mtr_get_pid_from_file($instances->[1]->{'path_pid'})) + if -r $instances->[1]->{'path_pid'}; + # Re-read pid from the file, since during tests Instance Manager could have # been restarted, so its pid could have been changed. @@ -3051,34 +3087,79 @@ sub im_stop($) { mtr_get_pid_from_file($instance_manager->{'path_pid'}) if -f $instance_manager->{'path_pid'}; + if (-f $instance_manager->{'path_angel_pid'}) + { + $instance_manager->{'angel_pid'} = + mtr_get_pid_from_file($instance_manager->{'path_angel_pid'}) + } + else + { + $instance_manager->{'angel_pid'} = undef; + } + # Inspired from mtr_stop_mysqld_servers(). start_reap_all(); - # Create list of pids. We should stop Instance Manager and all started - # mysqld-instances. Some of them may be nonguarded, so IM will not stop them - # on shutdown. + # Try graceful shutdown. - my @pids = ( $instance_manager->{'pid'} ); - my $instances = $instance_manager->{'instances'}; + mtr_kill_process($instance_manager->{'pid'}, 'TERM', 10, 1); - if ( -r $instances->[0]->{'path_pid'} ) + # Check that all processes died. + + my $clean_shutdown= 0; + + while (1) { - push(@pids, mtr_get_pid_from_file($instances->[0]->{'path_pid'})); + last if kill (0, $instance_manager->{'pid'}); + + last if (defined $instance_manager->{'angel_pid'}) && + kill (0, $instance_manager->{'angel_pid'}); + + foreach my $pid (@mysqld_pids) + { + last if kill (0, $pid); + } + + $clean_shutdown= 1; + last; } - if ( -r $instances->[1]->{'path_pid'} ) + # Kill leftovers (the order is important). + + unless ($clean_shutdown) { - push(@pids, mtr_get_pid_from_file($instances->[1]->{'path_pid'})); - } + mtr_kill_process($instance_manager->{'angel_pid'}, 'KILL', 10, 1) + if defined $instance_manager->{'angel_pid'}; + + mtr_kill_process($instance_manager->{'pid'}, 'KILL', 10, 1); + + # Shutdown managed mysqld-processes. Some of them may be nonguarded, so IM + # will not stop them on shutdown. So, we should firstly try to end them + # legally. + + mtr_kill_processes(\@mysqld_pids); - # Kill processes. + # Complain in error log so that a warning will be shown. + + my $errlog= "$opt_vardir/log/mysql-test-run.pl.err"; + + open (ERRLOG, ">>$errlog") || + mtr_error("Can not open error log ($errlog)"); + + my $ts= localtime(); + print ERRLOG + "Warning: [$ts] Instance Manager did not shutdown gracefully.\n"; + + close ERRLOG; + } - mtr_kill_processes(\@pids); + # That's all. stop_reap_all(); $instance_manager->{'pid'} = undef; + $instance_manager->{'angel_pid'} = undef; } @@ -3201,7 +3282,7 @@ sub run_mysqltest ($) { } my $cmdline_mysql= - "$exe_mysql --host=localhost --user=root --password= " . + "$exe_mysql --no-defaults --host=localhost --user=root --password= " . "--port=$master->[0]->{'path_myport'} " . "--socket=$master->[0]->{'path_mysock'}"; @@ -3404,12 +3485,12 @@ sub run_mysqltest ($) { debugger_arguments(\$args, \$exe, "client"); } - if ($glob_use_libtool and $opt_valgrind) + if ($exe_libtool and $opt_valgrind) { # Add "libtool --mode-execute" before the test to execute # if running in valgrind(to avoid valgrinding bash) unshift(@$args, "--mode=execute", $exe); - $exe= "libtool"; + $exe= $exe_libtool; } if ( $opt_check_testcases ) @@ -3479,9 +3560,9 @@ sub gdb_arguments { mtr_add_arg($$args, "$type"); mtr_add_arg($$args, "-e"); - if ( $glob_use_libtool ) + if ( $exe_libtool ) { - mtr_add_arg($$args, "libtool"); + mtr_add_arg($$args, $exe_libtool); mtr_add_arg($$args, "--mode=execute"); } @@ -3541,9 +3622,9 @@ sub ddd_arguments { my $save_exe= $$exe; $$args= []; - if ( $glob_use_libtool ) + if ( $exe_libtool ) { - $$exe= "libtool"; + $$exe= $exe_libtool; mtr_add_arg($$args, "--mode=execute"); mtr_add_arg($$args, "ddd"); } @@ -3564,6 +3645,8 @@ sub debugger_arguments { my $exe= shift; my $debugger= $opt_debugger || $opt_client_debugger; + # FIXME Need to change the below "eq"'s to + # "case unsensitive string contains" if ( $debugger eq "vcexpress" or $debugger eq "vc") { # vc[express] /debugexe exe arg1 .. argn diff --git a/mysql-test/mysql-test-run.sh b/mysql-test/mysql-test-run.sh index c018181b929..4cbb1bece9c 100644 --- a/mysql-test/mysql-test-run.sh +++ b/mysql-test/mysql-test-run.sh @@ -1350,7 +1350,6 @@ start_master() --innodb_data_file_path=ibdata1:128M:autoextend \ --open-files-limit=1024 \ --log-bin-trust-function-creators \ - --loose-binlog-show-xid=0 \ $MASTER_40_ARGS \ $SMALL_SERVER \ $MASTER_MYSQLD_BINLOG_OPT \ @@ -1374,7 +1373,6 @@ start_master() --language=$LANGUAGE \ --innodb_data_file_path=ibdata1:128M:autoextend \ --log-bin-trust-function-creators \ - --loose-binlog-show-xid=0 \ $MASTER_40_ARGS \ $SMALL_SERVER \ $MASTER_MYSQLD_BINLOG_OPT \ @@ -1547,7 +1545,6 @@ start_slave() --master-retry-count=10 \ -O slave_net_timeout=10 \ --log-bin-trust-function-creators \ - --loose-binlog-show-xid=0 \ $SMALL_SERVER \ $SLAVE_MYSQLD_BINLOG_OPT \ $EXTRA_SLAVE_MYSQLD_OPT $EXTRA_SLAVE_OPT \ diff --git a/mysql-test/r/alter_table.result b/mysql-test/r/alter_table.result index 1ad9cd6d1e9..f4332ea9888 100644 --- a/mysql-test/r/alter_table.result +++ b/mysql-test/r/alter_table.result @@ -647,3 +647,13 @@ SELECT LENGTH(s) FROM t1; LENGTH(s) 10 DROP TABLE t1; +CREATE TABLE t1 (v VARCHAR(3), b INT); +INSERT INTO t1 VALUES ('abc', 5); +SELECT * FROM t1; +v b +abc 5 +ALTER TABLE t1 MODIFY COLUMN v VARCHAR(4); +SELECT * FROM t1; +v b +abc 5 +DROP TABLE t1; diff --git a/mysql-test/r/ansi.result b/mysql-test/r/ansi.result index 00a526df8ea..527748e00d5 100644 --- a/mysql-test/r/ansi.result +++ b/mysql-test/r/ansi.result @@ -2,7 +2,7 @@ drop table if exists t1; set sql_mode="MySQL40"; select @@sql_mode; @@sql_mode -NO_FIELD_OPTIONS,MYSQL40,HIGH_NOT_PRECEDENCE +MYSQL40,HIGH_NOT_PRECEDENCE set @@sql_mode="ANSI"; select @@sql_mode; @@sql_mode @@ -17,3 +17,32 @@ SELECT id FROM t1 GROUP BY id2; id drop table t1; SET @@SQL_MODE=""; +CREATE TABLE t1 (i int auto_increment NOT NULL, PRIMARY KEY (i)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `i` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`i`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SET @@SQL_MODE="MYSQL323"; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `i` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`i`) +) TYPE=MyISAM +SET @@SQL_MODE="MYSQL40"; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `i` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`i`) +) TYPE=MyISAM +SET @@SQL_MODE="NO_FIELD_OPTIONS"; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `i` int(11) NOT NULL, + PRIMARY KEY (`i`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; diff --git a/mysql-test/r/archive.result b/mysql-test/r/archive.result index 09813458069..19cb0c9768f 100644 --- a/mysql-test/r/archive.result +++ b/mysql-test/r/archive.result @@ -1,4 +1,4 @@ -drop table if exists t1,t2; +drop table if exists t1,t2,t3; CREATE TABLE t1 ( Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL, Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL diff --git a/mysql-test/r/auto_increment.result b/mysql-test/r/auto_increment.result index 2fe4db859b5..d9e9392f618 100644 --- a/mysql-test/r/auto_increment.result +++ b/mysql-test/r/auto_increment.result @@ -355,6 +355,30 @@ CHECK TABLE t1; Table Op Msg_type Msg_text test.t1 check status OK DROP TABLE IF EXISTS t1; +CREATE TABLE `t1` ( +t1_name VARCHAR(255) DEFAULT NULL, +t1_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, +KEY (t1_name), +PRIMARY KEY (t1_id) +) AUTO_INCREMENT = 1000; +INSERT INTO t1 (t1_name) VALUES('MySQL'); +INSERT INTO t1 (t1_name) VALUES('MySQL'); +INSERT INTO t1 (t1_name) VALUES('MySQL'); +SELECT * from t1; +t1_name t1_id +MySQL 1000 +MySQL 1001 +MySQL 1002 +SHOW CREATE TABLE `t1`; +Table Create Table +t1 CREATE TABLE `t1` ( + `t1_name` varchar(255) DEFAULT NULL, + `t1_id` int(10) unsigned NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`t1_id`), + KEY `t1_name` (`t1_name`) +) ENGINE=MyISAM AUTO_INCREMENT=1003 DEFAULT CHARSET=latin1 +DROP TABLE `t1`; +End of 4.1 tests CREATE TABLE t1 ( `a` int(11) NOT NULL auto_increment, `b` int(11) default NULL,PRIMARY KEY (`a`),UNIQUE KEY `b` (`b`)); insert into t1 (b) values (1); replace into t1 (b) values (2), (1), (3); @@ -394,3 +418,9 @@ a val 2 1 3 1 drop table t1; +CREATE TABLE t1 (t1 INT(10) PRIMARY KEY, t2 INT(10)); +INSERT INTO t1 VALUES(0, 0); +INSERT INTO t1 VALUES(1, 1); +ALTER TABLE t1 CHANGE t1 t1 INT(10) auto_increment; +ERROR 23000: ALTER TABLE causes auto_increment resequencing, resulting in duplicate entry '1' for key 'PRIMARY' +DROP TABLE t1; diff --git a/mysql-test/r/binlog_row_blackhole.result b/mysql-test/r/binlog_row_blackhole.result index aa5c943de00..42bf7a10888 100644 --- a/mysql-test/r/binlog_row_blackhole.result +++ b/mysql-test/r/binlog_row_blackhole.result @@ -156,3 +156,9 @@ master-bin.000001 # Query 1 # use `test`; BEGIN master-bin.000001 # Table_map 1 # table_id: # (test.t1) master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F master-bin.000001 # Query 1 # use `test`; COMMIT +drop table if exists t1; +create table t1 (c char(20)) engine=MyISAM; +insert into t1 values ("Monty"),("WAX"),("Walrus"); +alter table t1 engine=blackhole; +ERROR HY000: Table storage engine for 't1' doesn't have this option +drop table t1; diff --git a/mysql-test/r/binlog_stm_blackhole.result b/mysql-test/r/binlog_stm_blackhole.result index 90eabc6fa66..64569993a7b 100644 --- a/mysql-test/r/binlog_stm_blackhole.result +++ b/mysql-test/r/binlog_stm_blackhole.result @@ -149,3 +149,9 @@ master-bin.000001 # Query 1 # use `test`; create table t1 (a int) engine=blackho master-bin.000001 # Query 1 # use `test`; BEGIN master-bin.000001 # Query 1 # use `test`; insert into t1 values(1) master-bin.000001 # Query 1 # use `test`; COMMIT +drop table if exists t1; +create table t1 (c char(20)) engine=MyISAM; +insert into t1 values ("Monty"),("WAX"),("Walrus"); +alter table t1 engine=blackhole; +ERROR HY000: Table storage engine for 't1' doesn't have this option +drop table t1; diff --git a/mysql-test/r/case.result b/mysql-test/r/case.result index 9d2706f64fa..1d2041432fe 100644 --- a/mysql-test/r/case.result +++ b/mysql-test/r/case.result @@ -103,8 +103,8 @@ t1 CREATE TABLE `t1` ( `c2` varchar(1) CHARACTER SET latin1 COLLATE latin1_danish_ci NOT NULL DEFAULT '', `c3` varbinary(1) NOT NULL DEFAULT '', `c4` varbinary(1) NOT NULL DEFAULT '', - `c5` varbinary(3) NOT NULL DEFAULT '', - `c6` varbinary(3) NOT NULL DEFAULT '', + `c5` varbinary(4) NOT NULL DEFAULT '', + `c6` varbinary(4) NOT NULL DEFAULT '', `c7` decimal(2,1) NOT NULL DEFAULT '0.0', `c8` decimal(2,1) NOT NULL DEFAULT '0.0', `c9` decimal(2,1) DEFAULT NULL, @@ -152,11 +152,11 @@ SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `COALESCE(1)` int(1) NOT NULL DEFAULT '0', - `COALESCE(1.0)` decimal(2,1) unsigned NOT NULL DEFAULT '0.0', + `COALESCE(1.0)` decimal(2,1) NOT NULL DEFAULT '0.0', `COALESCE('a')` varchar(1) NOT NULL DEFAULT '', `COALESCE(1,1.0)` decimal(2,1) NOT NULL DEFAULT '0.0', `COALESCE(1,'1')` varbinary(1) NOT NULL DEFAULT '', - `COALESCE(1.1,'1')` varbinary(3) NOT NULL DEFAULT '', + `COALESCE(1.1,'1')` varbinary(4) NOT NULL DEFAULT '', `COALESCE('a' COLLATE latin1_bin,'b')` varchar(1) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '' ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t1; diff --git a/mysql-test/r/contributors.result b/mysql-test/r/contributors.result new file mode 100644 index 00000000000..5739c2244c3 --- /dev/null +++ b/mysql-test/r/contributors.result @@ -0,0 +1,5 @@ +SHOW CONTRIBUTORS; +Name Location Comment +Ronald Bradford Brisbane, Australia EFF contribution for UC2006 Auction +Sheeri Kritzer Boston, Mass. USA EFF contribution for UC2006 Auction +Mark Shuttleworth London, UK. EFF contribution for UC2006 Auction diff --git a/mysql-test/r/ctype_sjis.result b/mysql-test/r/ctype_sjis.result index eaea2e7479a..1c9d540d574 100644 --- a/mysql-test/r/ctype_sjis.result +++ b/mysql-test/r/ctype_sjis.result @@ -172,6 +172,6 @@ c2h ab_def drop table t1; SET NAMES sjis; -SELECT HEX('²“‘@\Œ\') FROM DUAL; -HEX('²“‘@_Œ\') +SELECT HEX('²“‘@Œ\') FROM DUAL; +HEX('²“‘@Œ\') 8DB2939181408C5C diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index 44f6945238c..1246c6f3d5d 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -412,7 +412,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `c` char(10) CHARACTER SET utf8 DEFAULT NULL, - UNIQUE KEY `a` USING HASH (`c`(1)) + UNIQUE KEY `a` (`c`(1)) USING HASH ) ENGINE=MEMORY DEFAULT CHARSET=latin1 insert into t1 values ('a'),('b'),('c'),('d'),('e'),('f'); insert into t1 values ('aa'); @@ -448,7 +448,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `c` char(10) CHARACTER SET utf8 DEFAULT NULL, - UNIQUE KEY `a` USING BTREE (`c`(1)) + UNIQUE KEY `a` (`c`(1)) USING BTREE ) ENGINE=MEMORY DEFAULT CHARSET=latin1 insert into t1 values ('a'),('b'),('c'),('d'),('e'),('f'); insert into t1 values ('aa'); @@ -570,7 +570,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `c` char(10) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, - UNIQUE KEY `a` USING HASH (`c`(1)) + UNIQUE KEY `a` (`c`(1)) USING HASH ) ENGINE=MEMORY DEFAULT CHARSET=latin1 insert into t1 values ('a'),('b'),('c'),('d'),('e'),('f'); insert into t1 values ('aa'); @@ -606,7 +606,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `c` char(10) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, - UNIQUE KEY `a` USING BTREE (`c`(1)) + UNIQUE KEY `a` (`c`(1)) USING BTREE ) ENGINE=MEMORY DEFAULT CHARSET=latin1 insert into t1 values ('a'),('b'),('c'),('d'),('e'),('f'); insert into t1 values ('aa'); diff --git a/mysql-test/r/date_formats.result b/mysql-test/r/date_formats.result index 214c9466c8c..ea4ae8a8438 100644 --- a/mysql-test/r/date_formats.result +++ b/mysql-test/r/date_formats.result @@ -515,3 +515,39 @@ NULL select str_to_date( 1, IF(1=1,NULL,NULL) ); str_to_date( 1, IF(1=1,NULL,NULL) ) NULL +SELECT TIME_FORMAT("24:00:00", '%r'); +TIME_FORMAT("24:00:00", '%r') +12:00:00 AM +SELECT TIME_FORMAT("00:00:00", '%r'); +TIME_FORMAT("00:00:00", '%r') +12:00:00 AM +SELECT TIME_FORMAT("12:00:00", '%r'); +TIME_FORMAT("12:00:00", '%r') +12:00:00 PM +SELECT TIME_FORMAT("15:00:00", '%r'); +TIME_FORMAT("15:00:00", '%r') +03:00:00 PM +SELECT TIME_FORMAT("01:00:00", '%r'); +TIME_FORMAT("01:00:00", '%r') +01:00:00 AM +SELECT TIME_FORMAT("25:00:00", '%r'); +TIME_FORMAT("25:00:00", '%r') +01:00:00 AM +SELECT TIME_FORMAT("00:00:00", '%l %p'); +TIME_FORMAT("00:00:00", '%l %p') +12 AM +SELECT TIME_FORMAT("01:00:00", '%l %p'); +TIME_FORMAT("01:00:00", '%l %p') +1 AM +SELECT TIME_FORMAT("12:00:00", '%l %p'); +TIME_FORMAT("12:00:00", '%l %p') +12 PM +SELECT TIME_FORMAT("23:00:00", '%l %p'); +TIME_FORMAT("23:00:00", '%l %p') +11 PM +SELECT TIME_FORMAT("24:00:00", '%l %p'); +TIME_FORMAT("24:00:00", '%l %p') +12 AM +SELECT TIME_FORMAT("25:00:00", '%l %p'); +TIME_FORMAT("25:00:00", '%l %p') +1 AM diff --git a/mysql-test/r/distinct.result b/mysql-test/r/distinct.result index a6ad95570f8..89b17d69f40 100644 --- a/mysql-test/r/distinct.result +++ b/mysql-test/r/distinct.result @@ -533,3 +533,15 @@ select count(distinct concat(x,y)) from t1; count(distinct concat(x,y)) 2 drop table t1; +CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a,b)); +INSERT INTO t1 VALUES (1, 101); +INSERT INTO t1 SELECT a + 1, a + 101 FROM t1; +INSERT INTO t1 SELECT a + 2, a + 102 FROM t1; +INSERT INTO t1 SELECT a + 4, a + 104 FROM t1; +INSERT INTO t1 SELECT a + 8, a + 108 FROM t1; +EXPLAIN SELECT DISTINCT a,a FROM t1 WHERE b < 12 ORDER BY a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index NULL PRIMARY 8 NULL 16 Using where; Using index +SELECT DISTINCT a,a FROM t1 WHERE b < 12 ORDER BY a; +a a +DROP TABLE t1; diff --git a/mysql-test/r/events.result b/mysql-test/r/events.result index 01d206be7cb..77280f99b7c 100644 --- a/mysql-test/r/events.result +++ b/mysql-test/r/events.result @@ -17,13 +17,13 @@ db_x SHOW TABLES FROM db_x; Tables_in_db_x x_table -SET GLOBAL event_scheduler=0; +SET GLOBAL event_scheduler=2; DROP EVENT e_x1; DROP EVENT e_x2; DROP DATABASE db_x; DROP USER pauline@localhost; USE events_test; -SET GLOBAL event_scheduler=0; +SET GLOBAL event_scheduler=2; drop event if exists event1; Warnings: Note 1305 Event event1 does not exist @@ -100,7 +100,7 @@ a 800219 drop event non_qualif_ev; drop table non_qualif; -set global event_scheduler = 0; +set global event_scheduler = 2; create table t_event3 (a int, b float); drop event if exists event3; Warnings: @@ -254,7 +254,7 @@ event CREATE TABLE `event` ( `on_completion` enum('DROP','PRESERVE') NOT NULL DEFAULT 'DROP', `sql_mode` set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','NOT_USED','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES','ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER','HIGH_NOT_PRECEDENCE') NOT NULL DEFAULT '', `comment` char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', - PRIMARY KEY (`definer`,`db`,`name`) + PRIMARY KEY (`db`,`name`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Events' SELECT event_name FROM INFORMATION_SCHEMA.EVENTS; ERROR HY000: Cannot load from mysql.event. Table probably corrupted. See error log. @@ -280,87 +280,6 @@ SHOW EVENTS; Db Name Definer Type Execute at Interval value Interval field Starts Ends Status events_test intact_check root@localhost RECURRING NULL 10 HOUR # # ENABLED DROP EVENT intact_check; -create event one_event on schedule every 10 second do select 123; -SHOW EVENTS; -Db Name Definer Type Execute at Interval value Interval field Starts Ends Status -events_test one_event root@localhost RECURRING NULL 10 SECOND # # ENABLED -SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT from information_schema.events; -EVENT_CATALOG EVENT_SCHEMA EVENT_NAME DEFINER EVENT_BODY EVENT_TYPE EXECUTE_AT INTERVAL_VALUE INTERVAL_FIELD STATUS ON_COMPLETION EVENT_COMMENT -NULL events_test one_event root@localhost select 123 RECURRING NULL 10 SECOND ENABLED NOT PRESERVE -CREATE DATABASE events_test2; -CREATE USER ev_test@localhost; -GRANT ALL ON events_test.* to ev_test@localhost; -GRANT ALL on events_test2.* to ev_test@localhost; -REVOKE EVENT ON events_test2.* FROM ev_test@localhost; -REVOKE PROCESS on *.* from ev_test@localhost; -select "NEW CONNECTION"; -NEW CONNECTION -NEW CONNECTION -SELECT USER(), DATABASE(); -USER() DATABASE() -ev_test@localhost events_test2 -SHOW GRANTS; -Grants for ev_test@localhost -GRANT USAGE ON *.* TO 'ev_test'@'localhost' -GRANT ALL PRIVILEGES ON `events_test`.* TO 'ev_test'@'localhost' -GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, TRIGGER ON `events_test2`.* TO 'ev_test'@'localhost' -"Here comes an error:"; -SHOW EVENTS; -ERROR 42000: Access denied for user 'ev_test'@'localhost' to database 'events_test2' -USE events_test; -"Now the list should be empty:"; -SHOW EVENTS; -Db Name Definer Type Execute at Interval value Interval field Starts Ends Status -select concat("Let's create some new events from the name of ",user()); -concat("Let's create some new events from the name of ",user()) -Let's create some new events from the name of ev_test@localhost -create event one_event on schedule every 20 second do select 123; -create event two_event on schedule every 20 second on completion not preserve comment "two event" do select 123; -create event three_event on schedule every 20 second on completion preserve comment "three event" do select 123; -"Now we should see 3 events:"; -SHOW EVENTS; -Db Name Definer Type Execute at Interval value Interval field Starts Ends Status -events_test one_event ev_test@localhost RECURRING NULL 20 SECOND # # ENABLED -events_test three_event ev_test@localhost RECURRING NULL 20 SECOND # # ENABLED -events_test two_event ev_test@localhost RECURRING NULL 20 SECOND # # ENABLED -"This should show us only 3 events:"; -SHOW FULL EVENTS; -Db Name Definer Type Execute at Interval value Interval field Starts Ends Status -events_test one_event ev_test@localhost RECURRING NULL 20 SECOND # # ENABLED -events_test three_event ev_test@localhost RECURRING NULL 20 SECOND # # ENABLED -events_test two_event ev_test@localhost RECURRING NULL 20 SECOND # # ENABLED -"This should show us only 2 events:"; -SHOW FULL EVENTS LIKE 't%event'; -Db Name Definer Type Execute at Interval value Interval field Starts Ends Status -events_test three_event ev_test@localhost RECURRING NULL 20 SECOND # # ENABLED -events_test two_event ev_test@localhost RECURRING NULL 20 SECOND # # ENABLED -"This should show us no events:"; -SHOW FULL EVENTS FROM test LIKE '%'; -Db Name Definer Type Execute at Interval value Interval field Starts Ends Status -DROP DATABASE events_test2; -"should see 1 event:"; -SHOW EVENTS; -Db Name Definer Type Execute at Interval value Interval field Starts Ends Status -events_test one_event root@localhost RECURRING NULL 10 SECOND # # ENABLED -"we should see 4 events now:"; -SHOW FULL EVENTS; -Db Name Definer Type Execute at Interval value Interval field Starts Ends Status -events_test one_event ev_test@localhost RECURRING NULL 20 SECOND # # ENABLED -events_test three_event ev_test@localhost RECURRING NULL 20 SECOND # # ENABLED -events_test two_event ev_test@localhost RECURRING NULL 20 SECOND # # ENABLED -events_test one_event root@localhost RECURRING NULL 10 SECOND # # ENABLED -SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT from information_schema.events; -EVENT_CATALOG EVENT_SCHEMA EVENT_NAME DEFINER EVENT_BODY EVENT_TYPE EXECUTE_AT INTERVAL_VALUE INTERVAL_FIELD STATUS ON_COMPLETION EVENT_COMMENT -NULL events_test one_event ev_test@localhost select 123 RECURRING NULL 20 SECOND ENABLED NOT PRESERVE -NULL events_test three_event ev_test@localhost select 123 RECURRING NULL 20 SECOND ENABLED PRESERVE three event -NULL events_test two_event ev_test@localhost select 123 RECURRING NULL 20 SECOND ENABLED NOT PRESERVE two event -NULL events_test one_event root@localhost select 123 RECURRING NULL 10 SECOND ENABLED NOT PRESERVE -drop event one_event; -drop event two_event; -drop event three_event; -drop user ev_test@localhost; -drop event one_event; -"Sleep a bit so the server closes the second connection" create event e_26 on schedule at '2017-01-01 00:00:00' disable do set @a = 5; select db, name, body, definer, convert_tz(execute_at, 'UTC', 'SYSTEM'), on_completion from mysql.event; db name body definer convert_tz(execute_at, 'UTC', 'SYSTEM') on_completion @@ -373,12 +292,12 @@ ERROR HY000: Incorrect AT value: 'definitely not a datetime' set names utf8; create event задачка on schedule every 123 minute starts now() ends now() + interval 1 month do select 1; drop event задачка; -set event_scheduler=0; +set event_scheduler=2; ERROR HY000: Variable 'event_scheduler' is a GLOBAL variable and should be set with SET GLOBAL -set global event_scheduler=2; -ERROR 42000: Variable 'event_scheduler' can't be set to the value of '2' +set global event_scheduler=3; +ERROR 42000: Variable 'event_scheduler' can't be set to the value of '3' "DISABLE the scheduler. Testing that it does not work when the variable is 0" -set global event_scheduler=0; +set global event_scheduler=2; select definer, name, db from mysql.event; definer name db select get_lock("test_lock1", 20); @@ -389,9 +308,10 @@ create event закачка on schedule every 10 hour do select get_lock("test_l select definer, name, db from mysql.event; definer name db root@localhost закачка events_test -"Should be 0 processes" +"Should be only 1 process" select /*1*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; user host db command state info +event_scheduler localhost NULL Connect Suspended NULL select release_lock("test_lock1"); release_lock("test_lock1") 1 @@ -409,11 +329,12 @@ get_lock("test_lock2", 20) create event закачка on schedule every 10 hour do select get_lock("test_lock2", 20); "Let some time pass to the event starts" "Should have only 2 processes: the scheduler and the locked event" -select /*1*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; +select /*2*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; user host db command state info event_scheduler localhost NULL Connect Sleeping NULL root localhost events_test Connect User lock select get_lock("test_lock2", 20) "Release the mutex, the event worker should finish." +"Release the mutex, the event worker should finish." select release_lock("test_lock2"); release_lock("test_lock2") 1 @@ -423,21 +344,17 @@ select get_lock("test_lock2_1", 20); get_lock("test_lock2_1", 20) 1 create event закачка21 on schedule every 10 hour do select get_lock("test_lock2_1", 20); -"Should see 1 process, locked on get_lock(" -"Shutting down the scheduler, it should wait for the running event" -set global event_scheduler=0; -"Should have only 2 processes: the scheduler and the locked event" -select /*4*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; +"Should have only 3 processes: the scheduler, our conn and the locked event" +select /*3*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; user host db command state info event_scheduler localhost NULL Connect Sleeping NULL root localhost events_test Connect User lock select get_lock("test_lock2_1", 20) -"Release the lock so the child process should finish. Hence the scheduler also" -select release_lock("test_lock2_1"); -release_lock("test_lock2_1") -1 -"Should see 0 processes now:" -select /*5*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; +set global event_scheduler=2; +"Should have only our process now:" +select /*4*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; user host db command state info +event_scheduler localhost NULL Connect Suspended NULL +root localhost events_test Connect User lock select get_lock("test_lock2_1", 20) drop event закачка21; create table t_16 (s1 int); create trigger t_16_bi before insert on t_16 for each row create event e_16 on schedule every 1 second do set @a=5; diff --git a/mysql-test/r/events_bugs.result b/mysql-test/r/events_bugs.result index ef1ccfadecb..bc89c692f9a 100644 --- a/mysql-test/r/events_bugs.result +++ b/mysql-test/r/events_bugs.result @@ -35,7 +35,7 @@ create event e_55 on schedule every 10 hour starts 99990101000000 do drop table ERROR HY000: Incorrect STARTS value: '99990101000000' create event e_55 on schedule every 10 minute ends 99990101000000 do drop table t; ERROR HY000: ENDS is either invalid or before STARTS -set global event_scheduler=0; +set global event_scheduler=2; "Wait a bit to settle down" delete from mysql.event; set global event_scheduler= 1; @@ -57,7 +57,7 @@ root localhost events_test Connect User lock select get_lock('test_bug16407', 60 select release_lock('test_bug16407'); release_lock('test_bug16407') 1 -set global event_scheduler= 0; +set global event_scheduler= 2; select event_schema, event_name, sql_mode from information_schema.events order by event_schema, event_name; event_schema event_name sql_mode events_test e_16407 REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ANSI @@ -115,7 +115,7 @@ release_lock('ee_16407_2') select /*3*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; user host db command state info event_scheduler localhost NULL Connect Sleeping NULL -set global event_scheduler= 0; +set global event_scheduler= 2; select * from events_smode_test order by ev_name, a; ev_name a ee_16407_3 1980-02-19 @@ -175,7 +175,7 @@ drop event ee_16407_5; drop event ee_16407_6; drop procedure ee_16407_5_pendant; drop procedure ee_16407_6_pendant; -set global event_scheduler= 0; +set global event_scheduler= 2; drop table events_smode_test; set sql_mode=@old_sql_mode; drop database events_test; diff --git a/mysql-test/r/events_grant.result b/mysql-test/r/events_grant.result new file mode 100644 index 00000000000..6c140f91eaa --- /dev/null +++ b/mysql-test/r/events_grant.result @@ -0,0 +1,121 @@ +CREATE DATABASE IF NOT EXISTS events_test; +use events_test; +CREATE EVENT one_event ON SCHEDULE EVERY 10 SECOND DO SELECT 123; +SHOW EVENTS; +Db Name Definer Type Execute at Interval value Interval field Starts Ends Status +events_test one_event root@localhost RECURRING NULL 10 SECOND # # ENABLED +SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT from information_schema.events; +EVENT_CATALOG EVENT_SCHEMA EVENT_NAME DEFINER EVENT_BODY EVENT_TYPE EXECUTE_AT INTERVAL_VALUE INTERVAL_FIELD STATUS ON_COMPLETION EVENT_COMMENT +NULL events_test one_event root@localhost SELECT 123 RECURRING NULL 10 SECOND ENABLED NOT PRESERVE +CREATE DATABASE events_test2; +CREATE USER ev_test@localhost; +GRANT ALL ON events_test.* to ev_test@localhost; +GRANT ALL ON events_test2.* to ev_test@localhost; +REVOKE EVENT ON events_test2.* FROM ev_test@localhost; +select "NEW CONNECTION"; +NEW CONNECTION +NEW CONNECTION +SELECT USER(), DATABASE(); +USER() DATABASE() +ev_test@localhost events_test2 +SHOW GRANTS; +Grants for ev_test@localhost +GRANT USAGE ON *.* TO 'ev_test'@'localhost' +GRANT ALL PRIVILEGES ON `events_test`.* TO 'ev_test'@'localhost' +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, TRIGGER ON `events_test2`.* TO 'ev_test'@'localhost' +"Here comes an error:"; +SHOW EVENTS; +ERROR 42000: Access denied for user 'ev_test'@'localhost' to database 'events_test2' +USE events_test; +"We should see one event"; +SHOW EVENTS; +Db Name Definer Type Execute at Interval value Interval field Starts Ends Status +events_test one_event root@localhost RECURRING NULL 10 SECOND # # ENABLED +SELECT CONCAT("Let's create some new events from the name of ", USER()); +CONCAT("Let's create some new events from the name of ", USER()) +Let's create some new events from the name of ev_test@localhost +CREATE EVENT one_event ON SCHEDULE EVERY 20 SECOND DO SELECT 123; +ERROR HY000: Event 'one_event' already exists +CREATE EVENT two_event ON SCHEDULE EVERY 20 SECOND ON COMPLETION NOT PRESERVE COMMENT "two event" DO SELECT 123; +CREATE EVENT three_event ON SCHEDULE EVERY 20 SECOND ON COMPLETION PRESERVE COMMENT "three event" DO SELECT 123; +"Now we should see 3 events:"; +SHOW EVENTS; +Db Name Definer Type Execute at Interval value Interval field Starts Ends Status +events_test one_event root@localhost RECURRING NULL 10 SECOND # # ENABLED +events_test three_event ev_test@localhost RECURRING NULL 20 SECOND # # ENABLED +events_test two_event ev_test@localhost RECURRING NULL 20 SECOND # # ENABLED +"This should show us only 2 events:"; +SHOW EVENTS LIKE 't%event'; +Db Name Definer Type Execute at Interval value Interval field Starts Ends Status +events_test three_event ev_test@localhost RECURRING NULL 20 SECOND # # ENABLED +events_test two_event ev_test@localhost RECURRING NULL 20 SECOND # # ENABLED +"This should show us no events:"; +SHOW EVENTS FROM test LIKE '%'; +Db Name Definer Type Execute at Interval value Interval field Starts Ends Status +GRANT EVENT ON events_test2.* TO ev_test@localhost; +USE events_test2; +CREATE EVENT four_event ON SCHEDULE EVERY 20 SECOND DO SELECT 42; +USE events_test; +"We should see 4 events : one_event, two_event, three_event & four_event" +SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS; +EVENT_CATALOG EVENT_SCHEMA EVENT_NAME DEFINER EVENT_BODY EVENT_TYPE EXECUTE_AT INTERVAL_VALUE INTERVAL_FIELD STATUS ON_COMPLETION EVENT_COMMENT +NULL events_test one_event root@localhost SELECT 123 RECURRING NULL 10 SECOND ENABLED NOT PRESERVE +NULL events_test two_event ev_test@localhost SELECT 123 RECURRING NULL 20 SECOND ENABLED NOT PRESERVE two event +NULL events_test three_event ev_test@localhost SELECT 123 RECURRING NULL 20 SECOND ENABLED PRESERVE three event +NULL events_test2 four_event ev_test@localhost SELECT 42 RECURRING NULL 20 SECOND ENABLED NOT PRESERVE +DROP DATABASE events_test2; +"We should see 3 events : one_event, two_event, three_event" +SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS; +EVENT_CATALOG EVENT_SCHEMA EVENT_NAME DEFINER EVENT_BODY EVENT_TYPE EXECUTE_AT INTERVAL_VALUE INTERVAL_FIELD STATUS ON_COMPLETION EVENT_COMMENT +NULL events_test one_event root@localhost SELECT 123 RECURRING NULL 10 SECOND ENABLED NOT PRESERVE +NULL events_test two_event ev_test@localhost SELECT 123 RECURRING NULL 20 SECOND ENABLED NOT PRESERVE two event +NULL events_test three_event ev_test@localhost SELECT 123 RECURRING NULL 20 SECOND ENABLED PRESERVE three event +CREATE DATABASE events_test2; +USE events_test2; +CREATE EVENT five_event ON SCHEDULE EVERY 20 SECOND DO SELECT 42; +"Should see 4 events - one, two, three & five" +SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS; +EVENT_CATALOG EVENT_SCHEMA EVENT_NAME DEFINER EVENT_BODY EVENT_TYPE EXECUTE_AT INTERVAL_VALUE INTERVAL_FIELD STATUS ON_COMPLETION EVENT_COMMENT +NULL events_test one_event root@localhost SELECT 123 RECURRING NULL 10 SECOND ENABLED NOT PRESERVE +NULL events_test two_event ev_test@localhost SELECT 123 RECURRING NULL 20 SECOND ENABLED NOT PRESERVE two event +NULL events_test three_event ev_test@localhost SELECT 123 RECURRING NULL 20 SECOND ENABLED PRESERVE three event +NULL events_test2 five_event root@localhost SELECT 42 RECURRING NULL 20 SECOND ENABLED NOT PRESERVE +REVOKE EVENT ON events_test2.* FROM ev_test@localhost; +USE test; +"Should see 3 events - one, two & three" +SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS; +EVENT_CATALOG EVENT_SCHEMA EVENT_NAME DEFINER EVENT_BODY EVENT_TYPE EXECUTE_AT INTERVAL_VALUE INTERVAL_FIELD STATUS ON_COMPLETION EVENT_COMMENT +NULL events_test one_event root@localhost SELECT 123 RECURRING NULL 10 SECOND ENABLED NOT PRESERVE +NULL events_test two_event ev_test@localhost SELECT 123 RECURRING NULL 20 SECOND ENABLED NOT PRESERVE two event +NULL events_test three_event ev_test@localhost SELECT 123 RECURRING NULL 20 SECOND ENABLED PRESERVE three event +"Let's test ALTER EVENT which changes the definer" +USE events_test; +ALTER EVENT one_event ON SCHEDULE EVERY 10 SECOND; +"The definer should be ev_test@localhost" +SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_NAME='one_event'; +EVENT_CATALOG EVENT_SCHEMA EVENT_NAME DEFINER EVENT_BODY EVENT_TYPE EXECUTE_AT INTERVAL_VALUE INTERVAL_FIELD STATUS ON_COMPLETION EVENT_COMMENT +NULL events_test one_event ev_test@localhost SELECT 123 RECURRING NULL 10 SECOND ENABLED NOT PRESERVE +USE events_test; +ALTER EVENT one_event COMMENT "comment"; +"The definer should be root@localhost" +SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_NAME='one_event'; +EVENT_CATALOG EVENT_SCHEMA EVENT_NAME DEFINER EVENT_BODY EVENT_TYPE EXECUTE_AT INTERVAL_VALUE INTERVAL_FIELD STATUS ON_COMPLETION EVENT_COMMENT +NULL events_test one_event root@localhost SELECT 123 RECURRING NULL 10 SECOND ENABLED NOT PRESERVE comment +ALTER EVENT one_event DO SELECT 12; +"The definer should be ev_test@localhost" +SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_NAME='one_event'; +EVENT_CATALOG EVENT_SCHEMA EVENT_NAME DEFINER EVENT_BODY EVENT_TYPE EXECUTE_AT INTERVAL_VALUE INTERVAL_FIELD STATUS ON_COMPLETION EVENT_COMMENT +NULL events_test one_event ev_test@localhost SELECT 12 RECURRING NULL 10 SECOND ENABLED NOT PRESERVE comment +"make the definer again root@localhost" +ALTER EVENT one_event COMMENT "new comment"; +"test DROP by another user" +DROP EVENT one_event; +"One event should not be there" +SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS; +EVENT_CATALOG EVENT_SCHEMA EVENT_NAME DEFINER EVENT_BODY EVENT_TYPE EXECUTE_AT INTERVAL_VALUE INTERVAL_FIELD STATUS ON_COMPLETION EVENT_COMMENT +NULL events_test two_event ev_test@localhost SELECT 123 RECURRING NULL 20 SECOND ENABLED NOT PRESERVE two event +NULL events_test three_event ev_test@localhost SELECT 123 RECURRING NULL 20 SECOND ENABLED PRESERVE three event +NULL events_test2 five_event root@localhost SELECT 42 RECURRING NULL 20 SECOND ENABLED NOT PRESERVE +DROP USER ev_test@localhost; +DROP DATABASE events_test2; +DROP DATABASE events_test; diff --git a/mysql-test/r/events_logs_tests.result b/mysql-test/r/events_logs_tests.result index ab1666fefb9..ce58e0ec059 100644 --- a/mysql-test/r/events_logs_tests.result +++ b/mysql-test/r/events_logs_tests.result @@ -8,7 +8,7 @@ BEGIN SELECT user_host, argument FROM mysql.general_log WHERE argument LIKE '%alabala%'; END| "Check General Query Log" -SET GLOBAL event_scheduler=0; +SET GLOBAL event_scheduler=2; create event log_general on schedule every 1 minute do SELect 'alabala', sleep(3) from dual; TRUNCATE mysql.general_log; "1 row, the current statement!" @@ -19,10 +19,10 @@ SET GLOBAL event_scheduler=1; "Should see 3 rows - the 'SELect' is in the middle. The other two are selects from general_log" call select_general_log(); user_host argument -root[root] @ localhost [localhost] SELect 'alabala', sleep(3) from dual +USER_HOST SELect 'alabala', sleep(3) from dual DROP PROCEDURE select_general_log; DROP EVENT log_general; -SET GLOBAL event_scheduler=0; +SET GLOBAL event_scheduler=2; "Check slow query log" "Save the values" SET @old_global_long_query_time:=(select get_value()); @@ -36,14 +36,14 @@ SELECT user_host, query_time, db, sql_text FROM mysql.slow_log; user_host query_time db sql_text "Set new values" SET GLOBAL long_query_time=4; -SET SESSION long_query_time=2; +SET SESSION long_query_time=1; "Check that logging is working" -SELECT SLEEP(3); -SLEEP(3) +SELECT SLEEP(2); +SLEEP(2) 0 SELECT user_host, query_time, db, sql_text FROM mysql.slow_log; user_host query_time db sql_text -root[root] @ localhost [] SLEEPVAL events_test SELECT SLEEP(3) +USER_HOST SLEEPVAL events_test SELECT SLEEP(2) TRUNCATE mysql.slow_log; CREATE TABLE slow_event_test (slo_val tinyint, val tinyint); "This won't go to the slow log" @@ -54,7 +54,7 @@ SET GLOBAL event_scheduler=1; "Sleep some more time than the actual event run will take" SHOW VARIABLES LIKE 'event_scheduler'; Variable_name Value -event_scheduler ON +event_scheduler 1 "Check our table. Should see 1 row" SELECT * FROM slow_event_test; slo_val val @@ -64,18 +64,19 @@ SELECT user_host, query_time, db, sql_text FROM mysql.slow_log; user_host query_time db sql_text "This should go to the slow log" SET SESSION long_query_time=10; +SET GLOBAL long_query_time=1; DROP EVENT long_event; -CREATE EVENT long_event2 ON SCHEDULE EVERY 1 MINUTE DO INSERT INTO slow_event_test SELECT @@long_query_time, SLEEP(5); +CREATE EVENT long_event2 ON SCHEDULE EVERY 1 MINUTE DO INSERT INTO slow_event_test SELECT @@long_query_time, SLEEP(2); "Sleep some more time than the actual event run will take" "Check our table. Should see 2 rows" SELECT * FROM slow_event_test; slo_val val 4 0 -4 0 -"Check slow log. Should see 1 row because 5 is over the threshold of 4 for GLOBAL, though under SESSION which is 10" +1 0 +"Check slow log. Should see 1 row because 4 is over the threshold of 3 for GLOBAL, though under SESSION which is 10" SELECT user_host, query_time, db, sql_text FROM mysql.slow_log; user_host query_time db sql_text -root[root] @ localhost [localhost] SLEEPVAL events_test INSERT INTO slow_event_test SELECT @@long_query_time, SLEEP(5) +USER_HOST SLEEPVAL events_test INSERT INTO slow_event_test SELECT @@long_query_time, SLEEP(2) DROP EVENT long_event2; SET GLOBAL long_query_time =@old_global_long_query_time; SET SESSION long_query_time =@old_session_long_query_time; diff --git a/mysql-test/r/events_microsec.result b/mysql-test/r/events_microsec.result index ed15b066b93..b96bd551511 100644 --- a/mysql-test/r/events_microsec.result +++ b/mysql-test/r/events_microsec.result @@ -10,50 +10,4 @@ CREATE EVENT micro_test ON SCHEDULE EVERY 100 MINUTE_MICROSECOND DO SELECT 1; ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND' CREATE EVENT micro_test ON SCHEDULE EVERY 100 SECOND_MICROSECOND DO SELECT 1; ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND' -"Now create normal event and change it on SQL level" -CREATE EVENT micro_test2 ON SCHEDULE EVERY 1 MONTH DO SELECT 1; -UPDATE mysql.event SET interval_field='MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; -SHOW CREATE EVENT micro_test2; -ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND' -SET GLOBAL event_scheduler=0; -"Should not be running:" -SHOW VARIABLES like 'event_scheduler'; -Variable_name Value -event_scheduler OFF -UPDATE mysql.event SET interval_field='DAY_MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; -SHOW CREATE EVENT micro_test2; -ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND' -SET GLOBAL event_scheduler=0; -"Should not be running:" -SHOW VARIABLES like 'event_scheduler'; -Variable_name Value -event_scheduler OFF -UPDATE mysql.event SET interval_field='SECOND_MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; -SHOW CREATE EVENT micro_test2; -ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND' -SET GLOBAL event_scheduler=0; -"Should not be running:" -SHOW VARIABLES like 'event_scheduler'; -Variable_name Value -event_scheduler OFF -UPDATE mysql.event SET interval_field='HOUR_MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; -SHOW CREATE EVENT micro_test2; -ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND' -SET GLOBAL event_scheduler=0; -"Should not be running:" -SHOW VARIABLES like 'event_scheduler'; -Variable_name Value -event_scheduler OFF -UPDATE mysql.event SET interval_field='MINUTE_MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; -SHOW CREATE EVENT micro_test2; -ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND' -SET GLOBAL event_scheduler=0; -"Should not be running:" -SHOW VARIABLES like 'event_scheduler'; -Variable_name Value -event_scheduler OFF -SELECT COUNT(*) FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER='event_scheduler'; -COUNT(*) -0 -DROP EVENT micro_test2; drop database events_test; diff --git a/mysql-test/r/events_scheduling.result b/mysql-test/r/events_scheduling.result index 8b1f29d320f..aec2053f0e7 100644 --- a/mysql-test/r/events_scheduling.result +++ b/mysql-test/r/events_scheduling.result @@ -14,7 +14,7 @@ ENDS NOW() + INTERVAL 6 SECOND ON COMPLETION PRESERVE DO INSERT INTO table_2 VALUES(1); CREATE EVENT only_one_time ON SCHEDULE EVERY 2 SECOND ENDS NOW() + INTERVAL 1 SECOND DO INSERT INTO table_3 VALUES(1); -CREATE EVENT two_time ON SCHEDULE EVERY 1 SECOND ENDS NOW() + INTERVAL 1 SECOND DO INSERT INTO table_4 VALUES(1); +CREATE EVENT two_time ON SCHEDULE EVERY 1 SECOND ENDS NOW() + INTERVAL 1 SECOND ON COMPLETION PRESERVE DO INSERT INTO table_4 VALUES(1); SELECT IF(SUM(a) >= 4, 'OK', 'ERROR') FROM table_1; IF(SUM(a) >= 4, 'OK', 'ERROR') OK @@ -38,9 +38,12 @@ DROP EVENT start_n_end; "Already dropped because ended. Therefore an error." DROP EVENT only_one_time; ERROR HY000: Unknown event 'only_one_time' -"Already dropped because ended. Therefore an error." +"Should be preserved" +SELECT EVENT_NAME, STATUS FROM INFORMATION_SCHEMA.EVENTS; +EVENT_NAME STATUS +E19170 ENABLED +two_time DISABLED DROP EVENT two_time; -ERROR HY000: Unknown event 'two_time' DROP TABLE table_1; DROP TABLE table_2; DROP TABLE table_3; diff --git a/mysql-test/r/events_stress.result b/mysql-test/r/events_stress.result index 9f95cfad75d..ead618e8136 100644 --- a/mysql-test/r/events_stress.result +++ b/mysql-test/r/events_stress.result @@ -1,46 +1,61 @@ CREATE DATABASE IF NOT EXISTS events_test; -CREATE DATABASE events_test2; -USE events_test2; +CREATE DATABASE events_conn1_test2; +CREATE TABLE events_test.fill_it(test_name varchar(20), occur datetime); +CREATE USER event_user2@localhost; +CREATE DATABASE events_conn2_db; +GRANT ALL ON *.* TO event_user2@localhost; +CREATE USER event_user3@localhost; +CREATE DATABASE events_conn3_db; +GRANT ALL ON *.* TO event_user3@localhost; +"In the second connection we create some events which won't be dropped till the end" +"In the second connection we create some events which won't be dropped till the end" +USE events_conn1_test2; CREATE EVENT ev_drop1 ON SCHEDULE EVERY 10 MINUTE DISABLE DO SELECT 1; CREATE EVENT ev_drop2 ON SCHEDULE EVERY 10 MINUTE DISABLE DO SELECT 1; CREATE EVENT ev_drop3 ON SCHEDULE EVERY 10 MINUTE DISABLE DO SELECT 1; USE events_test; -SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_test2'; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS; +COUNT(*) +103 +SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2'; COUNT(*) 3 -DROP DATABASE events_test2; -SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_test2'; +DROP DATABASE events_conn1_test2; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2'; COUNT(*) 0 "Now testing stability - dropping db -> events while they are running" -CREATE DATABASE events_test2; -USE events_test2; -SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_test2'; +CREATE DATABASE events_conn1_test2; +USE events_conn1_test2; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2'; COUNT(*) -1000 +50 SET GLOBAL event_scheduler=1; -DROP DATABASE events_test2; -SET GLOBAL event_scheduler=0; -SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_test2'; +DROP DATABASE events_conn1_test2; +SET GLOBAL event_scheduler=2; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2'; COUNT(*) 0 -CREATE DATABASE events_test3; -USE events_test3; -SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_test3'; +CREATE DATABASE events_conn1_test3; +USE events_conn1_test3; +SET GLOBAL event_scheduler=1; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test3'; COUNT(*) -950 -CREATE DATABASE events_test4; -USE events_test4; -CREATE DATABASE events_test2; -USE events_test2; -SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_test2'; +50 +CREATE DATABASE events_conn1_test4; +USE events_conn1_test4; +CREATE DATABASE events_conn1_test2; +USE events_conn1_test2; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2'; COUNT(*) -1050 -DROP DATABASE events_test2; -SET GLOBAL event_scheduler=0; -DROP DATABASE events_test3; -SET GLOBAL event_scheduler=1; -DROP DATABASE events_test4; +50 +DROP DATABASE events_conn2_db; +DROP DATABASE events_conn3_db; +DROP DATABASE events_conn1_test2; +DROP DATABASE events_conn1_test3; +SET GLOBAL event_scheduler=2; +DROP DATABASE events_conn1_test4; SET GLOBAL event_scheduler=1; USE events_test; +DROP TABLE fill_it; DROP DATABASE events_test; diff --git a/mysql-test/r/explain.result b/mysql-test/r/explain.result index d66dec741bd..75e1548cdee 100644 --- a/mysql-test/r/explain.result +++ b/mysql-test/r/explain.result @@ -53,3 +53,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE ÔÁ ref ÉÎÄ0,ÉÎÄ01 ÉÎÄ0 5 const 1 Using where; Using index drop table ÔÁÂ; set names latin1; +select 3 into @v1; +explain select 3 into @v1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used diff --git a/mysql-test/r/flush.result b/mysql-test/r/flush.result index 16c308e3450..a7f5e5e8fec 100644 --- a/mysql-test/r/flush.result +++ b/mysql-test/r/flush.result @@ -48,3 +48,10 @@ lock table t1 read, t2 read, t3 read; flush tables with read lock; unlock tables; drop table t1, t2, t3; +create table t1 (c1 int); +create table t2 (c1 int); +lock table t1 write; + flush tables with read lock; + insert into t2 values(1); +unlock tables; +drop table t1, t2; diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result index 58bf3b36469..824edbbe3a6 100644 --- a/mysql-test/r/func_group.result +++ b/mysql-test/r/func_group.result @@ -821,144 +821,6 @@ SELECT MAX(id) FROM t1 WHERE id < 3 AND a=2 AND b=6; MAX(id) NULL DROP TABLE t1; -create table t1m (a int) engine=myisam; -create table t1i (a int) engine=innodb; -create table t2m (a int) engine=myisam; -create table t2i (a int) engine=innodb; -insert into t2m values (5); -insert into t2i values (5); -select min(a) from t1m; -min(a) -NULL -select min(7) from t1m; -min(7) -NULL -select min(7) from DUAL; -min(7) -NULL -explain select min(7) from t2m join t1m; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -select min(7) from t2m join t1m; -min(7) -NULL -select max(a) from t1m; -max(a) -NULL -select max(7) from t1m; -max(7) -NULL -select max(7) from DUAL; -max(7) -NULL -explain select max(7) from t2m join t1m; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -select max(7) from t2m join t1m; -max(7) -NULL -select 1, min(a) from t1m where a=99; -1 min(a) -1 NULL -select 1, min(a) from t1m where 1=99; -1 min(a) -1 NULL -select 1, min(1) from t1m where a=99; -1 min(1) -1 NULL -select 1, min(1) from t1m where 1=99; -1 min(1) -1 NULL -select 1, max(a) from t1m where a=99; -1 max(a) -1 NULL -select 1, max(a) from t1m where 1=99; -1 max(a) -1 NULL -select 1, max(1) from t1m where a=99; -1 max(1) -1 NULL -select 1, max(1) from t1m where 1=99; -1 max(1) -1 NULL -select min(a) from t1i; -min(a) -NULL -select min(7) from t1i; -min(7) -NULL -select min(7) from DUAL; -min(7) -NULL -explain select min(7) from t2i join t1i; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2i ALL NULL NULL NULL NULL 1 -1 SIMPLE t1i ALL NULL NULL NULL NULL 1 -select min(7) from t2i join t1i; -min(7) -NULL -select max(a) from t1i; -max(a) -NULL -select max(7) from t1i; -max(7) -NULL -select max(7) from DUAL; -max(7) -NULL -explain select max(7) from t2i join t1i; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2i ALL NULL NULL NULL NULL 1 -1 SIMPLE t1i ALL NULL NULL NULL NULL 1 -select max(7) from t2i join t1i; -max(7) -NULL -select 1, min(a) from t1i where a=99; -1 min(a) -1 NULL -select 1, min(a) from t1i where 1=99; -1 min(a) -1 NULL -select 1, min(1) from t1i where a=99; -1 min(1) -1 NULL -select 1, min(1) from t1i where 1=99; -1 min(1) -1 NULL -select 1, max(a) from t1i where a=99; -1 max(a) -1 NULL -select 1, max(a) from t1i where 1=99; -1 max(a) -1 NULL -select 1, max(1) from t1i where a=99; -1 max(1) -1 NULL -select 1, max(1) from t1i where 1=99; -1 max(1) -1 NULL -explain select count(*), min(7), max(7) from t1m, t1i; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1m system NULL NULL NULL NULL 0 const row not found -1 SIMPLE t1i ALL NULL NULL NULL NULL 1 -select count(*), min(7), max(7) from t1m, t1i; -count(*) min(7) max(7) -0 NULL NULL -explain select count(*), min(7), max(7) from t1m, t2i; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1m system NULL NULL NULL NULL 0 const row not found -1 SIMPLE t2i ALL NULL NULL NULL NULL 1 -select count(*), min(7), max(7) from t1m, t2i; -count(*) min(7) max(7) -0 NULL NULL -explain select count(*), min(7), max(7) from t2m, t1i; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2m system NULL NULL NULL NULL 1 -1 SIMPLE t1i ALL NULL NULL NULL NULL 1 -select count(*), min(7), max(7) from t2m, t1i; -count(*) min(7) max(7) -0 NULL NULL -drop table t1m, t1i, t2m, t2i; create table t2 (ff double); insert into t2 values (2.2); select cast(sum(distinct ff) as decimal(5,2)) from t2; diff --git a/mysql-test/r/func_in.result b/mysql-test/r/func_in.result index e3257ce5fd0..e38e2624e19 100644 --- a/mysql-test/r/func_in.result +++ b/mysql-test/r/func_in.result @@ -326,3 +326,20 @@ deallocate prepare s; set @str=NULL; drop table t2; drop table t1; +create table t1 ( +some_id smallint(5) unsigned, +key (some_id) +); +insert into t1 values (1),(2); +select some_id from t1 where some_id not in(2,-1); +some_id +1 +select some_id from t1 where some_id not in(-4,-1,-4); +some_id +1 +2 +select some_id from t1 where some_id not in(-4,-1,3423534,2342342); +some_id +1 +2 +drop table t1; diff --git a/mysql-test/r/func_misc.result b/mysql-test/r/func_misc.result index 5e375472c5f..10d20c001f1 100644 --- a/mysql-test/r/func_misc.result +++ b/mysql-test/r/func_misc.result @@ -51,6 +51,42 @@ select a from t1 where mid(a+0,6,3) = ( mid(20040106123400,6,3) ); a 2004-01-06 12:34:00 drop table t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (conn CHAR(7), connection_id INT); +INSERT INTO t1 VALUES ('default', CONNECTION_ID()); +SELECT GET_LOCK('bug16501',600); +GET_LOCK('bug16501',600) +1 +INSERT INTO t1 VALUES ('con1', CONNECTION_ID()); +SELECT IS_USED_LOCK('bug16501') = connection_id +FROM t1 +WHERE conn = 'default'; +IS_USED_LOCK('bug16501') = connection_id +1 + SELECT GET_LOCK('bug16501',600); +SELECT IS_USED_LOCK('bug16501') = CONNECTION_ID(); +IS_USED_LOCK('bug16501') = CONNECTION_ID() +1 +SELECT RELEASE_LOCK('bug16501'); +RELEASE_LOCK('bug16501') +1 +GET_LOCK('bug16501',600) +1 +SELECT IS_USED_LOCK('bug16501') = connection_id +FROM t1 +WHERE conn = 'con1'; +IS_USED_LOCK('bug16501') = connection_id +1 +SELECT IS_USED_LOCK('bug16501') = CONNECTION_ID(); +IS_USED_LOCK('bug16501') = CONNECTION_ID() +1 +SELECT RELEASE_LOCK('bug16501'); +RELEASE_LOCK('bug16501') +1 +SELECT IS_USED_LOCK('bug16501'); +IS_USED_LOCK('bug16501') +NULL +DROP TABLE t1; create table t1 as select uuid(), length(uuid()); show create table t1; Table Create Table diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index 0b706b24488..354c886b19b 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -1017,6 +1017,13 @@ t 1000000 1 drop table t1; +select load_file("lkjlkj"); +load_file("lkjlkj") +NULL +select ifnull(load_file("lkjlkj"),"it's null"); +ifnull(load_file("lkjlkj"),"it's null") +it's null +End of 4.1 tests create table t1 (d decimal default null); insert into t1 values (null); select format(d, 2) from t1; @@ -1039,4 +1046,10 @@ cast(ltrim(' 20.06 ') as decimal(19,2)) select cast(rtrim(ltrim(' 20.06 ')) as decimal(19,2)); cast(rtrim(ltrim(' 20.06 ')) as decimal(19,2)) 20.06 +select conv("18383815659218730760",10,10) + 0; +conv("18383815659218730760",10,10) + 0 +1.8383815659219e+19 +select "18383815659218730760" + 0; +"18383815659218730760" + 0 +1.8383815659219e+19 End of 5.0 tests diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index b9b717cb39c..283dd11ca1e 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -732,12 +732,6 @@ SELECT count(*) FROM t1 WHERE d>FROM_DAYS(TO_DAYS(@TMP)) AND d<=FROM_DAYS(TO_DAY count(*) 3 DROP TABLE t1; -explain extended select timestampdiff(SQL_TSI_WEEK, '2001-02-01', '2001-05-01') as a1, -timestampdiff(SQL_TSI_FRAC_SECOND, '2001-02-01 12:59:59.120000', '2001-05-01 12:58:58.119999') as a2; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used -Warnings: -Note 1003 select timestampdiff(WEEK,_latin1'2001-02-01',_latin1'2001-05-01') AS `a1`,timestampdiff(SECOND_FRAC,_latin1'2001-02-01 12:59:59.120000',_latin1'2001-05-01 12:58:58.119999') AS `a2` select last_day('2005-00-00'); last_day('2005-00-00') NULL @@ -753,6 +747,17 @@ last_day('2005-01-00') NULL Warnings: Warning 1292 Incorrect datetime value: '2005-01-00' +select monthname(str_to_date(null, '%m')), monthname(str_to_date(null, '%m')), +monthname(str_to_date(1, '%m')), monthname(str_to_date(0, '%m')); +monthname(str_to_date(null, '%m')) monthname(str_to_date(null, '%m')) monthname(str_to_date(1, '%m')) monthname(str_to_date(0, '%m')) +NULL NULL January NULL +End of 4.1 tests +explain extended select timestampdiff(SQL_TSI_WEEK, '2001-02-01', '2001-05-01') as a1, +timestampdiff(SQL_TSI_FRAC_SECOND, '2001-02-01 12:59:59.120000', '2001-05-01 12:58:58.119999') as a2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select timestampdiff(WEEK,_latin1'2001-02-01',_latin1'2001-05-01') AS `a1`,timestampdiff(SECOND_FRAC,_latin1'2001-02-01 12:59:59.120000',_latin1'2001-05-01 12:58:58.119999') AS `a2` select time_format('100:00:00', '%H %k %h %I %l'); time_format('100:00:00', '%H %k %h %I %l') 100 100 04 04 4 @@ -873,3 +878,38 @@ id day id day 1 2005-06-01 3 2005-07-15 3 2005-07-01 3 2005-07-15 DROP TABLE t1,t2; +End of 5.0 tests +select date_sub("0050-01-01 00:00:01",INTERVAL 2 SECOND); +date_sub("0050-01-01 00:00:01",INTERVAL 2 SECOND) +NULL +select date_sub("0199-01-01 00:00:01",INTERVAL 2 SECOND); +date_sub("0199-01-01 00:00:01",INTERVAL 2 SECOND) +NULL +select date_add("0199-12-31 23:59:59",INTERVAL 2 SECOND); +date_add("0199-12-31 23:59:59",INTERVAL 2 SECOND) +NULL +select date_sub("0200-01-01 00:00:01",INTERVAL 2 SECOND); +date_sub("0200-01-01 00:00:01",INTERVAL 2 SECOND) +0199-12-31 23:59:59 +select date_sub("0200-01-01 00:00:01",INTERVAL 1 SECOND); +date_sub("0200-01-01 00:00:01",INTERVAL 1 SECOND) +0200-01-01 00:00:00 +select date_sub("0200-01-01 00:00:01",INTERVAL 2 SECOND); +date_sub("0200-01-01 00:00:01",INTERVAL 2 SECOND) +0199-12-31 23:59:59 +select date_add("2001-01-01 23:59:59",INTERVAL -2000 YEAR); +date_add("2001-01-01 23:59:59",INTERVAL -2000 YEAR) +0001-01-01 23:59:59 +select date_sub("50-01-01 00:00:01",INTERVAL 2 SECOND); +date_sub("50-01-01 00:00:01",INTERVAL 2 SECOND) +2049-12-31 23:59:59 +select date_sub("90-01-01 00:00:01",INTERVAL 2 SECOND); +date_sub("90-01-01 00:00:01",INTERVAL 2 SECOND) +1989-12-31 23:59:59 +select date_sub("0069-01-01 00:00:01",INTERVAL 2 SECOND); +date_sub("0069-01-01 00:00:01",INTERVAL 2 SECOND) +NULL +select date_sub("0169-01-01 00:00:01",INTERVAL 2 SECOND); +date_sub("0169-01-01 00:00:01",INTERVAL 2 SECOND) +NULL +End of 5.1 tests diff --git a/mysql-test/r/gis-rtree.result b/mysql-test/r/gis-rtree.result index bf4a10a0041..cd6a2510001 100644 --- a/mysql-test/r/gis-rtree.result +++ b/mysql-test/r/gis-rtree.result @@ -294,7 +294,7 @@ t2 CREATE TABLE `t2` ( `g` geometry NOT NULL, PRIMARY KEY (`fid`), SPATIAL KEY `g` (`g`(32)) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 +) ENGINE=MyISAM AUTO_INCREMENT=101 DEFAULT CHARSET=latin1 SELECT count(*) FROM t2; count(*) 100 diff --git a/mysql-test/r/grant.result b/mysql-test/r/grant.result index 4815798d807..75afab911b9 100644 --- a/mysql-test/r/grant.result +++ b/mysql-test/r/grant.result @@ -357,12 +357,12 @@ show grants for grant_user@localhost; Grants for grant_user@localhost GRANT USAGE ON *.* TO 'grant_user'@'localhost' GRANT INSERT (a, d, c, b) ON `test`.`t1` TO 'grant_user'@'localhost' -select Host,Db,User,Table_name,Column_name,Column_priv from mysql.columns_priv; +select Host,Db,User,Table_name,Column_name,Column_priv from mysql.columns_priv order by Column_name; Host Db User Table_name Column_name Column_priv -localhost test grant_user t1 b Insert -localhost test grant_user t1 d Insert localhost test grant_user t1 a Insert +localhost test grant_user t1 b Insert localhost test grant_user t1 c Insert +localhost test grant_user t1 d Insert revoke ALL PRIVILEGES on t1 from grant_user@localhost; show grants for grant_user@localhost; Grants for grant_user@localhost @@ -381,13 +381,27 @@ grant update (a) on mysqltest_1.t1 to mysqltest_3@localhost; grant select (b) on mysqltest_1.t2 to mysqltest_3@localhost; grant select (c) on mysqltest_2.t1 to mysqltest_3@localhost; grant update (d) on mysqltest_2.t2 to mysqltest_3@localhost; -show grants for mysqltest_3@localhost; -Grants for mysqltest_3@localhost -GRANT USAGE ON *.* TO 'mysqltest_3'@'localhost' -GRANT SELECT (b) ON `mysqltest_1`.`t2` TO 'mysqltest_3'@'localhost' -GRANT UPDATE (a) ON `mysqltest_1`.`t1` TO 'mysqltest_3'@'localhost' -GRANT UPDATE (d) ON `mysqltest_2`.`t2` TO 'mysqltest_3'@'localhost' -GRANT SELECT (c) ON `mysqltest_2`.`t1` TO 'mysqltest_3'@'localhost' +SELECT * FROM INFORMATION_SCHEMA.COLUMN_PRIVILEGES +WHERE GRANTEE = '''mysqltest_3''@''localhost''' +ORDER BY TABLE_NAME,COLUMN_NAME,PRIVILEGE_TYPE; +GRANTEE TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME PRIVILEGE_TYPE IS_GRANTABLE +'mysqltest_3'@'localhost' NULL mysqltest_1 t1 a UPDATE NO +'mysqltest_3'@'localhost' NULL mysqltest_2 t1 c SELECT NO +'mysqltest_3'@'localhost' NULL mysqltest_1 t2 b SELECT NO +'mysqltest_3'@'localhost' NULL mysqltest_2 t2 d UPDATE NO +SELECT * FROM INFORMATION_SCHEMA.TABLE_PRIVILEGES +WHERE GRANTEE = '''mysqltest_3''@''localhost''' +ORDER BY TABLE_NAME,PRIVILEGE_TYPE; +GRANTEE TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PRIVILEGE_TYPE IS_GRANTABLE +SELECT * from INFORMATION_SCHEMA.SCHEMA_PRIVILEGES +WHERE GRANTEE = '''mysqltest_3''@''localhost''' +ORDER BY TABLE_SCHEMA,PRIVILEGE_TYPE; +GRANTEE TABLE_CATALOG TABLE_SCHEMA PRIVILEGE_TYPE IS_GRANTABLE +SELECT * from INFORMATION_SCHEMA.USER_PRIVILEGES +WHERE GRANTEE = '''mysqltest_3''@''localhost''' + ORDER BY TABLE_CATALOG,PRIVILEGE_TYPE; +GRANTEE TABLE_CATALOG PRIVILEGE_TYPE IS_GRANTABLE +'mysqltest_3'@'localhost' NULL USAGE NO update mysqltest_1.t1, mysqltest_1.t2 set q=10 where b=1; ERROR 42000: UPDATE command denied to user 'mysqltest_3'@'localhost' for column 'q' in table 't1' update mysqltest_1.t2, mysqltest_2.t2 set d=20 where d=1; diff --git a/mysql-test/r/group_min_max.result b/mysql-test/r/group_min_max.result index 6370f7699b3..d62586dba85 100644 --- a/mysql-test/r/group_min_max.result +++ b/mysql-test/r/group_min_max.result @@ -1981,46 +1981,7 @@ a b c d -create table t4 ( -pk_col int auto_increment primary key, a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' ' -) engine=innodb; -insert into t4 (a1, a2, b, c, d, dummy) select * from t1; -create index idx12672_0 on t4 (a1); -create index idx12672_1 on t4 (a1,a2,b,c); -create index idx12672_2 on t4 (a1,a2,b); -analyze table t1; -Table Op Msg_type Msg_text -test.t1 analyze status Table is already up to date -select distinct a1 from t4 where pk_col not in (1,2,3,4); -a1 -a -b -c -d -drop table t1,t2,t3,t4; -create table t1 ( -a varchar(30), b varchar(30), primary key(a), key(b) -) engine=innodb; -select distinct a from t1; -a -drop table t1; -create table t1(a int, key(a)) engine=innodb; -insert into t1 values(1); -select a, count(a) from t1 group by a with rollup; -a count(a) -1 1 -NULL 1 -drop table t1; -create table t1 (f1 int, f2 char(1), primary key(f1,f2)) engine=innodb; -insert into t1 values ( 1,"e"),(2,"a"),( 3,"c"),(4,"d"); -alter table t1 drop primary key, add primary key (f2, f1); -explain select distinct f1 a, f1 b from t1; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL PRIMARY 5 NULL 4 Using index; Using temporary -explain select distinct f1, f2 from t1; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL PRIMARY 5 NULL 3 Using index for group-by; Using temporary -drop table t1; +drop table t1,t2,t3; create table t1 (c1 int not null,c2 int not null, primary key(c1,c2)); insert into t1 (c1,c2) values (10,1),(10,2),(10,3),(20,4),(20,5),(20,6),(30,7),(30,8),(30,9); @@ -2116,3 +2077,25 @@ COUNT(DISTINCT a) 1 DROP TABLE t1; DROP PROCEDURE a; +CREATE TABLE t1 (a varchar(64) NOT NULL default '', PRIMARY KEY(a)); +INSERT INTO t1 (a) VALUES +(''), ('CENTRAL'), ('EASTERN'), ('GREATER LONDON'), +('NORTH CENTRAL'), ('NORTH EAST'), ('NORTH WEST'), ('SCOTLAND'), +('SOUTH EAST'), ('SOUTH WEST'), ('WESTERN'); +EXPLAIN SELECT DISTINCT a,a FROM t1 ORDER BY a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range NULL PRIMARY 66 NULL 12 Using index for group-by +SELECT DISTINCT a,a FROM t1 ORDER BY a; +a a + +CENTRAL CENTRAL +EASTERN EASTERN +GREATER LONDON GREATER LONDON +NORTH CENTRAL NORTH CENTRAL +NORTH EAST NORTH EAST +NORTH WEST NORTH WEST +SCOTLAND SCOTLAND +SOUTH EAST SOUTH EAST +SOUTH WEST SOUTH WEST +WESTERN WESTERN +DROP TABLE t1; diff --git a/mysql-test/r/having.result b/mysql-test/r/having.result index a37f260ff31..68b13b5fc0a 100644 --- a/mysql-test/r/having.result +++ b/mysql-test/r/having.result @@ -12,7 +12,7 @@ explain extended select count(a) as b from t1 where a=0 having b >=0; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables Warnings: -Note 1003 select count(`test`.`t1`.`a`) AS `b` from `test`.`t1` where 0 having (count(`test`.`t1`.`a`) >= 0) +Note 1003 select count(`test`.`t1`.`a`) AS `b` from `test`.`t1` where 0 having (`b` >= 0) drop table t1; CREATE TABLE t1 ( raw_id int(10) NOT NULL default '0', diff --git a/mysql-test/r/heap.result b/mysql-test/r/heap.result index 5a2d07db5e6..a75f6c96b20 100644 --- a/mysql-test/r/heap.result +++ b/mysql-test/r/heap.result @@ -556,9 +556,9 @@ t1 CREATE TABLE `t1` ( `v` varchar(10) DEFAULT NULL, `c` char(10) DEFAULT NULL, `t` varchar(50) DEFAULT NULL, - KEY `v` USING BTREE (`v`), - KEY `c` USING BTREE (`c`), - KEY `t` USING BTREE (`t`(10)) + KEY `v` (`v`) USING BTREE, + KEY `c` (`c`) USING BTREE, + KEY `t` (`t`(10)) USING BTREE ) ENGINE=MEMORY DEFAULT CHARSET=latin1 select count(*) from t1; count(*) @@ -718,3 +718,16 @@ Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length I t1 MEMORY 10 Fixed 0 11 0 # 0 0 NULL NULL NULL NULL latin1_swedish_ci NULL t2 MEMORY 10 Fixed 0 12 0 # 0 0 NULL NULL NULL NULL latin1_swedish_ci NULL drop table t1, t2; +CREATE TABLE t1(a VARCHAR(1), b VARCHAR(2), c VARCHAR(256), +KEY(a), KEY(b), KEY(c)) ENGINE=MEMORY; +INSERT INTO t1 VALUES('a','aa',REPEAT('a', 256)),('a','aa',REPEAT('a',256)); +SELECT COUNT(*) FROM t1 WHERE a='a'; +COUNT(*) +2 +SELECT COUNT(*) FROM t1 WHERE b='aa'; +COUNT(*) +2 +SELECT COUNT(*) FROM t1 WHERE c=REPEAT('a',256); +COUNT(*) +2 +DROP TABLE t1; diff --git a/mysql-test/r/heap_btree.result b/mysql-test/r/heap_btree.result index 7b944558a62..4c7ea0eae7b 100644 --- a/mysql-test/r/heap_btree.result +++ b/mysql-test/r/heap_btree.result @@ -256,3 +256,6 @@ SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() INDEX_LENGTH 21 DROP TABLE t1; +CREATE TABLE t1 (a INT, UNIQUE USING BTREE(a)) ENGINE=MEMORY; +INSERT INTO t1 VALUES(NULL),(NULL); +DROP TABLE t1; diff --git a/mysql-test/r/im_cmd_line.result b/mysql-test/r/im_cmd_line.result new file mode 100644 index 00000000000..5b289549a3f --- /dev/null +++ b/mysql-test/r/im_cmd_line.result @@ -0,0 +1,40 @@ +--> Listing users... +im_admin + +==> Adding user 'testuser'... + +--> IM password file: +testuser:*0D3CED9BEC10A777AEC23CCC353A8C08A633045E +im_admin:*598D51AD2DFF7792045D6DF3DDF9AA1AF737B295 +--> EOF + +--> Printing out line for 'testuser'... +testuser:*0D3CED9BEC10A777AEC23CCC353A8C08A633045E + +--> Listing users... +im_admin +testuser + +==> Changing the password of 'testuser'... + +--> IM password file: +im_admin:*598D51AD2DFF7792045D6DF3DDF9AA1AF737B295 +testuser:*39C549BDECFBA8AFC3CE6B948C9359A0ECE08DE2 +--> EOF + +--> Printing out line for 'testuser'... +testuser:*39C549BDECFBA8AFC3CE6B948C9359A0ECE08DE2 + +--> Listing users... +testuser +im_admin + +==> Dropping user 'testuser'... + +--> IM password file: +im_admin:*598D51AD2DFF7792045D6DF3DDF9AA1AF737B295 +--> EOF + +--> Listing users... +im_admin + diff --git a/mysql-test/r/im_daemon_life_cycle.result b/mysql-test/r/im_daemon_life_cycle.result index d0a76b450fe..29c9ea2047d 100644 --- a/mysql-test/r/im_daemon_life_cycle.result +++ b/mysql-test/r/im_daemon_life_cycle.result @@ -1,5 +1,5 @@ SHOW INSTANCES; -instance_name status +instance_name state mysqld1 online mysqld2 offline Killing the process... diff --git a/mysql-test/r/im_instance_conf.result b/mysql-test/r/im_instance_conf.result new file mode 100644 index 00000000000..efda9439f38 --- /dev/null +++ b/mysql-test/r/im_instance_conf.result @@ -0,0 +1,196 @@ +-------------------------------------------------------------------- +server_id = 1 +server_id = 2 +-------------------------------------------------------------------- +SHOW INSTANCES; +instance_name state +mysqld1 online +mysqld2 offline + +---> connection: mysql1_con +SHOW VARIABLES LIKE 'server_id'; +Variable_name Value +server_id 1 + +---> connection: default +CREATE INSTANCE mysqld3; +SHOW INSTANCES; +instance_name state +mysqld3 offline +mysqld2 offline +mysqld1 online +-------------------------------------------------------------------- +server_id = 1 +server_id = 2 +-------------------------------------------------------------------- +CREATE INSTANCE mysqld1; +ERROR HY000: Instance already exists +CREATE INSTANCE mysqld2; +ERROR HY000: Instance already exists +CREATE INSTANCE mysqld3; +ERROR HY000: Instance already exists +-------------------------------------------------------------------- +nonguarded +-------------------------------------------------------------------- +CREATE INSTANCE mysqld4 nonguarded; +SHOW INSTANCES; +instance_name state +mysqld3 offline +mysqld4 offline +mysqld1 online +mysqld2 offline +-------------------------------------------------------------------- +nonguarded +nonguarded +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +CREATE INSTANCE mysqld5 test-A = 000, test-B = test; +SHOW INSTANCES; +instance_name state +mysqld1 online +mysqld4 offline +mysqld5 offline +mysqld2 offline +mysqld3 offline +-------------------------------------------------------------------- +test-A=000 +-------------------------------------------------------------------- +test-B=test +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +CREATE INSTANCE mysqld6 test-C1 = 10 , test-C2 = 02 ; +SHOW INSTANCES; +instance_name state +mysqld1 online +mysqld2 offline +mysqld5 offline +mysqld6 offline +mysqld3 offline +mysqld4 offline +-------------------------------------------------------------------- +test-C1=10 +-------------------------------------------------------------------- +test-C2=02 +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +CREATE INSTANCE mysqld7 test-D = test-D-value ; +ERROR 42000: You have an error in your command syntax. Check the manual that corresponds to your MySQL Instance Manager version for the right syntax to use +SHOW INSTANCES; +instance_name state +mysqld1 online +mysqld2 offline +mysqld5 offline +mysqld6 offline +mysqld3 offline +mysqld4 offline +CREATE INSTANCE mysqld8 test-E 0 ; +ERROR 42000: You have an error in your command syntax. Check the manual that corresponds to your MySQL Instance Manager version for the right syntax to use +SHOW INSTANCES; +instance_name state +mysqld1 online +mysqld2 offline +mysqld5 offline +mysqld6 offline +mysqld3 offline +mysqld4 offline +CREATE INSTANCE mysqld8 test-F = ; +ERROR 42000: You have an error in your command syntax. Check the manual that corresponds to your MySQL Instance Manager version for the right syntax to use +SHOW INSTANCES; +instance_name state +mysqld1 online +mysqld2 offline +mysqld5 offline +mysqld6 offline +mysqld3 offline +mysqld4 offline +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +CREATE INSTANCE mysqld9 test-1=" hello world ", test-2=' '; +SHOW INSTANCES; +instance_name state +mysqld1 online +mysqld2 offline +mysqld5 offline +mysqld6 offline +mysqld3 offline +mysqld4 offline +mysqld9 offline +CREATE INSTANCE mysqld9a test-3='\b\babc\sdef'; +SHOW INSTANCES; +instance_name state +mysqld1 online +mysqld9a offline +mysqld5 offline +mysqld6 offline +mysqld3 offline +mysqld4 offline +mysqld9 offline +mysqld2 offline +CREATE INSTANCE mysqld9b test-4='abc\tdef', test-5='abc\ndef'; +SHOW INSTANCES; +instance_name state +mysqld9b offline +mysqld9a offline +mysqld5 offline +mysqld6 offline +mysqld3 offline +mysqld4 offline +mysqld9 offline +mysqld2 offline +mysqld1 online +CREATE INSTANCE mysqld9c test-6="abc\rdef", test-7="abc\\def"; +SHOW INSTANCES; +instance_name state +mysqld9b offline +mysqld6 offline +mysqld5 offline +mysqld9c offline +mysqld3 offline +mysqld4 offline +mysqld9 offline +mysqld2 offline +mysqld1 online +mysqld9a offline +CREATE INSTANCE mysqld10 test-bad=' \ '; +ERROR 42000: You have an error in your command syntax. Check the manual that corresponds to your MySQL Instance Manager version for the right syntax to use +SHOW INSTANCES; +instance_name state +mysqld9b offline +mysqld6 offline +mysqld5 offline +mysqld9c offline +mysqld3 offline +mysqld4 offline +mysqld9 offline +mysqld2 offline +mysqld1 online +mysqld9a offline +-------------------------------------------------------------------- +test-1= hello world +-------------------------------------------------------------------- +test-2= +-------------------------------------------------------------------- +test-3=abc def +-------------------------------------------------------------------- +test-4=abc def +-------------------------------------------------------------------- +test-5=abc +-------------------------------------------------------------------- +test-6=abc
def +-------------------------------------------------------------------- +test-7=abc\def +-------------------------------------------------------------------- +-------------------------------------------------------------------- +CREATE INSTANCE qqq1; +ERROR HY000: Malformed instance name. diff --git a/mysql-test/r/im_life_cycle.result b/mysql-test/r/im_life_cycle.result index e208ccb9f00..876fbb38eee 100644 --- a/mysql-test/r/im_life_cycle.result +++ b/mysql-test/r/im_life_cycle.result @@ -1,69 +1,93 @@ + +-------------------------------------------------------------------- +-- 1.1.1. +-------------------------------------------------------------------- SHOW INSTANCES; -instance_name status +instance_name state mysqld1 online mysqld2 offline -SHOW INSTANCE STATUS mysqld1; -instance_name status version_number version -mysqld1 online VERSION_NUMBER VERSION -SHOW INSTANCE STATUS mysqld2; -instance_name status version_number version -mysqld2 offline VERSION_NUMBER VERSION + +-------------------------------------------------------------------- +-- 1.1.2. +-------------------------------------------------------------------- START INSTANCE mysqld2; SHOW INSTANCES; -instance_name status +instance_name state mysqld1 online mysqld2 online -SHOW INSTANCE STATUS mysqld1; -instance_name status version_number version -mysqld1 online VERSION_NUMBER VERSION -SHOW INSTANCE STATUS mysqld2; -instance_name status version_number version -mysqld2 online VERSION_NUMBER VERSION SHOW VARIABLES LIKE 'port'; Variable_name Value -port IM_MYSQLD1_PORT +port IM_MYSQLD2_PORT + +-------------------------------------------------------------------- +-- 1.1.3. +-------------------------------------------------------------------- STOP INSTANCE mysqld2; SHOW INSTANCES; -instance_name status +instance_name state mysqld1 online mysqld2 offline SHOW INSTANCE STATUS mysqld1; -instance_name status version_number version -mysqld1 online VERSION_NUMBER VERSION +instance_name state version_number version mysqld_compatible +mysqld1 online VERSION_NUMBER VERSION no SHOW INSTANCE STATUS mysqld2; -instance_name status version_number version -mysqld2 offline VERSION_NUMBER VERSION +instance_name state version_number version mysqld_compatible +mysqld2 offline VERSION_NUMBER VERSION no + +-------------------------------------------------------------------- +-- 1.1.4. +-------------------------------------------------------------------- START INSTANCE mysqld3; ERROR HY000: Bad instance name. Check that the instance with such a name exists START INSTANCE mysqld1; ERROR HY000: The instance is already started + +-------------------------------------------------------------------- +-- 1.1.5. +-------------------------------------------------------------------- STOP INSTANCE mysqld3; ERROR HY000: Bad instance name. Check that the instance with such a name exists + +-------------------------------------------------------------------- +-- 1.1.6. +-------------------------------------------------------------------- SHOW INSTANCES; -instance_name status +instance_name state mysqld1 online mysqld2 offline Killing the process... Sleeping... Success: the process was restarted. + +-------------------------------------------------------------------- +-- 1.1.7. +-------------------------------------------------------------------- SHOW INSTANCES; -instance_name status +instance_name state mysqld1 online mysqld2 offline START INSTANCE mysqld2; SHOW INSTANCES; -instance_name status +instance_name state mysqld1 online mysqld2 online Killing the process... Sleeping... Success: the process was killed. SHOW INSTANCES; -instance_name status +instance_name state mysqld1 online mysqld2 offline + +-------------------------------------------------------------------- +-- 1.1.8. +-------------------------------------------------------------------- SHOW INSTANCE STATUS; ERROR 42000: You have an error in your command syntax. Check the manual that corresponds to your MySQL Instance Manager version for the right syntax to use + +-------------------------------------------------------------------- +-- BUG#12813 +-------------------------------------------------------------------- START INSTANCE mysqld1,mysqld2,mysqld3; ERROR 42000: You have an error in your command syntax. Check the manual that corresponds to your MySQL Instance Manager version for the right syntax to use STOP INSTANCE mysqld1,mysqld2,mysqld3; diff --git a/mysql-test/r/im_options.result b/mysql-test/r/im_options.result new file mode 100644 index 00000000000..8039333b7d9 --- /dev/null +++ b/mysql-test/r/im_options.result @@ -0,0 +1,150 @@ +-------------------------------------------------------------------- +server_id = 1 +server_id = 2 +-------------------------------------------------------------------- +SHOW VARIABLES LIKE 'server_id'; +Variable_name Value +server_id 1 +SHOW INSTANCES; +instance_name state +mysqld1 starting +mysqld2 offline +UNSET mysqld1.server_id; +ERROR HY000: The instance is active. Stop the instance first +SET mysqld1.server_id = 11; +ERROR HY000: The instance is active. Stop the instance first +CREATE INSTANCE mysqld3 datadir = '/'; +START INSTANCE mysqld3; +UNSET mysqld3.server_id; +ERROR HY000: The instance is active. Stop the instance first +SET mysqld3.server_id = 11; +ERROR HY000: The instance is active. Stop the instance first +STOP INSTANCE mysqld3; +SHOW INSTANCE STATUS mysqld3; +instance_name state version_number version mysqld_compatible +mysqld3 offline VERSION_NUMBER VERSION no +UNSET mysqld2.server_id; +UNSET mysqld2.server_id; +SHOW INSTANCE OPTIONS mysqld2; +option_name value +instance_name option_value +socket option_value +pid-file option_value +port option_value +datadir option_value +log option_value +log-error option_value +log-slow-queries option_value +language option_value +character-sets-dir option_value +basedir option_value +skip-stack-trace option_value +skip-innodb option_value +skip-bdb option_value +skip-ndbcluster option_value +nonguarded option_value +log-output option_value +SET mysqld2.server_id = 2; +SET mysqld2.server_id = 2; +SHOW INSTANCE OPTIONS mysqld2; +option_name value +instance_name option_value +socket option_value +pid-file option_value +port option_value +datadir option_value +log option_value +log-error option_value +log-slow-queries option_value +language option_value +character-sets-dir option_value +basedir option_value +skip-stack-trace option_value +skip-innodb option_value +skip-bdb option_value +skip-ndbcluster option_value +nonguarded option_value +log-output option_value +server_id option_value +UNSET mysqld2.server_id = 11; +ERROR 42000: You have an error in your command syntax. Check the manual that corresponds to your MySQL Instance Manager version for the right syntax to use +SET mysqld2.aaa, mysqld3.bbb, mysqld2.ccc = 0010, mysqld3.ddd = 0020; +-------------------------------------------------------------------- +aaa +-------------------------------------------------------------------- +bbb +-------------------------------------------------------------------- +ccc=0010 +-------------------------------------------------------------------- +ddd=0020 +-------------------------------------------------------------------- +UNSET mysqld2.aaa, mysqld3.bbb, mysqld2.ccc, mysqld3.ddd; +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +SET mysqld2.aaa, mysqld3.bbb, mysqld.ccc = 0010; +ERROR HY000: Bad instance name. Check that the instance with such a name exists +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +SET mysqld2.aaa, mysqld3.bbb, mysqld1.ccc = 0010; +ERROR HY000: The instance is active. Stop the instance first +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +UNSET mysqld2.server_id, mysqld3.server_id, mysqld.ccc; +ERROR HY000: Bad instance name. Check that the instance with such a name exists +-------------------------------------------------------------------- +server_id = 1 +server_id=2 +-------------------------------------------------------------------- +UNSET mysqld2.server_id, mysqld3.server_id, mysqld1.ccc; +ERROR HY000: The instance is active. Stop the instance first +-------------------------------------------------------------------- +server_id = 1 +server_id=2 +-------------------------------------------------------------------- +DROP INSTANCE mysqld3; +SET mysqld2.server_id=222; +SET mysqld2.server_id = 222; +SET mysqld2.server_id = 222 ; +SET mysqld2 . server_id = 222 ; +SET mysqld2 . server_id = 222 , mysqld2 . aaa , mysqld2 . bbb ; +-------------------------------------------------------------------- +server_id = 1 +server_id=222 +-------------------------------------------------------------------- +aaa +-------------------------------------------------------------------- +bbb +-------------------------------------------------------------------- +UNSET mysqld2 . aaa , mysqld2 . bbb ; +-------------------------------------------------------------------- +server_id = 1 +server_id=222 +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +-------------------------------------------------------------------- +server_id = 1 +server_id=222 +-------------------------------------------------------------------- +SHOW VARIABLES LIKE 'server_id'; +Variable_name Value +server_id 1 +SHOW INSTANCES; +instance_name state +mysqld1 online +mysqld2 offline +FLUSH INSTANCES; +ERROR HY000: At least one instance is active. Stop all instances first +STOP INSTANCE mysqld1; +SHOW INSTANCES; +instance_name state +mysqld1 offline +mysqld2 offline +FLUSH INSTANCES; diff --git a/mysql-test/r/im_options_set.result b/mysql-test/r/im_options_set.result deleted file mode 100644 index 0d2fa699fc7..00000000000 --- a/mysql-test/r/im_options_set.result +++ /dev/null @@ -1,20 +0,0 @@ -server_id =1 -server_id =2 -SHOW VARIABLES LIKE 'server_id'; -Variable_name Value -server_id 1 -SET mysqld1.server_id = 11; -server_id =11 -server_id =2 -SHOW VARIABLES LIKE 'server_id'; -Variable_name Value -server_id 1 -SET mysqld2.server_id = 12; -server_id =11 -server_id =12 -FLUSH INSTANCES; -server_id =11 -server_id =12 -SHOW VARIABLES LIKE 'server_id'; -Variable_name Value -server_id 1 diff --git a/mysql-test/r/im_options_unset.result b/mysql-test/r/im_options_unset.result deleted file mode 100644 index 834152c35d2..00000000000 --- a/mysql-test/r/im_options_unset.result +++ /dev/null @@ -1,15 +0,0 @@ -server_id =1 -server_id =2 -SHOW VARIABLES LIKE 'server_id'; -Variable_name Value -server_id 1 -UNSET mysqld1.server_id; -server_id =2 -SHOW VARIABLES LIKE 'server_id'; -Variable_name Value -server_id 1 -UNSET mysqld2.server_id; -FLUSH INSTANCES; -SHOW VARIABLES LIKE 'server_id'; -Variable_name Value -server_id 1 diff --git a/mysql-test/r/im_utils.result b/mysql-test/r/im_utils.result index 504b2efe4af..ae8e03bf8ea 100644 --- a/mysql-test/r/im_utils.result +++ b/mysql-test/r/im_utils.result @@ -1,11 +1,10 @@ SHOW INSTANCES; -instance_name status +instance_name state mysqld1 online mysqld2 offline SHOW INSTANCE OPTIONS mysqld1; option_name value instance_name VALUE -mysqld-path VALUE socket VALUE pid-file VALUE port VALUE @@ -25,8 +24,6 @@ log-output VALUE SHOW INSTANCE OPTIONS mysqld2; option_name value instance_name VALUE -mysqld-path VALUE -nonguarded VALUE socket VALUE pid-file VALUE port VALUE @@ -42,6 +39,7 @@ skip-stack-trace VALUE skip-innodb VALUE skip-bdb VALUE skip-ndbcluster VALUE +nonguarded VALUE log-output VALUE START INSTANCE mysqld2; STOP INSTANCE mysqld2; diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index 898dd64b794..603b7815d5b 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -1129,11 +1129,6 @@ DROP TABLE t1; DROP VIEW v1; DROP FUNCTION func1; DROP FUNCTION func2; -create database mysqltest; -create table mysqltest.t1(a int); -select table_schema from information_schema.tables where table_schema='mysqltest'; -table_schema -drop database mysqltest; select column_type, group_concat(table_schema, '.', table_name), count(*) as num from information_schema.columns where table_schema='information_schema' and @@ -1142,6 +1137,23 @@ group by column_type order by num; column_type group_concat(table_schema, '.', table_name) num varchar(7) information_schema.ROUTINES,information_schema.VIEWS 2 varchar(20) information_schema.COLUMNS,information_schema.FILES,information_schema.FILES,information_schema.PLUGINS,information_schema.PLUGINS,information_schema.PLUGINS 6 +create table t1(f1 char(1) not null, f2 char(9) not null) +default character set utf8; +select CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH from +information_schema.columns where table_schema='test' and table_name = 't1'; +CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH +1 3 +9 27 +drop table t1; +use mysql; +INSERT INTO `proc` VALUES ('test','','PROCEDURE','','SQL','CONTAINS_SQL', +'NO','DEFINER','','','BEGIN\r\n \r\nEND','root@%','2006-03-02 18:40:03', +'2006-03-02 18:40:03','',''); +select routine_name from information_schema.routines; +routine_name + +delete from proc where name=''; +use test; select * from information_schema.engines WHERE ENGINE="MyISAM"; ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS MyISAM ENABLED Default engine as of MySQL 3.23 with great performance NO NO NO @@ -1150,3 +1162,16 @@ select user,db from information_schema.processlist; user db user3148 test drop user user3148@localhost; +grant select on test.* to mysqltest_1@localhost; +create table t1 (id int); +create view v1 as select * from t1; +create definer = mysqltest_1@localhost +sql security definer view v2 as select 1; +select * from information_schema.views +where table_name='v1' or table_name='v2'; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME VIEW_DEFINITION CHECK_OPTION IS_UPDATABLE DEFINER SECURITY_TYPE +NULL test v1 NONE YES root@localhost DEFINER +NULL test v2 select 1 AS `1` NONE NO mysqltest_1@localhost DEFINER +drop view v1, v2; +drop table t1; +drop user mysqltest_1@localhost; diff --git a/mysql-test/r/information_schema_chmod.result b/mysql-test/r/information_schema_chmod.result new file mode 100644 index 00000000000..36124559439 --- /dev/null +++ b/mysql-test/r/information_schema_chmod.result @@ -0,0 +1,5 @@ +create database mysqltest; +create table mysqltest.t1(a int); +select table_schema from information_schema.tables where table_schema='mysqltest'; +table_schema +drop database mysqltest; diff --git a/mysql-test/r/information_schema_db.result b/mysql-test/r/information_schema_db.result index 37537e257da..5919e0f071d 100644 --- a/mysql-test/r/information_schema_db.result +++ b/mysql-test/r/information_schema_db.result @@ -1,3 +1,7 @@ +drop table if exists t1,t2; +drop view if exists v1,v2; +drop function if exists f1; +drop function if exists f2; use INFORMATION_SCHEMA; show tables; Tables_in_information_schema @@ -31,10 +35,12 @@ TABLE_CONSTRAINTS TABLE_PRIVILEGES TRIGGERS create database `inf%`; +create database mbase; use `inf%`; show tables; Tables_in_inf% grant all privileges on `inf%`.* to 'mysqltest_1'@'localhost'; +grant all privileges on `mbase`.* to 'mysqltest_1'@'localhost'; create table t1 (f1 int); create function func1(curr_int int) returns int begin @@ -43,9 +49,58 @@ select max(f1) from t1 into ret_val; return ret_val; end| create view v1 as select f1 from t1 where f1 = func1(f1); +create function func2() returns int return 1; +use mbase; +create procedure p1 () +begin +select table_name from information_schema.key_column_usage +order by table_name; +end| +create table t1 +(f1 int(10) unsigned not null, +f2 varchar(100) not null, +primary key (f1), unique key (f2)); select * from information_schema.tables; +call mbase.p1(); +call mbase.p1(); +call mbase.p1(); +use `inf%`; drop user mysqltest_1@localhost; +drop table t1; +select table_name, table_type, table_comment from information_schema.tables +where table_schema='inf%' and func2(); +table_name table_type table_comment +v1 VIEW View 'inf%.v1' references invalid table(s) or column(s) or function(s) or define +select table_name, table_type, table_comment from information_schema.tables +where table_schema='inf%' and func2(); +table_name table_type table_comment +v1 VIEW View 'inf%.v1' references invalid table(s) or column(s) or function(s) or define drop view v1; drop function func1; -drop table t1; +drop function func2; drop database `inf%`; +drop procedure mbase.p1; +drop database mbase; +use test; +create table t1 (i int); +create function f1 () returns int return (select max(i) from t1); +create view v1 as select f1(); +create table t2 (id int); +create function f2 () returns int return (select max(i) from t2); +create view v2 as select f2(); +drop table t2; +select table_name, table_type, table_comment from information_schema.tables +where table_schema='test'; +table_name table_type table_comment +t1 BASE TABLE +v1 VIEW VIEW +v2 VIEW View 'test.v2' references invalid table(s) or column(s) or function(s) or define +drop table t1; +select table_name, table_type, table_comment from information_schema.tables +where table_schema='test'; +table_name table_type table_comment +v1 VIEW View 'test.v1' references invalid table(s) or column(s) or function(s) or define +v2 VIEW View 'test.v2' references invalid table(s) or column(s) or function(s) or define +drop function f1; +drop function f2; +drop view v1, v2; diff --git a/mysql-test/r/information_schema_part.result b/mysql-test/r/information_schema_part.result index cf49abf888a..ef3ee19656b 100644 --- a/mysql-test/r/information_schema_part.result +++ b/mysql-test/r/information_schema_part.result @@ -111,3 +111,32 @@ NULL test t1 p0 NULL 1 NULL LINEAR HASH NULL month(f1) NULL NULL 0 0 0 # 1024 0 NULL test t1 p1 NULL 2 NULL LINEAR HASH NULL month(f1) NULL NULL 0 0 0 # 1024 0 # # NULL NULL default 0 default NULL test t1 p2 NULL 3 NULL LINEAR HASH NULL month(f1) NULL NULL 0 0 0 # 1024 0 # # NULL NULL default 0 default drop table t1; +create table t1 (a int) +PARTITION BY RANGE (a) +SUBPARTITION BY LINEAR HASH (a) +(PARTITION p0 VALUES LESS THAN (10)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (a) SUBPARTITION BY LINEAR HASH (a) (PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM) +select SUBPARTITION_METHOD FROM information_schema.partitions WHERE +table_schema="test" AND table_name="t1"; +SUBPARTITION_METHOD +LINEAR HASH +drop table t1; +create table t1 (a int) +PARTITION BY LIST (a) +(PARTITION p0 VALUES IN +(10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, +32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY LIST (a) (PARTITION p0 VALUES IN (10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53) ENGINE = MyISAM) +SELECT PARTITION_DESCRIPTION FROM information_schema.partitions WHERE +table_schema = "test" AND table_name = "t1"; +PARTITION_DESCRIPTION +10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53 +drop table t1; diff --git a/mysql-test/r/innodb.result b/mysql-test/r/innodb.result index 7ae87e42b8c..eca6d148567 100644 --- a/mysql-test/r/innodb.result +++ b/mysql-test/r/innodb.result @@ -1822,7 +1822,7 @@ Variable_name Value innodb_sync_spin_loops 20 show variables like "innodb_thread_concurrency"; Variable_name Value -innodb_thread_concurrency 20 +innodb_thread_concurrency 8 set global innodb_thread_concurrency=1001; show variables like "innodb_thread_concurrency"; Variable_name Value diff --git a/mysql-test/r/innodb_mysql.result b/mysql-test/r/innodb_mysql.result index fe9940f753f..918f1c2c7c5 100644 --- a/mysql-test/r/innodb_mysql.result +++ b/mysql-test/r/innodb_mysql.result @@ -1,4 +1,273 @@ -drop table if exists t1.t2; +drop table if exists t1,t2,t1m,t1i,t2m,t2i,t4; +create table t1 ( +c_id int(11) not null default '0', +org_id int(11) default null, +unique key contacts$c_id (c_id), +key contacts$org_id (org_id) +) engine=innodb; +insert into t1 values +(2,null),(120,null),(141,null),(218,7), (128,1), +(151,2),(234,2),(236,2),(243,2),(255,2),(259,2),(232,3),(235,3),(238,3), +(246,3),(253,3),(269,3),(285,3),(291,3),(293,3),(131,4),(230,4),(231,4); +create table t2 ( +slai_id int(11) not null default '0', +owner_tbl int(11) default null, +owner_id int(11) default null, +sla_id int(11) default null, +inc_web int(11) default null, +inc_email int(11) default null, +inc_chat int(11) default null, +inc_csr int(11) default null, +inc_total int(11) default null, +time_billed int(11) default null, +activedate timestamp null default null, +expiredate timestamp null default null, +state int(11) default null, +sla_set int(11) default null, +unique key t2$slai_id (slai_id), +key t2$owner_id (owner_id), +key t2$sla_id (sla_id) +) engine=innodb; +insert into t2(slai_id, owner_tbl, owner_id, sla_id) values +(1,3,1,1), (3,3,10,2), (4,3,3,6), (5,3,2,5), (6,3,8,3), (7,3,9,7), +(8,3,6,8), (9,3,4,9), (10,3,5,10), (11,3,11,11), (12,3,7,12); +flush tables; +select si.slai_id +from t1 c join t2 si on +((si.owner_tbl = 3 and si.owner_id = c.org_id) or +( si.owner_tbl = 2 and si.owner_id = c.c_id)) +where +c.c_id = 218 and expiredate is null; +slai_id +12 +select * from t1 where org_id is null; +c_id org_id +2 NULL +120 NULL +141 NULL +select si.slai_id +from t1 c join t2 si on +((si.owner_tbl = 3 and si.owner_id = c.org_id) or +( si.owner_tbl = 2 and si.owner_id = c.c_id)) +where +c.c_id = 218 and expiredate is null; +slai_id +12 +drop table t1, t2; +create table t1m (a int) engine=myisam; +create table t1i (a int) engine=innodb; +create table t2m (a int) engine=myisam; +create table t2i (a int) engine=innodb; +insert into t2m values (5); +insert into t2i values (5); +select min(a) from t1m; +min(a) +NULL +select min(7) from t1m; +min(7) +NULL +select min(7) from DUAL; +min(7) +NULL +explain select min(7) from t2m join t1m; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +select min(7) from t2m join t1m; +min(7) +NULL +select max(a) from t1m; +max(a) +NULL +select max(7) from t1m; +max(7) +NULL +select max(7) from DUAL; +max(7) +NULL +explain select max(7) from t2m join t1m; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +select max(7) from t2m join t1m; +max(7) +NULL +select 1, min(a) from t1m where a=99; +1 min(a) +1 NULL +select 1, min(a) from t1m where 1=99; +1 min(a) +1 NULL +select 1, min(1) from t1m where a=99; +1 min(1) +1 NULL +select 1, min(1) from t1m where 1=99; +1 min(1) +1 NULL +select 1, max(a) from t1m where a=99; +1 max(a) +1 NULL +select 1, max(a) from t1m where 1=99; +1 max(a) +1 NULL +select 1, max(1) from t1m where a=99; +1 max(1) +1 NULL +select 1, max(1) from t1m where 1=99; +1 max(1) +1 NULL +select min(a) from t1i; +min(a) +NULL +select min(7) from t1i; +min(7) +NULL +select min(7) from DUAL; +min(7) +NULL +explain select min(7) from t2i join t1i; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2i ALL NULL NULL NULL NULL 1 +1 SIMPLE t1i ALL NULL NULL NULL NULL 1 +select min(7) from t2i join t1i; +min(7) +NULL +select max(a) from t1i; +max(a) +NULL +select max(7) from t1i; +max(7) +NULL +select max(7) from DUAL; +max(7) +NULL +explain select max(7) from t2i join t1i; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2i ALL NULL NULL NULL NULL 1 +1 SIMPLE t1i ALL NULL NULL NULL NULL 1 +select max(7) from t2i join t1i; +max(7) +NULL +select 1, min(a) from t1i where a=99; +1 min(a) +1 NULL +select 1, min(a) from t1i where 1=99; +1 min(a) +1 NULL +select 1, min(1) from t1i where a=99; +1 min(1) +1 NULL +select 1, min(1) from t1i where 1=99; +1 min(1) +1 NULL +select 1, max(a) from t1i where a=99; +1 max(a) +1 NULL +select 1, max(a) from t1i where 1=99; +1 max(a) +1 NULL +select 1, max(1) from t1i where a=99; +1 max(1) +1 NULL +select 1, max(1) from t1i where 1=99; +1 max(1) +1 NULL +explain select count(*), min(7), max(7) from t1m, t1i; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1m system NULL NULL NULL NULL 0 const row not found +1 SIMPLE t1i ALL NULL NULL NULL NULL 1 +select count(*), min(7), max(7) from t1m, t1i; +count(*) min(7) max(7) +0 NULL NULL +explain select count(*), min(7), max(7) from t1m, t2i; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1m system NULL NULL NULL NULL 0 const row not found +1 SIMPLE t2i ALL NULL NULL NULL NULL 1 +select count(*), min(7), max(7) from t1m, t2i; +count(*) min(7) max(7) +0 NULL NULL +explain select count(*), min(7), max(7) from t2m, t1i; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2m system NULL NULL NULL NULL 1 +1 SIMPLE t1i ALL NULL NULL NULL NULL 1 +select count(*), min(7), max(7) from t2m, t1i; +count(*) min(7) max(7) +0 NULL NULL +drop table t1m, t1i, t2m, t2i; +create table t1 ( +a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' ' +); +insert into t1 (a1, a2, b, c, d) values +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'), +('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'), +('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'), +('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'), +('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'), +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'), +('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'), +('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'), +('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'), +('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'); +create table t4 ( +pk_col int auto_increment primary key, a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' ' +) engine=innodb; +insert into t4 (a1, a2, b, c, d, dummy) select * from t1; +create index idx12672_0 on t4 (a1); +create index idx12672_1 on t4 (a1,a2,b,c); +create index idx12672_2 on t4 (a1,a2,b); +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +select distinct a1 from t4 where pk_col not in (1,2,3,4); +a1 +a +b +c +d +drop table t1,t4; +create table t1 ( +a varchar(30), b varchar(30), primary key(a), key(b) +) engine=innodb; +select distinct a from t1; +a +drop table t1; +create table t1(a int, key(a)) engine=innodb; +insert into t1 values(1); +select a, count(a) from t1 group by a with rollup; +a count(a) +1 1 +NULL 1 +drop table t1; +create table t1 (f1 int, f2 char(1), primary key(f1,f2)) engine=innodb; +insert into t1 values ( 1,"e"),(2,"a"),( 3,"c"),(4,"d"); +alter table t1 drop primary key, add primary key (f2, f1); +explain select distinct f1 a, f1 b from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index NULL PRIMARY 5 NULL 4 Using index; Using temporary +explain select distinct f1, f2 from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range NULL PRIMARY 5 NULL 3 Using index for group-by; Using temporary +drop table t1; set storage_engine=innodb; CREATE TABLE t1 (a int, b int); insert into t1 values (1,1),(1,2); diff --git a/mysql-test/r/join.result b/mysql-test/r/join.result index ecf76d477a0..86288caf398 100644 --- a/mysql-test/r/join.result +++ b/mysql-test/r/join.result @@ -700,8 +700,8 @@ ERROR 42S22: Unknown column 't1.b' in 'on clause' select * from information_schema.statistics join information_schema.columns using(table_name,column_name) where table_name='user'; TABLE_NAME COLUMN_NAME TABLE_CATALOG TABLE_SCHEMA NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT TABLE_CATALOG TABLE_SCHEMA ORDINAL_POSITION COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA PRIVILEGES COLUMN_COMMENT -user Host NULL mysql 0 mysql PRIMARY 1 A NULL NULL NULL BTREE NULL mysql 1 NO char 20 60 NULL NULL utf8 utf8_bin char(60) PRI select,insert,update,references -user User NULL mysql 0 mysql PRIMARY 2 A 5 NULL NULL BTREE NULL mysql 2 NO char 5 16 NULL NULL utf8 utf8_bin char(16) PRI select,insert,update,references +user Host NULL mysql 0 mysql PRIMARY 1 A NULL NULL NULL BTREE NULL mysql 1 NO char 60 180 NULL NULL utf8 utf8_bin char(60) PRI select,insert,update,references +user User NULL mysql 0 mysql PRIMARY 2 A 5 NULL NULL BTREE NULL mysql 2 NO char 16 48 NULL NULL utf8 utf8_bin char(16) PRI select,insert,update,references drop table t1; drop table t2; drop table t3; diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result index 8a30f3c18ec..f4ec997e50c 100644 --- a/mysql-test/r/join_outer.result +++ b/mysql-test/r/join_outer.result @@ -1151,6 +1151,63 @@ EXPLAIN SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id WHERE t1.name LIKE 'A%' OR FALSE; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index PRIMARY,name name 23 NULL 3 Using where; Using index -1 SIMPLE t2 ref fkey fkey 5 test.t1.id 1 Using where; Using index +1 SIMPLE t2 index NULL fkey 5 NULL 5 Using index +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.fkey 1 Using where +DROP TABLE t1,t2; +DROP VIEW IF EXISTS v1,v2; +DROP TABLE IF EXISTS t1,t2; +CREATE TABLE t1 (a int); +CREATE table t2 (b int); +INSERT INTO t1 VALUES (1), (2), (3), (4), (1), (1), (3); +INSERT INTO t2 VALUES (2), (3); +CREATE VIEW v1 AS SELECT a FROM t1 JOIN t2 ON t1.a=t2.b; +CREATE VIEW v2 AS SELECT b FROM t2 JOIN t1 ON t2.b=t1.a; +SELECT v1.a, v2. b +FROM v1 LEFT OUTER JOIN v2 ON (v1.a=v2.b) AND (v1.a >= 3) +GROUP BY v1.a; +a b +2 NULL +3 3 +SELECT v1.a, v2. b +FROM { OJ v1 LEFT OUTER JOIN v2 ON (v1.a=v2.b) AND (v1.a >= 3) } +GROUP BY v1.a; +a b +2 NULL +3 3 +DROP VIEW v1,v2; +DROP TABLE t1,t2; +CREATE TABLE t1 (a int); +CREATE TABLE t2 (b int); +INSERT INTO t1 VALUES (1), (2), (3), (4); +INSERT INTO t2 VALUES (2), (3); +SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1=1); +a b +1 NULL +2 2 +3 3 +4 NULL +SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1 OR 1); +a b +1 NULL +2 2 +3 3 +4 NULL +SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (0 OR 1); +a b +1 NULL +2 2 +3 3 +4 NULL +SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1=1 OR 2=2); +a b +1 NULL +2 2 +3 3 +4 NULL +SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1=1 OR 1=0); +a b +1 NULL +2 2 +3 3 +4 NULL DROP TABLE t1,t2; diff --git a/mysql-test/r/lock_multi.result b/mysql-test/r/lock_multi.result index 1ab51e9fad5..180c8f41b70 100644 --- a/mysql-test/r/lock_multi.result +++ b/mysql-test/r/lock_multi.result @@ -50,3 +50,19 @@ Field Type Null Key Default Extra a int(11) YES NULL unlock tables; drop table t1; +use mysql; +LOCK TABLES columns_priv WRITE, db WRITE, host WRITE, user WRITE; +FLUSH TABLES; +use mysql; + SELECT user.Select_priv FROM user, db WHERE user.user = db.user LIMIT 1; +OPTIMIZE TABLES columns_priv, db, host, user; +Table Op Msg_type Msg_text +mysql.columns_priv optimize status OK +mysql.db optimize status OK +mysql.host optimize status OK +mysql.user optimize status OK +UNLOCK TABLES; +Select_priv +N +use test; +use test; diff --git a/mysql-test/r/log_tables.result b/mysql-test/r/log_tables.result index 2164c18823f..c61dd2247ee 100644 --- a/mysql-test/r/log_tables.result +++ b/mysql-test/r/log_tables.result @@ -2,14 +2,14 @@ use mysql; truncate table general_log; select * from general_log; event_time user_host thread_id server_id command_type argument -TIMESTAMP root[root] @ localhost [] 1 1 Query select * from general_log +TIMESTAMP USER_HOST THREAD_ID 1 Query select * from general_log truncate table slow_log; select * from slow_log; start_time user_host query_time lock_time rows_sent rows_examined db last_insert_id insert_id server_id sql_text truncate table general_log; select * from general_log where argument like '%general_log%'; event_time user_host thread_id server_id command_type argument -TIMESTAMP root[root] @ localhost [] 1 1 Query select * from general_log where argument like '%general_log%' +TIMESTAMP USER_HOST THREAD_ID 1 Query select * from general_log where argument like '%general_log%' create table join_test (verbose_comment varchar (80), command_type varchar(64)); insert into join_test values ("User performed a usual SQL query", "Query"); insert into join_test values ("New DB connection was registered", "Connect"); @@ -18,12 +18,12 @@ select verbose_comment, user_host, argument from mysql.general_log join join_test on (mysql.general_log.command_type = join_test.command_type); verbose_comment user_host argument -User performed a usual SQL query root[root] @ localhost [] select * from general_log where argument like '%general_log%' -User performed a usual SQL query root[root] @ localhost [] create table join_test (verbose_comment varchar (80), command_type varchar(64)) -User performed a usual SQL query root[root] @ localhost [] insert into join_test values ("User performed a usual SQL query", "Query") -User performed a usual SQL query root[root] @ localhost [] insert into join_test values ("New DB connection was registered", "Connect") -User performed a usual SQL query root[root] @ localhost [] insert into join_test values ("Get the table info", "Field List") -User performed a usual SQL query root[root] @ localhost [] select verbose_comment, user_host, argument +User performed a usual SQL query USER_HOST select * from general_log where argument like '%general_log%' +User performed a usual SQL query USER_HOST create table join_test (verbose_comment varchar (80), command_type varchar(64)) +User performed a usual SQL query USER_HOST insert into join_test values ("User performed a usual SQL query", "Query") +User performed a usual SQL query USER_HOST insert into join_test values ("New DB connection was registered", "Connect") +User performed a usual SQL query USER_HOST insert into join_test values ("Get the table info", "Field List") +User performed a usual SQL query USER_HOST select verbose_comment, user_host, argument from mysql.general_log join join_test on (mysql.general_log.command_type = join_test.command_type) drop table join_test; @@ -59,10 +59,10 @@ create table bug16905 (s char(15) character set utf8 default 'пуÑто'); insert into bug16905 values ('новое'); select * from mysql.general_log; event_time user_host thread_id server_id command_type argument -TIMESTAMP root[root] @ localhost [] 2 1 Query set names utf8 -TIMESTAMP root[root] @ localhost [] 2 1 Query create table bug16905 (s char(15) character set utf8 default 'пуÑто') -TIMESTAMP root[root] @ localhost [] 2 1 Query insert into bug16905 values ('новое') -TIMESTAMP root[root] @ localhost [] 2 1 Query select * from mysql.general_log +TIMESTAMP USER_HOST THREAD_ID 1 Query set names utf8 +TIMESTAMP USER_HOST THREAD_ID 1 Query create table bug16905 (s char(15) character set utf8 default 'пуÑто') +TIMESTAMP USER_HOST THREAD_ID 1 Query insert into bug16905 values ('новое') +TIMESTAMP USER_HOST THREAD_ID 1 Query select * from mysql.general_log drop table bug16905; truncate table mysql.slow_log; set session long_query_time=1; @@ -71,4 +71,4 @@ sleep(2) 0 select * from mysql.slow_log; start_time user_host query_time lock_time rows_sent rows_examined db last_insert_id insert_id server_id sql_text -TIMESTAMP, root[root] @ localhost [] USER_HOST, QUERY_TIME 1 0 test 0 0 1 select sleep(2) +TIMESTAMP USER_HOST QUERY_TIME 00:00:00 1 0 test 0 0 1 select sleep(2) diff --git a/mysql-test/r/merge.result b/mysql-test/r/merge.result index 538f1fa1a20..2f5f382028a 100644 --- a/mysql-test/r/merge.result +++ b/mysql-test/r/merge.result @@ -771,3 +771,11 @@ Table Op Msg_type Msg_text test.t1 check status OK test.t2 check status OK drop table t1, t2, t3; +drop table if exists t1; +Warnings: +Note 1051 Unknown table 't1' +create table t1 (c char(20)) engine=MyISAM; +insert into t1 values ("Monty"),("WAX"),("Walrus"); +alter table t1 engine=MERGE; +ERROR HY000: Table storage engine for 't1' doesn't have this option +drop table t1; diff --git a/mysql-test/r/metadata.result b/mysql-test/r/metadata.result index 0a170e16188..50b0b6ae294 100644 --- a/mysql-test/r/metadata.result +++ b/mysql-test/r/metadata.result @@ -2,7 +2,7 @@ drop table if exists t1,t2; select 1, 1.0, -1, "hello", NULL; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr def 1 8 1 1 N 32897 0 63 -def 1.0 246 3 3 N 161 1 63 +def 1.0 246 4 3 N 129 1 63 def -1 8 2 2 N 32897 0 63 def hello 253 5 5 N 1 31 8 def NULL 6 0 0 Y 32896 0 63 diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result index 8976c98136b..3226351f966 100644 --- a/mysql-test/r/myisam.result +++ b/mysql-test/r/myisam.result @@ -1421,15 +1421,6 @@ create table t3 (c1 int) engine=myisam pack_keys=default; create table t4 (c1 int) engine=myisam pack_keys=2; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '2' at line 1 drop table t1, t2, t3; -create table t1 (a int not null, key `a` key_block_size=1024 (a)); -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` int(11) NOT NULL, - KEY `a` KEY_BLOCK_SIZE=1024 (`a`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -drop table t1; -set @@new=1; create table t1 (a int not null, key `a` (a) key_block_size=1024); show create table t1; Table Create Table @@ -1574,4 +1565,5 @@ t1 CREATE TABLE `t1` ( drop table t1; create table t1 (a int not null, key key_block_size=1024 (a)); ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=1024 (a))' at line 1 -set @@new=0; +create table t1 (a int not null, key `a` key_block_size=1024 (a)); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key_block_size=1024 (a))' at line 1 diff --git a/mysql-test/r/mysql.result b/mysql-test/r/mysql.result index a067d3ad0f8..4b7084e813c 100644 --- a/mysql-test/r/mysql.result +++ b/mysql-test/r/mysql.result @@ -74,7 +74,7 @@ c_cp932 +----------------------+------------+--------+ | >a < | b | 123421 | | >a < | 0123456789 | 4 | -| >abcd< | NULL | 4 | +| >abcd< | | 4 | +----------------------+------------+--------+ +------+------+---------------------------+ | i | j | k | @@ -94,6 +94,14 @@ c_cp932 | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | i | int(11) | YES | | NULL | | -| j | int(11) | NO | | NULL | | +| j | int(11) | NO | | | | | k | int(11) | YES | | NULL | | +-------+---------+------+-----+---------+-------+ ++------+------+ +| i | s1 | ++------+------+ +| 1 | x | +| 2 | NULL | +| 3 | | ++------+------+ +End of 5.0 tests diff --git a/mysql-test/r/mysqlbinlog.result b/mysql-test/r/mysqlbinlog.result index 50e4cc28d93..c3be791b523 100644 --- a/mysql-test/r/mysqlbinlog.result +++ b/mysql-test/r/mysqlbinlog.result @@ -189,4 +189,9 @@ HEX(f) select HEX(f) from t4; HEX(f) 835C -drop table t1, t2, t03, t04, t3, t4; +flush logs; +select * from t5 /* must be (1),(1) */; +a +1 +1 +drop table t1, t2, t03, t04, t3, t4, t5; diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index 5da2be8da37..7075e7dec6d 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -1,4 +1,4 @@ -DROP TABLE IF EXISTS t1, `"t"1`, t1aa, t2, t2aa; +DROP TABLE IF EXISTS t1, `"t"1`, t1aa, t2, t2aa, t3; drop database if exists mysqldump_test_db; drop database if exists db1; drop database if exists db2; @@ -1509,6 +1509,7 @@ a b 12 meg drop table t1, t2; drop database db1; +--fields-optionally-enclosed-by=" CREATE DATABASE mysqldump_test_db; USE mysqldump_test_db; CREATE TABLE t1 ( a INT ); @@ -1701,6 +1702,81 @@ select * from t1; a b Osnabrück Köln drop table t1; +create table `t1` ( +t1_name varchar(255) default null, +t1_id int(10) unsigned not null auto_increment, +key (t1_name), +primary key (t1_id) +) auto_increment = 1000 default charset=latin1; +insert into t1 (t1_name) values('bla'); +insert into t1 (t1_name) values('bla'); +insert into t1 (t1_name) values('bla'); +select * from t1; +t1_name t1_id +bla 1000 +bla 1001 +bla 1002 +show create table `t1`; +Table Create Table +t1 CREATE TABLE `t1` ( + `t1_name` varchar(255) DEFAULT NULL, + `t1_id` int(10) unsigned NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`t1_id`), + KEY `t1_name` (`t1_name`) +) ENGINE=MyISAM AUTO_INCREMENT=1003 DEFAULT CHARSET=latin1 +DROP TABLE `t1`; +select * from t1; +t1_name t1_id +bla 1000 +bla 1001 +bla 1002 +show create table `t1`; +Table Create Table +t1 CREATE TABLE `t1` ( + `t1_name` varchar(255) DEFAULT NULL, + `t1_id` int(10) unsigned NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`t1_id`), + KEY `t1_name` (`t1_name`) +) ENGINE=MyISAM AUTO_INCREMENT=1003 DEFAULT CHARSET=latin1 +drop table `t1`; +create table t1(a int); +create table t2(a int); +create table t3(a int); + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; +DROP TABLE IF EXISTS `t3`; +CREATE TABLE `t3` ( + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1; +DROP TABLE IF EXISTS `t1`; +CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1; +DROP TABLE IF EXISTS `t2`; +CREATE TABLE `t2` ( + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +drop table t1, t2, t3; +End of 4.1 tests create table t1 (a binary(1), b blob); insert into t1 values ('',''); diff --git a/mysql-test/r/ndb_alter_table.result b/mysql-test/r/ndb_alter_table.result index 7c687ff33a1..e506973f347 100644 --- a/mysql-test/r/ndb_alter_table.result +++ b/mysql-test/r/ndb_alter_table.result @@ -1,4 +1,4 @@ -DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t1, t2; drop database if exists mysqltest; CREATE TABLE t1 ( a INT NOT NULL, @@ -328,3 +328,24 @@ select 'no_copy' from ndb_show_tables where id = @t1_id and name like '%t1%'; no_copy no_copy DROP TABLE t1, ndb_show_tables; +create table t1 (a int primary key auto_increment, b int) engine=ndb; +insert into t1 (b) values (101),(102),(103); +select * from t1 where a = 3; +a b +3 103 +alter table t1 rename t2; +insert into t2 (b) values (201),(202),(203); +select * from t2 where a = 6; +a b +6 203 +alter table t2 add c int; +insert into t2 (b) values (301),(302),(303); +select * from t2 where a = 9; +a b c +9 303 NULL +alter table t2 rename t1; +insert into t1 (b) values (401),(402),(403); +select * from t1 where a = 12; +a b c +12 403 NULL +drop table t1; diff --git a/mysql-test/r/ndb_autodiscover3.result b/mysql-test/r/ndb_autodiscover3.result new file mode 100644 index 00000000000..86495ebb3eb --- /dev/null +++ b/mysql-test/r/ndb_autodiscover3.result @@ -0,0 +1,53 @@ +drop table if exists t1, t2; +create table t1 (a int key) engine=ndbcluster; +begin; +insert into t1 values (1); +insert into t1 values (2); +ERROR HY000: Got temporary error 4025 'Node failure caused abort of transaction' from NDBCLUSTER +commit; +ERROR HY000: Got error 4350 'Transaction already aborted' from NDBCLUSTER +drop table t1; +create table t2 (a int, b int, primary key(a,b)) engine=ndbcluster; +insert into t2 values (1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1),(9,1),(10,1); +select * from t2 order by a limit 3; +a b +1 1 +2 1 +3 1 +select * from t2; +ERROR 42S02: Table 'test.t2' doesn't exist +show tables like 't2'; +Tables_in_test (t2) +reset master; +create table t2 (a int key) engine=ndbcluster; +insert into t2 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); +select * from t2 order by a limit 3; +a +1 +2 +3 +select * from t2 order by a limit 3; +a +1 +2 +3 +reset master; +select * from t2; +ERROR 42S02: Table 'test.t2' doesn't exist +show tables like 't2'; +Tables_in_test (t2) +reset master; +create table t2 (a int key) engine=ndbcluster; +insert into t2 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); +select * from t2 order by a limit 3; +a +1 +2 +3 +select * from t2 order by a limit 3; +a +1 +2 +3 +reset master; +drop table t2; diff --git a/mysql-test/r/ndb_basic.result b/mysql-test/r/ndb_basic.result index 9477caf97ab..631165d9fc8 100644 --- a/mysql-test/r/ndb_basic.result +++ b/mysql-test/r/ndb_basic.result @@ -6,13 +6,6 @@ attr1 INT NOT NULL, attr2 INT, attr3 VARCHAR(10) ) ENGINE=ndbcluster; -drop table t1; -CREATE TABLE t1 ( -pk1 INT NOT NULL PRIMARY KEY, -attr1 INT NOT NULL, -attr2 INT, -attr3 VARCHAR(10) -) ENGINE=ndbcluster; SHOW INDEX FROM t1; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment t1 0 PRIMARY 1 pk1 A 0 NULL NULL BTREE @@ -649,30 +642,30 @@ counter datavalue 6 newval 7 newval 8 newval -35 newval -36 newval -37 newval -38 newval -39 newval -40 newval -41 newval -42 newval -43 newval -44 newval -45 newval -46 newval -47 newval -48 newval -49 newval -50 newval -51 newval -52 newval -53 newval -54 newval -55 newval -56 newval -57 newval -58 newval +9 newval +10 newval +11 newval +12 newval +13 newval +14 newval +15 newval +16 newval +17 newval +18 newval +19 newval +20 newval +21 newval +22 newval +23 newval +24 newval +25 newval +26 newval +27 newval +28 newval +29 newval +30 newval +31 newval +32 newval drop table t1; CREATE TABLE t1 ( b INT ) PACK_KEYS = 0 ENGINE = ndb; select * from t1; @@ -755,3 +748,11 @@ f1 f2 f3 111111 aaaaaa 1 222222 bbbbbb 2 drop table t1; +CREATE TABLE t1 (a VARCHAR(255) NOT NULL, +CONSTRAINT pk_a PRIMARY KEY (a))engine=ndb; +CREATE TABLE t2(a VARCHAR(255) NOT NULL, +b VARCHAR(255) NOT NULL, +c VARCHAR(255) NOT NULL, +CONSTRAINT pk_b_c_id PRIMARY KEY (b,c), +CONSTRAINT fk_a FOREIGN KEY(a) REFERENCES t1(a))engine=ndb; +drop table t1, t2; diff --git a/mysql-test/r/ndb_bitfield.result b/mysql-test/r/ndb_bitfield.result index 9a8c571cfba..59c4d420b22 100644 --- a/mysql-test/r/ndb_bitfield.result +++ b/mysql-test/r/ndb_bitfield.result @@ -9,7 +9,7 @@ t1 CREATE TABLE `t1` ( `pk1` int(11) NOT NULL, `b` bit(64) DEFAULT NULL, PRIMARY KEY (`pk1`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 insert into t1 values (0,b'1111111111111111111111111111111111111111111111111111111111111111'), (1,b'1000000000000000000000000000000000000000000000000000000000000000'), diff --git a/mysql-test/r/ndb_blob.result b/mysql-test/r/ndb_blob.result index 7a781ae3bde..829c67905bf 100644 --- a/mysql-test/r/ndb_blob.result +++ b/mysql-test/r/ndb_blob.result @@ -500,3 +500,69 @@ select count(*) from t1; count(*) 0 drop table t1; +create table t1 ( +a varchar(40) not null, +b mediumint not null, +t text, +c varchar(2) not null, +d bigint not null, +primary key (a,b,c), +key (c,a), +unique key (d) +) engine=ndb; +insert into t1 (a,b,c,d,t) values ('a',1110,'a',1,@v1); +insert into t1 (a,b,c,d,t) values ('b',1110,'a',2,@v2); +insert into t1 (a,b,c,d,t) values ('a',1110,'b',3,@v3); +insert into t1 (a,b,c,d,t) values ('b',1110,'b',4,@v4); +select a,b,c,d,sha1(t) from t1 order by c,a; +a b c d sha1(t) +a 1110 a 1 558a30713786aa72f66abc1e6a521d55aacdeeb5 +b 1110 a 2 b238654911689bfb626a3ef9dba4a1ca074e6a5e +a 1110 b 3 2b6515f29c20b8e9e17cc597527e516c0de8d612 +b 1110 b 4 NULL +select a,b,c,d,sha1(t) from t1 where a='a' and b=1110 and c='a'; +a b c d sha1(t) +a 1110 a 1 558a30713786aa72f66abc1e6a521d55aacdeeb5 +select a,b,c,d,sha1(t) from t1 where a='a' and b=1110 and c='b'; +a b c d sha1(t) +a 1110 b 3 2b6515f29c20b8e9e17cc597527e516c0de8d612 +update t1 set t=@v4 where a='b' and b=1110 and c='a'; +update t1 set t=@v2 where a='b' and b=1110 and c='b'; +select a,b,c,d,sha1(t) from t1 order by c,a; +a b c d sha1(t) +a 1110 a 1 558a30713786aa72f66abc1e6a521d55aacdeeb5 +b 1110 a 2 NULL +a 1110 b 3 2b6515f29c20b8e9e17cc597527e516c0de8d612 +b 1110 b 4 b238654911689bfb626a3ef9dba4a1ca074e6a5e +update t1 set t=@v2 where d=2; +update t1 set t=@v4 where d=4; +select a,b,c,d,sha1(t) from t1 order by c,a; +a b c d sha1(t) +a 1110 a 1 558a30713786aa72f66abc1e6a521d55aacdeeb5 +b 1110 a 2 b238654911689bfb626a3ef9dba4a1ca074e6a5e +a 1110 b 3 2b6515f29c20b8e9e17cc597527e516c0de8d612 +b 1110 b 4 NULL +update t1 set t=@v4 where a='b' and c='a'; +update t1 set t=@v2 where a='b' and c='b'; +select a,b,c,d,sha1(t) from t1 order by c,a; +a b c d sha1(t) +a 1110 a 1 558a30713786aa72f66abc1e6a521d55aacdeeb5 +b 1110 a 2 NULL +a 1110 b 3 2b6515f29c20b8e9e17cc597527e516c0de8d612 +b 1110 b 4 b238654911689bfb626a3ef9dba4a1ca074e6a5e +update t1 set t=@v2 where b+d=1112; +update t1 set t=@v4 where b+d=1114; +select a,b,c,d,sha1(t) from t1 order by c,a; +a b c d sha1(t) +a 1110 a 1 558a30713786aa72f66abc1e6a521d55aacdeeb5 +b 1110 a 2 b238654911689bfb626a3ef9dba4a1ca074e6a5e +a 1110 b 3 2b6515f29c20b8e9e17cc597527e516c0de8d612 +b 1110 b 4 NULL +delete from t1 where a='a' and b=1110 and c='a'; +delete from t1 where a='b' and c='a'; +delete from t1 where d=3; +delete from t1 where b+d=1114; +select count(*) from t1; +count(*) +0 +drop table t1; diff --git a/mysql-test/r/ndb_blob_partition.result b/mysql-test/r/ndb_blob_partition.result deleted file mode 100644 index b08a91f0cdd..00000000000 --- a/mysql-test/r/ndb_blob_partition.result +++ /dev/null @@ -1,104 +0,0 @@ -drop table if exists t1; -create table t1 ( -a mediumint not null, -b text not null, -c int not null, -d longblob, -primary key using hash (a,c), -unique key (c) -) -engine=ndb -partition by range (c) -partitions 3 -( partition p1 values less than (200), -partition p2 values less than (300), -partition p3 values less than (400)); -insert into t1 values (1, @v1, 101, @v2); -insert into t1 values (1, @v2, 102, @v3); -insert into t1 values (1, @v3, 103, @v4); -insert into t1 values (2, @v4, 201, @v5); -insert into t1 values (2, @v5, 202, @v6); -insert into t1 values (2, @v6, 203, @v7); -insert into t1 values (3, @v7, 301, @v8); -insert into t1 values (3, @v8, 302, @v9); -insert into t1 values (3, @v9, 303, @v1); -select a, sha1(b), c, sha1(d) from t1 order by a; -a sha1(b) c sha1(d) -1 1d42dd9090cf78314a06665d4ea938c35cc760f4 101 10d3c783026b310218d10b7188da96a2401648c6 -1 10d3c783026b310218d10b7188da96a2401648c6 102 a33549d9844092289a58ac348dd59f09fc28406a -1 a33549d9844092289a58ac348dd59f09fc28406a 103 daa61c6de36a0526f0d47dc29d6b9de7e6d2630c -2 daa61c6de36a0526f0d47dc29d6b9de7e6d2630c 201 70fc9a7d08beebc522258bfb02000a30c77a8f1d -2 70fc9a7d08beebc522258bfb02000a30c77a8f1d 202 090565c580809efed3d369481a4bbb168b20713e -2 090565c580809efed3d369481a4bbb168b20713e 203 1e0070bec426871a46291de27b9bd6e4255ab4e5 -3 1e0070bec426871a46291de27b9bd6e4255ab4e5 301 acbaba01bc2e682f015f40e79d9cbe475db3002e -3 acbaba01bc2e682f015f40e79d9cbe475db3002e 302 9ee30d99162574f79c66ae95cdf132dcf9cbc259 -3 9ee30d99162574f79c66ae95cdf132dcf9cbc259 303 1d42dd9090cf78314a06665d4ea938c35cc760f4 -select a, sha1(b), c, sha1(d) from t1 where a = 1 and c = 101; -a sha1(b) c sha1(d) -1 1d42dd9090cf78314a06665d4ea938c35cc760f4 101 10d3c783026b310218d10b7188da96a2401648c6 -select a, sha1(b), c, sha1(d) from t1 where a = 2 and c = 201; -a sha1(b) c sha1(d) -2 daa61c6de36a0526f0d47dc29d6b9de7e6d2630c 201 70fc9a7d08beebc522258bfb02000a30c77a8f1d -select a, sha1(b), c, sha1(d) from t1 where a = 3 and c = 301; -a sha1(b) c sha1(d) -3 1e0070bec426871a46291de27b9bd6e4255ab4e5 301 acbaba01bc2e682f015f40e79d9cbe475db3002e -update t1 set b = @v3, d = @v4 where a = 1 and c = 102; -update t1 set b = @v6, d = @v7 where a = 2 and c = 202; -update t1 set b = @v9, d = @v1 where a = 3 and c = 302; -select a, sha1(b), c, sha1(d) from t1 order by a; -a sha1(b) c sha1(d) -1 1d42dd9090cf78314a06665d4ea938c35cc760f4 101 10d3c783026b310218d10b7188da96a2401648c6 -1 a33549d9844092289a58ac348dd59f09fc28406a 102 daa61c6de36a0526f0d47dc29d6b9de7e6d2630c -1 a33549d9844092289a58ac348dd59f09fc28406a 103 daa61c6de36a0526f0d47dc29d6b9de7e6d2630c -2 daa61c6de36a0526f0d47dc29d6b9de7e6d2630c 201 70fc9a7d08beebc522258bfb02000a30c77a8f1d -2 090565c580809efed3d369481a4bbb168b20713e 202 1e0070bec426871a46291de27b9bd6e4255ab4e5 -2 090565c580809efed3d369481a4bbb168b20713e 203 1e0070bec426871a46291de27b9bd6e4255ab4e5 -3 1e0070bec426871a46291de27b9bd6e4255ab4e5 301 acbaba01bc2e682f015f40e79d9cbe475db3002e -3 9ee30d99162574f79c66ae95cdf132dcf9cbc259 302 1d42dd9090cf78314a06665d4ea938c35cc760f4 -3 9ee30d99162574f79c66ae95cdf132dcf9cbc259 303 1d42dd9090cf78314a06665d4ea938c35cc760f4 -update t1 set b = @v4, d = @v5 where c = 103; -update t1 set b = @v7, d = @v8 where c = 203; -update t1 set b = @v1, d = @v2 where c = 303; -select a, sha1(b), c, sha1(d) from t1 order by a; -a sha1(b) c sha1(d) -1 1d42dd9090cf78314a06665d4ea938c35cc760f4 101 10d3c783026b310218d10b7188da96a2401648c6 -1 a33549d9844092289a58ac348dd59f09fc28406a 102 daa61c6de36a0526f0d47dc29d6b9de7e6d2630c -1 daa61c6de36a0526f0d47dc29d6b9de7e6d2630c 103 70fc9a7d08beebc522258bfb02000a30c77a8f1d -2 daa61c6de36a0526f0d47dc29d6b9de7e6d2630c 201 70fc9a7d08beebc522258bfb02000a30c77a8f1d -2 090565c580809efed3d369481a4bbb168b20713e 202 1e0070bec426871a46291de27b9bd6e4255ab4e5 -2 1e0070bec426871a46291de27b9bd6e4255ab4e5 203 acbaba01bc2e682f015f40e79d9cbe475db3002e -3 1e0070bec426871a46291de27b9bd6e4255ab4e5 301 acbaba01bc2e682f015f40e79d9cbe475db3002e -3 9ee30d99162574f79c66ae95cdf132dcf9cbc259 302 1d42dd9090cf78314a06665d4ea938c35cc760f4 -3 1d42dd9090cf78314a06665d4ea938c35cc760f4 303 10d3c783026b310218d10b7188da96a2401648c6 -update t1 set b = @v5, d = @v6; -select a, sha1(b), c, sha1(d) from t1 order by a; -a sha1(b) c sha1(d) -1 70fc9a7d08beebc522258bfb02000a30c77a8f1d 101 090565c580809efed3d369481a4bbb168b20713e -1 70fc9a7d08beebc522258bfb02000a30c77a8f1d 102 090565c580809efed3d369481a4bbb168b20713e -1 70fc9a7d08beebc522258bfb02000a30c77a8f1d 103 090565c580809efed3d369481a4bbb168b20713e -2 70fc9a7d08beebc522258bfb02000a30c77a8f1d 201 090565c580809efed3d369481a4bbb168b20713e -2 70fc9a7d08beebc522258bfb02000a30c77a8f1d 202 090565c580809efed3d369481a4bbb168b20713e -2 70fc9a7d08beebc522258bfb02000a30c77a8f1d 203 090565c580809efed3d369481a4bbb168b20713e -3 70fc9a7d08beebc522258bfb02000a30c77a8f1d 301 090565c580809efed3d369481a4bbb168b20713e -3 70fc9a7d08beebc522258bfb02000a30c77a8f1d 302 090565c580809efed3d369481a4bbb168b20713e -3 70fc9a7d08beebc522258bfb02000a30c77a8f1d 303 090565c580809efed3d369481a4bbb168b20713e -update t1 set b = @v1, d = @v2 where 100 < c and c < 200; -update t1 set b = @v4, d = @v5 where 200 < c and c < 300; -update t1 set b = @v7, d = @v8 where 300 < c and c < 400; -select a, sha1(b), c, sha1(d) from t1 order by a; -a sha1(b) c sha1(d) -1 1d42dd9090cf78314a06665d4ea938c35cc760f4 101 10d3c783026b310218d10b7188da96a2401648c6 -1 1d42dd9090cf78314a06665d4ea938c35cc760f4 102 10d3c783026b310218d10b7188da96a2401648c6 -1 1d42dd9090cf78314a06665d4ea938c35cc760f4 103 10d3c783026b310218d10b7188da96a2401648c6 -2 daa61c6de36a0526f0d47dc29d6b9de7e6d2630c 201 70fc9a7d08beebc522258bfb02000a30c77a8f1d -2 daa61c6de36a0526f0d47dc29d6b9de7e6d2630c 202 70fc9a7d08beebc522258bfb02000a30c77a8f1d -2 daa61c6de36a0526f0d47dc29d6b9de7e6d2630c 203 70fc9a7d08beebc522258bfb02000a30c77a8f1d -3 1e0070bec426871a46291de27b9bd6e4255ab4e5 301 acbaba01bc2e682f015f40e79d9cbe475db3002e -3 1e0070bec426871a46291de27b9bd6e4255ab4e5 302 acbaba01bc2e682f015f40e79d9cbe475db3002e -3 1e0070bec426871a46291de27b9bd6e4255ab4e5 303 acbaba01bc2e682f015f40e79d9cbe475db3002e -delete from t1 where a = 1 and c = 101; -delete from t1 where c = 102; -delete from t1; -select a, sha1(b), c, sha1(d) from t1 order by a; -a sha1(b) c sha1(d) -drop table t1; diff --git a/mysql-test/r/ndb_condition_pushdown.result b/mysql-test/r/ndb_condition_pushdown.result index 24fe30604ae..140324a21d8 100644 --- a/mysql-test/r/ndb_condition_pushdown.result +++ b/mysql-test/r/ndb_condition_pushdown.result @@ -1782,5 +1782,65 @@ select * from t5 where b like '%jo%' order by a; a b 1 jonas 3 johan +drop table t1; +create table t1 (a int, b varchar(3), primary key using hash(a)) +engine=ndb; +insert into t1 values (1,'a'), (2,'ab'), (3,'abc'); +set engine_condition_pushdown = off; +select * from t1 where b like 'ab'; +a b +2 ab +select * from t1 where b like 'ab' or b like 'ab'; +a b +2 ab +select * from t1 where b like 'abc'; +a b +3 abc +select * from t1 where b like 'abc' or b like 'abc'; +a b +3 abc +set engine_condition_pushdown = on; +select * from t1 where b like 'ab'; +a b +2 ab +select * from t1 where b like 'ab' or b like 'ab'; +a b +2 ab +select * from t1 where b like 'abc'; +a b +3 abc +select * from t1 where b like 'abc' or b like 'abc'; +a b +3 abc +drop table t1; +create table t1 (a int, b char(3), primary key using hash(a)) +engine=ndb; +insert into t1 values (1,'a'), (2,'ab'), (3,'abc'); +set engine_condition_pushdown = off; +select * from t1 where b like 'ab'; +a b +2 ab +select * from t1 where b like 'ab' or b like 'ab'; +a b +2 ab +select * from t1 where b like 'abc'; +a b +3 abc +select * from t1 where b like 'abc' or b like 'abc'; +a b +3 abc +set engine_condition_pushdown = on; +select * from t1 where b like 'ab'; +a b +2 ab +select * from t1 where b like 'ab' or b like 'ab'; +a b +2 ab +select * from t1 where b like 'abc'; +a b +3 abc +select * from t1 where b like 'abc' or b like 'abc'; +a b +3 abc set engine_condition_pushdown = @old_ecpd; DROP TABLE t1,t2,t3,t4,t5; diff --git a/mysql-test/r/ndb_dd_backuprestore.result b/mysql-test/r/ndb_dd_backuprestore.result index e7568e4ce49..33edf6783e6 100644 --- a/mysql-test/r/ndb_dd_backuprestore.result +++ b/mysql-test/r/ndb_dd_backuprestore.result @@ -155,333 +155,10 @@ DROP TABLE test.t1; DROP TABLE test.t2; DROP TABLE test.t3; DROP TABLE test.t4; -**** Test 3 Adding partition Test backup and restore **** -CREATE TABLESPACE table_space2 -ADD DATAFILE './table_space2/datafile.dat' -USE LOGFILE GROUP log_group1 -INITIAL_SIZE 12M -ENGINE NDB; -CREATE TABLE test.t1 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 VARCHAR(150) NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))TABLESPACE table_space1 STORAGE DISK ENGINE=NDB PARTITION BY HASH(c3) PARTITIONS 4; -CREATE TABLE test.t4 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 VARCHAR(180) NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))ENGINE=NDB PARTITION BY HASH(c3) PARTITIONS 2; -CREATE TABLE test.t2 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 TEXT NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))TABLESPACE table_space2 STORAGE DISK ENGINE=NDB PARTITION BY KEY(c3) (PARTITION p0 ENGINE = NDB, PARTITION p1 ENGINE = NDB); -CREATE TABLE test.t5 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 TEXT NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))ENGINE=NDB PARTITION BY KEY(pk1) (PARTITION p0 ENGINE = NDB, PARTITION p1 ENGINE = NDB); -CREATE TABLE test.t3 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 VARCHAR(202) NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))TABLESPACE table_space2 STORAGE DISK ENGINE=NDB PARTITION BY RANGE (c3) PARTITIONS 3 (PARTITION x1 VALUES LESS THAN (105), PARTITION x2 VALUES LESS THAN (333), PARTITION x3 VALUES LESS THAN (720)); -CREATE TABLE test.t6 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 VARCHAR(220) NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))ENGINE=NDB PARTITION BY RANGE (pk1) PARTITIONS 2 (PARTITION x1 VALUES LESS THAN (333), PARTITION x2 VALUES LESS THAN (720)); -SHOW CREATE TABLE test.t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `pk1` mediumint(9) NOT NULL AUTO_INCREMENT, - `c2` varchar(150) NOT NULL, - `c3` int(11) NOT NULL, - `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) TABLESPACE table_space1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY HASH (c3) PARTITIONS 4 -SHOW CREATE TABLE test.t2; -Table Create Table -t2 CREATE TABLE `t2` ( - `pk1` mediumint(9) NOT NULL AUTO_INCREMENT, - `c2` text NOT NULL, - `c3` int(11) NOT NULL, - `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) TABLESPACE table_space2 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (c3) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster) -SHOW CREATE TABLE test.t3; -Table Create Table -t3 CREATE TABLE `t3` ( - `pk1` mediumint(9) NOT NULL AUTO_INCREMENT, - `c2` varchar(202) NOT NULL, - `c3` int(11) NOT NULL, - `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) TABLESPACE table_space2 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY RANGE (c3) (PARTITION x1 VALUES LESS THAN (105) ENGINE = ndbcluster, PARTITION x2 VALUES LESS THAN (333) ENGINE = ndbcluster, PARTITION x3 VALUES LESS THAN (720) ENGINE = ndbcluster) -SHOW CREATE TABLE test.t4; -Table Create Table -t4 CREATE TABLE `t4` ( - `pk1` mediumint(9) NOT NULL AUTO_INCREMENT, - `c2` varchar(180) NOT NULL, - `c3` int(11) NOT NULL, - `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY HASH (c3) PARTITIONS 2 -SHOW CREATE TABLE test.t5; -Table Create Table -t5 CREATE TABLE `t5` ( - `pk1` mediumint(9) NOT NULL AUTO_INCREMENT, - `c2` text NOT NULL, - `c3` int(11) NOT NULL, - `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (pk1) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster) -SHOW CREATE TABLE test.t6; -Table Create Table -t6 CREATE TABLE `t6` ( - `pk1` mediumint(9) NOT NULL AUTO_INCREMENT, - `c2` varchar(220) NOT NULL, - `c3` int(11) NOT NULL, - `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY RANGE (pk1) (PARTITION x1 VALUES LESS THAN (333) ENGINE = ndbcluster, PARTITION x2 VALUES LESS THAN (720) ENGINE = ndbcluster) -SELECT * FROM information_schema.partitions WHERE table_name= 't1'; -TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME -NULL test t1 p0 NULL 1 NULL HASH NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -NULL test t1 p1 NULL 2 NULL HASH NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -NULL test t1 p2 NULL 3 NULL HASH NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -NULL test t1 p3 NULL 4 NULL HASH NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -SELECT * FROM information_schema.partitions WHERE table_name= 't2'; -TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME -NULL test t2 p0 NULL 1 NULL KEY NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -NULL test t2 p1 NULL 2 NULL KEY NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -SELECT * FROM information_schema.partitions WHERE table_name= 't3'; -TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME -NULL test t3 x1 NULL 1 NULL RANGE NULL c3 NULL 105 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -NULL test t3 x2 NULL 2 NULL RANGE NULL c3 NULL 333 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -NULL test t3 x3 NULL 3 NULL RANGE NULL c3 NULL 720 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -SELECT * FROM information_schema.partitions WHERE table_name= 't4'; -TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME -NULL test t4 p0 NULL 1 NULL HASH NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -NULL test t4 p1 NULL 2 NULL HASH NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -SELECT * FROM information_schema.partitions WHERE table_name= 't5'; -TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME -NULL test t5 p0 NULL 1 NULL KEY NULL pk1 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -NULL test t5 p1 NULL 2 NULL KEY NULL pk1 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -SELECT * FROM information_schema.partitions WHERE table_name= 't6'; -TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME -NULL test t6 x1 NULL 1 NULL RANGE NULL pk1 NULL 333 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -NULL test t6 x2 NULL 2 NULL RANGE NULL pk1 NULL 720 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -SELECT COUNT(*) FROM test.t1; -COUNT(*) -250 -SELECT pk1, c2, c3, hex(c4) FROM test.t1 ORDER BY c3 LIMIT 5; -pk1 c2 c3 hex(c4) -250 Sweden, Texas 2 0 -249 Sweden, Texas 4 0 -248 Sweden, Texas 6 0 -247 Sweden, Texas 8 0 -246 Sweden, Texas 10 0 -SELECT COUNT(*) FROM test.t2; -COUNT(*) -250 -SELECT pk1, c2, c3, hex(c4) FROM test.t2 ORDER BY c3 LIMIT 5; -pk1 c2 c3 hex(c4) -250 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 1 1 -249 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 3 1 -248 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 5 1 -247 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 7 1 -246 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 9 1 -SELECT COUNT(*) FROM test.t3; -COUNT(*) -250 -SELECT pk1, c2, c3, hex(c4) FROM test.t3 ORDER BY c3 LIMIT 5; -pk1 c2 c3 hex(c4) -250 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 0 1 -249 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 2 1 -248 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 4 1 -247 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 6 1 -246 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 8 1 -SELECT COUNT(*) FROM test.t4; -COUNT(*) -250 -SELECT pk1, c2, c3, hex(c4) FROM test.t4 ORDER BY c3 LIMIT 5; -pk1 c2 c3 hex(c4) -250 Sweden, Texas 2 0 -249 Sweden, Texas 4 0 -248 Sweden, Texas 6 0 -247 Sweden, Texas 8 0 -246 Sweden, Texas 10 0 -SELECT COUNT(*) FROM test.t5; -COUNT(*) -250 -SELECT pk1, c2, c3, hex(c4) FROM test.t5 ORDER BY c3 LIMIT 5; -pk1 c2 c3 hex(c4) -250 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 1 1 -249 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 3 1 -248 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 5 1 -247 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 7 1 -246 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 9 1 -SELECT COUNT(*) FROM test.t6; -COUNT(*) -250 -SELECT pk1, c2, c3, hex(c4) FROM test.t6 ORDER BY c3 LIMIT 5; -pk1 c2 c3 hex(c4) -250 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 0 1 -249 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 2 1 -248 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 4 1 -247 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 6 1 -246 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 8 1 -CREATE TEMPORARY TABLE IF NOT EXISTS test.backup_info (id INT, backup_id INT) ENGINE = HEAP; -DELETE FROM test.backup_info; -LOAD DATA INFILE '../tmp.dat' INTO TABLE test.backup_info FIELDS TERMINATED BY ','; -SELECT @the_backup_id:=backup_id FROM test.backup_info; -@the_backup_id:=backup_id -<the_backup_id> -DROP TABLE test.backup_info; -DROP TABLE test.t1; -DROP TABLE test.t2; -DROP TABLE test.t3; -DROP TABLE test.t4; -DROP TABLE test.t5; -DROP TABLE test.t6; ALTER TABLESPACE table_space1 DROP DATAFILE './table_space1/datafile.dat' ENGINE = NDB; -ALTER TABLESPACE table_space2 -DROP DATAFILE './table_space2/datafile.dat' -ENGINE = NDB; DROP TABLESPACE table_space1 ENGINE = NDB; -DROP TABLESPACE table_space2 -ENGINE = NDB; DROP LOGFILE GROUP log_group1 ENGINE =NDB; -SHOW CREATE TABLE test.t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `pk1` mediumint(9) NOT NULL AUTO_INCREMENT, - `c2` varchar(150) NOT NULL, - `c3` int(11) NOT NULL, - `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) TABLESPACE table_space1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY HASH (c3) PARTITIONS 4 -SHOW CREATE TABLE test.t2; -Table Create Table -t2 CREATE TABLE `t2` ( - `pk1` mediumint(9) NOT NULL AUTO_INCREMENT, - `c2` text NOT NULL, - `c3` int(11) NOT NULL, - `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) TABLESPACE table_space2 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (c3) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster) -SHOW CREATE TABLE test.t3; -Table Create Table -t3 CREATE TABLE `t3` ( - `pk1` mediumint(9) NOT NULL AUTO_INCREMENT, - `c2` varchar(202) NOT NULL, - `c3` int(11) NOT NULL, - `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) TABLESPACE table_space2 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY RANGE (c3) (PARTITION x1 VALUES LESS THAN (105) ENGINE = ndbcluster, PARTITION x2 VALUES LESS THAN (333) ENGINE = ndbcluster, PARTITION x3 VALUES LESS THAN (720) ENGINE = ndbcluster) -SHOW CREATE TABLE test.t4; -Table Create Table -t4 CREATE TABLE `t4` ( - `pk1` mediumint(9) NOT NULL AUTO_INCREMENT, - `c2` varchar(180) NOT NULL, - `c3` int(11) NOT NULL, - `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY HASH (c3) PARTITIONS 2 -SHOW CREATE TABLE test.t5; -Table Create Table -t5 CREATE TABLE `t5` ( - `pk1` mediumint(9) NOT NULL AUTO_INCREMENT, - `c2` text NOT NULL, - `c3` int(11) NOT NULL, - `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (pk1) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster) -SHOW CREATE TABLE test.t6; -Table Create Table -t6 CREATE TABLE `t6` ( - `pk1` mediumint(9) NOT NULL AUTO_INCREMENT, - `c2` varchar(220) NOT NULL, - `c3` int(11) NOT NULL, - `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY RANGE (pk1) (PARTITION x1 VALUES LESS THAN (333) ENGINE = ndbcluster, PARTITION x2 VALUES LESS THAN (720) ENGINE = ndbcluster) -SELECT * FROM information_schema.partitions WHERE table_name= 't1'; -TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME -NULL test t1 p0 NULL 1 NULL HASH NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -NULL test t1 p1 NULL 2 NULL HASH NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -NULL test t1 p2 NULL 3 NULL HASH NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -NULL test t1 p3 NULL 4 NULL HASH NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -SELECT * FROM information_schema.partitions WHERE table_name= 't2'; -TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME -NULL test t2 p0 NULL 1 NULL KEY NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -NULL test t2 p1 NULL 2 NULL KEY NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -SELECT * FROM information_schema.partitions WHERE table_name= 't3'; -TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME -NULL test t3 x1 NULL 1 NULL RANGE NULL c3 NULL 105 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -NULL test t3 x2 NULL 2 NULL RANGE NULL c3 NULL 333 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -NULL test t3 x3 NULL 3 NULL RANGE NULL c3 NULL 720 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -SELECT * FROM information_schema.partitions WHERE table_name= 't4'; -TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME -NULL test t4 p0 NULL 1 NULL HASH NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -NULL test t4 p1 NULL 2 NULL HASH NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -SELECT * FROM information_schema.partitions WHERE table_name= 't5'; -TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME -NULL test t5 p0 NULL 1 NULL KEY NULL pk1 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -NULL test t5 p1 NULL 2 NULL KEY NULL pk1 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -SELECT * FROM information_schema.partitions WHERE table_name= 't6'; -TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME -NULL test t6 x1 NULL 1 NULL RANGE NULL pk1 NULL 333 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -NULL test t6 x2 NULL 2 NULL RANGE NULL pk1 NULL 720 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default -SELECT COUNT(*) FROM test.t1; -COUNT(*) -250 -SELECT pk1, c2, c3, hex(c4) FROM test.t1 ORDER BY c3 LIMIT 5; -pk1 c2 c3 hex(c4) -250 Sweden, Texas 2 0 -249 Sweden, Texas 4 0 -248 Sweden, Texas 6 0 -247 Sweden, Texas 8 0 -246 Sweden, Texas 10 0 -SELECT COUNT(*) FROM test.t2; -COUNT(*) -250 -SELECT pk1, c2, c3, hex(c4) FROM test.t2 ORDER BY c3 LIMIT 5; -pk1 c2 c3 hex(c4) -250 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 1 1 -249 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 3 1 -248 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 5 1 -247 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 7 1 -246 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 9 1 -SELECT COUNT(*) FROM test.t3; -COUNT(*) -250 -SELECT pk1, c2, c3, hex(c4) FROM test.t3 ORDER BY c3 LIMIT 5; -pk1 c2 c3 hex(c4) -250 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 0 1 -249 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 2 1 -248 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 4 1 -247 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 6 1 -246 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 8 1 -SELECT COUNT(*) FROM test.t4; -COUNT(*) -250 -SELECT pk1, c2, c3, hex(c4) FROM test.t4 ORDER BY c3 LIMIT 5; -pk1 c2 c3 hex(c4) -250 Sweden, Texas 2 0 -249 Sweden, Texas 4 0 -248 Sweden, Texas 6 0 -247 Sweden, Texas 8 0 -246 Sweden, Texas 10 0 -SELECT COUNT(*) FROM test.t5; -COUNT(*) -250 -SELECT pk1, c2, c3, hex(c4) FROM test.t5 ORDER BY c3 LIMIT 5; -pk1 c2 c3 hex(c4) -250 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 1 1 -249 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 3 1 -248 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 5 1 -247 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 7 1 -246 Sweden, Texas, ITALY, Kyle, JO, JBM,TU 9 1 -SELECT COUNT(*) FROM test.t6; -COUNT(*) -250 -SELECT pk1, c2, c3, hex(c4) FROM test.t6 ORDER BY c3 LIMIT 5; -pk1 c2 c3 hex(c4) -250 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 0 1 -249 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 2 1 -248 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 4 1 -247 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 6 1 -246 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 8 1 -DROP TABLE test.t1; -DROP TABLE test.t2; -DROP TABLE test.t3; -DROP TABLE test.t4; -DROP TABLE test.t5; -DROP TABLE test.t6; -ALTER TABLESPACE table_space1 DROP DATAFILE './table_space1/datafile.dat' ENGINE=NDB; -ALTER TABLESPACE table_space2 DROP DATAFILE './table_space2/datafile.dat' ENGINE=NDB; -DROP TABLESPACE table_space1 ENGINE = NDB; -DROP TABLESPACE table_space2 ENGINE = NDB; -DROP LOGFILE GROUP log_group1 ENGINE = NDB; diff --git a/mysql-test/r/ndb_dd_basic.result b/mysql-test/r/ndb_dd_basic.result index ee1b717e6f1..6c10fbe63b3 100644 --- a/mysql-test/r/ndb_dd_basic.result +++ b/mysql-test/r/ndb_dd_basic.result @@ -11,7 +11,7 @@ ADD UNDOFILE 'undofile02.dat' INITIAL_SIZE = 4M ENGINE=XYZ; Warnings: -Error 1266 Using storage engine MyISAM for table 'lg1' +Error 1286 Unknown table engine 'XYZ' Error 1465 Table storage engine 'MyISAM' does not support the create option 'TABLESPACE or LOGFILE GROUP' CREATE TABLESPACE ts1 ADD DATAFILE 'datafile.dat' @@ -49,7 +49,7 @@ t1 CREATE TABLE `t1` ( `b` int(11) NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`pk1`) -) TABLESPACE ts1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) TABLESPACE ts1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 INSERT INTO t1 VALUES (0, 0, 0); SELECT * FROM t1; pk1 b c diff --git a/mysql-test/r/ndb_dd_disk2memory.result b/mysql-test/r/ndb_dd_disk2memory.result index 80056b7269d..bd5bbda42f3 100644 --- a/mysql-test/r/ndb_dd_disk2memory.result +++ b/mysql-test/r/ndb_dd_disk2memory.result @@ -218,7 +218,7 @@ t2 CREATE TABLE `t2` ( `b2` int(11) NOT NULL, `c2` int(11) NOT NULL, PRIMARY KEY (`pk2`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 SHOW CREATE TABLE test.t1; Table Create Table t1 CREATE TABLE `t1` ( @@ -226,7 +226,7 @@ t1 CREATE TABLE `t1` ( `b` int(11) NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`pk1`) -) TABLESPACE table_space1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) TABLESPACE table_space1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 ALTER TABLE test.t2 TABLESPACE table_space1 STORAGE DISK ENGINE=NDB; SHOW CREATE TABLE test.t2; @@ -236,7 +236,7 @@ t2 CREATE TABLE `t2` ( `b2` int(11) NOT NULL, `c2` int(11) NOT NULL, PRIMARY KEY (`pk2`) -) TABLESPACE table_space1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) TABLESPACE table_space1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 ALTER TABLE test.t1 ENGINE=NDBCLUSTER; SHOW CREATE TABLE test.t1; Table Create Table @@ -245,7 +245,7 @@ t1 CREATE TABLE `t1` ( `b` int(11) NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`pk1`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 DROP TABLE test.t1; DROP TABLE test.t2; diff --git a/mysql-test/r/ndb_gis.result b/mysql-test/r/ndb_gis.result index f9b9ceb76a5..67447a69242 100644 --- a/mysql-test/r/ndb_gis.result +++ b/mysql-test/r/ndb_gis.result @@ -14,7 +14,7 @@ gis_point CREATE TABLE `gis_point` ( `fid` int(11) NOT NULL AUTO_INCREMENT, `g` point DEFAULT NULL, PRIMARY KEY (`fid`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 SHOW FIELDS FROM gis_point; Field Type Null Key Default Extra fid int(11) NO PRI NULL auto_increment @@ -476,7 +476,7 @@ gis_point CREATE TABLE `gis_point` ( `fid` int(11) NOT NULL AUTO_INCREMENT, `g` point DEFAULT NULL, PRIMARY KEY (`fid`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 SHOW FIELDS FROM gis_point; Field Type Null Key Default Extra fid int(11) NO PRI NULL auto_increment diff --git a/mysql-test/r/ndb_index_unique.result b/mysql-test/r/ndb_index_unique.result index e18125f159e..88c6e00e215 100644 --- a/mysql-test/r/ndb_index_unique.result +++ b/mysql-test/r/ndb_index_unique.result @@ -99,7 +99,7 @@ CREATE TABLE t2 ( a int unsigned NOT NULL PRIMARY KEY, b int unsigned not null, c int unsigned not null, -UNIQUE USING HASH (b, c) +UNIQUE (b, c) USING HASH ) engine=ndbcluster; insert t2 values(1, 2, 3), (2, 3, 5), (3, 4, 6), (4, 5, 8), (5,6, 2), (6,7, 2); select * from t2 where a = 3; @@ -142,14 +142,14 @@ CREATE TABLE t2 ( a int unsigned NOT NULL PRIMARY KEY, b int unsigned not null, c int unsigned, -UNIQUE USING HASH (b, c) +UNIQUE (b, c) USING HASH ) engine=ndbcluster; ERROR 42000: Table handler doesn't support NULL in given index. Please change column 'c' to be NOT NULL or use another handler CREATE TABLE t3 ( a int unsigned NOT NULL, b int unsigned not null, c int unsigned, -PRIMARY KEY USING HASH (a, b) +PRIMARY KEY (a, b) USING HASH ) engine=ndbcluster; insert t3 values(1, 2, 3), (2, 3, 5), (3, 4, 6), (4, 5, 8), (5,6, 2), (6,7, 2); select * from t3 where a = 3; diff --git a/mysql-test/r/ndb_partition_error.result b/mysql-test/r/ndb_partition_error.result deleted file mode 100644 index d86dc382185..00000000000 --- a/mysql-test/r/ndb_partition_error.result +++ /dev/null @@ -1,47 +0,0 @@ -drop table if exists t1; -CREATE TABLE t1 ( -a int not null, -b int not null, -c int not null, -primary key(a,b), -index (a)) -engine = ndb -partition by range (a) -partitions 3 -(partition x1 values less than (5) nodegroup 12, -partition x2 values less than (10) nodegroup 13, -partition x3 values less than (20) nodegroup 14); -ERROR HY000: Can't create table 'test.t1' (errno: 140) -show warnings; -Level Code Message -Error 1296 Got error 771 'Given NODEGROUP doesn't exist in this cluster' from NDB -Error 1005 Can't create table 'test.t1' (errno: 140) -CREATE TABLE t1 ( -a int not null, -b int not null, -c int not null, -primary key(a)) -engine = ndb -partition by range (a) -partitions 3 -(partition x1 values less than (5), -partition x2 values less than (10), -partition x3 values less than (20)); -drop table t1; -CREATE TABLE t1 (id INT) ENGINE=NDB -PARTITION BY LIST(id) -(PARTITION p0 VALUES IN (2, 4), -PARTITION p1 VALUES IN (42, 142)); -INSERT INTO t1 VALUES (2); -UPDATE t1 SET id=5 WHERE id=2; -ERROR HY000: Table has no partition for value 5 -DROP TABLE t1; -create table t1 (a int,b int, c int) -engine = ndb -partition by list(a) -partitions 2 -(partition x123 values in (11, 12), -partition x234 values in (5, 1)); -insert into t1 values (NULL,1,1); -ERROR HY000: Table has no partition for value NULL -drop table t1; diff --git a/mysql-test/r/ndb_partition_key.result b/mysql-test/r/ndb_partition_key.result deleted file mode 100644 index 503283df532..00000000000 --- a/mysql-test/r/ndb_partition_key.result +++ /dev/null @@ -1,199 +0,0 @@ -DROP TABLE IF EXISTS t1; -CREATE TABLE t1 (a int, b int, c int, d int, PRIMARY KEY(a,b,c)) -ENGINE = NDB -PARTITION BY KEY (a,b); -insert into t1 values (1,1,1,1); -select * from t1; -a b c d -1 1 1 1 -update t1 set d = 2 where a = 1 and b = 1 and c = 1; -select * from t1; -a b c d -1 1 1 2 -delete from t1; -select * from t1; -a b c d -drop table t1; -CREATE TABLE t1 (a int, b int, c int, d int, PRIMARY KEY(a,b)) -ENGINE = NDB -PARTITION BY KEY (c); -ERROR HY000: A PRIMARY KEY need to include all fields in the partition function -CREATE TABLE t1 (a int, b int, c int, PRIMARY KEY(a,b)) -ENGINE = NDB -PARTITION BY KEY (a); -insert into t1 values -(1,1,3),(1,2,3),(1,3,3),(1,4,3),(1,5,3),(1,6,3), -(1,7,3),(1,8,3),(1,9,3),(1,10,3),(1,11,3),(1,12,3); -select * from t1 order by b; -a b c -1 1 3 -1 2 3 -1 3 3 -1 4 3 -1 5 3 -1 6 3 -1 7 3 -1 8 3 -1 9 3 -1 10 3 -1 11 3 -1 12 3 -DROP TABLE t1; -CREATE TABLE t1 (a INT, b CHAR(10) COLLATE latin1_bin, c INT, d INT, -PRIMARY KEY USING HASH (a,b,c)) -ENGINE=NDB -DEFAULT CHARSET=latin1 -PARTITION BY KEY (b); -insert into t1 values (1,"a",1,1),(2,"a",1,1),(3,"a",1,1); --- t1 -- - -Fragment type: 5 -K Value: 6 -Min load factor: 78 -Max load factor: 80 -Temporary table: no -Number of attributes: 4 -Number of primary keys: 3 -Length of frm data: # -Row Checksum: 1 -Row GCI: 1 -TableStatus: Retrieved --- Attributes -- -a Int PRIMARY KEY AT=FIXED ST=MEMORY -b Char(10;latin1_bin) PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY -c Int PRIMARY KEY AT=FIXED ST=MEMORY -d Int NULL AT=FIXED ST=MEMORY - --- Indexes -- -PRIMARY KEY(a, b, c) - UniqueHashIndex - - -NDBT_ProgramExit: 0 - OK - -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` int(11) NOT NULL DEFAULT '0', - `b` char(10) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '', - `c` int(11) NOT NULL DEFAULT '0', - `d` int(11) DEFAULT NULL, - PRIMARY KEY USING HASH (`a`,`b`,`c`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (b) -DROP TABLE t1; -CREATE TABLE t1 (a int not null primary key) -PARTITION BY KEY(a) -(PARTITION p0 ENGINE = NDB, PARTITION p1 ENGINE = NDB); -drop table t1; -CREATE TABLE t1 (a int not null primary key); -ALTER TABLE t1 -PARTITION BY KEY(a) -(PARTITION p0 ENGINE = NDB, PARTITION p1 ENGINE = NDB); -drop table t1; -create table t1 (a int) -engine=ndb -partition by key(a) -(partition p0, partition p1); -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` int(11) DEFAULT NULL -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster) -alter table t1 engine=heap; -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` int(11) DEFAULT NULL -) ENGINE=MEMORY DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = MEMORY, PARTITION p1 ENGINE = MEMORY) -alter table t1 engine=ndb; -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` int(11) DEFAULT NULL -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster) -alter table t1 engine=heap remove partitioning; -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` int(11) DEFAULT NULL -) ENGINE=MEMORY DEFAULT CHARSET=latin1 -alter table t1 engine=ndb -partition by key(a) -(partition p0, partition p1 engine = ndb); -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` int(11) DEFAULT NULL -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster) -alter table t1 -partition by key (a) -(partition p0 engine=ndb, partition p1 engine=ndb); -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` int(11) DEFAULT NULL -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster) -alter table t1 remove partitioning; -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` int(11) DEFAULT NULL -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () -alter table t1 -partition by key(a) -(partition p0 engine=ndb, partition p1); -ERROR HY000: The mix of handlers in the partitions is not allowed in this version of MySQL -alter table t1 -engine=ndb -partition by key(a) -(partition p0 engine=ndb, partition p1 engine = ndb); -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` int(11) DEFAULT NULL -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster) -drop table t1; -CREATE TABLE t1 ( -c1 MEDIUMINT NOT NULL AUTO_INCREMENT, -c2 TEXT NOT NULL, -c3 INT NOT NULL, -c4 BIT NOT NULL, -c5 FLOAT, -c6 VARCHAR(255), -c7 TIMESTAMP, -PRIMARY KEY(c1,c3)) -ENGINE=NDB -PARTITION BY KEY(c3) PARTITIONS 5; -ALTER TABLE t1 COALESCE PARTITION 4; -DROP TABLE t1; -CREATE TABLE t1 (a int primary key) -ENGINE=NDB -PARTITION BY KEY(a); -ALTER TABLE t1 OPTIMIZE PARTITION p0; -ERROR HY000: Table storage engine for 't1' doesn't have this option -ALTER TABLE t1 CHECK PARTITION p0; -ERROR HY000: Table storage engine for 't1' doesn't have this option -ALTER TABLE t1 REPAIR PARTITION p0; -ERROR HY000: Table storage engine for 't1' doesn't have this option -ALTER TABLE t1 ANALYZE PARTITION p0; -ERROR HY000: Table storage engine for 't1' doesn't have this option -ALTER TABLE t1 REBUILD PARTITION p0; -ERROR HY000: Table storage engine for 't1' doesn't have this option -DROP TABLE t1; -CREATE TABLE t1 ( -c1 MEDIUMINT NOT NULL AUTO_INCREMENT, -c2 TEXT NOT NULL, -c3 INT NOT NULL, -PRIMARY KEY(c1,c3)) -ENGINE=NDB -PARTITION BY KEY(c3) PARTITIONS 5; -ALTER TABLE t1 ADD COLUMN c4 INT AFTER c1; -DROP TABLE t1; -CREATE TABLE t1 ( -c1 MEDIUMINT NOT NULL AUTO_INCREMENT, -c2 TEXT NOT NULL, -c3 INT NOT NULL, -PRIMARY KEY(c1,c3)) -ENGINE=NDB -PARTITION BY KEY(c3); -ALTER TABLE t1 ADD COLUMN c4 INT AFTER c1; -DROP TABLE t1; diff --git a/mysql-test/r/ndb_partition_list.result b/mysql-test/r/ndb_partition_list.result deleted file mode 100644 index ce2574ddcc4..00000000000 --- a/mysql-test/r/ndb_partition_list.result +++ /dev/null @@ -1,51 +0,0 @@ -drop table if exists t1; -CREATE TABLE t1 ( f_int1 INTEGER NOT NULL, f_int2 INTEGER NOT NULL, -f_char1 CHAR(10), -f_char2 CHAR(10), f_charbig VARCHAR(1000), -PRIMARY KEY (f_int1,f_int2)) -ENGINE = NDB -PARTITION BY LIST(MOD(f_int1 + f_int2,4)) -(PARTITION part_3 VALUES IN (-3), -PARTITION part_2 VALUES IN (-2), -PARTITION part_1 VALUES IN (-1), -PARTITION part0 VALUES IN (0), -PARTITION part1 VALUES IN (1), -PARTITION part2 VALUES IN (2), -PARTITION part3 VALUES IN (3,4,5)); -INSERT INTO t1 SET f_int1 = -2, f_int2 = 20, f_char1 = '20', f_char2 = '20', f_charbig = '===20==='; -INSERT INTO t1 SET f_int1 = 1, f_int2 = 1, f_char1 = '1', f_char2 = '1', f_charbig = '===1==='; -INSERT INTO t1 SET f_int1 = 2, f_int2 = 1, f_char1 = '1', f_char2 = '1', f_charbig = '===1==='; -INSERT INTO t1 SET f_int1 = 3, f_int2 = 1, f_char1 = '1', f_char2 = '1', f_charbig = '===1==='; -INSERT INTO t1 SET f_int1 = 4, f_int2 = 1, f_char1 = '1', f_char2 = '1', f_charbig = '===1==='; -INSERT INTO t1 SET f_int1 = 5, f_int2 = 1, f_char1 = '1', f_char2 = '1', f_charbig = '===1==='; -INSERT INTO t1 SET f_int1 = 20, f_int2 = 1, f_char1 = '1', f_char2 = '1', f_charbig = '===1==='; -SELECT * FROM t1 ORDER BY f_int1; -f_int1 f_int2 f_char1 f_char2 f_charbig --2 20 20 20 ===20=== -1 1 1 1 ===1=== -2 1 1 1 ===1=== -3 1 1 1 ===1=== -4 1 1 1 ===1=== -5 1 1 1 ===1=== -20 1 1 1 ===1=== -DROP TABLE t1; -CREATE TABLE t1 ( f_int1 INTEGER, f_int2 INTEGER, f_char1 CHAR(10), -f_char2 CHAR(10), f_charbig VARCHAR(1000)) -ENGINE = NDB -PARTITION BY LIST(f_int1) -(PARTITION part_1 VALUES IN (-1), -PARTITION part0 VALUES IN (0,1), -PARTITION part1 VALUES IN (2)); -INSERT INTO t1 SET f_int1 = -1, f_int2 = 20, f_char1 = '20', f_char2 = '20', f_charbig = '===20==='; -INSERT INTO t1 SET f_int1 = 0, f_int2 = 20, f_char1 = '20', f_char2 = '20', f_charbig = '===20==='; -INSERT INTO t1 SET f_int1 = 1, f_int2 = 1, f_char1 = '1', f_char2 = '1', f_charbig = '===1==='; -INSERT INTO t1 SET f_int1 = 2, f_int2 = 1, f_char1 = '1', f_char2 = '1', f_charbig = '===1==='; -INSERT INTO t1 SET f_int1 = 20, f_int2 = 1, f_char1 = '1', f_char2 = '1', f_charbig = '===1==='; -ERROR HY000: Table has no partition for value 20 -SELECT * FROM t1 ORDER BY f_int1; -f_int1 f_int2 f_char1 f_char2 f_charbig --1 20 20 20 ===20=== -0 20 20 20 ===20=== -1 1 1 1 ===1=== -2 1 1 1 ===1=== -DROP TABLE t1; diff --git a/mysql-test/r/ndb_partition_range.result b/mysql-test/r/ndb_partition_range.result deleted file mode 100644 index cb79f04873e..00000000000 --- a/mysql-test/r/ndb_partition_range.result +++ /dev/null @@ -1,263 +0,0 @@ -drop table if exists t1; -CREATE TABLE t1 ( -a int not null, -b int not null, -c int not null, -primary key(a,b), -index (a)) -engine = ndb -partition by range (a) -partitions 3 -(partition x1 values less than (5), -partition x2 values less than (10), -partition x3 values less than (20)); -INSERT into t1 values (1, 1, 1); -INSERT into t1 values (6, 1, 1); -INSERT into t1 values (10, 1, 1); -INSERT into t1 values (15, 1, 1); -select * from information_schema.partitions where table_name= 't1'; -TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME -NULL test t1 x1 NULL 1 NULL RANGE NULL a NULL 5 0 0 0 # 0 0 # # NULL NULL default 0 default -NULL test t1 x2 NULL 2 NULL RANGE NULL a NULL 10 0 0 0 # 0 0 # # NULL NULL default 0 default -NULL test t1 x3 NULL 3 NULL RANGE NULL a NULL 20 0 0 0 # 0 0 # # NULL NULL default 0 default -select * from t1 order by a; -a b c -1 1 1 -6 1 1 -10 1 1 -15 1 1 -select * from t1 where a=1 order by a; -a b c -1 1 1 -select * from t1 where a=15 and b=1 order by a; -a b c -15 1 1 -select * from t1 where a=21 and b=1 order by a; -a b c -select * from t1 where a=21 order by a; -a b c -select * from t1 where a in (1,6,10,21) order by a; -a b c -1 1 1 -6 1 1 -10 1 1 -select * from t1 where b=1 and a in (1,6,10,21) order by a; -a b c -1 1 1 -6 1 1 -10 1 1 -drop table t1; -CREATE TABLE t1 ( -a int not null, -b int not null, -c int not null, -primary key(b), -unique (a)) -engine = ndb -partition by range (b) -partitions 3 -(partition x1 values less than (5), -partition x2 values less than (10), -partition x3 values less than (20)); -INSERT into t1 values (1, 1, 1); -INSERT into t1 values (2, 6, 1); -INSERT into t1 values (3, 10, 1); -INSERT into t1 values (4, 15, 1); -select * from t1 order by a; -a b c -1 1 1 -2 6 1 -3 10 1 -4 15 1 -UPDATE t1 set a = 5 WHERE b = 15; -select * from t1 order by a; -a b c -1 1 1 -2 6 1 -3 10 1 -5 15 1 -UPDATE t1 set a = 6 WHERE a = 5; -select * from t1 order by a; -a b c -1 1 1 -2 6 1 -3 10 1 -6 15 1 -select * from t1 where b=1 order by b; -a b c -1 1 1 -select * from t1 where b=15 and a=1 order by b; -a b c -select * from t1 where b=21 and a=1 order by b; -a b c -select * from t1 where b=21 order by b; -a b c -select * from t1 where b in (1,6,10,21) order by b; -a b c -1 1 1 -2 6 1 -3 10 1 -select * from t1 where a in (1,2,5,6) order by b; -a b c -1 1 1 -2 6 1 -6 15 1 -select * from t1 where a=1 and b in (1,6,10,21) order by b; -a b c -1 1 1 -DELETE from t1 WHERE b = 6; -DELETE from t1 WHERE a = 6; -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` int(11) NOT NULL, - `b` int(11) NOT NULL, - `c` int(11) NOT NULL, - PRIMARY KEY (`b`), - UNIQUE KEY `a` (`a`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY RANGE (b) (PARTITION x1 VALUES LESS THAN (5) ENGINE = ndbcluster, PARTITION x2 VALUES LESS THAN (10) ENGINE = ndbcluster, PARTITION x3 VALUES LESS THAN (20) ENGINE = ndbcluster) -drop table t1; -CREATE TABLE t1 -(id MEDIUMINT NOT NULL, -b1 BIT(8), -vc VARCHAR(255), -bc CHAR(255), -d DECIMAL(10,4) DEFAULT 0, -f FLOAT DEFAULT 0, -total BIGINT UNSIGNED, -y YEAR, -t DATE) ENGINE=NDB -PARTITION BY RANGE (YEAR(t)) -(PARTITION p0 VALUES LESS THAN (1901), -PARTITION p1 VALUES LESS THAN (1946), -PARTITION p2 VALUES LESS THAN (1966), -PARTITION p3 VALUES LESS THAN (1986), -PARTITION p4 VALUES LESS THAN (2005), -PARTITION p5 VALUES LESS THAN MAXVALUE); -INSERT INTO t1 VALUES (0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); -SELECT * FROM t1; -id b1 vc bc d f total y t -0 NULL NULL NULL NULL NULL NULL NULL NULL -ALTER TABLE t1 ENGINE=MYISAM; -SELECT * FROM t1; -id b1 vc bc d f total y t -0 NULL NULL NULL NULL NULL NULL NULL NULL -DROP TABLE t1; -CREATE LOGFILE GROUP lg1 -ADD UNDOFILE 'undofile.dat' - INITIAL_SIZE 16M -UNDO_BUFFER_SIZE=1M -ENGINE=NDB; -CREATE TABLESPACE ts1 -ADD DATAFILE 'datafile.dat' - USE LOGFILE GROUP lg1 -INITIAL_SIZE 12M -ENGINE NDB; -CREATE TABLE test.t1 ( -a1 INT, -a2 TEXT NOT NULL, -a3 BIT NOT NULL, -a4 DECIMAL(8,3), -a5 INT NOT NULL, -a6 INT, -PRIMARY KEY(a1)) -TABLESPACE ts1 STORAGE DISK ENGINE=NDB -PARTITION BY LIST (a1) -(PARTITION p0 VALUES IN (1,2,3,4,5), -PARTITION p1 VALUES IN (6,7,8,9, 10), -PARTITION p2 VALUES IN (11, 12, 13, 14, 15)); -ALTER TABLE test.t1 DROP COLUMN a6; -ALTER TABLE test.t1 ADD COLUMN a6 VARCHAR(255); -SELECT COUNT(*) FROM test.t1; -COUNT(*) -15 -ALTER TABLE test.t1 DROP COLUMN a4; -SELECT COUNT(*) FROM test.t1; -COUNT(*) -15 -DROP TABLE t1; -CREATE TABLE test.t1 ( -a1 INT, -a2 TEXT NOT NULL, -a3 BIT NOT NULL, -a4 DECIMAL(8,3), -a5 INT NOT NULL, -a6 VARCHAR(255), -PRIMARY KEY(a1)) -TABLESPACE ts1 STORAGE DISK ENGINE=NDB -PARTITION BY HASH(a1) -PARTITIONS 4; -SELECT COUNT(*) FROM test.t1; -COUNT(*) -15 -ALTER TABLE test.t1 DROP COLUMN a4; -SELECT COUNT(*) FROM test.t1; -COUNT(*) -15 -DROP TABLE t1; -ALTER TABLESPACE ts1 -DROP DATAFILE 'datafile.dat' -ENGINE=NDB; -DROP TABLESPACE ts1 ENGINE=NDB; -DROP LOGFILE GROUP lg1 ENGINE=NDB; -CREATE TABLE t1 -(id MEDIUMINT NOT NULL, -b1 BIT(8), -vc VARCHAR(255), -bc CHAR(255), -d DECIMAL(10,4) DEFAULT 0, -f FLOAT DEFAULT 0, -total BIGINT UNSIGNED, -y YEAR, -t DATE) ENGINE=NDB -PARTITION BY LIST(id) -(PARTITION p0 VALUES IN (2, 4), -PARTITION p1 VALUES IN (42, 142)); -INSERT INTO t1 VALUES (2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); -SELECT * FROM t1; -id b1 vc bc d f total y t -2 NULL NULL NULL NULL NULL NULL NULL NULL -ALTER TABLE t1 ADD PARTITION -(PARTITION p2 VALUES IN (412)); -SELECT * FROM t1; -id b1 vc bc d f total y t -2 NULL NULL NULL NULL NULL NULL NULL NULL -DROP TABLE t1; -CREATE TABLE t1 ( -a int not null, -b int not null, -c int not null) -partition by list(a) -partitions 2 -(partition x123 values in (1,5,6), -partition x234 values in (4,7,8)); -INSERT into t1 VALUES (5,1,1); -select * from t1; -a b c -5 1 1 -UPDATE t1 SET a=8 WHERE a=5 AND b=1; -select * from t1; -a b c -8 1 1 -drop table t1; -CREATE TABLE t1 ( f1 INTEGER, f2 char(20)) engine=ndb -PARTITION BY RANGE(f1) -( PARTITION part1 VALUES LESS THAN (2), -PARTITION part2 VALUES LESS THAN (1000)); -INSERT INTO t1 VALUES(1, '---1---'); -INSERT INTO t1 VALUES(2, '---2---'); -select * from t1 order by f1; -f1 f2 -1 ---1--- -2 ---2--- -UPDATE t1 SET f1 = f1 + 4 WHERE f1 = 2; -select * from t1 order by f1; -f1 f2 -1 ---1--- -6 ---2--- -UPDATE t1 SET f1 = f1 + 4 WHERE f1 = 1; -select * from t1 order by f1; -f1 f2 -5 ---1--- -6 ---2--- -drop table t1; diff --git a/mysql-test/r/ndb_rename.result b/mysql-test/r/ndb_rename.result new file mode 100644 index 00000000000..2cc2dfb3ff1 --- /dev/null +++ b/mysql-test/r/ndb_rename.result @@ -0,0 +1,24 @@ +DROP TABLE IF EXISTS t1,t2; +drop database if exists mysqltest; +CREATE TABLE t1 ( +pk1 INT NOT NULL PRIMARY KEY, +attr1 INT NOT NULL, +attr2 INT, +attr3 VARCHAR(10), +INDEX i1(attr1) +) ENGINE=ndbcluster; +INSERT INTO t1 VALUES (0,0,0,"zero"),(1,1,1,"one"),(2,2,2,"two"); +SELECT * FROM t1 WHERE attr1 = 1; +pk1 attr1 attr2 attr3 +1 1 1 one +alter table t1 rename t2; +SELECT * FROM t2 WHERE attr1 = 1; +pk1 attr1 attr2 attr3 +1 1 1 one +create database ndbtest; +alter table t2 rename ndbtest.t2; +SELECT * FROM ndbtest.t2 WHERE attr1 = 1; +pk1 attr1 attr2 attr3 +1 1 1 one +drop table ndbtest.t2; +drop database ndbtest; diff --git a/mysql-test/r/not_embedded_server.result b/mysql-test/r/not_embedded_server.result index e471b5a3afa..7cbe91b3753 100644 --- a/mysql-test/r/not_embedded_server.result +++ b/mysql-test/r/not_embedded_server.result @@ -1,5 +1,6 @@ prepare stmt1 from ' show full processlist '; execute stmt1; Id User Host db Command Time State Info +number event_scheduler localhost NULL Connect time Suspended NULL number root localhost test Query time NULL show full processlist deallocate prepare stmt1; diff --git a/mysql-test/r/openssl_1.result b/mysql-test/r/openssl_1.result index 91382619b6c..1fcfb11525e 100644 --- a/mysql-test/r/openssl_1.result +++ b/mysql-test/r/openssl_1.result @@ -3,8 +3,8 @@ create table t1(f1 int); insert into t1 values (5); grant select on test.* to ssl_user1@localhost require SSL; grant select on test.* to ssl_user2@localhost require cipher "DHE-RSA-AES256-SHA"; -grant select on test.* to ssl_user3@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "/C=SE/L=Uppsala/O=MySQL AB/CN=MySQL Client/Email=abstract.mysql.developer@mysql.com"; -grant select on test.* to ssl_user4@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "/C=SE/L=Uppsala/O=MySQL AB/CN=MySQL Client/Email=abstract.mysql.developer@mysql.com" ISSUER "/C=SE/L=Uppsala/O=MySQL AB/CN=Abstract MySQL Developer/Email=abstract.mysql.developer@mysql.com"; +grant select on test.* to ssl_user3@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "/C=SE/L=Uppsala/O=MySQL AB/CN=MySQL Client/emailAddress=abstract.mysql.developer@mysql.com"; +grant select on test.* to ssl_user4@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "/C=SE/L=Uppsala/O=MySQL AB/CN=MySQL Client/emailAddress=abstract.mysql.developer@mysql.com" ISSUER "/C=SE/L=Uppsala/O=MySQL AB/CN=Abstract MySQL Developer/emailAddress=abstract.mysql.developer@mysql.com"; flush privileges; SHOW STATUS LIKE 'Ssl_cipher'; Variable_name Value @@ -41,3 +41,10 @@ ERROR 42000: DELETE command denied to user 'ssl_user4'@'localhost' for table 't1 drop user ssl_user1@localhost, ssl_user2@localhost, ssl_user3@localhost, ssl_user4@localhost; drop table t1; +mysqltest: Could not open connection 'default': 2026 SSL connection error +mysqltest: Could not open connection 'default': 2026 SSL connection error +mysqltest: Could not open connection 'default': 2026 SSL connection error +Error when connection to server using SSL:Unable to get private key from '' +mysqltest: Could not open connection 'default': 2026 SSL connection error +Error when connection to server using SSL:Unable to get certificate from '' +mysqltest: Could not open connection 'default': 2026 SSL connection error diff --git a/mysql-test/r/outfile.result b/mysql-test/r/outfile.result Binary files differindex ee8c3249c9d..040dff576f8 100644 --- a/mysql-test/r/outfile.result +++ b/mysql-test/r/outfile.result diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 0da071374ea..6e440c4312c 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -1,4 +1,25 @@ drop table if exists t1; +create table t1 (a int) +partition by key(a) +(partition p0 engine = MEMORY); +drop table t1; +create table t1 (a int) +partition by range (a) +subpartition by key (a) +(partition p0 values less than (1)); +alter table t1 add partition (partition p1 values less than (2)); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (a) SUBPARTITION BY KEY (a) (PARTITION p0 VALUES LESS THAN (1) ENGINE = MyISAM, PARTITION p1 VALUES LESS THAN (2) ENGINE = MyISAM) +alter table t1 reorganize partition p1 into (partition p1 values less than (3)); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (a) SUBPARTITION BY KEY (a) (PARTITION p0 VALUES LESS THAN (1) ENGINE = MyISAM, PARTITION p1 VALUES LESS THAN (3) ENGINE = MyISAM) +drop table t1; CREATE TABLE t1 ( a int not null, b int not null, @@ -570,7 +591,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `a` int(11) DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (a) SUBPARTITION BY HASH (a) (PARTITION p0 VALUES LESS THAN (100) ) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (a) SUBPARTITION BY HASH (a) (PARTITION p0 VALUES LESS THAN (100) ENGINE = MyISAM) alter table t1 add partition (partition p1 values less than (200) (subpartition subpart21)); show create table t1; @@ -886,4 +907,62 @@ s1 2 3 drop table t1; +create table t1 (a int) engine=memory +partition by key(a); +insert into t1 values (1); +create index inx1 on t1(a); +drop table t1; +create table t1 (a int) +partition by key (a) +(partition p0 engine = MERGE); +ERROR HY000: MyISAM Merge handler cannot be used in partitioned tables +create table t1 (a varchar(1)) +partition by key (a) +as select 'a'; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(1) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY KEY (a) +drop table t1; +CREATE TABLE t1 (a int) ENGINE = MYISAM PARTITION BY KEY(a); +INSERT into t1 values (1), (2); +SHOW TABLE STATUS; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 2 7 14 0 0 0 NULL NULL NULL NULL latin1_swedish_ci NULL partitioned +DELETE from t1 where a = 1; +SHOW TABLE STATUS; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 1 14 14 0 0 7 NULL NULL NULL NULL latin1_swedish_ci NULL partitioned +ALTER TABLE t1 OPTIMIZE PARTITION p0; +SHOW TABLE STATUS; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 1 7 7 0 1024 0 NULL NULL NULL NULL latin1_swedish_ci NULL partitioned +DROP TABLE t1; +CREATE TABLE t1 (a int, index(a)) PARTITION BY KEY(a); +ALTER TABLE t1 DISABLE KEYS; +ALTER TABLE t1 ENABLE KEYS; +DROP TABLE t1; +create table t1 (a int) +engine=MEMORY +partition by key (a); +REPAIR TABLE t1; +Table Op Msg_type Msg_text +test.t1 repair note The storage engine for the table doesn't support repair +OPTIMIZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 optimize note The storage engine for the table doesn't support optimize +drop table t1; +create database db99; +use db99; +create table t1 (a int not null) +engine=archive +partition by list (a) +(partition p0 values in (1), partition p1 values in (2)); +insert into t1 values (1), (2); +create index inx on t1 (a); +alter table t1 add partition (partition p2 values in (3)); +alter table t1 drop partition p2; +use test; +drop database db99; End of 5.1 tests diff --git a/mysql-test/r/partition_02myisam.result b/mysql-test/r/partition_02myisam.result index a7786bfcfbd..147e705f861 100644 --- a/mysql-test/r/partition_02myisam.result +++ b/mysql-test/r/partition_02myisam.result @@ -996,7 +996,7 @@ Table Create Table t1 CREATE TABLE `t1` ( `f1` int(11) DEFAULT NULL, `f2` char(20) DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (f1) SUBPARTITION BY HASH (f1) SUBPARTITIONS 2 (PARTITION part1 VALUES LESS THAN (100) , PARTITION part2 VALUES LESS THAN (2147483647) ) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (f1) SUBPARTITION BY HASH (f1) SUBPARTITIONS 2 (PARTITION part1 VALUES LESS THAN (100) ENGINE = MyISAM, PARTITION part2 VALUES LESS THAN (2147483647) ENGINE = MyISAM) SELECT COUNT(*) = 0 AS my_value FROM t1; my_value 1 @@ -1098,7 +1098,7 @@ Table Create Table t1 CREATE TABLE `t1` ( `f1` int(11) DEFAULT NULL, `f2` char(20) DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (f1) SUBPARTITION BY HASH (f1) SUBPARTITIONS 1 (PARTITION part1 VALUES LESS THAN (100) , PARTITION part2 VALUES LESS THAN (2147483647) ) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (f1) SUBPARTITION BY HASH (f1) SUBPARTITIONS 1 (PARTITION part1 VALUES LESS THAN (100) ENGINE = MyISAM, PARTITION part2 VALUES LESS THAN (2147483647) ENGINE = MyISAM) SELECT COUNT(*) = 0 AS my_value FROM t1; my_value 1 diff --git a/mysql-test/r/partition_error.result b/mysql-test/r/partition_error.result index 1a0b1dd9b3a..a7ca3d9b2fa 100644 --- a/mysql-test/r/partition_error.result +++ b/mysql-test/r/partition_error.result @@ -554,3 +554,26 @@ PARTITION BY RANGE (a) (PARTITION p1 VALUES LESS THAN(5)); insert into t1 values (10); ERROR HY000: Table has no partition for value 10 drop table t1; +create table t1 (v varchar(12)) +partition by range (ascii(v)) +(partition p0 values less than (10)); +drop table t1; +create table t1 (a int) +partition by hash (rand(a)); +ERROR 42000: Constant/Random expression in (sub)partitioning function is not allowed near ')' at line 2 +create table t1 (a int) +partition by hash(CURTIME() + a); +ERROR 42000: Constant/Random expression in (sub)partitioning function is not allowed near ')' at line 2 +create table t1 (a int) +partition by hash (NOW()+a); +ERROR 42000: Constant/Random expression in (sub)partitioning function is not allowed near ')' at line 2 +create table t1 (a int) +partition by hash (extract(hour from convert_tz(a, '+00:00', '+00:00'))); +ERROR HY000: This partition function is not allowed +create table t1 (a int) +partition by range (a + (select count(*) from t1)) +(partition p1 values less than (1)); +ERROR HY000: This partition function is not allowed +create table t1 (a char(10)) +partition by hash (extractvalue(a,'a')); +ERROR HY000: The PARTITION function returns the wrong type diff --git a/mysql-test/r/ps_1general.result b/mysql-test/r/ps_1general.result index d0b773dfe34..1a1d6432411 100644 --- a/mysql-test/r/ps_1general.result +++ b/mysql-test/r/ps_1general.result @@ -299,7 +299,7 @@ t9 MyISAM 10 Dynamic 2 216 432 # 2048 0 NULL # # # latin1_swedish_ci NULL prepare stmt4 from ' show status like ''Threads_running'' '; execute stmt4; Variable_name Value -Threads_running 1 +Threads_running 2 prepare stmt4 from ' show variables like ''sql_mode'' '; execute stmt4; Variable_name Value diff --git a/mysql-test/r/ps_2myisam.result b/mysql-test/r/ps_2myisam.result index ffe2b4d6409..5ba601bf305 100644 --- a/mysql-test/r/ps_2myisam.result +++ b/mysql-test/r/ps_2myisam.result @@ -1777,7 +1777,7 @@ Table Create Table t5 CREATE TABLE `t5` ( `const01` bigint(1) NOT NULL DEFAULT '0', `param01` bigint(20) DEFAULT NULL, - `const02` decimal(2,1) unsigned NOT NULL DEFAULT '0.0', + `const02` decimal(2,1) NOT NULL DEFAULT '0.0', `param02` decimal(65,30) DEFAULT NULL, `const03` double NOT NULL DEFAULT '0', `param03` double DEFAULT NULL, @@ -1807,7 +1807,7 @@ select * from t5 ; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr def test t5 t5 const01 const01 8 1 1 N 32769 0 63 def test t5 t5 param01 param01 8 20 1 Y 32768 0 63 -def test t5 t5 const02 const02 246 3 3 N 33 1 63 +def test t5 t5 const02 const02 246 4 3 N 1 1 63 def test t5 t5 param02 param02 246 67 32 Y 0 30 63 def test t5 t5 const03 const03 5 17 1 N 32769 31 63 def test t5 t5 param03 param03 5 23 1 Y 32768 31 63 diff --git a/mysql-test/r/ps_3innodb.result b/mysql-test/r/ps_3innodb.result index 707e5ed681f..836fb7b58c2 100644 --- a/mysql-test/r/ps_3innodb.result +++ b/mysql-test/r/ps_3innodb.result @@ -1760,7 +1760,7 @@ Table Create Table t5 CREATE TABLE `t5` ( `const01` bigint(1) NOT NULL DEFAULT '0', `param01` bigint(20) DEFAULT NULL, - `const02` decimal(2,1) unsigned NOT NULL DEFAULT '0.0', + `const02` decimal(2,1) NOT NULL DEFAULT '0.0', `param02` decimal(65,30) DEFAULT NULL, `const03` double NOT NULL DEFAULT '0', `param03` double DEFAULT NULL, @@ -1790,7 +1790,7 @@ select * from t5 ; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr def test t5 t5 const01 const01 8 1 1 N 32769 0 63 def test t5 t5 param01 param01 8 20 1 Y 32768 0 63 -def test t5 t5 const02 const02 246 3 3 N 33 1 63 +def test t5 t5 const02 const02 246 4 3 N 1 1 63 def test t5 t5 param02 param02 246 67 32 Y 0 30 63 def test t5 t5 const03 const03 5 17 1 N 32769 31 63 def test t5 t5 param03 param03 5 23 1 Y 32768 31 63 diff --git a/mysql-test/r/ps_4heap.result b/mysql-test/r/ps_4heap.result index 06429f92580..150820d92f0 100644 --- a/mysql-test/r/ps_4heap.result +++ b/mysql-test/r/ps_4heap.result @@ -1761,7 +1761,7 @@ Table Create Table t5 CREATE TABLE `t5` ( `const01` bigint(1) NOT NULL DEFAULT '0', `param01` bigint(20) DEFAULT NULL, - `const02` decimal(2,1) unsigned NOT NULL DEFAULT '0.0', + `const02` decimal(2,1) NOT NULL DEFAULT '0.0', `param02` decimal(65,30) DEFAULT NULL, `const03` double NOT NULL DEFAULT '0', `param03` double DEFAULT NULL, @@ -1791,7 +1791,7 @@ select * from t5 ; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr def test t5 t5 const01 const01 8 1 1 N 32769 0 63 def test t5 t5 param01 param01 8 20 1 Y 32768 0 63 -def test t5 t5 const02 const02 246 3 3 N 33 1 63 +def test t5 t5 const02 const02 246 4 3 N 1 1 63 def test t5 t5 param02 param02 246 67 32 Y 0 30 63 def test t5 t5 const03 const03 5 17 1 N 32769 31 63 def test t5 t5 param03 param03 5 23 1 Y 32768 31 63 diff --git a/mysql-test/r/ps_5merge.result b/mysql-test/r/ps_5merge.result index c1002970932..72573ce3294 100644 --- a/mysql-test/r/ps_5merge.result +++ b/mysql-test/r/ps_5merge.result @@ -1697,7 +1697,7 @@ Table Create Table t5 CREATE TABLE `t5` ( `const01` bigint(1) NOT NULL DEFAULT '0', `param01` bigint(20) DEFAULT NULL, - `const02` decimal(2,1) unsigned NOT NULL DEFAULT '0.0', + `const02` decimal(2,1) NOT NULL DEFAULT '0.0', `param02` decimal(65,30) DEFAULT NULL, `const03` double NOT NULL DEFAULT '0', `param03` double DEFAULT NULL, @@ -1727,7 +1727,7 @@ select * from t5 ; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr def test t5 t5 const01 const01 8 1 1 N 32769 0 63 def test t5 t5 param01 param01 8 20 1 Y 32768 0 63 -def test t5 t5 const02 const02 246 3 3 N 33 1 63 +def test t5 t5 const02 const02 246 4 3 N 1 1 63 def test t5 t5 param02 param02 246 67 32 Y 0 30 63 def test t5 t5 const03 const03 5 17 1 N 32769 31 63 def test t5 t5 param03 param03 5 23 1 Y 32768 31 63 @@ -4711,7 +4711,7 @@ Table Create Table t5 CREATE TABLE `t5` ( `const01` bigint(1) NOT NULL DEFAULT '0', `param01` bigint(20) DEFAULT NULL, - `const02` decimal(2,1) unsigned NOT NULL DEFAULT '0.0', + `const02` decimal(2,1) NOT NULL DEFAULT '0.0', `param02` decimal(65,30) DEFAULT NULL, `const03` double NOT NULL DEFAULT '0', `param03` double DEFAULT NULL, @@ -4741,7 +4741,7 @@ select * from t5 ; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr def test t5 t5 const01 const01 8 1 1 N 32769 0 63 def test t5 t5 param01 param01 8 20 1 Y 32768 0 63 -def test t5 t5 const02 const02 246 3 3 N 33 1 63 +def test t5 t5 const02 const02 246 4 3 N 1 1 63 def test t5 t5 param02 param02 246 67 32 Y 0 30 63 def test t5 t5 const03 const03 5 17 1 N 32769 31 63 def test t5 t5 param03 param03 5 23 1 Y 32768 31 63 diff --git a/mysql-test/r/ps_6bdb.result b/mysql-test/r/ps_6bdb.result index ea1212addf5..44b4ebf33d4 100644 --- a/mysql-test/r/ps_6bdb.result +++ b/mysql-test/r/ps_6bdb.result @@ -1760,7 +1760,7 @@ Table Create Table t5 CREATE TABLE `t5` ( `const01` bigint(1) NOT NULL DEFAULT '0', `param01` bigint(20) DEFAULT NULL, - `const02` decimal(2,1) unsigned NOT NULL DEFAULT '0.0', + `const02` decimal(2,1) NOT NULL DEFAULT '0.0', `param02` decimal(65,30) DEFAULT NULL, `const03` double NOT NULL DEFAULT '0', `param03` double DEFAULT NULL, @@ -1790,7 +1790,7 @@ select * from t5 ; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr def test t5 t5 const01 const01 8 1 1 N 32769 0 63 def test t5 t5 param01 param01 8 20 1 Y 32768 0 63 -def test t5 t5 const02 const02 246 3 3 N 33 1 63 +def test t5 t5 const02 const02 246 4 3 N 1 1 63 def test t5 t5 param02 param02 246 67 32 Y 0 30 63 def test t5 t5 const03 const03 5 17 1 N 32769 31 63 def test t5 t5 param03 param03 5 23 1 Y 32768 31 63 diff --git a/mysql-test/r/ps_7ndb.result b/mysql-test/r/ps_7ndb.result index 65cf7c1f88c..543435e4cd9 100644 --- a/mysql-test/r/ps_7ndb.result +++ b/mysql-test/r/ps_7ndb.result @@ -1760,7 +1760,7 @@ Table Create Table t5 CREATE TABLE `t5` ( `const01` bigint(1) NOT NULL default '0', `param01` bigint(20) default NULL, - `const02` decimal(2,1) unsigned NOT NULL default '0.0', + `const02` decimal(2,1) NOT NULL default '0.0', `param02` decimal(65,30) default NULL, `const03` double NOT NULL default '0', `param03` double default NULL, @@ -1790,7 +1790,7 @@ select * from t5 ; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr def test t5 t5 const01 const01 8 1 1 N 32769 0 63 def test t5 t5 param01 param01 8 20 1 Y 32768 0 63 -def test t5 t5 const02 const02 246 3 3 N 33 1 63 +def test t5 t5 const02 const02 246 4 3 N 1 1 63 def test t5 t5 param02 param02 246 67 32 Y 0 30 63 def test t5 t5 const03 const03 5 17 1 N 32769 31 63 def test t5 t5 param03 param03 5 23 1 Y 32768 31 63 diff --git a/mysql-test/r/rpl_bit_npk.result b/mysql-test/r/rpl_bit_npk.result index 2850e63aabd..9599660f18f 100644 --- a/mysql-test/r/rpl_bit_npk.result +++ b/mysql-test/r/rpl_bit_npk.result @@ -56,86 +56,90 @@ INSERT INTO test.t1 VALUES (8,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,4 UNLOCK TABLES; UPDATE test.t1 set x034 = 50 where bit3 = b'000000'; UPDATE test.t1 set VNotSupp = 33 where bit1 = b'0'; -SELECT oSupp, sSuppD, GSuppDf, VNotSupp, x034 FROM test.t1; +SELECT oSupp, sSuppD, GSuppDf, VNotSupp, x034 +FROM test.t1 +ORDER BY oSupp, sSuppD, GSuppDf, VNotSupp, x034; oSupp sSuppD GSuppDf VNotSupp x034 5 5 3 NULL 1 5 5 3 2 1 -5 5 3 33 1 5 5 3 2 50 5 5 3 33 1 5 5 3 33 1 5 5 3 33 1 5 5 3 33 1 -SELECT hex(bit1) from test.t1; +5 5 3 33 1 +SELECT hex(bit1) from test.t1 ORDER BY bit1; hex(bit1) -3F -3F -0 -2A 0 0 0 0 -SELECT hex(bit2) from test.t1; -hex(bit2) -3E 0 2A 3F +3F +SELECT hex(bit2) from test.t1 ORDER BY bit2; +hex(bit2) +0 1 1 1 1 -SELECT hex(bit3) from test.t1; +2A +3E +3F +SELECT hex(bit3) from test.t1 ORDER BY bit3; hex(bit3) -35 -24 -15 0 1 1 1 1 -SELECT oSupp, sSuppD, GSuppDf, VNotSupp, x034 FROM test.t1; +15 +24 +35 +SELECT oSupp, sSuppD, GSuppDf, VNotSupp, x034 +FROM test.t1 +ORDER BY oSupp, sSuppD, GSuppDf, VNotSupp, x034; oSupp sSuppD GSuppDf VNotSupp x034 5 5 3 NULL 1 5 5 3 2 1 -5 5 3 33 1 5 5 3 2 50 5 5 3 33 1 5 5 3 33 1 5 5 3 33 1 5 5 3 33 1 -SELECT hex(bit1) from test.t1; +5 5 3 33 1 +SELECT hex(bit1) from test.t1 ORDER BY bit1; hex(bit1) -3F -3F -0 -2A 0 0 0 0 -SELECT hex(bit2) from test.t1; -hex(bit2) -3E 0 2A 3F +3F +SELECT hex(bit2) from test.t1 ORDER BY bit2; +hex(bit2) +0 1 1 1 1 -SELECT hex(bit3) from test.t1; +2A +3E +3F +SELECT hex(bit3) from test.t1 ORDER BY bit3; hex(bit3) -35 -24 -15 0 1 1 1 1 +15 +24 +35 CREATE TABLE test.t2 (a INT, b BIT(1)); INSERT INTO test.t2 VALUES (1, b'0'); INSERT INTO test.t2 VALUES (1, b'1'); @@ -144,19 +148,19 @@ CREATE TABLE test.t3 (a INT, b INT); INSERT INTO test.t3 VALUES (1, NULL); INSERT INTO test.t3 VALUES (1, 0); UPDATE test.t3 SET a = 2 WHERE b = 0; -SELECT a, hex(b) FROM test.t2; +SELECT a, hex(b) FROM test.t2 ORDER BY a,b; a hex(b) 1 0 2 1 -SELECT * FROM test.t3; +SELECT * FROM test.t3 ORDER BY a,b; a b 1 NULL 2 0 -SELECT a, hex(b) FROM test.t2; +SELECT a, hex(b) FROM test.t2 ORDER BY a,b; a hex(b) 1 0 2 1 -SELECT * FROM test.t3; +SELECT * FROM test.t3 ORDER BY a,b; a b 1 NULL 2 0 diff --git a/mysql-test/r/rpl_ndb_UUID.result b/mysql-test/r/rpl_ndb_UUID.result index c768779c49b..422379d4f55 100644 --- a/mysql-test/r/rpl_ndb_UUID.result +++ b/mysql-test/r/rpl_ndb_UUID.result @@ -33,7 +33,7 @@ t1 CREATE TABLE `t1` ( `blob_column` longblob, `vchar_column` varchar(100) DEFAULT NULL, PRIMARY KEY (`a`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 DROP PROCEDURE test.p1; DROP FUNCTION test.fn1; DROP TABLE test.t1; diff --git a/mysql-test/r/rpl_ndb_dd_advance.result b/mysql-test/r/rpl_ndb_dd_advance.result index ba89592b532..2cb1cce649b 100644 --- a/mysql-test/r/rpl_ndb_dd_advance.result +++ b/mysql-test/r/rpl_ndb_dd_advance.result @@ -69,7 +69,7 @@ t1 CREATE TABLE `t1` ( PRIMARY KEY (`c1`), KEY `t1_i` (`c2`,`c3`), KEY `c5` (`c5`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 **** Show first set of ALTERs on SLAVE **** SHOW CREATE TABLE t1; Table Create Table @@ -82,7 +82,7 @@ t1 CREATE TABLE `t1` ( PRIMARY KEY (`c1`), KEY `t1_i` (`c2`,`c3`), KEY `c5` (`c5`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 **** Second set of alters test 1 **** ALTER TABLE t1 RENAME t2; ALTER TABLE t2 DROP INDEX c5; @@ -101,7 +101,7 @@ t1 CREATE TABLE `t1` ( `c5` double DEFAULT NULL, PRIMARY KEY (`c1`), KEY `t1_i` (`c2`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 **** Show second set of ALTERs on SLAVE **** SHOW CREATE TABLE t1; Table Create Table @@ -113,7 +113,7 @@ t1 CREATE TABLE `t1` ( `c5` double DEFAULT NULL, PRIMARY KEY (`c1`), KEY `t1_i` (`c2`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 **** Third and last set of alters for test1 **** ALTER TABLE t1 CHANGE c1 c1 DOUBLE; ALTER TABLE t1 CHANGE c2 c2 DECIMAL(10,2); @@ -135,7 +135,7 @@ t1 CREATE TABLE `t1` ( `c5` double DEFAULT NULL, PRIMARY KEY (`c1`), KEY `t1_i` (`c2`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 SELECT * FROM t1 ORDER BY c1 LIMIT 5; c1 c2 c3 c5 1 2.00 b1b1b1b1b1b1b1b1b1b1 NULL @@ -153,7 +153,7 @@ t1 CREATE TABLE `t1` ( `c5` double DEFAULT NULL, PRIMARY KEY (`c1`), KEY `t1_i` (`c2`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 SELECT * FROM t1 where c1 = 1; c1 c2 c3 c5 1 2.00 b1b1b1b1b1b1b1b1b1b1 NULL diff --git a/mysql-test/r/rpl_ndb_dd_partitions.result b/mysql-test/r/rpl_ndb_dd_partitions.result deleted file mode 100644 index ece6b84c227..00000000000 --- a/mysql-test/r/rpl_ndb_dd_partitions.result +++ /dev/null @@ -1,726 +0,0 @@ -stop slave; -drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; -reset master; -reset slave; -drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; -start slave; ---- Doing pre test cleanup --- -DROP TABLE IF EXISTS t1; -CREATE LOGFILE GROUP lg1 -ADD UNDOFILE 'undofile.dat' -INITIAL_SIZE 16M -UNDO_BUFFER_SIZE = 1M -ENGINE=NDB; -ALTER LOGFILE GROUP lg1 -ADD UNDOFILE 'undofile02.dat' -INITIAL_SIZE = 4M -ENGINE=NDB; -CREATE TABLESPACE ts1 -ADD DATAFILE 'datafile.dat' -USE LOGFILE GROUP lg1 -INITIAL_SIZE 12M -ENGINE NDB; -ALTER TABLESPACE ts1 -ADD DATAFILE 'datafile02.dat' -INITIAL_SIZE = 4M -ENGINE=NDB; ---- Start test 2 partition RANGE testing -- ---- Do setup -- -CREATE TABLE t1 (id MEDIUMINT NOT NULL, b1 BIT(8), vc VARCHAR(63), -bc CHAR(63), d DECIMAL(10,4) DEFAULT 0, -f FLOAT DEFAULT 0, total BIGINT UNSIGNED, -y YEAR, t DATE) -TABLESPACE ts1 STORAGE DISK -ENGINE=NDB -PARTITION BY RANGE (YEAR(t)) -(PARTITION p0 VALUES LESS THAN (1901), -PARTITION p1 VALUES LESS THAN (1946), -PARTITION p2 VALUES LESS THAN (1966), -PARTITION p3 VALUES LESS THAN (1986), -PARTITION p4 VALUES LESS THAN (2005), -PARTITION p5 VALUES LESS THAN MAXVALUE); ---- Show table on master --- -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `id` mediumint(9) NOT NULL, - `b1` bit(8) DEFAULT NULL, - `vc` varchar(63) DEFAULT NULL, - `bc` char(63) DEFAULT NULL, - `d` decimal(10,4) DEFAULT '0.0000', - `f` float DEFAULT '0', - `total` bigint(20) unsigned DEFAULT NULL, - `y` year(4) DEFAULT NULL, - `t` date DEFAULT NULL -) TABLESPACE ts1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY RANGE (YEAR(t)) (PARTITION p0 VALUES LESS THAN (1901) ENGINE = ndbcluster, PARTITION p1 VALUES LESS THAN (1946) ENGINE = ndbcluster, PARTITION p2 VALUES LESS THAN (1966) ENGINE = ndbcluster, PARTITION p3 VALUES LESS THAN (1986) ENGINE = ndbcluster, PARTITION p4 VALUES LESS THAN (2005) ENGINE = ndbcluster, PARTITION p5 VALUES LESS THAN MAXVALUE ENGINE = ndbcluster) ---- Show table on slave -- -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `id` mediumint(9) NOT NULL, - `b1` bit(8) DEFAULT NULL, - `vc` varchar(63) DEFAULT NULL, - `bc` char(63) DEFAULT NULL, - `d` decimal(10,4) DEFAULT '0.0000', - `f` float DEFAULT '0', - `total` bigint(20) unsigned DEFAULT NULL, - `y` year(4) DEFAULT NULL, - `t` date DEFAULT NULL -) TABLESPACE ts1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY RANGE (YEAR(t)) (PARTITION p0 VALUES LESS THAN (1901) ENGINE = ndbcluster, PARTITION p1 VALUES LESS THAN (1946) ENGINE = ndbcluster, PARTITION p2 VALUES LESS THAN (1966) ENGINE = ndbcluster, PARTITION p3 VALUES LESS THAN (1986) ENGINE = ndbcluster, PARTITION p4 VALUES LESS THAN (2005) ENGINE = ndbcluster, PARTITION p5 VALUES LESS THAN MAXVALUE ENGINE = ndbcluster) ---- Perform basic operation on master --- ---- and ensure replicated correctly --- -"--- Insert into t1 --" as ""; ---- Select from t1 on master --- -select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; -id hex(b1) vc bc d f total y t -2 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1965-11-14 -4 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1985-11-14 -42 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1905-11-14 -142 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1995-11-14 -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2005-11-14 ---- Select from t1 on slave --- -select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; -id hex(b1) vc bc d f total y t -2 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1965-11-14 -4 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1985-11-14 -42 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1905-11-14 -142 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1995-11-14 -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2005-11-14 ---- Update t1 on master -- -UPDATE t1 SET b1 = 0, t="2006-02-22" WHERE id = 412; ---- Check the update on master --- -SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; -id hex(b1) vc bc d f total y t -412 0 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2006-02-22 ---- Check Update on slave --- -SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; -id hex(b1) vc bc d f total y t -412 0 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2006-02-22 ---- Remove a record from t1 on master --- -DELETE FROM t1 WHERE id = 42; ---- Show current count on master for t1 --- -SELECT COUNT(*) FROM t1; -COUNT(*) -4 ---- Show current count on slave for t1 --- -SELECT COUNT(*) FROM t1; -COUNT(*) -4 -DELETE FROM t1; ---- Check that simple Alter statements are replicated correctly --- -ALTER TABLE t1 MODIFY vc VARCHAR(255); ---- Show the new improved table on the master --- -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `id` mediumint(9) NOT NULL, - `b1` bit(8) DEFAULT NULL, - `vc` varchar(255) DEFAULT NULL, - `bc` char(63) DEFAULT NULL, - `d` decimal(10,4) DEFAULT '0.0000', - `f` float DEFAULT '0', - `total` bigint(20) unsigned DEFAULT NULL, - `y` year(4) DEFAULT NULL, - `t` date DEFAULT NULL -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY RANGE (YEAR(t)) (PARTITION p0 VALUES LESS THAN (1901) ENGINE = ndbcluster, PARTITION p1 VALUES LESS THAN (1946) ENGINE = ndbcluster, PARTITION p2 VALUES LESS THAN (1966) ENGINE = ndbcluster, PARTITION p3 VALUES LESS THAN (1986) ENGINE = ndbcluster, PARTITION p4 VALUES LESS THAN (2005) ENGINE = ndbcluster, PARTITION p5 VALUES LESS THAN MAXVALUE ENGINE = ndbcluster) ---- Make sure that our tables on slave are still same engine --- ---- and that the alter statements replicated correctly --- -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `id` mediumint(9) NOT NULL, - `b1` bit(8) DEFAULT NULL, - `vc` varchar(255) DEFAULT NULL, - `bc` char(63) DEFAULT NULL, - `d` decimal(10,4) DEFAULT '0.0000', - `f` float DEFAULT '0', - `total` bigint(20) unsigned DEFAULT NULL, - `y` year(4) DEFAULT NULL, - `t` date DEFAULT NULL -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY RANGE (YEAR(t)) (PARTITION p0 VALUES LESS THAN (1901) ENGINE = ndbcluster, PARTITION p1 VALUES LESS THAN (1946) ENGINE = ndbcluster, PARTITION p2 VALUES LESS THAN (1966) ENGINE = ndbcluster, PARTITION p3 VALUES LESS THAN (1986) ENGINE = ndbcluster, PARTITION p4 VALUES LESS THAN (2005) ENGINE = ndbcluster, PARTITION p5 VALUES LESS THAN MAXVALUE ENGINE = ndbcluster) ---- Perform basic operation on master --- ---- and ensure replicated correctly --- -"--- Insert into t1 --" as ""; ---- Select from t1 on master --- -select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; -id hex(b1) vc bc d f total y t -2 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1965-11-14 -4 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1985-11-14 -42 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1905-11-14 -142 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1995-11-14 -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2005-11-14 ---- Select from t1 on slave --- -select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; -id hex(b1) vc bc d f total y t -2 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1965-11-14 -4 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1985-11-14 -42 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1905-11-14 -142 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1995-11-14 -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2005-11-14 ---- Update t1 on master -- -UPDATE t1 SET b1 = 0, t="2006-02-22" WHERE id = 412; ---- Check the update on master --- -SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; -id hex(b1) vc bc d f total y t -412 0 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2006-02-22 ---- Check Update on slave --- -SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; -id hex(b1) vc bc d f total y t -412 0 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2006-02-22 ---- Remove a record from t1 on master --- -DELETE FROM t1 WHERE id = 42; ---- Show current count on master for t1 --- -SELECT COUNT(*) FROM t1; -COUNT(*) -4 ---- Show current count on slave for t1 --- -SELECT COUNT(*) FROM t1; -COUNT(*) -4 -DELETE FROM t1; ---- End test 2 partition RANGE testing --- ---- Do Cleanup --- -DROP TABLE IF EXISTS t1; ---- Start test 3 partition LIST testing --- ---- Do setup --- -CREATE TABLE t1 (id MEDIUMINT NOT NULL, b1 BIT(8), vc VARCHAR(63), -bc CHAR(63), d DECIMAL(10,4) DEFAULT 0, -f FLOAT DEFAULT 0, total BIGINT UNSIGNED, -y YEAR, t DATE) -TABLESPACE ts1 STORAGE DISK -ENGINE=NDB -PARTITION BY LIST(id) -(PARTITION p0 VALUES IN (2, 4), -PARTITION p1 VALUES IN (42, 142)); ---- Test 3 Alter to add partition --- -ALTER TABLE t1 ADD PARTITION (PARTITION p2 VALUES IN (412)); ---- Show table on master --- -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `id` mediumint(9) NOT NULL, - `b1` bit(8) DEFAULT NULL, - `vc` varchar(63) DEFAULT NULL, - `bc` char(63) DEFAULT NULL, - `d` decimal(10,4) DEFAULT '0.0000', - `f` float DEFAULT '0', - `total` bigint(20) unsigned DEFAULT NULL, - `y` year(4) DEFAULT NULL, - `t` date DEFAULT NULL -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY LIST (id) (PARTITION p0 VALUES IN (2,4) ENGINE = ndbcluster, PARTITION p1 VALUES IN (42,142) ENGINE = ndbcluster, PARTITION p2 VALUES IN (412) ENGINE = ndbcluster) ---- Show table on slave --- -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `id` mediumint(9) NOT NULL, - `b1` bit(8) DEFAULT NULL, - `vc` varchar(63) DEFAULT NULL, - `bc` char(63) DEFAULT NULL, - `d` decimal(10,4) DEFAULT '0.0000', - `f` float DEFAULT '0', - `total` bigint(20) unsigned DEFAULT NULL, - `y` year(4) DEFAULT NULL, - `t` date DEFAULT NULL -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY LIST (id) (PARTITION p0 VALUES IN (2,4) ENGINE = ndbcluster, PARTITION p1 VALUES IN (42,142) ENGINE = ndbcluster, PARTITION p2 VALUES IN (412) ENGINE = ndbcluster) ---- Perform basic operation on master --- ---- and ensure replicated correctly --- -"--- Insert into t1 --" as ""; ---- Select from t1 on master --- -select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; -id hex(b1) vc bc d f total y t -2 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1965-11-14 -4 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1985-11-14 -42 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1905-11-14 -142 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1995-11-14 -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2005-11-14 ---- Select from t1 on slave --- -select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; -id hex(b1) vc bc d f total y t -2 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1965-11-14 -4 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1985-11-14 -42 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1905-11-14 -142 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1995-11-14 -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2005-11-14 ---- Update t1 on master -- -UPDATE t1 SET b1 = 0, t="2006-02-22" WHERE id = 412; ---- Check the update on master --- -SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; -id hex(b1) vc bc d f total y t -412 0 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2006-02-22 ---- Check Update on slave --- -SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; -id hex(b1) vc bc d f total y t -412 0 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2006-02-22 ---- Remove a record from t1 on master --- -DELETE FROM t1 WHERE id = 42; ---- Show current count on master for t1 --- -SELECT COUNT(*) FROM t1; -COUNT(*) -4 ---- Show current count on slave for t1 --- -SELECT COUNT(*) FROM t1; -COUNT(*) -4 -DELETE FROM t1; ---- Check that simple Alter statements are replicated correctly --- -ALTER TABLE t1 MODIFY vc VARCHAR(255); ---- Show the new improved table on the master --- -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `id` mediumint(9) NOT NULL, - `b1` bit(8) DEFAULT NULL, - `vc` varchar(255) DEFAULT NULL, - `bc` char(63) DEFAULT NULL, - `d` decimal(10,4) DEFAULT '0.0000', - `f` float DEFAULT '0', - `total` bigint(20) unsigned DEFAULT NULL, - `y` year(4) DEFAULT NULL, - `t` date DEFAULT NULL -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY LIST (id) (PARTITION p0 VALUES IN (2,4) ENGINE = ndbcluster, PARTITION p1 VALUES IN (42,142) ENGINE = ndbcluster, PARTITION p2 VALUES IN (412) ENGINE = ndbcluster) ---- Make sure that our tables on slave are still same engine --- ---- and that the alter statements replicated correctly --- -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `id` mediumint(9) NOT NULL, - `b1` bit(8) DEFAULT NULL, - `vc` varchar(255) DEFAULT NULL, - `bc` char(63) DEFAULT NULL, - `d` decimal(10,4) DEFAULT '0.0000', - `f` float DEFAULT '0', - `total` bigint(20) unsigned DEFAULT NULL, - `y` year(4) DEFAULT NULL, - `t` date DEFAULT NULL -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY LIST (id) (PARTITION p0 VALUES IN (2,4) ENGINE = ndbcluster, PARTITION p1 VALUES IN (42,142) ENGINE = ndbcluster, PARTITION p2 VALUES IN (412) ENGINE = ndbcluster) ---- Perform basic operation on master --- ---- and ensure replicated correctly --- -"--- Insert into t1 --" as ""; ---- Select from t1 on master --- -select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; -id hex(b1) vc bc d f total y t -2 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1965-11-14 -4 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1985-11-14 -42 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1905-11-14 -142 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1995-11-14 -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2005-11-14 ---- Select from t1 on slave --- -select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; -id hex(b1) vc bc d f total y t -2 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1965-11-14 -4 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1985-11-14 -42 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1905-11-14 -142 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1995-11-14 -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2005-11-14 ---- Update t1 on master -- -UPDATE t1 SET b1 = 0, t="2006-02-22" WHERE id = 412; ---- Check the update on master --- -SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; -id hex(b1) vc bc d f total y t -412 0 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2006-02-22 ---- Check Update on slave --- -SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; -id hex(b1) vc bc d f total y t -412 0 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2006-02-22 ---- Remove a record from t1 on master --- -DELETE FROM t1 WHERE id = 42; ---- Show current count on master for t1 --- -SELECT COUNT(*) FROM t1; -COUNT(*) -4 ---- Show current count on slave for t1 --- -SELECT COUNT(*) FROM t1; -COUNT(*) -4 -DELETE FROM t1; ---- End test 3 partition LIST testing --- ---- Do Cleanup -- -DROP TABLE IF EXISTS t1; ---- Start test 4 partition HASH testing --- ---- Do setup --- -CREATE TABLE t1 (id MEDIUMINT NOT NULL, b1 BIT(8), vc VARCHAR(63), -bc CHAR(63), d DECIMAL(10,4) DEFAULT 0, -f FLOAT DEFAULT 0, total BIGINT UNSIGNED, -y YEAR, t DATE) -TABLESPACE ts1 STORAGE DISK -ENGINE=NDB -PARTITION BY HASH( YEAR(t) ) -PARTITIONS 4; ---- show that tables have been created correctly --- -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `id` mediumint(9) NOT NULL, - `b1` bit(8) DEFAULT NULL, - `vc` varchar(63) DEFAULT NULL, - `bc` char(63) DEFAULT NULL, - `d` decimal(10,4) DEFAULT '0.0000', - `f` float DEFAULT '0', - `total` bigint(20) unsigned DEFAULT NULL, - `y` year(4) DEFAULT NULL, - `t` date DEFAULT NULL -) TABLESPACE ts1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY HASH ( YEAR(t)) PARTITIONS 4 -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `id` mediumint(9) NOT NULL, - `b1` bit(8) DEFAULT NULL, - `vc` varchar(63) DEFAULT NULL, - `bc` char(63) DEFAULT NULL, - `d` decimal(10,4) DEFAULT '0.0000', - `f` float DEFAULT '0', - `total` bigint(20) unsigned DEFAULT NULL, - `y` year(4) DEFAULT NULL, - `t` date DEFAULT NULL -) TABLESPACE ts1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY HASH ( YEAR(t)) PARTITIONS 4 ---- Perform basic operation on master --- ---- and ensure replicated correctly --- -"--- Insert into t1 --" as ""; ---- Select from t1 on master --- -select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; -id hex(b1) vc bc d f total y t -2 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1965-11-14 -4 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1985-11-14 -42 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1905-11-14 -142 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1995-11-14 -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2005-11-14 ---- Select from t1 on slave --- -select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; -id hex(b1) vc bc d f total y t -2 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1965-11-14 -4 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1985-11-14 -42 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1905-11-14 -142 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1995-11-14 -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2005-11-14 ---- Update t1 on master -- -UPDATE t1 SET b1 = 0, t="2006-02-22" WHERE id = 412; ---- Check the update on master --- -SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; -id hex(b1) vc bc d f total y t -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2006-02-22 ---- Check Update on slave --- -SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; -id hex(b1) vc bc d f total y t -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2006-02-22 ---- Remove a record from t1 on master --- -DELETE FROM t1 WHERE id = 42; ---- Show current count on master for t1 --- -SELECT COUNT(*) FROM t1; -COUNT(*) -4 ---- Show current count on slave for t1 --- -SELECT COUNT(*) FROM t1; -COUNT(*) -4 -DELETE FROM t1; ---- Check that simple Alter statements are replicated correctly --- -ALTER TABLE t1 MODIFY vc VARCHAR(255); ---- Show the new improved table on the master --- -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `id` mediumint(9) NOT NULL, - `b1` bit(8) DEFAULT NULL, - `vc` varchar(255) DEFAULT NULL, - `bc` char(63) DEFAULT NULL, - `d` decimal(10,4) DEFAULT '0.0000', - `f` float DEFAULT '0', - `total` bigint(20) unsigned DEFAULT NULL, - `y` year(4) DEFAULT NULL, - `t` date DEFAULT NULL -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY HASH ( YEAR(t)) PARTITIONS 4 ---- Make sure that our tables on slave are still same engine --- ---- and that the alter statements replicated correctly --- -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `id` mediumint(9) NOT NULL, - `b1` bit(8) DEFAULT NULL, - `vc` varchar(255) DEFAULT NULL, - `bc` char(63) DEFAULT NULL, - `d` decimal(10,4) DEFAULT '0.0000', - `f` float DEFAULT '0', - `total` bigint(20) unsigned DEFAULT NULL, - `y` year(4) DEFAULT NULL, - `t` date DEFAULT NULL -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY HASH ( YEAR(t)) PARTITIONS 4 ---- Perform basic operation on master --- ---- and ensure replicated correctly --- -"--- Insert into t1 --" as ""; ---- Select from t1 on master --- -select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; -id hex(b1) vc bc d f total y t -2 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1965-11-14 -4 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1985-11-14 -42 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1905-11-14 -142 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1995-11-14 -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2005-11-14 ---- Select from t1 on slave --- -select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; -id hex(b1) vc bc d f total y t -2 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1965-11-14 -4 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1985-11-14 -42 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1905-11-14 -142 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1995-11-14 -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2005-11-14 ---- Update t1 on master -- -UPDATE t1 SET b1 = 0, t="2006-02-22" WHERE id = 412; ---- Check the update on master --- -SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; -id hex(b1) vc bc d f total y t -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2006-02-22 ---- Check Update on slave --- -SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; -id hex(b1) vc bc d f total y t -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2006-02-22 ---- Remove a record from t1 on master --- -DELETE FROM t1 WHERE id = 42; ---- Show current count on master for t1 --- -SELECT COUNT(*) FROM t1; -COUNT(*) -4 ---- Show current count on slave for t1 --- -SELECT COUNT(*) FROM t1; -COUNT(*) -4 -DELETE FROM t1; ---- End test 4 partition HASH testing --- ---- Do Cleanup -- -DROP TABLE IF EXISTS t1; ---- Start test 5 partition by key testing --- ---- Create Table Section --- -CREATE TABLE t1 (id MEDIUMINT NOT NULL, b1 BIT(8), vc VARCHAR(63), -bc CHAR(63), d DECIMAL(10,4) DEFAULT 0, -f FLOAT DEFAULT 0, total BIGINT UNSIGNED, -y YEAR, t DATE,PRIMARY KEY(id)) -TABLESPACE ts1 STORAGE DISK -ENGINE=NDB -PARTITION BY KEY() -PARTITIONS 4; ---- Show that tables on master are ndbcluster tables --- -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `id` mediumint(9) NOT NULL, - `b1` bit(8) DEFAULT NULL, - `vc` varchar(63) DEFAULT NULL, - `bc` char(63) DEFAULT NULL, - `d` decimal(10,4) DEFAULT '0.0000', - `f` float DEFAULT '0', - `total` bigint(20) unsigned DEFAULT NULL, - `y` year(4) DEFAULT NULL, - `t` date DEFAULT NULL, - PRIMARY KEY (`id`) -) TABLESPACE ts1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () PARTITIONS 4 ---- Show that tables on slave --- -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `id` mediumint(9) NOT NULL, - `b1` bit(8) DEFAULT NULL, - `vc` varchar(63) DEFAULT NULL, - `bc` char(63) DEFAULT NULL, - `d` decimal(10,4) DEFAULT '0.0000', - `f` float DEFAULT '0', - `total` bigint(20) unsigned DEFAULT NULL, - `y` year(4) DEFAULT NULL, - `t` date DEFAULT NULL, - PRIMARY KEY (`id`) -) TABLESPACE ts1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () PARTITIONS 4 ---- Perform basic operation on master --- ---- and ensure replicated correctly --- -"--- Insert into t1 --" as ""; ---- Select from t1 on master --- -select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; -id hex(b1) vc bc d f total y t -2 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1965-11-14 -4 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1985-11-14 -42 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1905-11-14 -142 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1995-11-14 -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2005-11-14 ---- Select from t1 on slave --- -select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; -id hex(b1) vc bc d f total y t -2 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1965-11-14 -4 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1985-11-14 -42 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1905-11-14 -142 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1995-11-14 -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2005-11-14 ---- Update t1 on master -- -UPDATE t1 SET b1 = 0, t="2006-02-22" WHERE id = 412; ---- Check the update on master --- -SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; -id hex(b1) vc bc d f total y t -412 0 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2006-02-22 ---- Check Update on slave --- -SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; -id hex(b1) vc bc d f total y t -412 0 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2006-02-22 ---- Remove a record from t1 on master --- -DELETE FROM t1 WHERE id = 42; ---- Show current count on master for t1 --- -SELECT COUNT(*) FROM t1; -COUNT(*) -4 ---- Show current count on slave for t1 --- -SELECT COUNT(*) FROM t1; -COUNT(*) -4 -DELETE FROM t1; ---- Check that simple Alter statements are replicated correctly --- -ALTER TABLE t1 DROP PRIMARY KEY, ADD PRIMARY KEY(id, total); ---- Show the new improved table on the master --- -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `id` mediumint(9) NOT NULL, - `b1` bit(8) DEFAULT NULL, - `vc` varchar(63) DEFAULT NULL, - `bc` char(63) DEFAULT NULL, - `d` decimal(10,4) DEFAULT '0.0000', - `f` float DEFAULT '0', - `total` bigint(20) unsigned NOT NULL DEFAULT '0', - `y` year(4) DEFAULT NULL, - `t` date DEFAULT NULL, - PRIMARY KEY (`id`,`total`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () PARTITIONS 4 ---- Make sure that our tables on slave are still right type --- ---- and that the alter statements replicated correctly --- -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `id` mediumint(9) NOT NULL, - `b1` bit(8) DEFAULT NULL, - `vc` varchar(63) DEFAULT NULL, - `bc` char(63) DEFAULT NULL, - `d` decimal(10,4) DEFAULT '0.0000', - `f` float DEFAULT '0', - `total` bigint(20) unsigned NOT NULL DEFAULT '0', - `y` year(4) DEFAULT NULL, - `t` date DEFAULT NULL, - PRIMARY KEY (`id`,`total`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () PARTITIONS 4 ---- Perform basic operation on master --- ---- and ensure replicated correctly --- -"--- Insert into t1 --" as ""; ---- Select from t1 on master --- -select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; -id hex(b1) vc bc d f total y t -2 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1965-11-14 -4 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1985-11-14 -42 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1905-11-14 -142 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1995-11-14 -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2005-11-14 ---- Select from t1 on slave --- -select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; -id hex(b1) vc bc d f total y t -2 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1965-11-14 -4 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1985-11-14 -42 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1905-11-14 -142 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1995-11-14 -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2005-11-14 ---- Update t1 on master -- -UPDATE t1 SET b1 = 0, t="2006-02-22" WHERE id = 412; ---- Check the update on master --- -SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; -id hex(b1) vc bc d f total y t -412 0 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2006-02-22 ---- Check Update on slave --- -SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; -id hex(b1) vc bc d f total y t -412 0 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2006-02-22 ---- Remove a record from t1 on master --- -DELETE FROM t1 WHERE id = 42; ---- Show current count on master for t1 --- -SELECT COUNT(*) FROM t1; -COUNT(*) -4 ---- Show current count on slave for t1 --- -SELECT COUNT(*) FROM t1; -COUNT(*) -4 -DELETE FROM t1; ---- Check that simple Alter statements are replicated correctly --- -ALTER TABLE t1 MODIFY vc VARCHAR(255); ---- Show the new improved table on the master --- -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `id` mediumint(9) NOT NULL, - `b1` bit(8) DEFAULT NULL, - `vc` varchar(255) DEFAULT NULL, - `bc` char(63) DEFAULT NULL, - `d` decimal(10,4) DEFAULT '0.0000', - `f` float DEFAULT '0', - `total` bigint(20) unsigned NOT NULL DEFAULT '0', - `y` year(4) DEFAULT NULL, - `t` date DEFAULT NULL, - PRIMARY KEY (`id`,`total`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () PARTITIONS 4 ---- Make sure that our tables on slave are still same engine --- ---- and that the alter statements replicated correctly --- -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `id` mediumint(9) NOT NULL, - `b1` bit(8) DEFAULT NULL, - `vc` varchar(255) DEFAULT NULL, - `bc` char(63) DEFAULT NULL, - `d` decimal(10,4) DEFAULT '0.0000', - `f` float DEFAULT '0', - `total` bigint(20) unsigned NOT NULL DEFAULT '0', - `y` year(4) DEFAULT NULL, - `t` date DEFAULT NULL, - PRIMARY KEY (`id`,`total`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () PARTITIONS 4 ---- Perform basic operation on master --- ---- and ensure replicated correctly --- -"--- Insert into t1 --" as ""; ---- Select from t1 on master --- -select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; -id hex(b1) vc bc d f total y t -2 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1965-11-14 -4 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1985-11-14 -42 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1905-11-14 -142 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1995-11-14 -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2005-11-14 ---- Select from t1 on slave --- -select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; -id hex(b1) vc bc d f total y t -2 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1965-11-14 -4 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1985-11-14 -42 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1905-11-14 -142 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 1995-11-14 -412 1 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2005-11-14 ---- Update t1 on master -- -UPDATE t1 SET b1 = 0, t="2006-02-22" WHERE id = 412; ---- Check the update on master --- -SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; -id hex(b1) vc bc d f total y t -412 0 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2006-02-22 ---- Check Update on slave --- -SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; -id hex(b1) vc bc d f total y t -412 0 Testing MySQL databases is a cool Must make it bug free for the customer 654321.4321 15.21 0 1965 2006-02-22 ---- Remove a record from t1 on master --- -DELETE FROM t1 WHERE id = 42; ---- Show current count on master for t1 --- -SELECT COUNT(*) FROM t1; -COUNT(*) -4 ---- Show current count on slave for t1 --- -SELECT COUNT(*) FROM t1; -COUNT(*) -4 -DELETE FROM t1; ---- End test 5 key partition testing --- ---- Do Cleanup --- -DROP TABLE IF EXISTS t1; -alter tablespace ts1 -drop datafile 'datafile.dat' -engine=ndb; -alter tablespace ts1 -drop datafile 'datafile02.dat' -engine=ndb; -DROP TABLESPACE ts1 ENGINE=NDB; -DROP LOGFILE GROUP lg1 ENGINE=NDB; diff --git a/mysql-test/r/rpl_ndb_log.result b/mysql-test/r/rpl_ndb_log.result index 5f6f040b715..c435fb37531 100644 --- a/mysql-test/r/rpl_ndb_log.result +++ b/mysql-test/r/rpl_ndb_log.result @@ -47,6 +47,10 @@ master-bin.000001 # Table_map 1 # table_id: # (test.t1) flush logs; create table t3 (a int)ENGINE=NDB; start slave; + +let $result_pattern= '%127.0.0.1%root%master-bin.000002%slave-relay-bin.000005%Yes%Yes%0%0%None%' ; + +--source include/wait_slave_status.inc flush logs; stop slave; create table t2 (n int)ENGINE=NDB; diff --git a/mysql-test/r/rpl_row_log.result b/mysql-test/r/rpl_row_log.result index 12b573b8bf6..65e9ee9fb9f 100644 --- a/mysql-test/r/rpl_row_log.result +++ b/mysql-test/r/rpl_row_log.result @@ -39,6 +39,10 @@ master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F flush logs; create table t3 (a int)ENGINE=MyISAM; start slave; + +let $result_pattern= '%127.0.0.1%root%master-bin.000002%slave-relay-bin.000005%Yes%Yes%0%0%None%' ; + +--source include/wait_slave_status.inc flush logs; stop slave; create table t2 (n int)ENGINE=MyISAM; diff --git a/mysql-test/r/rpl_row_log_innodb.result b/mysql-test/r/rpl_row_log_innodb.result index 48c79c9ab11..2c89ca5f8ff 100644 --- a/mysql-test/r/rpl_row_log_innodb.result +++ b/mysql-test/r/rpl_row_log_innodb.result @@ -41,6 +41,10 @@ master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F flush logs; create table t3 (a int)ENGINE=InnoDB; start slave; + +let $result_pattern= '%127.0.0.1%root%master-bin.000002%slave-relay-bin.000005%Yes%Yes%0%0%None%' ; + +--source include/wait_slave_status.inc flush logs; stop slave; create table t2 (n int)ENGINE=InnoDB; diff --git a/mysql-test/r/rpl_sp004.result b/mysql-test/r/rpl_sp004.result index dfc672d4cd7..1c0ed3cc50a 100644 --- a/mysql-test/r/rpl_sp004.result +++ b/mysql-test/r/rpl_sp004.result @@ -26,25 +26,25 @@ DROP TABLE IF EXISTS test.t2; INSERT INTO test.t3 VALUES(NULL,11111111.233333,NOW()); END| CALL test.p1(); -SELECT * FROM test.t1; +SELECT * FROM test.t1 ORDER BY a; a 1 2 3 12 -SELECT * FROM test.t2; +SELECT * FROM test.t2 ORDER BY a; a 1 2 3 8 -SELECT * FROM test.t1; +SELECT * FROM test.t1 ORDER BY a; a 1 2 3 12 -SELECT * FROM test.t2; +SELECT * FROM test.t2 ORDER BY a; a 1 2 @@ -62,25 +62,25 @@ t3 CALL test.p1(); Warnings: Note 1050 Table 't3' already exists -SELECT * FROM test.t1; +SELECT * FROM test.t1 ORDER BY a; a 1 2 3 12 -SELECT * FROM test.t2; +SELECT * FROM test.t2 ORDER BY a; a 1 2 3 8 -SELECT * FROM test.t1; +SELECT * FROM test.t1 ORDER BY a; a 1 2 3 12 -SELECT * FROM test.t2; +SELECT * FROM test.t2 ORDER BY a; a 1 2 diff --git a/mysql-test/r/rpl_stm_log.result b/mysql-test/r/rpl_stm_log.result index af774c5075f..02a861ceb53 100644 --- a/mysql-test/r/rpl_stm_log.result +++ b/mysql-test/r/rpl_stm_log.result @@ -39,6 +39,10 @@ master-bin.000001 # Query 1 # use `test`; insert into t1 values (NULL) flush logs; create table t3 (a int)ENGINE=MyISAM; start slave; + +let $result_pattern= '%127.0.0.1%root%master-bin.000002%slave-relay-bin.000005%Yes%Yes%0%0%None%' ; + +--source include/wait_slave_status.inc flush logs; stop slave; create table t2 (n int)ENGINE=MyISAM; diff --git a/mysql-test/r/rpl_stm_until.result b/mysql-test/r/rpl_stm_until.result index 11b69f55f82..e8e33b66864 100644 --- a/mysql-test/r/rpl_stm_until.result +++ b/mysql-test/r/rpl_stm_until.result @@ -19,9 +19,40 @@ n 2 3 4 -show slave status; -Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master -# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 780 slave-relay-bin.000004 # master-bin.000001 # No 0 0 323 # Master master-bin.000001 323 No # +SHOW SLAVE STATUS; +Slave_IO_State # +Master_Host 127.0.0.1 +Master_User root +Master_Port MASTER_MYPORT +Connect_Retry 1 +Master_Log_File master-bin.000001 +Read_Master_Log_Pos 780 +Relay_Log_File slave-relay-bin.000004 +Relay_Log_Pos # +Relay_Master_Log_File master-bin.000001 +Slave_IO_Running # +Slave_SQL_Running No +Replicate_Do_DB +Replicate_Ignore_DB +Replicate_Do_Table +Replicate_Ignore_Table +Replicate_Wild_Do_Table +Replicate_Wild_Ignore_Table +Last_Errno 0 +Last_Error +Skip_Counter 0 +Exec_Master_Log_Pos 323 +Relay_Log_Space # +Until_Condition Master +Until_Log_File master-bin.000001 +Until_Log_Pos 323 +Master_SSL_Allowed No +Master_SSL_CA_File +Master_SSL_CA_Path +Master_SSL_Cert +Master_SSL_Cipher +Master_SSL_Key +Seconds_Behind_Master # start slave until master_log_file='master-no-such-bin.000001', master_log_pos=291; select * from t1; n @@ -29,23 +60,116 @@ n 2 3 4 -show slave status; -Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master -# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 780 slave-relay-bin.000004 # master-bin.000001 # No 0 0 323 # Master master-no-such-bin.000001 291 No # +SHOW SLAVE STATUS; +Slave_IO_State # +Master_Host 127.0.0.1 +Master_User root +Master_Port MASTER_MYPORT +Connect_Retry 1 +Master_Log_File master-bin.000001 +Read_Master_Log_Pos 780 +Relay_Log_File slave-relay-bin.000004 +Relay_Log_Pos # +Relay_Master_Log_File master-bin.000001 +Slave_IO_Running # +Slave_SQL_Running No +Replicate_Do_DB +Replicate_Ignore_DB +Replicate_Do_Table +Replicate_Ignore_Table +Replicate_Wild_Do_Table +Replicate_Wild_Ignore_Table +Last_Errno 0 +Last_Error +Skip_Counter 0 +Exec_Master_Log_Pos 323 +Relay_Log_Space # +Until_Condition Master +Until_Log_File master-no-such-bin.000001 +Until_Log_Pos 291 +Master_SSL_Allowed No +Master_SSL_CA_File +Master_SSL_CA_Path +Master_SSL_Cert +Master_SSL_Cipher +Master_SSL_Key +Seconds_Behind_Master # start slave until relay_log_file='slave-relay-bin.000004', relay_log_pos=746; select * from t2; n 1 2 -show slave status; -Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master -# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 780 slave-relay-bin.000004 # master-bin.000001 # No 0 0 612 # Relay slave-relay-bin.000004 746 No # +SHOW SLAVE STATUS; +Slave_IO_State # +Master_Host 127.0.0.1 +Master_User root +Master_Port MASTER_MYPORT +Connect_Retry 1 +Master_Log_File master-bin.000001 +Read_Master_Log_Pos 780 +Relay_Log_File slave-relay-bin.000004 +Relay_Log_Pos # +Relay_Master_Log_File master-bin.000001 +Slave_IO_Running # +Slave_SQL_Running No +Replicate_Do_DB +Replicate_Ignore_DB +Replicate_Do_Table +Replicate_Ignore_Table +Replicate_Wild_Do_Table +Replicate_Wild_Ignore_Table +Last_Errno 0 +Last_Error +Skip_Counter 0 +Exec_Master_Log_Pos 612 +Relay_Log_Space # +Until_Condition Relay +Until_Log_File slave-relay-bin.000004 +Until_Log_Pos 746 +Master_SSL_Allowed No +Master_SSL_CA_File +Master_SSL_CA_Path +Master_SSL_Cert +Master_SSL_Cipher +Master_SSL_Key +Seconds_Behind_Master # start slave; stop slave; start slave until master_log_file='master-bin.000001', master_log_pos=776; -show slave status; -Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master -# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 780 slave-relay-bin.000004 # master-bin.000001 Yes No 0 0 780 # Master master-bin.000001 776 No # +SHOW SLAVE STATUS; +Slave_IO_State # +Master_Host 127.0.0.1 +Master_User root +Master_Port MASTER_MYPORT +Connect_Retry 1 +Master_Log_File master-bin.000001 +Read_Master_Log_Pos 780 +Relay_Log_File slave-relay-bin.000004 +Relay_Log_Pos # +Relay_Master_Log_File master-bin.000001 +Slave_IO_Running Yes +Slave_SQL_Running No +Replicate_Do_DB +Replicate_Ignore_DB +Replicate_Do_Table +Replicate_Ignore_Table +Replicate_Wild_Do_Table +Replicate_Wild_Ignore_Table +Last_Errno 0 +Last_Error +Skip_Counter 0 +Exec_Master_Log_Pos 780 +Relay_Log_Space # +Until_Condition Master +Until_Log_File master-bin.000001 +Until_Log_Pos 776 +Master_SSL_Allowed No +Master_SSL_CA_File +Master_SSL_CA_Path +Master_SSL_Cert +Master_SSL_Cipher +Master_SSL_Key +Seconds_Behind_Master # start slave until master_log_file='master-bin', master_log_pos=561; ERROR HY000: Incorrect parameter or combination of parameters for START SLAVE UNTIL start slave until master_log_file='master-bin.000001', master_log_pos=561, relay_log_pos=12; diff --git a/mysql-test/r/rpl_temporary.result b/mysql-test/r/rpl_temporary.result index 929dc33c447..01882c683a4 100644 --- a/mysql-test/r/rpl_temporary.result +++ b/mysql-test/r/rpl_temporary.result @@ -88,17 +88,23 @@ f 1 drop temporary table t4; drop table t5; -set @session.pseudo_thread_id=100; +set @@session.pseudo_thread_id=100; create temporary table t101 (id int); create temporary table t102 (id int); -set @session.pseudo_thread_id=200; +set @@session.pseudo_thread_id=200; create temporary table t201 (id int); -create temporary table `#not_user_table_prefixed_with_hash_sign_no_harm` (id int); -set @con1_id=connection_id(); -kill @con1_id; +create temporary table `#sql_not_user_table202` (id int); +set @@session.pseudo_thread_id=300; +create temporary table t301 (id int); +create temporary table t302 (id int); +create temporary table `#sql_not_user_table303` (id int); create table t1(f int); insert into t1 values (1); select * from t1 /* must be 1 */; f 1 drop table t1; +select * from t1; +a +1 +drop table t1; diff --git a/mysql-test/r/rpl_user_variables.result b/mysql-test/r/rpl_user_variables.result index b553d37a187..ed0d2782394 100644 --- a/mysql-test/r/rpl_user_variables.result +++ b/mysql-test/r/rpl_user_variables.result @@ -78,5 +78,6 @@ abcn1 abcn1n2 abc\def This is a test +insert into t1 select * FROM (select @var1 union select @var2) AS t2; drop table t1; stop slave; diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index e9092fc8a69..f45e16f66c1 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -3411,3 +3411,38 @@ SELECT * FROM t1; i 255 DROP TABLE t1; +create table t1 (a int); +insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t2 (a int, b int, c int, e int, primary key(a,b,c)); +insert into t2 select A.a, B.a, C.a, C.a from t1 A, t1 B, t1 C; +analyze table t2; +Table Op Msg_type Msg_text +test.t2 analyze status OK +select 'In next EXPLAIN, B.rows must be exactly 10:' Z; +Z +In next EXPLAIN, B.rows must be exactly 10: +explain select * from t2 A, t2 B where A.a=5 and A.b=5 and A.C<5 +and B.a=5 and B.b=A.e and (B.b =1 or B.b = 3 or B.b=5); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE A range PRIMARY PRIMARY 12 NULL 3 Using where +1 SIMPLE B ref PRIMARY PRIMARY 8 const,test.A.e 10 +drop table t1, t2; +CREATE TABLE t1 (a int PRIMARY KEY, b int, INDEX(b)); +INSERT INTO t1 VALUES (1, 3), (9,4), (7,5), (4,5), (6,2), +(3,1), (5,1), (8,9), (2,2), (0,9); +CREATE TABLE t2 (c int, d int, f int, INDEX(c,f)); +INSERT INTO t2 VALUES +(1,0,0), (1,0,1), (2,0,0), (2,0,1), (3,0,0), (4,0,1), +(5,0,0), (5,0,1), (6,0,0), (0,0,1), (7,0,0), (7,0,1), +(0,0,0), (0,0,1), (8,0,0), (8,0,1), (9,0,0), (9,0,1); +EXPLAIN +SELECT a, c, d, f FROM t1,t2 WHERE a=c AND b BETWEEN 4 AND 6; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range PRIMARY,b b 5 NULL 3 Using where +1 SIMPLE t2 ref c c 5 test.t1.a 2 Using where +EXPLAIN +SELECT a, c, d, f FROM t1,t2 WHERE a=c AND b BETWEEN 4 AND 6 AND a > 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range PRIMARY,b b 5 NULL 3 Using where +1 SIMPLE t2 ref c c 5 test.t1.a 2 Using where +DROP TABLE t1, t2; diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result index a8af5c59b81..5dcb8b2afd6 100644 --- a/mysql-test/r/show_check.result +++ b/mysql-test/r/show_check.result @@ -460,7 +460,7 @@ SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL, - KEY `i` USING HASH (`i`) + KEY `i` (`i`) USING HASH ) ENGINE=MEMORY DEFAULT CHARSET=latin1 DROP TABLE t1; CREATE TABLE t1 (i int, KEY USING BTREE (i)) ENGINE=MEMORY; @@ -468,7 +468,7 @@ SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL, - KEY `i` USING BTREE (`i`) + KEY `i` (`i`) USING BTREE ) ENGINE=MEMORY DEFAULT CHARSET=latin1 DROP TABLE t1; CREATE TABLE t1 (i int, KEY (i)) ENGINE=MyISAM; @@ -484,7 +484,7 @@ SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL, - KEY `i` USING BTREE (`i`) + KEY `i` (`i`) USING BTREE ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t1; CREATE TABLE t1 (i int, KEY (i)) ENGINE=MyISAM; @@ -507,14 +507,14 @@ SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL, - KEY `i` USING BTREE (`i`) + KEY `i` (`i`) USING BTREE ) ENGINE=MyISAM DEFAULT CHARSET=latin1 ALTER TABLE t1 ENGINE=MEMORY; SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL, - KEY `i` USING BTREE (`i`) + KEY `i` (`i`) USING BTREE ) ENGINE=MEMORY DEFAULT CHARSET=latin1 DROP TABLE t1; CREATE TABLE t1( @@ -549,8 +549,8 @@ Table Create Table t1 CREATE TABLE `t1` ( `c1` int(11) NOT NULL, `c2` int(11) NOT NULL, - PRIMARY KEY USING HASH (`c1`), - KEY `c2` USING BTREE (`c2`) + PRIMARY KEY (`c1`) USING HASH, + KEY `c2` (`c2`) USING BTREE ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t1; flush tables; diff --git a/mysql-test/r/skip_name_resolve.result b/mysql-test/r/skip_name_resolve.result index 8ef52e75238..855876825ad 100644 --- a/mysql-test/r/skip_name_resolve.result +++ b/mysql-test/r/skip_name_resolve.result @@ -10,5 +10,6 @@ user() # show processlist; Id User Host db Command Time State Info +<id> event_scheduler <host> NULL <command> <time> <state> <info> <id> root <host> test <command> <time> <state> <info> <id> root <host> test <command> <time> <state> <info> diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result index 931fa2ee402..fde273c55ee 100644 --- a/mysql-test/r/sp-error.result +++ b/mysql-test/r/sp-error.result @@ -282,9 +282,9 @@ select @tmp_x, @tmp_y, @tmp_z| @tmp_x @tmp_y @tmp_z 42 45 87 call p(42, 43, @tmp_z)| -ERROR 42000: OUT or INOUT argument 2 for routine test.p is not a variable +ERROR 42000: OUT or INOUT argument 2 for routine test.p is not a variable or NEW pseudo-variable in BEFORE trigger call p(42, @tmp_y, 43)| -ERROR 42000: OUT or INOUT argument 3 for routine test.p is not a variable +ERROR 42000: OUT or INOUT argument 3 for routine test.p is not a variable or NEW pseudo-variable in BEFORE trigger drop procedure p| create procedure p() begin end| lock table t1 read| diff --git a/mysql-test/r/sp-threads.result b/mysql-test/r/sp-threads.result index c516d7a643f..3cba437e0a6 100644 --- a/mysql-test/r/sp-threads.result +++ b/mysql-test/r/sp-threads.result @@ -34,6 +34,7 @@ lock tables t2 write; call bug9486(); show processlist; Id User Host db Command Time State Info +# event_scheduler localhost NULL Connect # Suspended NULL # root localhost test Sleep # NULL # root localhost test Query # Locked update t1, t2 set val= 1 where id1=id2 # root localhost test Query # NULL show processlist diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 5aa984bfa4e..9bdd1d5645f 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -4914,4 +4914,90 @@ schema_name select routine_name,routine_schema from information_schema.routines where routine_schema like 'bug18344%'| routine_name routine_schema +drop function if exists bug12472| +create function bug12472() returns int return (select count(*) from t1)| +create table t3 as select bug12472() as i| +show create table t3| +Table Create Table +t3 CREATE TABLE `t3` ( + `i` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +select * from t3| +i +0 +drop table t3| +create view v1 as select bug12472() as j| +create table t3 as select * from v1| +show create table t3| +Table Create Table +t3 CREATE TABLE `t3` ( + `j` bigint(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +select * from t3| +j +0 +drop table t3| +drop view v1| +drop function bug12472| +DROP FUNCTION IF EXISTS bug18589_f1| +DROP PROCEDURE IF EXISTS bug18589_p1| +DROP PROCEDURE IF EXISTS bug18589_p2| +CREATE FUNCTION bug18589_f1(arg TEXT) RETURNS TEXT +BEGIN +RETURN CONCAT(arg, ""); +END| +CREATE PROCEDURE bug18589_p1(arg TEXT, OUT ret TEXT) +BEGIN +SET ret = CONCAT(arg, ""); +END| +CREATE PROCEDURE bug18589_p2(arg TEXT) +BEGIN +DECLARE v TEXT; +CALL bug18589_p1(arg, v); +SELECT v; +END| +SELECT bug18589_f1(REPEAT("a", 767))| +bug18589_f1(REPEAT("a", 767)) +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +SET @bug18589_v1 = ""| +CALL bug18589_p1(REPEAT("a", 767), @bug18589_v1)| +SELECT @bug18589_v1| +@bug18589_v1 +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +CALL bug18589_p2(REPEAT("a", 767))| +v +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +DROP FUNCTION bug18589_f1| +DROP PROCEDURE bug18589_p1| +DROP PROCEDURE bug18589_p2| +DROP FUNCTION IF EXISTS bug18037_f1| +DROP PROCEDURE IF EXISTS bug18037_p1| +DROP PROCEDURE IF EXISTS bug18037_p2| +CREATE FUNCTION bug18037_f1() RETURNS INT +BEGIN +RETURN @@server_id; +END| +CREATE PROCEDURE bug18037_p1() +BEGIN +DECLARE v INT DEFAULT @@server_id; +END| +CREATE PROCEDURE bug18037_p2() +BEGIN +CASE @@server_id +WHEN -1 THEN +SELECT 0; +ELSE +SELECT 1; +END CASE; +END| +SELECT bug18037_f1()| +bug18037_f1() +1 +CALL bug18037_p1()| +CALL bug18037_p2()| +1 +1 +DROP FUNCTION bug18037_f1| +DROP PROCEDURE bug18037_p1| +DROP PROCEDURE bug18037_p2| drop table t1,t2; diff --git a/mysql-test/r/sp_notembedded.result b/mysql-test/r/sp_notembedded.result index c8cafe5ace1..c5d60446e0a 100644 --- a/mysql-test/r/sp_notembedded.result +++ b/mysql-test/r/sp_notembedded.result @@ -18,9 +18,11 @@ show processlist; end| call bug4902_2()| Id User Host db Command Time State Info +# event_scheduler localhost NULL Connect # Suspended NULL # root localhost test Query # NULL show processlist call bug4902_2()| Id User Host db Command Time State Info +# event_scheduler localhost NULL Connect # Suspended NULL # root localhost test Query # NULL show processlist drop procedure bug4902_2| drop function if exists bug5278| diff --git a/mysql-test/r/sql_mode.result b/mysql-test/r/sql_mode.result index 31b67529f8d..3466282a4b1 100644 --- a/mysql-test/r/sql_mode.result +++ b/mysql-test/r/sql_mode.result @@ -18,7 +18,7 @@ t1 CREATE TABLE `t1` ( `pseudo` varchar(35) CHARACTER SET latin2 NOT NULL DEFAULT '', `email` varchar(60) CHARACTER SET latin2 NOT NULL DEFAULT '', PRIMARY KEY (`a`), - UNIQUE KEY `email` USING BTREE (`email`) + UNIQUE KEY `email` (`email`) USING BTREE ) ENGINE=MEMORY DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC set @@sql_mode="ansi_quotes"; show variables like 'sql_mode'; @@ -31,7 +31,7 @@ t1 CREATE TABLE "t1" ( "pseudo" varchar(35) CHARACTER SET latin2 NOT NULL DEFAULT '', "email" varchar(60) CHARACTER SET latin2 NOT NULL DEFAULT '', PRIMARY KEY ("a"), - UNIQUE KEY "email" USING BTREE ("email") + UNIQUE KEY "email" ("email") USING BTREE ) ENGINE=MEMORY DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC set @@sql_mode="no_table_options"; show variables like 'sql_mode'; @@ -44,7 +44,7 @@ t1 CREATE TABLE `t1` ( `pseudo` varchar(35) CHARACTER SET latin2 NOT NULL DEFAULT '', `email` varchar(60) CHARACTER SET latin2 NOT NULL DEFAULT '', PRIMARY KEY (`a`), - UNIQUE KEY `email` USING BTREE (`email`) + UNIQUE KEY `email` (`email`) USING BTREE ) set @@sql_mode="no_key_options"; show variables like 'sql_mode'; diff --git a/mysql-test/r/status.result b/mysql-test/r/status.result index ca21b333a6a..e83ade78cf6 100644 --- a/mysql-test/r/status.result +++ b/mysql-test/r/status.result @@ -26,20 +26,20 @@ Last_query_cost 0.000000 FLUSH STATUS; SHOW STATUS LIKE 'max_used_connections'; Variable_name Value -Max_used_connections 1 +Max_used_connections 2 SET @save_thread_cache_size=@@thread_cache_size; SET GLOBAL thread_cache_size=3; SHOW STATUS LIKE 'max_used_connections'; Variable_name Value -Max_used_connections 3 +Max_used_connections 4 FLUSH STATUS; SHOW STATUS LIKE 'max_used_connections'; Variable_name Value -Max_used_connections 2 -SHOW STATUS LIKE 'max_used_connections'; -Variable_name Value Max_used_connections 3 SHOW STATUS LIKE 'max_used_connections'; Variable_name Value Max_used_connections 4 +SHOW STATUS LIKE 'max_used_connections'; +Variable_name Value +Max_used_connections 5 SET GLOBAL thread_cache_size=@save_thread_cache_size; diff --git a/mysql-test/r/strict.result b/mysql-test/r/strict.result index 92f1ba3a23e..5ca185d6abc 100644 --- a/mysql-test/r/strict.result +++ b/mysql-test/r/strict.result @@ -1288,3 +1288,13 @@ ERROR 22001: Data too long for column 'a' at row 1 select * from t1; a drop table t1; +set sql_mode='traditional'; +create table t1 (date date not null); +create table t2 select date from t1; +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `date` date NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t2,t1; +set @@sql_mode= @org_mode; diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 0a464d055c2..e307bb9eafe 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -1480,7 +1480,7 @@ Note 1003 select `test`.`t1`.`s1` AS `s1`,not(<in_optimizer>(`test`.`t1`.`s1`,<e explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 Using index -2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 1 Using index; Using where +2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 Using index; Using where Warnings: Note 1003 select `test`.`t1`.`s1` AS `s1`,not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL where (`test`.`t2`.`s1` < _latin1'a2'))))) AS `s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')` from `test`.`t1` drop table t1,t2; @@ -3169,3 +3169,38 @@ create table t2 (a int, b int); insert into t2 values (2, 1), (1, 0); delete from t1 where c <= 1140006215 and (select b from t2 where a = 2) = 1; drop table t1, t2; +CREATE TABLE t1 (a INT); +CREATE VIEW v1 AS SELECT * FROM t1 WHERE no_such_column = ANY (SELECT 1); +ERROR 42S22: Unknown column 'no_such_column' in 'where clause' +CREATE VIEW v2 AS SELECT * FROM t1 WHERE no_such_column = (SELECT 1); +ERROR 42S22: Unknown column 'no_such_column' in 'where clause' +SELECT * FROM t1 WHERE no_such_column = ANY (SELECT 1); +ERROR 42S22: Unknown column 'no_such_column' in 'IN/ALL/ANY subquery' +DROP TABLE t1; +create table t1 (i int, j bigint); +insert into t1 values (1, 2), (2, 2), (3, 2); +select * from (select min(i) from t1 where j=(select * from (select min(j) from t1) t2)) t3; +min(i) +1 +drop table t1; +CREATE TABLE t1 (i BIGINT UNSIGNED); +INSERT INTO t1 VALUES (10000000000000000000); +INSERT INTO t1 VALUES (1); +CREATE TABLE t2 (i BIGINT UNSIGNED); +INSERT INTO t2 VALUES (10000000000000000000); +INSERT INTO t2 VALUES (1); +/* simple test */ +SELECT t1.i FROM t1 JOIN t2 ON t1.i = t2.i; +i +10000000000000000000 +1 +/* subquery test */ +SELECT t1.i FROM t1 WHERE t1.i = (SELECT MAX(i) FROM t2); +i +10000000000000000000 +/* subquery test with cast*/ +SELECT t1.i FROM t1 WHERE t1.i = CAST((SELECT MAX(i) FROM t2) AS UNSIGNED); +i +10000000000000000000 +DROP TABLE t1; +DROP TABLE t2; diff --git a/mysql-test/r/symlink.result b/mysql-test/r/symlink.result index b3cb244c735..3b24210dd5d 100644 --- a/mysql-test/r/symlink.result +++ b/mysql-test/r/symlink.result @@ -40,7 +40,7 @@ t9 CREATE TABLE `t9` ( `b` char(16) NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`a`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 DATA DIRECTORY='MYSQLTEST_VARDIR/tmp/' INDEX DIRECTORY='MYSQLTEST_VARDIR/run/' +) ENGINE=MyISAM AUTO_INCREMENT=16725 DEFAULT CHARSET=latin1 DATA DIRECTORY='MYSQLTEST_VARDIR/tmp/' INDEX DIRECTORY='MYSQLTEST_VARDIR/run/' alter table t9 rename t8, add column d int not null; alter table t8 rename t7; rename table t7 to t9; @@ -53,7 +53,7 @@ t9 CREATE TABLE `t9` ( `c` int(11) NOT NULL, `d` int(11) NOT NULL, PRIMARY KEY (`a`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 DATA DIRECTORY='MYSQLTEST_VARDIR/tmp/' INDEX DIRECTORY='MYSQLTEST_VARDIR/run/' +) ENGINE=MyISAM AUTO_INCREMENT=16725 DEFAULT CHARSET=latin1 DATA DIRECTORY='MYSQLTEST_VARDIR/tmp/' INDEX DIRECTORY='MYSQLTEST_VARDIR/run/' Got one of the listed errors Got one of the listed errors Got one of the listed errors @@ -71,7 +71,7 @@ t9 CREATE TABLE `t9` ( `c` int(11) NOT NULL, `d` int(11) NOT NULL, PRIMARY KEY (`a`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 DATA DIRECTORY='MYSQLTEST_VARDIR/tmp/' INDEX DIRECTORY='MYSQLTEST_VARDIR/run/' +) ENGINE=MyISAM AUTO_INCREMENT=16725 DEFAULT CHARSET=latin1 DATA DIRECTORY='MYSQLTEST_VARDIR/tmp/' INDEX DIRECTORY='MYSQLTEST_VARDIR/run/' drop database mysqltest; create table t1 (a int not null) engine=myisam; show create table t1; diff --git a/mysql-test/r/system_mysql_db.result b/mysql-test/r/system_mysql_db.result index 30cde39531d..b9d3504993c 100644 --- a/mysql-test/r/system_mysql_db.result +++ b/mysql-test/r/system_mysql_db.result @@ -208,7 +208,7 @@ event CREATE TABLE `event` ( `on_completion` enum('DROP','PRESERVE') NOT NULL DEFAULT 'DROP', `sql_mode` set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','NOT_USED','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES','ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER','HIGH_NOT_PRECEDENCE') NOT NULL DEFAULT '', `comment` char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', - PRIMARY KEY (`definer`,`db`,`name`) + PRIMARY KEY (`db`,`name`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Events' show create table general_log; Table Create Table diff --git a/mysql-test/r/trigger-grant.result b/mysql-test/r/trigger-grant.result index 10f1e08eded..fec5d4812d9 100644 --- a/mysql-test/r/trigger-grant.result +++ b/mysql-test/r/trigger-grant.result @@ -364,3 +364,87 @@ SELECT @mysqltest_var; Hello, world! DROP USER mysqltest_u1@localhost; DROP DATABASE mysqltest_db1; +DELETE FROM mysql.user WHERE User LIKE 'mysqltest_%'; +DELETE FROM mysql.db WHERE User LIKE 'mysqltest_%'; +DELETE FROM mysql.tables_priv WHERE User LIKE 'mysqltest_%'; +DELETE FROM mysql.columns_priv WHERE User LIKE 'mysqltest_%'; +FLUSH PRIVILEGES; +DROP DATABASE IF EXISTS mysqltest_db1; +CREATE DATABASE mysqltest_db1; +USE mysqltest_db1; +CREATE TABLE t1 (i1 INT); +CREATE TABLE t2 (i1 INT); +CREATE USER mysqltest_dfn@localhost; +CREATE USER mysqltest_inv@localhost; +GRANT EXECUTE, CREATE ROUTINE, TRIGGER ON *.* TO mysqltest_dfn@localhost; +GRANT INSERT ON mysqltest_db1.* TO mysqltest_inv@localhost; +CREATE PROCEDURE p1(OUT i INT) DETERMINISTIC NO SQL SET i = 3; +CREATE PROCEDURE p2(INOUT i INT) DETERMINISTIC NO SQL SET i = i * 5; +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW +CALL p1(NEW.i1); +CREATE TRIGGER t2_bi BEFORE INSERT ON t2 FOR EACH ROW +CALL p2(NEW.i1); +INSERT INTO t1 VALUES (7); +ERROR 42000: UPDATE command denied to user 'mysqltest_dfn'@'localhost' for column 'i1' in table 't1' +INSERT INTO t2 VALUES (11); +ERROR 42000: SELECT,UPDATE command denied to user 'mysqltest_dfn'@'localhost' for column 'i1' in table 't2' +DROP TRIGGER t2_bi; +DROP TRIGGER t1_bi; +GRANT SELECT ON mysqltest_db1.* TO mysqltest_dfn@localhost; +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW +CALL p1(NEW.i1); +CREATE TRIGGER t2_bi BEFORE INSERT ON t2 FOR EACH ROW +CALL p2(NEW.i1); +INSERT INTO t1 VALUES (13); +ERROR 42000: UPDATE command denied to user 'mysqltest_dfn'@'localhost' for column 'i1' in table 't1' +INSERT INTO t2 VALUES (17); +ERROR 42000: UPDATE command denied to user 'mysqltest_dfn'@'localhost' for column 'i1' in table 't2' +REVOKE SELECT ON mysqltest_db1.* FROM mysqltest_dfn@localhost; +DROP TRIGGER t2_bi; +DROP TRIGGER t1_bi; +GRANT UPDATE ON mysqltest_db1.* TO mysqltest_dfn@localhost; +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW +CALL p1(NEW.i1); +CREATE TRIGGER t2_bi BEFORE INSERT ON t2 FOR EACH ROW +CALL p2(NEW.i1); +INSERT INTO t1 VALUES (19); +INSERT INTO t2 VALUES (23); +ERROR 42000: SELECT command denied to user 'mysqltest_dfn'@'localhost' for column 'i1' in table 't2' +REVOKE UPDATE ON mysqltest_db1.* FROM mysqltest_dfn@localhost; +DROP TRIGGER t2_bi; +DROP TRIGGER t1_bi; +GRANT SELECT, UPDATE ON mysqltest_db1.* TO mysqltest_dfn@localhost; +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW +CALL p1(NEW.i1); +CREATE TRIGGER t2_bi BEFORE INSERT ON t2 FOR EACH ROW +CALL p2(NEW.i1); +INSERT INTO t1 VALUES (29); +INSERT INTO t2 VALUES (31); +REVOKE SELECT, UPDATE ON mysqltest_db1.* FROM mysqltest_dfn@localhost; +DROP TRIGGER t2_bi; +DROP TRIGGER t1_bi; +DROP PROCEDURE p2; +DROP PROCEDURE p1; +GRANT UPDATE ON mysqltest_db1.* TO mysqltest_dfn@localhost; +CREATE PROCEDURE p1(OUT i INT) DETERMINISTIC NO SQL SET i = 37; +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW +CALL p1(NEW.i1); +INSERT INTO t1 VALUES (41); +DROP PROCEDURE p1; +CREATE PROCEDURE p1(IN i INT) DETERMINISTIC NO SQL SET @v1 = i + 43; +INSERT INTO t1 VALUES (47); +ERROR 42000: SELECT command denied to user 'mysqltest_dfn'@'localhost' for column 'i1' in table 't1' +DROP PROCEDURE p1; +CREATE PROCEDURE p1(INOUT i INT) DETERMINISTIC NO SQL SET i = i + 51; +INSERT INTO t1 VALUES (53); +ERROR 42000: SELECT command denied to user 'mysqltest_dfn'@'localhost' for column 'i1' in table 't1' +DROP PROCEDURE p1; +REVOKE UPDATE ON mysqltest_db1.* FROM mysqltest_dfn@localhost; +DROP TRIGGER t1_bi; +DROP USER mysqltest_inv@localhost; +DROP USER mysqltest_dfn@localhost; +DROP TABLE t2; +DROP TABLE t1; +DROP DATABASE mysqltest_db1; +USE test; +End of 5.0 tests. diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result index 5d5ea9511ba..24675f2cd66 100644 --- a/mysql-test/r/trigger.result +++ b/mysql-test/r/trigger.result @@ -949,9 +949,9 @@ insert into t1 values create function f2() returns int return (select max(b) from t2); insert into t2 select a, f2() from t1; load data infile '../std_data_ln/words.dat' into table t1 (a) set b:= f1(); -drop table t1, t2; drop function f1; drop function f2; +drop table t1, t2; create table t1(i int not null, j int not null, n numeric(15,2), primary key(i,j)); create table t2(i int not null, n numeric(15,2), primary key(i)); create trigger t1_ai after insert on t1 for each row @@ -998,3 +998,95 @@ SELECT * FROM t1 WHERE conn_id != trigger_conn_id; conn_id trigger_conn_id DROP TRIGGER t1_bi; DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (i1 INT); +SET @save_sql_mode=@@sql_mode; +SET SQL_MODE=''; +CREATE TRIGGER t1_ai AFTER INSERT ON t1 FOR EACH ROW +SET @x = 5/0; +SET SQL_MODE='traditional'; +CREATE TRIGGER t1_au AFTER UPDATE ON t1 FOR EACH ROW +SET @x = 5/0; +SET @x=1; +INSERT INTO t1 VALUES (@x); +SELECT @x; +@x +NULL +SET @x=2; +UPDATE t1 SET i1 = @x; +ERROR 22012: Division by 0 +SELECT @x; +@x +2 +SET SQL_MODE=''; +SET @x=3; +INSERT INTO t1 VALUES (@x); +SELECT @x; +@x +NULL +SET @x=4; +UPDATE t1 SET i1 = @x; +ERROR 22012: Division by 0 +SELECT @x; +@x +4 +SET @@sql_mode=@save_sql_mode; +DROP TRIGGER t1_ai; +DROP TRIGGER t1_au; +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +CREATE TABLE t1 (i1 INT); +INSERT INTO t1 VALUES (3); +CREATE PROCEDURE p1(OUT i1 INT) DETERMINISTIC NO SQL SET i1 = 5; +CREATE PROCEDURE p2(INOUT i1 INT) DETERMINISTIC NO SQL SET i1 = i1 * 7; +CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 FOR EACH ROW +BEGIN +CALL p1(NEW.i1); +CALL p2(NEW.i1); +END// +UPDATE t1 SET i1 = 11 WHERE i1 = 3; +DROP TRIGGER t1_bu; +DROP PROCEDURE p2; +DROP PROCEDURE p1; +INSERT INTO t1 VALUES (13); +CREATE PROCEDURE p1(OUT i1 INT) DETERMINISTIC NO SQL SET @a = 17; +CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 FOR EACH ROW +CALL p1(OLD.i1); +UPDATE t1 SET i1 = 19 WHERE i1 = 13; +ERROR 42000: OUT or INOUT argument 1 for routine test.p1 is not a variable or NEW pseudo-variable in BEFORE trigger +DROP TRIGGER t1_bu; +DROP PROCEDURE p1; +INSERT INTO t1 VALUES (23); +CREATE PROCEDURE p1(INOUT i1 INT) DETERMINISTIC NO SQL SET @a = i1 * 29; +CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 FOR EACH ROW +CALL p1(OLD.i1); +UPDATE t1 SET i1 = 31 WHERE i1 = 23; +ERROR 42000: OUT or INOUT argument 1 for routine test.p1 is not a variable or NEW pseudo-variable in BEFORE trigger +DROP TRIGGER t1_bu; +DROP PROCEDURE p1; +INSERT INTO t1 VALUES (37); +CREATE PROCEDURE p1(OUT i1 INT) DETERMINISTIC NO SQL SET @a = 41; +CREATE TRIGGER t1_au AFTER UPDATE ON t1 FOR EACH ROW +CALL p1(NEW.i1); +UPDATE t1 SET i1 = 43 WHERE i1 = 37; +ERROR 42000: OUT or INOUT argument 1 for routine test.p1 is not a variable or NEW pseudo-variable in BEFORE trigger +DROP TRIGGER t1_au; +DROP PROCEDURE p1; +INSERT INTO t1 VALUES (47); +CREATE PROCEDURE p1(INOUT i1 INT) DETERMINISTIC NO SQL SET @a = i1 * 49; +CREATE TRIGGER t1_au AFTER UPDATE ON t1 FOR EACH ROW +CALL p1(NEW.i1); +UPDATE t1 SET i1 = 51 WHERE i1 = 47; +ERROR 42000: OUT or INOUT argument 1 for routine test.p1 is not a variable or NEW pseudo-variable in BEFORE trigger +DROP TRIGGER t1_au; +DROP PROCEDURE p1; +SELECT * FROM t1; +i1 +35 +13 +23 +43 +51 +DROP TABLE t1; diff --git a/mysql-test/r/type_float.result b/mysql-test/r/type_float.result index d3c80a7c80e..cfae61d5e91 100644 --- a/mysql-test/r/type_float.result +++ b/mysql-test/r/type_float.result @@ -245,22 +245,22 @@ show warnings; Level Code Message desc t1; Field Type Null Key Default Extra -x decimal(21,2) unsigned NO 0.00 +x decimal(21,2) NO 0.00 drop table t1; create table t1 select 0.0 x; desc t1; Field Type Null Key Default Extra -x decimal(2,1) unsigned NO 0.0 +x decimal(2,1) NO 0.0 create table t2 select 105213674794682365.00 y; desc t2; Field Type Null Key Default Extra -y decimal(20,2) unsigned NO 0.00 +y decimal(20,2) NO 0.00 create table t3 select x+y a from t1,t2; show warnings; Level Code Message desc t3; Field Type Null Key Default Extra -a decimal(21,2) unsigned NO 0.00 +a decimal(21,2) NO 0.00 drop table t1,t2,t3; create table t1 (s1 float(0,2)); ERROR 42000: For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 's1'). diff --git a/mysql-test/r/type_newdecimal.result b/mysql-test/r/type_newdecimal.result index f96d5e383f4..702b589c911 100644 --- a/mysql-test/r/type_newdecimal.result +++ b/mysql-test/r/type_newdecimal.result @@ -68,10 +68,10 @@ NULL 1.1 NULL NULL NULL 1 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `nullif(1.1, 1.1)` decimal(2,1) unsigned DEFAULT NULL, - `nullif(1.1, 1.2)` decimal(2,1) unsigned DEFAULT NULL, - `nullif(1.1, 0.11e1)` decimal(2,1) unsigned DEFAULT NULL, - `nullif(1.0, 1)` decimal(2,1) unsigned DEFAULT NULL, + `nullif(1.1, 1.1)` decimal(2,1) DEFAULT NULL, + `nullif(1.1, 1.2)` decimal(2,1) DEFAULT NULL, + `nullif(1.1, 0.11e1)` decimal(2,1) DEFAULT NULL, + `nullif(1.0, 1)` decimal(2,1) DEFAULT NULL, `nullif(1, 1.0)` int(1) DEFAULT NULL, `nullif(1, 1.1)` int(1) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 @@ -174,9 +174,9 @@ create table t1 select round(15.4,-1), truncate(-5678.123451,-3), abs(-1.1), -(- show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `round(15.4,-1)` decimal(3,0) unsigned NOT NULL DEFAULT '0', + `round(15.4,-1)` decimal(3,0) NOT NULL DEFAULT '0', `truncate(-5678.123451,-3)` decimal(4,0) NOT NULL DEFAULT '0', - `abs(-1.1)` decimal(2,1) NOT NULL DEFAULT '0.0', + `abs(-1.1)` decimal(3,1) NOT NULL DEFAULT '0.0', `-(-1.1)` decimal(2,1) NOT NULL DEFAULT '0.0' ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; @@ -771,7 +771,7 @@ create table t1 as select 0.5; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `0.5` decimal(2,1) unsigned NOT NULL DEFAULT '0.0' + `0.5` decimal(2,1) NOT NULL DEFAULT '0.0' ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; select round(1.5),round(2.5); diff --git a/mysql-test/r/type_ranges.result b/mysql-test/r/type_ranges.result index 0ba8916f5b1..ba401a22945 100644 --- a/mysql-test/r/type_ranges.result +++ b/mysql-test/r/type_ranges.result @@ -241,7 +241,7 @@ Field Type Collation Null Key Default Extra Privileges Comment auto int(5) unsigned NULL NO 0 # string char(10) latin1_swedish_ci YES newdefault # tiny tinyint(4) NULL NO 0 # -short smallint(6) NULL NO 0 # +short smallint(6) NULL NO # medium mediumint(8) NULL NO 0 # long_int int(11) NULL NO 0 # longlong bigint(13) NULL NO 0 # @@ -259,7 +259,7 @@ date_time datetime NULL YES NULL # new_blob_col varchar(20) latin1_swedish_ci YES NULL # tinyblob_col tinyblob NULL YES NULL # mediumblob_col mediumblob NULL NO # -options enum('one','two','tree') latin1_swedish_ci NO one # +options enum('one','two','tree') latin1_swedish_ci NO # flags set('one','two','tree') latin1_swedish_ci NO # new_field char(10) latin1_swedish_ci NO new # select t1.auto,t2.auto from t1,t2 where t1.auto=t2.auto and ((t1.string<>t2.string and (t1.string is not null or t2.string is not null)) or (t1.tiny<>t2.tiny and (t1.tiny is not null or t2.tiny is not null)) or (t1.short<>t2.short and (t1.short is not null or t2.short is not null)) or (t1.medium<>t2.medium and (t1.medium is not null or t2.medium is not null)) or (t1.long_int<>t2.long_int and (t1.long_int is not null or t2.long_int is not null)) or (t1.longlong<>t2.longlong and (t1.longlong is not null or t2.longlong is not null)) or (t1.real_float<>t2.real_float and (t1.real_float is not null or t2.real_float is not null)) or (t1.real_double<>t2.real_double and (t1.real_double is not null or t2.real_double is not null)) or (t1.utiny<>t2.utiny and (t1.utiny is not null or t2.utiny is not null)) or (t1.ushort<>t2.ushort and (t1.ushort is not null or t2.ushort is not null)) or (t1.umedium<>t2.umedium and (t1.umedium is not null or t2.umedium is not null)) or (t1.ulong<>t2.ulong and (t1.ulong is not null or t2.ulong is not null)) or (t1.ulonglong<>t2.ulonglong and (t1.ulonglong is not null or t2.ulonglong is not null)) or (t1.time_stamp<>t2.time_stamp and (t1.time_stamp is not null or t2.time_stamp is not null)) or (t1.date_field<>t2.date_field and (t1.date_field is not null or t2.date_field is not null)) or (t1.time_field<>t2.time_field and (t1.time_field is not null or t2.time_field is not null)) or (t1.date_time<>t2.date_time and (t1.date_time is not null or t2.date_time is not null)) or (t1.new_blob_col<>t2.new_blob_col and (t1.new_blob_col is not null or t2.new_blob_col is not null)) or (t1.tinyblob_col<>t2.tinyblob_col and (t1.tinyblob_col is not null or t2.tinyblob_col is not null)) or (t1.mediumblob_col<>t2.mediumblob_col and (t1.mediumblob_col is not null or t2.mediumblob_col is not null)) or (t1.options<>t2.options and (t1.options is not null or t2.options is not null)) or (t1.flags<>t2.flags and (t1.flags is not null or t2.flags is not null)) or (t1.new_field<>t2.new_field and (t1.new_field is not null or t2.new_field is not null))); diff --git a/mysql-test/r/variables.result b/mysql-test/r/variables.result index 43b32782c63..e4b3fc2c2e2 100644 --- a/mysql-test/r/variables.result +++ b/mysql-test/r/variables.result @@ -1,4 +1,31 @@ drop table if exists t1,t2; +set @my_binlog_cache_size =@@global.binlog_cache_size; +set @my_connect_timeout =@@global.connect_timeout; +set @my_delayed_insert_timeout =@@global.delayed_insert_timeout; +set @my_delayed_queue_size =@@global.delayed_queue_size; +set @my_flush =@@global.flush; +set @my_flush_time =@@global.flush_time; +set @my_key_buffer_size =@@global.key_buffer_size; +set @my_max_binlog_cache_size =@@global.max_binlog_cache_size; +set @my_max_binlog_size =@@global.max_binlog_size; +set @my_max_connect_errors =@@global.max_connect_errors; +set @my_max_delayed_threads =@@global.max_delayed_threads; +set @my_max_heap_table_size =@@global.max_heap_table_size; +set @my_max_insert_delayed_threads=@@global.max_insert_delayed_threads; +set @my_max_join_size =@@global.max_join_size; +set @my_max_user_connections =@@global.max_user_connections; +set @my_max_write_lock_count =@@global.max_write_lock_count; +set @my_myisam_data_pointer_size =@@global.myisam_data_pointer_size; +set @my_net_buffer_length =@@global.net_buffer_length; +set @my_net_write_timeout =@@global.net_write_timeout; +set @my_net_read_timeout =@@global.net_read_timeout; +set @my_query_cache_limit =@@global.query_cache_limit; +set @my_query_cache_type =@@global.query_cache_type; +set @my_rpl_recovery_rank =@@global.rpl_recovery_rank; +set @my_server_id =@@global.server_id; +set @my_slow_launch_time =@@global.slow_launch_time; +set @my_storage_engine =@@global.storage_engine; +set @my_thread_cache_size =@@global.thread_cache_size; set @`test`=1; select @test, @`test`, @TEST, @`TEST`, @"teSt"; @test @`test` @TEST @`TEST` @"teSt" @@ -612,4 +639,59 @@ select @@version, @@version_comment, @@version_compile_machine, @@version_compile_os; @@version @@version_comment @@version_compile_machine @@version_compile_os # # # # +select @@basedir, @@datadir, @@tmpdir; +@@basedir @@datadir @@tmpdir +# # # +show variables like 'basedir'; +Variable_name Value +basedir # +show variables like 'datadir'; +Variable_name Value +datadir # +show variables like 'tmpdir'; +Variable_name Value +tmpdir # +select @@ssl_ca, @@ssl_capath, @@ssl_cert, @@ssl_cipher, @@ssl_key; +@@ssl_ca @@ssl_capath @@ssl_cert @@ssl_cipher @@ssl_key +# # # # # +show variables like 'ssl%'; +Variable_name Value +ssl_ca # +ssl_capath # +ssl_cert # +ssl_cipher # +ssl_key # +select @@log_queries_not_using_indexes; +@@log_queries_not_using_indexes +0 +show variables like 'log_queries_not_using_indexes'; +Variable_name Value +log_queries_not_using_indexes OFF End of 5.0 tests +set global binlog_cache_size =@my_binlog_cache_size; +set global connect_timeout =@my_connect_timeout; +set global delayed_insert_timeout =@my_delayed_insert_timeout; +set global delayed_queue_size =@my_delayed_queue_size; +set global flush =@my_flush; +set global flush_time =@my_flush_time; +set global key_buffer_size =@my_key_buffer_size; +set global max_binlog_cache_size =default; +set global max_binlog_size =@my_max_binlog_size; +set global max_connect_errors =@my_max_connect_errors; +set global max_delayed_threads =@my_max_delayed_threads; +set global max_heap_table_size =@my_max_heap_table_size; +set global max_insert_delayed_threads=@my_max_insert_delayed_threads; +set global max_join_size =@my_max_join_size; +set global max_user_connections =@my_max_user_connections; +set global max_write_lock_count =@my_max_write_lock_count; +set global myisam_data_pointer_size =@my_myisam_data_pointer_size; +set global net_buffer_length =@my_net_buffer_length; +set global net_write_timeout =@my_net_write_timeout; +set global net_read_timeout =@my_net_read_timeout; +set global query_cache_limit =@my_query_cache_limit; +set global query_cache_type =@my_query_cache_type; +set global rpl_recovery_rank =@my_rpl_recovery_rank; +set global server_id =@my_server_id; +set global slow_launch_time =@my_slow_launch_time; +set global storage_engine =@my_storage_engine; +set global thread_cache_size =@my_thread_cache_size; diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index c5446ac314e..10a9ac87748 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -706,7 +706,7 @@ create view v1 as select a from t1; create view v2 as select a from t2 where a in (select a from v1); show create view v2; View Create View -v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t2`.`a` AS `a` from `t2` where `a` in (select `v1`.`a` AS `a` from `v1`) +v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t2`.`a` AS `a` from `t2` where `t2`.`a` in (select `v1`.`a` AS `a` from `v1`) drop view v2, v1; drop table t1, t2; CREATE VIEW `v 1` AS select 5 AS `5`; @@ -2649,3 +2649,90 @@ ldt 2006-01-01 03:00:00 drop view v1, v2; drop table t1; +CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, d datetime); +CREATE VIEW v1 AS +SELECT id, date(d) + INTERVAL TIME_TO_SEC(d) SECOND AS t, COUNT(*) +FROM t1 GROUP BY id, t; +SHOW CREATE VIEW v1; +View Create View +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`id` AS `id`,(cast(`t1`.`d` as date) + interval time_to_sec(`t1`.`d`) second) AS `t`,count(0) AS `COUNT(*)` from `t1` group by `t1`.`id`,(cast(`t1`.`d` as date) + interval time_to_sec(`t1`.`d`) second) +SELECT * FROM v1; +id t COUNT(*) +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 (i INT, j BIGINT); +INSERT INTO t1 VALUES (1, 2), (2, 2), (3, 2); +CREATE VIEW v1 AS SELECT MIN(j) AS j FROM t1; +CREATE VIEW v2 AS SELECT MIN(i) FROM t1 WHERE j = ( SELECT * FROM v1 ); +SELECT * FROM v2; +MIN(i) +1 +DROP VIEW v2, v1; +DROP TABLE t1; +CREATE TABLE t1( +fName varchar(25) NOT NULL, +lName varchar(25) NOT NULL, +DOB date NOT NULL, +uID int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY); +INSERT INTO t1(fName, lName, DOB) VALUES +('Hank', 'Hill', '1964-09-29'), +('Tom', 'Adams', '1908-02-14'), +('Homer', 'Simpson', '1968-03-05'); +CREATE VIEW v1 AS +SELECT (year(now())-year(DOB)) AS Age +FROM t1 HAVING Age < 75; +SHOW CREATE VIEW v1; +View Create View +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select sql_no_cache (year(now()) - year(`t1`.`DOB`)) AS `Age` from `t1` having (`Age` < 75) +SELECT (year(now())-year(DOB)) AS Age FROM t1 HAVING Age < 75; +Age +42 +38 +SELECT * FROM v1; +Age +42 +38 +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, a char(6) DEFAULT 'xxx'); +INSERT INTO t1(id) VALUES (1), (2), (3), (4); +INSERT INTO t1 VALUES (5,'yyy'), (6,'yyy'); +SELECT * FROM t1; +id a +1 xxx +2 xxx +3 xxx +4 xxx +5 yyy +6 yyy +CREATE VIEW v1(a, m) AS SELECT a, MIN(id) FROM t1 GROUP BY a; +SELECT * FROM v1; +a m +xxx 1 +yyy 5 +CREATE TABLE t2 SELECT * FROM v1; +INSERT INTO t2(m) VALUES (0); +SELECT * FROM t2; +a m +xxx 1 +yyy 5 +xxx 0 +DROP VIEW v1; +DROP TABLE t1,t2; +CREATE TABLE t1 (id int PRIMARY KEY, e ENUM('a','b') NOT NULL DEFAULT 'b'); +INSERT INTO t1(id) VALUES (1), (2), (3); +INSERT INTO t1 VALUES (4,'a'); +SELECT * FROM t1; +id e +1 b +2 b +3 b +4 a +CREATE VIEW v1(m, e) AS SELECT MIN(id), e FROM t1 GROUP BY e; +CREATE TABLE t2 SELECT * FROM v1; +SELECT * FROM t2; +m e +4 a +1 b +DROP VIEW v1; +DROP TABLE IF EXISTS t1,t2; diff --git a/mysql-test/r/view_grant.result b/mysql-test/r/view_grant.result index 2a27dba6101..db82016f398 100644 --- a/mysql-test/r/view_grant.result +++ b/mysql-test/r/view_grant.result @@ -535,3 +535,88 @@ View Create View v2 CREATE ALGORITHM=UNDEFINED DEFINER=`some_user`@`localhost` SQL SECURITY INVOKER VIEW `v2` AS select 1 AS `1` drop view v1; drop view v2; +CREATE DATABASE mysqltest1; +CREATE USER readonly@localhost; +CREATE TABLE mysqltest1.t1 (x INT); +INSERT INTO mysqltest1.t1 VALUES (1), (2); +CREATE SQL SECURITY INVOKER VIEW mysqltest1.v_t1 AS SELECT * FROM mysqltest1.t1; +CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_ts AS SELECT * FROM mysqltest1.t1; +CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_ti AS SELECT * FROM mysqltest1.t1; +CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_tu AS SELECT * FROM mysqltest1.t1; +CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_tus AS SELECT * FROM mysqltest1.t1; +CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_td AS SELECT * FROM mysqltest1.t1; +CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_tds AS SELECT * FROM mysqltest1.t1; +GRANT SELECT, INSERT, UPDATE, DELETE ON mysqltest1.v_t1 TO readonly; +GRANT SELECT ON mysqltest1.v_ts TO readonly; +GRANT INSERT ON mysqltest1.v_ti TO readonly; +GRANT UPDATE ON mysqltest1.v_tu TO readonly; +GRANT UPDATE,SELECT ON mysqltest1.v_tus TO readonly; +GRANT DELETE ON mysqltest1.v_td TO readonly; +GRANT DELETE,SELECT ON mysqltest1.v_tds TO readonly; +SELECT * FROM mysqltest1.v_t1; +ERROR HY000: View 'mysqltest1.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them +INSERT INTO mysqltest1.v_t1 VALUES(4); +ERROR HY000: View 'mysqltest1.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them +DELETE FROM mysqltest1.v_t1 WHERE x = 1; +ERROR HY000: View 'mysqltest1.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them +UPDATE mysqltest1.v_t1 SET x = 3 WHERE x = 2; +ERROR HY000: View 'mysqltest1.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them +UPDATE mysqltest1.v_t1 SET x = 3; +ERROR HY000: View 'mysqltest1.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them +DELETE FROM mysqltest1.v_t1; +ERROR HY000: View 'mysqltest1.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them +SELECT 1 FROM mysqltest1.v_t1; +ERROR HY000: View 'mysqltest1.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them +SELECT * FROM mysqltest1.t1; +ERROR 42000: SELECT command denied to user 'readonly'@'localhost' for table 't1' +SELECT * FROM mysqltest1.v_ts; +x +1 +2 +SELECT * FROM mysqltest1.v_ts, mysqltest1.t1 WHERE mysqltest1.t1.x = mysqltest1.v_ts.x; +ERROR 42000: SELECT command denied to user 'readonly'@'localhost' for table 't1' +SELECT * FROM mysqltest1.v_ti; +ERROR 42000: SELECT command denied to user 'readonly'@'localhost' for table 'v_ti' +INSERT INTO mysqltest1.v_ts VALUES (100); +ERROR 42000: INSERT command denied to user 'readonly'@'localhost' for table 'v_ts' +INSERT INTO mysqltest1.v_ti VALUES (100); +UPDATE mysqltest1.v_ts SET x= 200 WHERE x = 100; +ERROR 42000: UPDATE command denied to user 'readonly'@'localhost' for table 'v_ts' +UPDATE mysqltest1.v_ts SET x= 200; +ERROR 42000: UPDATE command denied to user 'readonly'@'localhost' for table 'v_ts' +UPDATE mysqltest1.v_tu SET x= 200 WHERE x = 100; +UPDATE mysqltest1.v_tus SET x= 200 WHERE x = 100; +UPDATE mysqltest1.v_tu SET x= 200; +DELETE FROM mysqltest1.v_ts WHERE x= 200; +ERROR 42000: DELETE command denied to user 'readonly'@'localhost' for table 'v_ts' +DELETE FROM mysqltest1.v_ts; +ERROR 42000: DELETE command denied to user 'readonly'@'localhost' for table 'v_ts' +DELETE FROM mysqltest1.v_td WHERE x= 200; +ERROR 42000: SELECT command denied to user 'readonly'@'localhost' for column 'x' in table 'v_td' +DELETE FROM mysqltest1.v_tds WHERE x= 200; +DELETE FROM mysqltest1.v_td; +DROP VIEW mysqltest1.v_tds; +DROP VIEW mysqltest1.v_td; +DROP VIEW mysqltest1.v_tus; +DROP VIEW mysqltest1.v_tu; +DROP VIEW mysqltest1.v_ti; +DROP VIEW mysqltest1.v_ts; +DROP VIEW mysqltest1.v_t1; +DROP TABLE mysqltest1.t1; +DROP USER readonly@localhost; +DROP DATABASE mysqltest1; +CREATE TABLE t1 (a INT PRIMARY KEY); +INSERT INTO t1 VALUES (1), (2), (3); +CREATE DEFINER = 'no-such-user'@localhost VIEW v AS SELECT a from t1; +Warnings: +Note 1449 There is no 'no-such-user'@'localhost' registered +SHOW CREATE VIEW v; +View Create View +v CREATE ALGORITHM=UNDEFINED DEFINER=`no-such-user`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select `t1`.`a` AS `a` from `t1` +Warnings: +Note 1449 There is no 'no-such-user'@'localhost' registered +SELECT * FROM v; +ERROR HY000: There is no 'no-such-user'@'localhost' registered +DROP VIEW v; +DROP TABLE t1; +USE test; diff --git a/mysql-test/std_data/bug15328.cnf b/mysql-test/std_data/bug15328.cnf new file mode 100644 index 00000000000..e23d33bfa54 --- /dev/null +++ b/mysql-test/std_data/bug15328.cnf @@ -0,0 +1,2 @@ +[mysqldump] +fields-optionally-enclosed-by=" diff --git a/mysql-test/std_data/cacert.pem b/mysql-test/std_data/cacert.pem index a63dae57767..b445e77d7c4 100644 --- a/mysql-test/std_data/cacert.pem +++ b/mysql-test/std_data/cacert.pem @@ -1,21 +1,17 @@ -----BEGIN CERTIFICATE----- -MIIDcTCCAtqgAwIBAgIBADANBgkqhkiG9w0BAQQFADCBiDELMAkGA1UEBhMCU0Ux -EDAOBgNVBAcTB1VwcHNhbGExETAPBgNVBAoTCE15U1FMIEFCMSEwHwYDVQQDExhB -YnN0cmFjdCBNeVNRTCBEZXZlbG9wZXIxMTAvBgkqhkiG9w0BCQEWImFic3RyYWN0 -Lm15c3FsLmRldmVsb3BlckBteXNxbC5jb20wHhcNMDMwOTEyMTYxNDE2WhcNMTMw -OTA5MTYxNDE2WjCBiDELMAkGA1UEBhMCU0UxEDAOBgNVBAcTB1VwcHNhbGExETAP -BgNVBAoTCE15U1FMIEFCMSEwHwYDVQQDExhBYnN0cmFjdCBNeVNRTCBEZXZlbG9w -ZXIxMTAvBgkqhkiG9w0BCQEWImFic3RyYWN0Lm15c3FsLmRldmVsb3BlckBteXNx -bC5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKrT7zp5tp5djXp+TEQs -5ZEds1XUglp/EQUQ1FMMb1Xe6gqJsQ62O+jsUe0nrUjXBrUCUy49k6mcnmQtZREj -l1pWKmzx1fgcYpxTwxaY7IKB2jik5IWprhVPmSQ+AWss43oolXMZWR+csKehqm3j -+YNZc9NsR4ydE71l0VEtJEQvAgMBAAGjgegwgeUwHQYDVR0OBBYEFIiYZdnz8osD -HWZgYSP6rXNt02iSMIG1BgNVHSMEga0wgaqAFIiYZdnz8osDHWZgYSP6rXNt02iS -oYGOpIGLMIGIMQswCQYDVQQGEwJTRTEQMA4GA1UEBxMHVXBwc2FsYTERMA8GA1UE -ChMITXlTUUwgQUIxITAfBgNVBAMTGEFic3RyYWN0IE15U1FMIERldmVsb3BlcjEx -MC8GCSqGSIb3DQEJARYiYWJzdHJhY3QubXlzcWwuZGV2ZWxvcGVyQG15c3FsLmNv -bYIBADAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBAUAA4GBAGIL22MCIU/0sKDp -pZIhoabvNVDTfuhtene+WBCrzCzGXPZjB4+b/KAJJNvOR4zi43Kk7euu+PENs9M7 -nKpInMdhvT1RcCnUHJ3jBCvDDzXab2msqn3rxhwetWWbfE0OeEn/PoQcwiZCe7x5 -h+Zz+oUbvsEe4DjtDVgG4UH9nSSS +MIICrTCCAhagAwIBAgIJAIAO/Ybiptv1MA0GCSqGSIb3DQEBBAUAMEQxCzAJBgNV +BAYTAlNFMRAwDgYDVQQIEwdVcHBzYWxhMRAwDgYDVQQHEwdVcHBzYWxhMREwDwYD +VQQKEwhNeVNRTCBBQjAeFw0wNjA1MDMwODQ4NTRaFw0wOTAxMjcwODQ4NTRaMEQx +CzAJBgNVBAYTAlNFMRAwDgYDVQQIEwdVcHBzYWxhMRAwDgYDVQQHEwdVcHBzYWxh +MREwDwYDVQQKEwhNeVNRTCBBQjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA ++C46EQl1u7tQ6gb9eqc8V079gr8YmDPCEqtjO8bCIbchpjOpDITx0WZz36Sn9E72 +GPJwNip4FxLaPRIA3xNQHM5cE5U53qznlRx1Fc4O3hcWCvyCqNDl/vzPAh3pI6Bl +Ku9hfHXpp93W812smVPe9haShEXGgbEPYGzvOfVdu/MCAwEAAaOBpjCBozAdBgNV +HQ4EFgQUjIy/6OCTmqtPHBFha6/qzVk3yTcwdAYDVR0jBG0wa4AUjIy/6OCTmqtP +HBFha6/qzVk3yTehSKRGMEQxCzAJBgNVBAYTAlNFMRAwDgYDVQQIEwdVcHBzYWxh +MRAwDgYDVQQHEwdVcHBzYWxhMREwDwYDVQQKEwhNeVNRTCBBQoIJAIAO/Ybiptv1 +MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEA8lD9zyB820Oq1aj7ZafX +De/hbdt9RIl2tzgw2K3r1KZGdXJVL0vSt5fZ51Nq9lg7OPJy3iXf+caBJEp0IJpB +uf4Gfr6zfXw+UlY6ZthRtHQHoXKcbskECjH5/ps/Uaa+dpVQ9O+Ii1rPzmgo6ztM +s+xZ46ESBt4WiHXm8kwbU9Y= -----END CERTIFICATE----- diff --git a/mysql-test/std_data/client-cert.pem b/mysql-test/std_data/client-cert.pem index 4c81162c911..fdd5c86a23f 100644 --- a/mysql-test/std_data/client-cert.pem +++ b/mysql-test/std_data/client-cert.pem @@ -1,67 +1,42 @@ Certificate: Data: - Version: 3 (0x2) + Version: 1 (0x0) Serial Number: 1 (0x1) Signature Algorithm: md5WithRSAEncryption - Issuer: C=SE, L=Uppsala, O=MySQL AB, CN=Abstract MySQL Developer/Email=abstract.mysql.developer@mysql.com + Issuer: C=SE, ST=Uppsala, L=Uppsala, O=MySQL AB Validity - Not Before: Sep 12 16:21:19 2003 GMT - Not After : Sep 9 16:21:19 2013 GMT - Subject: C=SE, L=Uppsala, O=MySQL AB, CN=MySQL Client/Email=abstract.mysql.developer@mysql.com + Not Before: May 3 08:55:39 2006 GMT + Not After : Jan 27 08:55:39 2009 GMT + Subject: C=SE, ST=Uppsala, L=Uppsala, O=MySQL AB/emailAddress=abstract.mysql.developer@mysql.com Subject Public Key Info: Public Key Algorithm: rsaEncryption - RSA Public Key: (1024 bit) - Modulus (1024 bit): - 00:c4:03:0a:ee:e3:b1:12:fc:ee:b4:19:f4:e1:60: - 1d:e0:28:c3:96:2d:df:82:69:cd:74:7c:54:58:d0: - ae:b3:59:3f:0c:19:1c:99:10:a6:12:c9:cf:3a:64: - 05:43:8e:bf:d2:65:36:80:91:0b:65:b0:27:26:38: - c9:23:d8:36:a2:4a:f0:f7:c0:2f:68:38:70:01:27: - 29:ff:b2:c5:52:e1:6b:f1:c8:d7:c3:5c:ee:f0:37: - 6c:2a:9b:96:1a:05:9e:eb:33:a2:39:5a:77:66:62: - 27:75:1f:2f:6f:38:da:e5:9f:78:af:ca:6b:22:3f: - 57:2b:bc:a6:8f:47:d1:99:6f + RSA Public Key: (512 bit) + Modulus (512 bit): + 00:d8:db:68:28:49:84:4d:d6:0f:5c:bc:3d:9a:ab: + 70:d5:3e:f5:b5:17:ba:ef:e1:f8:87:54:30:22:1f: + 81:07:bf:f9:24:7f:8a:54:10:e9:5f:e6:99:50:04: + d4:3b:55:a9:f1:52:ad:12:2b:5a:da:5c:be:8c:3e: + 5b:9e:b0:5a:19 Exponent: 65537 (0x10001) - X509v3 extensions: - X509v3 Basic Constraints: - CA:FALSE - Netscape Comment: - OpenSSL Generated Certificate - X509v3 Subject Key Identifier: - 80:81:A9:22:EB:AB:D6:CA:7E:3F:8D:BB:D1:AC:2A:F4:87:9D:13:29 - X509v3 Authority Key Identifier: - keyid:88:98:65:D9:F3:F2:8B:03:1D:66:60:61:23:FA:AD:73:6D:D3:68:92 - DirName:/C=SE/L=Uppsala/O=MySQL AB/CN=Abstract MySQL Developer/Email=abstract.mysql.developer@mysql.com - serial:00 - Signature Algorithm: md5WithRSAEncryption - 86:17:1c:f3:9f:10:1b:75:47:03:ca:54:ea:ef:f7:15:54:8d: - 8f:58:c9:64:7d:de:2e:bf:ea:a6:5d:72:56:c9:81:be:bb:1c: - 78:a5:91:d6:f8:77:df:9d:d2:cb:94:d9:06:61:4f:05:21:22: - 2a:ea:9e:c3:8b:4d:fe:94:c7:98:61:cd:7e:88:19:c9:92:01: - 1f:10:5b:c6:16:95:99:9b:32:01:3a:89:df:fa:0a:89:ac:fa: - b5:40:55:7a:ca:0a:bd:5d:8b:06:d8:7e:e1:44:8c:70:c8:63: - c7:77:6a:37:3d:a4:ac:57:dc:00:c1:c1:f3:72:17:5b:50:95: - ee:b7 + 07:57:bf:07:92:c2:8e:86:24:6b:0a:bf:e5:31:21:44:c3:60: + 02:a6:ac:9e:f7:db:7a:6e:fc:4f:d4:7b:54:18:80:47:d2:4a: + 63:0e:e3:f8:af:6e:58:e3:97:5a:2b:82:5d:76:20:d1:33:a0: + f5:43:a1:d1:51:f4:ca:c8:b3:1a:66:4e:0e:55:df:d2:e8:fa: + 83:18:42:f5:ec:66:40:f0:39:e8:f9:d7:cf:f6:dd:e4:7b:69: + dd:0c:92:d8:52:95:43:6f:29:3d:f0:8d:4c:dd:52:ea:6b:a0: + 39:0f:dc:59:a7:5c:37:6b:8b:05:44:b7:69:ea:a3:58:e0:4e: + ce:d6 -----BEGIN CERTIFICATE----- -MIIDkTCCAvqgAwIBAgIBATANBgkqhkiG9w0BAQQFADCBiDELMAkGA1UEBhMCU0Ux -EDAOBgNVBAcTB1VwcHNhbGExETAPBgNVBAoTCE15U1FMIEFCMSEwHwYDVQQDExhB -YnN0cmFjdCBNeVNRTCBEZXZlbG9wZXIxMTAvBgkqhkiG9w0BCQEWImFic3RyYWN0 -Lm15c3FsLmRldmVsb3BlckBteXNxbC5jb20wHhcNMDMwOTEyMTYyMTE5WhcNMTMw -OTA5MTYyMTE5WjB8MQswCQYDVQQGEwJTRTEQMA4GA1UEBxMHVXBwc2FsYTERMA8G -A1UEChMITXlTUUwgQUIxFTATBgNVBAMTDE15U1FMIENsaWVudDExMC8GCSqGSIb3 -DQEJARYiYWJzdHJhY3QubXlzcWwuZGV2ZWxvcGVyQG15c3FsLmNvbTCBnzANBgkq -hkiG9w0BAQEFAAOBjQAwgYkCgYEAxAMK7uOxEvzutBn04WAd4CjDli3fgmnNdHxU -WNCus1k/DBkcmRCmEsnPOmQFQ46/0mU2gJELZbAnJjjJI9g2okrw98AvaDhwAScp -/7LFUuFr8cjXw1zu8DdsKpuWGgWe6zOiOVp3ZmIndR8vbzja5Z94r8prIj9XK7ym -j0fRmW8CAwEAAaOCARQwggEQMAkGA1UdEwQCMAAwLAYJYIZIAYb4QgENBB8WHU9w -ZW5TU0wgR2VuZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQWBBSAgaki66vWyn4/ -jbvRrCr0h50TKTCBtQYDVR0jBIGtMIGqgBSImGXZ8/KLAx1mYGEj+q1zbdNokqGB -jqSBizCBiDELMAkGA1UEBhMCU0UxEDAOBgNVBAcTB1VwcHNhbGExETAPBgNVBAoT -CE15U1FMIEFCMSEwHwYDVQQDExhBYnN0cmFjdCBNeVNRTCBEZXZlbG9wZXIxMTAv -BgkqhkiG9w0BCQEWImFic3RyYWN0Lm15c3FsLmRldmVsb3BlckBteXNxbC5jb22C -AQAwDQYJKoZIhvcNAQEEBQADgYEAhhcc858QG3VHA8pU6u/3FVSNj1jJZH3eLr/q -pl1yVsmBvrsceKWR1vh3353Sy5TZBmFPBSEiKuqew4tN/pTHmGHNfogZyZIBHxBb -xhaVmZsyATqJ3/oKiaz6tUBVesoKvV2LBth+4USMcMhjx3dqNz2krFfcAMHB83IX -W1CV7rc= +MIIB5jCCAU8CAQEwDQYJKoZIhvcNAQEEBQAwRDELMAkGA1UEBhMCU0UxEDAOBgNV +BAgTB1VwcHNhbGExEDAOBgNVBAcTB1VwcHNhbGExETAPBgNVBAoTCE15U1FMIEFC +MB4XDTA2MDUwMzA4NTUzOVoXDTA5MDEyNzA4NTUzOVowdzELMAkGA1UEBhMCU0Ux +EDAOBgNVBAgTB1VwcHNhbGExEDAOBgNVBAcTB1VwcHNhbGExETAPBgNVBAoTCE15 +U1FMIEFCMTEwLwYJKoZIhvcNAQkBFiJhYnN0cmFjdC5teXNxbC5kZXZlbG9wZXJA +bXlzcWwuY29tMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANjbaChJhE3WD1y8PZqr +cNU+9bUXuu/h+IdUMCIfgQe/+SR/ilQQ6V/mmVAE1DtVqfFSrRIrWtpcvow+W56w +WhkCAwEAATANBgkqhkiG9w0BAQQFAAOBgQAHV78HksKOhiRrCr/lMSFEw2ACpqye +99t6bvxP1HtUGIBH0kpjDuP4r25Y45daK4JddiDRM6D1Q6HRUfTKyLMaZk4OVd/S +6PqDGEL17GZA8Dno+dfP9t3ke2ndDJLYUpVDbyk98I1M3VLqa6A5D9xZp1w3a4sF +RLdp6qNY4E7O1g== -----END CERTIFICATE----- diff --git a/mysql-test/std_data/client-key.pem b/mysql-test/std_data/client-key.pem index 58fa805e620..22f8e23ab2a 100644 --- a/mysql-test/std_data/client-key.pem +++ b/mysql-test/std_data/client-key.pem @@ -1,15 +1,9 @@ -----BEGIN RSA PRIVATE KEY----- -MIICXQIBAAKBgQDEAwru47ES/O60GfThYB3gKMOWLd+Cac10fFRY0K6zWT8MGRyZ -EKYSyc86ZAVDjr/SZTaAkQtlsCcmOMkj2DaiSvD3wC9oOHABJyn/ssVS4WvxyNfD -XO7wN2wqm5YaBZ7rM6I5WndmYid1Hy9vONrln3ivymsiP1crvKaPR9GZbwIDAQAB -AoGAcR7IaoGhKbIrGGl6d67+zuT3q24h9aOV3Mn7653TlNHGnvbHGFcRYPpyy+H5 -X7m8XnHm+F+80hzNGzPecP9Q12oPOyoZgeQn6bTK73OFkNcX7FAkNdyH4xVhf2aK -YOzTcQfq3gRCqXtVIg4qBShTMjJLE31R8H430Or62XmJgFECQQDjP+Kz+ecQwuTB -HADLm+GQgceIB1kLgdQoZ3deUxGvqtVImuDRViSM0F2srfJ4GfkEDhc27UI5f6ir -ZTOw4ww7AkEA3M9wCPgWNtbOXbYjaNA0IzHcjMDxQDVvJAmb3EiZlKQp4EfrESxR -ly/u08TyfwrK6q5WS7xE0ad8+95G1af4XQJBAI9+3ME20SB1YItMCniHYwSj3oHX -2fN5NKWax/Zoz+c0IV+qZMHq+kNso2oRoOUTyXk1CJWndcTnBnPMALr2c9cCQQCZ -VL7Cq6uZVx6kemcqUHH0AprZbt3YLYLI7pc5p3xmeHzPzoEQQstBhjp8+aU+zPrN -blRkcQ8E2x5yNA7SLLrNAkAhzkA+EK8hc0f9W3ncy+py0Rn0i5Ay0N3T715vkThf -CfOHE3L91dLlmYpL5xVqOpugY/2sHyxwctv97DgS6tHZ +MIIBOgIBAAJBANjbaChJhE3WD1y8PZqrcNU+9bUXuu/h+IdUMCIfgQe/+SR/ilQQ +6V/mmVAE1DtVqfFSrRIrWtpcvow+W56wWhkCAwEAAQJAK27WT6tZylUjQomZNQ89 +TBiOEbUtBbqWklQ0R8FTkH9uKV+8KYQ+k+tMkoAEGFfChB0YfofNQ2KZYWWw4yOB +WQIhAPXXDQt73aou10s+cmKM3C3WzLmIZtrvm9wNBXWDGxgTAiEA4dG4cXrZfa1M +TTbjzNU1/Jf50/M8SvZDWMPQWxJ8oqMCIH6zBpYUkHlVCsBMvsbrsc4uFfTIx7mu +I7WVQGr/1sbhAiBf4uFirjtztgZUMx5/d3k5DH80lG/hlLf8FQl/4lWx6QIhAPHw +CXfPUbUFl4r/i9Br5+exGol50qX4F3aP5Sh5EnZT -----END RSA PRIVATE KEY----- diff --git a/mysql-test/std_data/server-cert.pem b/mysql-test/std_data/server-cert.pem index debf7026e3c..f420b4f3124 100644 --- a/mysql-test/std_data/server-cert.pem +++ b/mysql-test/std_data/server-cert.pem @@ -1,67 +1,42 @@ Certificate: Data: - Version: 3 (0x2) - Serial Number: 2 (0x2) + Version: 1 (0x0) + Serial Number: 1 (0x1) Signature Algorithm: md5WithRSAEncryption - Issuer: C=SE, L=Uppsala, O=MySQL AB, CN=Abstract MySQL Developer/Email=abstract.mysql.developer@mysql.com + Issuer: C=SE, ST=Uppsala, L=Uppsala, O=MySQL AB Validity - Not Before: Sep 12 16:22:06 2003 GMT - Not After : Sep 9 16:22:06 2013 GMT - Subject: C=SE, L=Uppsala, O=MySQL AB, CN=MySQL Server/Email=abstract.mysql.developer@mysql.com + Not Before: May 3 08:54:13 2006 GMT + Not After : Jan 27 08:54:13 2009 GMT + Subject: C=SE, ST=Uppsala, L=Uppsala, O=MySQL AB, CN=localhost/emailAddress=abstract.mysql.developer@mysql.com Subject Public Key Info: Public Key Algorithm: rsaEncryption - RSA Public Key: (1024 bit) - Modulus (1024 bit): - 00:e9:86:7a:55:84:88:4c:be:a4:f8:92:73:30:12: - 49:0b:7a:85:87:39:34:39:0d:7d:0b:8d:18:c2:17: - 95:13:52:d2:3f:55:10:57:c8:3f:5a:f5:b2:fa:8b: - d0:67:49:cc:aa:82:fc:9f:ce:00:b4:73:f3:36:d2: - 3a:d3:c2:b0:0e:14:c3:d4:b2:21:74:a1:f0:31:81: - 60:87:98:73:5c:10:c1:b1:1a:4d:f1:f3:b0:98:3f: - f0:d7:97:9b:2b:fd:d5:21:79:b2:2f:eb:64:15:c9: - 9b:9d:fc:9e:2d:d4:f8:04:5b:ea:a9:75:4b:42:c3: - 3d:0e:4d:2a:a8:b8:ca:99:8d + RSA Public Key: (512 bit) + Modulus (512 bit): + 00:d9:fd:da:b3:fb:7c:e0:b0:03:be:97:c6:a4:36: + ac:71:af:bb:2d:e5:84:ed:f3:8f:2b:eb:11:e5:aa: + 66:ed:bf:62:6b:e3:ce:fa:80:ed:90:ff:b9:4a:39: + 20:40:b6:f2:99:bf:2f:33:b5:f2:ec:3a:90:60:1d: + 9e:94:7e:a4:1b Exponent: 65537 (0x10001) - X509v3 extensions: - X509v3 Basic Constraints: - CA:FALSE - Netscape Comment: - OpenSSL Generated Certificate - X509v3 Subject Key Identifier: - 6E:E4:9B:6A:C5:EA:E4:E6:C7:EF:D7:1E:C8:63:45:60:2B:1B:D4:D4 - X509v3 Authority Key Identifier: - keyid:88:98:65:D9:F3:F2:8B:03:1D:66:60:61:23:FA:AD:73:6D:D3:68:92 - DirName:/C=SE/L=Uppsala/O=MySQL AB/CN=Abstract MySQL Developer/Email=abstract.mysql.developer@mysql.com - serial:00 - Signature Algorithm: md5WithRSAEncryption - 31:77:69:b9:bd:ab:29:f3:fc:5a:09:16:6f:5d:42:ea:ba:01: - 55:69:e3:75:cf:b8:d1:b7:b9:bf:da:63:85:8c:48:92:06:60: - 76:97:e0:00:78:4b:ad:da:ab:6a:90:6d:8b:03:a8:b1:e9:09: - 78:e1:29:98:56:12:60:6b:42:fe:e8:a7:c4:f8:d6:15:07:e8: - 2b:c2:d8:8a:e5:1b:2e:51:08:9b:56:e3:b3:7a:4c:3e:e5:be: - 4a:4d:f8:65:7b:a8:21:e0:ca:fe:8b:ab:d7:ec:f2:2d:f7:d0: - bf:d7:c5:23:1c:08:d8:aa:57:c7:f3:5f:ba:33:3f:78:d1:f4: - 8e:5e + de:5e:35:cd:7b:11:e6:7c:c5:7c:d6:27:4e:72:12:49:42:eb: + 6f:2c:96:f3:f4:00:78:a7:4f:9f:2d:7b:d7:30:39:af:49:4d: + df:b1:55:0d:30:be:23:6f:06:67:fd:dd:ba:98:66:36:c6:32: + b7:ed:63:fc:aa:49:cd:4f:72:98:3b:13:0e:f6:28:d7:d4:eb: + 04:6b:dc:e8:c7:04:80:92:e4:04:86:0b:ed:32:25:76:1d:a9: + 5c:a9:2c:18:2c:bd:bc:15:ed:e1:76:96:4d:bb:0d:41:44:06: + 2c:ad:45:bb:db:61:ad:17:11:cb:49:70:67:eb:c6:27:d3:91: + c8:f2 -----BEGIN CERTIFICATE----- -MIIDkTCCAvqgAwIBAgIBAjANBgkqhkiG9w0BAQQFADCBiDELMAkGA1UEBhMCU0Ux -EDAOBgNVBAcTB1VwcHNhbGExETAPBgNVBAoTCE15U1FMIEFCMSEwHwYDVQQDExhB -YnN0cmFjdCBNeVNRTCBEZXZlbG9wZXIxMTAvBgkqhkiG9w0BCQEWImFic3RyYWN0 -Lm15c3FsLmRldmVsb3BlckBteXNxbC5jb20wHhcNMDMwOTEyMTYyMjA2WhcNMTMw -OTA5MTYyMjA2WjB8MQswCQYDVQQGEwJTRTEQMA4GA1UEBxMHVXBwc2FsYTERMA8G -A1UEChMITXlTUUwgQUIxFTATBgNVBAMTDE15U1FMIFNlcnZlcjExMC8GCSqGSIb3 -DQEJARYiYWJzdHJhY3QubXlzcWwuZGV2ZWxvcGVyQG15c3FsLmNvbTCBnzANBgkq -hkiG9w0BAQEFAAOBjQAwgYkCgYEA6YZ6VYSITL6k+JJzMBJJC3qFhzk0OQ19C40Y -wheVE1LSP1UQV8g/WvWy+ovQZ0nMqoL8n84AtHPzNtI608KwDhTD1LIhdKHwMYFg -h5hzXBDBsRpN8fOwmD/w15ebK/3VIXmyL+tkFcmbnfyeLdT4BFvqqXVLQsM9Dk0q -qLjKmY0CAwEAAaOCARQwggEQMAkGA1UdEwQCMAAwLAYJYIZIAYb4QgENBB8WHU9w -ZW5TU0wgR2VuZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQWBBRu5Jtqxerk5sfv -1x7IY0VgKxvU1DCBtQYDVR0jBIGtMIGqgBSImGXZ8/KLAx1mYGEj+q1zbdNokqGB -jqSBizCBiDELMAkGA1UEBhMCU0UxEDAOBgNVBAcTB1VwcHNhbGExETAPBgNVBAoT -CE15U1FMIEFCMSEwHwYDVQQDExhBYnN0cmFjdCBNeVNRTCBEZXZlbG9wZXIxMTAv -BgkqhkiG9w0BCQEWImFic3RyYWN0Lm15c3FsLmRldmVsb3BlckBteXNxbC5jb22C -AQAwDQYJKoZIhvcNAQEEBQADgYEAMXdpub2rKfP8WgkWb11C6roBVWnjdc+40be5 -v9pjhYxIkgZgdpfgAHhLrdqrapBtiwOosekJeOEpmFYSYGtC/uinxPjWFQfoK8LY -iuUbLlEIm1bjs3pMPuW+Sk34ZXuoIeDK/our1+zyLffQv9fFIxwI2KpXx/NfujM/ -eNH0jl4= +MIIB+zCCAWQCAQEwDQYJKoZIhvcNAQEEBQAwRDELMAkGA1UEBhMCU0UxEDAOBgNV +BAgTB1VwcHNhbGExEDAOBgNVBAcTB1VwcHNhbGExETAPBgNVBAoTCE15U1FMIEFC +MB4XDTA2MDUwMzA4NTQxM1oXDTA5MDEyNzA4NTQxM1owgYsxCzAJBgNVBAYTAlNF +MRAwDgYDVQQIEwdVcHBzYWxhMRAwDgYDVQQHEwdVcHBzYWxhMREwDwYDVQQKEwhN +eVNRTCBBQjESMBAGA1UEAxMJbG9jYWxob3N0MTEwLwYJKoZIhvcNAQkBFiJhYnN0 +cmFjdC5teXNxbC5kZXZlbG9wZXJAbXlzcWwuY29tMFwwDQYJKoZIhvcNAQEBBQAD +SwAwSAJBANn92rP7fOCwA76XxqQ2rHGvuy3lhO3zjyvrEeWqZu2/YmvjzvqA7ZD/ +uUo5IEC28pm/LzO18uw6kGAdnpR+pBsCAwEAATANBgkqhkiG9w0BAQQFAAOBgQDe +XjXNexHmfMV81idOchJJQutvLJbz9AB4p0+fLXvXMDmvSU3fsVUNML4jbwZn/d26 +mGY2xjK37WP8qknNT3KYOxMO9ijX1OsEa9zoxwSAkuQEhgvtMiV2HalcqSwYLL28 +Fe3hdpZNuw1BRAYsrUW722GtFxHLSXBn68Yn05HI8g== -----END CERTIFICATE----- diff --git a/mysql-test/std_data/server-key.pem b/mysql-test/std_data/server-key.pem index 4292dc79929..a4842624c0c 100644 --- a/mysql-test/std_data/server-key.pem +++ b/mysql-test/std_data/server-key.pem @@ -1,15 +1,9 @@ -----BEGIN RSA PRIVATE KEY----- -MIICXgIBAAKBgQDphnpVhIhMvqT4knMwEkkLeoWHOTQ5DX0LjRjCF5UTUtI/VRBX -yD9a9bL6i9BnScyqgvyfzgC0c/M20jrTwrAOFMPUsiF0ofAxgWCHmHNcEMGxGk3x -87CYP/DXl5sr/dUhebIv62QVyZud/J4t1PgEW+qpdUtCwz0OTSqouMqZjQIDAQAB -AoGBALTq11nrjIEQbdSZ+R1z/R0kddB2U+wjdA3/6P9tr7PBxVsFdtzbKaI5mcib -iwCKX0J2qmrP+SHUdsexBZxLR4KV/Z55v9Pym99Dy+DxDA95zURyCMKRBIzlU5uN -F7USEQoltLUCsmZwNWdit0gfxSWdddkHNuI0uxTzHwuDcUlNAkEA/76zVremngNL -DlekM9NPn/8E/TXBHN1b1jdUKd7WymSJykdcm3viU98dFNZFWF8B0jiTcuBKXgpR -vTShNab/swJBAOnCGp554BLhioTyyk8qjRLt3xEsjsDljJULHVLYWcUqIkMf97GL -VLBhl6ZEI9i0WduqvgZ+Bacd0uHqIHz1Yb8CQQDm1CjqTDiGxlIoT9JVNJTZxEOs -h6gVdXY+kxHT+N3FL5luiZp8fAR7zxVgiUVtzdLG+2madfapiobcT3RyCJkhAkBI -64AaR7KasTjg2Ew7/e4cJZAcb2XozrLYG6t+GHeIhehCQEqoW+qDSy5fc4orI7eU -SuMUa2OgCjGqv7p6wKFJAkEAznmum/MbVOBpC4FsdnIGkxyFKIbh2OLY2aUb2KkK -Ouf4S8Y5Ldgszi0fnDPRaxWJzewwZKvcff2zj+mYZeAXbA== +MIIBOgIBAAJBANn92rP7fOCwA76XxqQ2rHGvuy3lhO3zjyvrEeWqZu2/YmvjzvqA +7ZD/uUo5IEC28pm/LzO18uw6kGAdnpR+pBsCAwEAAQJBAMieYdpmRoUaODf9wqh6 +ULXH/sG8i1vaXRcUHcJ50oRVfVK8/tGGvUuTDu6MeINTdahNDlYfjwOjKWVXys1w +h6ECIQDs6s7DfczK2bKCLt0zqg24mZL3rOpGmDU+TatwN1yVgwIhAOuMzdVTX39p +328+5WxJvBOFfxmSmqdDhIFpnRMvgguJAiByvKjT/km+970+1OllyvaIL0AA2OpA +tBgdC0p6tyUMdwIgKuHAWzTJbu28UolVxQgLaFZmVCZ/ZzIAfnrWsLZ2a1kCIBq/ +ywJ2cpyFlgazu8AH6KCQa0ok9s70ElaB6FEC85Al -----END RSA PRIVATE KEY----- diff --git a/mysql-test/std_data/untrusted-cacert.pem b/mysql-test/std_data/untrusted-cacert.pem new file mode 100644 index 00000000000..981dd004fc6 --- /dev/null +++ b/mysql-test/std_data/untrusted-cacert.pem @@ -0,0 +1,53 @@ +Certificate: + Data: + Version: 3 (0x2) + Serial Number: 0 (0x0) + Signature Algorithm: md5WithRSAEncryption + Issuer: C=US, ST=Oregon, L=Portland, O=sawtooth, CN=www.sawtooth-consulting.com/emailAddress=info@yassl.com + Validity + Not Before: Jan 18 20:12:32 2005 GMT + Not After : Oct 15 20:12:32 2007 GMT + Subject: C=US, ST=Oregon, L=Portland, O=sawtooth, CN=www.sawtooth-consulting.com/emailAddress=info@yassl.com + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public Key: (512 bit) + Modulus (512 bit): + 00:cf:2b:14:00:b0:3c:df:6f:9e:91:40:ec:c8:f6: + 90:b2:5b:b4:70:80:a5:a4:0a:73:c7:44:f3:2a:26: + c4:2f:f1:3a:f1:c3:c4:ac:fc:c3:d2:c3:bf:f5:d7: + 6a:38:42:ad:22:ab:c8:c4:4b:4c:1d:16:af:05:34: + 7d:79:97:5e:e1 + Exponent: 65537 (0x10001) + X509v3 extensions: + X509v3 Subject Key Identifier: + CB:0F:1F:E9:A2:76:71:C9:E6:E8:23:A6:C1:18:B7:CC:44:CF:B9:84 + X509v3 Authority Key Identifier: + keyid:CB:0F:1F:E9:A2:76:71:C9:E6:E8:23:A6:C1:18:B7:CC:44:CF:B9:84 + DirName:/C=US/ST=Oregon/L=Portland/O=sawtooth/CN=www.sawtooth-consulting.com/emailAddress=info@yassl.com + serial:00 + + X509v3 Basic Constraints: + CA:TRUE + Signature Algorithm: md5WithRSAEncryption + 27:f7:3d:fb:39:6f:73:a4:86:f3:a0:48:22:60:84:e9:5c:3d: + 28:36:05:16:44:98:07:87:e1:5d:b5:f3:a7:bc:33:5f:f4:29: + a9:5f:87:33:df:e6:8e:bd:e2:f3:0a:c8:00:69:ae:3d:41:47: + 03:ea:0b:4c:67:45:4b:ab:f3:39 +-----BEGIN CERTIFICATE----- +MIIC7zCCApmgAwIBAgIBADANBgkqhkiG9w0BAQQFADCBiTELMAkGA1UEBhMCVVMx +DzANBgNVBAgTBk9yZWdvbjERMA8GA1UEBxMIUG9ydGxhbmQxETAPBgNVBAoTCHNh +d3Rvb3RoMSQwIgYDVQQDExt3d3cuc2F3dG9vdGgtY29uc3VsdGluZy5jb20xHTAb +BgkqhkiG9w0BCQEWDmluZm9AeWFzc2wuY29tMB4XDTA1MDExODIwMTIzMloXDTA3 +MTAxNTIwMTIzMlowgYkxCzAJBgNVBAYTAlVTMQ8wDQYDVQQIEwZPcmVnb24xETAP +BgNVBAcTCFBvcnRsYW5kMREwDwYDVQQKEwhzYXd0b290aDEkMCIGA1UEAxMbd3d3 +LnNhd3Rvb3RoLWNvbnN1bHRpbmcuY29tMR0wGwYJKoZIhvcNAQkBFg5pbmZvQHlh +c3NsLmNvbTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDPKxQAsDzfb56RQOzI9pCy +W7RwgKWkCnPHRPMqJsQv8Trxw8Ss/MPSw7/112o4Qq0iq8jES0wdFq8FNH15l17h +AgMBAAGjgekwgeYwHQYDVR0OBBYEFMsPH+midnHJ5ugjpsEYt8xEz7mEMIG2BgNV +HSMEga4wgauAFMsPH+midnHJ5ugjpsEYt8xEz7mEoYGPpIGMMIGJMQswCQYDVQQG +EwJVUzEPMA0GA1UECBMGT3JlZ29uMREwDwYDVQQHEwhQb3J0bGFuZDERMA8GA1UE +ChMIc2F3dG9vdGgxJDAiBgNVBAMTG3d3dy5zYXd0b290aC1jb25zdWx0aW5nLmNv +bTEdMBsGCSqGSIb3DQEJARYOaW5mb0B5YXNzbC5jb22CAQAwDAYDVR0TBAUwAwEB +/zANBgkqhkiG9w0BAQQFAANBACf3Pfs5b3OkhvOgSCJghOlcPSg2BRZEmAeH4V21 +86e8M1/0KalfhzPf5o694vMKyABprj1BRwPqC0xnRUur8zk= +-----END CERTIFICATE----- diff --git a/mysql-test/t/alter_table.test b/mysql-test/t/alter_table.test index 7cddb8bafa9..efe58579785 100644 --- a/mysql-test/t/alter_table.test +++ b/mysql-test/t/alter_table.test @@ -469,3 +469,16 @@ ALTER TABLE t1 MODIFY s BINARY(10); SELECT HEX(s) FROM t1; SELECT LENGTH(s) FROM t1; DROP TABLE t1; + +# +# Bug#19386: Multiple alter causes crashed table +# The trailing column would get corrupted data, or server could not even read +# it. +# + +CREATE TABLE t1 (v VARCHAR(3), b INT); +INSERT INTO t1 VALUES ('abc', 5); +SELECT * FROM t1; +ALTER TABLE t1 MODIFY COLUMN v VARCHAR(4); +SELECT * FROM t1; +DROP TABLE t1; diff --git a/mysql-test/t/ansi.test b/mysql-test/t/ansi.test index 444bf982b8a..fa7f999954e 100644 --- a/mysql-test/t/ansi.test +++ b/mysql-test/t/ansi.test @@ -26,4 +26,16 @@ drop table t1; SET @@SQL_MODE=""; +# Bug#14515 + +CREATE TABLE t1 (i int auto_increment NOT NULL, PRIMARY KEY (i)); +SHOW CREATE TABLE t1; +SET @@SQL_MODE="MYSQL323"; +SHOW CREATE TABLE t1; +SET @@SQL_MODE="MYSQL40"; +SHOW CREATE TABLE t1; +SET @@SQL_MODE="NO_FIELD_OPTIONS"; +SHOW CREATE TABLE t1; +DROP TABLE t1; + # End of 4.1 tests diff --git a/mysql-test/t/archive.test b/mysql-test/t/archive.test index 7e091991475..c89d31c69b9 100644 --- a/mysql-test/t/archive.test +++ b/mysql-test/t/archive.test @@ -5,7 +5,7 @@ -- source include/have_archive.inc --disable_warnings -drop table if exists t1,t2; +drop table if exists t1,t2,t3; --enable_warnings CREATE TABLE t1 ( diff --git a/mysql-test/t/auto_increment.test b/mysql-test/t/auto_increment.test index b20fe80303d..e0b024d021b 100644 --- a/mysql-test/t/auto_increment.test +++ b/mysql-test/t/auto_increment.test @@ -219,7 +219,26 @@ INSERT INTO t1 (b) VALUES ('bbbb'); CHECK TABLE t1; DROP TABLE IF EXISTS t1; -# End of 4.1 tests +# BUG #19025: + +CREATE TABLE `t1` ( + t1_name VARCHAR(255) DEFAULT NULL, + t1_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + KEY (t1_name), + PRIMARY KEY (t1_id) +) AUTO_INCREMENT = 1000; + +INSERT INTO t1 (t1_name) VALUES('MySQL'); +INSERT INTO t1 (t1_name) VALUES('MySQL'); +INSERT INTO t1 (t1_name) VALUES('MySQL'); + +SELECT * from t1; + +SHOW CREATE TABLE `t1`; + +DROP TABLE `t1`; + +--echo End of 4.1 tests # # Bug #11080 & #11005 Multi-row REPLACE fails on a duplicate key error @@ -256,3 +275,14 @@ update t1 set a=2 where a=1; insert into t1 (val) values (1); select * from t1; drop table t1; + +# +# Test key duplications with auto-increment in ALTER TABLE +# bug #14573 +# +CREATE TABLE t1 (t1 INT(10) PRIMARY KEY, t2 INT(10)); +INSERT INTO t1 VALUES(0, 0); +INSERT INTO t1 VALUES(1, 1); +--error ER_DUP_ENTRY +ALTER TABLE t1 CHANGE t1 t1 INT(10) auto_increment; +DROP TABLE t1; diff --git a/mysql-test/t/contributors.test b/mysql-test/t/contributors.test new file mode 100644 index 00000000000..e463c4a888b --- /dev/null +++ b/mysql-test/t/contributors.test @@ -0,0 +1 @@ +SHOW CONTRIBUTORS; diff --git a/mysql-test/t/ctype_sjis.test b/mysql-test/t/ctype_sjis.test index 1d807b5e9a8..01e0b334554 100644 --- a/mysql-test/t/ctype_sjis.test +++ b/mysql-test/t/ctype_sjis.test @@ -78,6 +78,6 @@ SET collation_connection='sjis_bin'; --character_set sjis SET NAMES sjis; -SELECT HEX('²“‘@\Œ\') FROM DUAL; +SELECT HEX('²“‘@Œ\') FROM DUAL; # End of 4.1 tests diff --git a/mysql-test/t/date_formats.test b/mysql-test/t/date_formats.test index 2e1af51efa7..39a530ba733 100644 --- a/mysql-test/t/date_formats.test +++ b/mysql-test/t/date_formats.test @@ -280,3 +280,33 @@ select str_to_date( 1, NULL ); select str_to_date( NULL, 1 ); select str_to_date( 1, IF(1=1,NULL,NULL) ); # End of 4.1 tests + +# +# Bug#11326 +# TIME_FORMAT using "%r" returns wrong hour using 24:00:00 in TIME column +# +# This tests that 24:00:00 does not return PM, when it should be AM. +# Some other values are being tested same time. +# + +SELECT TIME_FORMAT("24:00:00", '%r'); +SELECT TIME_FORMAT("00:00:00", '%r'); +SELECT TIME_FORMAT("12:00:00", '%r'); +SELECT TIME_FORMAT("15:00:00", '%r'); +SELECT TIME_FORMAT("01:00:00", '%r'); +SELECT TIME_FORMAT("25:00:00", '%r'); + +# +# Bug#11324 +# TIME_FORMAT using "%l:%i" returns 36:00 with 24:00:00 in TIME column +# +# This tests that 24:00:00 does not change to "36:00 AM". Testing +# some other values same time. +# + +SELECT TIME_FORMAT("00:00:00", '%l %p'); +SELECT TIME_FORMAT("01:00:00", '%l %p'); +SELECT TIME_FORMAT("12:00:00", '%l %p'); +SELECT TIME_FORMAT("23:00:00", '%l %p'); +SELECT TIME_FORMAT("24:00:00", '%l %p'); +SELECT TIME_FORMAT("25:00:00", '%l %p'); diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def index 288d060b2b5..77ca2e29669 100644 --- a/mysql-test/t/disabled.def +++ b/mysql-test/t/disabled.def @@ -9,13 +9,13 @@ # Do not use any TAB characters for whitespace. # ############################################################################## -events_bugs : BUG#17619 2006-02-21 andrey Race conditions -events_stress : BUG#17619 2006-02-21 andrey Race conditions -events : BUG#17619 2006-02-21 andrey Race conditions -events_scheduling : BUG#19170 2006-04-26 andrey Test case of 19170 fails on some platforms. Has to be checked. +#events_bugs : BUG#17619 2006-02-21 andrey Race conditions +#events_stress : BUG#17619 2006-02-21 andrey Race conditions +#events : BUG#17619 2006-02-21 andrey Race conditions +#events_scheduling : BUG#19170 2006-04-26 andrey Test case of 19170 fails on some platforms. Has to be checked. ndb_autodiscover : BUG#18952 2006-02-16 jmiller Needs to be fixed w.r.t binlog ndb_autodiscover2 : BUG#18952 2006-02-16 jmiller Needs to be fixed w.r.t binlog -ndb_binlog_discover : BUG#19395 2006-04-28 tomas/knielsen mysqld does not always detect cluster shutdown +#ndb_binlog_discover : BUG#19395 2006-04-28 tomas/knielsen mysqld does not always detect cluster shutdown #ndb_cache2 : BUG#18597 2006-03-28 brian simultaneous drop table and ndb statistics update triggers node failure #ndb_cache_multi2 : BUG#18597 2006-04-10 kent simultaneous drop table and ndb statistics update triggers node failure ndb_load : BUG#17233 2006-05-04 tomas failed load data from infile causes mysqld dbug_assert, binlog not flushed @@ -24,18 +24,17 @@ ps_7ndb : BUG#18950 2006-02-16 jmiller create table like does n rpl_ndb_2innodb : BUG#19227 2006-04-20 pekka pk delete apparently not replicated rpl_ndb_2myisam : BUG#19227 2006-04-20 pekka pk delete apparently not replicated rpl_ndb_auto_inc : BUG#17086 2006-02-16 jmiller CR: auto_increment_increment and auto_increment_offset produce duplicate key er -rpl_ndb_commit_afterflush : BUG#19328 2006-05-04 tomas Slave timeout with COM_REGISTER_SLAVE error causing stop +#rpl_ndb_commit_afterflush : BUG#19328 2006-05-04 tomas Slave timeout with COM_REGISTER_SLAVE error causing stop rpl_ndb_dd_partitions : BUG#19259 2006-04-21 rpl_ndb_dd_partitions fails on s/AMD rpl_ndb_ddl : BUG#18946 result file needs update + test needs to checked -rpl_ndb_innodb2ndb : BUG#17400 2006-04-19 tomas Cluster Replication: delete & update of rows in table without pk fails on slave. -rpl_ndb_log : BUG#18947 2006-03-21 tomas CRBR: order in binlog of create table and insert (on different table) not determ -rpl_ndb_myisam2ndb : BUG#17400 2006-04-19 tomas Cluster Replication: delete & update of rows in table without pk fails on slave. +rpl_ndb_innodb2ndb : Bug #19710 Cluster replication to partition table fails on DELETE FROM statement +#rpl_ndb_log : BUG#18947 2006-03-21 tomas CRBR: order in binlog of create table and insert (on different table) not determ +rpl_ndb_myisam2ndb : Bug #19710 Cluster replication to partition table fails on DELETE FROM statement rpl_switch_stm_row_mixed : BUG#18590 2006-03-28 brian rpl_row_blob_innodb : BUG#18980 2006-04-10 kent Test fails randomly rpl_row_func003 : BUG#19074 2006-13-04 andrei test failed rpl_row_inexist_tbl : BUG#18948 2006-03-09 mats Disabled since patch makes this test wait forever rpl_sp : BUG#16456 2006-02-16 jmiller -udf : BUG#18564 2006-03-27 ian (Permission by Brian) # the below testcase have been reworked to avoid the bug, test contains comment, keep bug open #ndb_binlog_ddl_multi : BUG#18976 2006-04-10 kent CRBR: multiple binlog, second binlog may miss schema log events diff --git a/mysql-test/t/distinct.test b/mysql-test/t/distinct.test index 45bd0c7a51c..09f07c2852f 100644 --- a/mysql-test/t/distinct.test +++ b/mysql-test/t/distinct.test @@ -382,3 +382,19 @@ INSERT INTO t1 VALUES select count(distinct x,y) from t1; select count(distinct concat(x,y)) from t1; drop table t1; + +# +# Bug #18068: SELECT DISTINCT +# +CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a,b)); + +INSERT INTO t1 VALUES (1, 101); +INSERT INTO t1 SELECT a + 1, a + 101 FROM t1; +INSERT INTO t1 SELECT a + 2, a + 102 FROM t1; +INSERT INTO t1 SELECT a + 4, a + 104 FROM t1; +INSERT INTO t1 SELECT a + 8, a + 108 FROM t1; + +EXPLAIN SELECT DISTINCT a,a FROM t1 WHERE b < 12 ORDER BY a; +SELECT DISTINCT a,a FROM t1 WHERE b < 12 ORDER BY a; + +DROP TABLE t1; diff --git a/mysql-test/t/events.test b/mysql-test/t/events.test index fbcd4924d56..a3e2bbc0998 100644 --- a/mysql-test/t/events.test +++ b/mysql-test/t/events.test @@ -15,11 +15,10 @@ CREATE EVENT e_x2 ON SCHEDULE EVERY 1 SECOND DO DROP TABLE x_table; connection default; SHOW DATABASES LIKE 'db_x'; SET GLOBAL event_scheduler=1; ---sleep 2 +--sleep 1.5 SHOW DATABASES LIKE 'db_x'; SHOW TABLES FROM db_x; -SET GLOBAL event_scheduler=0; ---sleep 1 +SET GLOBAL event_scheduler=2; connection priv_conn; DROP EVENT e_x1; DROP EVENT e_x2; @@ -31,8 +30,7 @@ USE events_test; # # END: BUG #17289 Events: missing privilege check for drop database # -SET GLOBAL event_scheduler=0; ---sleep 1 +SET GLOBAL event_scheduler=2; drop event if exists event1; create event event1 on schedule every 15 minute starts now() ends date_add(now(), interval 5 hour) DO begin end; alter event event1 rename to event2 enable; @@ -92,11 +90,11 @@ drop event e_43; --echo "Let's check whether we can use non-qualified names" create table non_qualif(a int); create event non_qualif_ev on schedule every 10 minute do insert into non_qualif values (800219); ---sleep 2 +--sleep 1 select * from non_qualif; drop event non_qualif_ev; drop table non_qualif; -set global event_scheduler = 0; +set global event_scheduler = 2; create table t_event3 (a int, b float); drop event if exists event3; @@ -150,9 +148,9 @@ set names cp1251; create event ðóóò21 on schedule every '50:23:59:95' day_second COMMENT 'òîâà å 1251 êîìåíòàð' do select 1; SHOW CREATE EVENT ðóóò21; insert into mysql.event (db, name, body, definer, interval_value, interval_field) values (database(), "root22", "select 1", user(), 100, "SECOND_MICROSECOND"); ---error 1235 +--error ER_NOT_SUPPORTED_YET show create event root22; ---error 1235 +--error ER_NOT_SUPPORTED_YET SHOW EVENTS; drop event root22; drop event root6; @@ -241,82 +239,6 @@ DROP EVENT intact_check; # mysql.event intact checking end # -# -#INFORMATION_SCHEMA.EVENTS test begin -# -create event one_event on schedule every 10 second do select 123; ---replace_column 8 # 9 # -SHOW EVENTS; -SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT from information_schema.events; -CREATE DATABASE events_test2; -CREATE USER ev_test@localhost; -GRANT ALL ON events_test.* to ev_test@localhost; -GRANT ALL on events_test2.* to ev_test@localhost; -REVOKE EVENT ON events_test2.* FROM ev_test@localhost; -REVOKE PROCESS on *.* from ev_test@localhost; -#now we are on con1 -connect (ev_con1,localhost,ev_test,,events_test2); -select "NEW CONNECTION"; -SELECT USER(), DATABASE(); -SHOW GRANTS; - ---echo "Here comes an error:"; -#NO EVENT_ACL on events_test2 ---error 1044 -SHOW EVENTS; -USE events_test; - ---echo "Now the list should be empty:"; ---replace_column 8 # 9 # -SHOW EVENTS; -#now create an event with the same name but we are different user -select concat("Let's create some new events from the name of ",user()); -create event one_event on schedule every 20 second do select 123; -create event two_event on schedule every 20 second on completion not preserve comment "two event" do select 123; -create event three_event on schedule every 20 second on completion preserve comment "three event" do select 123; - ---echo "Now we should see 3 events:"; ---replace_column 8 # 9 # -SHOW EVENTS; - ---echo "This should show us only 3 events:"; ---replace_column 8 # 9 # -SHOW FULL EVENTS; - ---echo "This should show us only 2 events:"; ---replace_column 8 # 9 # -SHOW FULL EVENTS LIKE 't%event'; - ---echo "This should show us no events:"; ---replace_column 8 # 9 # -SHOW FULL EVENTS FROM test LIKE '%'; -#ok, we are back -connection default; -DROP DATABASE events_test2; - ---echo "should see 1 event:"; ---replace_column 8 # 9 # -SHOW EVENTS; - ---echo "we should see 4 events now:"; ---replace_column 8 # 9 # -SHOW FULL EVENTS; -SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT from information_schema.events; - -connection ev_con1; -drop event one_event; -drop event two_event; -drop event three_event; -disconnect ev_con1; -connection default; -drop user ev_test@localhost; -drop event one_event; -# -##INFORMATION_SCHEMA.EVENTS test end -# - ---echo "Sleep a bit so the server closes the second connection" ---sleep 2 create event e_26 on schedule at '2017-01-01 00:00:00' disable do set @a = 5; select db, name, body, definer, convert_tz(execute_at, 'UTC', 'SYSTEM'), on_completion from mysql.event; drop event e_26; @@ -330,21 +252,21 @@ create event задачка on schedule every 123 minute starts now() ends now() drop event задачка; # event_scheduler is a global var ---error 1229 -set event_scheduler=0; -# event_scheduler could be only either 0 or 1 ---error 1231 -set global event_scheduler=2; +--error ER_GLOBAL_VARIABLE +set event_scheduler=2; +# event_scheduler could be only either 1 or 2 +--error ER_WRONG_VALUE_FOR_VAR +set global event_scheduler=3; --echo "DISABLE the scheduler. Testing that it does not work when the variable is 0" -set global event_scheduler=0; +set global event_scheduler=2; select definer, name, db from mysql.event; select get_lock("test_lock1", 20); create event закачка on schedule every 10 hour do select get_lock("test_lock1", 20); --echo "Should return 1 row" select definer, name, db from mysql.event; ---echo "Should be 0 processes" +--echo "Should be only 1 process" select /*1*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; select release_lock("test_lock1"); drop event закачка; @@ -360,9 +282,9 @@ select get_lock("test_lock2", 20); --echo "Create an event which tries to acquire a mutex. The event locks on the mutex" create event закачка on schedule every 10 hour do select get_lock("test_lock2", 20); --echo "Let some time pass to the event starts" ---sleep 2 +--sleep 1 --echo "Should have only 2 processes: the scheduler and the locked event" -select /*1*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; +select /*2*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;--echo "Release the mutex, the event worker should finish." --echo "Release the mutex, the event worker should finish." select release_lock("test_lock2"); drop event закачка; @@ -379,18 +301,11 @@ set global event_scheduler=1; select get_lock("test_lock2_1", 20); create event закачка21 on schedule every 10 hour do select get_lock("test_lock2_1", 20); --sleep 1 ---echo "Should see 1 process, locked on get_lock(" -#select /*3*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; ---echo "Shutting down the scheduler, it should wait for the running event" -set global event_scheduler=0; ---sleep 1 ---echo "Should have only 2 processes: the scheduler and the locked event" +--echo "Should have only 3 processes: the scheduler, our conn and the locked event" +select /*3*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; +set global event_scheduler=2; +--echo "Should have only our process now:" select /*4*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; ---echo "Release the lock so the child process should finish. Hence the scheduler also" -select release_lock("test_lock2_1"); ---sleep 1 ---echo "Should see 0 processes now:" -select /*5*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; drop event закачка21; #### @@ -426,7 +341,7 @@ drop event white_space; # END: BUG #17453: Creating Event crash the server # -##set global event_scheduler=1; +# # Bug#17403 "Events: packets out of order with show create event" # create event e1 on schedule every 1 year do set @a = 5; @@ -440,7 +355,7 @@ drop event e1; ##select get_lock("test_lock3", 20); ##create event закачка on schedule every 10 hour do select get_lock("test_lock3", 20); ##select sleep(2); -##show processlist; +##select /*5*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; ##drop event закачка; ##select release_lock("test_lock3"); @@ -450,14 +365,14 @@ drop event e1; ##select get_lock("test_lock4", 20); ##create event закачка4 on schedule every 1 second do select get_lock("test_lock4", 20); ##select sleep(3); -##--replace_column 1 # 6 # +##select /*6*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; ##drop event закачка4; ##select release_lock("test_lock4"); -##set global event_scheduler=0; +##set global event_scheduler=2; ##select sleep(2); ##--replace_column 1 # 6 # +##show processlist; ##select count(*) from mysql.event; drop database events_test; - diff --git a/mysql-test/t/events_bugs.test b/mysql-test/t/events_bugs.test index 3f339ff0398..e3b79a6bd13 100644 --- a/mysql-test/t/events_bugs.test +++ b/mysql-test/t/events_bugs.test @@ -30,13 +30,13 @@ set @a=3; CREATE PROCEDURE p_16 () CREATE EVENT e_16 ON SCHEDULE EVERY @a SECOND DO SET @a=5; call p_16(); --echo "Here we used to crash!" ---error 1516 +--error ER_EVENT_ALREADY_EXISTS call p_16(); ---error 1516 +--error ER_EVENT_ALREADY_EXISTS call p_16(); DROP EVENT e_16; CALL p_16(); ---error 1516 +--error ER_EVENT_ALREADY_EXISTS CALL p_16(); DROP PROCEDURE p_16; DROP EVENT e_16; @@ -47,9 +47,9 @@ DROP EVENT e_16; # # Start - 16396: Events: Distant-future dates become past dates # ---error 1504 +--error ER_WRONG_VALUE create event e_55 on schedule at 99990101000000 do drop table t; ---error 1504 +--error ER_WRONG_VALUE create event e_55 on schedule every 10 hour starts 99990101000000 do drop table t; --error ER_EVENT_ENDS_BEFORE_STARTS create event e_55 on schedule every 10 minute ends 99990101000000 do drop table t; @@ -60,7 +60,7 @@ create event e_55 on schedule every 10 minute ends 99990101000000 do drop table # # Start - 16407: Events: Changes in sql_mode won't be taken into account # -set global event_scheduler=0; +set global event_scheduler=2; --echo "Wait a bit to settle down" --sleep 1 delete from mysql.event; @@ -79,7 +79,7 @@ delimiter ;| --echo "Now if everything is fine the event has compiled and is locked select /*1*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; select release_lock('test_bug16407'); -set global event_scheduler= 0; +set global event_scheduler= 2; select event_schema, event_name, sql_mode from information_schema.events order by event_schema, event_name; --echo "Let's check whether we change the sql_mode on ALTER EVENT" set sql_mode='traditional'; @@ -121,9 +121,9 @@ set global event_scheduler= 1; --sleep 1 select /*2*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; select release_lock('ee_16407_2'); ---sleep 3 +--sleep 2 select /*3*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; -set global event_scheduler= 0; +set global event_scheduler= 2; select * from events_smode_test order by ev_name, a; --echo "OK, last check before we drop them" select event_schema, event_name, sql_mode from information_schema.events order by event_schema, event_name; @@ -156,7 +156,7 @@ set global event_scheduler= 1; --echo "Should have 2 locked processes" select /*4*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; select release_lock('ee_16407_5'); ---sleep 3 +--sleep 2 --echo "Should have 0 processes locked" select /*5*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; select * from events_smode_test order by ev_name, a; @@ -166,7 +166,7 @@ drop event ee_16407_5; drop event ee_16407_6; drop procedure ee_16407_5_pendant; drop procedure ee_16407_6_pendant; -set global event_scheduler= 0; +set global event_scheduler= 2; drop table events_smode_test; set sql_mode=@old_sql_mode; # diff --git a/mysql-test/t/events_grant.test b/mysql-test/t/events_grant.test new file mode 100644 index 00000000000..ba94944a3cf --- /dev/null +++ b/mysql-test/t/events_grant.test @@ -0,0 +1,105 @@ +CREATE DATABASE IF NOT EXISTS events_test; +use events_test; +# +# Events grants test begin +# +CREATE EVENT one_event ON SCHEDULE EVERY 10 SECOND DO SELECT 123; +--replace_column 8 # 9 # +SHOW EVENTS; +SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT from information_schema.events; +CREATE DATABASE events_test2; +CREATE USER ev_test@localhost; +GRANT ALL ON events_test.* to ev_test@localhost; +GRANT ALL ON events_test2.* to ev_test@localhost; +REVOKE EVENT ON events_test2.* FROM ev_test@localhost; +#now we are on con1 +connect (ev_con1,localhost,ev_test,,events_test2); +select "NEW CONNECTION"; +SELECT USER(), DATABASE(); +SHOW GRANTS; +--echo "Here comes an error:"; +#NO EVENT_ACL on events_test2 +--error 1044 +SHOW EVENTS; +USE events_test; +--echo "We should see one event"; +--replace_column 8 # 9 # +SHOW EVENTS; +#now create an event with the same name but we are different user +SELECT CONCAT("Let's create some new events from the name of ", USER()); +--error ER_EVENT_ALREADY_EXISTS +CREATE EVENT one_event ON SCHEDULE EVERY 20 SECOND DO SELECT 123; +CREATE EVENT two_event ON SCHEDULE EVERY 20 SECOND ON COMPLETION NOT PRESERVE COMMENT "two event" DO SELECT 123; +CREATE EVENT three_event ON SCHEDULE EVERY 20 SECOND ON COMPLETION PRESERVE COMMENT "three event" DO SELECT 123; + +--echo "Now we should see 3 events:"; +--replace_column 8 # 9 # +SHOW EVENTS; + +--echo "This should show us only 2 events:"; +--replace_column 8 # 9 # +SHOW EVENTS LIKE 't%event'; + +--echo "This should show us no events:"; +--replace_column 8 # 9 # +SHOW EVENTS FROM test LIKE '%'; +#ok, we are back +connection default; +GRANT EVENT ON events_test2.* TO ev_test@localhost; +connection ev_con1; +USE events_test2; +CREATE EVENT four_event ON SCHEDULE EVERY 20 SECOND DO SELECT 42; +connection default; +USE events_test; +--echo "We should see 4 events : one_event, two_event, three_event & four_event" +SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS; +DROP DATABASE events_test2; +--echo "We should see 3 events : one_event, two_event, three_event" +SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS; + +connection default; +CREATE DATABASE events_test2; +USE events_test2; +CREATE EVENT five_event ON SCHEDULE EVERY 20 SECOND DO SELECT 42; + +connection ev_con1; +--echo "Should see 4 events - one, two, three & five" +SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS; +connection default; +REVOKE EVENT ON events_test2.* FROM ev_test@localhost; +connection ev_con1; +USE test; +--echo "Should see 3 events - one, two & three" +SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS; +--echo "Let's test ALTER EVENT which changes the definer" +USE events_test; +ALTER EVENT one_event ON SCHEDULE EVERY 10 SECOND; +--echo "The definer should be ev_test@localhost" +SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_NAME='one_event'; +connection default; +USE events_test; +ALTER EVENT one_event COMMENT "comment"; +connection ev_con1; +--echo "The definer should be root@localhost" +SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_NAME='one_event'; +ALTER EVENT one_event DO SELECT 12; +--echo "The definer should be ev_test@localhost" +SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_NAME='one_event'; +connection default; +--echo "make the definer again root@localhost" +ALTER EVENT one_event COMMENT "new comment"; +connection ev_con1; +--echo "test DROP by another user" +DROP EVENT one_event; +connection default; +--echo "One event should not be there" +SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS; +disconnect ev_con1; +connection default; +DROP USER ev_test@localhost; +DROP DATABASE events_test2; +# +## EVENTS grants test end +# + +DROP DATABASE events_test; diff --git a/mysql-test/t/events_logs_tests.test b/mysql-test/t/events_logs_tests.test index 21adc17d5b8..6d3b3292630 100644 --- a/mysql-test/t/events_logs_tests.test +++ b/mysql-test/t/events_logs_tests.test @@ -10,19 +10,21 @@ BEGIN END| delimiter ;| --echo "Check General Query Log" -SET GLOBAL event_scheduler=0; +SET GLOBAL event_scheduler=2; create event log_general on schedule every 1 minute do SELect 'alabala', sleep(3) from dual; TRUNCATE mysql.general_log; --echo "1 row, the current statement!" +--replace_column 1 USER_HOST call select_general_log(); SET GLOBAL event_scheduler=1; --echo "Wait the scheduler to start" --echo "Should see 3 rows - the 'SELect' is in the middle. The other two are selects from general_log" --sleep 2 +--replace_column 1 USER_HOST call select_general_log(); DROP PROCEDURE select_general_log; DROP EVENT log_general; -SET GLOBAL event_scheduler=0; +SET GLOBAL event_scheduler=2; --sleep 1 --echo "Check slow query log" @@ -50,13 +52,14 @@ SET @old_session_long_query_time:=@@long_query_time; SHOW VARIABLES LIKE 'log_slow_queries'; DROP FUNCTION get_value; TRUNCATE mysql.slow_log; +--replace_column 1 USER_HOST SELECT user_host, query_time, db, sql_text FROM mysql.slow_log; --echo "Set new values" SET GLOBAL long_query_time=4; -SET SESSION long_query_time=2; +SET SESSION long_query_time=1; --echo "Check that logging is working" -SELECT SLEEP(3); ---replace_regex /00:00:0[3-5]/SLEEPVAL/ +SELECT SLEEP(2); +--replace_column 1 USER_HOST 2 SLEEPVAL SELECT user_host, query_time, db, sql_text FROM mysql.slow_log; TRUNCATE mysql.slow_log; CREATE TABLE slow_event_test (slo_val tinyint, val tinyint); @@ -73,14 +76,15 @@ SELECT * FROM slow_event_test; SELECT user_host, query_time, db, sql_text FROM mysql.slow_log; --echo "This should go to the slow log" SET SESSION long_query_time=10; +SET GLOBAL long_query_time=1; DROP EVENT long_event; -CREATE EVENT long_event2 ON SCHEDULE EVERY 1 MINUTE DO INSERT INTO slow_event_test SELECT @@long_query_time, SLEEP(5); +CREATE EVENT long_event2 ON SCHEDULE EVERY 1 MINUTE DO INSERT INTO slow_event_test SELECT @@long_query_time, SLEEP(2); --echo "Sleep some more time than the actual event run will take" ---sleep 7 +--sleep 3 --echo "Check our table. Should see 2 rows" SELECT * FROM slow_event_test; ---echo "Check slow log. Should see 1 row because 5 is over the threshold of 4 for GLOBAL, though under SESSION which is 10" ---replace_regex /00:00:0[5-7]/SLEEPVAL/ +--echo "Check slow log. Should see 1 row because 4 is over the threshold of 3 for GLOBAL, though under SESSION which is 10" +--replace_column 1 USER_HOST 2 SLEEPVAL SELECT user_host, query_time, db, sql_text FROM mysql.slow_log; DROP EVENT long_event2; SET GLOBAL long_query_time =@old_global_long_query_time; diff --git a/mysql-test/t/events_microsec.test b/mysql-test/t/events_microsec.test index 34855fdadff..e01120a0756 100644 --- a/mysql-test/t/events_microsec.test +++ b/mysql-test/t/events_microsec.test @@ -1,55 +1,15 @@ create database if not exists events_test; use events_test; ---error 1235 +--error ER_NOT_SUPPORTED_YET CREATE EVENT micro_test ON SCHEDULE EVERY 100 MICROSECOND DO SELECT 1; ---error 1235 +--error ER_NOT_SUPPORTED_YET CREATE EVENT micro_test ON SCHEDULE EVERY 100 DAY_MICROSECOND DO SELECT 1; ---error 1235 +--error ER_NOT_SUPPORTED_YET CREATE EVENT micro_test ON SCHEDULE EVERY 100 HOUR_MICROSECOND DO SELECT 1; ---error 1235 +--error ER_NOT_SUPPORTED_YET CREATE EVENT micro_test ON SCHEDULE EVERY 100 MINUTE_MICROSECOND DO SELECT 1; ---error 1235 +--error ER_NOT_SUPPORTED_YET CREATE EVENT micro_test ON SCHEDULE EVERY 100 SECOND_MICROSECOND DO SELECT 1; ---echo "Now create normal event and change it on SQL level" -CREATE EVENT micro_test2 ON SCHEDULE EVERY 1 MONTH DO SELECT 1; -UPDATE mysql.event SET interval_field='MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; ---error 1235 -SHOW CREATE EVENT micro_test2; -SET GLOBAL event_scheduler=0; ---sleep 1 ---echo "Should not be running:" -SHOW VARIABLES like 'event_scheduler'; -UPDATE mysql.event SET interval_field='DAY_MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; ---error 1235 -SHOW CREATE EVENT micro_test2; -SET GLOBAL event_scheduler=0; ---sleep 1 ---echo "Should not be running:" -SHOW VARIABLES like 'event_scheduler'; -UPDATE mysql.event SET interval_field='SECOND_MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; ---error 1235 -SHOW CREATE EVENT micro_test2; -SET GLOBAL event_scheduler=0; ---sleep 1 ---echo "Should not be running:" -SHOW VARIABLES like 'event_scheduler'; -UPDATE mysql.event SET interval_field='HOUR_MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; ---error 1235 -SHOW CREATE EVENT micro_test2; -SET GLOBAL event_scheduler=0; ---sleep 1 ---echo "Should not be running:" -SHOW VARIABLES like 'event_scheduler'; -UPDATE mysql.event SET interval_field='MINUTE_MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; ---error 1235 -SHOW CREATE EVENT micro_test2; -SET GLOBAL event_scheduler=0; ---sleep 1 ---echo "Should not be running:" -SHOW VARIABLES like 'event_scheduler'; -SELECT COUNT(*) FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER='event_scheduler'; -DROP EVENT micro_test2; - drop database events_test; diff --git a/mysql-test/t/events_scheduling.test b/mysql-test/t/events_scheduling.test index ae3cc7d5fac..a73d25cd8ee 100644 --- a/mysql-test/t/events_scheduling.test +++ b/mysql-test/t/events_scheduling.test @@ -15,7 +15,7 @@ CREATE EVENT start_n_end DO INSERT INTO table_2 VALUES(1); --sleep 5 CREATE EVENT only_one_time ON SCHEDULE EVERY 2 SECOND ENDS NOW() + INTERVAL 1 SECOND DO INSERT INTO table_3 VALUES(1); -CREATE EVENT two_time ON SCHEDULE EVERY 1 SECOND ENDS NOW() + INTERVAL 1 SECOND DO INSERT INTO table_4 VALUES(1); +CREATE EVENT two_time ON SCHEDULE EVERY 1 SECOND ENDS NOW() + INTERVAL 1 SECOND ON COMPLETION PRESERVE DO INSERT INTO table_4 VALUES(1); --sleep 5 SELECT IF(SUM(a) >= 4, 'OK', 'ERROR') FROM table_1; SELECT IF(SUM(a) >= 5, 'OK', 'ERROR') FROM table_2; @@ -28,8 +28,8 @@ DROP EVENT start_n_end; --echo "Already dropped because ended. Therefore an error." --error ER_EVENT_DOES_NOT_EXIST DROP EVENT only_one_time; ---echo "Already dropped because ended. Therefore an error." ---error ER_EVENT_DOES_NOT_EXIST +--echo "Should be preserved" +SELECT EVENT_NAME, STATUS FROM INFORMATION_SCHEMA.EVENTS; DROP EVENT two_time; DROP TABLE table_1; DROP TABLE table_2; diff --git a/mysql-test/t/events_stress.test b/mysql-test/t/events_stress.test index f6eed79425c..8d0034c232e 100644 --- a/mysql-test/t/events_stress.test +++ b/mysql-test/t/events_stress.test @@ -2,78 +2,124 @@ CREATE DATABASE IF NOT EXISTS events_test; # # DROP DATABASE test start (bug #16406) # -CREATE DATABASE events_test2; -USE events_test2; +CREATE DATABASE events_conn1_test2; +CREATE TABLE events_test.fill_it(test_name varchar(20), occur datetime); +CREATE USER event_user2@localhost; +CREATE DATABASE events_conn2_db; +GRANT ALL ON *.* TO event_user2@localhost; +CREATE USER event_user3@localhost; +CREATE DATABASE events_conn3_db; +GRANT ALL ON *.* TO event_user3@localhost; +connect (conn2,localhost,event_user2,,events_conn2_db); +--echo "In the second connection we create some events which won't be dropped till the end" +--disable_query_log +let $1= 50; +while ($1) +{ + eval CREATE EVENT conn2_ev$1 ON SCHEDULE EVERY 1 SECOND DO INSERT INTO events_test.fill_it VALUES("conn2_ev$1", NOW()); + dec $1; +} +--enable_query_log +connect (conn3,localhost,event_user3,,events_conn3_db); +--echo "In the second connection we create some events which won't be dropped till the end" +--disable_query_log +let $1= 50; +while ($1) +{ + eval CREATE EVENT conn3_ev$1 ON SCHEDULE EVERY 1 SECOND DO INSERT INTO events_test.fill_it VALUES("conn3_ev$1", NOW()); + dec $1; +} +--enable_query_log +connection default; +USE events_conn1_test2; CREATE EVENT ev_drop1 ON SCHEDULE EVERY 10 MINUTE DISABLE DO SELECT 1; CREATE EVENT ev_drop2 ON SCHEDULE EVERY 10 MINUTE DISABLE DO SELECT 1; CREATE EVENT ev_drop3 ON SCHEDULE EVERY 10 MINUTE DISABLE DO SELECT 1; USE events_test; -SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_test2'; -DROP DATABASE events_test2; -SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_test2'; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2'; +DROP DATABASE events_conn1_test2; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2'; --echo "Now testing stability - dropping db -> events while they are running" -CREATE DATABASE events_test2; -USE events_test2; +CREATE DATABASE events_conn1_test2; +USE events_conn1_test2; --disable_query_log -let $1= 1000; +let $1= 50; while ($1) { - eval CREATE EVENT ev_drop$1 ON SCHEDULE EVERY 1 SECOND DO SELECT $1; + eval CREATE EVENT conn1_round1_ev$1 ON SCHEDULE EVERY 1 SECOND DO INSERT INTO events_test.fill_it VALUES("conn1_round1_ev$1", NOW()); dec $1; } --enable_query_log -SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_test2'; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2'; SET GLOBAL event_scheduler=1; ---sleep 4 -DROP DATABASE events_test2; +--sleep 6 +DROP DATABASE events_conn1_test2; -SET GLOBAL event_scheduler=0; ---sleep 2 -SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_test2'; -CREATE DATABASE events_test3; -USE events_test3; +SET GLOBAL event_scheduler=2; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2'; +CREATE DATABASE events_conn1_test3; +USE events_conn1_test3; --disable_query_log -let $1= 950; +let $1= 50; while ($1) { - eval CREATE EVENT ev_drop$1 ON SCHEDULE EVERY 1 SECOND DO SELECT $1; + eval CREATE EVENT conn1_round2_ev$1 ON SCHEDULE EVERY 1 SECOND DO INSERT INTO events_test.fill_it VALUES("conn1_round2_ev$1", NOW()); dec $1; } --enable_query_log -SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_test3'; ---sleep 3 -CREATE DATABASE events_test4; -USE events_test4; +SET GLOBAL event_scheduler=1; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test3'; +CREATE DATABASE events_conn1_test4; +USE events_conn1_test4; --disable_query_log -let $1= 860; +let $1= 50; while ($1) { - eval CREATE EVENT ev_drop$1 ON SCHEDULE EVERY 1 SECOND DO SELECT $1; + eval CREATE EVENT conn1_round3_ev$1 ON SCHEDULE EVERY 1 SECOND DO INSERT INTO events_test.fill_it VALUES("conn1_round3_ev$1", NOW()); dec $1; } --enable_query_log - -CREATE DATABASE events_test2; -USE events_test2; +CREATE DATABASE events_conn1_test2; +USE events_conn1_test2; --disable_query_log -let $1= 1050; +let $1= 50; while ($1) { - eval CREATE EVENT ev_drop$1 ON SCHEDULE EVERY 1 SECOND DO SELECT $1; + eval CREATE EVENT ev_round4_drop$1 ON SCHEDULE EVERY 1 SECOND DO INSERT INTO events_test.fill_it VALUES("conn1_round4_ev$1", NOW()); dec $1; } --enable_query_log -SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_test2'; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2'; --sleep 6 -DROP DATABASE events_test2; -SET GLOBAL event_scheduler=0; -DROP DATABASE events_test3; -SET GLOBAL event_scheduler=1; -DROP DATABASE events_test4; +connection conn2; +--send +DROP DATABASE events_conn2_db; +connection conn3; +--send +DROP DATABASE events_conn3_db; +connection default; +--send +DROP DATABASE events_conn1_test2; +DROP DATABASE events_conn1_test3; +SET GLOBAL event_scheduler=2; +DROP DATABASE events_conn1_test4; SET GLOBAL event_scheduler=1; +connection conn2; +reap; +disconnect conn2; +connection conn3; +reap; +disconnect conn3; +connection default; USE events_test; +DROP TABLE fill_it; +--disable_query_log +DROP USER event_user2@localhost; +DROP USER event_user3@localhost; +--enable_query_log # # DROP DATABASE test end (bug #16406) # diff --git a/mysql-test/t/explain.test b/mysql-test/t/explain.test index 2a3a23c5f96..a38771db233 100644 --- a/mysql-test/t/explain.test +++ b/mysql-test/t/explain.test @@ -43,3 +43,12 @@ drop table ÔÁÂ; set names latin1; # End of 4.1 tests + + +# +# Bug#15463: EXPLAIN SELECT..INTO hangs the client (QB, command line) +# +select 3 into @v1; +explain select 3 into @v1; + +# End of 5.0 tests. diff --git a/mysql-test/t/flush.test b/mysql-test/t/flush.test index f5fd9fcadf2..95ba633fefd 100644 --- a/mysql-test/t/flush.test +++ b/mysql-test/t/flush.test @@ -102,3 +102,43 @@ unlock tables; drop table t1, t2, t3; # End of 4.1 tests + +# +# Test of deadlock problem when doing FLUSH TABLE with read lock +# (Bug was in NTPL threads in Linux when using different mutex while +# waiting for a condtion variable) + +create table t1 (c1 int); +create table t2 (c1 int); + +connect (con1,localhost,root,,); +connect (con3,localhost,root,,); + +connection con1; +lock table t1 write; + +connection con2; +send flush tables with read lock; +--sleep 1 + +connection con3; +send insert into t2 values(1); +--sleep 1 + +connection con1; +unlock tables; +disconnect con1; + +connection con2; +reap; +disconnect con2; + +connection con3; +# It hangs here (insert into t2 does not end). +reap; +disconnect con3; + +connection default; +drop table t1, t2; + +# End of 5.0 tests diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test index c667f90940c..fb9470c16dd 100644 --- a/mysql-test/t/func_group.test +++ b/mysql-test/t/func_group.test @@ -539,77 +539,6 @@ INSERT INTO t1 VALUES SELECT MAX(id) FROM t1 WHERE id < 3 AND a=2 AND b=6; DROP TABLE t1; -# -# Bug #12882 min/max inconsistent on empty table -# - ---disable_warnings -create table t1m (a int) engine=myisam; -create table t1i (a int) engine=innodb; -create table t2m (a int) engine=myisam; -create table t2i (a int) engine=innodb; ---enable_warnings -insert into t2m values (5); -insert into t2i values (5); - -# test with MyISAM -select min(a) from t1m; -select min(7) from t1m; -select min(7) from DUAL; -explain select min(7) from t2m join t1m; -select min(7) from t2m join t1m; - -select max(a) from t1m; -select max(7) from t1m; -select max(7) from DUAL; -explain select max(7) from t2m join t1m; -select max(7) from t2m join t1m; - -select 1, min(a) from t1m where a=99; -select 1, min(a) from t1m where 1=99; -select 1, min(1) from t1m where a=99; -select 1, min(1) from t1m where 1=99; - -select 1, max(a) from t1m where a=99; -select 1, max(a) from t1m where 1=99; -select 1, max(1) from t1m where a=99; -select 1, max(1) from t1m where 1=99; - -# test with InnoDB -select min(a) from t1i; -select min(7) from t1i; -select min(7) from DUAL; -explain select min(7) from t2i join t1i; -select min(7) from t2i join t1i; - -select max(a) from t1i; -select max(7) from t1i; -select max(7) from DUAL; -explain select max(7) from t2i join t1i; -select max(7) from t2i join t1i; - -select 1, min(a) from t1i where a=99; -select 1, min(a) from t1i where 1=99; -select 1, min(1) from t1i where a=99; -select 1, min(1) from t1i where 1=99; - -select 1, max(a) from t1i where a=99; -select 1, max(a) from t1i where 1=99; -select 1, max(1) from t1i where a=99; -select 1, max(1) from t1i where 1=99; - -# mixed MyISAM/InnoDB test -explain select count(*), min(7), max(7) from t1m, t1i; -select count(*), min(7), max(7) from t1m, t1i; - -explain select count(*), min(7), max(7) from t1m, t2i; -select count(*), min(7), max(7) from t1m, t2i; - -explain select count(*), min(7), max(7) from t2m, t1i; -select count(*), min(7), max(7) from t2m, t1i; - -drop table t1m, t1i, t2m, t2i; - # End of 4.1 tests # diff --git a/mysql-test/t/func_in.test b/mysql-test/t/func_in.test index 351d1fc2c92..8ddf1fbe314 100644 --- a/mysql-test/t/func_in.test +++ b/mysql-test/t/func_in.test @@ -220,3 +220,15 @@ set @str=NULL; drop table t2; drop table t1; +# BUG#19618: Crash in range optimizer for +# "unsigned_keypart NOT IN(negative_number,...)" +# (introduced in fix BUG#15872) +create table t1 ( + some_id smallint(5) unsigned, + key (some_id) +); +insert into t1 values (1),(2); +select some_id from t1 where some_id not in(2,-1); +select some_id from t1 where some_id not in(-4,-1,-4); +select some_id from t1 where some_id not in(-4,-1,3423534,2342342); +drop table t1; diff --git a/mysql-test/t/func_misc.test b/mysql-test/t/func_misc.test index 4a618a56483..0475dd4bdb6 100644 --- a/mysql-test/t/func_misc.test +++ b/mysql-test/t/func_misc.test @@ -38,6 +38,46 @@ select a from t1 where mid(a+0,6,3) = ( mid(20040106123400,6,3) ); drop table t1; + +# +# Bug#16501: IS_USED_LOCK does not appear to work +# +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (conn CHAR(7), connection_id INT); +INSERT INTO t1 VALUES ('default', CONNECTION_ID()); + +SELECT GET_LOCK('bug16501',600); + +connect (con1,localhost,root,,); +INSERT INTO t1 VALUES ('con1', CONNECTION_ID()); +SELECT IS_USED_LOCK('bug16501') = connection_id +FROM t1 +WHERE conn = 'default'; +send SELECT GET_LOCK('bug16501',600); + +connection default; +SELECT IS_USED_LOCK('bug16501') = CONNECTION_ID(); +SELECT RELEASE_LOCK('bug16501'); +connection con1; +reap; +connection default; +SELECT IS_USED_LOCK('bug16501') = connection_id +FROM t1 +WHERE conn = 'con1'; + +connection con1; +SELECT IS_USED_LOCK('bug16501') = CONNECTION_ID(); +SELECT RELEASE_LOCK('bug16501'); +SELECT IS_USED_LOCK('bug16501'); + +disconnect con1; +connection default; + +DROP TABLE t1; + # End of 4.1 tests # diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index 85cedee0f4a..7f809dbc4a1 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -666,7 +666,14 @@ select rpad(i, 7, ' ') as t from t1; --disable_metadata drop table t1; -# End of 4.1 tests +# +# Bug #10418: LOAD_FILE does not behave like in manual if file does not exist +# + +select load_file("lkjlkj"); +select ifnull(load_file("lkjlkj"),"it's null"); + +--echo End of 4.1 tests # # Bug #13361: SELECT FORMAT(<decimal field with null>, 2) crashes @@ -691,4 +698,10 @@ select cast(rtrim(' 20.06 ') as decimal(19,2)); select cast(ltrim(' 20.06 ') as decimal(19,2)); select cast(rtrim(ltrim(' 20.06 ')) as decimal(19,2)); +# +# Bug #13975: "same string" + 0 has 2 different results +# +select conv("18383815659218730760",10,10) + 0; +select "18383815659218730760" + 0; + --echo End of 5.0 tests diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index 229b24c73ca..e6c1ddfcf1f 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -352,12 +352,6 @@ INSERT INTO t1 VALUES (NOW()); SELECT count(*) FROM t1 WHERE d>FROM_DAYS(TO_DAYS(@TMP)) AND d<=FROM_DAYS(TO_DAYS(@TMP)+1); DROP TABLE t1; - -# End of 4.1 tests - -explain extended select timestampdiff(SQL_TSI_WEEK, '2001-02-01', '2001-05-01') as a1, - timestampdiff(SQL_TSI_FRAC_SECOND, '2001-02-01 12:59:59.120000', '2001-05-01 12:58:58.119999') as a2; - # # Bug #10568 # @@ -367,6 +361,18 @@ select last_day('2005-00-01'); select last_day('2005-01-00'); # +# Bug #18501: monthname and NULLs +# + +select monthname(str_to_date(null, '%m')), monthname(str_to_date(null, '%m')), + monthname(str_to_date(1, '%m')), monthname(str_to_date(0, '%m')); + +--echo End of 4.1 tests + +explain extended select timestampdiff(SQL_TSI_WEEK, '2001-02-01', '2001-05-01') as a1, + timestampdiff(SQL_TSI_FRAC_SECOND, '2001-02-01 12:59:59.120000', '2001-05-01 12:58:58.119999') as a2; + +# # Bug #10590: %h, %I, and %l format specifies should all return results in # the 0-11 range # @@ -469,4 +475,23 @@ SELECT * FROM t1, t2 DROP TABLE t1,t2; -# End of 5.0 tests +--echo End of 5.0 tests + +# +# Bug #18997 +# + +select date_sub("0050-01-01 00:00:01",INTERVAL 2 SECOND); +select date_sub("0199-01-01 00:00:01",INTERVAL 2 SECOND); +select date_add("0199-12-31 23:59:59",INTERVAL 2 SECOND); +select date_sub("0200-01-01 00:00:01",INTERVAL 2 SECOND); +select date_sub("0200-01-01 00:00:01",INTERVAL 1 SECOND); +select date_sub("0200-01-01 00:00:01",INTERVAL 2 SECOND); +select date_add("2001-01-01 23:59:59",INTERVAL -2000 YEAR); +select date_sub("50-01-01 00:00:01",INTERVAL 2 SECOND); +select date_sub("90-01-01 00:00:01",INTERVAL 2 SECOND); +select date_sub("0069-01-01 00:00:01",INTERVAL 2 SECOND); +select date_sub("0169-01-01 00:00:01",INTERVAL 2 SECOND); + + +--echo End of 5.1 tests diff --git a/mysql-test/t/grant.test b/mysql-test/t/grant.test index 97f13381557..3db38d93ee1 100644 --- a/mysql-test/t/grant.test +++ b/mysql-test/t/grant.test @@ -302,7 +302,7 @@ DROP DATABASE testdb10; create table t1(a int, b int, c int, d int); grant insert(b), insert(c), insert(d), insert(a) on t1 to grant_user@localhost; show grants for grant_user@localhost; -select Host,Db,User,Table_name,Column_name,Column_priv from mysql.columns_priv; +select Host,Db,User,Table_name,Column_name,Column_priv from mysql.columns_priv order by Column_name; revoke ALL PRIVILEGES on t1 from grant_user@localhost; show grants for grant_user@localhost; select Host,Db,User,Table_name,Column_name,Column_priv from mysql.columns_priv; @@ -326,7 +326,18 @@ grant select (c) on mysqltest_2.t1 to mysqltest_3@localhost; grant update (d) on mysqltest_2.t2 to mysqltest_3@localhost; connect (conn1,localhost,mysqltest_3,,); connection conn1; -show grants for mysqltest_3@localhost; +SELECT * FROM INFORMATION_SCHEMA.COLUMN_PRIVILEGES + WHERE GRANTEE = '''mysqltest_3''@''localhost''' + ORDER BY TABLE_NAME,COLUMN_NAME,PRIVILEGE_TYPE; +SELECT * FROM INFORMATION_SCHEMA.TABLE_PRIVILEGES + WHERE GRANTEE = '''mysqltest_3''@''localhost''' + ORDER BY TABLE_NAME,PRIVILEGE_TYPE; +SELECT * from INFORMATION_SCHEMA.SCHEMA_PRIVILEGES + WHERE GRANTEE = '''mysqltest_3''@''localhost''' + ORDER BY TABLE_SCHEMA,PRIVILEGE_TYPE; +SELECT * from INFORMATION_SCHEMA.USER_PRIVILEGES + WHERE GRANTEE = '''mysqltest_3''@''localhost''' + ORDER BY TABLE_CATALOG,PRIVILEGE_TYPE; --error 1143 update mysqltest_1.t1, mysqltest_1.t2 set q=10 where b=1; --error 1143 diff --git a/mysql-test/t/group_min_max.test b/mysql-test/t/group_min_max.test index bff07366ec2..874f3cd1a80 100644 --- a/mysql-test/t/group_min_max.test +++ b/mysql-test/t/group_min_max.test @@ -659,59 +659,7 @@ select a1 from t1 where a2 = 'b' group by a1; explain select distinct a1 from t1 where a2 = 'b'; select distinct a1 from t1 where a2 = 'b'; -# -# Bug #12672: primary key implcitly included in every innodb index -# - ---disable_warnings -create table t4 ( - pk_col int auto_increment primary key, a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' ' -) engine=innodb; ---enable_warnings -insert into t4 (a1, a2, b, c, d, dummy) select * from t1; - -create index idx12672_0 on t4 (a1); -create index idx12672_1 on t4 (a1,a2,b,c); -create index idx12672_2 on t4 (a1,a2,b); -analyze table t1; - -select distinct a1 from t4 where pk_col not in (1,2,3,4); - -drop table t1,t2,t3,t4; - -# -# Bug #6142: a problem with the empty innodb table -# - ---disable_warnings -create table t1 ( - a varchar(30), b varchar(30), primary key(a), key(b) -) engine=innodb; ---enable_warnings -select distinct a from t1; -drop table t1; - -# -# Bug #9798: group by with rollup -# - ---disable_warnings -create table t1(a int, key(a)) engine=innodb; ---enable_warnings -insert into t1 values(1); -select a, count(a) from t1 group by a with rollup; -drop table t1; - -# -# Bug #13293 Wrongly used index results in endless loop. -# -create table t1 (f1 int, f2 char(1), primary key(f1,f2)) engine=innodb; -insert into t1 values ( 1,"e"),(2,"a"),( 3,"c"),(4,"d"); -alter table t1 drop primary key, add primary key (f2, f1); -explain select distinct f1 a, f1 b from t1; -explain select distinct f1, f2 from t1; -drop table t1; - +drop table t1,t2,t3; # # Bug #14920 Ordering aggregated result sets with composite primary keys # corrupts resultset @@ -782,3 +730,19 @@ SELECT COUNT(DISTINCT a) FROM t1 WHERE a=0; DROP TABLE t1; DROP PROCEDURE a; + +# +# Bug #18068: SELECT DISTINCT +# + +CREATE TABLE t1 (a varchar(64) NOT NULL default '', PRIMARY KEY(a)); + +INSERT INTO t1 (a) VALUES + (''), ('CENTRAL'), ('EASTERN'), ('GREATER LONDON'), + ('NORTH CENTRAL'), ('NORTH EAST'), ('NORTH WEST'), ('SCOTLAND'), + ('SOUTH EAST'), ('SOUTH WEST'), ('WESTERN'); + +EXPLAIN SELECT DISTINCT a,a FROM t1 ORDER BY a; +SELECT DISTINCT a,a FROM t1 ORDER BY a; + +DROP TABLE t1; diff --git a/mysql-test/t/heap.test b/mysql-test/t/heap.test index 82294db336d..e501fce1eeb 100644 --- a/mysql-test/t/heap.test +++ b/mysql-test/t/heap.test @@ -458,4 +458,16 @@ create table t2 (c varchar(10)) engine=memory; show table status like 't_'; drop table t1, t2; +# +# BUG#18233 - Memory tables INDEX USING HASH (a,b) returns 1 row on +# SELECT WHERE a= AND b= +# +CREATE TABLE t1(a VARCHAR(1), b VARCHAR(2), c VARCHAR(256), + KEY(a), KEY(b), KEY(c)) ENGINE=MEMORY; +INSERT INTO t1 VALUES('a','aa',REPEAT('a', 256)),('a','aa',REPEAT('a',256)); +SELECT COUNT(*) FROM t1 WHERE a='a'; +SELECT COUNT(*) FROM t1 WHERE b='aa'; +SELECT COUNT(*) FROM t1 WHERE c=REPEAT('a',256); +DROP TABLE t1; + # End of 5.0 tests diff --git a/mysql-test/t/heap_btree.test b/mysql-test/t/heap_btree.test index f1b9d290885..fb715fccefe 100644 --- a/mysql-test/t/heap_btree.test +++ b/mysql-test/t/heap_btree.test @@ -176,4 +176,12 @@ UPDATE t1 SET val=1; SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1'; DROP TABLE t1; +# +# BUG#12873 - BTREE index on MEMORY table with multiple NULL values doesn't +# work properly +# +CREATE TABLE t1 (a INT, UNIQUE USING BTREE(a)) ENGINE=MEMORY; +INSERT INTO t1 VALUES(NULL),(NULL); +DROP TABLE t1; + # End of 4.1 tests diff --git a/mysql-test/t/im_cmd_line.imtest b/mysql-test/t/im_cmd_line.imtest new file mode 100644 index 00000000000..00e8351535e --- /dev/null +++ b/mysql-test/t/im_cmd_line.imtest @@ -0,0 +1,68 @@ +########################################################################### +# +# Tests for user-management command-line options. +# +########################################################################### + +--source include/im_check_os.inc + +########################################################################### + +# List users so we are sure about starting conditions. + +--echo --> Listing users... +--exec $IM_EXE --defaults-file="$IM_DEFAULTS_PATH" --list-users 2>&1 >/dev/null +--echo + +# Add a new user. + +--echo ==> Adding user 'testuser'... +--exec $IM_EXE --defaults-file="$IM_DEFAULTS_PATH" --add-user --username=testuser --password=abc 2>&1 >/dev/null +--echo + +--echo --> IM password file: +--exec cat $IM_PASSWORD_PATH +--echo --> EOF +--echo + +--echo --> Printing out line for 'testuser'... +--exec $IM_EXE --defaults-file="$IM_DEFAULTS_PATH" --passwd --username=testuser --password=abc | tail -1 +--echo + +--echo --> Listing users... +--exec $IM_EXE --defaults-file="$IM_DEFAULTS_PATH" --list-users 2>&1 >/dev/null +--echo + +# Edit user's attributes. + +--echo ==> Changing the password of 'testuser'... +--exec $IM_EXE --defaults-file="$IM_DEFAULTS_PATH" --edit-user --username=testuser --password=xyz 2>&1 >/dev/null +--echo + +--echo --> IM password file: +--exec cat $IM_PASSWORD_PATH +--echo --> EOF +--echo + +--echo --> Printing out line for 'testuser'... +--exec $IM_EXE --defaults-file="$IM_DEFAULTS_PATH" --passwd --username=testuser --password=xyz | tail -1 +--echo + +--echo --> Listing users... +--exec $IM_EXE --defaults-file="$IM_DEFAULTS_PATH" --list-users 2>&1 >/dev/null +--echo + +# Drop user. + +--echo ==> Dropping user 'testuser'... +--exec $IM_EXE --defaults-file="$IM_DEFAULTS_PATH" --drop-user --username=testuser 2>&1 >/dev/null +--echo + +--echo --> IM password file: +--exec cat $IM_PASSWORD_PATH +--echo --> EOF +--echo + +--echo --> Listing users... +--exec $IM_EXE --defaults-file="$IM_DEFAULTS_PATH" --list-users 2>&1 >/dev/null +--echo diff --git a/mysql-test/t/im_daemon_life_cycle-im.opt b/mysql-test/t/im_daemon_life_cycle-im.opt index 21c01191e4c..3a45c7a41f7 100644 --- a/mysql-test/t/im_daemon_life_cycle-im.opt +++ b/mysql-test/t/im_daemon_life_cycle-im.opt @@ -1,2 +1,3 @@ --run-as-service --log=$MYSQLTEST_VARDIR/log/im.log +--monitoring-interval=1 diff --git a/mysql-test/t/im_daemon_life_cycle.imtest b/mysql-test/t/im_daemon_life_cycle.imtest index 87388d7c1e6..d173ce2a6e2 100644 --- a/mysql-test/t/im_daemon_life_cycle.imtest +++ b/mysql-test/t/im_daemon_life_cycle.imtest @@ -10,6 +10,9 @@ ########################################################################### +--sleep 3 +# should be longer than monitoring interval and enough to start instance. + SHOW INSTANCES; --exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_PATH_PID restarted diff --git a/mysql-test/t/im_instance_conf-im.opt b/mysql-test/t/im_instance_conf-im.opt new file mode 100644 index 00000000000..34b74ce0c95 --- /dev/null +++ b/mysql-test/t/im_instance_conf-im.opt @@ -0,0 +1 @@ +--monitoring-interval=1 diff --git a/mysql-test/t/im_instance_conf.imtest b/mysql-test/t/im_instance_conf.imtest new file mode 100644 index 00000000000..17703fdd303 --- /dev/null +++ b/mysql-test/t/im_instance_conf.imtest @@ -0,0 +1,228 @@ +########################################################################### +# +# This test suite checks the following statements: +# - CREATE INSTANCE <instance_name> [option1[=option1_value], ...]; +# - DROP INSTANCE <instance_name>; +# +# For CREATE INSTANCE we check that: +# - CREATE INSTANCE succeeds for non-existing instance; +# - CREATE INSTANCE fails for existing instance; +# - CREATE INSTANCE can get additional options with and w/o values; +# - CREATE INSTANCE parses options and handles grammar errors correctly. +# Check that strings with spaces are handled correctly, unknown (for +# mysqld) options should also be handled; +# - CREATE INSTANCE updates both config file and internal configuration cache; +# - CREATE INSTANCE allows to create instances only with properly formed +# names (mysqld*); +# +# For DROP INSTANCE we check that: +# - DROP INSTANCE succeeds for existing instance; +# - DROP INSTANCE fails for non-existing instance; +# - DROP INSTANCE fails for active instance. +# - DROP INSTANCE updates both config file and internal configuration cache; +# +########################################################################### + +--source include/im_check_os.inc + +########################################################################### +# +# Check starting conditions. +# +########################################################################### + +# Check that the configuration file contains only instances that we expect. + +--echo -------------------------------------------------------------------- +--exec grep server_id $MYSQLTEST_VARDIR/im.cnf; +--echo -------------------------------------------------------------------- + +# Check that mysqld1 is reported as running. + +--sleep 3 +# should be longer than monitoring interval and enough to start instance. + +SHOW INSTANCES; + +# Check that the expected mysqld instance is actually run (check that we can +# connect and execute something). + +--echo +--echo ---> connection: mysql1_con +--connect (mysql1_con,localhost,root,,mysql,$IM_MYSQLD1_PORT,$IM_MYSQLD1_SOCK) +--connection mysql1_con + +SHOW VARIABLES LIKE 'server_id'; + +--disconnect mysql1_con + +--echo +--echo ---> connection: default +--connection default + +########################################################################### +# +# CREATE INSTANCE tests. +# +########################################################################### + +# Check that CREATE INSTANCE succeeds for non-existing instance and also check +# that both config file and internal configuration cache have been updated. + +CREATE INSTANCE mysqld3; + +SHOW INSTANCES; + +--echo -------------------------------------------------------------------- +--exec grep server_id $MYSQLTEST_VARDIR/im.cnf ; +--echo -------------------------------------------------------------------- + +# Check that CREATE INSTANCE fails for existing instance. Let's all three +# existing instances (running one, stopped one and just created one). Just in +# case... + +--error 3012 # ER_CREATE_EXISTING_INSTANCE +CREATE INSTANCE mysqld1; + +--error 3012 # ER_CREATE_EXISTING_INSTANCE +CREATE INSTANCE mysqld2; + +--error 3012 # ER_CREATE_EXISTING_INSTANCE +CREATE INSTANCE mysqld3; + +# Check that CREATE INSTANCE can get additional options with and w/o values. +# Ensure that config file is updated properly. + +# - without values; + +--echo -------------------------------------------------------------------- +--exec grep nonguarded $MYSQLTEST_VARDIR/im.cnf; +--echo -------------------------------------------------------------------- + +CREATE INSTANCE mysqld4 nonguarded; + +SHOW INSTANCES; + +--echo -------------------------------------------------------------------- +--exec grep nonguarded $MYSQLTEST_VARDIR/im.cnf; +--echo -------------------------------------------------------------------- + +# - with value; + +--echo -------------------------------------------------------------------- +--exec grep test-A $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- +--exec grep test-B $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- + +CREATE INSTANCE mysqld5 test-A = 000, test-B = test; + +SHOW INSTANCES; + +--echo -------------------------------------------------------------------- +--exec grep test-A $MYSQLTEST_VARDIR/im.cnf; +--echo -------------------------------------------------------------------- +--exec grep test-B $MYSQLTEST_VARDIR/im.cnf; +--echo -------------------------------------------------------------------- + +# Check that CREATE INSTANCE parses options and handles grammar errors +# correctly. Check that strings with spaces are handled correctly, +# unknown (for mysqld) options should also be handled. + +# - check handling of extra spaces; + +--echo -------------------------------------------------------------------- +--exec grep test-C $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- + +CREATE INSTANCE mysqld6 test-C1 = 10 , test-C2 = 02 ; + +SHOW INSTANCES; + +--echo -------------------------------------------------------------------- +--exec grep test-C1 $MYSQLTEST_VARDIR/im.cnf; +--echo -------------------------------------------------------------------- +--exec grep test-C2 $MYSQLTEST_VARDIR/im.cnf; +--echo -------------------------------------------------------------------- + +# - check handling of grammar error; + +--echo -------------------------------------------------------------------- +--exec grep test-D $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- +--exec grep test-E $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- + +--error ER_SYNTAX_ERROR +CREATE INSTANCE mysqld7 test-D = test-D-value ; +SHOW INSTANCES; + +--error ER_SYNTAX_ERROR +CREATE INSTANCE mysqld8 test-E 0 ; +SHOW INSTANCES; + +--error ER_SYNTAX_ERROR +CREATE INSTANCE mysqld8 test-F = ; +SHOW INSTANCES; + +--echo -------------------------------------------------------------------- +--exec grep test-D $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- +--exec grep test-E $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- + +# - check parsing of string option values + +--echo -------------------------------------------------------------------- +--exec grep test-1 $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- +--exec grep test-2 $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- +--exec grep test-3 $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- +--exec grep test-4 $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- + +CREATE INSTANCE mysqld9 test-1=" hello world ", test-2=' '; +SHOW INSTANCES; + +CREATE INSTANCE mysqld9a test-3='\b\babc\sdef'; +# test-3='abc def' +SHOW INSTANCES; + +CREATE INSTANCE mysqld9b test-4='abc\tdef', test-5='abc\ndef'; +SHOW INSTANCES; + +CREATE INSTANCE mysqld9c test-6="abc\rdef", test-7="abc\\def"; +# test-6=abc +SHOW INSTANCES; + +--error ER_SYNTAX_ERROR +CREATE INSTANCE mysqld10 test-bad=' \ '; +SHOW INSTANCES; + +--echo -------------------------------------------------------------------- +--exec grep test-1 $MYSQLTEST_VARDIR/im.cnf; +--echo -------------------------------------------------------------------- +--exec grep test-2 $MYSQLTEST_VARDIR/im.cnf; +--echo -------------------------------------------------------------------- +--exec grep test-3 $MYSQLTEST_VARDIR/im.cnf; +--echo -------------------------------------------------------------------- +--exec grep test-4 $MYSQLTEST_VARDIR/im.cnf; +--echo -------------------------------------------------------------------- +--exec grep test-5 $MYSQLTEST_VARDIR/im.cnf; +--echo -------------------------------------------------------------------- +--exec grep test-6 $MYSQLTEST_VARDIR/im.cnf; +--echo -------------------------------------------------------------------- +--exec grep test-7 $MYSQLTEST_VARDIR/im.cnf; +--echo -------------------------------------------------------------------- +--exec grep test-bad $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- + + +# Check that CREATE INSTANCE allows to create instances only with properly +# formed names (mysqld*). + +--error 3014 # ER_MALFORMED_INSTANCE_NAME +CREATE INSTANCE qqq1; + diff --git a/mysql-test/t/im_life_cycle-im.opt b/mysql-test/t/im_life_cycle-im.opt new file mode 100644 index 00000000000..34b74ce0c95 --- /dev/null +++ b/mysql-test/t/im_life_cycle-im.opt @@ -0,0 +1 @@ +--monitoring-interval=1 diff --git a/mysql-test/t/im_life_cycle.imtest b/mysql-test/t/im_life_cycle.imtest index 246843a022b..d71cdc86624 100644 --- a/mysql-test/t/im_life_cycle.imtest +++ b/mysql-test/t/im_life_cycle.imtest @@ -17,11 +17,15 @@ # ########################################################################### +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.1. +--echo -------------------------------------------------------------------- + +--sleep 3 +# should be longer than monitoring interval and enough to start instance. + SHOW INSTANCES; ---replace_column 3 VERSION_NUMBER 4 VERSION -SHOW INSTANCE STATUS mysqld1; ---replace_column 3 VERSION_NUMBER 4 VERSION -SHOW INSTANCE STATUS mysqld2; ########################################################################### # @@ -33,20 +37,22 @@ SHOW INSTANCE STATUS mysqld2; # ########################################################################### +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.2. +--echo -------------------------------------------------------------------- + START INSTANCE mysqld2; -# FIXME +# FIXME: START INSTANCE should be synchronous. --sleep 3 +# should be longer than monitoring interval and enough to start instance. SHOW INSTANCES; ---replace_column 3 VERSION_NUMBER 4 VERSION -SHOW INSTANCE STATUS mysqld1; ---replace_column 3 VERSION_NUMBER 4 VERSION -SHOW INSTANCE STATUS mysqld2; ---connect (mysql_con,localhost,root,,mysql,$IM_MYSQLD1_PORT,$IM_MYSQLD1_SOCK) +--connect (mysql_con,localhost,root,,mysql,$IM_MYSQLD2_PORT,$IM_MYSQLD2_SOCK) --connection mysql_con ---replace_result $IM_MYSQLD1_PORT IM_MYSQLD1_PORT +--replace_result $IM_MYSQLD2_PORT IM_MYSQLD2_PORT SHOW VARIABLES LIKE 'port'; --connection default @@ -61,9 +67,15 @@ SHOW VARIABLES LIKE 'port'; # ########################################################################### +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.3. +--echo -------------------------------------------------------------------- + STOP INSTANCE mysqld2; -# FIXME +# FIXME: STOP INSTANCE should be synchronous. --sleep 3 +# should be longer than monitoring interval and enough to stop instance. SHOW INSTANCES; --replace_column 3 VERSION_NUMBER 4 VERSION @@ -81,16 +93,17 @@ SHOW INSTANCE STATUS mysqld2; # ########################################################################### ---error 3000 +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.4. +--echo -------------------------------------------------------------------- + +--error 3000 # ER_BAD_INSTANCE_NAME START INSTANCE mysqld3; ---error 3002 +--error 3002 # ER_INSTANCE_ALREADY_STARTED START INSTANCE mysqld1; -# FIXME TODO -# BUG#12813: START/STOP INSTANCE commands accept a list as argument -# START INSTANCE mysqld1, mysqld2; - ########################################################################### # # 1.1.5. Check that Instance Manager reports correct errors for 'STOP INSTANCE' @@ -101,39 +114,54 @@ START INSTANCE mysqld1; # ########################################################################### ---error 3000 +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.5. +--echo -------------------------------------------------------------------- + +--error 3000 # ER_BAD_INSTANCE_NAME STOP INSTANCE mysqld3; # TODO: IM should be fixed. # BUG#12673: Instance Manager allows to stop the instance many times -# --error 3002 +# --error 3002 # ER_INSTANCE_ALREADY_STARTED # STOP INSTANCE mysqld2; -# FIXME TODO -# BUG#12813: START/STOP INSTANCE commands accept a list as argument -# STOP INSTANCE mysqld1, mysqld2; - ########################################################################### # # 1.1.6. Check that Instance Manager is able to restart guarded instances. # ########################################################################### +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.6. +--echo -------------------------------------------------------------------- + SHOW INSTANCES; --exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD1_PATH_PID restarted +--sleep 3 +# should be longer than monitoring interval and enough to start instance. + ########################################################################### # # 1.1.7. Check that Instance Manager does not restart non-guarded instance. # ########################################################################### +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.7. +--echo -------------------------------------------------------------------- + SHOW INSTANCES; START INSTANCE mysqld2; -# FIXME +# FIXME: START INSTANCE should be synchronous. --sleep 3 +# should be longer than monitoring interval and enough to start instance. SHOW INSTANCES; @@ -147,7 +175,13 @@ SHOW INSTANCES; # incomplete SHOW INSTANCE STATUS command. # ########################################################################### ---error 1149 + +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.8. +--echo -------------------------------------------------------------------- + +--error ER_SYNTAX_ERROR SHOW INSTANCE STATUS; # @@ -159,8 +193,13 @@ SHOW INSTANCE STATUS; # a list as argument. # ---error 1149 +--echo +--echo -------------------------------------------------------------------- +--echo -- BUG#12813 +--echo -------------------------------------------------------------------- + +--error ER_SYNTAX_ERROR START INSTANCE mysqld1,mysqld2,mysqld3; ---error 1149 +--error ER_SYNTAX_ERROR STOP INSTANCE mysqld1,mysqld2,mysqld3; diff --git a/mysql-test/t/im_options.imtest b/mysql-test/t/im_options.imtest new file mode 100644 index 00000000000..cd905416cda --- /dev/null +++ b/mysql-test/t/im_options.imtest @@ -0,0 +1,268 @@ +########################################################################### +# +# This test suite checks the following statements: +# - SET <instance id>.<option name> = <option value>; +# - UNSET <instance id>.<option name> = <option value>; +# - FLUSH INSTANCES; +# +# For SET/UNSET we check that: +# - SET ignores spaces correctly; +# - UNSET does not allow option-value part (= <option value>); +# - SET/UNSET can be applied several times w/o error; +# - SET/UNSET is allowed only for stopped instances; +# - SET/UNSET updates both the configuration cache in IM and +# the configuration file; +# +# For FLUSH INSTANCES we check that: +# - FLUSH INSTANCES is allowed only when all instances are stopped; +# +# According to the IM implementation details, we should play at least with the +# following options: +# - server_id +# - port +# - nonguarded + +# Let's test SET statement on the option 'server_id'. It's expected that +# originally the instances have the following server ids and states: +# - mysqld1: server_id: 1; running (online) +# - mysqld2: server_id: 2; stopped (offline) +# +########################################################################### + +--source include/im_check_os.inc + +########################################################################### +# +# Check starting conditions. +# +########################################################################### + +# - check the configuration file; + +--echo -------------------------------------------------------------------- +--exec grep server_id $MYSQLTEST_VARDIR/im.cnf ; +--echo -------------------------------------------------------------------- + +# - check the running instances. + +--connect (mysql1_con,localhost,root,,mysql,$IM_MYSQLD1_PORT,$IM_MYSQLD1_SOCK) + +--connection mysql1_con + +SHOW VARIABLES LIKE 'server_id'; + +--connection default + +# - check the internal cache. + +SHOW INSTANCES; + +########################################################################### +# +# Check that SET/UNSET is allowed only for stopped instances. +# +########################################################################### + +# - check that SET/UNSET is denied for running instances; + +--error 3015 # ER_INSTANCE_IS_ACTIVE +UNSET mysqld1.server_id; + +--error 3015 # ER_INSTANCE_IS_ACTIVE +SET mysqld1.server_id = 11; + +# - check that SET/UNSET is denied for active instances: +# - create dummy misconfigured instance; +# - start it; +# - try to set/unset options; + +CREATE INSTANCE mysqld3 datadir = '/'; +START INSTANCE mysqld3; + +# FIXME: START INSTANCE should be synchronous. +--sleep 3 +# should be longer than monitoring interval and enough to start instance. + +# NOTE: We can not analyze state of the instance here -- it can be Failed or +# Starting because Instance Manager is trying to start the misconfigured +# instance several times. + +--error 3015 # ER_INSTANCE_IS_ACTIVE +UNSET mysqld3.server_id; + +--error 3015 # ER_INSTANCE_IS_ACTIVE +SET mysqld3.server_id = 11; + +STOP INSTANCE mysqld3; + +# FIXME: STOP INSTANCE should be synchronous. +--sleep 3 +# should be longer than monitoring interval and enough to stop instance. + +--replace_column 3 VERSION_NUMBER 4 VERSION +SHOW INSTANCE STATUS mysqld3; + +# - check that SET/UNSET succeed for stopped instances; +# - check that SET/UNSET can be applied multiple times; + +UNSET mysqld2.server_id; +UNSET mysqld2.server_id; + +--replace_column 2 option_value +SHOW INSTANCE OPTIONS mysqld2; + +SET mysqld2.server_id = 2; +SET mysqld2.server_id = 2; + +--replace_column 2 option_value +SHOW INSTANCE OPTIONS mysqld2; + +# - check that UNSET does not allow option-value part (= <option value>); + +--error ER_SYNTAX_ERROR +UNSET mysqld2.server_id = 11; + +# - check that SET/UNSET working properly with multiple options; + +SET mysqld2.aaa, mysqld3.bbb, mysqld2.ccc = 0010, mysqld3.ddd = 0020; + +--echo -------------------------------------------------------------------- +--exec grep aaa $MYSQLTEST_VARDIR/im.cnf ; +--echo -------------------------------------------------------------------- +--exec grep bbb $MYSQLTEST_VARDIR/im.cnf ; +--echo -------------------------------------------------------------------- +--exec grep ccc $MYSQLTEST_VARDIR/im.cnf ; +--echo -------------------------------------------------------------------- +--exec grep ddd $MYSQLTEST_VARDIR/im.cnf ; +--echo -------------------------------------------------------------------- + +UNSET mysqld2.aaa, mysqld3.bbb, mysqld2.ccc, mysqld3.ddd; + +--echo -------------------------------------------------------------------- +--exec grep aaa $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- +--exec grep bbb $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- +--exec grep ccc $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- +--exec grep ddd $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- + +# - check that if some instance name is invalid or the active is active, +# whole SET-statement will not be executed; + +--error 3000 # ER_BAD_INSTANCE_NAME +SET mysqld2.aaa, mysqld3.bbb, mysqld.ccc = 0010; + +--echo -------------------------------------------------------------------- +--exec grep aaa $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- +--exec grep bbb $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- +--exec grep ccc $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- + +--error 3015 # ER_INSTANCE_IS_ACTIVE +SET mysqld2.aaa, mysqld3.bbb, mysqld1.ccc = 0010; + +--echo -------------------------------------------------------------------- +--exec grep aaa $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- +--exec grep bbb $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- +--exec grep ccc $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- + +# - check that if some instance name is invalid or the active is active, +# whole UNSET-statement will not be executed; + +--error 3000 # ER_BAD_INSTANCE_NAME +UNSET mysqld2.server_id, mysqld3.server_id, mysqld.ccc; + +--echo -------------------------------------------------------------------- +--exec grep server_id $MYSQLTEST_VARDIR/im.cnf; +--echo -------------------------------------------------------------------- + +--error 3015 # ER_INSTANCE_IS_ACTIVE +UNSET mysqld2.server_id, mysqld3.server_id, mysqld1.ccc; + +--echo -------------------------------------------------------------------- +--exec grep server_id $MYSQLTEST_VARDIR/im.cnf; +--echo -------------------------------------------------------------------- + +DROP INSTANCE mysqld3; + +# - check that spaces are handled correctly; + +SET mysqld2.server_id=222; +SET mysqld2.server_id = 222; +SET mysqld2.server_id = 222 ; +SET mysqld2 . server_id = 222 ; +SET mysqld2 . server_id = 222 , mysqld2 . aaa , mysqld2 . bbb ; + +--echo -------------------------------------------------------------------- +--exec grep server_id $MYSQLTEST_VARDIR/im.cnf ; +--echo -------------------------------------------------------------------- +--exec grep aaa $MYSQLTEST_VARDIR/im.cnf ; +--echo -------------------------------------------------------------------- +--exec grep bbb $MYSQLTEST_VARDIR/im.cnf ; +--echo -------------------------------------------------------------------- + +UNSET mysqld2 . aaa , mysqld2 . bbb ; + +--echo -------------------------------------------------------------------- +--exec grep server_id $MYSQLTEST_VARDIR/im.cnf ; +--echo -------------------------------------------------------------------- +--exec grep aaa $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- +--exec grep bbb $MYSQLTEST_VARDIR/im.cnf || true; +--echo -------------------------------------------------------------------- + +########################################################################### +# +# Check that SET/UNSET updates both the configuration cache in IM and +# the configuration file. +# +########################################################################### + +# - check that the configuration file has been updated (i.e. contains +# server_id=SERVER_ID for mysqld2); + +--echo -------------------------------------------------------------------- +--exec grep server_id $MYSQLTEST_VARDIR/im.cnf ; +--echo -------------------------------------------------------------------- + +# - (for mysqld1) check that the running instance has not been affected: +# connect to the instance and check that 'SHOW VARIABLES LIKE 'server_id'' +# returns zero; + +--connection mysql1_con + +SHOW VARIABLES LIKE 'server_id'; + +--connection default + +# - check that internal cache of Instance Manager has been affected; +# TODO: we should check only server_id option here. + +# SHOW INSTANCE OPTIONS mysqld2; + +########################################################################### +# +# Check that FLUSH INSTANCES is allowed only when all instances are stopped. +# +########################################################################### + +SHOW INSTANCES; + +--error 3016 # ER_THERE_IS_ACTIVE_INSTACE +FLUSH INSTANCES; + +STOP INSTANCE mysqld1; +# FIXME: STOP INSTANCE should be synchronous. +--sleep 3 +# should be longer than monitoring interval and enough to stop instance. + +SHOW INSTANCES; + +FLUSH INSTANCES; diff --git a/mysql-test/t/im_options_set.imtest b/mysql-test/t/im_options_set.imtest deleted file mode 100644 index a9b64861f99..00000000000 --- a/mysql-test/t/im_options_set.imtest +++ /dev/null @@ -1,142 +0,0 @@ -########################################################################### -# -# This file contains test for (3) test suite. -# -# Consult WL#2789 for more information. -# -########################################################################### - -# -# Check the options-management commands: -# - SET; -# - FLUSH INSTANCES; -# -# Let's test the commands on the option 'server_id'. It's expected that -# originally the instances have the following server ids: -# - mysqld1: 1 -# - mysqld2: 2 -# -# 1. SET <instance_id>.server_id= SERVER_ID); where SERVER_ID is 11 or 12. -# 1.1. check that the configuration file has been updated (i.e. contains -# server_id=SERVER_ID for the instance); -# 1.2. (for mysqld1) check that the running instance has not been affected: -# connect to the instance and check that 'SHOW VARIABLES LIKE 'server_id'' -# returns zero; -# 1.3. check that internal cache of Instance Manager has not been affected -# (i.e. SHOW INSTANCE OPTIONS <instance> does not contain updated value). -# -# 2. FLUSH INSTANCES; -# 2.1. check that the configuration file has not been updated; -# 2.2. (for mysqld1) check that the running instance has not been affected: -# connect to the instance and check that 'SHOW VARIABLES LIKE 'server_id'' -# returns zero value; -# 2.3. check that internal cache of Instance Manager has been updated (i.e. -# SHOW INSTANCE OPTIONS <instance> contains 'server_id=SERVER_ID' line). -# -# 3. Restore options. -# - -########################################################################### - ---source include/im_check_os.inc - -########################################################################### -# -# 0. Check starting conditions. -# -########################################################################### - -# - check the configuration file; - ---exec grep server_id $MYSQLTEST_VARDIR/im.cnf ; - -# - check the running instances. - ---connect (mysql1_con,localhost,root,,mysql,$IM_MYSQLD1_PORT,$IM_MYSQLD1_SOCK) - ---connection mysql1_con - -SHOW VARIABLES LIKE 'server_id'; - ---connection default - -# - check the internal cache. -# TODO: we should check only server_id option here. - -# SHOW INSTANCE OPTIONS mysqld1; -# SHOW INSTANCE OPTIONS mysqld2; - -########################################################################### -# -# 1. SET <instance_id>.server_id= SERVER_ID); where SERVER_ID is 11 or 12. -# -########################################################################### - -# * mysqld1 - -SET mysqld1.server_id = 11; - -# - check that the configuration file has been updated (i.e. contains -# server_id=SERVER_ID for the instance); - ---exec grep server_id $MYSQLTEST_VARDIR/im.cnf ; - -# - (for mysqld1) check that the running instance has not been affected: -# connect to the instance and check that 'SHOW VARIABLES LIKE 'server_id'' -# returns zero; - ---connection mysql1_con - -SHOW VARIABLES LIKE 'server_id'; - ---connection default - -# - check that internal cache of Instance Manager has not been affected -# (i.e. SHOW INSTANCE OPTIONS <instance> does not contain updated value). -# TODO: we should check only server_id option here. - -# SHOW INSTANCE OPTIONS mysqld1; - -# * mysqld2 - -SET mysqld2.server_id = 12; - -# - check that the configuration file has been updated (i.e. contains -# server_id=SERVER_ID for the instance); - ---exec grep server_id $MYSQLTEST_VARDIR/im.cnf ; - -# - check that internal cache of Instance Manager has not been affected -# (i.e. SHOW INSTANCE OPTIONS <instance> does not contain updated value). -# TODO: we should check only server_id option here. - -# SHOW INSTANCE OPTIONS mysqld2; - -########################################################################### -# -# 2. FLUSH INSTANCES; -# -########################################################################### - -FLUSH INSTANCES; - -# - check that the configuration file has not been updated; - ---exec grep server_id $MYSQLTEST_VARDIR/im.cnf ; - -# - (for mysqld1) check that the running instance has not been affected: -# connect to the instance and check that 'SHOW VARIABLES LIKE 'server_id'' -# returns zero value; - ---connection mysql1_con - -SHOW VARIABLES LIKE 'server_id'; - ---connection default - -# - check that internal cache of Instance Manager has been updated (i.e. -# SHOW INSTANCE OPTIONS <instance> contains 'server_id=' line). -# TODO: we should check only server_id option here. - -# SHOW INSTANCE OPTIONS mysqld1; -# SHOW INSTANCE OPTIONS mysqld2; diff --git a/mysql-test/t/im_options_unset.imtest b/mysql-test/t/im_options_unset.imtest deleted file mode 100644 index 40629805d45..00000000000 --- a/mysql-test/t/im_options_unset.imtest +++ /dev/null @@ -1,150 +0,0 @@ -########################################################################### -# -# This file contains test for (3) test suite. -# -# Consult WL#2789 for more information. -# -########################################################################### - -# -# Check the options-management commands: -# - UNSET; -# - FLUSH INSTANCES; -# -# Let's test the commands on the option 'server_id'. It's expected that -# originally the instances have the following server ids: -# - mysqld1: 1 -# - mysqld2: 2 -# -# The test case: -# -# 1. UNSET <instance_id>.server_id; -# -# Do the step for both instances. -# -# 1.1. check that the configuration file has been updated (i.e. does not -# contain 'server_id=' line for the instance); -# 1.2. (for mysqld1) check that the running instance has not been affected: -# connect to the instance and check that 'SHOW VARIABLES LIKE 'server_id'' -# returns non-zero value; -# 1.3. check that internal cache of Instance Manager is not affected (i.e. -# SHOW INSTANCE OPTIONS <instance> contains non-zero value for server_id); -# -# 2. FLUSH INSTANCES; -# -# Do the step for both instances. -# -# 2.1. check that the configuration file has not been updated (i.e. does not -# contain 'server_id=' for the instance); -# 2.2. (for mysqld1) check that the running instance has not been affected: -# connect to the instance and check that 'SHOW VARIABLES LIKE 'server_id'' -# returns non-zero value; -# 2.3. check that internal cache of Instance Manager has been updated (i.e. -# SHOW INSTANCE OPTIONS <instance> does not contain 'server_id=' line). -# - -########################################################################### - ---source include/im_check_os.inc - -########################################################################### -# -# 0. Check starting conditions. -# -########################################################################### - -# - check the configuration file; - ---exec grep server_id $MYSQLTEST_VARDIR/im.cnf ; - -# - check the running instances. - ---connect (mysql1_con,localhost,root,,mysql,$IM_MYSQLD1_PORT,$IM_MYSQLD1_SOCK) - ---connection mysql1_con - -SHOW VARIABLES LIKE 'server_id'; - ---connection default - -# - check the internal cache. -# TODO: we should check only server_id option here. - -# SHOW INSTANCE OPTIONS mysqld1; -# SHOW INSTANCE OPTIONS mysqld2; - -########################################################################### -# -# 1. UNSET <instance_id>.server_id; -# -########################################################################### - -# * mysqld1 - -UNSET mysqld1.server_id; - -# - check that the configuration file has been updated (i.e. does not -# contain 'server_id=' line for the instance); - ---exec grep server_id $MYSQLTEST_VARDIR/im.cnf ; - -# - check that the running instance has not been affected: connect to the -# instance and check that 'SHOW VARIABLES LIKE 'server_id'' returns non-zero -# value; - ---connection mysql1_con - -SHOW VARIABLES LIKE 'server_id'; - ---connection default - -# - check that internal cache of Instance Manager is not affected (i.e. SHOW -# INSTANCE OPTIONS <instance> contains non-zero value for server_id); -# TODO: we should check only server_id option here. - -# SHOW INSTANCE OPTIONS mysqld1; - -# * mysqld2 - -UNSET mysqld2.server_id; - -# - check that the configuration file has been updated (i.e. does not -# contain 'server_id=' line for the instance); - ---exec grep server_id $MYSQLTEST_VARDIR/im.cnf || true; - -# - check that internal cache of Instance Manager is not affected (i.e. SHOW -# INSTANCE OPTIONS <instance> contains non-zero value for server_id); -# TODO: we should check only server_id option here. - -# SHOW INSTANCE OPTIONS mysqld2; - -########################################################################### -# -# 2. FLUSH INSTANCES; -# -########################################################################### - -FLUSH INSTANCES; - -# - check that the configuration file has not been updated (i.e. does not -# contain 'server_id=' for the instance); - ---exec grep server_id $MYSQLTEST_VARDIR/im.cnf || true; - -# - (for mysqld1) check that the running instance has not been affected: -# connect to the instance and check that 'SHOW VARIABLES LIKE 'server_id'' -# returns non-zero value; - ---connection mysql1_con - -SHOW VARIABLES LIKE 'server_id'; - ---connection default - -# - check that internal cache of Instance Manager has been updated (i.e. -# SHOW INSTANCE OPTIONS <instance> does not contain 'server_id=' line). -# TODO: we should check only server_id option here. - -# SHOW INSTANCE OPTIONS mysqld1; -# SHOW INSTANCE OPTIONS mysqld2; diff --git a/mysql-test/t/im_utils-im.opt b/mysql-test/t/im_utils-im.opt new file mode 100644 index 00000000000..34b74ce0c95 --- /dev/null +++ b/mysql-test/t/im_utils-im.opt @@ -0,0 +1 @@ +--monitoring-interval=1 diff --git a/mysql-test/t/im_utils.imtest b/mysql-test/t/im_utils.imtest index dc6fb93c4ff..8e8d475cfee 100644 --- a/mysql-test/t/im_utils.imtest +++ b/mysql-test/t/im_utils.imtest @@ -17,6 +17,9 @@ # - the second instance is offline; # +--sleep 3 +# should be longer than monitoring interval and enough to start instance. + SHOW INSTANCES; # @@ -41,8 +44,9 @@ SHOW INSTANCE OPTIONS mysqld2; START INSTANCE mysqld2; -# FIXME --- sleep 3 +# FIXME: START INSTANCE should be synchronous. +--sleep 3 +# should be longer than monitoring interval and enough to start instance. STOP INSTANCE mysqld2; diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index b7151b03ae1..acb877e1e74 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -5,9 +5,6 @@ # on the presence of the log tables (which are CSV-based). --source include/have_csv.inc -# This test uses chmod, can't be run with root permissions --- source include/not_as_root.inc - # Test for information_schema.schemata & # show databases @@ -797,15 +794,6 @@ DROP VIEW v1; DROP FUNCTION func1; DROP FUNCTION func2; -# -# Bug #15851 Unlistable directories yield no info from information_schema -# -create database mysqltest; -create table mysqltest.t1(a int); ---exec chmod -r $MYSQLTEST_VARDIR/master-data/mysqltest -select table_schema from information_schema.tables where table_schema='mysqltest'; ---exec chmod +r $MYSQLTEST_VARDIR/master-data/mysqltest -drop database mysqltest; # # Bug#15307 GROUP_CONCAT() with ORDER BY returns empty set on information_schema @@ -817,6 +805,26 @@ table_schema='information_schema' and group by column_type order by num; # +# Bug#19236 bad COLUMNS.CHARACTER_MAXIMUM_LENGHT and CHARACTER_OCTET_LENGTH +# +create table t1(f1 char(1) not null, f2 char(9) not null) +default character set utf8; +select CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH from +information_schema.columns where table_schema='test' and table_name = 't1'; +drop table t1; + +# +# Bug#18177 any access to INFORMATION_SCHEMA.ROUTINES crashes +# +use mysql; +INSERT INTO `proc` VALUES ('test','','PROCEDURE','','SQL','CONTAINS_SQL', +'NO','DEFINER','','','BEGIN\r\n \r\nEND','root@%','2006-03-02 18:40:03', +'2006-03-02 18:40:03','',''); +select routine_name from information_schema.routines; +delete from proc where name=''; +use test; + +# # End of 5.0 tests. # # Show engines @@ -835,4 +843,22 @@ select user,db from information_schema.processlist; connection default; drop user user3148@localhost; +# +# Bug#16681 information_schema shows forbidden VIEW details +# +grant select on test.* to mysqltest_1@localhost; +create table t1 (id int); +create view v1 as select * from t1; +create definer = mysqltest_1@localhost +sql security definer view v2 as select 1; + +connect (con16681,localhost,mysqltest_1,,test); +connection con16681; + +select * from information_schema.views +where table_name='v1' or table_name='v2'; +connection default; +drop view v1, v2; +drop table t1; +drop user mysqltest_1@localhost; diff --git a/mysql-test/t/information_schema_chmod.test b/mysql-test/t/information_schema_chmod.test new file mode 100644 index 00000000000..c7ea2b03890 --- /dev/null +++ b/mysql-test/t/information_schema_chmod.test @@ -0,0 +1,23 @@ +# +# Due to "Bug#18474 Unlistable directories yield no info from +# information_schema, part2" this test can't be run on Window with our +# current test framework. When "chmod -r" is done within cygwin the +# MySQL Server can still read the directory. +# Manual testing shows the functionalty to skip unlistable directories +# works on windows +# +--source include/not_windows.inc + +# This test uses chmod, can't be run with root permissions +-- source include/not_as_root.inc + + +# +# Bug #15851 Unlistable directories yield no info from information_schema +# +create database mysqltest; +create table mysqltest.t1(a int); +--exec chmod -r $MYSQLTEST_VARDIR/master-data/mysqltest +select table_schema from information_schema.tables where table_schema='mysqltest'; +--exec chmod +r $MYSQLTEST_VARDIR/master-data/mysqltest +drop database mysqltest; diff --git a/mysql-test/t/information_schema_db.test b/mysql-test/t/information_schema_db.test index b65135a621d..2cfa766d799 100644 --- a/mysql-test/t/information_schema_db.test +++ b/mysql-test/t/information_schema_db.test @@ -1,16 +1,25 @@ -- source include/testdb_only.inc +--disable_warnings +drop table if exists t1,t2; +drop view if exists v1,v2; +drop function if exists f1; +drop function if exists f2; +--enable_warnings + use INFORMATION_SCHEMA; --replace_result Tables_in_INFORMATION_SCHEMA Tables_in_information_schema show tables; --replace_result 'Tables_in_INFORMATION_SCHEMA (T%)' 'Tables_in_information_schema (T%)' show tables from INFORMATION_SCHEMA like 'T%'; create database `inf%`; +create database mbase; use `inf%`; show tables; # # Bug#18113 SELECT * FROM information_schema.xxx crashes server +# Bug#17204 second CALL to procedure crashes Server # Crash happened when one selected data from one of INFORMATION_SCHEMA # tables and in order to build its contents server had to open view which # used stored function and table or view on which one had not global or @@ -18,6 +27,7 @@ show tables; # privileges at all). # grant all privileges on `inf%`.* to 'mysqltest_1'@'localhost'; +grant all privileges on `mbase`.* to 'mysqltest_1'@'localhost'; create table t1 (f1 int); delimiter |; create function func1(curr_int int) returns int @@ -28,15 +38,63 @@ begin end| delimiter ;| create view v1 as select f1 from t1 where f1 = func1(f1); +create function func2() returns int return 1; + +use mbase; +delimiter |; +create procedure p1 () +begin +select table_name from information_schema.key_column_usage +order by table_name; +end| +delimiter ;| + +create table t1 +(f1 int(10) unsigned not null, + f2 varchar(100) not null, + primary key (f1), unique key (f2)); + connect (user1,localhost,mysqltest_1,,); connection user1; --disable_result_log select * from information_schema.tables; +call mbase.p1(); +call mbase.p1(); +call mbase.p1(); --enable_result_log + connection default; +use `inf%`; drop user mysqltest_1@localhost; +drop table t1; +select table_name, table_type, table_comment from information_schema.tables +where table_schema='inf%' and func2(); +select table_name, table_type, table_comment from information_schema.tables +where table_schema='inf%' and func2(); drop view v1; drop function func1; -drop table t1; +drop function func2; drop database `inf%`; +drop procedure mbase.p1; +drop database mbase; + +# +# Bug#18282 INFORMATION_SCHEMA.TABLES provides inconsistent info about invalid views +# +use test; +create table t1 (i int); +create function f1 () returns int return (select max(i) from t1); +create view v1 as select f1(); +create table t2 (id int); +create function f2 () returns int return (select max(i) from t2); +create view v2 as select f2(); +drop table t2; +select table_name, table_type, table_comment from information_schema.tables +where table_schema='test'; +drop table t1; +select table_name, table_type, table_comment from information_schema.tables +where table_schema='test'; +drop function f1; +drop function f2; +drop view v1, v2; diff --git a/mysql-test/t/information_schema_part.test b/mysql-test/t/information_schema_part.test index 163b04248b8..4cbf21ca1d3 100644 --- a/mysql-test/t/information_schema_part.test +++ b/mysql-test/t/information_schema_part.test @@ -99,3 +99,25 @@ select * from information_schema.partitions where table_schema="test" and table_name="t1"; drop table t1; +# +# Bug 20161 Partitions: SUBPARTITION METHOD doesn't show LINEAR keyword +# +create table t1 (a int) +PARTITION BY RANGE (a) +SUBPARTITION BY LINEAR HASH (a) +(PARTITION p0 VALUES LESS THAN (10)); + +SHOW CREATE TABLE t1; +select SUBPARTITION_METHOD FROM information_schema.partitions WHERE +table_schema="test" AND table_name="t1"; +drop table t1; + +create table t1 (a int) +PARTITION BY LIST (a) +(PARTITION p0 VALUES IN +(10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, + 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53)); +SHOW CREATE TABLE t1; +SELECT PARTITION_DESCRIPTION FROM information_schema.partitions WHERE +table_schema = "test" AND table_name = "t1"; +drop table t1; diff --git a/mysql-test/t/innodb_mysql.test b/mysql-test/t/innodb_mysql.test index c0fb3ab917b..0a9eeb049b0 100644 --- a/mysql-test/t/innodb_mysql.test +++ b/mysql-test/t/innodb_mysql.test @@ -1,9 +1,229 @@ -- source include/have_innodb.inc --disable_warnings -drop table if exists t1.t2; +drop table if exists t1,t2,t1m,t1i,t2m,t2i,t4; --enable_warnings +# BUG#16798: Uninitialized row buffer reads in ref-or-null optimizer +# (repeatable only w/innodb). +create table t1 ( + c_id int(11) not null default '0', + org_id int(11) default null, + unique key contacts$c_id (c_id), + key contacts$org_id (org_id) +) engine=innodb; +insert into t1 values + (2,null),(120,null),(141,null),(218,7), (128,1), + (151,2),(234,2),(236,2),(243,2),(255,2),(259,2),(232,3),(235,3),(238,3), + (246,3),(253,3),(269,3),(285,3),(291,3),(293,3),(131,4),(230,4),(231,4); + +create table t2 ( + slai_id int(11) not null default '0', + owner_tbl int(11) default null, + owner_id int(11) default null, + sla_id int(11) default null, + inc_web int(11) default null, + inc_email int(11) default null, + inc_chat int(11) default null, + inc_csr int(11) default null, + inc_total int(11) default null, + time_billed int(11) default null, + activedate timestamp null default null, + expiredate timestamp null default null, + state int(11) default null, + sla_set int(11) default null, + unique key t2$slai_id (slai_id), + key t2$owner_id (owner_id), + key t2$sla_id (sla_id) +) engine=innodb; +insert into t2(slai_id, owner_tbl, owner_id, sla_id) values + (1,3,1,1), (3,3,10,2), (4,3,3,6), (5,3,2,5), (6,3,8,3), (7,3,9,7), + (8,3,6,8), (9,3,4,9), (10,3,5,10), (11,3,11,11), (12,3,7,12); + +flush tables; +select si.slai_id +from t1 c join t2 si on + ((si.owner_tbl = 3 and si.owner_id = c.org_id) or + ( si.owner_tbl = 2 and si.owner_id = c.c_id)) +where + c.c_id = 218 and expiredate is null; + +select * from t1 where org_id is null; +select si.slai_id +from t1 c join t2 si on + ((si.owner_tbl = 3 and si.owner_id = c.org_id) or + ( si.owner_tbl = 2 and si.owner_id = c.c_id)) +where + c.c_id = 218 and expiredate is null; + +drop table t1, t2; + +# +# Bug #12882 min/max inconsistent on empty table +# + +--disable_warnings +create table t1m (a int) engine=myisam; +create table t1i (a int) engine=innodb; +create table t2m (a int) engine=myisam; +create table t2i (a int) engine=innodb; +--enable_warnings +insert into t2m values (5); +insert into t2i values (5); + +# test with MyISAM +select min(a) from t1m; +select min(7) from t1m; +select min(7) from DUAL; +explain select min(7) from t2m join t1m; +select min(7) from t2m join t1m; + +select max(a) from t1m; +select max(7) from t1m; +select max(7) from DUAL; +explain select max(7) from t2m join t1m; +select max(7) from t2m join t1m; + +select 1, min(a) from t1m where a=99; +select 1, min(a) from t1m where 1=99; +select 1, min(1) from t1m where a=99; +select 1, min(1) from t1m where 1=99; + +select 1, max(a) from t1m where a=99; +select 1, max(a) from t1m where 1=99; +select 1, max(1) from t1m where a=99; +select 1, max(1) from t1m where 1=99; + +# test with InnoDB +select min(a) from t1i; +select min(7) from t1i; +select min(7) from DUAL; +explain select min(7) from t2i join t1i; +select min(7) from t2i join t1i; + +select max(a) from t1i; +select max(7) from t1i; +select max(7) from DUAL; +explain select max(7) from t2i join t1i; +select max(7) from t2i join t1i; + +select 1, min(a) from t1i where a=99; +select 1, min(a) from t1i where 1=99; +select 1, min(1) from t1i where a=99; +select 1, min(1) from t1i where 1=99; + +select 1, max(a) from t1i where a=99; +select 1, max(a) from t1i where 1=99; +select 1, max(1) from t1i where a=99; +select 1, max(1) from t1i where 1=99; + +# mixed MyISAM/InnoDB test +explain select count(*), min(7), max(7) from t1m, t1i; +select count(*), min(7), max(7) from t1m, t1i; + +explain select count(*), min(7), max(7) from t1m, t2i; +select count(*), min(7), max(7) from t1m, t2i; + +explain select count(*), min(7), max(7) from t2m, t1i; +select count(*), min(7), max(7) from t2m, t1i; + +drop table t1m, t1i, t2m, t2i; + +# +# Bug #12672: primary key implcitly included in every innodb index +# (was part of group_min_max.test) +# + +create table t1 ( + a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' ' +); + +insert into t1 (a1, a2, b, c, d) values +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'), +('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'), +('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'), +('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'), +('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'), +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'), +('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'), +('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'), +('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'), +('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'); +--disable_warnings +create table t4 ( + pk_col int auto_increment primary key, a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' ' +) engine=innodb; +--enable_warnings +insert into t4 (a1, a2, b, c, d, dummy) select * from t1; + +create index idx12672_0 on t4 (a1); +create index idx12672_1 on t4 (a1,a2,b,c); +create index idx12672_2 on t4 (a1,a2,b); +analyze table t1; + +select distinct a1 from t4 where pk_col not in (1,2,3,4); + +drop table t1,t4; + +# +# Bug #6142: a problem with the empty innodb table +# (was part of group_min_max.test) +# + +--disable_warnings +create table t1 ( + a varchar(30), b varchar(30), primary key(a), key(b) +) engine=innodb; +--enable_warnings +select distinct a from t1; +drop table t1; + +# +# Bug #9798: group by with rollup +# (was part of group_min_max.test) +# + +--disable_warnings +create table t1(a int, key(a)) engine=innodb; +--enable_warnings +insert into t1 values(1); +select a, count(a) from t1 group by a with rollup; +drop table t1; + +# +# Bug #13293 Wrongly used index results in endless loop. +# (was part of group_min_max.test) +# +create table t1 (f1 int, f2 char(1), primary key(f1,f2)) engine=innodb; +insert into t1 values ( 1,"e"),(2,"a"),( 3,"c"),(4,"d"); +alter table t1 drop primary key, add primary key (f2, f1); +explain select distinct f1 a, f1 b from t1; +explain select distinct f1, f2 from t1; +drop table t1; + + # # Test of behaviour with CREATE ... SELECT # diff --git a/mysql-test/t/join_outer.test b/mysql-test/t/join_outer.test index c194213e0c9..dc4e240750c 100644 --- a/mysql-test/t/join_outer.test +++ b/mysql-test/t/join_outer.test @@ -779,3 +779,47 @@ SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id WHERE t1.name LIKE 'A%' OR FALSE; DROP TABLE t1,t2; + +# +# Bug 19396: LEFT OUTER JOIN over views in curly braces +# +--disable_warnings +DROP VIEW IF EXISTS v1,v2; +DROP TABLE IF EXISTS t1,t2; +--enable_warnings + +CREATE TABLE t1 (a int); +CREATE table t2 (b int); +INSERT INTO t1 VALUES (1), (2), (3), (4), (1), (1), (3); +INSERT INTO t2 VALUES (2), (3); + +CREATE VIEW v1 AS SELECT a FROM t1 JOIN t2 ON t1.a=t2.b; +CREATE VIEW v2 AS SELECT b FROM t2 JOIN t1 ON t2.b=t1.a; + +SELECT v1.a, v2. b + FROM v1 LEFT OUTER JOIN v2 ON (v1.a=v2.b) AND (v1.a >= 3) + GROUP BY v1.a; +SELECT v1.a, v2. b + FROM { OJ v1 LEFT OUTER JOIN v2 ON (v1.a=v2.b) AND (v1.a >= 3) } + GROUP BY v1.a; + +DROP VIEW v1,v2; +DROP TABLE t1,t2; + +# +# Bug 19816: LEFT OUTER JOIN with constant ORed predicates in WHERE clause +# + +CREATE TABLE t1 (a int); +CREATE TABLE t2 (b int); +INSERT INTO t1 VALUES (1), (2), (3), (4); +INSERT INTO t2 VALUES (2), (3); + +SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1=1); + +SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1 OR 1); +SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (0 OR 1); +SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1=1 OR 2=2); +SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1=1 OR 1=0); + +DROP TABLE t1,t2; diff --git a/mysql-test/t/lock_multi.test b/mysql-test/t/lock_multi.test index 3d07ec98d69..a24ee8be64e 100644 --- a/mysql-test/t/lock_multi.test +++ b/mysql-test/t/lock_multi.test @@ -126,3 +126,35 @@ show columns from t1; connection locker; unlock tables; drop table t1; + +# +# Bug#16986 - Deadlock condition with MyISAM tables +# +connection locker; +use mysql; +LOCK TABLES columns_priv WRITE, db WRITE, host WRITE, user WRITE; +FLUSH TABLES; +--sleep 1 +# +connection reader; +use mysql; +#NOTE: This must be a multi-table select, otherwise the deadlock will not occur +send SELECT user.Select_priv FROM user, db WHERE user.user = db.user LIMIT 1; +--sleep 1 +# +connection locker; +# Make test case independent from earlier grants. +--replace_result "Table is already up to date" "OK" +OPTIMIZE TABLES columns_priv, db, host, user; +UNLOCK TABLES; +# +connection reader; +reap; +use test; +# +connection locker; +use test; +# +connection default; + +# End of 5.0 tests diff --git a/mysql-test/t/log_tables.test b/mysql-test/t/log_tables.test index 048da802d02..5b79e5e4625 100644 --- a/mysql-test/t/log_tables.test +++ b/mysql-test/t/log_tables.test @@ -16,10 +16,10 @@ use mysql; # truncate table general_log; ---replace_column 1 TIMESTAMP +--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID select * from general_log; truncate table slow_log; ---replace_column 1 TIMESTAMP +--replace_column 1 TIMESTAMP 2 USER_HOST select * from slow_log; # @@ -31,7 +31,7 @@ select * from slow_log; # truncate table general_log; ---replace_column 1 TIMESTAMP +--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID select * from general_log where argument like '%general_log%'; @@ -47,6 +47,7 @@ insert into join_test values ("User performed a usual SQL query", "Query"); insert into join_test values ("New DB connection was registered", "Connect"); insert into join_test values ("Get the table info", "Field List"); +--replace_column 2 USER_HOST select verbose_comment, user_host, argument from mysql.general_log join join_test on (mysql.general_log.command_type = join_test.command_type); @@ -156,7 +157,7 @@ truncate table mysql.general_log; set names utf8; create table bug16905 (s char(15) character set utf8 default 'пуÑто'); insert into bug16905 values ('новое'); ---replace_column 1 TIMESTAMP +--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID select * from mysql.general_log; drop table bug16905; @@ -167,7 +168,7 @@ drop table bug16905; truncate table mysql.slow_log; set session long_query_time=1; select sleep(2); ---replace_column 1 TIMESTAMP, 3 USER_HOST, 4 QUERY_TIME +--replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME select * from mysql.slow_log; # kill all connections diff --git a/mysql-test/t/merge.test b/mysql-test/t/merge.test index 9fe7bb787cb..9fee4a03b81 100644 --- a/mysql-test/t/merge.test +++ b/mysql-test/t/merge.test @@ -382,3 +382,15 @@ check table t1, t2; drop table t1, t2, t3; # End of 4.1 tests + +# +# BUG#10952 - alter table ... lost data without errors and warnings +# +drop table if exists t1; +create table t1 (c char(20)) engine=MyISAM; +insert into t1 values ("Monty"),("WAX"),("Walrus"); +--error 1031 +alter table t1 engine=MERGE; +drop table t1; + +# End of 5.0 tests diff --git a/mysql-test/t/myisam.test b/mysql-test/t/myisam.test index 87a00399c23..a77537f3ff5 100644 --- a/mysql-test/t/myisam.test +++ b/mysql-test/t/myisam.test @@ -811,13 +811,6 @@ drop table t1, t2, t3; # Test of key_block_size # -# Old format, to be obsolete in 5.3 -create table t1 (a int not null, key `a` key_block_size=1024 (a)); -show create table t1; -drop table t1; - -set @@new=1; - create table t1 (a int not null, key `a` (a) key_block_size=1024); show create table t1; drop table t1; @@ -874,5 +867,6 @@ drop table t1; --error 1064 create table t1 (a int not null, key key_block_size=1024 (a)); +--error 1064 +create table t1 (a int not null, key `a` key_block_size=1024 (a)); -set @@new=0; diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test index e76553f42e7..ac4c323f51e 100644 --- a/mysql-test/t/mysql.test +++ b/mysql-test/t/mysql.test @@ -72,3 +72,11 @@ drop table t1; # --exec $MYSQL -t --default-character-set utf8 test -e "create table t1 (i int, j int not null, k int); insert into t1 values (null, 1, null); select * from t1; describe t1; drop table t1;" +# +# Bug#19564: mysql displays NULL instead of space +# +--exec $MYSQL -t test -e "create table b19564 (i int, s1 char(1)); insert into b19564 values (1, 'x'); insert into b19564 values (2, NULL); insert into b19564 values (3, ' '); select * from b19564 order by i; drop table b19564;" + +--echo End of 5.0 tests + + diff --git a/mysql-test/t/mysqlbinlog.test b/mysql-test/t/mysqlbinlog.test index 1bede1d5c9a..ceba78bf762 100644 --- a/mysql-test/t/mysqlbinlog.test +++ b/mysql-test/t/mysqlbinlog.test @@ -124,9 +124,19 @@ select HEX(f) from t3; select HEX(f) from t04; select HEX(f) from t4; +# +#BUG#14157: utf8 encoding in binlog without set character_set_client +# +flush logs; +--exec $MYSQL test -e 'create table if not exists t5 (a int); set names latin1; create temporary table `äöüÄÖÜ` (a int); insert into `äöüÄÖÜ` values (1); insert into t5 select * from `äöüÄÖÜ`' +# resulted binlog, parly consisting of multi-byte utf8 chars, +# must be digestable for both client and server. In 4.1 the client +# should use default-character-set same as the server. +--exec $MYSQL_BINLOG --short-form $MYSQLTEST_VARDIR/log/master-bin.000006 | $MYSQL +select * from t5 /* must be (1),(1) */; # clean up -drop table t1, t2, t03, t04, t3, t4; +drop table t1, t2, t03, t04, t3, t4, t5; -# End of 4.1 tests +# End of 5.0 tests diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index c5c3f88d8c8..1aef8f6c176 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -2,7 +2,7 @@ --source include/not_embedded.inc --disable_warnings -DROP TABLE IF EXISTS t1, `"t"1`, t1aa, t2, t2aa; +DROP TABLE IF EXISTS t1, `"t"1`, t1aa, t2, t2aa, t3; drop database if exists mysqldump_test_db; drop database if exists db1; drop database if exists db2; @@ -607,6 +607,13 @@ drop table t1, t2; drop database db1; # +# BUG#15328 Segmentation fault occured if my.cnf is invalid for escape sequence +# + +--exec $MYSQL_MY_PRINT_DEFAULTS --defaults-extra-file=$MYSQL_TEST_DIR/std_data/bug15328.cnf mysqldump + + +# # Bug #9558 mysqldump --no-data db t1 t2 format still dumps data # @@ -713,6 +720,46 @@ select * from t1; drop table t1; # +# BUG #19025 mysqldump doesn't correctly dump "auto_increment = [int]" +# +create table `t1` ( + t1_name varchar(255) default null, + t1_id int(10) unsigned not null auto_increment, + key (t1_name), + primary key (t1_id) +) auto_increment = 1000 default charset=latin1; + +insert into t1 (t1_name) values('bla'); +insert into t1 (t1_name) values('bla'); +insert into t1 (t1_name) values('bla'); + +select * from t1; + +show create table `t1`; + +--exec $MYSQL_DUMP --skip-comments test t1 > $MYSQLTEST_VARDIR/tmp/bug19025.sql +DROP TABLE `t1`; + +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug19025.sql + +select * from t1; + +show create table `t1`; + +drop table `t1`; + +# +# Bug #18536: wrong table order +# + +create table t1(a int); +create table t2(a int); +create table t3(a int); +--error 6 +--exec $MYSQL_DUMP --skip-comments --force --no-data test t3 t1 non_existing t2 +drop table t1, t2, t3; + +--echo End of 4.1 tests # Bug #13318: Bad result with empty field and --hex-blob # create table t1 (a binary(1), b blob); @@ -721,7 +768,6 @@ insert into t1 values ('',''); --exec $MYSQL_DUMP --skip-comments --hex-blob test t1 drop table t1; -# End of 4.1 tests # # dump of view @@ -1158,7 +1204,7 @@ select * from words2; # Drop table "words" and run with threads, should fail drop table words; ---replace_regex /.*mysqlimport/mysql-import/ +--replace_regex /.*mysqlimport(\.exe)*/mysql-import/ --error 1 --exec $MYSQL_IMPORT --silent --use-threads=2 test $MYSQLTEST_VARDIR/tmp/t1.txt $MYSQLTEST_VARDIR/tmp/t2.txt $MYSQLTEST_VARDIR/std_data_ln/words.dat $MYSQLTEST_VARDIR/std_data_ln/words2.dat 2>&1 diff --git a/mysql-test/t/ndb_alter_table.test b/mysql-test/t/ndb_alter_table.test index 29deea4aa0d..8e3b4a6ca89 100644 --- a/mysql-test/t/ndb_alter_table.test +++ b/mysql-test/t/ndb_alter_table.test @@ -3,7 +3,7 @@ -- source include/not_embedded.inc --disable_warnings -DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t1, t2; drop database if exists mysqltest; --enable_warnings @@ -383,3 +383,18 @@ LOAD DATA INFILE 'tmp.dat' INTO TABLE ndb_show_tables; select 'no_copy' from ndb_show_tables where id = @t1_id and name like '%t1%'; DROP TABLE t1, ndb_show_tables; + +# simple test that auto incr is not lost at rename or alter +create table t1 (a int primary key auto_increment, b int) engine=ndb; +insert into t1 (b) values (101),(102),(103); +select * from t1 where a = 3; +alter table t1 rename t2; +insert into t2 (b) values (201),(202),(203); +select * from t2 where a = 6; +alter table t2 add c int; +insert into t2 (b) values (301),(302),(303); +select * from t2 where a = 9; +alter table t2 rename t1; +insert into t1 (b) values (401),(402),(403); +select * from t1 where a = 12; +drop table t1; diff --git a/mysql-test/t/ndb_autodiscover3.test b/mysql-test/t/ndb_autodiscover3.test new file mode 100644 index 00000000000..ed75c89cdd1 --- /dev/null +++ b/mysql-test/t/ndb_autodiscover3.test @@ -0,0 +1,76 @@ +-- source include/have_ndb.inc +-- source include/have_multi_ndb.inc +-- source include/not_embedded.inc + + +--disable_warnings +drop table if exists t1, t2; +--enable_warnings + +# +# Transaction ongoing while cluster is restarted +# +--connection server1 +create table t1 (a int key) engine=ndbcluster; + +begin; +insert into t1 values (1); + +--exec $NDB_MGM --no-defaults -e "all restart" >> $NDB_TOOLS_OUTPUT +--exec $NDB_TOOLS_DIR/ndb_waiter --no-defaults >> $NDB_TOOLS_OUTPUT + +--error 1297 +insert into t1 values (2); +--error 1296 +commit; + +drop table t1; + +# +# Stale cache after restart -i +# +--connection server1 +create table t2 (a int, b int, primary key(a,b)) engine=ndbcluster; +insert into t2 values (1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1),(9,1),(10,1); +select * from t2 order by a limit 3; + +--exec $NDB_MGM --no-defaults -e "all restart -i" >> $NDB_TOOLS_OUTPUT +--exec $NDB_TOOLS_DIR/ndb_waiter --no-defaults >> $NDB_TOOLS_OUTPUT +# to ensure mysqld has connected again, and recreated system tables +--exec $NDB_TOOLS_DIR/ndb_desc --no-defaults -r 30 -d cluster apply_status >> $NDB_TOOLS_OUTPUT + +--connection server2 +--error ER_NO_SUCH_TABLE +select * from t2; +show tables like 't2'; +reset master; +create table t2 (a int key) engine=ndbcluster; +insert into t2 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); +select * from t2 order by a limit 3; + +# server 1 should have a stale cache, and in this case wrong frm, transaction must be retried +--connection server1 +select * from t2 order by a limit 3; +reset master; + +--exec $NDB_MGM --no-defaults -e "all restart -i" >> $NDB_TOOLS_OUTPUT +--exec $NDB_TOOLS_DIR/ndb_waiter --no-defaults >> $NDB_TOOLS_OUTPUT +# to ensure mysqld has connected again, and recreated system tables +--exec $NDB_TOOLS_DIR/ndb_desc --no-defaults -r 30 -d cluster apply_status >> $NDB_TOOLS_OUTPUT + +--connection server1 +--error ER_NO_SUCH_TABLE +select * from t2; +show tables like 't2'; +reset master; +create table t2 (a int key) engine=ndbcluster; +insert into t2 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); +select * from t2 order by a limit 3; + +# server 2 should have a stale cache, but with right frm, transaction need not be retried +--connection server2 +select * from t2 order by a limit 3; +reset master; + +drop table t2; +# End of 4.1 tests diff --git a/mysql-test/t/ndb_basic.test b/mysql-test/t/ndb_basic.test index edf74ab1df9..c7fa5aeee1e 100644 --- a/mysql-test/t/ndb_basic.test +++ b/mysql-test/t/ndb_basic.test @@ -6,17 +6,16 @@ DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; drop database if exists mysqltest; --enable_warnings -# workaround for bug#16445 -# remove to reproduce bug and run tests from ndb start -# and with ndb_autodiscover disabled. Fails on Linux 50 % of the times - -CREATE TABLE t1 ( - pk1 INT NOT NULL PRIMARY KEY, - attr1 INT NOT NULL, - attr2 INT, - attr3 VARCHAR(10) -) ENGINE=ndbcluster; -drop table t1; +## workaround for bug#16445 +## remove to reproduce bug and run tests from ndb start +## and with ndb_autodiscover disabled. Fails on Linux 50 % of the times +#CREATE TABLE t1 ( +# pk1 INT NOT NULL PRIMARY KEY, +# attr1 INT NOT NULL, +# attr2 INT, +# attr3 VARCHAR(10) +#) ENGINE=ndbcluster; +#drop table t1; # # Basic test to show that the NDB @@ -714,3 +713,17 @@ select * from t1 order by f1; select * from t1 order by f2; select * from t1 order by f3; drop table t1; + +# +# Bug #18483 Cannot create table with FK constraint +# ndb does not support foreign key constraint, it is silently ignored +# in line with other storage engines +# +CREATE TABLE t1 (a VARCHAR(255) NOT NULL, + CONSTRAINT pk_a PRIMARY KEY (a))engine=ndb; +CREATE TABLE t2(a VARCHAR(255) NOT NULL, + b VARCHAR(255) NOT NULL, + c VARCHAR(255) NOT NULL, + CONSTRAINT pk_b_c_id PRIMARY KEY (b,c), + CONSTRAINT fk_a FOREIGN KEY(a) REFERENCES t1(a))engine=ndb; +drop table t1, t2; diff --git a/mysql-test/t/ndb_blob.test b/mysql-test/t/ndb_blob.test index bf82a793049..d6e0edc89f0 100644 --- a/mysql-test/t/ndb_blob.test +++ b/mysql-test/t/ndb_blob.test @@ -428,4 +428,60 @@ truncate t1; select count(*) from t1; drop table t1; +# -- bug#19956 - var* key, complex key + +create table t1 ( + a varchar(40) not null, + b mediumint not null, + t text, + c varchar(2) not null, + d bigint not null, + primary key (a,b,c), + key (c,a), + unique key (d) +) engine=ndb; + +--disable_query_log +set @s1 = 'rggurloniukyehuxdbfkkyzlceixzrehqhvxvxbpwizzvjzpucqmzrhzxzfau'; +set @s2 = 'ykyymbzqgqlcjhlhmyqelfoaaohvtbekvifukdtnvcrrjveevfakxarxexomz'; +set @s3 = 'dbnfqyzgtqxalcrwtfsqabknvtfcbpoonxsjiqvmhnfikxxhcgoexlkoezvah'; +set @v1 = repeat(@s1,123); +set @v2 = repeat(@s2,234); +set @v3 = repeat(@s3,345); +set @v4 = NULL; +--enable_query_log + +insert into t1 (a,b,c,d,t) values ('a',1110,'a',1,@v1); +insert into t1 (a,b,c,d,t) values ('b',1110,'a',2,@v2); +insert into t1 (a,b,c,d,t) values ('a',1110,'b',3,@v3); +insert into t1 (a,b,c,d,t) values ('b',1110,'b',4,@v4); +select a,b,c,d,sha1(t) from t1 order by c,a; + +select a,b,c,d,sha1(t) from t1 where a='a' and b=1110 and c='a'; +select a,b,c,d,sha1(t) from t1 where a='a' and b=1110 and c='b'; + +update t1 set t=@v4 where a='b' and b=1110 and c='a'; +update t1 set t=@v2 where a='b' and b=1110 and c='b'; +select a,b,c,d,sha1(t) from t1 order by c,a; + +update t1 set t=@v2 where d=2; +update t1 set t=@v4 where d=4; +select a,b,c,d,sha1(t) from t1 order by c,a; + +update t1 set t=@v4 where a='b' and c='a'; +update t1 set t=@v2 where a='b' and c='b'; +select a,b,c,d,sha1(t) from t1 order by c,a; + +update t1 set t=@v2 where b+d=1112; +update t1 set t=@v4 where b+d=1114; +select a,b,c,d,sha1(t) from t1 order by c,a; + +delete from t1 where a='a' and b=1110 and c='a'; +delete from t1 where a='b' and c='a'; +delete from t1 where d=3; +delete from t1 where b+d=1114; +select count(*) from t1; + +drop table t1; + # End of 4.1 tests diff --git a/mysql-test/t/ndb_blob_partition.test b/mysql-test/t/ndb_blob_partition.test deleted file mode 100644 index a3948cc9491..00000000000 --- a/mysql-test/t/ndb_blob_partition.test +++ /dev/null @@ -1,93 +0,0 @@ ---source include/have_ndb.inc --- source include/not_embedded.inc - ---disable_warnings -drop table if exists t1; ---enable_warnings - -# -# Minimal NDB blobs test with range partitions. -# - -create table t1 ( - a mediumint not null, - b text not null, - c int not null, - d longblob, - primary key using hash (a,c), - unique key (c) -) - engine=ndb - partition by range (c) - partitions 3 - ( partition p1 values less than (200), - partition p2 values less than (300), - partition p3 values less than (400)); - ---disable_query_log -sleep 1; - -# length 61 -set @s0 = 'rggurloniukyehuxdbfkkyzlceixzrehqhvxvxbpwizzvjzpucqmzrhzxzfau'; -set @s1 = 'ykyymbzqgqlcjhlhmyqelfoaaohvtbekvifukdtnvcrrjveevfakxarxexomz'; -set @s2 = 'dbnfqyzgtqxalcrwtfsqabknvtfcbpoonxsjiqvmhnfikxxhcgoexlkoezvah'; - -set @v1 = repeat(@s0, 100); -- 1d42dd9090cf78314a06665d4ea938c35cc760f4 -set @v2 = repeat(@s1, 200); -- 10d3c783026b310218d10b7188da96a2401648c6 -set @v3 = repeat(@s2, 300); -- a33549d9844092289a58ac348dd59f09fc28406a -set @v4 = repeat(@s0, 400); -- daa61c6de36a0526f0d47dc29d6b9de7e6d2630c -set @v5 = repeat(@s1, 500); -- 70fc9a7d08beebc522258bfb02000a30c77a8f1d -set @v6 = repeat(@s2, 600); -- 090565c580809efed3d369481a4bbb168b20713e -set @v7 = repeat(@s0, 700); -- 1e0070bec426871a46291de27b9bd6e4255ab4e5 -set @v8 = repeat(@s1, 800); -- acbaba01bc2e682f015f40e79d9cbe475db3002e -set @v9 = repeat(@s2, 900); -- 9ee30d99162574f79c66ae95cdf132dcf9cbc259 ---enable_query_log - -# -- insert -- -insert into t1 values (1, @v1, 101, @v2); -insert into t1 values (1, @v2, 102, @v3); -insert into t1 values (1, @v3, 103, @v4); -insert into t1 values (2, @v4, 201, @v5); -insert into t1 values (2, @v5, 202, @v6); -insert into t1 values (2, @v6, 203, @v7); -insert into t1 values (3, @v7, 301, @v8); -insert into t1 values (3, @v8, 302, @v9); -insert into t1 values (3, @v9, 303, @v1); -select a, sha1(b), c, sha1(d) from t1 order by a; - -# -- pk read -- -select a, sha1(b), c, sha1(d) from t1 where a = 1 and c = 101; -select a, sha1(b), c, sha1(d) from t1 where a = 2 and c = 201; -select a, sha1(b), c, sha1(d) from t1 where a = 3 and c = 301; - -# -- pk update -- -update t1 set b = @v3, d = @v4 where a = 1 and c = 102; -update t1 set b = @v6, d = @v7 where a = 2 and c = 202; -update t1 set b = @v9, d = @v1 where a = 3 and c = 302; -select a, sha1(b), c, sha1(d) from t1 order by a; - -# -- hash index update -- -update t1 set b = @v4, d = @v5 where c = 103; -update t1 set b = @v7, d = @v8 where c = 203; -update t1 set b = @v1, d = @v2 where c = 303; -select a, sha1(b), c, sha1(d) from t1 order by a; - -# -- full scan update -- -update t1 set b = @v5, d = @v6; -select a, sha1(b), c, sha1(d) from t1 order by a; - -# -- range scan update -update t1 set b = @v1, d = @v2 where 100 < c and c < 200; -update t1 set b = @v4, d = @v5 where 200 < c and c < 300; -update t1 set b = @v7, d = @v8 where 300 < c and c < 400; -select a, sha1(b), c, sha1(d) from t1 order by a; - -# -- delete -- -delete from t1 where a = 1 and c = 101; -delete from t1 where c = 102; -# delete from t1 where c < 300; # XXX coredump -delete from t1; -select a, sha1(b), c, sha1(d) from t1 order by a; - -# -- clean up -- -drop table t1; diff --git a/mysql-test/t/ndb_condition_pushdown.test b/mysql-test/t/ndb_condition_pushdown.test index 44740c1a486..3b53f7b3431 100644 --- a/mysql-test/t/ndb_condition_pushdown.test +++ b/mysql-test/t/ndb_condition_pushdown.test @@ -1649,5 +1649,42 @@ set engine_condition_pushdown = on; explain select * from t5 where b like '%jo%'; select * from t5 where b like '%jo%' order by a; +# bug#17421 -1 +drop table t1; +create table t1 (a int, b varchar(3), primary key using hash(a)) +engine=ndb; +insert into t1 values (1,'a'), (2,'ab'), (3,'abc'); +# in TUP the constants 'ab' 'abc' were expected in varchar format +# "like" returned error which became "false" +# scan filter negates "or" which exposes the bug +set engine_condition_pushdown = off; +select * from t1 where b like 'ab'; +select * from t1 where b like 'ab' or b like 'ab'; +select * from t1 where b like 'abc'; +select * from t1 where b like 'abc' or b like 'abc'; +set engine_condition_pushdown = on; +select * from t1 where b like 'ab'; +select * from t1 where b like 'ab' or b like 'ab'; +select * from t1 where b like 'abc'; +select * from t1 where b like 'abc' or b like 'abc'; + +# bug#17421 -2 +drop table t1; +create table t1 (a int, b char(3), primary key using hash(a)) +engine=ndb; +insert into t1 values (1,'a'), (2,'ab'), (3,'abc'); +# test that incorrect MySQL behaviour is preserved +# 'ab ' LIKE 'ab' is true in MySQL +set engine_condition_pushdown = off; +select * from t1 where b like 'ab'; +select * from t1 where b like 'ab' or b like 'ab'; +select * from t1 where b like 'abc'; +select * from t1 where b like 'abc' or b like 'abc'; +set engine_condition_pushdown = on; +select * from t1 where b like 'ab'; +select * from t1 where b like 'ab' or b like 'ab'; +select * from t1 where b like 'abc'; +select * from t1 where b like 'abc' or b like 'abc'; + set engine_condition_pushdown = @old_ecpd; DROP TABLE t1,t2,t3,t4,t5; diff --git a/mysql-test/t/ndb_dd_backuprestore.test b/mysql-test/t/ndb_dd_backuprestore.test index be6d73e27b4..1508cccb46d 100644 --- a/mysql-test/t/ndb_dd_backuprestore.test +++ b/mysql-test/t/ndb_dd_backuprestore.test @@ -159,185 +159,15 @@ DROP TABLE test.t1; DROP TABLE test.t2; DROP TABLE test.t3; DROP TABLE test.t4; -###################### Adding partition ################################# --- echo **** Test 3 Adding partition Test backup and restore **** - -CREATE TABLESPACE table_space2 -ADD DATAFILE './table_space2/datafile.dat' -USE LOGFILE GROUP log_group1 -INITIAL_SIZE 12M -ENGINE NDB; - -CREATE TABLE test.t1 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 VARCHAR(150) NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))TABLESPACE table_space1 STORAGE DISK ENGINE=NDB PARTITION BY HASH(c3) PARTITIONS 4; - -CREATE TABLE test.t4 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 VARCHAR(180) NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))ENGINE=NDB PARTITION BY HASH(c3) PARTITIONS 2; - -CREATE TABLE test.t2 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 TEXT NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))TABLESPACE table_space2 STORAGE DISK ENGINE=NDB PARTITION BY KEY(c3) (PARTITION p0 ENGINE = NDB, PARTITION p1 ENGINE = NDB); - -CREATE TABLE test.t5 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 TEXT NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))ENGINE=NDB PARTITION BY KEY(pk1) (PARTITION p0 ENGINE = NDB, PARTITION p1 ENGINE = NDB); - -CREATE TABLE test.t3 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 VARCHAR(202) NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))TABLESPACE table_space2 STORAGE DISK ENGINE=NDB PARTITION BY RANGE (c3) PARTITIONS 3 (PARTITION x1 VALUES LESS THAN (105), PARTITION x2 VALUES LESS THAN (333), PARTITION x3 VALUES LESS THAN (720)); - -CREATE TABLE test.t6 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 VARCHAR(220) NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))ENGINE=NDB PARTITION BY RANGE (pk1) PARTITIONS 2 (PARTITION x1 VALUES LESS THAN (333), PARTITION x2 VALUES LESS THAN (720)); - -SHOW CREATE TABLE test.t1; - -SHOW CREATE TABLE test.t2; - -SHOW CREATE TABLE test.t3; - -SHOW CREATE TABLE test.t4; - -SHOW CREATE TABLE test.t5; - -SHOW CREATE TABLE test.t6; - -SELECT * FROM information_schema.partitions WHERE table_name= 't1'; - -SELECT * FROM information_schema.partitions WHERE table_name= 't2'; - -SELECT * FROM information_schema.partitions WHERE table_name= 't3'; - -SELECT * FROM information_schema.partitions WHERE table_name= 't4'; - -SELECT * FROM information_schema.partitions WHERE table_name= 't5'; - -SELECT * FROM information_schema.partitions WHERE table_name= 't6'; - - -let $j= 500; ---disable_query_log -while ($j) -{ - eval INSERT INTO test.t1 VALUES (NULL, "Sweden, Texas", $j, b'0'); - eval INSERT INTO test.t4 VALUES (NULL, "Sweden, Texas", $j, b'0'); - dec $j; - eval INSERT INTO test.t2 VALUES (NULL, "Sweden, Texas, ITALY, Kyle, JO, JBM,TU", $j, b'1'); - eval INSERT INTO test.t5 VALUES (NULL, "Sweden, Texas, ITALY, Kyle, JO, JBM,TU", $j, b'1'); - dec $j; - eval INSERT INTO test.t3 VALUES (NULL, "TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU", $j, b'1'); - eval INSERT INTO test.t6 VALUES (NULL, "TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU", $j, b'1'); } --enable_query_log - -SELECT COUNT(*) FROM test.t1; - -SELECT pk1, c2, c3, hex(c4) FROM test.t1 ORDER BY c3 LIMIT 5; - -SELECT COUNT(*) FROM test.t2; - -SELECT pk1, c2, c3, hex(c4) FROM test.t2 ORDER BY c3 LIMIT 5; - -SELECT COUNT(*) FROM test.t3; - -SELECT pk1, c2, c3, hex(c4) FROM test.t3 ORDER BY c3 LIMIT 5; - -SELECT COUNT(*) FROM test.t4; - -SELECT pk1, c2, c3, hex(c4) FROM test.t4 ORDER BY c3 LIMIT 5; - -SELECT COUNT(*) FROM test.t5; - -SELECT pk1, c2, c3, hex(c4) FROM test.t5 ORDER BY c3 LIMIT 5; - -SELECT COUNT(*) FROM test.t6; - -SELECT pk1, c2, c3, hex(c4) FROM test.t6 ORDER BY c3 LIMIT 5; - --- source include/ndb_backup.inc - -DROP TABLE test.t1; -DROP TABLE test.t2; -DROP TABLE test.t3; -DROP TABLE test.t4; -DROP TABLE test.t5; -DROP TABLE test.t6; ALTER TABLESPACE table_space1 DROP DATAFILE './table_space1/datafile.dat' ENGINE = NDB; -ALTER TABLESPACE table_space2 -DROP DATAFILE './table_space2/datafile.dat' -ENGINE = NDB; - DROP TABLESPACE table_space1 ENGINE = NDB; -DROP TABLESPACE table_space2 -ENGINE = NDB; - DROP LOGFILE GROUP log_group1 ENGINE =NDB; --- source include/ndb_restore_master.inc - - -SHOW CREATE TABLE test.t1; - -SHOW CREATE TABLE test.t2; - -SHOW CREATE TABLE test.t3; - -SHOW CREATE TABLE test.t4; - -SHOW CREATE TABLE test.t5; - -SHOW CREATE TABLE test.t6; - -SELECT * FROM information_schema.partitions WHERE table_name= 't1'; - -SELECT * FROM information_schema.partitions WHERE table_name= 't2'; - -SELECT * FROM information_schema.partitions WHERE table_name= 't3'; - -SELECT * FROM information_schema.partitions WHERE table_name= 't4'; - -SELECT * FROM information_schema.partitions WHERE table_name= 't5'; - -SELECT * FROM information_schema.partitions WHERE table_name= 't6'; - -SELECT COUNT(*) FROM test.t1; - -SELECT pk1, c2, c3, hex(c4) FROM test.t1 ORDER BY c3 LIMIT 5; - -SELECT COUNT(*) FROM test.t2; - -SELECT pk1, c2, c3, hex(c4) FROM test.t2 ORDER BY c3 LIMIT 5; - -SELECT COUNT(*) FROM test.t3; - -SELECT pk1, c2, c3, hex(c4) FROM test.t3 ORDER BY c3 LIMIT 5; - -SELECT COUNT(*) FROM test.t4; - -SELECT pk1, c2, c3, hex(c4) FROM test.t4 ORDER BY c3 LIMIT 5; - -SELECT COUNT(*) FROM test.t5; - -SELECT pk1, c2, c3, hex(c4) FROM test.t5 ORDER BY c3 LIMIT 5; - -SELECT COUNT(*) FROM test.t6; - -SELECT pk1, c2, c3, hex(c4) FROM test.t6 ORDER BY c3 LIMIT 5; - -# Cleanup - -DROP TABLE test.t1; -DROP TABLE test.t2; -DROP TABLE test.t3; -DROP TABLE test.t4; -DROP TABLE test.t5; -DROP TABLE test.t6; - -ALTER TABLESPACE table_space1 DROP DATAFILE './table_space1/datafile.dat' ENGINE=NDB; - -ALTER TABLESPACE table_space2 DROP DATAFILE './table_space2/datafile.dat' ENGINE=NDB; - -DROP TABLESPACE table_space1 ENGINE = NDB; - -DROP TABLESPACE table_space2 ENGINE = NDB; - -DROP LOGFILE GROUP log_group1 ENGINE = NDB; - #End 5.1 test case - - diff --git a/mysql-test/t/ndb_index_unique.test b/mysql-test/t/ndb_index_unique.test index 700ff55c2d5..a40efc8a40c 100644 --- a/mysql-test/t/ndb_index_unique.test +++ b/mysql-test/t/ndb_index_unique.test @@ -72,7 +72,7 @@ CREATE TABLE t2 ( a int unsigned NOT NULL PRIMARY KEY, b int unsigned not null, c int unsigned not null, - UNIQUE USING HASH (b, c) + UNIQUE (b, c) USING HASH ) engine=ndbcluster; insert t2 values(1, 2, 3), (2, 3, 5), (3, 4, 6), (4, 5, 8), (5,6, 2), (6,7, 2); @@ -96,7 +96,7 @@ CREATE TABLE t2 ( a int unsigned NOT NULL PRIMARY KEY, b int unsigned not null, c int unsigned, - UNIQUE USING HASH (b, c) + UNIQUE (b, c) USING HASH ) engine=ndbcluster; # @@ -107,7 +107,7 @@ CREATE TABLE t3 ( a int unsigned NOT NULL, b int unsigned not null, c int unsigned, - PRIMARY KEY USING HASH (a, b) + PRIMARY KEY (a, b) USING HASH ) engine=ndbcluster; insert t3 values(1, 2, 3), (2, 3, 5), (3, 4, 6), (4, 5, 8), (5,6, 2), (6,7, 2); diff --git a/mysql-test/t/ndb_partition_error.test b/mysql-test/t/ndb_partition_error.test deleted file mode 100644 index 06581f1270f..00000000000 --- a/mysql-test/t/ndb_partition_error.test +++ /dev/null @@ -1,71 +0,0 @@ --- source include/have_ndb.inc -#--disable_abort_on_error -# -# Simple test for the partition storage engine -# Focuses on range partitioning tests -# -#-- source include/have_partition.inc - ---disable_warnings -drop table if exists t1; ---enable_warnings - -# -# Partition by range, generate node group error -# ---error 1005 -CREATE TABLE t1 ( -a int not null, -b int not null, -c int not null, -primary key(a,b), -index (a)) -engine = ndb -partition by range (a) -partitions 3 -(partition x1 values less than (5) nodegroup 12, - partition x2 values less than (10) nodegroup 13, - partition x3 values less than (20) nodegroup 14); -show warnings; - -# -# Partition by range, create normal valid table -# -CREATE TABLE t1 ( -a int not null, -b int not null, -c int not null, -primary key(a)) -engine = ndb -partition by range (a) -partitions 3 -(partition x1 values less than (5), - partition x2 values less than (10), - partition x3 values less than (20)); - -drop table t1; - -# -# Bug #17763 mysqld cores with list partitioning if update to missing partition -# -CREATE TABLE t1 (id INT) ENGINE=NDB - PARTITION BY LIST(id) - (PARTITION p0 VALUES IN (2, 4), - PARTITION p1 VALUES IN (42, 142)); -INSERT INTO t1 VALUES (2); ---error ER_NO_PARTITION_FOR_GIVEN_VALUE -UPDATE t1 SET id=5 WHERE id=2; -DROP TABLE t1; - -# -# NULL for LIST partition -# -create table t1 (a int,b int, c int) -engine = ndb -partition by list(a) -partitions 2 -(partition x123 values in (11, 12), - partition x234 values in (5, 1)); ---error ER_NO_PARTITION_FOR_GIVEN_VALUE -insert into t1 values (NULL,1,1); -drop table t1; diff --git a/mysql-test/t/ndb_partition_key.test b/mysql-test/t/ndb_partition_key.test deleted file mode 100644 index ce939663ab8..00000000000 --- a/mysql-test/t/ndb_partition_key.test +++ /dev/null @@ -1,198 +0,0 @@ --- source include/have_ndb.inc - ---disable_warnings -DROP TABLE IF EXISTS t1; ---enable_warnings - -# -# Basic syntax test -# - -# Support for partition key verified -CREATE TABLE t1 (a int, b int, c int, d int, PRIMARY KEY(a,b,c)) - ENGINE = NDB - PARTITION BY KEY (a,b); - -insert into t1 values (1,1,1,1); -select * from t1; -update t1 set d = 2 where a = 1 and b = 1 and c = 1; -select * from t1; -delete from t1; -select * from t1; - -drop table t1; - -# only support for partition key on primary key ---error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF -CREATE TABLE t1 (a int, b int, c int, d int, PRIMARY KEY(a,b)) - ENGINE = NDB - PARTITION BY KEY (c); - -CREATE TABLE t1 (a int, b int, c int, PRIMARY KEY(a,b)) - ENGINE = NDB - PARTITION BY KEY (a); - -insert into t1 values - (1,1,3),(1,2,3),(1,3,3),(1,4,3),(1,5,3),(1,6,3), - (1,7,3),(1,8,3),(1,9,3),(1,10,3),(1,11,3),(1,12,3); - -select * from t1 order by b; - -DROP TABLE t1; - -# -# Test partition and char support -# - -CREATE TABLE t1 (a INT, b CHAR(10) COLLATE latin1_bin, c INT, d INT, - PRIMARY KEY USING HASH (a,b,c)) - ENGINE=NDB - DEFAULT CHARSET=latin1 - PARTITION BY KEY (b); - -insert into t1 values (1,"a",1,1),(2,"a",1,1),(3,"a",1,1); - -# should show only one attribute with DISTRIBUTION KEY ---exec $NDB_TOOLS_DIR/ndb_desc --no-defaults -d test t1 | sed 's/Version: [0-9]*//' | sed 's/\(Length of frm data: \)[0-9]*/\1#/' - -# -# Test that explicit partition info is not shown in show create table -# result should not contain (PARTITION P0 ... etc) since this is what shows up in -# mysqldump, and we don't want that info there -# -show create table t1; - -DROP TABLE t1; - -# -# Bug #13155: Problem in Create Table using SHOW CREATE TABLE syntax -# -CREATE TABLE t1 (a int not null primary key) -PARTITION BY KEY(a) -(PARTITION p0 ENGINE = NDB, PARTITION p1 ENGINE = NDB); - -drop table t1; - -CREATE TABLE t1 (a int not null primary key); -ALTER TABLE t1 -PARTITION BY KEY(a) -(PARTITION p0 ENGINE = NDB, PARTITION p1 ENGINE = NDB); - -drop table t1; - -# -# Bug #17754 Improper handling of removal of partitioning in ALTER TABLE -# Also added a number of general test cases in the same area -# -create table t1 (a int) -engine=ndb -partition by key(a) -(partition p0, partition p1); -show create table t1; - -alter table t1 engine=heap; -show create table t1; - -alter table t1 engine=ndb; -show create table t1; - -alter table t1 engine=heap remove partitioning; -show create table t1; - -alter table t1 engine=ndb -partition by key(a) -(partition p0, partition p1 engine = ndb); -show create table t1; - -alter table t1 -partition by key (a) -(partition p0 engine=ndb, partition p1 engine=ndb); -show create table t1; - -alter table t1 remove partitioning; -show create table t1; - ---error ER_MIX_HANDLER_ERROR -alter table t1 -partition by key(a) -(partition p0 engine=ndb, partition p1); - -alter table t1 -engine=ndb -partition by key(a) -(partition p0 engine=ndb, partition p1 engine = ndb); -show create table t1; - -drop table t1; - -# -# BUG 16810 Out of memory when coalesce partition -# -CREATE TABLE t1 ( - c1 MEDIUMINT NOT NULL AUTO_INCREMENT, - c2 TEXT NOT NULL, - c3 INT NOT NULL, - c4 BIT NOT NULL, - c5 FLOAT, - c6 VARCHAR(255), - c7 TIMESTAMP, - PRIMARY KEY(c1,c3)) - ENGINE=NDB - PARTITION BY KEY(c3) PARTITIONS 5; - -let $j= 11; ---disable_query_log -while ($j) -{ - eval INSERT INTO t1 VALUES (NULL, "Tested Remotely from Texas, USA", $j, -b'0', - $j.00,"By JBM $j","2006-01-26"); - dec $j; -} ---enable_query_log -ALTER TABLE t1 COALESCE PARTITION 4; - -DROP TABLE t1; - -# -# Bug 16822: OPTIMIZE TABLE hangs test -# -CREATE TABLE t1 (a int primary key) -ENGINE=NDB -PARTITION BY KEY(a); ---error 1031 -ALTER TABLE t1 OPTIMIZE PARTITION p0; ---error 1031 -ALTER TABLE t1 CHECK PARTITION p0; ---error 1031 -ALTER TABLE t1 REPAIR PARTITION p0; ---error 1031 -ALTER TABLE t1 ANALYZE PARTITION p0; ---error 1031 -ALTER TABLE t1 REBUILD PARTITION p0; -DROP TABLE t1; - -# -# BUG 16806: ALTER TABLE fails -# -CREATE TABLE t1 ( - c1 MEDIUMINT NOT NULL AUTO_INCREMENT, - c2 TEXT NOT NULL, - c3 INT NOT NULL, - PRIMARY KEY(c1,c3)) - ENGINE=NDB - PARTITION BY KEY(c3) PARTITIONS 5; - -ALTER TABLE t1 ADD COLUMN c4 INT AFTER c1; -DROP TABLE t1; - -CREATE TABLE t1 ( - c1 MEDIUMINT NOT NULL AUTO_INCREMENT, - c2 TEXT NOT NULL, - c3 INT NOT NULL, - PRIMARY KEY(c1,c3)) - ENGINE=NDB - PARTITION BY KEY(c3); - -ALTER TABLE t1 ADD COLUMN c4 INT AFTER c1; -DROP TABLE t1; diff --git a/mysql-test/t/ndb_partition_list.test b/mysql-test/t/ndb_partition_list.test deleted file mode 100644 index 2ad37b8768c..00000000000 --- a/mysql-test/t/ndb_partition_list.test +++ /dev/null @@ -1,64 +0,0 @@ ---source include/have_ndb.inc -# -# Simple test for the partition storage engine -# Focuses on range partitioning tests -# -#-- source include/have_partition.inc - ---disable_warnings -drop table if exists t1; ---enable_warnings - -# -# Partition by list, basic -# - -CREATE TABLE t1 ( f_int1 INTEGER NOT NULL, f_int2 INTEGER NOT NULL, - f_char1 CHAR(10), - f_char2 CHAR(10), f_charbig VARCHAR(1000), -PRIMARY KEY (f_int1,f_int2)) -ENGINE = NDB -PARTITION BY LIST(MOD(f_int1 + f_int2,4)) -(PARTITION part_3 VALUES IN (-3), - PARTITION part_2 VALUES IN (-2), - PARTITION part_1 VALUES IN (-1), - PARTITION part0 VALUES IN (0), - PARTITION part1 VALUES IN (1), - PARTITION part2 VALUES IN (2), - PARTITION part3 VALUES IN (3,4,5)); - -INSERT INTO t1 SET f_int1 = -2, f_int2 = 20, f_char1 = '20', f_char2 = '20', f_charbig = '===20==='; -INSERT INTO t1 SET f_int1 = 1, f_int2 = 1, f_char1 = '1', f_char2 = '1', f_charbig = '===1==='; -INSERT INTO t1 SET f_int1 = 2, f_int2 = 1, f_char1 = '1', f_char2 = '1', f_charbig = '===1==='; -INSERT INTO t1 SET f_int1 = 3, f_int2 = 1, f_char1 = '1', f_char2 = '1', f_charbig = '===1==='; -INSERT INTO t1 SET f_int1 = 4, f_int2 = 1, f_char1 = '1', f_char2 = '1', f_charbig = '===1==='; -INSERT INTO t1 SET f_int1 = 5, f_int2 = 1, f_char1 = '1', f_char2 = '1', f_charbig = '===1==='; -INSERT INTO t1 SET f_int1 = 20, f_int2 = 1, f_char1 = '1', f_char2 = '1', f_charbig = '===1==='; - -SELECT * FROM t1 ORDER BY f_int1; - -DROP TABLE t1; - -# -# Partition by list, no pk -# - -CREATE TABLE t1 ( f_int1 INTEGER, f_int2 INTEGER, f_char1 CHAR(10), - f_char2 CHAR(10), f_charbig VARCHAR(1000)) -ENGINE = NDB -PARTITION BY LIST(f_int1) -(PARTITION part_1 VALUES IN (-1), - PARTITION part0 VALUES IN (0,1), - PARTITION part1 VALUES IN (2)); - -INSERT INTO t1 SET f_int1 = -1, f_int2 = 20, f_char1 = '20', f_char2 = '20', f_charbig = '===20==='; -INSERT INTO t1 SET f_int1 = 0, f_int2 = 20, f_char1 = '20', f_char2 = '20', f_charbig = '===20==='; -INSERT INTO t1 SET f_int1 = 1, f_int2 = 1, f_char1 = '1', f_char2 = '1', f_charbig = '===1==='; -INSERT INTO t1 SET f_int1 = 2, f_int2 = 1, f_char1 = '1', f_char2 = '1', f_charbig = '===1==='; ---error ER_NO_PARTITION_FOR_GIVEN_VALUE -INSERT INTO t1 SET f_int1 = 20, f_int2 = 1, f_char1 = '1', f_char2 = '1', f_charbig = '===1==='; - -SELECT * FROM t1 ORDER BY f_int1; - -DROP TABLE t1; - diff --git a/mysql-test/t/ndb_partition_range.test b/mysql-test/t/ndb_partition_range.test deleted file mode 100644 index 981467d4055..00000000000 --- a/mysql-test/t/ndb_partition_range.test +++ /dev/null @@ -1,260 +0,0 @@ --- source include/have_ndb.inc -#--disable_abort_on_error -# -# Simple test for the partition storage engine -# Focuses on range partitioning tests -# -#-- source include/have_partition.inc - ---disable_warnings -drop table if exists t1; ---enable_warnings - -# -# Partition by range, basic -# -CREATE TABLE t1 ( -a int not null, -b int not null, -c int not null, -primary key(a,b), -index (a)) -engine = ndb -partition by range (a) -partitions 3 -(partition x1 values less than (5), - partition x2 values less than (10), - partition x3 values less than (20)); - -# Simple insert and verify test -INSERT into t1 values (1, 1, 1); -INSERT into t1 values (6, 1, 1); -INSERT into t1 values (10, 1, 1); -INSERT into t1 values (15, 1, 1); - ---replace_column 16 # 19 # 20 # -select * from information_schema.partitions where table_name= 't1'; - -select * from t1 order by a; - -select * from t1 where a=1 order by a; -select * from t1 where a=15 and b=1 order by a; -select * from t1 where a=21 and b=1 order by a; -select * from t1 where a=21 order by a; -select * from t1 where a in (1,6,10,21) order by a; -select * from t1 where b=1 and a in (1,6,10,21) order by a; - -drop table t1; - -# -# Partition by range, basic -# -CREATE TABLE t1 ( -a int not null, -b int not null, -c int not null, -primary key(b), -unique (a)) -engine = ndb -partition by range (b) -partitions 3 -(partition x1 values less than (5), - partition x2 values less than (10), - partition x3 values less than (20)); - -# Simple insert and verify test -INSERT into t1 values (1, 1, 1); -INSERT into t1 values (2, 6, 1); -INSERT into t1 values (3, 10, 1); -INSERT into t1 values (4, 15, 1); - -select * from t1 order by a; -UPDATE t1 set a = 5 WHERE b = 15; -select * from t1 order by a; -UPDATE t1 set a = 6 WHERE a = 5; -select * from t1 order by a; - -select * from t1 where b=1 order by b; -select * from t1 where b=15 and a=1 order by b; -select * from t1 where b=21 and a=1 order by b; -select * from t1 where b=21 order by b; -select * from t1 where b in (1,6,10,21) order by b; -select * from t1 where a in (1,2,5,6) order by b; -select * from t1 where a=1 and b in (1,6,10,21) order by b; - -DELETE from t1 WHERE b = 6; -DELETE from t1 WHERE a = 6; - -# -# Test that explicit partition info _is_ shown in show create table -# result _should_ contain (PARTITION x1 ... etc) -# -show create table t1; - -drop table t1; - -# -# Bug #17499, #17687 -# Alter partitioned NDB table causes mysqld to core -# - -CREATE TABLE t1 - (id MEDIUMINT NOT NULL, - b1 BIT(8), - vc VARCHAR(255), - bc CHAR(255), - d DECIMAL(10,4) DEFAULT 0, - f FLOAT DEFAULT 0, - total BIGINT UNSIGNED, - y YEAR, - t DATE) ENGINE=NDB - PARTITION BY RANGE (YEAR(t)) - (PARTITION p0 VALUES LESS THAN (1901), - PARTITION p1 VALUES LESS THAN (1946), - PARTITION p2 VALUES LESS THAN (1966), - PARTITION p3 VALUES LESS THAN (1986), - PARTITION p4 VALUES LESS THAN (2005), - PARTITION p5 VALUES LESS THAN MAXVALUE); - -INSERT INTO t1 VALUES (0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); -SELECT * FROM t1; -ALTER TABLE t1 ENGINE=MYISAM; -SELECT * FROM t1; -DROP TABLE t1; - -CREATE LOGFILE GROUP lg1 - ADD UNDOFILE 'undofile.dat' - INITIAL_SIZE 16M - UNDO_BUFFER_SIZE=1M - ENGINE=NDB; - -CREATE TABLESPACE ts1 - ADD DATAFILE 'datafile.dat' - USE LOGFILE GROUP lg1 - INITIAL_SIZE 12M - ENGINE NDB; - -CREATE TABLE test.t1 ( - a1 INT, - a2 TEXT NOT NULL, - a3 BIT NOT NULL, - a4 DECIMAL(8,3), - a5 INT NOT NULL, - a6 INT, - PRIMARY KEY(a1)) - TABLESPACE ts1 STORAGE DISK ENGINE=NDB - PARTITION BY LIST (a1) - (PARTITION p0 VALUES IN (1,2,3,4,5), - PARTITION p1 VALUES IN (6,7,8,9, 10), - PARTITION p2 VALUES IN (11, 12, 13, 14, 15)); - -# Alter table directly without any statements inbetween -ALTER TABLE test.t1 DROP COLUMN a6; -ALTER TABLE test.t1 ADD COLUMN a6 VARCHAR(255); - -let $j= 15; ---disable_query_log -while ($j) -{ -eval INSERT INTO test.t1 VALUES ($j, "Tested Remotely from Texas, USA", -b'1',$j.00,$j+1,"By NIK $j"); -dec $j; -} ---enable_query_log -SELECT COUNT(*) FROM test.t1; - -ALTER TABLE test.t1 DROP COLUMN a4; -SELECT COUNT(*) FROM test.t1; - -DROP TABLE t1; - -CREATE TABLE test.t1 ( - a1 INT, - a2 TEXT NOT NULL, - a3 BIT NOT NULL, - a4 DECIMAL(8,3), - a5 INT NOT NULL, - a6 VARCHAR(255), - PRIMARY KEY(a1)) - TABLESPACE ts1 STORAGE DISK ENGINE=NDB - PARTITION BY HASH(a1) - PARTITIONS 4; - -let $j= 15; ---disable_query_log -while ($j) -{ -eval INSERT INTO test.t1 VALUES ($j, "Tested Remotely from Texas, USA", -b'1',$j.00,$j+1,"By NIK $j"); -dec $j; -} ---enable_query_log -SELECT COUNT(*) FROM test.t1; - -ALTER TABLE test.t1 DROP COLUMN a4; -SELECT COUNT(*) FROM test.t1; - -DROP TABLE t1; - -ALTER TABLESPACE ts1 - DROP DATAFILE 'datafile.dat' - ENGINE=NDB; -DROP TABLESPACE ts1 ENGINE=NDB; -DROP LOGFILE GROUP lg1 ENGINE=NDB; - - -# -# Bug #17701 ALTER TABLE t1 ADD PARTITION for PARTITION BY LIST hangs test -# - -CREATE TABLE t1 - (id MEDIUMINT NOT NULL, - b1 BIT(8), - vc VARCHAR(255), - bc CHAR(255), - d DECIMAL(10,4) DEFAULT 0, - f FLOAT DEFAULT 0, - total BIGINT UNSIGNED, - y YEAR, - t DATE) ENGINE=NDB - PARTITION BY LIST(id) - (PARTITION p0 VALUES IN (2, 4), - PARTITION p1 VALUES IN (42, 142)); - -INSERT INTO t1 VALUES (2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); -SELECT * FROM t1; -ALTER TABLE t1 ADD PARTITION - (PARTITION p2 VALUES IN (412)); -SELECT * FROM t1; -DROP TABLE t1; - -# -# Bug #17806 Update on NDB table with list partition causes mysqld to core -# Bug #16385 Partitions: crash when updating a range partitioned NDB table -# -CREATE TABLE t1 ( -a int not null, -b int not null, -c int not null) -partition by list(a) -partitions 2 -(partition x123 values in (1,5,6), - partition x234 values in (4,7,8)); -INSERT into t1 VALUES (5,1,1); -select * from t1; -UPDATE t1 SET a=8 WHERE a=5 AND b=1; -select * from t1; -drop table t1; - -CREATE TABLE t1 ( f1 INTEGER, f2 char(20)) engine=ndb -PARTITION BY RANGE(f1) -( PARTITION part1 VALUES LESS THAN (2), -PARTITION part2 VALUES LESS THAN (1000)); -INSERT INTO t1 VALUES(1, '---1---'); -INSERT INTO t1 VALUES(2, '---2---'); -select * from t1 order by f1; -UPDATE t1 SET f1 = f1 + 4 WHERE f1 = 2; -select * from t1 order by f1; -UPDATE t1 SET f1 = f1 + 4 WHERE f1 = 1; -select * from t1 order by f1; -drop table t1; diff --git a/mysql-test/t/ndb_rename.test b/mysql-test/t/ndb_rename.test new file mode 100644 index 00000000000..7f9fd0e6984 --- /dev/null +++ b/mysql-test/t/ndb_rename.test @@ -0,0 +1,36 @@ +-- source include/have_ndb.inc +-- source include/not_embedded.inc + +--disable_warnings +DROP TABLE IF EXISTS t1,t2; +drop database if exists mysqltest; +--enable_warnings + +# +# Table rename tests +# + +# +# Create a normal table with primary key +# +CREATE TABLE t1 ( + pk1 INT NOT NULL PRIMARY KEY, + attr1 INT NOT NULL, + attr2 INT, + attr3 VARCHAR(10), + INDEX i1(attr1) +) ENGINE=ndbcluster; + +INSERT INTO t1 VALUES (0,0,0,"zero"),(1,1,1,"one"),(2,2,2,"two"); +SELECT * FROM t1 WHERE attr1 = 1; +alter table t1 rename t2; +SELECT * FROM t2 WHERE attr1 = 1; + +create database ndbtest; +alter table t2 rename ndbtest.t2; +SELECT * FROM ndbtest.t2 WHERE attr1 = 1; + +drop table ndbtest.t2; +drop database ndbtest; + +# End of 4.1 tests diff --git a/mysql-test/t/openssl_1.test b/mysql-test/t/openssl_1.test index 4cc9113048f..afee381f5b7 100644 --- a/mysql-test/t/openssl_1.test +++ b/mysql-test/t/openssl_1.test @@ -10,8 +10,8 @@ insert into t1 values (5); grant select on test.* to ssl_user1@localhost require SSL; grant select on test.* to ssl_user2@localhost require cipher "DHE-RSA-AES256-SHA"; -grant select on test.* to ssl_user3@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "/C=SE/L=Uppsala/O=MySQL AB/CN=MySQL Client/Email=abstract.mysql.developer@mysql.com"; -grant select on test.* to ssl_user4@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "/C=SE/L=Uppsala/O=MySQL AB/CN=MySQL Client/Email=abstract.mysql.developer@mysql.com" ISSUER "/C=SE/L=Uppsala/O=MySQL AB/CN=Abstract MySQL Developer/Email=abstract.mysql.developer@mysql.com"; +grant select on test.* to ssl_user3@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "/C=SE/L=Uppsala/O=MySQL AB/CN=MySQL Client/emailAddress=abstract.mysql.developer@mysql.com"; +grant select on test.* to ssl_user4@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "/C=SE/L=Uppsala/O=MySQL AB/CN=MySQL Client/emailAddress=abstract.mysql.developer@mysql.com" ISSUER "/C=SE/L=Uppsala/O=MySQL AB/CN=Abstract MySQL Developer/emailAddress=abstract.mysql.developer@mysql.com"; flush privileges; connect (con1,localhost,ssl_user1,,,,,SSL); @@ -54,3 +54,41 @@ ssl_user3@localhost, ssl_user4@localhost; drop table t1; # End of 4.1 tests + +# +# Test that we can't open connection to server if we are using +# a different cacert +# +--exec echo "this query should not execute;" > $MYSQLTEST_VARDIR/tmp/test.sql +--error 1 +--exec $MYSQL_TEST --ssl-ca=$MYSQL_TEST_DIR/std_data/untrusted-cacert.pem --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 + +# +# Test that we can't open connection to server if we are using +# a blank ca +# +--error 1 +--exec $MYSQL_TEST --ssl-ca= --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 + +# +# Test that we can't open connection to server if we are using +# a nonexistent ca file +# +--error 1 +--exec $MYSQL_TEST --ssl-ca=nonexisting_file.pem --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 + +# +# Test that we can't open connection to server if we are using +# a blank client-key +# +--error 1 +--exec $MYSQL_TEST --ssl-key= --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 + +# +# Test that we can't open connection to server if we are using +# a blank client-cert +# +--error 1 +--exec $MYSQL_TEST --ssl-cert= --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 + + diff --git a/mysql-test/t/outfile.test b/mysql-test/t/outfile.test index d404a6fff9f..c48e6c9730d 100644 --- a/mysql-test/t/outfile.test +++ b/mysql-test/t/outfile.test @@ -40,7 +40,6 @@ eval select * into dumpfile "../tmp/outfile-test.2" from t1; --error 1086 eval select * into dumpfile "../tmp/outfile-test.3" from t1; enable_query_log; ---error 13,2 select load_file(concat(@tmpdir,"/outfile-test.not-exist")); --exec rm $MYSQLTEST_VARDIR/tmp/outfile-test.1 --exec rm $MYSQLTEST_VARDIR/tmp/outfile-test.2 diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index 272cdc27af6..be4fc1081f3 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -9,6 +9,24 @@ drop table if exists t1; --enable_warnings +create table t1 (a int) +partition by key(a) +(partition p0 engine = MEMORY); +drop table t1; + +# +# BUG 19067 ALTER TABLE .. ADD PARTITION for subpartitioned table crashes +# +create table t1 (a int) +partition by range (a) +subpartition by key (a) +(partition p0 values less than (1)); +alter table t1 add partition (partition p1 values less than (2)); +show create table t1; +alter table t1 reorganize partition p1 into (partition p1 values less than (3)); +show create table t1; +drop table t1; + # # Partition by key no partition defined => OK # @@ -1009,4 +1027,84 @@ select auto_increment from information_schema.tables where table_name='t1'; select * from t1; drop table t1; +# +# BUG 19140 Partitions: Create index for partitioned table crashes +# +create table t1 (a int) engine=memory +partition by key(a); +insert into t1 values (1); +create index inx1 on t1(a); +drop table t1; + +# +# BUG 19304 Partitions: MERGE handler not allowed in partitioned tables +# +--error ER_PARTITION_MERGE_ERROR +create table t1 (a int) +partition by key (a) +(partition p0 engine = MERGE); + +# +# BUG 19062 Partition clause ignored if CREATE TABLE ... AS SELECT ...; +# +create table t1 (a varchar(1)) +partition by key (a) +as select 'a'; + +show create table t1; +drop table t1; + +# +# BUG 19501 Partitions: SHOW TABLE STATUS shows wrong Data_free +# +CREATE TABLE t1 (a int) ENGINE = MYISAM PARTITION BY KEY(a); +INSERT into t1 values (1), (2); +--replace_column 9 0 12 NULL 13 NULL 14 NULL +SHOW TABLE STATUS; +DELETE from t1 where a = 1; +--replace_column 9 0 12 NULL 13 NULL 14 NULL +SHOW TABLE STATUS; +ALTER TABLE t1 OPTIMIZE PARTITION p0; +--replace_column 12 NULL 13 NULL 14 NULL +SHOW TABLE STATUS; +DROP TABLE t1; + +# +# BUG 19502: ENABLE/DISABLE Keys don't work for partitioned tables +# +CREATE TABLE t1 (a int, index(a)) PARTITION BY KEY(a); +ALTER TABLE t1 DISABLE KEYS; +ALTER TABLE t1 ENABLE KEYS; +DROP TABLE t1; + +# +# Bug 17455 Partitions: Wrong message and error when using Repair/Optimize +# table on partitioned table +# +create table t1 (a int) +engine=MEMORY +partition by key (a); + +REPAIR TABLE t1; +OPTIMIZE TABLE t1; + +drop table t1; + +# +# Bug 17310 Partitions: Bugs with archived partitioned tables +# +create database db99; +use db99; +create table t1 (a int not null) +engine=archive +partition by list (a) +(partition p0 values in (1), partition p1 values in (2)); +insert into t1 values (1), (2); +--error 0, 1005 +create index inx on t1 (a); +alter table t1 add partition (partition p2 values in (3)); +alter table t1 drop partition p2; +use test; +drop database db99; + --echo End of 5.1 tests diff --git a/mysql-test/t/partition_error.test b/mysql-test/t/partition_error.test index 03a2ab41807..659f0b8cef4 100644 --- a/mysql-test/t/partition_error.test +++ b/mysql-test/t/partition_error.test @@ -747,3 +747,31 @@ CREATE TABLE t1(a int) --error ER_NO_PARTITION_FOR_GIVEN_VALUE insert into t1 values (10); drop table t1; + +# +# Bug 18198 Partitions: Verify that erroneus partition functions doesn't work +# +create table t1 (v varchar(12)) +partition by range (ascii(v)) +(partition p0 values less than (10)); +drop table t1; + +-- error 1064 +create table t1 (a int) +partition by hash (rand(a)); +-- error 1064 +create table t1 (a int) +partition by hash(CURTIME() + a); +-- error 1064 +create table t1 (a int) +partition by hash (NOW()+a); +-- error ER_PARTITION_FUNCTION_IS_NOT_ALLOWED +create table t1 (a int) +partition by hash (extract(hour from convert_tz(a, '+00:00', '+00:00'))); +-- error ER_PARTITION_FUNCTION_IS_NOT_ALLOWED +create table t1 (a int) +partition by range (a + (select count(*) from t1)) +(partition p1 values less than (1)); +-- error ER_PARTITION_FUNC_NOT_ALLOWED_ERROR +create table t1 (a char(10)) +partition by hash (extractvalue(a,'a')); diff --git a/mysql-test/t/partition_mgm_err2.test b/mysql-test/t/partition_mgm_err2.test index dd96731ccdd..7d15bd7b19f 100644 --- a/mysql-test/t/partition_mgm_err2.test +++ b/mysql-test/t/partition_mgm_err2.test @@ -15,7 +15,7 @@ enable_query_log; --system mkdir $MYSQLTEST_VARDIR/tmp/bug14354 disable_query_log; eval CREATE TABLE t1 (id int) PARTITION BY RANGE(id) ( -PARTITION p1 VALUES LESS THAN (20) ENGINE=myiasm +PARTITION p1 VALUES LESS THAN (20) ENGINE=myisam DATA DIRECTORY="$MYSQLTEST_VARDIR/tmp/bug14354" INDEX DIRECTORY="$MYSQLTEST_VARDIR/tmp/bug14354"); enable_query_log; diff --git a/mysql-test/t/ps_1general.test b/mysql-test/t/ps_1general.test index f61a7820afe..0b9a46ad4d3 100644 --- a/mysql-test/t/ps_1general.test +++ b/mysql-test/t/ps_1general.test @@ -321,13 +321,15 @@ execute stmt4; prepare stmt4 from ' show variables like ''sql_mode'' '; execute stmt4; prepare stmt4 from ' show engine bdb logs '; -# The output depends on the history (actions of the bdb engine). +# The output depends on the bdb being enabled and on the history +# history (actions of the bdb engine). # That is the reason why, we switch the output here off. # (The real output will be tested in ps_6bdb.test) -# --replace_result $MYSQL_TEST_DIR TEST_DIR +--disable_warnings --disable_result_log execute stmt4; --enable_result_log +--enable_warnings prepare stmt4 from ' show grants for user '; --error 1295 prepare stmt4 from ' show create table t2 '; diff --git a/mysql-test/t/rename.test b/mysql-test/t/rename.test index 5caecef176e..86e4b6eed0a 100644 --- a/mysql-test/t/rename.test +++ b/mysql-test/t/rename.test @@ -61,9 +61,15 @@ connection con2; sleep 1; show tables; UNLOCK TABLES; -sleep 1; +connection con1; +reap; +connection con2; show tables; drop table t2, t4; +disconnect con2; +disconnect con1; +connection default; + # End of 4.1 tests diff --git a/mysql-test/t/rpl_bit_npk.test b/mysql-test/t/rpl_bit_npk.test index 07fc42b09ef..12b587919f9 100644 --- a/mysql-test/t/rpl_bit_npk.test +++ b/mysql-test/t/rpl_bit_npk.test @@ -70,18 +70,22 @@ UNLOCK TABLES; UPDATE test.t1 set x034 = 50 where bit3 = b'000000'; UPDATE test.t1 set VNotSupp = 33 where bit1 = b'0'; -SELECT oSupp, sSuppD, GSuppDf, VNotSupp, x034 FROM test.t1; -SELECT hex(bit1) from test.t1; -SELECT hex(bit2) from test.t1; -SELECT hex(bit3) from test.t1; +SELECT oSupp, sSuppD, GSuppDf, VNotSupp, x034 + FROM test.t1 + ORDER BY oSupp, sSuppD, GSuppDf, VNotSupp, x034; +SELECT hex(bit1) from test.t1 ORDER BY bit1; +SELECT hex(bit2) from test.t1 ORDER BY bit2; +SELECT hex(bit3) from test.t1 ORDER BY bit3; save_master_pos; connection slave; sync_with_master; -SELECT oSupp, sSuppD, GSuppDf, VNotSupp, x034 FROM test.t1; -SELECT hex(bit1) from test.t1; -SELECT hex(bit2) from test.t1; -SELECT hex(bit3) from test.t1; +SELECT oSupp, sSuppD, GSuppDf, VNotSupp, x034 + FROM test.t1 + ORDER BY oSupp, sSuppD, GSuppDf, VNotSupp, x034; +SELECT hex(bit1) from test.t1 ORDER BY bit1; +SELECT hex(bit2) from test.t1 ORDER BY bit2; +SELECT hex(bit3) from test.t1 ORDER BY bit3; connection master; CREATE TABLE test.t2 (a INT, b BIT(1)); @@ -94,14 +98,14 @@ INSERT INTO test.t3 VALUES (1, NULL); INSERT INTO test.t3 VALUES (1, 0); UPDATE test.t3 SET a = 2 WHERE b = 0; -SELECT a, hex(b) FROM test.t2; -SELECT * FROM test.t3; +SELECT a, hex(b) FROM test.t2 ORDER BY a,b; +SELECT * FROM test.t3 ORDER BY a,b; save_master_pos; connection slave; sync_with_master; -SELECT a, hex(b) FROM test.t2; -SELECT * FROM test.t3; +SELECT a, hex(b) FROM test.t2 ORDER BY a,b; +SELECT * FROM test.t3 ORDER BY a,b; connection master; DROP TABLE IF EXISTS test.t1; diff --git a/mysql-test/t/rpl_multi_engine.test b/mysql-test/t/rpl_multi_engine.test index 3f7b7b11c0d..10780c765f7 100644 --- a/mysql-test/t/rpl_multi_engine.test +++ b/mysql-test/t/rpl_multi_engine.test @@ -1,5 +1,9 @@ # See if replication between MyISAM, MEMORY and InnoDB works. +#This test case is not written for NDB, result files do not +#match when NDB is the default engine +-- source include/not_ndb_default.inc + -- source include/master-slave.inc connection slave; diff --git a/mysql-test/t/rpl_ndb_dd_partitions.test b/mysql-test/t/rpl_ndb_dd_partitions.test deleted file mode 100644 index 9291f38e8db..00000000000 --- a/mysql-test/t/rpl_ndb_dd_partitions.test +++ /dev/null @@ -1,310 +0,0 @@ -####################################### -# Author: JBM # -# Date: 2006-03-09 # -# Purpose: To test the replication of # -# Cluster Disk Data using partitions # -####################################### - ---source include/have_ndb.inc ---source include/have_binlog_format_row.inc ---source include/master-slave.inc - ---echo --- Doing pre test cleanup --- - -connection master; ---disable_warnings -DROP TABLE IF EXISTS t1; ---enable_query_log - - -# Start by creating a logfile group -################################## - -CREATE LOGFILE GROUP lg1 -ADD UNDOFILE 'undofile.dat' -INITIAL_SIZE 16M -UNDO_BUFFER_SIZE = 1M -ENGINE=NDB; - -ALTER LOGFILE GROUP lg1 -ADD UNDOFILE 'undofile02.dat' -INITIAL_SIZE = 4M -ENGINE=NDB; - -################################################### -# Create a tablespace connected to the logfile group -################################################### - -CREATE TABLESPACE ts1 -ADD DATAFILE 'datafile.dat' -USE LOGFILE GROUP lg1 -INITIAL_SIZE 12M -ENGINE NDB; - -ALTER TABLESPACE ts1 -ADD DATAFILE 'datafile02.dat' -INITIAL_SIZE = 4M -ENGINE=NDB; - -################################################################# - ---echo --- Start test 2 partition RANGE testing -- ---echo --- Do setup -- - - -################################################# -# Requirment: Create table that is partitioned # -# by range on year i.e. year(t) and replicate # -# basice operations such at insert, update # -# delete between 2 different storage engines # -# Alter table and ensure table is handled # -# Correctly on the slave # -################################################# - -CREATE TABLE t1 (id MEDIUMINT NOT NULL, b1 BIT(8), vc VARCHAR(63), - bc CHAR(63), d DECIMAL(10,4) DEFAULT 0, - f FLOAT DEFAULT 0, total BIGINT UNSIGNED, - y YEAR, t DATE) - TABLESPACE ts1 STORAGE DISK - ENGINE=NDB - PARTITION BY RANGE (YEAR(t)) - (PARTITION p0 VALUES LESS THAN (1901), - PARTITION p1 VALUES LESS THAN (1946), - PARTITION p2 VALUES LESS THAN (1966), - PARTITION p3 VALUES LESS THAN (1986), - PARTITION p4 VALUES LESS THAN (2005), - PARTITION p5 VALUES LESS THAN MAXVALUE); - ---echo --- Show table on master --- - -SHOW CREATE TABLE t1; - ---echo --- Show table on slave -- - -sync_slave_with_master; -SHOW CREATE TABLE t1; - ---echo --- Perform basic operation on master --- ---echo --- and ensure replicated correctly --- - ---source include/rpl_multi_engine3.inc - ---echo --- Check that simple Alter statements are replicated correctly --- - -ALTER TABLE t1 MODIFY vc VARCHAR(255); - ---echo --- Show the new improved table on the master --- - -SHOW CREATE TABLE t1; - ---echo --- Make sure that our tables on slave are still same engine --- ---echo --- and that the alter statements replicated correctly --- - -sync_slave_with_master; -SHOW CREATE TABLE t1; - ---echo --- Perform basic operation on master --- ---echo --- and ensure replicated correctly --- ---enable_query_log - ---source include/rpl_multi_engine3.inc - ---echo --- End test 2 partition RANGE testing --- ---echo --- Do Cleanup --- - -DROP TABLE IF EXISTS t1; - -######################################################## - ---echo --- Start test 3 partition LIST testing --- ---echo --- Do setup --- -################################################# - - -CREATE TABLE t1 (id MEDIUMINT NOT NULL, b1 BIT(8), vc VARCHAR(63), - bc CHAR(63), d DECIMAL(10,4) DEFAULT 0, - f FLOAT DEFAULT 0, total BIGINT UNSIGNED, - y YEAR, t DATE) - TABLESPACE ts1 STORAGE DISK - ENGINE=NDB - PARTITION BY LIST(id) - (PARTITION p0 VALUES IN (2, 4), - PARTITION p1 VALUES IN (42, 142)); - ---echo --- Test 3 Alter to add partition --- - -ALTER TABLE t1 ADD PARTITION (PARTITION p2 VALUES IN (412)); - ---echo --- Show table on master --- - -SHOW CREATE TABLE t1; - ---echo --- Show table on slave --- - -sync_slave_with_master; -SHOW CREATE TABLE t1; - ---echo --- Perform basic operation on master --- ---echo --- and ensure replicated correctly --- - ---source include/rpl_multi_engine3.inc - ---echo --- Check that simple Alter statements are replicated correctly --- - -ALTER TABLE t1 MODIFY vc VARCHAR(255); - ---echo --- Show the new improved table on the master --- - -SHOW CREATE TABLE t1; - ---echo --- Make sure that our tables on slave are still same engine --- ---echo --- and that the alter statements replicated correctly --- - -sync_slave_with_master; -SHOW CREATE TABLE t1; - ---echo --- Perform basic operation on master --- ---echo --- and ensure replicated correctly --- - ---source include/rpl_multi_engine3.inc - ---echo --- End test 3 partition LIST testing --- ---echo --- Do Cleanup -- - -DROP TABLE IF EXISTS t1; - -######################################################## - ---echo --- Start test 4 partition HASH testing --- ---echo --- Do setup --- -################################################# - - -CREATE TABLE t1 (id MEDIUMINT NOT NULL, b1 BIT(8), vc VARCHAR(63), - bc CHAR(63), d DECIMAL(10,4) DEFAULT 0, - f FLOAT DEFAULT 0, total BIGINT UNSIGNED, - y YEAR, t DATE) - TABLESPACE ts1 STORAGE DISK - ENGINE=NDB - PARTITION BY HASH( YEAR(t) ) - PARTITIONS 4; - ---echo --- show that tables have been created correctly --- - -SHOW CREATE TABLE t1; -sync_slave_with_master; -SHOW CREATE TABLE t1; - ---echo --- Perform basic operation on master --- ---echo --- and ensure replicated correctly --- - ---source include/rpl_multi_engine3.inc - ---echo --- Check that simple Alter statements are replicated correctly --- - -ALTER TABLE t1 MODIFY vc VARCHAR(255); - ---echo --- Show the new improved table on the master --- - -SHOW CREATE TABLE t1; - ---echo --- Make sure that our tables on slave are still same engine --- ---echo --- and that the alter statements replicated correctly --- - -sync_slave_with_master; -SHOW CREATE TABLE t1; - ---echo --- Perform basic operation on master --- ---echo --- and ensure replicated correctly --- - ---source include/rpl_multi_engine3.inc - ---echo --- End test 4 partition HASH testing --- ---echo --- Do Cleanup -- - -DROP TABLE IF EXISTS t1; - -######################################################## - ---echo --- Start test 5 partition by key testing --- ---echo --- Create Table Section --- - -################################################# - -CREATE TABLE t1 (id MEDIUMINT NOT NULL, b1 BIT(8), vc VARCHAR(63), - bc CHAR(63), d DECIMAL(10,4) DEFAULT 0, - f FLOAT DEFAULT 0, total BIGINT UNSIGNED, - y YEAR, t DATE,PRIMARY KEY(id)) - TABLESPACE ts1 STORAGE DISK - ENGINE=NDB - PARTITION BY KEY() - PARTITIONS 4; - ---echo --- Show that tables on master are ndbcluster tables --- - -SHOW CREATE TABLE t1; - ---echo --- Show that tables on slave --- - -sync_slave_with_master; -SHOW CREATE TABLE t1; - ---echo --- Perform basic operation on master --- ---echo --- and ensure replicated correctly --- - ---source include/rpl_multi_engine3.inc - -# Okay lets see how it holds up to table changes ---echo --- Check that simple Alter statements are replicated correctly --- - -ALTER TABLE t1 DROP PRIMARY KEY, ADD PRIMARY KEY(id, total); - ---echo --- Show the new improved table on the master --- - -SHOW CREATE TABLE t1; - ---echo --- Make sure that our tables on slave are still right type --- ---echo --- and that the alter statements replicated correctly --- - -sync_slave_with_master; -SHOW CREATE TABLE t1; - ---echo --- Perform basic operation on master --- ---echo --- and ensure replicated correctly --- - ---source include/rpl_multi_engine3.inc - ---echo --- Check that simple Alter statements are replicated correctly --- - -ALTER TABLE t1 MODIFY vc VARCHAR(255); - ---echo --- Show the new improved table on the master --- - -SHOW CREATE TABLE t1; - ---echo --- Make sure that our tables on slave are still same engine --- ---echo --- and that the alter statements replicated correctly --- - -sync_slave_with_master; -SHOW CREATE TABLE t1; - ---echo --- Perform basic operation on master --- ---echo --- and ensure replicated correctly --- - ---source include/rpl_multi_engine3.inc - ---echo --- End test 5 key partition testing --- ---echo --- Do Cleanup --- - -DROP TABLE IF EXISTS t1; -alter tablespace ts1 -drop datafile 'datafile.dat' -engine=ndb; -alter tablespace ts1 -drop datafile 'datafile02.dat' -engine=ndb; -DROP TABLESPACE ts1 ENGINE=NDB; -DROP LOGFILE GROUP lg1 ENGINE=NDB; ---sync_slave_with_master - -# End of 5.1 test case diff --git a/mysql-test/t/rpl_ndb_innodb2ndb-slave.opt b/mysql-test/t/rpl_ndb_innodb2ndb-slave.opt index f47e5a7e98f..d6f11dcd7bc 100644 --- a/mysql-test/t/rpl_ndb_innodb2ndb-slave.opt +++ b/mysql-test/t/rpl_ndb_innodb2ndb-slave.opt @@ -1 +1 @@ ---binlog-format=row --default-storage-engine=ndb +--binlog-format=row --default-storage-engine=ndbcluster diff --git a/mysql-test/t/rpl_ndb_myisam2ndb-slave.opt b/mysql-test/t/rpl_ndb_myisam2ndb-slave.opt index f31d53c3cb1..b7990823676 100644 --- a/mysql-test/t/rpl_ndb_myisam2ndb-slave.opt +++ b/mysql-test/t/rpl_ndb_myisam2ndb-slave.opt @@ -1 +1 @@ ---default-storage-engine=ndb --binlog-format=row +--default-storage-engine=ndbcluster --binlog-format=row diff --git a/mysql-test/t/rpl_row_basic_11bugs.test b/mysql-test/t/rpl_row_basic_11bugs.test index d098723644f..3a686ea6b3d 100644 --- a/mysql-test/t/rpl_row_basic_11bugs.test +++ b/mysql-test/t/rpl_row_basic_11bugs.test @@ -1,5 +1,11 @@ --source include/have_row_based.inc --source include/have_binlog_format_row.inc + + +#This test case is not written for NDB, the result files +#will not match when NDB is the default engine +-- source include/not_ndb_default.inc + --source include/master-slave.inc # Bug#15942 (RBR ignores --binlog_ignore_db and tries to map to table diff --git a/mysql-test/t/rpl_row_flsh_tbls.test b/mysql-test/t/rpl_row_flsh_tbls.test index 1a81da39896..9e8efc1ac9c 100644 --- a/mysql-test/t/rpl_row_flsh_tbls.test +++ b/mysql-test/t/rpl_row_flsh_tbls.test @@ -6,6 +6,11 @@ let $rename_event_pos= 615; # Bug#18326: Do not lock table for writing during prepare of statement # The use of the ps protocol causes extra table maps in the binlog, so # we disable the ps-protocol for this statement. + +# Merge tables are not supported in NDB +-- source include/not_ndb_default.inc + + --disable_ps_protocol -- source extra/rpl_tests/rpl_flsh_tbls.test --enable_ps_protocol diff --git a/mysql-test/t/rpl_sp004.test b/mysql-test/t/rpl_sp004.test index 335a17c7af0..055a13cc157 100644 --- a/mysql-test/t/rpl_sp004.test +++ b/mysql-test/t/rpl_sp004.test @@ -44,13 +44,13 @@ END| delimiter ;| CALL test.p1(); -SELECT * FROM test.t1; -SELECT * FROM test.t2; +SELECT * FROM test.t1 ORDER BY a; +SELECT * FROM test.t2 ORDER BY a; save_master_pos; connection slave; sync_with_master; -SELECT * FROM test.t1; -SELECT * FROM test.t2; +SELECT * FROM test.t1 ORDER BY a; +SELECT * FROM test.t2 ORDER BY a; connection master; CALL test.p2(); @@ -66,14 +66,14 @@ SHOW TABLES; connection master; CALL test.p1(); -SELECT * FROM test.t1; -SELECT * FROM test.t2; +SELECT * FROM test.t1 ORDER BY a; +SELECT * FROM test.t2 ORDER BY a; #SELECT * FROM test.t3; save_master_pos; connection slave; sync_with_master; -SELECT * FROM test.t1; -SELECT * FROM test.t2; +SELECT * FROM test.t1 ORDER BY a; +SELECT * FROM test.t2 ORDER BY a; #SELECT * FROM test.t3; --exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/sp004_master.sql diff --git a/mysql-test/t/rpl_stm_until.test b/mysql-test/t/rpl_stm_until.test index 1bd87db88cb..9a4e4471fe1 100644 --- a/mysql-test/t/rpl_stm_until.test +++ b/mysql-test/t/rpl_stm_until.test @@ -32,7 +32,7 @@ wait_for_slave_to_stop; select * from t1; --replace_result $MASTER_MYPORT MASTER_MYPORT --replace_column 1 # 9 # 11 # 23 # 33 # -show slave status; +--query_vertical SHOW SLAVE STATUS # this should fail right after start start slave until master_log_file='master-no-such-bin.000001', master_log_pos=291; @@ -42,7 +42,7 @@ sleep 2; wait_for_slave_to_stop; --replace_result $MASTER_MYPORT MASTER_MYPORT --replace_column 1 # 9 # 11 # 23 # 33 # -show slave status; +--query_vertical SHOW SLAVE STATUS # try replicate all up to and not including the second insert to t2; start slave until relay_log_file='slave-relay-bin.000004', relay_log_pos=746; @@ -51,7 +51,7 @@ wait_for_slave_to_stop; select * from t2; --replace_result $MASTER_MYPORT MASTER_MYPORT --replace_column 1 # 9 # 11 # 23 # 33 # -show slave status; +--query_vertical SHOW SLAVE STATUS # clean up start slave; @@ -68,7 +68,7 @@ wait_for_slave_to_stop; # here the sql slave thread should be stopped --replace_result $MASTER_MYPORT MASTER_MYPORT bin.000005 bin.000004 bin.000006 bin.000004 bin.000007 bin.000004 --replace_column 1 # 9 # 23 # 33 # -show slave status; +--query_vertical SHOW SLAVE STATUS #testing various error conditions --error 1277 diff --git a/mysql-test/t/rpl_temporary.test b/mysql-test/t/rpl_temporary.test index 612ab54dff1..0d91a9f8e91 100644 --- a/mysql-test/t/rpl_temporary.test +++ b/mysql-test/t/rpl_temporary.test @@ -165,14 +165,19 @@ drop table t5; # value was set up at the moment of temp table creation # connection con1; -set @session.pseudo_thread_id=100; +set @@session.pseudo_thread_id=100; create temporary table t101 (id int); create temporary table t102 (id int); -set @session.pseudo_thread_id=200; +set @@session.pseudo_thread_id=200; create temporary table t201 (id int); -create temporary table `#not_user_table_prefixed_with_hash_sign_no_harm` (id int); -set @con1_id=connection_id(); -kill @con1_id; +#create temporary table `t``201` (id int); +# emulate internal temp table not to come to binlog +create temporary table `#sql_not_user_table202` (id int); +set @@session.pseudo_thread_id=300; +create temporary table t301 (id int); +create temporary table t302 (id int); +create temporary table `#sql_not_user_table303` (id int); +disconnect con1; #now do something to show that slave is ok after DROP temp tables connection master; @@ -185,4 +190,17 @@ select * from t1 /* must be 1 */; connection master; drop table t1; -# End of 5.1 tests + +# +#14157: utf8 encoding in binlog without set character_set_client +# +--exec $MYSQL --character-sets-dir=../sql/share/charsets/ --default-character-set=latin1 test -e 'create table t1 (a int); set names latin1; create temporary table `äöüÄÖÜ` (a int); insert into `äöüÄÖÜ` values (1); insert into t1 select * from `äöüÄÖÜ`' + +sync_slave_with_master; +#connection slave; +select * from t1; + +connection master; +drop table t1; + +# End of 5.0 tests diff --git a/mysql-test/t/rpl_user_variables.test b/mysql-test/t/rpl_user_variables.test index cb2a1e1d853..08717fce114 100644 --- a/mysql-test/t/rpl_user_variables.test +++ b/mysql-test/t/rpl_user_variables.test @@ -1,8 +1,4 @@ ################################### -# Change Author: JBM -# Change Date: 2006-01-17 -# Change: Added order by -################################### # # Test of replicating user variables # @@ -55,6 +51,7 @@ SELECT * FROM t1 ORDER BY n; sync_slave_with_master; SELECT * FROM t1 ORDER BY n; connection master; +insert into t1 select * FROM (select @var1 union select @var2) AS t2; drop table t1; sync_slave_with_master; stop slave; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 8e3c5847846..4b6ae921b9b 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2886,3 +2886,37 @@ SELECT * FROM t1; UPDATE t1 SET i = i - 1; SELECT * FROM t1; DROP TABLE t1; + +# BUG#17379 + +create table t1 (a int); +insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t2 (a int, b int, c int, e int, primary key(a,b,c)); +insert into t2 select A.a, B.a, C.a, C.a from t1 A, t1 B, t1 C; +analyze table t2; +select 'In next EXPLAIN, B.rows must be exactly 10:' Z; + +explain select * from t2 A, t2 B where A.a=5 and A.b=5 and A.C<5 + and B.a=5 and B.b=A.e and (B.b =1 or B.b = 3 or B.b=5); +drop table t1, t2; + +# +#Bug #18940: selection of optimal execution plan caused by equality +# propagation (the bug was fixed by the patch for bug #17379) + +CREATE TABLE t1 (a int PRIMARY KEY, b int, INDEX(b)); +INSERT INTO t1 VALUES (1, 3), (9,4), (7,5), (4,5), (6,2), + (3,1), (5,1), (8,9), (2,2), (0,9); + +CREATE TABLE t2 (c int, d int, f int, INDEX(c,f)); +INSERT INTO t2 VALUES + (1,0,0), (1,0,1), (2,0,0), (2,0,1), (3,0,0), (4,0,1), + (5,0,0), (5,0,1), (6,0,0), (0,0,1), (7,0,0), (7,0,1), + (0,0,0), (0,0,1), (8,0,0), (8,0,1), (9,0,0), (9,0,1); + +EXPLAIN +SELECT a, c, d, f FROM t1,t2 WHERE a=c AND b BETWEEN 4 AND 6; +EXPLAIN +SELECT a, c, d, f FROM t1,t2 WHERE a=c AND b BETWEEN 4 AND 6 AND a > 0; + +DROP TABLE t1, t2; diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 8ccd954eeea..8f5fcdc9d52 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -5780,6 +5780,122 @@ select routine_name,routine_schema from information_schema.routines where # +# BUG#12472/BUG#15137 'CREATE TABLE ... SELECT ... which explicitly or +# implicitly uses stored function gives "Table not locked" error'. +# +--disable_warnings +drop function if exists bug12472| +--enable_warnings +create function bug12472() returns int return (select count(*) from t1)| +# Check case when function is used directly +create table t3 as select bug12472() as i| +show create table t3| +select * from t3| +drop table t3| +# Check case when function is used indirectly through view +create view v1 as select bug12472() as j| +create table t3 as select * from v1| +show create table t3| +select * from t3| +drop table t3| +drop view v1| +drop function bug12472| + + +# +# BUG#18587: Function that accepts and returns TEXT garbles data if longer than +# 766 chars +# + +# Prepare. + +--disable_warnings +DROP FUNCTION IF EXISTS bug18589_f1| +DROP PROCEDURE IF EXISTS bug18589_p1| +DROP PROCEDURE IF EXISTS bug18589_p2| +--enable_warnings + +CREATE FUNCTION bug18589_f1(arg TEXT) RETURNS TEXT +BEGIN + RETURN CONCAT(arg, ""); +END| + +CREATE PROCEDURE bug18589_p1(arg TEXT, OUT ret TEXT) +BEGIN + SET ret = CONCAT(arg, ""); +END| + +CREATE PROCEDURE bug18589_p2(arg TEXT) +BEGIN + DECLARE v TEXT; + CALL bug18589_p1(arg, v); + SELECT v; +END| + +# Test case. + +SELECT bug18589_f1(REPEAT("a", 767))| + +SET @bug18589_v1 = ""| +CALL bug18589_p1(REPEAT("a", 767), @bug18589_v1)| +SELECT @bug18589_v1| + +CALL bug18589_p2(REPEAT("a", 767))| + +# Cleanup. + +DROP FUNCTION bug18589_f1| +DROP PROCEDURE bug18589_p1| +DROP PROCEDURE bug18589_p2| + + +# +# BUG#18037: Server crash when returning system variable in stored procedures +# BUG#19633: Stack corruption in fix_fields()/THD::rollback_item_tree_changes() +# + +# Prepare. + +--disable_warnings +DROP FUNCTION IF EXISTS bug18037_f1| +DROP PROCEDURE IF EXISTS bug18037_p1| +DROP PROCEDURE IF EXISTS bug18037_p2| +--enable_warnings + +# Test case. + +CREATE FUNCTION bug18037_f1() RETURNS INT +BEGIN + RETURN @@server_id; +END| + +CREATE PROCEDURE bug18037_p1() +BEGIN + DECLARE v INT DEFAULT @@server_id; +END| + +CREATE PROCEDURE bug18037_p2() +BEGIN + CASE @@server_id + WHEN -1 THEN + SELECT 0; + ELSE + SELECT 1; + END CASE; +END| + +SELECT bug18037_f1()| +CALL bug18037_p1()| +CALL bug18037_p2()| + +# Cleanup. + +DROP FUNCTION bug18037_f1| +DROP PROCEDURE bug18037_p1| +DROP PROCEDURE bug18037_p2| + + +# # BUG#NNNN: New bug synopsis # #--disable_warnings diff --git a/mysql-test/t/strict.test b/mysql-test/t/strict.test index 54260b09331..212150e057c 100644 --- a/mysql-test/t/strict.test +++ b/mysql-test/t/strict.test @@ -1145,3 +1145,13 @@ create table t1(a bit(2)); insert into t1 values(b'101'); select * from t1; drop table t1; + +# +# Bug#17626 CREATE TABLE ... SELECT failure with TRADITIONAL SQL mode +# +set sql_mode='traditional'; +create table t1 (date date not null); +create table t2 select date from t1; +show create table t2; +drop table t2,t1; +set @@sql_mode= @org_mode; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 1ef80bdd7ac..8916a5cec6d 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -2085,3 +2085,49 @@ create table t2 (a int, b int); insert into t2 values (2, 1), (1, 0); delete from t1 where c <= 1140006215 and (select b from t2 where a = 2) = 1; drop table t1, t2; + +# +# Bug #7549: Missing error message for invalid view selection with subquery +# + +CREATE TABLE t1 (a INT); + +--error 1054 +CREATE VIEW v1 AS SELECT * FROM t1 WHERE no_such_column = ANY (SELECT 1); +--error 1054 +CREATE VIEW v2 AS SELECT * FROM t1 WHERE no_such_column = (SELECT 1); +--error 1054 +SELECT * FROM t1 WHERE no_such_column = ANY (SELECT 1); + +DROP TABLE t1; + +# +# Bug#19077: A nested materialized derived table is used before being populated. +# +create table t1 (i int, j bigint); +insert into t1 values (1, 2), (2, 2), (3, 2); +select * from (select min(i) from t1 where j=(select * from (select min(j) from t1) t2)) t3; +drop table t1; + +# +# Bug#19700: subselect returning BIGINT always returned it as SIGNED +# +CREATE TABLE t1 (i BIGINT UNSIGNED); +INSERT INTO t1 VALUES (10000000000000000000); -- > MAX SIGNED BIGINT 9323372036854775807 +INSERT INTO t1 VALUES (1); + +CREATE TABLE t2 (i BIGINT UNSIGNED); +INSERT INTO t2 VALUES (10000000000000000000); -- same as first table +INSERT INTO t2 VALUES (1); + +/* simple test */ +SELECT t1.i FROM t1 JOIN t2 ON t1.i = t2.i; + +/* subquery test */ +SELECT t1.i FROM t1 WHERE t1.i = (SELECT MAX(i) FROM t2); + +/* subquery test with cast*/ +SELECT t1.i FROM t1 WHERE t1.i = CAST((SELECT MAX(i) FROM t2) AS UNSIGNED); + +DROP TABLE t1; +DROP TABLE t2; diff --git a/mysql-test/t/trigger-grant.test b/mysql-test/t/trigger-grant.test index 67aec1496dd..8ca8ffe904b 100644 --- a/mysql-test/t/trigger-grant.test +++ b/mysql-test/t/trigger-grant.test @@ -690,3 +690,176 @@ SELECT @mysqltest_var; DROP USER mysqltest_u1@localhost; DROP DATABASE mysqltest_db1; + + +# +# Test for bug #14635 Accept NEW.x as INOUT parameters to stored +# procedures from within triggers +# +# We require UPDATE privilege when NEW.x passed as OUT parameter, and +# SELECT and UPDATE when NEW.x passed as INOUT parameter. +# +DELETE FROM mysql.user WHERE User LIKE 'mysqltest_%'; +DELETE FROM mysql.db WHERE User LIKE 'mysqltest_%'; +DELETE FROM mysql.tables_priv WHERE User LIKE 'mysqltest_%'; +DELETE FROM mysql.columns_priv WHERE User LIKE 'mysqltest_%'; +FLUSH PRIVILEGES; + +--disable_warnings +DROP DATABASE IF EXISTS mysqltest_db1; +--enable_warnings + +CREATE DATABASE mysqltest_db1; +USE mysqltest_db1; + +CREATE TABLE t1 (i1 INT); +CREATE TABLE t2 (i1 INT); + +CREATE USER mysqltest_dfn@localhost; +CREATE USER mysqltest_inv@localhost; + +GRANT EXECUTE, CREATE ROUTINE, TRIGGER ON *.* TO mysqltest_dfn@localhost; +GRANT INSERT ON mysqltest_db1.* TO mysqltest_inv@localhost; + +connect (definer,localhost,mysqltest_dfn,,mysqltest_db1); +connect (invoker,localhost,mysqltest_inv,,mysqltest_db1); + +connection definer; +CREATE PROCEDURE p1(OUT i INT) DETERMINISTIC NO SQL SET i = 3; +CREATE PROCEDURE p2(INOUT i INT) DETERMINISTIC NO SQL SET i = i * 5; + +# Check that having no privilege won't work. +connection definer; +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW + CALL p1(NEW.i1); +CREATE TRIGGER t2_bi BEFORE INSERT ON t2 FOR EACH ROW + CALL p2(NEW.i1); + +connection invoker; +--error ER_COLUMNACCESS_DENIED_ERROR +INSERT INTO t1 VALUES (7); +--error ER_COLUMNACCESS_DENIED_ERROR +INSERT INTO t2 VALUES (11); + +connection definer; +DROP TRIGGER t2_bi; +DROP TRIGGER t1_bi; + +# Check that having only SELECT privilege is not enough. +connection default; +GRANT SELECT ON mysqltest_db1.* TO mysqltest_dfn@localhost; + +connection definer; +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW + CALL p1(NEW.i1); +CREATE TRIGGER t2_bi BEFORE INSERT ON t2 FOR EACH ROW + CALL p2(NEW.i1); + +connection invoker; +--error ER_COLUMNACCESS_DENIED_ERROR +INSERT INTO t1 VALUES (13); +--error ER_COLUMNACCESS_DENIED_ERROR +INSERT INTO t2 VALUES (17); + +connection default; +REVOKE SELECT ON mysqltest_db1.* FROM mysqltest_dfn@localhost; + +connection definer; +DROP TRIGGER t2_bi; +DROP TRIGGER t1_bi; + +# Check that having only UPDATE privilege is enough for OUT parameter, +# but not for INOUT parameter. +connection default; +GRANT UPDATE ON mysqltest_db1.* TO mysqltest_dfn@localhost; + +connection definer; +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW + CALL p1(NEW.i1); +CREATE TRIGGER t2_bi BEFORE INSERT ON t2 FOR EACH ROW + CALL p2(NEW.i1); + +connection invoker; +INSERT INTO t1 VALUES (19); +--error ER_COLUMNACCESS_DENIED_ERROR +INSERT INTO t2 VALUES (23); + +connection default; +REVOKE UPDATE ON mysqltest_db1.* FROM mysqltest_dfn@localhost; + +connection definer; +DROP TRIGGER t2_bi; +DROP TRIGGER t1_bi; + +# Check that having SELECT and UPDATE privileges is enough. +connection default; +GRANT SELECT, UPDATE ON mysqltest_db1.* TO mysqltest_dfn@localhost; + +connection definer; +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW + CALL p1(NEW.i1); +CREATE TRIGGER t2_bi BEFORE INSERT ON t2 FOR EACH ROW + CALL p2(NEW.i1); + +connection invoker; +INSERT INTO t1 VALUES (29); +INSERT INTO t2 VALUES (31); + +connection default; +REVOKE SELECT, UPDATE ON mysqltest_db1.* FROM mysqltest_dfn@localhost; + +connection definer; +DROP TRIGGER t2_bi; +DROP TRIGGER t1_bi; + +connection default; +DROP PROCEDURE p2; +DROP PROCEDURE p1; + +# Check that late procedure redefining won't open a security hole. +connection default; +GRANT UPDATE ON mysqltest_db1.* TO mysqltest_dfn@localhost; + +connection definer; +CREATE PROCEDURE p1(OUT i INT) DETERMINISTIC NO SQL SET i = 37; +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW + CALL p1(NEW.i1); + +connection invoker; +INSERT INTO t1 VALUES (41); + +connection definer; +DROP PROCEDURE p1; +CREATE PROCEDURE p1(IN i INT) DETERMINISTIC NO SQL SET @v1 = i + 43; + +connection invoker; +--error ER_COLUMNACCESS_DENIED_ERROR +INSERT INTO t1 VALUES (47); + +connection definer; +DROP PROCEDURE p1; +CREATE PROCEDURE p1(INOUT i INT) DETERMINISTIC NO SQL SET i = i + 51; + +connection invoker; +--error ER_COLUMNACCESS_DENIED_ERROR +INSERT INTO t1 VALUES (53); + +connection default; +DROP PROCEDURE p1; +REVOKE UPDATE ON mysqltest_db1.* FROM mysqltest_dfn@localhost; + +connection definer; +DROP TRIGGER t1_bi; + +# Cleanup. +disconnect definer; +disconnect invoker; +connection default; +DROP USER mysqltest_inv@localhost; +DROP USER mysqltest_dfn@localhost; +DROP TABLE t2; +DROP TABLE t1; +DROP DATABASE mysqltest_db1; +USE test; + +--echo End of 5.0 tests. diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test index 00c85a650d1..a87f289e94e 100644 --- a/mysql-test/t/trigger.test +++ b/mysql-test/t/trigger.test @@ -1111,9 +1111,9 @@ insert into t1 values create function f2() returns int return (select max(b) from t2); insert into t2 select a, f2() from t1; load data infile '../std_data_ln/words.dat' into table t1 (a) set b:= f1(); -drop table t1, t2; drop function f1; drop function f2; +drop table t1, t2; # # Test for bug #16021 "Wrong index given to function in trigger" which @@ -1165,4 +1165,126 @@ SELECT * FROM t1 WHERE conn_id != trigger_conn_id; DROP TRIGGER t1_bi; DROP TABLE t1; + +# +# Bug#6951: Triggers/Traditional: SET @ result wrong +# +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (i1 INT); + +SET @save_sql_mode=@@sql_mode; + +SET SQL_MODE=''; + +CREATE TRIGGER t1_ai AFTER INSERT ON t1 FOR EACH ROW + SET @x = 5/0; + +SET SQL_MODE='traditional'; + +CREATE TRIGGER t1_au AFTER UPDATE ON t1 FOR EACH ROW + SET @x = 5/0; + +SET @x=1; +INSERT INTO t1 VALUES (@x); +SELECT @x; + +SET @x=2; +--error 1365 +UPDATE t1 SET i1 = @x; +SELECT @x; + +SET SQL_MODE=''; + +SET @x=3; +INSERT INTO t1 VALUES (@x); +SELECT @x; + +SET @x=4; +--error 1365 +UPDATE t1 SET i1 = @x; +SELECT @x; + +SET @@sql_mode=@save_sql_mode; + +DROP TRIGGER t1_ai; +DROP TRIGGER t1_au; +DROP TABLE t1; + + +# +# Test for bug #14635 Accept NEW.x as INOUT parameters to stored +# procedures from within triggers +# +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +--enable_warnings + +CREATE TABLE t1 (i1 INT); + +# Check that NEW.x pseudo variable is accepted as INOUT and OUT +# parameter to stored routine. +INSERT INTO t1 VALUES (3); +CREATE PROCEDURE p1(OUT i1 INT) DETERMINISTIC NO SQL SET i1 = 5; +CREATE PROCEDURE p2(INOUT i1 INT) DETERMINISTIC NO SQL SET i1 = i1 * 7; +delimiter //; +CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 FOR EACH ROW +BEGIN + CALL p1(NEW.i1); + CALL p2(NEW.i1); +END// +delimiter ;// +UPDATE t1 SET i1 = 11 WHERE i1 = 3; +DROP TRIGGER t1_bu; +DROP PROCEDURE p2; +DROP PROCEDURE p1; + +# Check that OLD.x pseudo variable is not accepted as INOUT and OUT +# parameter to stored routine. +INSERT INTO t1 VALUES (13); +CREATE PROCEDURE p1(OUT i1 INT) DETERMINISTIC NO SQL SET @a = 17; +CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 FOR EACH ROW + CALL p1(OLD.i1); +--error ER_SP_NOT_VAR_ARG +UPDATE t1 SET i1 = 19 WHERE i1 = 13; +DROP TRIGGER t1_bu; +DROP PROCEDURE p1; + +INSERT INTO t1 VALUES (23); +CREATE PROCEDURE p1(INOUT i1 INT) DETERMINISTIC NO SQL SET @a = i1 * 29; +CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 FOR EACH ROW + CALL p1(OLD.i1); +--error ER_SP_NOT_VAR_ARG +UPDATE t1 SET i1 = 31 WHERE i1 = 23; +DROP TRIGGER t1_bu; +DROP PROCEDURE p1; + +# Check that NEW.x pseudo variable is read-only in the AFTER TRIGGER. +INSERT INTO t1 VALUES (37); +CREATE PROCEDURE p1(OUT i1 INT) DETERMINISTIC NO SQL SET @a = 41; +CREATE TRIGGER t1_au AFTER UPDATE ON t1 FOR EACH ROW + CALL p1(NEW.i1); +--error ER_SP_NOT_VAR_ARG +UPDATE t1 SET i1 = 43 WHERE i1 = 37; +DROP TRIGGER t1_au; +DROP PROCEDURE p1; + +INSERT INTO t1 VALUES (47); +CREATE PROCEDURE p1(INOUT i1 INT) DETERMINISTIC NO SQL SET @a = i1 * 49; +CREATE TRIGGER t1_au AFTER UPDATE ON t1 FOR EACH ROW + CALL p1(NEW.i1); +--error ER_SP_NOT_VAR_ARG +UPDATE t1 SET i1 = 51 WHERE i1 = 47; +DROP TRIGGER t1_au; +DROP PROCEDURE p1; + +# Post requisite. +SELECT * FROM t1; + +DROP TABLE t1; + # End of 5.0 tests diff --git a/mysql-test/t/variables-master.opt b/mysql-test/t/variables-master.opt deleted file mode 100644 index abd826bc7fa..00000000000 --- a/mysql-test/t/variables-master.opt +++ /dev/null @@ -1 +0,0 @@ ---max_join_size=100 diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test index 018337f2631..7aa79f0eb40 100644 --- a/mysql-test/t/variables.test +++ b/mysql-test/t/variables.test @@ -5,6 +5,37 @@ drop table if exists t1,t2; --enable_warnings +# +# Bug #19263: variables.test doesn't clean up after itself (I/II -- save) +# +set @my_binlog_cache_size =@@global.binlog_cache_size; +set @my_connect_timeout =@@global.connect_timeout; +set @my_delayed_insert_timeout =@@global.delayed_insert_timeout; +set @my_delayed_queue_size =@@global.delayed_queue_size; +set @my_flush =@@global.flush; +set @my_flush_time =@@global.flush_time; +set @my_key_buffer_size =@@global.key_buffer_size; +set @my_max_binlog_cache_size =@@global.max_binlog_cache_size; +set @my_max_binlog_size =@@global.max_binlog_size; +set @my_max_connect_errors =@@global.max_connect_errors; +set @my_max_delayed_threads =@@global.max_delayed_threads; +set @my_max_heap_table_size =@@global.max_heap_table_size; +set @my_max_insert_delayed_threads=@@global.max_insert_delayed_threads; +set @my_max_join_size =@@global.max_join_size; +set @my_max_user_connections =@@global.max_user_connections; +set @my_max_write_lock_count =@@global.max_write_lock_count; +set @my_myisam_data_pointer_size =@@global.myisam_data_pointer_size; +set @my_net_buffer_length =@@global.net_buffer_length; +set @my_net_write_timeout =@@global.net_write_timeout; +set @my_net_read_timeout =@@global.net_read_timeout; +set @my_query_cache_limit =@@global.query_cache_limit; +set @my_query_cache_type =@@global.query_cache_type; +set @my_rpl_recovery_rank =@@global.rpl_recovery_rank; +set @my_server_id =@@global.server_id; +set @my_slow_launch_time =@@global.slow_launch_time; +set @my_storage_engine =@@global.storage_engine; +set @my_thread_cache_size =@@global.thread_cache_size; + # case insensitivity tests (new in 5.0) set @`test`=1; select @test, @`test`, @TEST, @`TEST`, @"teSt"; @@ -508,4 +539,68 @@ select @@system_time_zone; select @@version, @@version_comment, @@version_compile_machine, @@version_compile_os; +# +# Bug #1039: make tmpdir and datadir available as @@variables (also included +# basedir) +# +# Don't actually output, since it depends on the system +--replace_column 1 # 2 # 3 # +select @@basedir, @@datadir, @@tmpdir; +--replace_column 2 # +show variables like 'basedir'; +--replace_column 2 # +show variables like 'datadir'; +--replace_column 2 # +show variables like 'tmpdir'; + +# +# Bug #19606: make ssl settings available via SHOW VARIABLES and @@variables +# +# Don't actually output, since it depends on the system +--replace_column 1 # 2 # 3 # 4 # 5 # +select @@ssl_ca, @@ssl_capath, @@ssl_cert, @@ssl_cipher, @@ssl_key; +--replace_column 2 # +show variables like 'ssl%'; + +# +# Bug #19616: make log_queries_not_using_indexes available in SHOW VARIABLES +# and as @@log_queries_not_using_indexes +# +select @@log_queries_not_using_indexes; +show variables like 'log_queries_not_using_indexes'; + --echo End of 5.0 tests + +# This is at the very after the versioned tests, since it involves doing +# cleanup +# +# Bug #19263: variables.test doesn't clean up after itself (II/II -- +# restore) +# +set global binlog_cache_size =@my_binlog_cache_size; +set global connect_timeout =@my_connect_timeout; +set global delayed_insert_timeout =@my_delayed_insert_timeout; +set global delayed_queue_size =@my_delayed_queue_size; +set global flush =@my_flush; +set global flush_time =@my_flush_time; +set global key_buffer_size =@my_key_buffer_size; +set global max_binlog_cache_size =default; #@my_max_binlog_cache_size; +set global max_binlog_size =@my_max_binlog_size; +set global max_connect_errors =@my_max_connect_errors; +set global max_delayed_threads =@my_max_delayed_threads; +set global max_heap_table_size =@my_max_heap_table_size; +set global max_insert_delayed_threads=@my_max_insert_delayed_threads; +set global max_join_size =@my_max_join_size; +set global max_user_connections =@my_max_user_connections; +set global max_write_lock_count =@my_max_write_lock_count; +set global myisam_data_pointer_size =@my_myisam_data_pointer_size; +set global net_buffer_length =@my_net_buffer_length; +set global net_write_timeout =@my_net_write_timeout; +set global net_read_timeout =@my_net_read_timeout; +set global query_cache_limit =@my_query_cache_limit; +set global query_cache_type =@my_query_cache_type; +set global rpl_recovery_rank =@my_rpl_recovery_rank; +set global server_id =@my_server_id; +set global slow_launch_time =@my_slow_launch_time; +set global storage_engine =@my_storage_engine; +set global thread_cache_size =@my_thread_cache_size; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 6094382c094..535ba3da7fa 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2517,3 +2517,87 @@ create view v2 as select convert_tz(dt, 'UTC', 'Europe/Moscow') as ldt from v1; select * from v2; drop view v1, v2; drop table t1; + +# +# Bug #19490: usage of view specified by a query with GROUP BY +# an expression containing non-constant interval + +CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, d datetime); + +CREATE VIEW v1 AS +SELECT id, date(d) + INTERVAL TIME_TO_SEC(d) SECOND AS t, COUNT(*) + FROM t1 GROUP BY id, t; + +SHOW CREATE VIEW v1; +SELECT * FROM v1; + +DROP VIEW v1; +DROP TABLE t1; + +# +# Bug#19077: A nested materialized view is used before being populated. +# +CREATE TABLE t1 (i INT, j BIGINT); +INSERT INTO t1 VALUES (1, 2), (2, 2), (3, 2); +CREATE VIEW v1 AS SELECT MIN(j) AS j FROM t1; +CREATE VIEW v2 AS SELECT MIN(i) FROM t1 WHERE j = ( SELECT * FROM v1 ); +SELECT * FROM v2; +DROP VIEW v2, v1; +DROP TABLE t1; + +# +# Bug #19573: VIEW with HAVING that refers an alias name +# + +CREATE TABLE t1( + fName varchar(25) NOT NULL, + lName varchar(25) NOT NULL, + DOB date NOT NULL, + uID int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY); + +INSERT INTO t1(fName, lName, DOB) VALUES + ('Hank', 'Hill', '1964-09-29'), + ('Tom', 'Adams', '1908-02-14'), + ('Homer', 'Simpson', '1968-03-05'); + +CREATE VIEW v1 AS + SELECT (year(now())-year(DOB)) AS Age + FROM t1 HAVING Age < 75; +SHOW CREATE VIEW v1; + +SELECT (year(now())-year(DOB)) AS Age FROM t1 HAVING Age < 75; +SELECT * FROM v1; + +DROP VIEW v1; +DROP TABLE t1; + +# +# Bug #19089: wrong inherited dafault values in temp table views +# + +CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, a char(6) DEFAULT 'xxx'); +INSERT INTO t1(id) VALUES (1), (2), (3), (4); +INSERT INTO t1 VALUES (5,'yyy'), (6,'yyy'); +SELECT * FROM t1; + +CREATE VIEW v1(a, m) AS SELECT a, MIN(id) FROM t1 GROUP BY a; +SELECT * FROM v1; + +CREATE TABLE t2 SELECT * FROM v1; +INSERT INTO t2(m) VALUES (0); +SELECT * FROM t2; + +DROP VIEW v1; +DROP TABLE t1,t2; + +CREATE TABLE t1 (id int PRIMARY KEY, e ENUM('a','b') NOT NULL DEFAULT 'b'); +INSERT INTO t1(id) VALUES (1), (2), (3); +INSERT INTO t1 VALUES (4,'a'); +SELECT * FROM t1; + +CREATE VIEW v1(m, e) AS SELECT MIN(id), e FROM t1 GROUP BY e; +CREATE TABLE t2 SELECT * FROM v1; +SELECT * FROM t2; + +DROP VIEW v1; +DROP TABLE IF EXISTS t1,t2; diff --git a/mysql-test/t/view_grant.test b/mysql-test/t/view_grant.test index e057ba537f6..aa420689149 100644 --- a/mysql-test/t/view_grant.test +++ b/mysql-test/t/view_grant.test @@ -718,3 +718,98 @@ show create view v1; show create view v2; drop view v1; drop view v2; + +# +# Bug#18681: View privileges are broken +# +CREATE DATABASE mysqltest1; +CREATE USER readonly@localhost; +CREATE TABLE mysqltest1.t1 (x INT); +INSERT INTO mysqltest1.t1 VALUES (1), (2); +CREATE SQL SECURITY INVOKER VIEW mysqltest1.v_t1 AS SELECT * FROM mysqltest1.t1; +CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_ts AS SELECT * FROM mysqltest1.t1; +CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_ti AS SELECT * FROM mysqltest1.t1; +CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_tu AS SELECT * FROM mysqltest1.t1; +CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_tus AS SELECT * FROM mysqltest1.t1; +CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_td AS SELECT * FROM mysqltest1.t1; +CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_tds AS SELECT * FROM mysqltest1.t1; +GRANT SELECT, INSERT, UPDATE, DELETE ON mysqltest1.v_t1 TO readonly; +GRANT SELECT ON mysqltest1.v_ts TO readonly; +GRANT INSERT ON mysqltest1.v_ti TO readonly; +GRANT UPDATE ON mysqltest1.v_tu TO readonly; +GRANT UPDATE,SELECT ON mysqltest1.v_tus TO readonly; +GRANT DELETE ON mysqltest1.v_td TO readonly; +GRANT DELETE,SELECT ON mysqltest1.v_tds TO readonly; + +CONNECT (n1,localhost,readonly,,); +CONNECTION n1; + +--error 1356 +SELECT * FROM mysqltest1.v_t1; +--error 1356 +INSERT INTO mysqltest1.v_t1 VALUES(4); +--error 1356 +DELETE FROM mysqltest1.v_t1 WHERE x = 1; +--error 1356 +UPDATE mysqltest1.v_t1 SET x = 3 WHERE x = 2; +--error 1356 +UPDATE mysqltest1.v_t1 SET x = 3; +--error 1356 +DELETE FROM mysqltest1.v_t1; +--error 1356 +SELECT 1 FROM mysqltest1.v_t1; +--error 1142 +SELECT * FROM mysqltest1.t1; + +SELECT * FROM mysqltest1.v_ts; +--error 1142 +SELECT * FROM mysqltest1.v_ts, mysqltest1.t1 WHERE mysqltest1.t1.x = mysqltest1.v_ts.x; +--error 1142 +SELECT * FROM mysqltest1.v_ti; + +--error 1142 +INSERT INTO mysqltest1.v_ts VALUES (100); +INSERT INTO mysqltest1.v_ti VALUES (100); + +--error 1142 +UPDATE mysqltest1.v_ts SET x= 200 WHERE x = 100; +--error 1142 +UPDATE mysqltest1.v_ts SET x= 200; +UPDATE mysqltest1.v_tu SET x= 200 WHERE x = 100; +UPDATE mysqltest1.v_tus SET x= 200 WHERE x = 100; +UPDATE mysqltest1.v_tu SET x= 200; + +--error 1142 +DELETE FROM mysqltest1.v_ts WHERE x= 200; +--error 1142 +DELETE FROM mysqltest1.v_ts; +--error 1143 +DELETE FROM mysqltest1.v_td WHERE x= 200; +DELETE FROM mysqltest1.v_tds WHERE x= 200; +DELETE FROM mysqltest1.v_td; + +CONNECTION default; +DROP VIEW mysqltest1.v_tds; +DROP VIEW mysqltest1.v_td; +DROP VIEW mysqltest1.v_tus; +DROP VIEW mysqltest1.v_tu; +DROP VIEW mysqltest1.v_ti; +DROP VIEW mysqltest1.v_ts; +DROP VIEW mysqltest1.v_t1; +DROP TABLE mysqltest1.t1; +DROP USER readonly@localhost; +DROP DATABASE mysqltest1; + +# +# BUG#14875: Bad view DEFINER makes SHOW CREATE VIEW fail +# +CREATE TABLE t1 (a INT PRIMARY KEY); +INSERT INTO t1 VALUES (1), (2), (3); +CREATE DEFINER = 'no-such-user'@localhost VIEW v AS SELECT a from t1; +--warning 1448 +SHOW CREATE VIEW v; +--error 1449 +SELECT * FROM v; +DROP VIEW v; +DROP TABLE t1; +USE test; diff --git a/mysql-test/t/wait_timeout.test b/mysql-test/t/wait_timeout.test index 1fef3deea3c..9310c3502b9 100644 --- a/mysql-test/t/wait_timeout.test +++ b/mysql-test/t/wait_timeout.test @@ -4,10 +4,41 @@ # # Bug #8731: wait_timeout does not work on Mac OS X # + + +# Connect with another connection and reset counters +--disable_query_log +connect (wait_con,localhost,root,,test,,); +flush status; # Reset counters +connection wait_con; +let $retries=300; +let $aborted_clients = `SHOW STATUS LIKE 'aborted_clients'`; +set @aborted_clients= 0; +--enable_query_log + +# Disable reconnect and do the query +connection default; --disable_reconnect select 1; -# wait_timeout is 1, so we should get disconnected now ---sleep 2 + +# Switch to wait_con and wait until server has aborted the connection +--disable_query_log +connection wait_con; +while (!`select @aborted_clients`) +{ + sleep 0.1; + let $aborted_clients = `SHOW STATUS LIKE 'aborted_clients'`; + eval set @aborted_clients= SUBSTRING('$aborted_clients', 16)+0; + + dec $retries; + if (!$retries) + { + Failed to detect that client has been aborted; + } +} +--enable_query_log + +connection default; # When the connection is closed in this way, the error code should # be consistent see bug#2845 for an explanation --error 2006 @@ -15,12 +46,41 @@ select 2; --enable_reconnect select 3; +# # Do the same test as above on a TCP connection +# (which we get by specifying a ip adress) + +# Connect with another connection and reset counters +--disable_query_log +connection wait_con; +flush status; # Reset counters +let $retries=300; +let $aborted_clients = `SHOW STATUS LIKE 'aborted_clients'`; +set @aborted_clients= 0; +--enable_query_log + connect (con1,127.0.0.1,root,,test,$MASTER_MYPORT,); --disable_reconnect select 1; -# wait_timeout is 1, so we should get disconnected now ---sleep 2 + +# Switch to wait_con and wait until server has aborted the connection +--disable_query_log +connection wait_con; +while (!`select @aborted_clients`) +{ + sleep 0.1; + let $aborted_clients = `SHOW STATUS LIKE 'aborted_clients'`; + eval set @aborted_clients= SUBSTRING('$aborted_clients', 16)+0; + + dec $retries; + if (!$retries) + { + Failed to detect that client has been aborted; + } +} +--enable_query_log + +connection con1; # When the connection is closed in this way, the error code should # be consistent see bug#2845 for an explanation --error 2006 diff --git a/mysql-test/valgrind.supp b/mysql-test/valgrind.supp index 1a08abcf953..258e4d4a22b 100644 --- a/mysql-test/valgrind.supp +++ b/mysql-test/valgrind.supp @@ -11,26 +11,65 @@ fun:calloc fun:_dl_allocate_tls fun:allocate_stack + fun:pthread_create* +} + +{ + pthread allocate_tls memory loss 2 + Memcheck:Leak + fun:calloc + fun:_dl_allocate_tls fun:pthread_create@@GLIBC_2.1 } { - pthread allocate_dtv memory loss + pthead_exit memory loss 1 + Memcheck:Leak + fun:malloc + fun:_dl_new_object + fun:_dl_map_object_from_fd +} + +{ + pthread_exit memory loss 2 + Memcheck:Leak + fun:malloc + fun:_dl_map_object + fun:dl_open_worker +} + +{ + pthread_exit memory loss 3 + Memcheck:Leak + fun:malloc + fun:_dl_map_object_deps + fun:dl_open_worker +} + +{ + pthread_exit memory loss 4 Memcheck:Leak fun:calloc - fun:allocate_dtv - fun:_dl_allocate_tls_storage - fun:__GI__dl_allocate_tls - fun:pthread_create + fun:_dl_check_map_versions + fun:dl_open_worker } { - pthread allocate_dtv memory loss second + pthread_exit memory loss 5 + Memcheck:Leak + fun:calloc + fun:_dl_new_object + fun:_dl_map_object_from_fd +} + +{ + pthread allocate_dtv memory loss Memcheck:Leak fun:calloc fun:allocate_dtv - fun:_dl_allocate_tls - fun:pthread_create* + fun:_dl_allocate_tls_storage + fun:__GI__dl_allocate_tls + fun:pthread_create } { @@ -83,6 +122,15 @@ obj:/lib/ld-*.so } +{ + strlen/_dl_init_paths/dl_main/_dl_sysdep_start(Cond) + Memcheck:Cond + fun:strlen + fun:_dl_init_paths + fun:dl_main + fun:_dl_sysdep_start +} + { pthread errno Memcheck:Leak @@ -135,6 +183,24 @@ } { + libz longest_match3 + Memcheck:Cond + fun:longest_match + fun:deflate_slow + fun:deflate + fun:azflush +} + +{ + libz longest_match3 + Memcheck:Cond + fun:longest_match + fun:deflate_slow + fun:deflate + fun:azclose +} + +{ libz deflate Memcheck:Cond obj:*/libz.so.* @@ -174,6 +240,173 @@ fun:kill_server_thread } + +# Red Hat AS 4 32 bit +{ + dl_relocate_object + Memcheck:Cond + fun:_dl_relocate_object +} + +# +# Leaks reported in _dl_* internal functions on Linux amd64 / glibc2.3.2. +# + +{ + _dl_start invalid write8 + Memcheck:Addr8 + fun:_dl_start +} + +{ + _dl_start invalid write4 + Memcheck:Addr4 + fun:_dl_start +} + +{ + _dl_start/_dl_setup_hash invalid read8 + Memcheck:Addr8 + fun:_dl_setup_hash + fun:_dl_start +} + +{ + _dl_sysdep_start invalid write8 + Memcheck:Addr8 + fun:_dl_sysdep_start +} + +{ + _dl_init invalid write8 + Memcheck:Addr8 + fun:_dl_init +} + +{ + _dl_init invalid write4 + Memcheck:Addr4 + fun:_dl_init +} + +{ + _dl_init/_dl_init invalid read8 + Memcheck:Addr8 + fun:_dl_debug_initialize + fun:_dl_init +} + +{ + _dl_init/_dl_debug_state invalid read8 + Memcheck:Addr8 + fun:_dl_debug_state + fun:_dl_init +} + +{ + init invalid write8 + Memcheck:Addr8 + fun:init +} + +{ + fixup invalid write8 + Memcheck:Addr8 + fun:fixup +} + +{ + fixup/_dl_lookup_versioned_symbol invalid read8 + Memcheck:Addr8 + fun:_dl_lookup_versioned_symbol + fun:fixup +} + +{ + _dl_runtime_resolve invalid read8 + Memcheck:Addr8 + fun:_dl_runtime_resolve +} + +{ + __libc_start_main invalid write8 + Memcheck:Addr8 + fun:__libc_start_main +} + +{ + __libc_start_main/__sigjmp_save invalid write4 + Memcheck:Addr4 + fun:__sigjmp_save + fun:__libc_start_main +} + +# +# These seem to be libc threading stuff, not related to MySQL code (allocations +# during pthread_exit()). Googling shows other projects also using these +# suppressions. +# +# Note that these all stem from pthread_exit() deeper in the call stack, but +# Valgrind only allows the top four calls in the suppressions. +# + +{ + libc pthread_exit 1 + Memcheck:Leak + fun:malloc + fun:_dl_new_object + fun:_dl_map_object_from_fd + fun:_dl_map_object +} + +{ + libc pthread_exit 2 + Memcheck:Leak + fun:malloc + fun:_dl_map_object + fun:dl_open_worker + fun:_dl_catch_error +} + +{ + libc pthread_exit 3 + Memcheck:Leak + fun:malloc + fun:_dl_map_object_deps + fun:dl_open_worker + fun:_dl_catch_error +} + +{ + libc pthread_exit 4 + Memcheck:Leak + fun:calloc + fun:_dl_check_map_versions + fun:dl_open_worker + fun:_dl_catch_error +} + +{ + libc pthread_exit 5 + Memcheck:Leak + fun:calloc + fun:_dl_new_object + fun:_dl_map_object_from_fd + fun:_dl_map_object +} + + +# +# This is seen internally in the system libraries on 64-bit RHAS3. +# + +{ + __lll_mutex_unlock_wake uninitialized + Memcheck:Param + futex(utime) + fun:__lll_mutex_unlock_wake +} + # # Warning when printing stack trace (to suppress some not needed warnings) # diff --git a/mysql-test/valgrind.supp.orig b/mysql-test/valgrind.supp.orig new file mode 100644 index 00000000000..1a08abcf953 --- /dev/null +++ b/mysql-test/valgrind.supp.orig @@ -0,0 +1,189 @@ +# +# Suppress some common (not fatal) errors in system libraries found by valgrind +# + +# +# Pthread doesn't free all thread specific memory before program exists +# +{ + pthread allocate_tls memory loss + Memcheck:Leak + fun:calloc + fun:_dl_allocate_tls + fun:allocate_stack + fun:pthread_create@@GLIBC_2.1 +} + +{ + pthread allocate_dtv memory loss + Memcheck:Leak + fun:calloc + fun:allocate_dtv + fun:_dl_allocate_tls_storage + fun:__GI__dl_allocate_tls + fun:pthread_create +} + +{ + pthread allocate_dtv memory loss second + Memcheck:Leak + fun:calloc + fun:allocate_dtv + fun:_dl_allocate_tls + fun:pthread_create* +} + +{ + pthread allocate_dtv memory loss second + Memcheck:Leak + fun:calloc + fun:allocate_dtv + fun:_dl_allocate_tls + fun:pthread_create* +} + +{ + pthread memalign memory loss + Memcheck:Leak + fun:memalign + fun:_dl_allocate_tls_storage + fun:__GI__dl_allocate_tls + fun:pthread_create +} + +{ + pthread pthread_key_create + Memcheck:Leak + fun:malloc + fun:* + fun:* + fun:pthread_key_create + fun:my_thread_global_init +} + +{ + pthread strstr uninit + Memcheck:Cond + fun:strstr + obj:/lib/tls/libpthread.so.* + obj:/lib/tls/libpthread.so.* + fun:call_init + fun:_dl_init + obj:/lib/ld-*.so +} + +{ + pthread strstr uninit + Memcheck:Cond + fun:strstr + obj:/lib/tls/libpthread.so.* + obj:/lib/tls/libpthread.so.* + fun:call_init + fun:_dl_init + obj:/lib/ld-*.so +} + +{ + pthread errno + Memcheck:Leak + fun:calloc + fun:_dlerror_run + fun:dlsym + fun:__errno_location +} + + +# +# Warnings in libz becasue it works with aligned memory(?) +# + +{ + libz tr_flush_block + Memcheck:Cond + fun:_tr_flush_block + fun:deflate_slow + fun:deflate + fun:do_flush + fun:gzclose +} + +{ + libz tr_flush_block2 + Memcheck:Cond + fun:_tr_flush_block + fun:deflate_slow + fun:deflate + fun:compress2 +} + +{ + libz longest_match + Memcheck:Cond + fun:longest_match + fun:deflate_slow + fun:deflate + fun:do_flush +} + +{ + libz longest_match2 + Memcheck:Cond + fun:longest_match + fun:deflate_slow + fun:deflate + fun:compress2 +} + +{ + libz deflate + Memcheck:Cond + obj:*/libz.so.* + obj:*/libz.so.* + fun:deflate + fun:compress2 +} + +{ + libz deflate2 + Memcheck:Cond + obj:*/libz.so.* + obj:*/libz.so.* + fun:deflate + obj:*/libz.so.* + fun:gzflush +} + +{ + libz deflate3 + Memcheck:Cond + obj:*/libz.so.* + obj:*/libz.so.* + fun:deflate + fun:do_flush +} + +# +# Warning from my_thread_init becasue mysqld dies before kill thread exists +# + +{ + my_thread_init kill thread memory loss second + Memcheck:Leak + fun:calloc + fun:my_thread_init + fun:kill_server_thread +} + +# +# Warning when printing stack trace (to suppress some not needed warnings) +# + +{ + vprintf on stacktrace + Memcheck:Cond + fun:vfprintf + fun:uffered_vfprintf + fun:vfprintf + fun:fprintf + fun:print_stacktrace +} diff --git a/mysys/cmakelists.txt b/mysys/CMakeLists.txt index 4aa99a70121..4aa99a70121 100644 --- a/mysys/cmakelists.txt +++ b/mysys/CMakeLists.txt diff --git a/mysys/Makefile.am b/mysys/Makefile.am index abc5cc142f5..2838427e9e0 100644 --- a/mysys/Makefile.am +++ b/mysys/Makefile.am @@ -20,8 +20,7 @@ MYSQLBASEdir= $(prefix) INCLUDES = @ZLIB_INCLUDES@ -I$(top_builddir)/include \ -I$(top_srcdir)/include -I$(srcdir) pkglib_LIBRARIES = libmysys.a -LDADD = libmysys.a ../dbug/libdbug.a \ - ../strings/libmystrings.a +LDADD = libmysys.a $(top_builddir)/strings/libmystrings.a noinst_HEADERS = mysys_priv.h my_static.h libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c my_mmap.c \ mf_path.c mf_loadpath.c my_file.c \ @@ -32,7 +31,7 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c my_mmap.c \ mf_tempdir.c my_lock.c mf_brkhant.c my_alarm.c \ my_malloc.c my_realloc.c my_once.c mulalloc.c \ my_alloc.c safemalloc.c my_new.cc \ - my_vle.c \ + my_vle.c my_atomic.c \ my_fopen.c my_fstream.c my_getsystime.c \ my_error.c errors.c my_div.c my_messnc.c \ mf_format.c mf_same.c mf_dirname.c mf_fn_ext.c \ @@ -40,7 +39,7 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c my_mmap.c \ mf_pack.c mf_unixpath.c mf_strip.c \ mf_wcomp.c mf_wfile.c my_gethwaddr.c \ mf_qsort.c mf_qsort2.c mf_sort.c \ - ptr_cmp.c mf_radix.c queues.c \ + ptr_cmp.c mf_radix.c queues.c my_getncpus.c \ tree.c trie.c list.c hash.c array.c string.c typelib.c \ my_copy.c my_append.c my_lib.c \ my_delete.c my_rename.c my_redel.c \ @@ -57,14 +56,13 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c my_mmap.c \ my_windac.c my_access.c base64.c EXTRA_DIST = thr_alarm.c thr_lock.c my_pthread.c my_thr_init.c \ thr_mutex.c thr_rwlock.c \ - cmakelists.txt mf_soundex.c \ + CMakeLists.txt mf_soundex.c \ my_conio.c my_wincond.c my_winsem.c my_winthread.c libmysys_a_LIBADD = @THREAD_LOBJECTS@ # test_dir_DEPENDENCIES= $(LIBRARIES) # testhash_DEPENDENCIES= $(LIBRARIES) # test_charset_DEPENDENCIES= $(LIBRARIES) # charset2html_DEPENDENCIES= $(LIBRARIES) -EXTRA_PROGRAMS = DEFS = -DDEFAULT_BASEDIR=\"$(prefix)\" \ -DDATADIR="\"$(MYSQLDATAdir)\"" \ -DDEFAULT_CHARSET_HOME="\"$(MYSQLBASEdir)\"" \ diff --git a/mysys/default.c b/mysys/default.c index 580bcc19eca..863ebc37dbc 100644 --- a/mysys/default.c +++ b/mysys/default.c @@ -244,7 +244,8 @@ err: handle_option_ctx structure. group_name The name of the group the option belongs to. option The very option to be processed. It is already - prepared to be used in argv (has -- prefix) + prepared to be used in argv (has -- prefix). If it + is NULL, we are handling a new group (section). DESCRIPTION This handler checks whether a group is one of the listed and adds an option @@ -263,6 +264,9 @@ static int handle_default_option(void *in_ctx, const char *group_name, char *tmp; struct handle_option_ctx *ctx= (struct handle_option_ctx *) in_ctx; + if (!option) + return 0; + if (find_type((char *)group_name, ctx->group, 3)) { if (!(tmp= alloc_root(ctx->alloc, (uint) strlen(option) + 1))) @@ -719,6 +723,10 @@ static int search_default_file_with_ext(Process_option_func opt_handler, end[0]=0; strnmov(curr_gr, ptr, min((uint) (end-ptr)+1, 4096)); + + /* signal that a new group is found */ + opt_handler(handler_ctx, curr_gr, NULL); + continue; } if (!found_group) @@ -755,7 +763,9 @@ static int search_default_file_with_ext(Process_option_func opt_handler, value_end=value; /* remove quotes around argument */ - if ((*value == '\"' || *value == '\'') && *value == value_end[-1]) + if ((*value == '\"' || *value == '\'') && /* First char is quote */ + (value + 1 < value_end ) && /* String is longer than 1 */ + *value == value_end[-1] ) /* First char is equal to last char */ { value++; value_end--; diff --git a/mysys/default_modify.c b/mysys/default_modify.c index 0f58b8a930c..8dbcac699ea 100644 --- a/mysys/default_modify.c +++ b/mysys/default_modify.c @@ -40,11 +40,13 @@ static char *add_option(char *dst, const char *option_value, SYNOPSYS modify_defaults_file() file_location The location of configuration file to edit - option option to look for - option value The value of the option we would like to set - section_name the name of the section - remove_option This is true if we want to remove the option. - False otherwise. + option The name of the option to look for (can be NULL) + option value The value of the option we would like to set (can be NULL) + section_name The name of the section (must be NOT NULL) + remove_option This defines what we want to remove: + - MY_REMOVE_NONE -- nothing to remove; + - MY_REMOVE_OPTION -- remove the specified option; + - MY_REMOVE_SECTION -- remove the specified section; IMPLEMENTATION We open the option file first, then read the file line-by-line, looking for the section we need. At the same time we put these lines @@ -67,7 +69,9 @@ int modify_defaults_file(const char *file_location, const char *option, FILE *cnf_file; MY_STAT file_stat; char linebuff[BUFF_SIZE], *src_ptr, *dst_ptr, *file_buffer; - uint opt_len, optval_len, sect_len, nr_newlines= 0, buffer_size; + uint opt_len= 0; + uint optval_len= 0; + uint sect_len, nr_newlines= 0, buffer_size; my_bool in_section= FALSE, opt_applied= 0; uint reserve_extended; uint new_opt_len; @@ -81,8 +85,11 @@ int modify_defaults_file(const char *file_location, const char *option, if (my_fstat(fileno(cnf_file), &file_stat, MYF(0))) goto malloc_err; - opt_len= (uint) strlen(option); - optval_len= (uint) strlen(option_value); + if (option && option_value) + { + opt_len= (uint) strlen(option); + optval_len= (uint) strlen(option_value); + } new_opt_len= opt_len + 1 + optval_len + NEWLINE_LEN; @@ -119,8 +126,8 @@ int modify_defaults_file(const char *file_location, const char *option, continue; } - /* correct the option */ - if (in_section && !strncmp(src_ptr, option, opt_len) && + /* correct the option (if requested) */ + if (option && in_section && !strncmp(src_ptr, option, opt_len) && (*(src_ptr + opt_len) == '=' || my_isspace(&my_charset_latin1, *(src_ptr + opt_len)) || *(src_ptr + opt_len) == '\0')) @@ -143,7 +150,12 @@ int modify_defaults_file(const char *file_location, const char *option, } else { - /* If going to new group and we have option to apply, do it now */ + /* + If we are going to the new group and have an option to apply, do + it now. If we are removing a single option or the whole section + this will only trigger opt_applied flag. + */ + if (in_section && !opt_applied && *src_ptr == '[') { dst_ptr= add_option(dst_ptr, option_value, option, remove_option); @@ -153,7 +165,10 @@ int modify_defaults_file(const char *file_location, const char *option, for (; nr_newlines; nr_newlines--) dst_ptr= strmov(dst_ptr, NEWLINE); - dst_ptr= strmov(dst_ptr, linebuff); + + /* Skip the section if MY_REMOVE_SECTION was given */ + if (!in_section || remove_option != MY_REMOVE_SECTION) + dst_ptr= strmov(dst_ptr, linebuff); } /* Look for a section */ if (*src_ptr == '[') @@ -167,18 +182,31 @@ int modify_defaults_file(const char *file_location, const char *option, {} if (*src_ptr != ']') + { + in_section= FALSE; continue; /* Missing closing parenthesis. Assume this was no group */ + } + + if (remove_option == MY_REMOVE_SECTION) + dst_ptr= dst_ptr - strlen(linebuff); + in_section= TRUE; } else in_section= FALSE; /* mark that this section is of no interest to us */ } } - /* File ended. */ - if (!opt_applied && !remove_option && in_section) + + /* + File ended. Apply an option or set opt_applied flag (in case of + MY_REMOVE_SECTION) so that the changes are saved. Do not do anything + if we are removing non-existent option. + */ + + if (!opt_applied && in_section && (remove_option != MY_REMOVE_OPTION)) { /* New option still remains to apply at the end */ - if (*(dst_ptr - 1) != '\n') + if (!remove_option && *(dst_ptr - 1) != '\n') dst_ptr= strmov(dst_ptr, NEWLINE); dst_ptr= add_option(dst_ptr, option_value, option, remove_option); opt_applied= 1; diff --git a/mysys/mf_keycache.c b/mysys/mf_keycache.c index 1dab9a47ed8..71d73048a7b 100644 --- a/mysys/mf_keycache.c +++ b/mysys/mf_keycache.c @@ -84,14 +84,6 @@ #define KEYCACHE_DEBUG_LOG "my_key_cache_debug.log" */ -#if defined(MSDOS) && !defined(M_IC80386) -/* we nead much memory */ -#undef my_malloc_lock -#undef my_free_lock -#define my_malloc_lock(A,B) halloc((long) (A/IO_SIZE),IO_SIZE) -#define my_free_lock(A,B) hfree(A) -#endif /* defined(MSDOS) && !defined(M_IC80386) */ - #define STRUCT_PTR(TYPE, MEMBER, a) \ (TYPE *) ((char *) (a) - offsetof(TYPE, MEMBER)) diff --git a/mysys/mf_path.c b/mysys/mf_path.c index cdaee74dd2c..571c4aa9fba 100644 --- a/mysys/mf_path.c +++ b/mysys/mf_path.c @@ -73,7 +73,7 @@ my_string my_path(my_string to, const char *progname, /* test if file without filename is found in path */ /* Returns to if found and to has dirpart if found, else NullS */ -#if defined(MSDOS) || defined(__WIN__) +#if defined(__WIN__) #define F_OK 0 #define PATH_SEP ';' #define PROGRAM_EXTENSION ".exe" diff --git a/mysys/mf_tempfile.c b/mysys/mf_tempfile.c index b079b9ec8e3..4f6cbd2f243 100644 --- a/mysys/mf_tempfile.c +++ b/mysys/mf_tempfile.c @@ -24,7 +24,7 @@ #endif #ifdef HAVE_TEMPNAM -#if !defined(MSDOS) && !defined(__NETWARE__) +#if !defined(__NETWARE__) extern char **environ; #endif #endif diff --git a/mysys/my_access.c b/mysys/my_access.c index 871de8de0b8..9255d716919 100644 --- a/mysys/my_access.c +++ b/mysys/my_access.c @@ -156,7 +156,7 @@ int check_if_legal_tablename(const char *name) } -#if defined(MSDOS) || defined(__WIN__) || defined(__EMX__) +#if defined(__WIN__) || defined(__EMX__) /* @@ -199,4 +199,4 @@ int check_if_legal_filename(const char *path) DBUG_RETURN(0); } -#endif /* defined(MSDOS) || defined(__WIN__) || defined(__EMX__) */ +#endif /* defined(__WIN__) || defined(__EMX__) */ diff --git a/mysys/my_atomic.c b/mysys/my_atomic.c new file mode 100644 index 00000000000..21b80f0f6a1 --- /dev/null +++ b/mysys/my_atomic.c @@ -0,0 +1,46 @@ +/* Copyright (C) 2006 MySQL 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 */ + +#include <my_global.h> +#include <my_pthread.h> + +#ifndef HAVE_INLINE +/* + the following will cause all inline functions to be instantiated +*/ +#define HAVE_INLINE +#define static extern +#endif + +#include <my_atomic.h> + +/* + checks that the current build of atomic ops + can run on this machine + + RETURN + ATOMIC_xxx values, see my_atomic.h +*/ +int my_atomic_initialize() +{ + /* currently the only thing worth checking is SMP/UP issue */ +#ifdef MY_ATOMIC_MODE_DUMMY + return my_getncpus() == 1 ? MY_ATOMIC_OK : MY_ATOMIC_NOT_1CPU; +#else + return MY_ATOMIC_OK; +#endif +} + diff --git a/mysys/my_clock.c b/mysys/my_clock.c index 384239bb2b2..41d659c0ffe 100644 --- a/mysys/my_clock.c +++ b/mysys/my_clock.c @@ -24,7 +24,7 @@ long my_clock(void) { -#if !defined(MSDOS) && !defined(__WIN__) && !defined(__NETWARE__) +#if !defined(__WIN__) && !defined(__NETWARE__) struct tms tmsbuf; VOID(times(&tmsbuf)); return (tmsbuf.tms_utime + tmsbuf.tms_stime); diff --git a/mysys/my_copy.c b/mysys/my_copy.c index 342b1cdc104..a8a3a775040 100644 --- a/mysys/my_copy.c +++ b/mysys/my_copy.c @@ -95,7 +95,7 @@ int my_copy(const char *from, const char *to, myf MyFlags) if (MyFlags & MY_HOLD_ORIGINAL_MODES && !new_file_stat) DBUG_RETURN(0); /* File copyed but not stat */ VOID(chmod(to, stat_buff.st_mode & 07777)); /* Copy modes */ -#if !defined(MSDOS) && !defined(__WIN__) && !defined(__NETWARE__) +#if !defined(__WIN__) && !defined(__NETWARE__) VOID(chown(to, stat_buff.st_uid,stat_buff.st_gid)); /* Copy ownership */ #endif #if !defined(VMS) && !defined(__ZTC__) diff --git a/mysys/my_create.c b/mysys/my_create.c index d42e7e0db69..d27edb31d32 100644 --- a/mysys/my_create.c +++ b/mysys/my_create.c @@ -19,7 +19,7 @@ #include <my_dir.h> #include "mysys_err.h" #include <errno.h> -#if defined(MSDOS) || defined(__WIN__) +#if defined(__WIN__) #include <share.h> #endif @@ -47,13 +47,6 @@ File my_create(const char *FileName, int CreateFlags, int access_flags, #elif defined(VMS) fd = open((my_string) FileName, access_flags | O_CREAT, 0, "ctx=stm","ctx=bin"); -#elif defined(MSDOS) - if (access_flags & O_SHARE) - fd = sopen((my_string) FileName, access_flags | O_CREAT | O_BINARY, - SH_DENYNO, MY_S_IREAD | MY_S_IWRITE); - else - fd = open((my_string) FileName, access_flags | O_CREAT | O_BINARY, - MY_S_IREAD | MY_S_IWRITE); #elif defined(__WIN__) fd= my_sopen((my_string) FileName, access_flags | O_CREAT | O_BINARY, SH_DENYNO, MY_S_IREAD | MY_S_IWRITE); diff --git a/mysys/my_dup.c b/mysys/my_dup.c index f4c420eb459..9666f5b1858 100644 --- a/mysys/my_dup.c +++ b/mysys/my_dup.c @@ -19,7 +19,7 @@ #include "mysys_err.h" #include <my_dir.h> #include <errno.h> -#if defined(MSDOS) || defined(__WIN__) +#if defined(__WIN__) #include <share.h> #endif diff --git a/mysys/my_gethostbyname.c b/mysys/my_gethostbyname.c index 27281f3489d..0644ba02bbd 100644 --- a/mysys/my_gethostbyname.c +++ b/mysys/my_gethostbyname.c @@ -18,7 +18,7 @@ /* Thread safe version of gethostbyname_r() */ #include "mysys_priv.h" -#if !defined(MSDOS) && !defined(__WIN__) +#if !defined(__WIN__) #include <netdb.h> #endif #include <my_net.h> diff --git a/mysys/my_getncpus.c b/mysys/my_getncpus.c new file mode 100644 index 00000000000..6c45617e496 --- /dev/null +++ b/mysys/my_getncpus.c @@ -0,0 +1,40 @@ +/* Copyright (C) 2006 MySQL 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 */ + +/* get the number of (online) CPUs */ + +#include "mysys_priv.h" +#include <unistd.h> + +static int ncpus=0; + +#ifdef _SC_NPROCESSORS_ONLN +int my_getncpus() +{ + if (!ncpus) + ncpus= sysconf(_SC_NPROCESSORS_ONLN); + return ncpus; +} + +#else +/* unknown */ +int my_getncpus() +{ + return 2; +} + +#endif + diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index 95dc5afeae9..4de2984d9b9 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -486,7 +486,7 @@ invalid value '%s'\n", } get_one_option(optp->id, optp, argument); - (*argc)--; /* option handled (short or long), decrease argument count */ + (*argc)--; /* option handled (short or long), decrease argument count */ } else /* non-option found */ (*argv)[argvpos++]= cur_arg; diff --git a/mysys/my_getwd.c b/mysys/my_getwd.c index 765c30bc281..de8ad108ba4 100644 --- a/mysys/my_getwd.c +++ b/mysys/my_getwd.c @@ -22,7 +22,7 @@ #ifdef HAVE_GETWD #include <sys/param.h> #endif -#if defined(MSDOS) || defined(__WIN__) +#if defined(__WIN__) #include <m_ctype.h> #include <dos.h> #include <direct.h> @@ -39,11 +39,9 @@ int my_getwd(my_string buf, uint size, myf MyFlags) DBUG_ENTER("my_getwd"); DBUG_PRINT("my",("buf: 0x%lx size: %d MyFlags %d", buf,size,MyFlags)); -#if ! defined(MSDOS) if (curr_dir[0]) /* Current pos is saved here */ VOID(strmake(buf,&curr_dir[0],size-1)); else -#endif { #if defined(HAVE_GETCWD) if (!getcwd(buf,size-2) && MyFlags & MY_WME) @@ -87,43 +85,13 @@ int my_setwd(const char *dir, myf MyFlags) int res; size_s length; my_string start,pos; -#if defined(VMS) || defined(MSDOS) +#if defined(VMS) char buff[FN_REFLEN]; #endif DBUG_ENTER("my_setwd"); DBUG_PRINT("my",("dir: '%s' MyFlags %d", dir, MyFlags)); start=(my_string) dir; -#if defined(MSDOS) /* MSDOS chdir can't change drive */ -#if !defined(_DDL) && !defined(WIN32) - if ((pos=(char*) strchr(dir,FN_DEVCHAR)) != 0) - { - uint drive,drives; - - pos++; /* Skip FN_DEVCHAR */ - drive=(uint) (my_toupper(&my_charset_latin1,dir[0])-'A'+1); - drives= (uint) -1; - if ((pos-(byte*) dir) == 2 && drive > 0 && drive < 32) - { - _dos_setdrive(drive,&drives); - _dos_getdrive(&drives); - } - if (drive != drives) - { - *pos='\0'; /* Dir is now only drive */ - my_errno=errno; - my_error(EE_SETWD,MYF(ME_BELL+ME_WAITTANG),dir,ENOENT); - DBUG_RETURN(-1); - } - dir=pos; /* drive changed, change now path */ - } -#endif - if (*((pos=strend(dir)-1)) == FN_LIBCHAR && pos != dir) - { - strmov(buff,dir)[-1]=0; /* Remove last '/' */ - dir=buff; - } -#endif /* MSDOS*/ if (! dir[0] || (dir[0] == FN_LIBCHAR && dir[1] == 0)) dir=FN_ROOTDIR; #ifdef VMS diff --git a/mysys/my_init.c b/mysys/my_init.c index 4d7299c7cb1..588bb6f46d6 100644 --- a/mysys/my_init.c +++ b/mysys/my_init.c @@ -181,7 +181,7 @@ Voluntary context switches %ld, Involuntary context switches %ld\n", rus.ru_msgsnd, rus.ru_msgrcv, rus.ru_nsignals, rus.ru_nvcsw, rus.ru_nivcsw); #endif -#if ( defined(MSDOS) || defined(__NETWARE__) ) && !defined(__WIN__) +#if defined(__NETWARE__) && !defined(__WIN__) fprintf(info_file,"\nRun time: %.1f\n",(double) clock()/CLOCKS_PER_SEC); #endif #if defined(SAFEMALLOC) @@ -197,8 +197,10 @@ Voluntary context switches %ld, Involuntary context switches %ld\n", _CrtDumpMemoryLeaks(); #endif } + + if (!(infoflag & MY_DONT_FREE_DBUG)) + DBUG_END(); /* Must be done before my_thread_end */ #ifdef THREAD - DBUG_POP(); /* Must be done before my_thread_end */ my_thread_end(); my_thread_global_end(); #if defined(SAFE_MUTEX) diff --git a/mysys/my_lib.c b/mysys/my_lib.c index e96286a94a8..42c57e9d3c4 100644 --- a/mysys/my_lib.c +++ b/mysys/my_lib.c @@ -15,7 +15,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* TODO: check for overun of memory for names. */ -/* Convert MSDOS-TIME to standar time_t */ +/* Convert MSDOS-TIME to standar time_t (still needed?) */ #define USES_TYPES /* sys/types is included */ #include "mysys_priv.h" @@ -37,7 +37,7 @@ # if defined(HAVE_NDIR_H) # include <ndir.h> # endif -# if defined(MSDOS) || defined(__WIN__) +# if defined(__WIN__) # include <dos.h> # ifdef __BORLANDC__ # include <dir.h> @@ -94,7 +94,7 @@ static int comp_names(struct fileinfo *a, struct fileinfo *b) } /* comp_names */ -#if !defined(MSDOS) && !defined(__WIN__) +#if !defined(__WIN__) MY_DIR *my_dir(const char *path, myf MyFlags) { @@ -347,7 +347,7 @@ my_string directory_file_name (my_string dst, const char *src) #endif /* VMS */ } /* directory_file_name */ -#elif defined(WIN32) +#else /* ***************************************************************************** @@ -386,7 +386,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags) *tmp_file++= '.'; /* From current dev-dir */ if (tmp_file[-1] != FN_LIBCHAR) *tmp_file++ =FN_LIBCHAR; - tmp_file[0]='*'; /* MSDOS needs this !??? */ + tmp_file[0]='*'; /* Windows needs this !??? */ tmp_file[1]='.'; tmp_file[2]='*'; tmp_file[3]='\0'; @@ -509,109 +509,7 @@ error: DBUG_RETURN((MY_DIR *) NULL); } /* my_dir */ -#else /* MSDOS and not WIN32 */ - - -/****************************************************************************** -** At MSDOS you always get stat of files, but time is in packed MSDOS-format -******************************************************************************/ - -MY_DIR *my_dir(const char* path, myf MyFlags) -{ - char *buffer; - MY_DIR *result= 0; - FILEINFO finfo; - DYNAMIC_ARRAY *dir_entries_storage; - MEM_ROOT *names_storage; - struct find_t find; - ushort mode; - char tmp_path[FN_REFLEN],*tmp_file,attrib; - DBUG_ENTER("my_dir"); - DBUG_PRINT("my",("path: '%s' stat: %d MyFlags: %d",path,MyFlags)); - - /* Put LIB-CHAR as last path-character if not there */ - - tmp_file=tmp_path; - if (!*path) - *tmp_file++ ='.'; /* From current dir */ - tmp_file= strmov(tmp_file,path); - if (tmp_file[-1] == FN_DEVCHAR) - *tmp_file++= '.'; /* From current dev-dir */ - if (tmp_file[-1] != FN_LIBCHAR) - *tmp_file++ =FN_LIBCHAR; - tmp_file[0]='*'; /* MSDOS needs this !??? */ - tmp_file[1]='.'; - tmp_file[2]='*'; - tmp_file[3]='\0'; - - if (_dos_findfirst(tmp_path,_A_NORMAL | _A_SUBDIR, &find)) - goto error; - - if (!(buffer= my_malloc(ALIGN_SIZE(sizeof(MY_DIR)) + - ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)) + - sizeof(MEM_ROOT), MyFlags))) - goto error; - - dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR))); - names_storage= (MEM_ROOT*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)) + - ALIGN_SIZE(sizeof(DYNAMIC_ARRAY))); - - if (my_init_dynamic_array(dir_entries_storage, sizeof(FILEINFO), - ENTRIES_START_SIZE, ENTRIES_INCREMENT)) - { - my_free((gptr) buffer,MYF(0)); - goto error; - } - init_alloc_root(names_storage, NAMES_START_SIZE, NAMES_START_SIZE); - - /* MY_DIR structure is allocated and completly initialized at this point */ - result= (MY_DIR*)buffer; - - do - { - if (!(finfo.name= strdup_root(names_storage, find.name))) - goto error; - - if (MyFlags & MY_WANT_STAT) - { - if (!(finfo.mystat= (MY_STAT*)alloc_root(names_storage, - sizeof(MY_STAT)))) - goto error; - - bzero(finfo.mystat, sizeof(MY_STAT)); - finfo.mystat->st_size= find.size; - mode= MY_S_IREAD; attrib= find.attrib; - if (!(attrib & _A_RDONLY)) - mode|= MY_S_IWRITE; - if (attrib & _A_SUBDIR) - mode|= MY_S_IFDIR; - finfo.mystat->st_mode= mode; - finfo.mystat->st_mtime= ((uint32) find.wr_date << 16) + find.wr_time; - } - else - finfo.mystat= NULL; - - if (push_dynamic(dir_entries_storage, (gptr)&finfo)) - goto error; - - } while (_dos_findnext(&find) == 0); - - result->dir_entry= (FILEINFO *)dir_entries_storage->buffer; - result->number_off_files= dir_entries_storage->elements; - - if (!(MyFlags & MY_DONT_SORT)) - qsort((void *) result->dir_entry, result->number_off_files, - sizeof(FILEINFO), (qsort_cmp) comp_names); - DBUG_RETURN(result); - -error: - my_dirend(result); - if (MyFlags & MY_FAE+MY_WME) - my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,errno); - DBUG_RETURN((MY_DIR *) NULL); -} /* my_dir */ - -#endif /* WIN32 && MSDOS */ +#endif /* __WIN__ */ /**************************************************************************** ** File status diff --git a/mysys/my_net.c b/mysys/my_net.c index be92adae353..09c09b280d1 100644 --- a/mysys/my_net.c +++ b/mysys/my_net.c @@ -20,7 +20,7 @@ #include <m_string.h> /* for thread safe my_inet_ntoa */ -#if !defined(MSDOS) && !defined(__WIN__) +#if !defined(__WIN__) #include <netdb.h> #ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> @@ -31,7 +31,7 @@ #ifdef HAVE_ARPA_INET_H #include <arpa/inet.h> #endif -#endif /* !defined(MSDOS) && !defined(__WIN__) */ +#endif /* !defined(__WIN__) */ void my_inet_ntoa(struct in_addr in, char *buf) { diff --git a/mysys/my_open.c b/mysys/my_open.c index ed323b3b1ad..6041ddde9fc 100644 --- a/mysys/my_open.c +++ b/mysys/my_open.c @@ -19,7 +19,7 @@ #include "mysys_err.h" #include <my_dir.h> #include <errno.h> -#if defined(MSDOS) || defined(__WIN__) +#if defined(__WIN__) #include <share.h> #endif @@ -45,7 +45,7 @@ File my_open(const char *FileName, int Flags, myf MyFlags) DBUG_ENTER("my_open"); DBUG_PRINT("my",("Name: '%s' Flags: %d MyFlags: %d", FileName, Flags, MyFlags)); -#if defined(MSDOS) || defined(__WIN__) +#if defined(__WIN__) /* Check that we don't try to open or create a file name that may cause problems for us in the future (like PRN) diff --git a/mysys/my_redel.c b/mysys/my_redel.c index 02d3db8b860..abfe84102ef 100644 --- a/mysys/my_redel.c +++ b/mysys/my_redel.c @@ -90,14 +90,14 @@ int my_copystat(const char *from, const char *to, int MyFlags) return 1; VOID(chmod(to, statbuf.st_mode & 07777)); /* Copy modes */ -#if !defined(MSDOS) && !defined(__WIN__) && !defined(__NETWARE__) +#if !defined(__WIN__) && !defined(__NETWARE__) if (statbuf.st_nlink > 1 && MyFlags & MY_LINK_WARNING) { if (MyFlags & MY_LINK_WARNING) my_error(EE_LINK_WARNING,MYF(ME_BELL+ME_WAITTANG),from,statbuf.st_nlink); } VOID(chown(to, statbuf.st_uid, statbuf.st_gid)); /* Copy ownership */ -#endif /* MSDOS */ +#endif /* !__WIN__ && !__NETWARE__ */ #ifndef VMS #ifndef __ZTC__ diff --git a/plugin/fulltext/Makefile.am b/plugin/fulltext/Makefile.am index 4df5a1dc78a..7b4ae22cbd2 100644 --- a/plugin/fulltext/Makefile.am +++ b/plugin/fulltext/Makefile.am @@ -6,4 +6,4 @@ noinst_LTLIBRARIES= mypluglib.la #pkglib_LTLIBRARIES= mypluglib.la mypluglib_la_SOURCES= plugin_example.c mypluglib_la_LDFLAGS= -module -rpath $(pkglibdir) - +mypluglib_la_CFLAGS= -DMYSQL_DYNAMIC_PLUGIN diff --git a/plugin/fulltext/plugin_example.c b/plugin/fulltext/plugin_example.c index 9b937453ce4..eefb10bd26b 100644 --- a/plugin/fulltext/plugin_example.c +++ b/plugin/fulltext/plugin_example.c @@ -144,10 +144,7 @@ static void add_word(MYSQL_FTPARSER_PARAM *param, char *word, size_t len) MYSQL_FTPARSER_BOOLEAN_INFO bool_info= { FT_TOKEN_WORD, 0, 0, 0, 0, ' ', 0 }; - if (param->mode == MYSQL_FTPARSER_FULL_BOOLEAN_INFO) - param->mysql_add_word(param->mysql_ftparam, word, len, &bool_info); - else - param->mysql_add_word(param->mysql_ftparam, word, len, 0); + param->mysql_add_word(param, word, len, &bool_info); } /* diff --git a/regex/cmakelists.txt b/regex/CMakeLists.txt index e00f339b3b9..e00f339b3b9 100644 --- a/regex/cmakelists.txt +++ b/regex/CMakeLists.txt diff --git a/regex/Makefile.am b/regex/Makefile.am index 6fd5b1b57a2..1f496fcec62 100644 --- a/regex/Makefile.am +++ b/regex/Makefile.am @@ -25,7 +25,7 @@ re_SOURCES = split.c debug.c main.c re_LDFLAGS= @NOINST_LDFLAGS@ EXTRA_DIST = tests CHANGES COPYRIGHT WHATSNEW regexp.c \ debug.ih engine.ih main.ih regcomp.ih regerror.ih \ - regex.3 regex.7 cmakelists.txt + regex.3 regex.7 CMakeLists.txt test: re tests ./re < tests diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 56a2d4a7bc6..af3cbc19cb5 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -30,7 +30,6 @@ bin_SCRIPTS = @server_scripts@ \ mysql_find_rows \ mysqlhotcopy \ mysqldumpslow \ - mysql_explain_log \ mysqld_multi \ mysql_create_system_tables @@ -55,7 +54,6 @@ EXTRA_SCRIPTS = make_binary_distribution.sh \ mysql_find_rows.sh \ mysqlhotcopy.sh \ mysqldumpslow.sh \ - mysql_explain_log.sh \ mysqld_multi.sh \ mysqld_safe.sh \ mysql_create_system_tables.sh @@ -83,7 +81,6 @@ CLEANFILES = @server_scripts@ \ mysql_find_rows \ mysqlhotcopy \ mysqldumpslow \ - mysql_explain_log \ mysql_tableinfo \ mysqld_multi \ make_win_src_distribution \ diff --git a/scripts/make_binary_distribution.sh b/scripts/make_binary_distribution.sh index aa29d48d50d..1b071a294ed 100644 --- a/scripts/make_binary_distribution.sh +++ b/scripts/make_binary_distribution.sh @@ -148,7 +148,7 @@ BIN_FILES="extra/comp_err$BS extra/replace$BS extra/perror$BS \ if [ $BASE_SYSTEM = "netware" ] ; then BIN_FILES="$BIN_FILES \ netware/mysqld_safe$BS netware/mysql_install_db$BS \ - netware/init_db.sql netware/test_db.sql netware/mysql_explain_log$BS \ + netware/init_db.sql netware/test_db.sql$BS \ netware/mysqlhotcopy$BS netware/libmysql$BS netware/init_secure_db.sql \ "; # For all other platforms: diff --git a/scripts/mysql_create_system_tables.sh b/scripts/mysql_create_system_tables.sh index a401e1d0159..69ea8e3d004 100644 --- a/scripts/mysql_create_system_tables.sh +++ b/scripts/mysql_create_system_tables.sh @@ -827,7 +827,7 @@ then c_ev="$c_ev 'HIGH_NOT_PRECEDENCE'" c_ev="$c_ev ) DEFAULT '' NOT NULL," c_ev="$c_ev comment char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default ''," - c_ev="$c_ev PRIMARY KEY (definer, db, name)" + c_ev="$c_ev PRIMARY KEY (db, name)" c_ev="$c_ev ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT 'Events';" fi diff --git a/scripts/mysql_explain_log.sh b/scripts/mysql_explain_log.sh deleted file mode 100644 index 973d9e8a363..00000000000 --- a/scripts/mysql_explain_log.sh +++ /dev/null @@ -1,392 +0,0 @@ -#!@PERL@ -w -use strict; -use DBI; - -use Getopt::Long; -$Getopt::Long::ignorecase=0; - -print "explain_log provided by http://www.mobile.de\n"; -print "=========== ================================\n"; - -my $Param={}; - -$Param->{host}=''; -$Param->{user}=''; -$Param->{password}=''; -$Param->{PrintError}=0; -$Param->{socket}=''; - -if (!GetOptions ('date|d:i' => \$Param->{ViewDate}, - 'host|h:s' => \$Param->{host}, - 'user|u:s' => \$Param->{user}, - 'password|p:s' => \$Param->{password}, - 'printerror|e:s' => \$Param->{PrintError}, - 'socket|s:s' => \$Param->{socket}, - )) { - ShowOptions(); -} -else { - $Param->{UpdateCount} = 0; - $Param->{SelectCount} = 0; - $Param->{IdxUseCount} = 0; - $Param->{LineCount} = 0; - - $Param->{Init} = 0; - $Param->{Field} = 0; - $Param->{Refresh} = 0; - $Param->{QueryCount} = 0; - $Param->{Statistics} =0; - - $Param->{Query} = undef; - $Param->{ALL} = undef ; - $Param->{Comment} = undef ; - - @{$Param->{Rows}} = (qw|possible_keys key type|); - - if ($Param->{ViewDate}) { - $Param->{View} = 0; - } - else { - $Param->{View} = 1; - } - - #print "Date=$Param->{ViewDate}, host=$Param->{host}, user=$Param->{user}, password=$Param->{password}\n"; - - $Param->{dbh}=DBI->connect("DBI:mysql:host=$Param->{host}".($Param->{socket}?";mysql_socket=$Param->{socket}":""),$Param->{user},$Param->{password},{PrintError=>0}); - if (DBI::err()) { - print "Error: " . DBI::errstr() . "\n"; - } - else { - $Param->{Start} = time; - while(<STDIN>) { - $Param->{LineCount} ++ ; - - if ($Param->{ViewDate} ) { - if (m/^(\d{6})\s+\d{1,2}:\d\d:\d\d\s.*$/) { # get date - #print "# $1 #\n"; - if ($1 == $Param->{ViewDate}) { - $Param->{View} = 1; - } - else { - $Param->{View} = 0; - } - } - } - if ($Param->{View} ) { - #print "->>>$_"; - - if (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Connect.+\s+on\s+(.*)$/i) { # get connection ID($2) and database($3) - #print "C-$1--$2--$3------\n"; - RunQuery($Param); - if (defined $3) { - $Param->{CID}->{$2} = $3 ; - #print "DB:$Param->{CID}->{$2} .. $2 .. $3 \n"; - } - } - - elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Connect.+$/i) { # get connection ID($2) and database($3) - #print "\n <<<<<<<<<<<<<<<<<<----------------------------<<<<<<<<<<<<<<<< \n"; - #print "Connect \n"; - RunQuery($Param); - } - elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Change user .*\s+on\s+(.*)$/i) { # get connection ID($2) and database($3) - #print "C-$1--$2--$3------\n"; - RunQuery($Param); - if (defined $3) { - $Param->{CID}->{$2} = $3 ; - #print "DB:$Param->{CID}->{$2} .. $2 .. $3 \n"; - } - } - - elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Quit\s+$/i) { # remove connection ID($2) and querystring - #print "Q-$1--$2--------\n"; - RunQuery($Param); - delete $Param->{CID}->{$2} ; - } - - elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Query\s+(select.+)$/i) { # get connection ID($2) and querystring - #print "S1-$1--$2--$3------\n"; - RunQuery($Param); - unless ($Param->{CID}->{$2}) { - #print "Error: No Database for Handle: $2 found\n"; - } - else { - $Param->{DB}=$Param->{CID}->{$2}; - - my $s = "$3"; - $s =~ s/from\s/from $Param->{DB}./i; - $Param->{Query}="EXPLAIN $s"; - - #$s =~ m/from\s+(\w+[.]\w+)/i; - #$Param->{tab} =$1; - #print "-- $Param->{tab} -- $s --\n"; - } - } - - elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Query\s+(update.+)$/i) { # get connection ID($2) and querystring - #print "S2--$1--$2--$3------\n"; - RunQuery($Param); - unless ($Param->{CID}->{$2}) { - #print "Error: No Database for Handle: $2 found\n"; - } - else { - $Param->{DB}=$Param->{CID}->{$2}; - - my $ud = $3; - $ud =~ m/^update\s+(\w+).+(where.+)$/i; - $Param->{Query} ="EXPLAIN SELECT * FROM $1 $2"; - $Param->{Query} =~ s/from\s/from $Param->{DB}./i; - - #$Param->{Query} =~ m/from\s+(\w+[.]\w+)/i; - #$Param->{tab} =$1; - } - } - - elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Statistics\s+(.*)$/i) { # get connection ID($2) and info? - $Param->{Statistics} ++; - #print "Statistics--$1--$2--$3------\n"; - RunQuery($Param); - } - elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Query\s+(.+)$/i) { # get connection ID($2) - $Param->{QueryCount} ++; - #print "Query-NULL $3\n"; - RunQuery($Param); - } - elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Refresh\s+(.+)$/i) { # get connection ID($2) - $Param->{Refresh} ++; - #print "Refresh\n"; - RunQuery($Param); - } - elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Init\s+(.+)$/i) { # get connection ID($2) - $Param->{Init} ++; - #print "Init $3\n"; - RunQuery($Param); - } - elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Field\s+(.+)$/i) { # get connection ID($2) - $Param->{Field} ++; - #print "Field $3\n"; - RunQuery($Param); - } - - elsif (m/^\s+(.+)$/ ) { # command could be some lines ... - #print "multi-lined ($1)\n"; - my ($A)=$1; - chomp $A; - $Param->{Query} .= " $1"; - #print "multi-lined ($1)<<$Param->{Query}>>\n"; - } - - - } - - } - - $Param->{dbh}->disconnect(); - - if (1 == 0) { - print "\nunclosed handles----------------------------------------\n"; - my $count=0; - foreach (sort keys %{$Param->{CID}}) { - print "$count | $_ : $Param->{CID}->{$_} \n"; - $count ++; - } - } - - print "\nIndex usage ------------------------------------\n"; - foreach my $t (sort keys %{$Param->{Data}}) { - print "\nTable\t$t: ---\n"; - foreach my $k (sort keys %{$Param->{Data}->{$t}}) { - print " count\t$k:\n"; - my %h = %{$Param->{Data}->{$t}->{$k}}; - foreach (sort {$h{$a} <=> $h{$b}} keys %h) { - print " $Param->{Data}->{$t}->{$k}->{$_}\t$_\n"; - } - } - } - - $Param->{AllCount}=0; - print "\nQueries causing table scans -------------------\n\n"; - foreach (@{$Param->{ALL}}) { - $Param->{AllCount} ++; - print "$_\n"; - } - print "Sum: $Param->{AllCount} table scans\n"; - - print "\nSummary ---------------------------------------\n\n"; - print "Select: \t$Param->{SelectCount} queries\n"; - print "Update: \t$Param->{UpdateCount} queries\n"; - print "\n"; - - print "Init: \t$Param->{Init} times\n"; - print "Field: \t$Param->{Field} times\n"; - print "Refresh: \t$Param->{Refresh} times\n"; - print "Query: \t$Param->{QueryCount} times\n"; - print "Statistics:\t$Param->{Statistics} times\n"; - print "\n"; - - print "Logfile: \t$Param->{LineCount} lines\n"; - print "Started: \t".localtime($Param->{Start})."\n"; - print "Finished: \t".localtime(time)."\n"; - - } -} - - -########################################################################### -# -# -# -sub RunQuery { - my $Param = shift ; - - if (defined $Param->{Query}) { - if (defined $Param->{DB} ) { - - $Param->{Query} =~ m/from\s+(\w+[.]\w+|\w+)/i; - $Param->{tab} =$1; - #print "||$Param->{tab} -- $Param->{Query}\n"; - - my $sth=$Param->{dbh}->prepare("USE $Param->{DB}"); - if (DBI::err()) { - if ($Param->{PrintError}) {print "Error: ".DBI::errstr()."\n";} - } - else { - $sth->execute(); - if (DBI::err()) { - if ($Param->{PrintError}) {print "Error: ".DBI::errstr()."\n";} - } - else { - $sth->finish(); - - $sth=$Param->{dbh}->prepare($Param->{Query}); - if (DBI::err()) { - if ($Param->{PrintError}) {print "Error: ".DBI::errstr()."\n";} - } - else { - #print "$Param->{Query}\n"; - $sth->execute(); - if (DBI::err()) { - if ($Param->{PrintError}) {print "[$Param->{LineCount}]<<$Param->{Query}>>\n";} - if ($Param->{PrintError}) {print "Error: ".DBI::errstr()."\n";} - } - else { - my $row = undef; - while ($row = $sth->fetchrow_hashref()) { - $Param->{SelectCount} ++; - - if (defined $row->{Comment}) { - push (@{$Param->{Comment}}, "$row->{Comment}; $_; $Param->{DB}; $Param->{Query}"); - } - foreach (@{$Param->{Rows}}) { - if (defined $row->{$_}) { - #if (($_ eq 'type' ) and ($row->{$_} eq 'ALL')) { - if ($row->{type} eq 'ALL') { - push (@{$Param->{ALL}}, "$Param->{Query}"); - #print ">> $row->{$_} $_ $Param->{DB} $Param->{Query}\n"; - } - $Param->{IdxUseCount} ++; - $Param->{Data}->{$Param->{tab}}->{$_}->{$row->{$_}} ++; - } - } - } - } - } - } - } - $sth->finish(); - } - $Param->{Query} = undef ; - } -} - -########################################################################### -# -# -# -sub ShowOptions { - print <<EOF; -Usage: $0 [OPTIONS] < LOGFILE - ---date=YYMMDD select only entrys of date --d=YYMMDD ---host=HOSTNAME db-host to ask --h=HOSTNAME ---user=USERNAME db-user --u=USERNAME ---password=PASSWORD password of db-user --p=PASSWORD ---socket=SOCKET mysqld socket file to connect --s=SOCKET - -Read logfile from STDIN an try to EXPLAIN all SELECT statements. All UPDATE statements are rewritten to an EXPLAIN SELECT statement. The results of the EXPLAIN statement are collected and counted. All results with type=ALL are collected in an separete list. Results are printed to STDOUT. - -EOF -} - -1; - -__END__ - -=pod - -=head1 NAME - -explain_log.pl - -Feed a mysqld general logfile (created with mysqld --log) back into mysql -and collect statistics about index usage with EXPLAIN. - -=head1 DISCUSSION - -To optimize your indices, you have to know which ones are actually -used and what kind of queries are causing table scans. Especially -if you are generating your queries dynamically and you have a huge -amount of queries going on, this isn't easy. - -Use this tool to take a look at the effects of your real life queries. -Then add indices to avoid table scans and remove those which aren't used. - -=head1 USAGE - -explain_log.pl [--date=YYMMDD] --host=dbhost] [--user=dbuser] [--password=dbpw] [--socket=/path/to/socket] < logfile - ---date=YYMMDD select only entrys of date - --d=YYMMDD - ---host=HOSTNAME db-host to ask - --h=HOSTNAME - ---user=USERNAME db-user - --u=USERNAME - ---password=PASSWORD password of db-user - --p=PASSWORD - ---socket=SOCKET change path to the socket - --s=SOCKET - -=head1 EXAMPLE - -explain_log.pl --host=localhost --user=foo --password=bar < /var/lib/mysql/mobile.log - -=head1 AUTHORS - - Stefan Nitz - Jan Willamowius <jan@mobile.de>, http://www.mobile.de - Dennis Haney <davh@davh.dk> (Added socket support) - -=head1 RECRUITING - -If you are looking for a MySQL or Perl job, take a look at http://www.mobile.de -and send me an email with your resume (you must be speaking German!). - -=head1 SEE ALSO - -mysql documentation - -=cut diff --git a/scripts/mysql_fix_privilege_tables.sql b/scripts/mysql_fix_privilege_tables.sql index 5b3cab16db2..f3c0c7f13be 100644 --- a/scripts/mysql_fix_privilege_tables.sql +++ b/scripts/mysql_fix_privilege_tables.sql @@ -570,7 +570,7 @@ DROP PROCEDURE create_log_tables; CREATE TABLE event ( db char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', - name char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', + name char(64) CHARACTER SET utf8 NOT NULL default '', body longblob NOT NULL, definer char(77) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', execute_at DATETIME default NULL, @@ -636,7 +636,7 @@ SELECT @hadEventPriv :=1 FROM user WHERE Event_priv LIKE '%'; ALTER TABLE user add Event_priv enum('N','Y') character set utf8 DEFAULT 'N' NOT NULL AFTER Create_user_priv; ALTER TABLE db add Event_priv enum('N','Y') character set utf8 DEFAULT 'N' NOT NULL; ALTER TABLE event DROP PRIMARY KEY; -ALTER TABLE event ADD PRIMARY KEY(definer, db, name); +ALTER TABLE event ADD PRIMARY KEY(db, name); ALTER TABLE event ADD sql_mode set('REAL_AS_FLOAT', 'PIPES_AS_CONCAT', diff --git a/scripts/mysqld_safe.sh b/scripts/mysqld_safe.sh index 83bc8ce8954..744a4791307 100644 --- a/scripts/mysqld_safe.sh +++ b/scripts/mysqld_safe.sh @@ -31,7 +31,6 @@ Usage: $0 [OPTIONS] --defaults-file=FILE Use the specified defaults file --defaults-extra-file=FILE Also use defaults from the specified file --ledir=DIRECTORY Look for mysqld in the specified directory - --log-error=FILE Log errors to the specified log file --open-files-limit=LIMIT Limit the number of open files --core-file-size=LIMIT Limit core files to the specified size --timezone=TZ Set the system timezone @@ -46,6 +45,11 @@ EOF exit 1 } +shell_quote_string() { + # This sed command makes sure that any special chars are quoted, + # so the arg gets passed exactly to the server. + echo "$1" | sed -e 's,\([^a-zA-Z0-9/_.=-]\),\\\1,g' +} parse_arguments() { # We only need to pass arguments through to the server if we don't @@ -69,14 +73,14 @@ parse_arguments() { --pid-file=*) pid_file=`echo "$arg" | sed -e "s;--pid-file=;;"` ;; --user=*) user=`echo "$arg" | sed -e "s;--[^=]*=;;"` ; SET_USER=1 ;; - # these two might have been set in a [mysqld_safe] section of my.cnf + # these might have been set in a [mysqld_safe] section of my.cnf # they are added to mysqld command line to override settings from my.cnf + --log-error=*) err_log=`echo "$arg" | sed -e "s;--log-error=;;"` ;; --socket=*) mysql_unix_port=`echo "$arg" | sed -e "s;--socket=;;"` ;; --port=*) mysql_tcp_port=`echo "$arg" | sed -e "s;--port=;;"` ;; # mysqld_safe-specific options - must be set in my.cnf ([mysqld_safe])! --ledir=*) ledir=`echo "$arg" | sed -e "s;--ledir=;;"` ;; - --log-error=*) err_log=`echo "$arg" | sed -e "s;--log-error=;;"` ;; --open-files-limit=*) open_files=`echo "$arg" | sed -e "s;--open-files-limit=;;"` ;; --core-file-size=*) core_file_size=`echo "$arg" | sed -e "s;--core-file-size=;;"` ;; --timezone=*) TZ=`echo "$arg" | sed -e "s;--timezone=;;"` ; export TZ; ;; @@ -97,9 +101,7 @@ parse_arguments() { *) if test -n "$pick_args" then - # This sed command makes sure that any special chars are quoted, - # so the arg gets passed exactly to the server. - args="$args "`echo "$arg" | sed -e 's,\([^a-zA-Z0-9_.-]\),\\\\\1,g'` + append_arg_to_args "$arg" fi ;; esac @@ -194,6 +196,10 @@ else print_defaults="my_print_defaults" fi +append_arg_to_args () { + args="$args "`shell_quote_string "$1"` +} + args= SET_USER=2 parse_arguments `$print_defaults $defaults --loose-verbose mysqld server` @@ -239,15 +245,39 @@ else * ) pid_file="$DATADIR/$pid_file" ;; esac fi -test -z "$err_log" && err_log=$DATADIR/`@HOSTNAME@`.err +append_arg_to_args "--pid-file=$pid_file" + +if [ -n "$err_log" ] +then + # mysqld adds ".err" if there is no extension on the --log-err + # argument; must match that here, or mysqld_safe will write to a + # different log file than mysqld + + # mysqld does not add ".err" to "--log-error=foo."; it considers a + # trailing "." as an extension + if expr "$err_log" : '.*\.[^/]*$' > /dev/null + then + : + else + err_log="$err_log".err + fi + + case "$err_log" in + /* ) ;; + * ) err_log="$DATADIR/$err_log" ;; + esac +else + err_log=$DATADIR/`@HOSTNAME@`.err +fi +append_arg_to_args "--log-error=$err_log" if test -n "$mysql_unix_port" then - args="--socket=$mysql_unix_port $args" + append_arg_to_args "--socket=$mysql_unix_port" fi if test -n "$mysql_tcp_port" then - args="--port=$mysql_tcp_port $args" + append_arg_to_args "--port=$mysql_tcp_port" fi if test $niceness -eq 0 @@ -314,7 +344,7 @@ then if test -n "$open_files" then ulimit -n $open_files - args="--open-files-limit=$open_files $args" + append_arg_to_args "--open-files-limit=$open_files" fi if test -n "$core_file_size" then @@ -372,12 +402,18 @@ echo "`date +'%y%m%d %H:%M:%S mysqld started'`" >> $err_log while true do rm -f $safe_mysql_unix_port $pid_file # Some extra safety - if test -z "$args" - then - $NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file @MYSQLD_DEFAULT_SWITCHES@ >> $err_log 2>&1 - else - eval "$NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file @MYSQLD_DEFAULT_SWITCHES@ $args >> $err_log 2>&1" - fi + + cmd="$NOHUP_NICENESS" + + for i in "$ledir/$MYSQLD" "$defaults" "--basedir=$MY_BASEDIR_VERSION" \ + "--datadir=$DATADIR" "$USER_OPTION" + do + cmd="$cmd "`shell_quote_string "$i"` + done + cmd="$cmd $args >> "`shell_quote_string "$err_log"`" 2>&1" + #echo "Running mysqld: [$cmd]" + eval "$cmd" + if test ! -f $pid_file # This is removed if normal shutdown then echo "STOPPING server from pid file $pid_file" diff --git a/server-tools/instance-manager/cmakelists.txt b/server-tools/instance-manager/CMakeLists.txt index c20b9c7f9df..1983d459ce2 100644 --- a/server-tools/instance-manager/cmakelists.txt +++ b/server-tools/instance-manager/CMakeLists.txt @@ -9,6 +9,7 @@ ADD_EXECUTABLE(mysqlmanager buffer.cc command.cc commands.cc guardian.cc instanc instance_options.cc listener.cc log.cc manager.cc messages.cc mysql_connection.cc mysqlmanager.cc options.cc parse.cc parse_output.cc priv.cc protocol.cc thread_registry.cc user_map.cc imservice.cpp windowsservice.cpp + user_management_commands.cc ../../sql/net_serv.cc ../../sql-common/pack.c ../../sql/password.c ../../sql/sql_state.c ../../sql-common/client.c ../../libmysql/get_password.c ../../libmysql/errmsg.c) diff --git a/server-tools/instance-manager/IMService.cpp b/server-tools/instance-manager/IMService.cpp index b7ea8e7eb81..f9ea7ee471d 100644 --- a/server-tools/instance-manager/IMService.cpp +++ b/server-tools/instance-manager/IMService.cpp @@ -20,7 +20,7 @@ IMService::~IMService(void) void IMService::Stop() { ReportStatus(SERVICE_STOP_PENDING); - + // stop the IM work raise(SIGTERM); } @@ -30,15 +30,14 @@ void IMService::Run(DWORD argc, LPTSTR *argv) // report to the SCM that we're about to start ReportStatus((DWORD)SERVICE_START_PENDING); - Options o; - o.load(argc, argv); - + Options::load(argc, argv); + // init goes here ReportStatus((DWORD)SERVICE_RUNNING); // wait for main loop to terminate - manager(o); - o.cleanup(); + manager(); + Options::cleanup(); } void IMService::Log(const char *msg) @@ -46,13 +45,13 @@ void IMService::Log(const char *msg) log_info(msg); } -int HandleServiceOptions(Options options) +int HandleServiceOptions() { int ret_val= 0; IMService winService; - if (options.install_as_service) + if (Options::Service::install_as_service) { if (winService.IsInstalled()) log_info("Service is already installed"); @@ -64,7 +63,7 @@ int HandleServiceOptions(Options options) ret_val= 1; } } - else if (options.remove_service) + else if (Options::Service::remove_service) { if (! winService.IsInstalled()) log_info("Service is not installed"); @@ -77,6 +76,19 @@ int HandleServiceOptions(Options options) } } else - ret_val= !winService.Init(); + { + log_info("Initializing Instance Manager service..."); + + if (!winService.Init()) + { + log_info("Service failed to initialize."); + fprintf(stderr, + "The service should be started by Windows Service Manager.\n" + "The MySQL Manager should be started with '--standalone'\n" + "to run from command line."); + ret_val= 1; + } + } + return ret_val; } diff --git a/server-tools/instance-manager/IMService.h b/server-tools/instance-manager/IMService.h index cad38bebdaf..94d59c2af31 100644 --- a/server-tools/instance-manager/IMService.h +++ b/server-tools/instance-manager/IMService.h @@ -1,3 +1,21 @@ +/* + Copyright (C) 2006 MySQL 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 +*/ + #pragma once #include "windowsservice.h" @@ -12,3 +30,5 @@ protected: void Stop(); void Run(DWORD argc, LPTSTR *argv); }; + +extern int HandleServiceOptions(); diff --git a/server-tools/instance-manager/Makefile.am b/server-tools/instance-manager/Makefile.am index 462d7984aa4..4139bf2eb10 100644 --- a/server-tools/instance-manager/Makefile.am +++ b/server-tools/instance-manager/Makefile.am @@ -76,7 +76,10 @@ mysqlmanager_SOURCES= command.cc command.h mysqlmanager.cc \ guardian.cc guardian.h \ parse_output.cc parse_output.h \ mysql_manager_error.h \ - portability.h + portability.h \ + exit_codes.h \ + user_management_commands.h \ + user_management_commands.cc mysqlmanager_LDADD= @CLIENT_EXTRA_LDFLAGS@ \ liboptions.la \ @@ -88,7 +91,7 @@ mysqlmanager_LDADD= @CLIENT_EXTRA_LDFLAGS@ \ @openssl_libs@ @yassl_libs@ @ZLIB_LIBS@ EXTRA_DIST = WindowsService.cpp WindowsService.h IMService.cpp \ - IMService.h cmakelists.txt + IMService.h CMakeLists.txt tags: ctags -R *.h *.cc diff --git a/server-tools/instance-manager/WindowsService.cpp b/server-tools/instance-manager/WindowsService.cpp index 192045b7a4c..8a36a2f2fdd 100644 --- a/server-tools/instance-manager/WindowsService.cpp +++ b/server-tools/instance-manager/WindowsService.cpp @@ -7,9 +7,9 @@ static WindowsService *gService; WindowsService::WindowsService(void) : statusCheckpoint(0), serviceName(NULL), - inited(false), + inited(FALSE), dwAcceptedControls(SERVICE_ACCEPT_STOP), - debugging(false) + debugging(FALSE) { gService= this; status.dwServiceType= SERVICE_WIN32_OWN_PROCESS; @@ -22,11 +22,12 @@ WindowsService::~WindowsService(void) BOOL WindowsService::Install() { - bool ret_val= false; + bool ret_val= FALSE; SC_HANDLE newService; SC_HANDLE scm; - if (IsInstalled()) return true; + if (IsInstalled()) + return TRUE; // determine the name of the currently executing file char szFilePath[_MAX_PATH]; @@ -34,7 +35,7 @@ BOOL WindowsService::Install() // open a connection to the SCM if (!(scm= OpenSCManager(0, 0,SC_MANAGER_CREATE_SERVICE))) - return false; + return FALSE; newService= CreateService(scm, serviceName, displayName, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, @@ -45,7 +46,7 @@ BOOL WindowsService::Install() if (newService) { CloseServiceHandle(newService); - ret_val= true; + ret_val= TRUE; } CloseServiceHandle(scm); @@ -56,34 +57,35 @@ BOOL WindowsService::Init() { assert(serviceName != NULL); - if (inited) return true; + if (inited) + return TRUE; SERVICE_TABLE_ENTRY stb[] = { { (LPSTR)serviceName, (LPSERVICE_MAIN_FUNCTION) ServiceMain}, { NULL, NULL } }; - inited= true; + inited= TRUE; return StartServiceCtrlDispatcher(stb); //register with the Service Manager } BOOL WindowsService::Remove() { - bool ret_val= false; + bool ret_val= FALSE; - if (! IsInstalled()) - return true; + if (!IsInstalled()) + return TRUE; // open a connection to the SCM SC_HANDLE scm= OpenSCManager(0, 0,SC_MANAGER_CREATE_SERVICE); - if (! scm) - return false; + if (!scm) + return FALSE; SC_HANDLE service= OpenService(scm, serviceName, DELETE); if (service) { if (DeleteService(service)) - ret_val= true; + ret_val= TRUE; DWORD dw= ::GetLastError(); CloseServiceHandle(service); } @@ -116,7 +118,8 @@ void WindowsService::SetAcceptedControls(DWORD acceptedControls) BOOL WindowsService::ReportStatus(DWORD currentState, DWORD waitHint, DWORD dwError) { - if(debugging) return TRUE; + if (debugging) + return TRUE; if(currentState == SERVICE_START_PENDING) status.dwControlsAccepted= 0; diff --git a/server-tools/instance-manager/WindowsService.h b/server-tools/instance-manager/WindowsService.h index 1a034ce1351..3af7cdf39a7 100644 --- a/server-tools/instance-manager/WindowsService.h +++ b/server-tools/instance-manager/WindowsService.h @@ -1,3 +1,21 @@ +/* + Copyright (C) 2006 MySQL 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 +*/ + #pragma once class WindowsService diff --git a/server-tools/instance-manager/command.h b/server-tools/instance-manager/command.h index b84cc6a8e9e..f31ea404867 100644 --- a/server-tools/instance-manager/command.h +++ b/server-tools/instance-manager/command.h @@ -22,10 +22,12 @@ #pragma interface #endif -/* Class responsible for allocation of im commands. */ +/* Class responsible for allocation of IM commands. */ class Instance_map; +struct st_net; + /* Command - entry point for any command. GangOf4: 'Command' design pattern @@ -37,8 +39,18 @@ public: Command(Instance_map *instance_map_arg= 0); virtual ~Command(); - /* method of executing: */ - virtual int execute(struct st_net *net, ulong connection_id) = 0; + /* + This operation incapsulates behaviour of the command. + + SYNOPSYS + net The network connection to the client. + connection_id Client connection ID + + RETURN + 0 On success + non 0 On error. Client error code is returned. + */ + virtual int execute(st_net *net, ulong connection_id) = 0; protected: Instance_map *instance_map; diff --git a/server-tools/instance-manager/commands.cc b/server-tools/instance-manager/commands.cc index 7b999f61503..07e1e9a18f3 100644 --- a/server-tools/instance-manager/commands.cc +++ b/server-tools/instance-manager/commands.cc @@ -14,36 +14,53 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#if defined(__GNUC__) && defined(USE_PRAGMA_IMPLEMENTATION) +#pragma implementation +#endif + #include "commands.h" +#include <my_global.h> +#include <m_ctype.h> +#include <mysql.h> +#include <my_dir.h> + +#include "buffer.h" +#include "guardian.h" #include "instance_map.h" +#include "log.h" +#include "manager.h" #include "messages.h" #include "mysqld_error.h" #include "mysql_manager_error.h" -#include "protocol.h" -#include "buffer.h" #include "options.h" +#include "priv.h" +#include "protocol.h" -#include <m_string.h> -#include <m_ctype.h> -#include <mysql.h> -#include <my_dir.h> + +/* + modify_defaults_to_im_error -- a map of error codes of + mysys::modify_defaults_file() into Instance Manager error codes. +*/ + +static const int modify_defaults_to_im_error[]= { 0, ER_OUT_OF_RESOURCES, + ER_ACCESS_OPTION_FILE }; /* - Add a string to a buffer + Add a string to a buffer. SYNOPSYS put_to_buff() buff buffer to add the string str string to add - uint offset in the buff to add a string + position offset in the buff to add a string DESCRIPTION Function to add a string to the buffer. It is different from - store_to_protocol_packet, which is used in the protocol.cc. The last - one also stores the length of the string in a special way. + store_to_protocol_packet, which is used in the protocol.cc. + The last one also stores the length of the string in a special way. This is required for MySQL client/server protocol support only. RETURN @@ -51,7 +68,6 @@ 1 - error occured */ - static inline int put_to_buff(Buffer *buff, const char *str, uint *position) { uint len= strlen(str); @@ -88,749 +104,1615 @@ static int parse_version_number(const char *version_str, char *version, } -/* implementation for Show_instances: */ +/************************************************************************** + Implementation of Instance_name. +**************************************************************************/ +Instance_name::Instance_name(const LEX_STRING *name) +{ + str.str= str_buffer; + str.length= name->length; -/* - The method sends a list of instances in the instance map to the client. + if (str.length > MAX_INSTANCE_NAME_SIZE - 1) + str.length= MAX_INSTANCE_NAME_SIZE - 1; - SYNOPSYS - Show_instances::execute() - net The network connection to the client. - connection_id Client connection ID + strmake(str.str, name->str, str.length); +} - RETURN - 0 - ok - 1 - error occured +/************************************************************************** + Implementation of Show_instances. +**************************************************************************/ + +/* + Implementation of SHOW INSTANCES statement. + + Possible error codes: + ER_OUT_OF_RESOURCES Not enough resources to complete the operation */ -int Show_instances::execute(struct st_net *net, ulong connection_id) +int Show_instances::execute(st_net *net, ulong connection_id) { - Buffer send_buff; /* buffer for packets */ - LIST name, status; - NAME_WITH_LENGTH name_field, status_field; + int err_code; + + if ((err_code= write_header(net)) || + (err_code= write_data(net))) + return err_code; + + if (send_eof(net) || net_flush(net)) + return ER_OUT_OF_RESOURCES; + + return 0; +} + + +int Show_instances::write_header(st_net *net) +{ + LIST name, state; + LEX_STRING name_field, state_field; LIST *field_list; - uint position=0; - name_field.name= (char*) "instance_name"; + name_field.str= (char *) "instance_name"; name_field.length= DEFAULT_FIELD_LENGTH; name.data= &name_field; - status_field.name= (char*) "status"; - status_field.length= DEFAULT_FIELD_LENGTH; - status.data= &status_field; - field_list= list_add(NULL, &status); + + state_field.str= (char *) "state"; + state_field.length= DEFAULT_FIELD_LENGTH; + state.data= &state_field; + + field_list= list_add(NULL, &state); field_list= list_add(field_list, &name); - send_fields(net, field_list); + return send_fields(net, field_list) ? ER_OUT_OF_RESOURCES : 0; +} + +int Show_instances::write_data(st_net *net) +{ + my_bool err_status= FALSE; + + Instance *instance; + Instance_map::Iterator iterator(instance_map); + + instance_map->guardian->lock(); + instance_map->lock(); + + while ((instance= iterator.next())) { - Instance *instance; - Instance_map::Iterator iterator(instance_map); + Buffer send_buf; /* buffer for packets */ + uint pos= 0; + + const char *instance_name= instance->options.instance_name.str; + const char *state_name= instance_map->get_instance_state_name(instance); - instance_map->lock(); - while ((instance= iterator.next())) + if (store_to_protocol_packet(&send_buf, instance_name, &pos) || + store_to_protocol_packet(&send_buf, state_name, &pos) || + my_net_write(net, send_buf.buffer, pos)) { - position= 0; - store_to_protocol_packet(&send_buff, instance->options.instance_name, - &position); - if (instance->is_running()) - store_to_protocol_packet(&send_buff, (char*) "online", &position); - else - store_to_protocol_packet(&send_buff, (char*) "offline", &position); - if (my_net_write(net, send_buff.buffer, (uint) position)) - goto err; + err_status= TRUE; + break; } - instance_map->unlock(); } - if (send_eof(net)) - goto err; - if (net_flush(net)) - goto err; - return 0; -err: - return ER_OUT_OF_RESOURCES; + instance_map->unlock(); + instance_map->guardian->unlock(); + + return err_status ? ER_OUT_OF_RESOURCES : 0; } -/* implementation for Flush_instances: */ +/************************************************************************** + Implementation of Flush_instances. +**************************************************************************/ -int Flush_instances::execute(struct st_net *net, ulong connection_id) +/* + Implementation of FLUSH INSTANCES statement. + + Possible error codes: + ER_OUT_OF_RESOURCES Not enough resources to complete the operation + ER_THERE_IS_ACTIVE_INSTACE If there is an active instance +*/ + +int Flush_instances::execute(st_net *net, ulong connection_id) { - if (instance_map->flush_instances() || - net_send_ok(net, connection_id, NULL)) + instance_map->guardian->lock(); + instance_map->lock(); + + if (instance_map->is_there_active_instance()) + { + instance_map->unlock(); + instance_map->guardian->unlock(); + return ER_THERE_IS_ACTIVE_INSTACE; + } + + if (instance_map->flush_instances()) + { + instance_map->unlock(); + instance_map->guardian->unlock(); return ER_OUT_OF_RESOURCES; + } - return 0; + instance_map->unlock(); + instance_map->guardian->unlock(); + + return net_send_ok(net, connection_id, NULL) ? ER_OUT_OF_RESOURCES : 0; } -/* implementation for Show_instance_status: */ +/************************************************************************** + Implementation of Abstract_instance_cmd. +**************************************************************************/ -Show_instance_status::Show_instance_status(Instance_map *instance_map_arg, - const char *name, uint len) - :Command(instance_map_arg) +Abstract_instance_cmd::Abstract_instance_cmd( + Instance_map *instance_map_arg, const LEX_STRING *instance_name_arg) + :Command(instance_map_arg), + instance_name(instance_name_arg) { - Instance *instance; + /* + MT-NOTE: we can not make a search for Instance object here, + because it can dissappear after releasing the lock. + */ +} + + +int Abstract_instance_cmd::execute(st_net *net, ulong connection_id) +{ + int err_code; + + instance_map->lock(); + + { + Instance *instance= instance_map->find(get_instance_name()); + + if (!instance) + { + instance_map->unlock(); + return ER_BAD_INSTANCE_NAME; + } + + err_code= execute_impl(net, instance); + } + + instance_map->unlock(); + + if (!err_code) + err_code= send_ok_response(net, connection_id); - /* we make a search here, since we don't want to store the name */ - if ((instance= instance_map->find(name, len))) - instance_name= instance->options.instance_name; - else - instance_name= NULL; + return err_code; } -/* - The method sends a table with a status of requested instance to the client. +/************************************************************************** + Implementation of Show_instance_status. +**************************************************************************/ - SYNOPSYS - Show_instance_status::do_command() - net The network connection to the client. - instance_name The name of the instance. +Show_instance_status::Show_instance_status(Instance_map *instance_map_arg, + const LEX_STRING *instance_name_arg) + :Abstract_instance_cmd(instance_map_arg, instance_name_arg) +{ +} - RETURN - 0 - ok - 1 - error occured + +/* + Implementation of SHOW INSTANCE STATUS statement. + + Possible error codes: + ER_BAD_INSTANCE_NAME The instance with the given name does not exist + ER_OUT_OF_RESOURCES Not enough resources to complete the operation */ +int Show_instance_status::execute_impl(st_net *net, Instance *instance) +{ + int err_code; + + if ((err_code= write_header(net)) || + (err_code= write_data(net, instance))) + return err_code; -int Show_instance_status::execute(struct st_net *net, - ulong connection_id) + return 0; +} + + +int Show_instance_status::send_ok_response(st_net *net, ulong connection_id) { - enum { MAX_VERSION_LENGTH= 40 }; - Buffer send_buff; /* buffer for packets */ - LIST name, status, version, version_number; + if (send_eof(net) || net_flush(net)) + return ER_OUT_OF_RESOURCES; + + return 0; +} + + +int Show_instance_status::write_header(st_net *net) +{ + LIST name, state, version, version_number, mysqld_compatible; LIST *field_list; - NAME_WITH_LENGTH name_field, status_field, version_field, - version_number_field; - uint position=0; + LEX_STRING name_field, state_field, version_field, + version_number_field, mysqld_compatible_field; - if (!instance_name) - return ER_BAD_INSTANCE_NAME; + /* Create list of the fileds to be passed to send_fields(). */ - /* create list of the fileds to be passed to send_fields */ - name_field.name= (char*) "instance_name"; + name_field.str= (char *) "instance_name"; name_field.length= DEFAULT_FIELD_LENGTH; name.data= &name_field; - status_field.name= (char*) "status"; - status_field.length= DEFAULT_FIELD_LENGTH; - status.data= &status_field; - version_field.name= (char*) "version"; + + state_field.str= (char *) "state"; + state_field.length= DEFAULT_FIELD_LENGTH; + state.data= &state_field; + + version_field.str= (char *) "version"; version_field.length= MAX_VERSION_LENGTH; version.data= &version_field; - version_number_field.name= (char*) "version_number"; + + version_number_field.str= (char *) "version_number"; version_number_field.length= MAX_VERSION_LENGTH; version_number.data= &version_number_field; - field_list= list_add(NULL, &version); + + mysqld_compatible_field.str= (char *) "mysqld_compatible"; + mysqld_compatible_field.length= DEFAULT_FIELD_LENGTH; + mysqld_compatible.data= &mysqld_compatible_field; + + field_list= list_add(NULL, &mysqld_compatible); + field_list= list_add(field_list, &version); field_list= list_add(field_list, &version_number); - field_list= list_add(field_list, &status); + field_list= list_add(field_list, &state); field_list= list_add(field_list, &name); - send_fields(net, field_list); + return send_fields(net, field_list) ? ER_OUT_OF_RESOURCES : 0; +} - { - Instance *instance; - store_to_protocol_packet(&send_buff, (char*) instance_name, &position); - if (!(instance= instance_map->find(instance_name, strlen(instance_name)))) - goto err; - if (instance->is_running()) - store_to_protocol_packet(&send_buff, (char*) "online", &position); - else - store_to_protocol_packet(&send_buff, (char*) "offline", &position); +int Show_instance_status::write_data(st_net *net, Instance *instance) +{ + Buffer send_buf; /* buffer for packets */ + char version_num_buf[MAX_VERSION_LENGTH]; + uint pos= 0; - if (instance->options.mysqld_version) - { - char parsed_version[MAX_VERSION_LENGTH]; + const char *state_name; + const char *version_tag= "unknown"; + const char *version_num= "unknown"; + const char *mysqld_compatible_status; - parse_version_number(instance->options.mysqld_version, parsed_version, - sizeof(parsed_version)); - store_to_protocol_packet(&send_buff, parsed_version, &position); + instance_map->guardian->lock(); + state_name= instance_map->get_instance_state_name(instance); + mysqld_compatible_status= instance->is_mysqld_compatible() ? "yes" : "no"; + instance_map->guardian->unlock(); - store_to_protocol_packet(&send_buff, instance->options.mysqld_version, - &position); - } - else - { - store_to_protocol_packet(&send_buff, (char*) "unknown", &position); - store_to_protocol_packet(&send_buff, (char*) "unknown", &position); - } + if (instance->options.mysqld_version) + { + if (parse_version_number(instance->options.mysqld_version, version_num_buf, + sizeof(version_num_buf))) + return ER_OUT_OF_RESOURCES; - if (send_buff.is_error() || - my_net_write(net, send_buff.buffer, (uint) position)) - goto err; + version_num= version_num_buf; + version_tag= instance->options.mysqld_version; } - if (send_eof(net) || net_flush(net)) - goto err; + if (store_to_protocol_packet(&send_buf, get_instance_name()->str, &pos) || + store_to_protocol_packet(&send_buf, state_name, &pos) || + store_to_protocol_packet(&send_buf, version_num, &pos) || + store_to_protocol_packet(&send_buf, version_tag, &pos) || + store_to_protocol_packet(&send_buf, mysqld_compatible_status, &pos) || + my_net_write(net, send_buf.buffer, (uint) pos)) + { + return ER_OUT_OF_RESOURCES; + } return 0; +} -err: - return ER_OUT_OF_RESOURCES; + +/************************************************************************** + Implementation of Show_instance_options. +**************************************************************************/ + +Show_instance_options::Show_instance_options( + Instance_map *instance_map_arg, const LEX_STRING *instance_name_arg) + :Abstract_instance_cmd(instance_map_arg, instance_name_arg) +{ } -/* Implementation for Show_instance_options */ +/* + Implementation of SHOW INSTANCE OPTIONS statement. + + Possible error codes: + ER_BAD_INSTANCE_NAME The instance with the given name does not exist + ER_OUT_OF_RESOURCES Not enough resources to complete the operation +*/ -Show_instance_options::Show_instance_options(Instance_map *instance_map_arg, - const char *name, uint len): - Command(instance_map_arg) +int Show_instance_options::execute_impl(st_net *net, Instance *instance) { - Instance *instance; + int err_code; + + if ((err_code= write_header(net)) || + (err_code= write_data(net, instance))) + return err_code; - /* we make a search here, since we don't want to store the name */ - if ((instance= instance_map->find(name, len))) - instance_name= instance->options.instance_name; - else - instance_name= NULL; + return 0; } -int Show_instance_options::execute(struct st_net *net, ulong connection_id) +int Show_instance_options::send_ok_response(st_net *net, ulong connection_id) +{ + if (send_eof(net) || net_flush(net)) + return ER_OUT_OF_RESOURCES; + + return 0; +} + + +int Show_instance_options::write_header(st_net *net) { - Buffer send_buff; /* buffer for packets */ LIST name, option; LIST *field_list; - NAME_WITH_LENGTH name_field, option_field; - uint position=0; + LEX_STRING name_field, option_field; - if (!instance_name) - return ER_BAD_INSTANCE_NAME; + /* Create list of the fileds to be passed to send_fields(). */ - /* create list of the fileds to be passed to send_fields */ - name_field.name= (char*) "option_name"; + name_field.str= (char *) "option_name"; name_field.length= DEFAULT_FIELD_LENGTH; name.data= &name_field; - option_field.name= (char*) "value"; + + option_field.str= (char *) "value"; option_field.length= DEFAULT_FIELD_LENGTH; option.data= &option_field; + field_list= list_add(NULL, &option); field_list= list_add(field_list, &name); - send_fields(net, field_list); + return send_fields(net, field_list) ? ER_OUT_OF_RESOURCES : 0; +} + +int Show_instance_options::write_data(st_net *net, Instance *instance) +{ + Buffer send_buff; /* buffer for packets */ + uint pos= 0; + + if (store_to_protocol_packet(&send_buff, "instance_name", &pos) || + store_to_protocol_packet(&send_buff, get_instance_name()->str, &pos) || + my_net_write(net, send_buff.buffer, pos)) { - Instance *instance; - - if (!(instance= instance_map->find(instance_name, strlen(instance_name)))) - goto err; - store_to_protocol_packet(&send_buff, (char*) "instance_name", &position); - store_to_protocol_packet(&send_buff, (char*) instance_name, &position); - if (my_net_write(net, send_buff.buffer, (uint) position)) - goto err; - if ((instance->options.mysqld_path)) - { - position= 0; - store_to_protocol_packet(&send_buff, (char*) "mysqld-path", &position); - store_to_protocol_packet(&send_buff, - (char*) instance->options.mysqld_path, - &position); - if (send_buff.is_error() || - my_net_write(net, send_buff.buffer, (uint) position)) - goto err; - } + return ER_OUT_OF_RESOURCES; + } - if ((instance->options.nonguarded)) + /* Loop through the options. */ + + for (int i= 0; i < instance->options.get_num_options(); i++) + { + Named_value option= instance->options.get_option(i); + const char *option_value= option.get_value()[0] ? option.get_value() : ""; + + pos= 0; + + if (store_to_protocol_packet(&send_buff, option.get_name(), &pos) || + store_to_protocol_packet(&send_buff, option_value, &pos) || + my_net_write(net, send_buff.buffer, pos)) { - position= 0; - store_to_protocol_packet(&send_buff, (char*) "nonguarded", &position); - store_to_protocol_packet(&send_buff, "", &position); - if (send_buff.is_error() || - my_net_write(net, send_buff.buffer, (uint) position)) - goto err; + return ER_OUT_OF_RESOURCES; } + } + + return 0; +} + + +/************************************************************************** + Implementation of Start_instance. +**************************************************************************/ - /* loop through the options stored in DYNAMIC_ARRAY */ - for (uint i= 0; i < instance->options.options_array.elements; i++) +Start_instance::Start_instance(Instance_map *instance_map_arg, + const LEX_STRING *instance_name_arg) + :Abstract_instance_cmd(instance_map_arg, instance_name_arg) +{ +} + + +/* + Implementation of START INSTANCE statement. + + Possible error codes: + ER_BAD_INSTANCE_NAME The instance with the given name does not exist + ER_OUT_OF_RESOURCES Not enough resources to complete the operation +*/ + +int Start_instance::execute_impl(st_net *net, Instance *instance) +{ + int err_code; + + if ((err_code= instance->start())) + return err_code; + + if (!(instance->options.nonguarded)) + instance_map->guardian->guard(instance); + + return 0; +} + + +int Start_instance::send_ok_response(st_net *net, ulong connection_id) +{ + if (net_send_ok(net, connection_id, "Instance started")) + return ER_OUT_OF_RESOURCES; + + return 0; +} + + +/************************************************************************** + Implementation of Stop_instance. +**************************************************************************/ + +Stop_instance::Stop_instance(Instance_map *instance_map_arg, + const LEX_STRING *instance_name_arg) + :Abstract_instance_cmd(instance_map_arg, instance_name_arg) +{ +} + + +/* + Implementation of STOP INSTANCE statement. + + Possible error codes: + ER_BAD_INSTANCE_NAME The instance with the given name does not exist + ER_OUT_OF_RESOURCES Not enough resources to complete the operation +*/ + +int Stop_instance::execute_impl(st_net *net, Instance *instance) +{ + int err_code; + + if (!(instance->options.nonguarded)) + instance_map->guardian->stop_guard(instance); + + if ((err_code= instance->stop())) + return err_code; + + return 0; +} + + +int Stop_instance::send_ok_response(st_net *net, ulong connection_id) +{ + if (net_send_ok(net, connection_id, NULL)) + return ER_OUT_OF_RESOURCES; + + return 0; +} + + +/************************************************************************** + Implementation for Create_instance. +**************************************************************************/ + +Create_instance::Create_instance(Instance_map *instance_map_arg, + const LEX_STRING *instance_name_arg) + :Command(instance_map_arg), + instance_name(instance_name_arg) +{ +} + + +/* + This operation initializes Create_instance object. + + SYNOPSYS + text [IN/OUT] a pointer to the text containing instance options. + + RETURN + FALSE On success. + TRUE On error. +*/ + +bool Create_instance::init(const char **text) +{ + return options.init() || parse_args(text); +} + + +/* + This operation parses CREATE INSTANCE options. + + SYNOPSYS + text [IN/OUT] a pointer to the text containing instance options. + + RETURN + FALSE On success. + TRUE On syntax error. +*/ + +bool Create_instance::parse_args(const char **text) +{ + uint len; + + /* Check if we have something (and trim leading spaces). */ + + get_word(text, &len, NONSPACE); + + if (len == 0) + return FALSE; /* OK: no option. */ + + /* Main parsing loop. */ + + while (TRUE) + { + LEX_STRING option_name; + char *option_name_str; + char *option_value_str= NULL; + + /* Looking for option name. */ + + get_word(text, &option_name.length, OPTION_NAME); + + if (option_name.length == 0) + return TRUE; /* Syntax error: option name expected. */ + + option_name.str= (char *) *text; + *text+= option_name.length; + + /* Looking for equal sign. */ + + skip_spaces(text); + + if (**text == '=') { - char *tmp_option, *option_value; - get_dynamic(&(instance->options.options_array), (gptr) &tmp_option, i); - option_value= strchr(tmp_option, '='); - /* split the option string into two parts if it has a value */ + ++(*text); /* Skip an equal sign. */ + + /* Looking for option value. */ - position= 0; - if (option_value != NULL) + skip_spaces(text); + + if (!**text) + return TRUE; /* Syntax error: EOS when option value expected. */ + + if (**text != '\'' && **text != '"') { - *option_value= 0; - store_to_protocol_packet(&send_buff, tmp_option + 2, &position); - store_to_protocol_packet(&send_buff, option_value + 1, &position); - /* join name and the value into the same option again */ - *option_value= '='; + /* Option value is a simple token. */ + + LEX_STRING option_value; + + get_word(text, &option_value.length, ALPHANUM); + + if (option_value.length == 0) + return TRUE; /* internal parser error. */ + + option_value.str= (char *) *text; + *text+= option_value.length; + + if (!(option_value_str= Named_value::alloc_str(&option_value))) + return TRUE; /* out of memory during parsing. */ } else { - store_to_protocol_packet(&send_buff, tmp_option + 2, &position); - store_to_protocol_packet(&send_buff, "", &position); + /* Option value is a string. */ + + if (parse_option_value(*text, &len, &option_value_str)) + return TRUE; /* Syntax error: invalid string specification. */ + + *text+= len; } + } + + if (!option_value_str) + { + LEX_STRING empty_str= { C_STRING_WITH_SIZE("") }; + + if (!(option_value_str= Named_value::alloc_str(&empty_str))) + return TRUE; /* out of memory during parsing. */ + } + + if (!(option_name_str= Named_value::alloc_str(&option_name))) + { + Named_value::free_str(&option_value_str); + return TRUE; /* out of memory during parsing. */ + } + + { + Named_value option(option_name_str, option_value_str); - if (send_buff.is_error() || - my_net_write(net, send_buff.buffer, (uint) position)) - goto err; + if (options.add_element(&option)) + { + option.free(); + return TRUE; /* out of memory during parsing. */ + } } + + skip_spaces(text); + + if (!**text) + return FALSE; /* OK: end of options. */ + + if (**text != ',') + return TRUE; /* Syntax error: comma expected. */ + + ++(*text); } +} - if (send_eof(net) || net_flush(net)) - goto err; - return 0; +/* + Implementation of CREATE INSTANCE statement. + + Possible error codes: + ER_MALFORMED_INSTANCE_NAME Instance name is malformed + ER_CREATE_EXISTING_INSTANCE There is an instance with the given name + ER_OUT_OF_RESOURCES Not enough resources to complete the operation +*/ + +int Create_instance::execute(st_net *net, ulong connection_id) +{ + int err_code; + + /* Check that the name is valid and there is no instance with such name. */ + + if (!Instance::is_name_valid(get_instance_name())) + return ER_MALFORMED_INSTANCE_NAME; + + /* + NOTE: In order to prevent race condition, we should perform all operations + on under acquired lock. + */ + + instance_map->lock(); -err: - return ER_OUT_OF_RESOURCES; + if (instance_map->find(get_instance_name())) + { + instance_map->unlock(); + return ER_CREATE_EXISTING_INSTANCE; + } + + if ((err_code= instance_map->create_instance(get_instance_name(), &options))) + { + instance_map->unlock(); + return err_code; + } + + if ((err_code= create_instance_in_file(get_instance_name(), &options))) + { + Instance *instance= instance_map->find(get_instance_name()); + + if (instance) + instance_map->remove_instance(instance); /* instance is deleted here. */ + + instance_map->unlock(); + return err_code; + } + + /* That's all. */ + + instance_map->unlock(); + + /* Send the result. */ + + if (net_send_ok(net, connection_id, NULL)) + return ER_OUT_OF_RESOURCES; + + return 0; } -/* Implementation for Start_instance */ +/************************************************************************** + Implementation for Drop_instance. +**************************************************************************/ -Start_instance::Start_instance(Instance_map *instance_map_arg, - const char *name, uint len) - :Command(instance_map_arg) +Drop_instance::Drop_instance(Instance_map *instance_map_arg, + const LEX_STRING *instance_name_arg) + :Abstract_instance_cmd(instance_map_arg, instance_name_arg) { - /* we make a search here, since we don't want to store the name */ - if ((instance= instance_map->find(name, len))) - instance_name= instance->options.instance_name; } -int Start_instance::execute(struct st_net *net, ulong connection_id) +/* + Implementation of DROP INSTANCE statement. + + Possible error codes: + ER_BAD_INSTANCE_NAME The instance with the given name does not exist + ER_DROP_ACTIVE_INSTANCE The specified instance is active + ER_OUT_OF_RESOURCES Not enough resources to complete the operation +*/ + +int Drop_instance::execute_impl(st_net *net, Instance *instance) { - uint err_code; - if (instance == 0) - return ER_BAD_INSTANCE_NAME; /* haven't found an instance */ - else - { - if ((err_code= instance->start())) - return err_code; + int err_code; + + /* Check that the instance is offline. */ + + if (instance_map->guardian->is_active(instance)) + return ER_DROP_ACTIVE_INSTANCE; - if (!(instance->options.nonguarded)) - instance_map->guardian->guard(instance); + err_code= modify_defaults_file(Options::Main::config_file, NULL, NULL, + get_instance_name()->str, MY_REMOVE_SECTION); + DBUG_ASSERT(err_code >= 0 && err_code <= 2); - net_send_ok(net, connection_id, "Instance started"); - return 0; + if (err_code) + { + log_error("Can not remove instance '%s' from defaults file (%s). " + "Original error code: %d.", + (const char *) get_instance_name()->str, + (const char *) Options::Main::config_file, + (int) err_code); } + + if (err_code) + return modify_defaults_to_im_error[err_code]; + + /* Remove instance from the instance map hash and Guardian's list. */ + + if (!instance->options.nonguarded) + instance_map->guardian->stop_guard(instance); + + if ((err_code= instance->stop())) + return err_code; + + instance_map->remove_instance(instance); + + return 0; } -/* implementation for Show_instance_log: */ +int Drop_instance::send_ok_response(st_net *net, ulong connection_id) +{ + if (net_send_ok(net, connection_id, "Instance dropped")) + return ER_OUT_OF_RESOURCES; + + return 0; +} + + +/************************************************************************** + Implementation for Show_instance_log. +**************************************************************************/ Show_instance_log::Show_instance_log(Instance_map *instance_map_arg, - const char *name, uint len, + const LEX_STRING *instance_name_arg, Log_type log_type_arg, - const char *size_arg, - const char *offset_arg) - :Command(instance_map_arg) + uint size_arg, uint offset_arg) + :Abstract_instance_cmd(instance_map_arg, instance_name_arg), + log_type(log_type_arg), + size(size_arg), + offset(offset_arg) { - Instance *instance; +} + + +/* + Implementation of SHOW INSTANCE LOG statement. + + Possible error codes: + ER_BAD_INSTANCE_NAME The instance with the given name does not exist + ER_OFFSET_ERROR We were requested to read negative number of + bytes from the log + ER_NO_SUCH_LOG The specified type of log is not available for + the given instance + ER_GUESS_LOGFILE IM wasn't able to figure out the log + placement, while it is enabled. Probably user + should specify the path to the logfile + explicitly. + ER_OPEN_LOGFILE Cannot open the logfile + ER_READ_FILE Cannot read the logfile + ER_OUT_OF_RESOURCES Not enough resources to complete the operation +*/ + +int Show_instance_log::execute_impl(st_net *net, Instance *instance) +{ + int err_code; - if (offset_arg != NULL) - offset= atoi(offset_arg); - else - offset= 0; - size= atoi(size_arg); - log_type= log_type_arg; + if ((err_code= check_params(instance))) + return err_code; + + if ((err_code= write_header(net)) || + (err_code= write_data(net, instance))) + return err_code; - /* we make a search here, since we don't want to store the name */ - if ((instance= instance_map->find(name, len))) - instance_name= instance->options.instance_name; - else - instance_name= NULL; + return 0; } +int Show_instance_log::send_ok_response(st_net *net, ulong connection_id) +{ + if (send_eof(net) || net_flush(net)) + return ER_OUT_OF_RESOURCES; -/* - Open the logfile, read requested part of the log and send the info - to the client. + return 0; +} - SYNOPSYS - Show_instance_log::execute() - net The network connection to the client. - connection_id Client connection ID - DESCRIPTION +int Show_instance_log::check_params(Instance *instance) +{ + const char *logpath= instance->options.logs[log_type]; - Send a table with the content of the log requested. The function also - deals with errro handling, to be verbose. + /* Cannot read negative number of bytes. */ - RETURN - ER_OFFSET_ERROR We were requested to read negative number of bytes - from the log - ER_NO_SUCH_LOG The kind log being read is not enabled in the instance - ER_GUESS_LOGFILE IM wasn't able to figure out the log placement, while - it is enabled. Probably user should specify the path - to the logfile explicitly. - ER_OPEN_LOGFILE Cannot open the logfile - ER_READ_FILE Cannot read the logfile - ER_OUT_OF_RESOURCES We weren't able to allocate some resources -*/ + if (offset > size) + return ER_OFFSET_ERROR; + + /* Instance has no such log. */ + + if (logpath == NULL) + return ER_NO_SUCH_LOG; -int Show_instance_log::execute(struct st_net *net, ulong connection_id) + if (*logpath == '\0') + return ER_GUESS_LOGFILE; + + return 0; +} + + +int Show_instance_log::write_header(st_net *net) { - Buffer send_buff; /* buffer for packets */ LIST name; LIST *field_list; - NAME_WITH_LENGTH name_field; - uint position= 0; + LEX_STRING name_field; - /* create list of the fileds to be passed to send_fields */ - name_field.name= (char*) "Log"; + /* Create list of the fields to be passed to send_fields(). */ + + name_field.str= (char *) "Log"; name_field.length= DEFAULT_FIELD_LENGTH; - name.data= &name_field; - field_list= list_add(NULL, &name); - if (!instance_name) - return ER_BAD_INSTANCE_NAME; + name.data= &name_field; - /* cannot read negative number of bytes */ - if (offset > size) - return ER_OFFSET_ERROR; + field_list= list_add(NULL, &name); - send_fields(net, field_list); + return send_fields(net, field_list) ? ER_OUT_OF_RESOURCES : 0; +} - { - Instance *instance; - const char *logpath; - File fd; - if ((instance= instance_map->find(instance_name, - strlen(instance_name))) == NULL) - goto err; +int Show_instance_log::write_data(st_net *net, Instance *instance) +{ + Buffer send_buff; /* buffer for packets */ + uint pos= 0; - logpath= instance->options.logs[log_type]; + const char *logpath= instance->options.logs[log_type]; + File fd; - /* Instance has no such log */ - if (logpath == NULL) - return ER_NO_SUCH_LOG; + size_t buff_size; + int read_len; - if (*logpath == '\0') - return ER_GUESS_LOGFILE; + MY_STAT file_stat; + Buffer read_buff; + if ((fd= my_open(logpath, O_RDONLY | O_BINARY, MYF(MY_WME))) <= 0) + return ER_OPEN_LOGFILE; - if ((fd= my_open(logpath, O_RDONLY | O_BINARY, MYF(MY_WME))) >= 0) - { - size_t buff_size; - int read_len; - /* calculate buffer size */ - MY_STAT file_stat; - Buffer read_buff; + /* my_fstat doesn't use the flag parameter */ + if (my_fstat(fd, &file_stat, MYF(0))) + { + close(fd); + return ER_OUT_OF_RESOURCES; + } - /* my_fstat doesn't use the flag parameter */ - if (my_fstat(fd, &file_stat, MYF(0))) - goto err; + /* calculate buffer size */ + buff_size= (size - offset); - buff_size= (size - offset); + read_buff.reserve(0, buff_size); - read_buff.reserve(0, buff_size); + /* read in one chunk */ + read_len= (int)my_seek(fd, file_stat.st_size - size, MY_SEEK_SET, MYF(0)); - /* read in one chunk */ - read_len= (int)my_seek(fd, file_stat.st_size - size, MY_SEEK_SET, MYF(0)); + if ((read_len= my_read(fd, (byte*) read_buff.buffer, + buff_size, MYF(0))) < 0) + { + close(fd); + return ER_READ_FILE; + } - if ((read_len= my_read(fd, (byte*) read_buff.buffer, - buff_size, MYF(0))) < 0) - return ER_READ_FILE; - store_to_protocol_packet(&send_buff, read_buff.buffer, - &position, read_len); - close(fd); - } - else - return ER_OPEN_LOGFILE; + close(fd); - if (my_net_write(net, send_buff.buffer, (uint) position)) - goto err; + if (store_to_protocol_packet(&send_buff, read_buff.buffer, &pos, read_len) || + my_net_write(net, send_buff.buffer, pos)) + { + return ER_OUT_OF_RESOURCES; } - if (send_eof(net) || net_flush(net)) - goto err; - return 0; - -err: - return ER_OUT_OF_RESOURCES; } -/* implementation for Show_instance_log_files: */ +/************************************************************************** + Implementation of Show_instance_log_files. +**************************************************************************/ Show_instance_log_files::Show_instance_log_files - (Instance_map *instance_map_arg, const char *name, uint len) - :Command(instance_map_arg) + (Instance_map *instance_map_arg, + const LEX_STRING *instance_name_arg) + :Abstract_instance_cmd(instance_map_arg, instance_name_arg) { - Instance *instance; - - /* we make a search here, since we don't want to store the name */ - if ((instance= instance_map->find(name, len))) - instance_name= instance->options.instance_name; - else - instance_name= NULL; } /* - The method sends a table with a list of log files - used by the instance. + Implementation of SHOW INSTANCE LOG FILES statement. - SYNOPSYS - Show_instance_log_files::execute() - net The network connection to the client. - connection_id The ID of the client connection - - RETURN - ER_BAD_INSTANCE_NAME The instance name specified is not valid - ER_OUT_OF_RESOURCES some error occured - 0 - ok + Possible error codes: + ER_BAD_INSTANCE_NAME The instance with the given name does not exist + ER_OUT_OF_RESOURCES Not enough resources to complete the operation */ -int Show_instance_log_files::execute(struct st_net *net, ulong connection_id) +int Show_instance_log_files::execute_impl(st_net *net, Instance *instance) +{ + int err_code; + + if ((err_code= write_header(net)) || + (err_code= write_data(net, instance))) + return err_code; + + return 0; +} + + +int Show_instance_log_files::send_ok_response(st_net *net, ulong connection_id) +{ + if (send_eof(net) || net_flush(net)) + return ER_OUT_OF_RESOURCES; + + return 0; +} + + +int Show_instance_log_files::write_header(st_net *net) { - Buffer send_buff; /* buffer for packets */ LIST name, path, size; LIST *field_list; - NAME_WITH_LENGTH name_field, path_field, size_field; - uint position= 0; + LEX_STRING name_field, path_field, size_field; - if (!instance_name) - return ER_BAD_INSTANCE_NAME; + /* Create list of the fileds to be passed to send_fields(). */ - /* create list of the fileds to be passed to send_fields */ - name_field.name= (char*) "Logfile"; + name_field.str= (char *) "Logfile"; name_field.length= DEFAULT_FIELD_LENGTH; name.data= &name_field; - path_field.name= (char*) "Path"; + + path_field.str= (char *) "Path"; path_field.length= DEFAULT_FIELD_LENGTH; path.data= &path_field; - size_field.name= (char*) "File size"; + + size_field.str= (char *) "File size"; size_field.length= DEFAULT_FIELD_LENGTH; size.data= &size_field; + field_list= list_add(NULL, &size); field_list= list_add(field_list, &path); field_list= list_add(field_list, &name); - send_fields(net, field_list); + return send_fields(net, field_list) ? ER_OUT_OF_RESOURCES : 0; +} - Instance *instance; - if ((instance= instance_map-> - find(instance_name, strlen(instance_name))) == NULL) - goto err; +int Show_instance_log_files::write_data(st_net *net, Instance *instance) +{ + Buffer send_buff; /* buffer for packets */ + /* + We have alike structure in instance_options.cc. We use such to be able + to loop through the options, which we need to handle in some common way. + */ + struct log_files_st + { + const char *name; + const char *value; + } logs[]= + { + {"ERROR LOG", instance->options.logs[IM_LOG_ERROR]}, + {"GENERAL LOG", instance->options.logs[IM_LOG_GENERAL]}, + {"SLOW LOG", instance->options.logs[IM_LOG_SLOW]}, + {NULL, NULL} + }; + struct log_files_st *log_files; + + for (log_files= logs; log_files->name; log_files++) { + if (!log_files->value) + continue; + + struct stat file_stat; /* - We have alike structure in instance_options.cc. We use such to be able - to loop through the options, which we need to handle in some common way. + Save some more space for the log file names. In fact all + we need is strlen("GENERAL_LOG") + 1 */ - struct log_files_st - { - const char *name; - const char *value; - } logs[]= - { - {"ERROR LOG", instance->options.logs[IM_LOG_ERROR]}, - {"GENERAL LOG", instance->options.logs[IM_LOG_GENERAL]}, - {"SLOW LOG", instance->options.logs[IM_LOG_SLOW]}, - {NULL, NULL} - }; - struct log_files_st *log_files; - - for (log_files= logs; log_files->name; log_files++) + enum { LOG_NAME_BUFFER_SIZE= 20 }; + char buff[LOG_NAME_BUFFER_SIZE]; + + uint pos= 0; + + const char *log_path= ""; + const char *log_size= "0"; + + if (!stat(log_files->value, &file_stat) && + MY_S_ISREG(file_stat.st_mode)) { - if (log_files->value != NULL) - { - struct stat file_stat; - /* - Save some more space for the log file names. In fact all - we need is srtlen("GENERAL_LOG") + 1 - */ - enum { LOG_NAME_BUFFER_SIZE= 20 }; - char buff[LOG_NAME_BUFFER_SIZE]; - - position= 0; - /* store the type of the log in the send buffer */ - store_to_protocol_packet(&send_buff, log_files->name, &position); - if (stat(log_files->value, &file_stat)) - { - store_to_protocol_packet(&send_buff, "", &position); - store_to_protocol_packet(&send_buff, (char*) "0", &position); - } - else if (MY_S_ISREG(file_stat.st_mode)) - { - store_to_protocol_packet(&send_buff, - (char*) log_files->value, - &position); - int10_to_str(file_stat.st_size, buff, 10); - store_to_protocol_packet(&send_buff, (char*) buff, &position); - } - - if (my_net_write(net, send_buff.buffer, (uint) position)) - goto err; - } + int10_to_str(file_stat.st_size, buff, 10); + + log_path= log_files->value; + log_size= buff; } - } - if (send_eof(net) || net_flush(net)) - goto err; + if (store_to_protocol_packet(&send_buff, log_files->name, &pos) || + store_to_protocol_packet(&send_buff, log_path, &pos) || + store_to_protocol_packet(&send_buff, log_size, &pos) || + my_net_write(net, send_buff.buffer, pos)) + return ER_OUT_OF_RESOURCES; + } return 0; - -err: - return ER_OUT_OF_RESOURCES; } -/* implementation for SET instance_name.option=option_value: */ +/************************************************************************** + Implementation of Abstract_option_cmd. +**************************************************************************/ + +/* + Instance_options_list -- a data class representing a list of options for + some instance. +*/ -Set_option::Set_option(Instance_map *instance_map_arg, - const char *name, uint len, - const char *option_arg, uint option_len_arg, - const char *option_value_arg, uint option_value_len_arg) - :Command(instance_map_arg) +class Instance_options_list { - Instance *instance; +public: + Instance_options_list(const LEX_STRING *instance_name_arg); - /* we make a search here, since we don't want to store the name */ - if ((instance= instance_map->find(name, len))) - { - instance_name= instance->options.instance_name; +public: + bool init(); - /* add prefix for add_option */ - if ((option_len_arg < MAX_OPTION_LEN - 1) || - (option_value_len_arg < MAX_OPTION_LEN - 1)) - { - strmake(option, option_arg, option_len_arg); - strmake(option_value, option_value_arg, option_value_len_arg); - } - else - { - option[0]= 0; - option_value[0]= 0; - } - instance_name_len= len; - } - else + const LEX_STRING *get_instance_name() const { - instance_name= NULL; - instance_name_len= 0; + return instance_name.get_str(); } + +public: + /* + This member is set and used only in Abstract_option_cmd::execute_impl(). + Normally it is not used (and should not). + + The problem is that construction and execution of commands are made not + in one transaction (not under one lock session). So, we can not initialize + instance in constructor and use it in execution. + */ + Instance *instance; + + Named_value_arr options; + +private: + Instance_name instance_name; +}; + + +/**************************************************************************/ + +Instance_options_list::Instance_options_list( + const LEX_STRING *instance_name_arg) + :instance(NULL), + instance_name(instance_name_arg) +{ } -/* - The method sends a table with a list of log files - used by the instance. +bool Instance_options_list::init() +{ + return options.init(); +} - SYNOPSYS - Set_option::correct_file() - skip Skip the option, being searched while writing the result file. - That is, to delete it. - DESCRIPTION +/**************************************************************************/ + +C_MODE_START + +static byte* get_item_key(const byte* item, uint* len, + my_bool __attribute__((unused)) t) +{ + const Instance_options_list *lst= (const Instance_options_list *) item; + *len= lst->get_instance_name()->length; + return (byte *) lst->get_instance_name()->str; +} + +static void delete_item(void *item) +{ + delete (Instance_options_list *) item; +} + +C_MODE_END + + +/**************************************************************************/ + +Abstract_option_cmd::Abstract_option_cmd(Instance_map *instance_map_arg) + :Command(instance_map_arg), + initialized(FALSE) +{ +} + + +Abstract_option_cmd::~Abstract_option_cmd() +{ + if (initialized) + hash_free(&instance_options_map); +} + + +bool Abstract_option_cmd::add_option(const LEX_STRING *instance_name, + Named_value *option) +{ + Instance_options_list *lst= get_instance_options_list(instance_name); + + if (!lst) + return TRUE; + lst->options.add_element(option); + + return FALSE; +} + + +bool Abstract_option_cmd::init(const char **text) +{ + static const int INITIAL_HASH_SIZE= 16; + + if (hash_init(&instance_options_map, default_charset_info, + INITIAL_HASH_SIZE, 0, 0, get_item_key, delete_item, 0)) + return TRUE; + + if (parse_args(text)) + return TRUE; + + initialized= TRUE; + + return FALSE; +} + + +/* Correct the option file. The "skip" option is used to remove the found option. + SYNOPSYS + Abstract_option_cmd::correct_file() + skip Skip the option, being searched while writing the result file. + That is, to delete it. + RETURN - ER_OUT_OF_RESOURCES out of resources + 0 Success + ER_OUT_OF_RESOURCES Not enough resources to complete the operation ER_ACCESS_OPTION_FILE Cannot access the option file - 0 - ok */ -int Set_option::correct_file(int skip) +int Abstract_option_cmd::correct_file(Instance *instance, Named_value *option, + bool skip) { - static const int mysys_to_im_error[]= { 0, ER_OUT_OF_RESOURCES, - ER_ACCESS_OPTION_FILE }; - int error; + int err_code= modify_defaults_file(Options::Main::config_file, + option->get_name(), + option->get_value(), + instance->get_name()->str, + skip); + + DBUG_ASSERT(err_code >= 0 && err_code <= 2); - error= modify_defaults_file(Options::config_file, option, - option_value, instance_name, skip); - DBUG_ASSERT(error >= 0 && error <= 2); + if (err_code) + { + log_error("Can not modify option (%s) in defaults file (%s). " + "Original error code: %d.", + (const char *) option->get_name(), + (const char *) Options::Main::config_file, + (int) err_code); + } - return mysys_to_im_error[error]; + return modify_defaults_to_im_error[err_code]; } /* - The method sets an option in the the default config file (/etc/my.cnf). - - SYNOPSYS - Set_option::do_command() - net The network connection to the client. - - RETURN - 0 - ok - 1 - error occured + Implementation of SET statement. + + Possible error codes: + ER_BAD_INSTANCE_NAME The instance with the given name does not exist + ER_INCOMPATIBLE_OPTION The specified option can not be set for + mysqld-compatible instance + ER_INSTANCE_IS_ACTIVE The specified instance is active + ER_OUT_OF_RESOURCES Not enough resources to complete the operation */ -int Set_option::do_command(struct st_net *net) +int Abstract_option_cmd::execute(st_net *net, ulong connection_id) { - int error; + int err_code; - /* we must hold the instance_map mutex while changing config file */ instance_map->lock(); - error= correct_file(FALSE); + + err_code= execute_impl(net, connection_id); + instance_map->unlock(); - return error; + return err_code; +} + + +Instance_options_list * +Abstract_option_cmd::get_instance_options_list(const LEX_STRING *instance_name) +{ + Instance_options_list *lst= + (Instance_options_list *) hash_search(&instance_options_map, + (byte *) instance_name->str, + instance_name->length); + + if (!lst) + { + lst= new Instance_options_list(instance_name); + + if (!lst) + return NULL; + + if (lst->init() || my_hash_insert(&instance_options_map, (byte *) lst)) + { + delete lst; + return NULL; + } + } + + return lst; } -int Set_option::execute(struct st_net *net, ulong connection_id) +int Abstract_option_cmd::execute_impl(st_net *net, ulong connection_id) { - if (instance_name != NULL) + int err_code; + + /* Check that all the specified instances exist and are offline. */ + + for (uint i= 0; i < instance_options_map.records; ++i) { - int val; + Instance_options_list *lst= + (Instance_options_list *) hash_element(&instance_options_map, i); - val= do_command(net); + lst->instance= instance_map->find(lst->get_instance_name()); - if (val == 0) - net_send_ok(net, connection_id, NULL); + if (!lst->instance) + return ER_BAD_INSTANCE_NAME; - return val; + if (instance_map->guardian->is_active(lst->instance)) + return ER_INSTANCE_IS_ACTIVE; } - return ER_BAD_INSTANCE_NAME; + /* Perform command-specific (SET/UNSET) actions. */ + + for (uint i= 0; i < instance_options_map.records; ++i) + { + Instance_options_list *lst= + (Instance_options_list *) hash_element(&instance_options_map, i); + + for (int j= 0; j < lst->options.get_size(); ++j) + { + Named_value option= lst->options.get_element(j); + err_code= process_option(lst->instance, &option); + + if (err_code) + break; + } + + if (err_code) + break; + } + + if (err_code == 0) + net_send_ok(net, connection_id, NULL); + + return err_code; } -/* the only function from Unset_option we need to Implement */ +/************************************************************************** + Implementation of Set_option. +**************************************************************************/ -int Unset_option::do_command(struct st_net *net) +Set_option::Set_option(Instance_map *instance_map_arg) + :Abstract_option_cmd(instance_map_arg) { - return correct_file(TRUE); } -/* Implementation for Stop_instance: */ +/* + This operation parses SET options. + + SYNOPSYS + text [IN/OUT] a pointer to the text containing options. -Stop_instance::Stop_instance(Instance_map *instance_map_arg, - const char *name, uint len) - :Command(instance_map_arg) + RETURN + FALSE On success. + TRUE On syntax error. +*/ + +bool Set_option::parse_args(const char **text) { - /* we make a search here, since we don't want to store the name */ - if ((instance= instance_map->find(name, len))) - instance_name= instance->options.instance_name; + uint len; + + /* Check if we have something (and trim leading spaces). */ + + get_word(text, &len, NONSPACE); + + if (len == 0) + return TRUE; /* Syntax error: no option. */ + + /* Main parsing loop. */ + + while (TRUE) + { + LEX_STRING instance_name; + LEX_STRING option_name; + char *option_name_str; + char *option_value_str= NULL; + + /* Looking for instance name. */ + + get_word(text, &instance_name.length, ALPHANUM); + + if (instance_name.length == 0) + return TRUE; /* Syntax error: instance name expected. */ + + instance_name.str= (char *) *text; + *text+= instance_name.length; + + skip_spaces(text); + + /* Check the the delimiter is a dot. */ + + if (**text != '.') + return TRUE; /* Syntax error: dot expected. */ + + ++(*text); + + /* Looking for option name. */ + + get_word(text, &option_name.length, OPTION_NAME); + + if (option_name.length == 0) + return TRUE; /* Syntax error: option name expected. */ + + option_name.str= (char *) *text; + *text+= option_name.length; + + /* Looking for equal sign. */ + + skip_spaces(text); + + if (**text == '=') + { + ++(*text); /* Skip an equal sign. */ + + /* Looking for option value. */ + + skip_spaces(text); + + if (!**text) + return TRUE; /* Syntax error: EOS when option value expected. */ + + if (**text != '\'' && **text != '"') + { + /* Option value is a simple token. */ + + LEX_STRING option_value; + + get_word(text, &option_value.length, ALPHANUM); + + if (option_value.length == 0) + return TRUE; /* internal parser error. */ + + option_value.str= (char *) *text; + *text+= option_value.length; + + if (!(option_value_str= Named_value::alloc_str(&option_value))) + return TRUE; /* out of memory during parsing. */ + } + else + { + /* Option value is a string. */ + + if (parse_option_value(*text, &len, &option_value_str)) + return TRUE; /* Syntax error: invalid string specification. */ + + *text+= len; + } + } + + if (!option_value_str) + { + LEX_STRING empty_str= { C_STRING_WITH_SIZE("") }; + + if (!(option_value_str= Named_value::alloc_str(&empty_str))) + return TRUE; /* out of memory during parsing. */ + } + + if (!(option_name_str= Named_value::alloc_str(&option_name))) + { + Named_value::free_str(&option_name_str); + return TRUE; /* out of memory during parsing. */ + } + + { + Named_value option(option_name_str, option_value_str); + + if (add_option(&instance_name, &option)) + { + option.free(); + return TRUE; /* out of memory during parsing. */ + } + } + + skip_spaces(text); + + if (!**text) + return FALSE; /* OK: end of options. */ + + if (**text != ',') + return TRUE; /* Syntax error: comma expected. */ + + ++(*text); /* Skip a comma. */ + } } -int Stop_instance::execute(struct st_net *net, ulong connection_id) +int Set_option::process_option(Instance *instance, Named_value *option) { - uint err_code; + /* Check that the option is valid. */ + + if (instance->is_mysqld_compatible() && + Instance_options::is_option_im_specific(option->get_name())) + { + log_error("Error: IM-option (%s) can not be used " + "in the configuration of mysqld-compatible instance (%s).", + (const char *) option->get_name(), + (const char *) instance->get_name()->str); + return ER_INCOMPATIBLE_OPTION; + } - if (instance == 0) - return ER_BAD_INSTANCE_NAME; /* haven't found an instance */ + /* Update the configuration file. */ - if (!(instance->options.nonguarded)) - instance_map->guardian->stop_guard(instance); + int err_code= correct_file(instance, option, FALSE); - if ((err_code= instance->stop())) + if (err_code) + return err_code; + + /* Update the internal cache. */ + + if (instance->options.set_option(option)) + return ER_OUT_OF_RESOURCES; + + return 0; +} + + +/************************************************************************** + Implementation of Unset_option. +**************************************************************************/ + +Unset_option::Unset_option(Instance_map *instance_map_arg) + :Abstract_option_cmd(instance_map_arg) +{ +} + + +/* + This operation parses UNSET options. + + SYNOPSYS + text [IN/OUT] a pointer to the text containing options. + + RETURN + FALSE On success. + TRUE On syntax error. +*/ + +bool Unset_option::parse_args(const char **text) +{ + uint len; + + /* Check if we have something (and trim leading spaces). */ + + get_word(text, &len, NONSPACE); + + if (len == 0) + return TRUE; /* Syntax error: no option. */ + + /* Main parsing loop. */ + + while (TRUE) + { + LEX_STRING instance_name; + LEX_STRING option_name; + char *option_name_str; + char *option_value_str; + + /* Looking for instance name. */ + + get_word(text, &instance_name.length, ALPHANUM); + + if (instance_name.length == 0) + return TRUE; /* Syntax error: instance name expected. */ + + instance_name.str= (char *) *text; + *text+= instance_name.length; + + skip_spaces(text); + + /* Check the the delimiter is a dot. */ + + if (**text != '.') + return TRUE; /* Syntax error: dot expected. */ + + ++(*text); /* Skip a dot. */ + + /* Looking for option name. */ + + get_word(text, &option_name.length, OPTION_NAME); + + if (option_name.length == 0) + return TRUE; /* Syntax error: option name expected. */ + + option_name.str= (char *) *text; + *text+= option_name.length; + + if (!(option_name_str= Named_value::alloc_str(&option_name))) + return TRUE; /* out of memory during parsing. */ + + { + LEX_STRING empty_str= { C_STRING_WITH_SIZE("") }; + + if (!(option_value_str= Named_value::alloc_str(&empty_str))) + { + Named_value::free_str(&option_name_str); + return TRUE; + } + } + + { + Named_value option(option_name_str, option_value_str); + + if (add_option(&instance_name, &option)) + { + option.free(); + return TRUE; /* out of memory during parsing. */ + } + } + + skip_spaces(text); + + if (!**text) + return FALSE; /* OK: end of options. */ + + if (**text != ',') + return TRUE; /* Syntax error: comma expected. */ + + ++(*text); /* Skip a comma. */ + } +} + + +/* + Implementation of UNSET statement. + + Possible error codes: + ER_BAD_INSTANCE_NAME The instance name specified is not valid + ER_INSTANCE_IS_ACTIVE The specified instance is active + ER_OUT_OF_RESOURCES Not enough resources to complete the operation +*/ + +int Unset_option::process_option(Instance *instance, Named_value *option) +{ + /* Update the configuration file. */ + + int err_code= correct_file(instance, option, TRUE); + + if (err_code) return err_code; - net_send_ok(net, connection_id, NULL); + /* Update the internal cache. */ + + instance->options.unset_option(option->get_name()); + return 0; } -int Syntax_error::execute(struct st_net *net, ulong connection_id) +/************************************************************************** + Implementation of Syntax_error. +**************************************************************************/ + +int Syntax_error::execute(st_net *net, ulong connection_id) { return ER_SYNTAX_ERROR; } diff --git a/server-tools/instance-manager/commands.h b/server-tools/instance-manager/commands.h index bfd38d34889..9a9911f2358 100644 --- a/server-tools/instance-manager/commands.h +++ b/server-tools/instance-manager/commands.h @@ -16,10 +16,20 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <my_global.h> +#include <my_sys.h> +#include <m_string.h> +#include <hash.h> + #include "command.h" #include "instance.h" #include "parse.h" +#if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE) +#pragma interface +#endif + + /* Print all instances of this instance manager. Grammar: SHOW ISTANCES @@ -31,12 +41,16 @@ public: Show_instances(Instance_map *instance_map_arg): Command(instance_map_arg) {} - int execute(struct st_net *net, ulong connection_id); + int execute(st_net *net, ulong connection_id); + +private: + int write_header(st_net *net); + int write_data(st_net *net); }; /* - Reread configuration file and refresh instance map. + Reread configuration file and refresh internal cache. Grammar: FLUSH INSTANCES */ @@ -46,7 +60,43 @@ public: Flush_instances(Instance_map *instance_map_arg): Command(instance_map_arg) {} - int execute(struct st_net *net, ulong connection_id); + int execute(st_net *net, ulong connection_id); +}; + + +/* + Abstract class for Instance-specific commands. +*/ + +class Abstract_instance_cmd : public Command +{ +public: + Abstract_instance_cmd(Instance_map *instance_map_arg, + const LEX_STRING *instance_name_arg); + +public: + virtual int execute(st_net *net, ulong connection_id); + +protected: + /* MT-NOTE: this operation is called under acquired Instance_map's lock. */ + virtual int execute_impl(st_net *net, Instance *instance) = 0; + + /* + This operation is invoked on successful return of execute_impl() and is + intended to send closing data. + + MT-NOTE: this operation is called under released Instance_map's lock. + */ + virtual int send_ok_response(st_net *net, ulong connection_id) = 0; + +protected: + inline const LEX_STRING *get_instance_name() const + { + return instance_name.get_str(); + } + +private: + Instance_name instance_name; }; @@ -55,31 +105,40 @@ public: Grammar: SHOW ISTANCE STATUS <instance_name> */ -class Show_instance_status : public Command +class Show_instance_status : public Abstract_instance_cmd { public: - Show_instance_status(Instance_map *instance_map_arg, - const char *name, uint len); - int execute(struct st_net *net, ulong connection_id); - const char *instance_name; + const LEX_STRING *instance_name_arg); + +protected: + virtual int execute_impl(st_net *net, Instance *instance); + virtual int send_ok_response(st_net *net, ulong connection_id); + +private: + int write_header(st_net *net); + int write_data(st_net *net, Instance *instance); }; /* - Print options if chosen instance. + Print options of chosen instance. Grammar: SHOW INSTANCE OPTIONS <instance_name> */ -class Show_instance_options : public Command +class Show_instance_options : public Abstract_instance_cmd { public: - Show_instance_options(Instance_map *instance_map_arg, - const char *name, uint len); + const LEX_STRING *instance_name_arg); - int execute(struct st_net *net, ulong connection_id); - const char *instance_name; +protected: + virtual int execute_impl(st_net *net, Instance *instance); + virtual int send_ok_response(st_net *net, ulong connection_id); + +private: + int write_header(st_net *net); + int write_data(st_net *net, Instance *instance); }; @@ -88,14 +147,15 @@ public: Grammar: START INSTANCE <instance_name> */ -class Start_instance : public Command +class Start_instance : public Abstract_instance_cmd { public: - Start_instance(Instance_map *instance_map_arg, const char *name, uint len); + Start_instance(Instance_map *instance_map_arg, + const LEX_STRING *instance_name_arg); - int execute(struct st_net *net, ulong connection_id); - const char *instance_name; - Instance *instance; +protected: + virtual int execute_impl(st_net *net, Instance *instance); + virtual int send_ok_response(st_net *net, ulong connection_id); }; @@ -104,33 +164,95 @@ public: Grammar: STOP INSTANCE <instance_name> */ -class Stop_instance : public Command +class Stop_instance : public Abstract_instance_cmd { public: - Stop_instance(Instance_map *instance_map_arg, const char *name, uint len); + Stop_instance(Instance_map *instance_map_arg, + const LEX_STRING *instance_name_arg); - Instance *instance; - int execute(struct st_net *net, ulong connection_id); - const char *instance_name; +protected: + virtual int execute_impl(st_net *net, Instance *instance); + virtual int send_ok_response(st_net *net, ulong connection_id); }; /* - Print requested part of the log + Create an instance. + Grammar: CREATE INSTANCE <instance_name> [<options>] +*/ + +class Create_instance : public Command +{ +public: + Create_instance(Instance_map *instance_map_arg, + const LEX_STRING *instance_name_arg); + +public: + bool init(const char **text); + +protected: + virtual int execute(st_net *net, ulong connection_id); + + inline const LEX_STRING *get_instance_name() const + { + return instance_name.get_str(); + } + +private: + bool parse_args(const char **text); + +private: + Instance_name instance_name; + + Named_value_arr options; +}; + + +/* + Drop an instance. + Grammar: DROP INSTANCE <instance_name> + + Operation is permitted only if the instance is stopped. On successful + completion the instance section is removed from config file and the instance + is removed from the instance map. +*/ + +class Drop_instance : public Abstract_instance_cmd +{ +public: + Drop_instance(Instance_map *instance_map_arg, + const LEX_STRING *instance_name_arg); + +protected: + virtual int execute_impl(st_net *net, Instance *instance); + virtual int send_ok_response(st_net *net, ulong connection_id); +}; + + +/* + Print requested part of the log. Grammar: - SHOW <instance_name> log {ERROR | SLOW | GENERAL} size[, offset_from_end] + SHOW <instance_name> LOG {ERROR | SLOW | GENERAL} size[, offset_from_end] */ -class Show_instance_log : public Command +class Show_instance_log : public Abstract_instance_cmd { public: + Show_instance_log(Instance_map *instance_map_arg, + const LEX_STRING *instance_name_arg, + Log_type log_type_arg, uint size_arg, uint offset_arg); + +protected: + virtual int execute_impl(st_net *net, Instance *instance); + virtual int send_ok_response(st_net *net, ulong connection_id); + +private: + int check_params(Instance *instance); + int write_header(st_net *net); + int write_data(st_net *net, Instance *instance); - Show_instance_log(Instance_map *instance_map_arg, const char *name, - uint len, Log_type log_type_arg, const char *size_arg, - const char *offset_arg); - int execute(struct st_net *net, ulong connection_id); +private: Log_type log_type; - const char *instance_name; uint size; uint offset; }; @@ -141,75 +263,112 @@ public: Grammar: SHOW <instance_name> LOG FILES */ -class Show_instance_log_files : public Command +class Show_instance_log_files : public Abstract_instance_cmd { public: - Show_instance_log_files(Instance_map *instance_map_arg, - const char *name, uint len); - int execute(struct st_net *net, ulong connection_id); - const char *instance_name; - const char *option; + const LEX_STRING *instance_name_arg); + +protected: + virtual int execute_impl(st_net *net, Instance *instance); + virtual int send_ok_response(st_net *net, ulong connection_id); + +private: + int write_header(st_net *net); + int write_data(st_net *net, Instance *instance); }; /* - Syntax error command. This command is issued if parser reported a syntax - error. We need it to distinguish the parse error and the situation when - parser internal error occured. E.g. parsing failed because we hadn't had - enought memory. In the latter case parse_command() should return an error. + Abstract class for option-management commands. */ -class Syntax_error : public Command +class Instance_options_list; + +class Abstract_option_cmd : public Command { public: - int execute(struct st_net *net, ulong connection_id); + ~Abstract_option_cmd(); + +public: + bool add_option(const LEX_STRING *instance_name, Named_value *option); + +public: + bool init(const char **text); + + virtual int execute(st_net *net, ulong connection_id); + +protected: + Abstract_option_cmd(Instance_map *instance_map_arg); + + int correct_file(Instance *instance, Named_value *option, bool skip); + +protected: + virtual bool parse_args(const char **text) = 0; + virtual int process_option(Instance *instance, Named_value *option) = 0; + +private: + Instance_options_list * + get_instance_options_list(const LEX_STRING *instance_name); + + int execute_impl(st_net *net, ulong connection_id); + +private: + HASH instance_options_map; + bool initialized; }; + /* Set an option for the instance. - Grammar: SET instance_name.option=option_value + Grammar: SET instance_name.option[=option_value][, ...] */ -class Set_option : public Command +class Set_option : public Abstract_option_cmd { public: - Set_option(Instance_map *instance_map_arg, const char *name, uint len, - const char *option_arg, uint option_len, - const char *option_value_arg, uint option_value_len); - /* - the following function is virtual to let Unset_option to use - */ - virtual int do_command(struct st_net *net); - int execute(struct st_net *net, ulong connection_id); + Set_option(Instance_map *instance_map_arg); + protected: - int correct_file(int skip); -public: - const char *instance_name; - uint instance_name_len; - /* buffer for the option */ - enum { MAX_OPTION_LEN= 1024 }; - char option[MAX_OPTION_LEN]; - char option_value[MAX_OPTION_LEN]; + virtual bool parse_args(const char **text); + virtual int process_option(Instance *instance, Named_value *option); }; /* - Remove option of the instance from config file - Grammar: UNSET instance_name.option + Remove option of the instance. + Grammar: UNSET instance_name.option[, ...] */ -class Unset_option: public Set_option +class Unset_option: public Abstract_option_cmd { public: - Unset_option(Instance_map *instance_map_arg, const char *name, uint len, - const char *option_arg, uint option_len, - const char *option_value_arg, uint option_value_len): - Set_option(instance_map_arg, name, len, option_arg, option_len, - option_value_arg, option_value_len) - {} - int do_command(struct st_net *net); + Unset_option(Instance_map *instance_map_arg); + +protected: + virtual bool parse_args(const char **text); + virtual int process_option(Instance *instance, Named_value *option); }; +/* + Syntax error command. + + This command is issued if parser reported a syntax error. We need it to + distinguish between syntax error and internal parser error. E.g. parsing + failed because we hadn't had enought memory. In the latter case the parser + just returns NULL. +*/ + +class Syntax_error : public Command +{ +public: + /* This is just to avoid compiler warning. */ + Syntax_error() :Command(NULL) + {} + +public: + int execute(st_net *net, ulong connection_id); +}; + #endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_COMMANDS_H */ diff --git a/server-tools/instance-manager/exit_codes.h b/server-tools/instance-manager/exit_codes.h new file mode 100644 index 00000000000..560ce30b7aa --- /dev/null +++ b/server-tools/instance-manager/exit_codes.h @@ -0,0 +1,41 @@ +#ifndef INCLUDES_MYSQL_INSTANCE_MANAGER_EXIT_CODES_H +#define INCLUDES_MYSQL_INSTANCE_MANAGER_EXIT_CODES_H + +/* + Copyright (C) 2006 MySQL 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 +*/ + +/* + This file contains a list of exit codes, which are used when Instance + Manager is working in user-management mode. +*/ + +const int ERR_OK = 0; + +const int ERR_OUT_OF_MEMORY = 1; +const int ERR_INVALID_USAGE = 2; +const int ERR_INTERNAL_ERROR = 3; +const int ERR_IO_ERROR = 4; +const int ERR_PASSWORD_FILE_CORRUPTED = 5; +const int ERR_PASSWORD_FILE_DOES_NOT_EXIST = 6; + +const int ERR_CAN_NOT_READ_USER_NAME = 10; +const int ERR_CAN_NOT_READ_PASSWORD = 11; +const int ERR_USER_ALREADY_EXISTS = 12; +const int ERR_USER_NOT_FOUND = 13; + +#endif // INCLUDES_MYSQL_INSTANCE_MANAGER_EXIT_CODES_H diff --git a/server-tools/instance-manager/guardian.cc b/server-tools/instance-manager/guardian.cc index 3be672cd71c..b58241272f9 100644 --- a/server-tools/instance-manager/guardian.cc +++ b/server-tools/instance-manager/guardian.cc @@ -21,16 +21,14 @@ #include "guardian.h" -#include "instance_map.h" -#include "instance.h" -#include "mysql_manager_error.h" -#include "log.h" -#include "portability.h" - #include <string.h> #include <sys/types.h> #include <signal.h> +#include "instance.h" +#include "instance_map.h" +#include "log.h" +#include "mysql_manager_error.h" pthread_handler_t guardian(void *arg) @@ -40,6 +38,37 @@ pthread_handler_t guardian(void *arg) return 0; } + +const char * +Guardian_thread::get_instance_state_name(enum_instance_state state) +{ + switch (state) { + case NOT_STARTED: + return "offline"; + + case STARTING: + return "starting"; + + case STARTED: + return "online"; + + case JUST_CRASHED: + return "failed"; + + case CRASHED: + return "crashed"; + + case CRASHED_AND_ABANDONED: + return "abandoned"; + + case STOPPING: + return "stopping"; + } + + return NULL; /* just to ignore compiler warning. */ +} + + Guardian_thread::Guardian_thread(Thread_registry &thread_registry_arg, Instance_map *instance_map_arg, uint monitoring_interval_arg) : @@ -89,10 +118,17 @@ void Guardian_thread::process_instance(Instance *instance, if (current_node->state == STOPPING) { /* this brach is executed during shutdown */ - if (instance->options.shutdown_delay_val) + if (instance->options.shutdown_delay) + { + /* + NOTE: it is important to check shutdown_delay here, but use + shutdown_delay_val. The idea is that if the option is unset, + shutdown_delay will be NULL, but shutdown_delay_val will not be reset. + */ waitchild= instance->options.shutdown_delay_val; + } - /* this returns true if and only if an instance was stopped for sure */ + /* this returns TRUE if and only if an instance was stopped for sure */ if (instance->is_crashed()) *guarded_instances= list_delete(*guarded_instances, node); else if ( (uint) (current_time - current_node->last_checked) > waitchild) @@ -139,9 +175,12 @@ void Guardian_thread::process_instance(Instance *instance, case JUST_CRASHED: if (current_time - current_node->crash_moment <= 2) { - instance->start(); - log_info("guardian: starting instance %s", - instance->options.instance_name); + if (instance->is_crashed()) + { + instance->start(); + log_info("guardian: starting instance %s", + instance->options.instance_name); + } } else current_node->state= CRASHED; @@ -152,14 +191,21 @@ void Guardian_thread::process_instance(Instance *instance, { if ((current_node->restart_counter < restart_retry)) { - instance->start(); - current_node->last_checked= current_time; - current_node->restart_counter++; - log_info("guardian: restarting instance %s", - instance->options.instance_name); + if (instance->is_crashed()) + { + instance->start(); + current_node->last_checked= current_time; + current_node->restart_counter++; + log_info("guardian: restarting instance %s", + instance->options.instance_name); + } } else + { + log_info("guardian: cannot start instance %s. Abandoning attempts " + "to (re)start it", instance->options.instance_name); current_node->state= CRASHED_AND_ABANDONED; + } } break; case CRASHED_AND_ABANDONED: @@ -242,7 +288,9 @@ int Guardian_thread::is_stopped() SYNOPSYS Guardian_thread::init() - NOTE: One should always lock guardian before calling this routine. + NOTE: The operation should be invoked with the following locks acquired: + - Guardian_thread; + - Instance_map; RETURN 0 - ok @@ -261,12 +309,11 @@ int Guardian_thread::init() while ((instance= iterator.next())) { - if (!(instance->options.nonguarded)) - if (guard(instance, TRUE)) /* do not lock guardian */ - { - instance_map->unlock(); - return 1; - } + if (instance->options.nonguarded) + continue; + + if (guard(instance, TRUE)) /* do not lock guardian */ + return 1; } return 0; @@ -334,24 +381,14 @@ int Guardian_thread::stop_guard(Instance *instance) LIST *node; pthread_mutex_lock(&LOCK_guardian); - node= guarded_instances; - while (node != NULL) - { - /* - We compare only pointers, as we always use pointers from the - instance_map's MEM_ROOT. - */ - if (((GUARD_NODE *) node->data)->instance == instance) - { - guarded_instances= list_delete(guarded_instances, node); - pthread_mutex_unlock(&LOCK_guardian); - return 0; - } - else - node= node->next; - } + node= find_instance_node(instance); + + if (node != NULL) + guarded_instances= list_delete(guarded_instances, node); + pthread_mutex_unlock(&LOCK_guardian); + /* if there is nothing to delete it is also fine */ return 0; } @@ -420,7 +457,7 @@ int Guardian_thread::stop_instances(bool stop_instances_arg) void Guardian_thread::lock() { - pthread_mutex_lock(&LOCK_guardian); + pthread_mutex_lock(&LOCK_guardian); } @@ -428,3 +465,41 @@ void Guardian_thread::unlock() { pthread_mutex_unlock(&LOCK_guardian); } + + +LIST *Guardian_thread::find_instance_node(Instance *instance) +{ + LIST *node= guarded_instances; + + while (node != NULL) + { + /* + We compare only pointers, as we always use pointers from the + instance_map's MEM_ROOT. + */ + if (((GUARD_NODE *) node->data)->instance == instance) + return node; + + node= node->next; + } + + return NULL; +} + + +bool Guardian_thread::is_active(Instance *instance) +{ + bool guarded; + + lock(); + + guarded= find_instance_node(instance) != NULL; + + /* is_running() can take a long time, so let's unlock mutex first. */ + unlock(); + + if (guarded) + return true; + + return instance->is_running(); +} diff --git a/server-tools/instance-manager/guardian.h b/server-tools/instance-manager/guardian.h index 16b4c373c91..6d3a2b222d7 100644 --- a/server-tools/instance-manager/guardian.h +++ b/server-tools/instance-manager/guardian.h @@ -17,11 +17,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <my_global.h> -#include "thread_registry.h" - #include <my_sys.h> #include <my_list.h> +#include "thread_registry.h" + #if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE) #pragma interface #endif @@ -79,6 +79,8 @@ public: time_t last_checked; }; + /* Return client state name. */ + static const char *get_instance_state_name(enum_instance_state state); Guardian_thread(Thread_registry &thread_registry_arg, Instance_map *instance_map_arg, @@ -94,11 +96,28 @@ public: int guard(Instance *instance, bool nolock= FALSE); /* Stop instance protection */ int stop_guard(Instance *instance); - /* Returns true if guardian thread is stopped */ + /* Returns TRUE if guardian thread is stopped */ int is_stopped(); void lock(); void unlock(); + /* + Return an internal list node for the given instance if the instance is + managed by Guardian. Otherwise, return NULL. + + MT-NOTE: must be called under acquired lock. + */ + LIST *find_instance_node(Instance *instance); + + /* The operation is used to check if the instance is active or not. */ + bool is_active(Instance *instance); + + /* + Return state of the given instance list node. The pointer must specify + a valid list node. + */ + inline enum_instance_state get_instance_state(LIST *instance_node); + public: pthread_cond_t COND_guardian; @@ -108,6 +127,7 @@ private: /* check instance state and act accordingly */ void process_instance(Instance *instance, GUARD_NODE *current_node, LIST **guarded_instances, LIST *elem); + int stopped; private: @@ -115,9 +135,15 @@ private: Thread_info thread_info; LIST *guarded_instances; MEM_ROOT alloc; - enum { MEM_ROOT_BLOCK_SIZE= 512 }; /* this variable is set to TRUE when we want to stop Guardian thread */ bool shutdown_requested; }; + +inline Guardian_thread::enum_instance_state +Guardian_thread::get_instance_state(LIST *instance_node) +{ + return ((GUARD_NODE *) instance_node->data)->state; +} + #endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_GUARDIAN_H */ diff --git a/server-tools/instance-manager/instance.cc b/server-tools/instance-manager/instance.cc index 39381b457ab..456052bf7e5 100644 --- a/server-tools/instance-manager/instance.cc +++ b/server-tools/instance-manager/instance.cc @@ -20,18 +20,27 @@ #include "instance.h" -#include "mysql_manager_error.h" -#include "log.h" -#include "instance_map.h" -#include "priv.h" -#include "portability.h" +#include <my_global.h> +#include <mysql.h> + +#include <signal.h> #ifndef __WIN__ #include <sys/wait.h> #endif -#include <my_sys.h> -#include <signal.h> -#include <m_string.h> -#include <mysql.h> + +#include "guardian.h" +#include "instance_map.h" +#include "log.h" +#include "mysql_manager_error.h" +#include "portability.h" +#include "priv.h" + + +const LEX_STRING +Instance::DFLT_INSTANCE_NAME= { C_STRING_WITH_SIZE("mysqld") }; + +static const char * const INSTANCE_NAME_PREFIX= Instance::DFLT_INSTANCE_NAME.str; +static const int INSTANCE_NAME_PREFIX_LEN= Instance::DFLT_INSTANCE_NAME.length; static void start_and_monitor_instance(Instance_options *old_instance_options, @@ -152,7 +161,7 @@ static int start_process(Instance_options *instance_options, switch (*pi) { case 0: /* never happens on QNX */ - execv(instance_options->mysqld_path, instance_options->argv); + execv(instance_options->mysqld_path.str, instance_options->argv); /* exec never returns */ exit(1); case -1: @@ -180,7 +189,7 @@ static int start_process(Instance_options *instance_options, char *cmdline= new char[cmdlen]; if (cmdline == NULL) return 1; - + cmdline[0]= 0; for (int i= 0; instance_options->argv[i] != 0; i++) { @@ -232,9 +241,7 @@ static int start_process(Instance_options *instance_options, static void start_and_monitor_instance(Instance_options *old_instance_options, Instance_map *instance_map) { - enum { MAX_INSTANCE_NAME_LEN= 512 }; - char instance_name_buff[MAX_INSTANCE_NAME_LEN]; - uint instance_name_len; + Instance_name instance_name(&old_instance_options->instance_name); Instance *current_instance; My_process_info process_info; @@ -248,11 +255,8 @@ static void start_and_monitor_instance(Instance_options *old_instance_options, Save the instance name in the case if Instance object we are using is destroyed. (E.g. by "FLUSH INSTANCES") */ - strmake(instance_name_buff, old_instance_options->instance_name, - MAX_INSTANCE_NAME_LEN - 1); - instance_name_len= old_instance_options->instance_name_len; - log_info("starting instance %s", instance_name_buff); + log_info("starting instance %s", (const char *) instance_name.get_c_str()); if (start_process(old_instance_options, &process_info)) { @@ -266,15 +270,36 @@ static void start_and_monitor_instance(Instance_options *old_instance_options, /* don't check for return value */ wait_process(&process_info); - current_instance= instance_map->find(instance_name_buff, instance_name_len); + instance_map->lock(); + + current_instance= instance_map->find(instance_name.get_str()); if (current_instance) current_instance->set_crash_flag_n_wake_all(); + instance_map->unlock(); + return; } +bool Instance::is_name_valid(const LEX_STRING *name) +{ + const char *name_suffix= name->str + INSTANCE_NAME_PREFIX_LEN; + + if (strncmp(name->str, INSTANCE_NAME_PREFIX, INSTANCE_NAME_PREFIX_LEN) != 0) + return FALSE; + + return *name_suffix == 0 || my_isdigit(default_charset_info, *name_suffix); +} + + +bool Instance::is_mysqld_compatible_name(const LEX_STRING *name) +{ + return strcmp(name->str, INSTANCE_NAME_PREFIX) == 0; +} + + Instance_map *Instance::get_map() { return instance_map; @@ -309,11 +334,11 @@ int Instance::start() { /* clear crash flag */ pthread_mutex_lock(&LOCK_instance); - crashed= 0; + crashed= FALSE; pthread_mutex_unlock(&LOCK_instance); - if (!is_running()) + if (configured && !is_running()) { remove_pid(); @@ -339,8 +364,8 @@ int Instance::start() return 0; } - /* the instance is started already */ - return ER_INSTANCE_ALREADY_STARTED; + /* The instance is started already or misconfigured. */ + return configured ? ER_INSTANCE_ALREADY_STARTED : ER_INSTANCE_MISCONFIGURED; } /* @@ -363,7 +388,7 @@ void Instance::set_crash_flag_n_wake_all() { /* set instance state to crashed */ pthread_mutex_lock(&LOCK_instance); - crashed= 1; + crashed= TRUE; pthread_mutex_unlock(&LOCK_instance); /* @@ -378,7 +403,7 @@ void Instance::set_crash_flag_n_wake_all() -Instance::Instance(): crashed(0) +Instance::Instance(): crashed(FALSE), configured(FALSE) { pthread_mutex_init(&LOCK_instance, 0); pthread_cond_init(&COND_instance_stopped, 0); @@ -392,9 +417,9 @@ Instance::~Instance() } -int Instance::is_crashed() +bool Instance::is_crashed() { - int val; + bool val; pthread_mutex_lock(&LOCK_instance); val= crashed; pthread_mutex_unlock(&LOCK_instance); @@ -413,10 +438,17 @@ bool Instance::is_running() bool return_val; if (options.mysqld_port) + { + /* + NOTE: it is important to check mysqld_port here, but use + mysqld_port_val. The idea is that if the option is unset, mysqld_port + will be NULL, but mysqld_port_val will not be reset. + */ port= options.mysqld_port_val; + } if (options.mysqld_socket) - socket= strchr(options.mysqld_socket, '=') + 1; + socket= options.mysqld_socket; /* no port was specified => instance falled back to default value */ if (!options.mysqld_port && !options.mysqld_socket) @@ -469,8 +501,15 @@ int Instance::stop() struct timespec timeout; uint waitchild= (uint) DEFAULT_SHUTDOWN_DELAY; - if (options.shutdown_delay_val) + if (options.shutdown_delay) + { + /* + NOTE: it is important to check shutdown_delay here, but use + shutdown_delay_val. The idea is that if the option is unset, + shutdown_delay will be NULL, but shutdown_delay_val will not be reset. + */ waitchild= options.shutdown_delay_val; + } kill_instance(SIGTERM); /* sleep on condition to wait for SIGCHLD */ @@ -588,20 +627,33 @@ void Instance::kill_instance(int signum) } /* - We execute this function to initialize instance parameters. - Return value: 0 - ok. 1 - unable to init DYNAMIC_ARRAY. + Initialize instance parameters. + + SYNOPSYS + Instance::init() + name_arg name of the instance + + RETURN: + 0 ok + !0 error */ -int Instance::init(const char *name_arg) +int Instance::init(const LEX_STRING *name_arg) { + mysqld_compatible= is_mysqld_compatible_name(name_arg); + return options.init(name_arg); } int Instance::complete_initialization(Instance_map *instance_map_arg, - const char *mysqld_path, - uint instance_type) + const char *mysqld_path) { instance_map= instance_map_arg; - return options.complete_initialization(mysqld_path, instance_type); + configured= !options.complete_initialization(mysqld_path); + return 0; + /* + TODO: return actual status (from + Instance_options::complete_initialization()) here. + */ } diff --git a/server-tools/instance-manager/instance.h b/server-tools/instance-manager/instance.h index adb66991685..1f06cabebf7 100644 --- a/server-tools/instance-manager/instance.h +++ b/server-tools/instance-manager/instance.h @@ -17,7 +17,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <my_global.h> +#include <m_string.h> + #include "instance_options.h" +#include "priv.h" #if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE) #pragma interface @@ -25,31 +28,120 @@ class Instance_map; + +/* + Instance_name -- the class represents instance name -- a string of length + less than MAX_INSTANCE_NAME_SIZE. + + Generally, this is just a string with self-memory-management and should be + eliminated in the future. +*/ + +class Instance_name +{ +public: + Instance_name(const LEX_STRING *name); + +public: + inline const LEX_STRING *get_str() const + { + return &str; + } + + inline const char *get_c_str() const + { + return str.str; + } + + inline uint get_length() const + { + return str.length; + } + +private: + LEX_STRING str; + char str_buffer[MAX_INSTANCE_NAME_SIZE]; +}; + + class Instance { public: + /* + The following two constants defines name of the default mysqld-instance + ("mysqld"). + */ + static const LEX_STRING DFLT_INSTANCE_NAME; + +public: + /* + The operation is intended to check whether string is a well-formed + instance name or not. + */ + static bool is_name_valid(const LEX_STRING *name); + + /* + The operation is intended to check if the given instance name is + mysqld-compatible or not. + */ + static bool is_mysqld_compatible_name(const LEX_STRING *name); + +public: Instance(); ~Instance(); - int init(const char *name); + int init(const LEX_STRING *name_arg); int complete_initialization(Instance_map *instance_map_arg, - const char *mysqld_path, uint instance_type); + const char *mysqld_path); bool is_running(); int start(); int stop(); /* send a signal to the instance */ void kill_instance(int signo); - int is_crashed(); + bool is_crashed(); void set_crash_flag_n_wake_all(); Instance_map *get_map(); + /* + The operation is intended to check if the instance is mysqld-compatible + or not. + */ + inline bool is_mysqld_compatible() const; + + /* + The operation is intended to check if the instance is configured properly + or not. Misconfigured instances are not managed. + */ + inline bool is_configured() const; + + inline const LEX_STRING *get_name() const; + public: enum { DEFAULT_SHUTDOWN_DELAY= 35 }; Instance_options options; private: - int crashed; + /* This attributes is a flag, specifies if the instance has been crashed. */ + bool crashed; + + /* + This attribute specifies if the instance is configured properly or not. + Misconfigured instances are not managed. + */ + bool configured; + + /* + This attribute specifies whether the instance is mysqld-compatible or not. + Mysqld-compatible instances can contain only mysqld-specific options. + At the moment an instance is mysqld-compatible if its name is "mysqld". + + The idea is that [mysqld] section should contain only mysqld-specific + options (no Instance Manager-specific options) to be readable by mysqld + program. + */ + bool mysqld_compatible; + /* Mutex protecting the instance. Currently we use it to avoid the double start of the instance. This happens when the instance is starting @@ -66,4 +158,22 @@ private: void remove_pid(); }; + +inline bool Instance::is_mysqld_compatible() const +{ + return mysqld_compatible; +} + + +inline bool Instance::is_configured() const +{ + return configured; +} + + +inline const LEX_STRING *Instance::get_name() const +{ + return &options.instance_name; +} + #endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_INSTANCE_H */ diff --git a/server-tools/instance-manager/instance_map.cc b/server-tools/instance-manager/instance_map.cc index 543c9c31bfa..c9608fa7c14 100644 --- a/server-tools/instance-manager/instance_map.cc +++ b/server-tools/instance-manager/instance_map.cc @@ -20,14 +20,19 @@ #include "instance_map.h" +#include <my_global.h> +#include <m_ctype.h> +#include <mysql_com.h> + #include "buffer.h" +#include "guardian.h" #include "instance.h" #include "log.h" +#include "manager.h" +#include "mysqld_error.h" +#include "mysql_manager_error.h" #include "options.h" - -#include <m_ctype.h> -#include <mysql_com.h> -#include <m_string.h> +#include "priv.h" /* Note: As we are going to suppost different types of connections, @@ -45,8 +50,8 @@ static byte* get_instance_key(const byte* u, uint* len, my_bool __attribute__((unused)) t) { const Instance *instance= (const Instance *) u; - *len= instance->options.instance_name_len; - return (byte *) instance->options.instance_name; + *len= instance->options.instance_name.length; + return (byte *) instance->options.instance_name.str; } static void delete_instance(void *u) @@ -79,16 +84,60 @@ static void delete_instance(void *u) static int process_option(void *ctx, const char *group, const char *option) { - Instance_map *map= NULL; + Instance_map *map= (Instance_map*) ctx; + LEX_STRING group_str; - map = (Instance_map*) ctx; - return map->process_one_option(group, option); + group_str.str= (char *) group; + group_str.length= strlen(group); + + return map->process_one_option(&group_str, option); } C_MODE_END /* + Parse option string. + + SYNOPSIS + parse_option() + option_str [IN] option string (e.g. "--name=value") + option_name_buf [OUT] parsed name of the option. + Must be of (MAX_OPTION_LEN + 1) size. + option_value_buf [OUT] parsed value of the option. + Must be of (MAX_OPTION_LEN + 1) size. + + DESCRIPTION + This is an auxiliary function and should not be used externally. It is + intended to parse whole option string into option name and option value. +*/ + +static void parse_option(const char *option_str, + char *option_name_buf, + char *option_value_buf) +{ + const char *eq_pos; + const char *ptr= option_str; + + while (*ptr == '-') + ++ptr; + + strmake(option_name_buf, ptr, MAX_OPTION_LEN + 1); + + eq_pos= strchr(ptr, '='); + if (eq_pos) + { + option_name_buf[eq_pos - ptr]= 0; + strmake(option_value_buf, eq_pos + 1, MAX_OPTION_LEN + 1); + } + else + { + option_value_buf[0]= 0; + } +} + + +/* Process one option from the configuration file. SYNOPSIS @@ -103,34 +152,64 @@ C_MODE_END of the instance map object. */ -int Instance_map::process_one_option(const char *group, const char *option) +int Instance_map::process_one_option(const LEX_STRING *group, + const char *option) { Instance *instance= NULL; - static const char prefix[]= { 'm', 'y', 's', 'q', 'l', 'd' }; - if (strncmp(group, prefix, sizeof prefix) == 0 && - ((my_isdigit(default_charset_info, group[sizeof prefix])) - || group[sizeof(prefix)] == '\0')) + if (!Instance::is_name_valid(group)) + { + /* + Current section name is not a valid instance name. + We should skip it w/o error. + */ + return 0; + } + + if (!(instance= (Instance *) hash_search(&hash, (byte *) group->str, + group->length))) + { + if (!(instance= new Instance())) + return 1; + + if (instance->init(group) || add_instance(instance)) { - if (!(instance= (Instance *) hash_search(&hash, (byte *) group, - strlen(group)))) - { - if (!(instance= new Instance)) - goto err; - if (instance->init(group) || my_hash_insert(&hash, (byte *) instance)) - goto err_instance; - } - - if (instance->options.add_option(option)) - goto err; /* the instance'll be deleted when we destroy the map */ + delete instance; + return 1; } - return 0; + if (instance->is_mysqld_compatible()) + log_info("Warning: instance name '%s' is mysqld-compatible.", + (const char *) group->str); -err_instance: - delete instance; -err: - return 1; + log_info("mysqld instance '%s' has been added successfully.", + (const char *) group->str); + } + + if (option) + { + char option_name[MAX_OPTION_LEN + 1]; + char option_value[MAX_OPTION_LEN + 1]; + + parse_option(option, option_name, option_value); + + if (instance->is_mysqld_compatible() && + Instance_options::is_option_im_specific(option_name)) + { + log_info("Warning: configuration of mysqld-compatible instance '%s' " + "contains IM-specific option '%s'. " + "This breaks backward compatibility for the configuration file.", + (const char *) group->str, + (const char *) option_name); + } + + Named_value option(option_name, option_value); + + if (instance->options.set_option(&option)) + return 1; /* the instance'll be deleted when we destroy the map */ + } + + return 0; } @@ -181,7 +260,7 @@ void Instance_map::unlock() - pass on the new map to the guardian thread: it will start all instances that are marked `guarded' and not yet started. Note, as the check whether an instance is started is currently - very simple (returns true if there is a MySQL server running + very simple (returns TRUE if there is a MySQL server running at the given port), this function has some peculiar side-effects: * if the port number of a running instance was changed, the @@ -194,9 +273,9 @@ void Instance_map::unlock() In order to avoid such side effects one should never call FLUSH INSTANCES without prior stop of all running instances. - TODO - FLUSH INSTANCES should return an error if it's called - while there is a running instance. + NOTE: The operation should be invoked with the following locks acquired: + - Guardian_thread; + - Instance_map; */ int Instance_map::flush_instances() @@ -209,67 +288,169 @@ int Instance_map::flush_instances() guardian (2) reload the instance map (3) reinitialize the guardian with new instances. */ - guardian->lock(); - pthread_mutex_lock(&LOCK_instance_map); hash_free(&hash); hash_init(&hash, default_charset_info, START_HASH_SIZE, 0, 0, get_instance_key, delete_instance, 0); + rc= load(); guardian->init(); - pthread_mutex_unlock(&LOCK_instance_map); - guardian->unlock(); return rc; } -Instance * -Instance_map::find(const char *name, uint name_len) +bool Instance_map::is_there_active_instance() { Instance *instance; - pthread_mutex_lock(&LOCK_instance_map); - instance= (Instance *) hash_search(&hash, (byte *) name, name_len); - pthread_mutex_unlock(&LOCK_instance_map); - return instance; + Iterator iterator(this); + + while ((instance= iterator.next())) + { + if (guardian->find_instance_node(instance) != NULL || + instance->is_running()) + { + return TRUE; + } + } + + return FALSE; } -int Instance_map::complete_initialization() +int Instance_map::add_instance(Instance *instance) { - Instance *instance; - uint i= 0; + return my_hash_insert(&hash, (byte *) instance); +} - if (hash.records == 0) /* no instances found */ - { - if ((instance= new Instance) == 0) - goto err; +int Instance_map::remove_instance(Instance *instance) +{ + return hash_delete(&hash, (byte *) instance); +} - if (instance->init("mysqld") || my_hash_insert(&hash, (byte *) instance)) - goto err_instance; - /* - After an instance have been added to the instance_map, - hash_free should handle it's deletion => goto err, not - err_instance. - */ - if (instance->complete_initialization(this, mysqld_path, - DEFAULT_SINGLE_INSTANCE)) - goto err; +int Instance_map::create_instance(const LEX_STRING *instance_name, + const Named_value_arr *options) +{ + Instance *instance= new Instance(); + + if (!instance) + { + log_error("Error: can not initialize (name: '%s').", + (const char *) instance_name->str); + return ER_OUT_OF_RESOURCES; } - else - while (i < hash.records) + + if (instance->init(instance_name)) + { + log_error("Error: can not initialize (name: '%s').", + (const char *) instance_name->str); + delete instance; + return ER_OUT_OF_RESOURCES; + } + + for (int i= 0; options && i < options->get_size(); ++i) + { + Named_value option= options->get_element(i); + + if (instance->is_mysqld_compatible() && + Instance_options::is_option_im_specific(option.get_name())) { - instance= (Instance *) hash_element(&hash, i); - if (instance->complete_initialization(this, mysqld_path, USUAL_INSTANCE)) - goto err; - i++; + log_error("Error: IM-option (%s) can not be used " + "in configuration of mysqld-compatible instance (%s).", + (const char *) option.get_name(), + (const char *) instance_name->str); + delete instance; + return ER_INCOMPATIBLE_OPTION; } + instance->options.set_option(&option); + } + + if (instance->is_mysqld_compatible()) + log_info("Warning: instance name '%s' is mysqld-compatible.", + (const char *) instance_name->str); + + if (instance->complete_initialization(this, mysqld_path)) + { + log_error("Error: can not complete initialization of instance (name: '%s').", + (const char *) instance_name->str); + delete instance; + return ER_OUT_OF_RESOURCES; + /* TODO: return more appropriate error code in this case. */ + } + + if (add_instance(instance)) + { + log_error("Error: can not register instance (name: '%s').", + (const char *) instance_name->str); + delete instance; + return ER_OUT_OF_RESOURCES; + } + return 0; -err_instance: - delete instance; -err: - return 1; +} + + +Instance * Instance_map::find(const LEX_STRING *name) +{ + return (Instance *) hash_search(&hash, (byte *) name->str, name->length); +} + + +bool Instance_map::complete_initialization() +{ + bool mysqld_found; + + /* Complete initialization of all registered instances. */ + + for (uint i= 0; i < hash.records; ++i) + { + Instance *instance= (Instance *) hash_element(&hash, i); + + if (instance->complete_initialization(this, mysqld_path)) + return TRUE; + } + + /* That's all if we are runnning in an ordinary mode. */ + + if (!Options::Main::mysqld_safe_compatible) + return FALSE; + + /* In mysqld-compatible mode we must ensure that there 'mysqld' instance. */ + + mysqld_found= find(&Instance::DFLT_INSTANCE_NAME) != NULL; + + if (mysqld_found) + return FALSE; + + if (create_instance(&Instance::DFLT_INSTANCE_NAME, NULL)) + { + log_error("Error: could not create default instance."); + return TRUE; + } + + switch (create_instance_in_file(&Instance::DFLT_INSTANCE_NAME, NULL)) + { + case 0: + case ER_CONF_FILE_DOES_NOT_EXIST: + /* + Continue if the instance has been added to the config file + successfully, or the config file just does not exist. + */ + break; + + default: + log_error("Error: could not add default instance to the config file."); + + Instance *instance= find(&Instance::DFLT_INSTANCE_NAME); + + if (instance) + remove_instance(instance); /* instance is deleted here. */ + + return TRUE; + } + + return FALSE; } @@ -297,10 +478,10 @@ int Instance_map::load() name and start looking for files named "my.cnf.cnf" in all default dirs. Which is not what we want. */ - if (Options::is_forced_default_file) + if (Options::Main::is_forced_default_file) { snprintf(defaults_file_arg, FN_REFLEN, "--defaults-file=%s", - Options::config_file); + Options::Main::config_file); argv_options[1]= defaults_file_arg; argv_options[2]= '\0'; @@ -314,15 +495,12 @@ int Instance_map::load() If the routine failed, we'll simply fallback to defaults in complete_initialization(). */ - if (my_search_option_files(Options::config_file, &argc, + if (my_search_option_files(Options::Main::config_file, &argc, (char ***) &argv, &args_used, process_option, (void*) this)) log_info("Falling back to compiled-in defaults"); - if (complete_initialization()) - return 1; - - return 0; + return complete_initialization(); } @@ -343,3 +521,105 @@ Instance *Instance_map::Iterator::next() return NULL; } + +const char *Instance_map::get_instance_state_name(Instance *instance) +{ + LIST *instance_node; + + if (!instance->is_configured()) + return "misconfigured"; + + if ((instance_node= guardian->find_instance_node(instance)) != NULL) + { + /* The instance is managed by Guardian: we can report precise state. */ + + return Guardian_thread::get_instance_state_name( + guardian->get_instance_state(instance_node)); + } + + /* The instance is not managed by Guardian: we can report status only. */ + + return instance->is_running() ? "online" : "offline"; +} + + +/* + Create a new configuration section for mysqld-instance in the config file. + + SYNOPSYS + create_instance_in_file() + instance_name mysqld-instance name + options options for the new mysqld-instance + + RETURN + 0 On success + ER_CONF_FILE_DOES_NOT_EXIST If config file does not exist + ER_ACCESS_OPTION_FILE If config file is not writable or some I/O + error ocurred during writing configuration +*/ + +int create_instance_in_file(const LEX_STRING *instance_name, + const Named_value_arr *options) +{ + File cnf_file; + + if (my_access(Options::Main::config_file, W_OK)) + { + log_error("Error: configuration file (%s) does not exist.", + (const char *) Options::Main::config_file); + return ER_CONF_FILE_DOES_NOT_EXIST; + } + + cnf_file= my_open(Options::Main::config_file, O_WRONLY | O_APPEND, MYF(0)); + + if (cnf_file <= 0) + { + log_error("Error: can not open configuration file (%s): %s.", + (const char *) Options::Main::config_file, + (const char *) strerror(errno)); + return ER_ACCESS_OPTION_FILE; + } + + if (my_write(cnf_file, (byte*)NEWLINE, NEWLINE_LEN, MYF(MY_NABP)) || + my_write(cnf_file, (byte*)"[", 1, MYF(MY_NABP)) || + my_write(cnf_file, (byte*)instance_name->str, instance_name->length, + MYF(MY_NABP)) || + my_write(cnf_file, (byte*)"]", 1, MYF(MY_NABP)) || + my_write(cnf_file, (byte*)NEWLINE, NEWLINE_LEN, MYF(MY_NABP))) + { + log_error("Error: can not write to configuration file (%s): %s.", + (const char *) Options::Main::config_file, + (const char *) strerror(errno)); + my_close(cnf_file, MYF(0)); + return ER_ACCESS_OPTION_FILE; + } + + for (int i= 0; options && i < options->get_size(); ++i) + { + char option_str[MAX_OPTION_STR_LEN]; + char *ptr; + int option_str_len; + Named_value option= options->get_element(i); + + ptr= strxnmov(option_str, MAX_OPTION_LEN + 1, option.get_name(), NullS); + + if (option.get_value()[0]) + ptr= strxnmov(ptr, MAX_OPTION_LEN + 2, "=", option.get_value(), NullS); + + option_str_len= ptr - option_str; + + if (my_write(cnf_file, (byte*)option_str, option_str_len, MYF(MY_NABP)) || + my_write(cnf_file, (byte*)NEWLINE, NEWLINE_LEN, MYF(MY_NABP))) + { + log_error("Error: can not write to configuration file (%s): %s.", + (const char *) Options::Main::config_file, + (const char *) strerror(errno)); + my_close(cnf_file, MYF(0)); + return ER_ACCESS_OPTION_FILE; + } + } + + my_close(cnf_file, MYF(0)); + + return 0; +} diff --git a/server-tools/instance-manager/instance_map.h b/server-tools/instance-manager/instance_map.h index d3de42f4d80..8e6d2360652 100644 --- a/server-tools/instance-manager/instance_map.h +++ b/server-tools/instance-manager/instance_map.h @@ -17,21 +17,24 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <my_global.h> - -#include "protocol.h" -#include "guardian.h" - #include <my_sys.h> +#include <m_string.h> #include <hash.h> #if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE) #pragma interface #endif +class Guardian_thread; class Instance; +class Named_value_arr; + extern int load_all_groups(char ***groups, const char *filename); extern void free_groups(char **groups); +extern int create_instance_in_file(const LEX_STRING *instance_name, + const Named_value_arr *options); + /* Instance_map - stores all existing instances @@ -56,22 +59,64 @@ public: }; friend class Iterator; public: - /* returns a pointer to the instance or NULL, if there is no such instance */ - Instance *find(const char *name, uint name_len); + /* + Return a pointer to the instance or NULL, if there is no such instance. + MT-NOTE: must be called under acquired lock. + */ + Instance *find(const LEX_STRING *name); + /* Clear the configuration cache and reload the configuration file. */ int flush_instances(); + + /* The operation is used to check if there is an active instance or not. */ + bool is_there_active_instance(); + void lock(); void unlock(); + int init(); + /* Process a given option and assign it to appropricate instance. This is required for the option handler, passed to my_search_option_files(). */ - int process_one_option(const char *group, const char *option); + int process_one_option(const LEX_STRING *group, const char *option); + + /* + Add an instance into the internal hash. + + MT-NOTE: the operation must be called under acquired lock. + */ + int add_instance(Instance *instance); + + /* + Remove instance from the internal hash. + + MT-NOTE: the operation must be called under acquired lock. + */ + int remove_instance(Instance *instance); + + /* + Create a new instance and register it in the internal hash. + + MT-NOTE: the operation must be called under acquired lock. + */ + int create_instance(const LEX_STRING *instance_name, + const Named_value_arr *options); Instance_map(const char *default_mysqld_path_arg); ~Instance_map(); + /* + Retrieve client state name of the given instance. + + MT-NOTE: the options must be called under acquired locks of the following + objects: + - Instance_map; + - Guardian_thread; + */ + const char *get_instance_state_name(Instance *instance); + public: const char *mysqld_path; Guardian_thread *guardian; @@ -80,7 +125,7 @@ private: /* loads options from config files */ int load(); /* inits instances argv's after all options have been loaded */ - int complete_initialization(); + bool complete_initialization(); private: enum { START_HASH_SIZE = 16 }; pthread_mutex_t LOCK_instance_map; diff --git a/server-tools/instance-manager/instance_options.cc b/server-tools/instance-manager/instance_options.cc index 8bbd362a15b..b05e40734b7 100644 --- a/server-tools/instance-manager/instance_options.cc +++ b/server-tools/instance-manager/instance_options.cc @@ -20,28 +20,24 @@ #include "instance_options.h" -#include "parse_output.h" -#include "buffer.h" -#include "log.h" - +#include <my_global.h> #include <my_sys.h> -#include <signal.h> #include <m_string.h> -#ifdef __WIN__ -#define NEWLINE_LEN 2 -#else -#define NEWLINE_LEN 1 -#endif +#include <signal.h> + +#include "buffer.h" +#include "instance.h" +#include "log.h" +#include "parse_output.h" +#include "priv.h" /* Create "mysqld ..." command in the buffer */ static inline int create_mysqld_command(Buffer *buf, - const char *mysqld_path_str, - uint mysqld_path_len, - const char *option, - uint option_len) + const LEX_STRING *mysqld_path, + const LEX_STRING *option) { int position= 0; @@ -50,13 +46,13 @@ static inline int create_mysqld_command(Buffer *buf, #ifdef __WIN__ buf->append(position++, "\"", 1); #endif - buf->append(position, mysqld_path_str, mysqld_path_len); - position+= mysqld_path_len; + buf->append(position, mysqld_path->str, mysqld_path->length); + position+= mysqld_path->length; #ifdef __WIN__ buf->append(position++, "\"", 1); #endif /* here the '\0' character is copied from the option string */ - buf->append(position, option, option_len); + buf->append(position, option->str, option->length + 1); return buf->is_error(); } @@ -64,6 +60,42 @@ static inline int create_mysqld_command(Buffer *buf, } +bool Instance_options::is_option_im_specific(const char *option_name) +{ + static const char *IM_SPECIFIC_OPTIONS[] = + { + "nonguarded", + "mysqld-path", + "shutdown-delay", + NULL + }; + + for (int i= 0; IM_SPECIFIC_OPTIONS[i]; ++i) + { + if (!strcmp(option_name, IM_SPECIFIC_OPTIONS[i])) + return TRUE; + } + + return FALSE; +} + + +Instance_options::Instance_options() + :mysqld_version(NULL), mysqld_socket(NULL), mysqld_datadir(NULL), + mysqld_pid_file(NULL), mysqld_port(NULL), mysqld_port_val(0), + nonguarded(NULL), shutdown_delay(NULL), shutdown_delay_val(0), + filled_default_options(0) +{ + mysqld_path.str= NULL; + mysqld_path.length= 0; + + mysqld_real_path.str= NULL; + mysqld_real_path.length= 0; + + memset(logs, 0, sizeof(logs)); +} + + /* Get compiled-in value of default_option @@ -87,13 +119,13 @@ int Instance_options::get_default_option(char *result, size_t result_len, const char *option_name) { int rc= 1; - char verbose_option[]= " --no-defaults --verbose --help"; + LEX_STRING verbose_option= + { C_STRING_WITH_SIZE(" --no-defaults --verbose --help") }; - /* reserve space fot the path + option + final '\0' */ - Buffer cmd(mysqld_path_len + sizeof(verbose_option)); + /* reserve space for the path + option + final '\0' */ + Buffer cmd(mysqld_path.length + verbose_option.length + 1); - if (create_mysqld_command(&cmd, mysqld_path, mysqld_path_len, - verbose_option, sizeof(verbose_option))) + if (create_mysqld_command(&cmd, &mysqld_path, &verbose_option)) goto err; /* +2 eats first "--" from the option string (E.g. "--datadir") */ @@ -121,21 +153,19 @@ err: int Instance_options::fill_instance_version() { - enum { MAX_VERSION_STRING_LENGTH= 160 }; - char result[MAX_VERSION_STRING_LENGTH]; - char version_option[]= " --no-defaults --version"; + char result[MAX_VERSION_LENGTH]; + LEX_STRING version_option= + { C_STRING_WITH_SIZE(" --no-defaults --version") }; int rc= 1; - Buffer cmd(mysqld_path_len + sizeof(version_option)); + Buffer cmd(mysqld_path.length + version_option.length + 1); - if (create_mysqld_command(&cmd, mysqld_path, mysqld_path_len, - version_option, sizeof(version_option))) + if (create_mysqld_command(&cmd, &mysqld_path, &version_option)) goto err; - bzero(result, MAX_VERSION_STRING_LENGTH); + bzero(result, MAX_VERSION_LENGTH); - rc= parse_output_and_get_value(cmd.buffer, "Ver", - result, MAX_VERSION_STRING_LENGTH, - GET_LINE); + rc= parse_output_and_get_value(cmd.buffer, "Ver", result, + MAX_VERSION_LENGTH, GET_LINE); if (*result != '\0') { @@ -146,6 +176,7 @@ int Instance_options::fill_instance_version() start= result; while (my_isspace(default_charset_info, *start)) ++start; + mysqld_version= strdup_root(&alloc, start); } err: @@ -178,12 +209,12 @@ err: int Instance_options::fill_mysqld_real_path() { char result[FN_REFLEN]; - char help_option[]= " --no-defaults --help"; + LEX_STRING help_option= + { C_STRING_WITH_SIZE(" --no-defaults --help") }; int rc= 1; - Buffer cmd(mysqld_path_len + sizeof(help_option)); + Buffer cmd(mysqld_path.length + help_option.length); - if (create_mysqld_command(&cmd, mysqld_path, mysqld_path_len, - help_option, sizeof(help_option))) + if (create_mysqld_command(&cmd, &mysqld_path, &help_option)) goto err; bzero(result, FN_REFLEN); @@ -198,7 +229,8 @@ int Instance_options::fill_mysqld_real_path() /* chop the path of at [OPTIONS] */ if ((options_str= strstr(result, "[OPTIONS]"))) *options_str= '\0'; - mysqld_real_path= strdup_root(&alloc, result); + mysqld_real_path.str= strdup_root(&alloc, result); + mysqld_real_path.length= strlen(mysqld_real_path.str); } err: if (rc) @@ -255,8 +287,7 @@ int Instance_options::fill_log_options() else { /* below is safe, as --datadir always has a value */ - strmake(datadir, - strchr(mysqld_datadir, '=') + 1, MAX_LOG_OPTION_LENGTH - 1); + strmake(datadir, mysqld_datadir, MAX_LOG_OPTION_LENGTH - 1); } if (gethostname(hostname,sizeof(hostname)-1) < 0) @@ -342,7 +373,6 @@ err: int Instance_options::get_pid_filename(char *result) { - const char *pid_file= mysqld_pid_file; char datadir[MAX_PATH_LEN]; if (mysqld_datadir == NULL) @@ -352,14 +382,10 @@ int Instance_options::get_pid_filename(char *result) return 1; } else - strxnmov(datadir, MAX_PATH_LEN - 1, strchr(mysqld_datadir, '=') + 1, - "/", NullS); - - DBUG_ASSERT(mysqld_pid_file); - pid_file= strchr(pid_file, '=') + 1; + strxnmov(datadir, MAX_PATH_LEN - 1, mysqld_datadir, "/", NullS); /* get the full path to the pidfile */ - my_load_path(result, pid_file, datadir); + my_load_path(result, mysqld_pid_file, datadir); return 0; } @@ -388,23 +414,23 @@ pid_t Instance_options::get_pid() } -int Instance_options::complete_initialization(const char *default_path, - uint instance_type) +int Instance_options::complete_initialization(const char *default_path) { + int arg_idx; const char *tmp; char *end; - if (!mysqld_path && !(mysqld_path= strdup_root(&alloc, default_path))) + if (!mysqld_path.str && !(mysqld_path.str= strdup_root(&alloc, default_path))) goto err; // it's safe to cast this to char* since this is a buffer we are allocating - end= convert_dirname((char*)mysqld_path, mysqld_path, NullS); + end= convert_dirname((char*)mysqld_path.str, mysqld_path.str, NullS); end[-1]= 0; - mysqld_path_len= strlen(mysqld_path); + mysqld_path.length= strlen(mysqld_path.str); if (mysqld_port) - mysqld_port_val= atoi(strchr(mysqld_port, '=') + 1); + mysqld_port_val= atoi(mysqld_port); if (shutdown_delay) shutdown_delay_val= atoi(shutdown_delay); @@ -412,7 +438,7 @@ int Instance_options::complete_initialization(const char *default_path, if (!(tmp= strdup_root(&alloc, "--no-defaults"))) goto err; - if (!(mysqld_pid_file)) + if (!mysqld_pid_file) { char pidfilename[MAX_PATH_LEN]; char hostname[MAX_PATH_LEN]; @@ -421,26 +447,27 @@ int Instance_options::complete_initialization(const char *default_path, If we created only one istance [mysqld], because no config. files were found, we would like to model mysqld pid file values. */ + if (!gethostname(hostname, sizeof(hostname) - 1)) { - if (instance_type & DEFAULT_SINGLE_INSTANCE) - strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", hostname, - ".pid", NullS); + if (Instance::is_mysqld_compatible_name(&instance_name)) + strxnmov(pidfilename, MAX_PATH_LEN - 1, hostname, ".pid", NullS); else - strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", instance_name, - "-", hostname, ".pid", NullS); + strxnmov(pidfilename, MAX_PATH_LEN - 1, instance_name.str, "-", + hostname, ".pid", NullS); } else { - if (instance_type & DEFAULT_SINGLE_INSTANCE) - strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", "mysql", - ".pid", NullS); + if (Instance::is_mysqld_compatible_name(&instance_name)) + strxnmov(pidfilename, MAX_PATH_LEN - 1, "mysql", ".pid", NullS); else - strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", instance_name, - ".pid", NullS); + strxnmov(pidfilename, MAX_PATH_LEN - 1, instance_name.str, ".pid", + NullS); } - add_option(pidfilename); + Named_value option((char *) "pid-file", pidfilename); + + set_option(&option); } if (get_pid_filename(pid_file_with_path)) @@ -448,20 +475,37 @@ int Instance_options::complete_initialization(const char *default_path, /* we need to reserve space for the final zero + possible default options */ if (!(argv= (char**) - alloc_root(&alloc, (options_array.elements + 1 + alloc_root(&alloc, (get_num_options() + 1 + MAX_NUMBER_OF_DEFAULT_OPTIONS) * sizeof(char*)))) goto err; + filled_default_options= 0; /* the path must be first in the argv */ - if (add_to_argv(mysqld_path)) + if (add_to_argv(mysqld_path.str)) goto err; if (add_to_argv(tmp)) goto err; - memcpy((gptr) (argv + filled_default_options), options_array.buffer, - options_array.elements*sizeof(char*)); - argv[filled_default_options + options_array.elements]= 0; + arg_idx= filled_default_options; + for (int opt_idx= 0; opt_idx < get_num_options(); ++opt_idx) + { + char option_str[MAX_OPTION_STR_LEN]; + Named_value option= get_option(opt_idx); + + if (is_option_im_specific(option.get_name())) + continue; + + char *ptr= strxnmov(option_str, MAX_OPTION_LEN + 3, "--", option.get_name(), + NullS); + + if (option.get_value()[0]) + strxnmov(ptr, MAX_OPTION_LEN + 2, "=", option.get_value(), NullS); + + argv[arg_idx++]= strdup_root(&alloc, option_str); + } + + argv[arg_idx]= 0; if (fill_log_options() || fill_mysqld_real_path() || fill_instance_version()) goto err; @@ -473,75 +517,91 @@ err: } -/* - Assigns given value to the appropriate option from the class. +bool Instance_options::set_option(Named_value *option) +{ + bool err_status; + int idx= find_option(option->get_name()); + char *option_name_str; + char *option_value_str; - SYNOPSYS - add_option() - option string with the option prefixed by -- + if (!(option_name_str= Named_value::alloc_str(option->get_name()))) + return TRUE; - DESCRIPTION + if (!(option_value_str= Named_value::alloc_str(option->get_value()))) + { + Named_value::free_str(&option_name_str); + return TRUE; + } - The method is called from the option handling routine. + Named_value option_copy(option_name_str, option_value_str); - RETURN - 0 - ok - 1 - error occured -*/ + if (idx < 0) + err_status= options.add_element(&option_copy); + else + err_status= options.replace_element(idx, &option_copy); + + if (!err_status) + update_var(option_copy.get_name(), option_copy.get_value()); + else + option_copy.free(); + + return err_status; +} -int Instance_options::add_option(const char* option) + +void Instance_options::unset_option(const char *option_name) { - char *tmp; - enum { SAVE_VALUE= 1, SAVE_WHOLE, SAVE_WHOLE_AND_ADD }; - struct selected_options_st + int idx= find_option(option_name); + + if (idx < 0) + return; /* the option has not been set. */ + + options.remove_element(idx); + + update_var(option_name, NULL); +} + + +void Instance_options::update_var(const char *option_name, + const char *option_value) +{ + struct options_st { const char *name; - uint length; - const char **value; - uint type; - } options[]= + uint name_len; + const char **var; + } options_def[]= { - {"--socket=", 9, &mysqld_socket, SAVE_WHOLE_AND_ADD}, - {"--port=", 7, &mysqld_port, SAVE_WHOLE_AND_ADD}, - {"--datadir=", 10, &mysqld_datadir, SAVE_WHOLE_AND_ADD}, - {"--bind-address=", 15, &mysqld_bind_address, SAVE_WHOLE_AND_ADD}, - {"--pid-file=", 11, &mysqld_pid_file, SAVE_WHOLE_AND_ADD}, - {"--mysqld-path=", 14, &mysqld_path, SAVE_VALUE}, - {"--nonguarded", 9, &nonguarded, SAVE_WHOLE}, - {"--shutdown_delay", 9, &shutdown_delay, SAVE_VALUE}, - {NULL, 0, NULL, 0} + {"socket", 6, &mysqld_socket}, + {"port", 4, &mysqld_port}, + {"datadir", 7, &mysqld_datadir}, + {"pid-file", 8, &mysqld_pid_file}, + {"nonguarded", 10, &nonguarded}, + {"mysqld-path", 11, (const char **) &mysqld_path.str}, + {"shutdown-delay", 14, &shutdown_delay}, + {NULL, 0, NULL} }; - struct selected_options_st *selected_options; - if (!(tmp= strdup_root(&alloc, option))) - goto err; + for (options_st *opt= options_def; opt->name; ++opt) + { + if (!strncmp(opt->name, option_name, opt->name_len)) + { + *(opt->var)= option_value; + break; + } + } +} - for (selected_options= options; selected_options->name; selected_options++) - { - if (strncmp(tmp, selected_options->name, selected_options->length) == 0) - switch (selected_options->type) { - case SAVE_WHOLE_AND_ADD: - *(selected_options->value)= tmp; - insert_dynamic(&options_array,(gptr) &tmp); - return 0; - case SAVE_VALUE: - *(selected_options->value)= strchr(tmp, '=') + 1; - return 0; - case SAVE_WHOLE: - *(selected_options->value)= tmp; - return 0; - default: - break; - } - } - - /* if we haven't returned earlier we should just save the option */ - insert_dynamic(&options_array,(gptr) &tmp); - return 0; +int Instance_options::find_option(const char *option_name) +{ + for (int i= 0; i < get_num_options(); i++) + { + if (!strcmp(get_option(i).get_name(), option_name)) + return i; + } -err: - return 1; + return -1; } @@ -559,7 +619,10 @@ int Instance_options::add_to_argv(const char* option) void Instance_options::print_argv() { int i; - printf("printing out an instance %s argv:\n", instance_name); + + printf("printing out an instance %s argv:\n", + (const char *) instance_name.str); + for (i=0; argv[i] != NULL; i++) printf("argv: %s\n", argv[i]); } @@ -570,17 +633,17 @@ void Instance_options::print_argv() Return value: 0 - ok. 1 - unable to allocate memory. */ -int Instance_options::init(const char *instance_name_arg) +int Instance_options::init(const LEX_STRING *instance_name_arg) { - instance_name_len= strlen(instance_name_arg); + instance_name.length= instance_name_arg->length; init_alloc_root(&alloc, MEM_ROOT_BLOCK_SIZE, 0); - if (my_init_dynamic_array(&options_array, sizeof(char*), 0, 32)) + if (options.init()) goto err; - if (!(instance_name= strmake_root(&alloc, (char*) instance_name_arg, - instance_name_len))) + if (!(instance_name.str= strmake_root(&alloc, instance_name_arg->str, + instance_name_arg->length))) goto err; return 0; @@ -593,6 +656,4 @@ err: Instance_options::~Instance_options() { free_root(&alloc, MYF(0)); - delete_dynamic(&options_array); } - diff --git a/server-tools/instance-manager/instance_options.h b/server-tools/instance-manager/instance_options.h index b316dbf00fc..c3b0a16a40d 100644 --- a/server-tools/instance-manager/instance_options.h +++ b/server-tools/instance-manager/instance_options.h @@ -18,8 +18,9 @@ #include <my_global.h> #include <my_sys.h> + #include "parse.h" -#include "portability.h" +#include "portability.h" /* for pid_t on Win32 */ #if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE) #pragma interface @@ -35,25 +36,26 @@ don't have to synchronize between threads. */ -#define USUAL_INSTANCE 0 -#define DEFAULT_SINGLE_INSTANCE 1 - class Instance_options { public: - Instance_options() : - mysqld_version(0), mysqld_socket(0), mysqld_datadir(0), - mysqld_bind_address(0), mysqld_pid_file(0), mysqld_port(0), - mysqld_port_val(0), mysqld_path(0), mysqld_real_path(0), - nonguarded(0), shutdown_delay(0), - shutdown_delay_val(0), filled_default_options(0) - {} + /* The operation is used to check if the option is IM-specific or not. */ + static bool is_option_im_specific(const char *option_name); + +public: + Instance_options(); ~Instance_options(); /* fills in argv */ - int complete_initialization(const char *default_path, uint instance_type); + int complete_initialization(const char *default_path); - int add_option(const char* option); - int init(const char *instance_name_arg); + bool set_option(Named_value *option); + void unset_option(const char *option_name); + + inline int get_num_options() const; + inline Named_value get_option(int idx) const; + +public: + int init(const LEX_STRING *instance_name_arg); pid_t get_pid(); int get_pid_filename(char *result); int unlink_pidfile(); @@ -66,7 +68,6 @@ public: */ enum { MAX_PATH_LEN= 512 }; enum { MAX_NUMBER_OF_DEFAULT_OPTIONS= 2 }; - enum { MEM_ROOT_BLOCK_SIZE= 512 }; char pid_file_with_path[MAX_PATH_LEN]; char **argv; /* @@ -77,23 +78,18 @@ public: /* We need the some options, so we store them as a separate pointers */ const char *mysqld_socket; const char *mysqld_datadir; - const char *mysqld_bind_address; const char *mysqld_pid_file; const char *mysqld_port; uint mysqld_port_val; - const char *instance_name; - uint instance_name_len; - const char *mysqld_path; - uint mysqld_path_len; - const char *mysqld_real_path; + LEX_STRING instance_name; + LEX_STRING mysqld_path; + LEX_STRING mysqld_real_path; const char *nonguarded; const char *shutdown_delay; uint shutdown_delay_val; /* log enums are defined in parse.h */ char *logs[3]; - /* this value is computed and cashed here */ - DYNAMIC_ARRAY options_array; private: int fill_log_options(); int fill_instance_version(); @@ -101,9 +97,27 @@ private: int add_to_argv(const char *option); int get_default_option(char *result, size_t result_len, const char *option_name); + + void update_var(const char *option_name, const char *option_value); + int find_option(const char *option_name); + private: uint filled_default_options; MEM_ROOT alloc; + + Named_value_arr options; }; + +inline int Instance_options::get_num_options() const +{ + return options.get_size(); +} + + +inline Named_value Instance_options::get_option(int idx) const +{ + return options.get_element(idx); +} + #endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_INSTANCE_OPTIONS_H */ diff --git a/server-tools/instance-manager/listener.cc b/server-tools/instance-manager/listener.cc index 500b25bec03..da9338e28c5 100644 --- a/server-tools/instance-manager/listener.cc +++ b/server-tools/instance-manager/listener.cc @@ -19,21 +19,23 @@ #endif #include "listener.h" -#include "priv.h" -#include <m_string.h> + +#include <my_global.h> #include <mysql.h> #include <violite.h> + +#include <sys/stat.h> #ifndef __WIN__ #include <sys/un.h> #endif -#include <sys/stat.h> -#include "thread_registry.h" -#include "options.h" #include "instance_map.h" #include "log.h" #include "mysql_connection.h" +#include "options.h" #include "portability.h" +#include "priv.h" +#include "thread_registry.h" /* @@ -62,8 +64,7 @@ private: Listener_thread::Listener_thread(const Listener_thread_args &args) : - Listener_thread_args(args.thread_registry, args.options, args.user_map, - args.instance_map) + Listener_thread_args(args.thread_registry, args.user_map, args.instance_map) ,total_connection_count(0) ,thread_info(pthread_self()) ,num_sockets(0) @@ -234,14 +235,16 @@ int Listener_thread::create_tcp_socket() bzero(&ip_socket_address, sizeof(ip_socket_address)); ulong im_bind_addr; - if (options.bind_address != 0) + if (Options::Main::bind_address != 0) { - if ((im_bind_addr= (ulong) inet_addr(options.bind_address)) == INADDR_NONE) + im_bind_addr= (ulong) inet_addr(Options::Main::bind_address); + + if (im_bind_addr == INADDR_NONE) im_bind_addr= htonl(INADDR_ANY); } else im_bind_addr= htonl(INADDR_ANY); - uint im_port= options.port_number; + uint im_port= Options::Main::port_number; ip_socket_address.sin_family= AF_INET; ip_socket_address.sin_addr.s_addr= im_bind_addr; @@ -295,7 +298,7 @@ create_unix_socket(struct sockaddr_un &unix_socket_address) bzero(&unix_socket_address, sizeof(unix_socket_address)); unix_socket_address.sun_family= AF_UNIX; - strmake(unix_socket_address.sun_path, options.socket_file_name, + strmake(unix_socket_address.sun_path, Options::Main::socket_file_name, sizeof(unix_socket_address.sun_path)); unlink(unix_socket_address.sun_path); // in case we have stale socket file diff --git a/server-tools/instance-manager/listener.h b/server-tools/instance-manager/listener.h index 28ccbf91731..c28ab0649d7 100644 --- a/server-tools/instance-manager/listener.h +++ b/server-tools/instance-manager/listener.h @@ -27,23 +27,19 @@ pthread_handler_t listener(void *arg); class Thread_registry; -struct Options; class User_map; class Instance_map; struct Listener_thread_args { Thread_registry &thread_registry; - const Options &options; const User_map &user_map; Instance_map &instance_map; Listener_thread_args(Thread_registry &thread_registry_arg, - const Options &options_arg, const User_map &user_map_arg, Instance_map &instance_map_arg) : thread_registry(thread_registry_arg) - ,options(options_arg) ,user_map(user_map_arg) ,instance_map(instance_map_arg) {} diff --git a/server-tools/instance-manager/log.cc b/server-tools/instance-manager/log.cc index 3f54bc0649a..a88344f0b91 100644 --- a/server-tools/instance-manager/log.cc +++ b/server-tools/instance-manager/log.cc @@ -14,14 +14,16 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <my_global.h> - #include "log.h" -#include "portability.h" -#include <stdarg.h> + +#include <my_global.h> #include <m_string.h> #include <my_sys.h> +#include <stdarg.h> + +#include "portability.h" /* for vsnprintf() on Windows. */ + /* TODO: - add flexible header support @@ -71,7 +73,7 @@ static inline void log(FILE *file, const char *format, va_list args) { int size= sizeof(buff_stack) * 2; buff_msg= (char*) my_malloc(size, MYF(0)); - while (true) + while (TRUE) { if (buff_msg == 0) { diff --git a/server-tools/instance-manager/manager.cc b/server-tools/instance-manager/manager.cc index 95f9029f648..599131089ed 100644 --- a/server-tools/instance-manager/manager.cc +++ b/server-tools/instance-manager/manager.cc @@ -14,39 +14,55 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <my_global.h> #include "manager.h" -#include "priv.h" -#include "thread_registry.h" -#include "listener.h" -#include "instance_map.h" -#include "options.h" -#include "user_map.h" -#include "log.h" -#include "guardian.h" - -#include <my_sys.h> +#include <my_global.h> #include <m_string.h> -#include <signal.h> +#include <my_sys.h> #include <thr_alarm.h> + +#include <signal.h> #ifndef __WIN__ #include <sys/wait.h> #endif +#include "exit_codes.h" +#include "guardian.h" +#include "instance_map.h" +#include "listener.h" +#include "log.h" +#include "options.h" +#include "priv.h" +#include "thread_registry.h" +#include "user_map.h" + -static int create_pid_file(const char *pid_file_name) +int create_pid_file(const char *pid_file_name, int pid) { - if (FILE *pid_file= my_fopen(pid_file_name, - O_WRONLY | O_CREAT | O_BINARY, MYF(0))) + FILE *pid_file; + + if (!(pid_file= my_fopen(pid_file_name, O_WRONLY | O_CREAT | O_BINARY, + MYF(0)))) + { + log_error("Error: can not create pid file '%s': %s (errno: %d)", + (const char *) pid_file_name, + (const char *) strerror(errno), + (int) errno); + return 1; + } + + if (fprintf(pid_file, "%d\n", (int) pid) <= 0) { - fprintf(pid_file, "%d\n", (int) getpid()); - my_fclose(pid_file, MYF(0)); - return 0; + log_error("Error: can not write to pid file '%s': %s (errno: %d)", + (const char *) pid_file_name, + (const char *) strerror(errno), + (int) errno); + return 1; } - log_error("can't create pid file %s: errno=%d, %s", - pid_file_name, errno, strerror(errno)); - return 1; + + my_fclose(pid_file, MYF(0)); + + return 0; } #ifndef __WIN__ @@ -82,14 +98,14 @@ bool have_signal; void onsignal(int signo) { - have_signal= true; + have_signal= TRUE; } void set_signals(sigset_t *set) { signal(SIGINT, onsignal); signal(SIGTERM, onsignal); - have_signal= false; + have_signal= FALSE; } int my_sigwait(const sigset_t *set, int *sig) @@ -109,10 +125,16 @@ int my_sigwait(const sigset_t *set, int *sig) listener thread, write pid file and enter into signal handling. See also comments in mysqlmanager.cc to picture general Instance Manager architecture. + + TODO: how about returning error status. */ -void manager(const Options &options) +void manager() { + int err_code; + const char *err_msg; + bool shutdown_complete= FALSE; + Thread_registry thread_registry; /* All objects created in the manager() function live as long as @@ -121,49 +143,61 @@ void manager(const Options &options) */ User_map user_map; - Instance_map instance_map(options.default_mysqld_path); + Instance_map instance_map(Options::Main::default_mysqld_path); Guardian_thread guardian_thread(thread_registry, &instance_map, - options.monitoring_interval); + Options::Main::monitoring_interval); - Listener_thread_args listener_args(thread_registry, options, user_map, - instance_map); + Listener_thread_args listener_args(thread_registry, user_map, instance_map); manager_pid= getpid(); instance_map.guardian= &guardian_thread; - if (instance_map.init() || user_map.init()) - return; + /* Initialize instance map. */ - if (user_map.load(options.password_file_name)) + if (instance_map.init()) + { + log_error("Error: can not initialize instance list: out of memory."); return; + } - /* write pid file */ - if (create_pid_file(options.pid_file_name)) - return; + /* Initialize user map and load password file. */ - sigset_t mask; - set_signals(&mask); + if (user_map.init()) + { + log_error("Error: can not initialize user list: out of memory."); + return; + } - /* create the listener */ + if ((err_code= user_map.load(Options::Main::password_file_name, &err_msg))) { - pthread_t listener_thd_id; - pthread_attr_t listener_thd_attr; - int rc; + if (err_code == ERR_PASSWORD_FILE_DOES_NOT_EXIST && + Options::Main::mysqld_safe_compatible) + { + /* + The password file does not exist, but we are running in + mysqld_safe-compatible mode. Continue, but complain in log. + */ - pthread_attr_init(&listener_thd_attr); - pthread_attr_setdetachstate(&listener_thd_attr, PTHREAD_CREATE_DETACHED); - rc= set_stacksize_n_create_thread(&listener_thd_id, &listener_thd_attr, - listener, &listener_args); - pthread_attr_destroy(&listener_thd_attr); - if (rc) + log_error("Warning: password file does not exist, " + "nobody will be able to connect to Instance Manager."); + } + else { - log_error("manager(): set_stacksize_n_create_thread(listener) failed"); - goto err; + log_error("Error: %s.", (const char *) err_msg); + return; } - } + /* write Instance Manager pid file */ + + log_info("IM pid file: '%s'; PID: %d.", + (const char *) Options::Main::pid_file_name, + (int) manager_pid); + + if (create_pid_file(Options::Main::pid_file_name, manager_pid)) + return; /* necessary logging has been already done. */ + /* create guardian thread */ { pthread_t guardian_thd_id; @@ -193,17 +227,46 @@ void manager(const Options &options) To work nicely with LinuxThreads, the signal thread is the first thread in the process. */ - int signo; - bool shutdown_complete; - shutdown_complete= FALSE; + { + instance_map.guardian->lock(); + instance_map.lock(); - if (instance_map.flush_instances()) + int flush_instances_status= instance_map.flush_instances(); + + instance_map.unlock(); + instance_map.guardian->unlock(); + + if (flush_instances_status) + { + log_error("Cannot init instances repository. This might be caused by " + "the wrong config file options. For instance, missing mysqld " + "binary. Aborting."); + return; + } + } + + /* Initialize signals and alarm-infrastructure. */ + + sigset_t mask; + set_signals(&mask); + + /* create the listener */ { - log_error("Cannot init instances repository. This might be caused by " - "the wrong config file options. For instance, missing mysqld " - "binary. Aborting."); - return; + pthread_t listener_thd_id; + pthread_attr_t listener_thd_attr; + int rc; + + pthread_attr_init(&listener_thd_attr); + pthread_attr_setdetachstate(&listener_thd_attr, PTHREAD_CREATE_DETACHED); + rc= set_stacksize_n_create_thread(&listener_thd_id, &listener_thd_attr, + listener, &listener_args); + pthread_attr_destroy(&listener_thd_attr); + if (rc) + { + log_error("manager(): set_stacksize_n_create_thread(listener) failed"); + goto err; + } } /* @@ -214,6 +277,7 @@ void manager(const Options &options) while (!shutdown_complete) { + int signo; int status= 0; if ((status= my_sigwait(&mask, &signo)) != 0) @@ -240,7 +304,7 @@ void manager(const Options &options) { if (!guardian_thread.is_stopped()) { - bool stop_instances= true; + bool stop_instances= TRUE; guardian_thread.request_shutdown(stop_instances); pthread_cond_signal(&guardian_thread.COND_guardian); } @@ -254,7 +318,7 @@ void manager(const Options &options) err: /* delete the pid file */ - my_delete(options.pid_file_name, MYF(0)); + my_delete(Options::Main::pid_file_name, MYF(0)); #ifndef __WIN__ /* free alarm structures */ @@ -262,4 +326,3 @@ err: /* don't pthread_exit to kill all threads who did not shut down in time */ #endif } - diff --git a/server-tools/instance-manager/manager.h b/server-tools/instance-manager/manager.h index 12ed6b3b1ff..7aa4b3e1a96 100644 --- a/server-tools/instance-manager/manager.h +++ b/server-tools/instance-manager/manager.h @@ -16,8 +16,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -struct Options; +void manager(); -void manager(const Options &options); +int create_pid_file(const char *pid_file_name, int pid); #endif // INCLUDES_MYSQL_INSTANCE_MANAGER_MANAGER_H diff --git a/server-tools/instance-manager/messages.cc b/server-tools/instance-manager/messages.cc index a9b00b9e01f..af35af1e7b0 100644 --- a/server-tools/instance-manager/messages.cc +++ b/server-tools/instance-manager/messages.cc @@ -14,15 +14,14 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <my_global.h> #include "messages.h" +#include <my_global.h> +#include <mysql_com.h> + #include "mysqld_error.h" #include "mysql_manager_error.h" -#include <mysql_com.h> -#include <assert.h> - static const char *mysqld_error_message(unsigned sql_errno) { @@ -70,6 +69,23 @@ static const char *mysqld_error_message(unsigned sql_errno) "in the instance options"; case ER_ACCESS_OPTION_FILE: return "Cannot open the option file to edit. Check permissions"; + case ER_DROP_ACTIVE_INSTANCE: + return "Cannot drop an active instance. You should stop it first"; + case ER_CREATE_EXISTING_INSTANCE: + return "Instance already exists"; + case ER_INSTANCE_MISCONFIGURED: + return "Instance is misconfigured. Cannot start it"; + case ER_MALFORMED_INSTANCE_NAME: + return "Malformed instance name."; + case ER_INSTANCE_IS_ACTIVE: + return "The instance is active. Stop the instance first"; + case ER_THERE_IS_ACTIVE_INSTACE: + return "At least one instance is active. Stop all instances first"; + case ER_INCOMPATIBLE_OPTION: + return "Instance Manager-specific options are prohibited from being used " + "in the configuration of mysqld-compatible instances"; + case ER_CONF_FILE_DOES_NOT_EXIST: + return "Configuration file does not exist"; default: DBUG_ASSERT(0); return 0; diff --git a/server-tools/instance-manager/mysql_connection.cc b/server-tools/instance-manager/mysql_connection.cc index dcd1807701f..17cda3af704 100644 --- a/server-tools/instance-manager/mysql_connection.cc +++ b/server-tools/instance-manager/mysql_connection.cc @@ -20,22 +20,24 @@ #include "mysql_connection.h" -#include "priv.h" -#include "mysql_manager_error.h" -#include "mysqld_error.h" -#include "thread_registry.h" +#include <m_string.h> +#include <m_string.h> +#include <my_global.h> +#include <mysql_com.h> +#include <mysql.h> +#include <my_sys.h> +#include <violite.h> + +#include "command.h" #include "log.h" -#include "user_map.h" -#include "protocol.h" #include "messages.h" -#include "command.h" +#include "mysqld_error.h" +#include "mysql_manager_error.h" #include "parse.h" - -#include <mysql.h> -#include <violite.h> -#include <mysql_com.h> -#include <m_string.h> -#include <my_sys.h> +#include "priv.h" +#include "protocol.h" +#include "thread_registry.h" +#include "user_map.h" Mysql_connection_thread_args::Mysql_connection_thread_args( @@ -56,7 +58,7 @@ Mysql_connection_thread_args::Mysql_connection_thread_args( See also comments in mysqlmanager.cc to picture general Instance Manager architecture. We use conventional technique to work with classes without exceptions: - class acquires all vital resource in init(); Thus if init() succeed, + class acquires all vital resource in init(); Thus if init() succeed, a user must call cleanup(). All other methods are valid only between init() and cleanup(). */ @@ -190,8 +192,6 @@ void Mysql_connection_thread::run() int Mysql_connection_thread::check_connection() { ulong pkt_len=0; // to hold client reply length - /* maximum size of the version string */ - enum { MAX_VERSION_LENGTH= 80 }; /* buffer for the first packet */ /* packet contains: */ char buff[MAX_VERSION_LENGTH + 1 + // server version, 0-ended @@ -202,8 +202,8 @@ int Mysql_connection_thread::check_connection() char *pos= buff; ulong server_flags; - memcpy(pos, mysqlmanager_version, mysqlmanager_version_length + 1); - pos+= mysqlmanager_version_length + 1; + memcpy(pos, mysqlmanager_version.str, mysqlmanager_version.length + 1); + pos+= mysqlmanager_version.length + 1; int4store((uchar*) pos, connection_id); pos+= 4; @@ -271,12 +271,14 @@ int Mysql_connection_thread::check_connection() const char *user= pos; const char *password= strend(user)+1; ulong password_len= *password++; + LEX_STRING user_name= { (char *) user, password - user - 2 }; + if (password_len != SCRAMBLE_LENGTH) { net_send_error(&net, ER_ACCESS_DENIED_ERROR); return 1; } - if (user_map.authenticate(user, password-user-2, password, scramble)) + if (user_map.authenticate(&user_name, password, scramble)) { net_send_error(&net, ER_ACCESS_DENIED_ERROR); return 1; @@ -312,7 +314,7 @@ int Mysql_connection_thread::do_command() packet= (char*) net.read_pos; enum enum_server_command command= (enum enum_server_command) (uchar) *packet; - log_info("connection %d: packet_length=%d, command=%d", + log_info("connection %d: packet_length=%d, command=%d", connection_id, packet_length, command); return dispatch_command(command, packet + 1, packet_length - 1); } @@ -336,7 +338,7 @@ int Mysql_connection_thread::dispatch_command(enum enum_server_command command, if (Command *command= parse_command(&instance_map, packet)) { int res= 0; - log_info("query for connection %d successefully parsed",connection_id); + log_info("query for connection %d successfully parsed",connection_id); res= command->execute(&net, connection_id); delete command; if (!res) @@ -380,5 +382,5 @@ pthread_handler_t mysql_connection(void *arg) } /* - vim: fdm=marker + vim: fdm=marker */ diff --git a/server-tools/instance-manager/mysql_manager_error.h b/server-tools/instance-manager/mysql_manager_error.h index ff782923a8e..373c7d798a0 100644 --- a/server-tools/instance-manager/mysql_manager_error.h +++ b/server-tools/instance-manager/mysql_manager_error.h @@ -29,5 +29,13 @@ #define ER_ACCESS_OPTION_FILE 3008 #define ER_OFFSET_ERROR 3009 #define ER_READ_FILE 3010 +#define ER_DROP_ACTIVE_INSTANCE 3011 +#define ER_CREATE_EXISTING_INSTANCE 3012 +#define ER_INSTANCE_MISCONFIGURED 3013 +#define ER_MALFORMED_INSTANCE_NAME 3014 +#define ER_INSTANCE_IS_ACTIVE 3015 +#define ER_THERE_IS_ACTIVE_INSTACE 3016 +#define ER_INCOMPATIBLE_OPTION 3017 +#define ER_CONF_FILE_DOES_NOT_EXIST 3018 #endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_MYSQL_MANAGER_ERROR_H */ diff --git a/server-tools/instance-manager/mysqlmanager.cc b/server-tools/instance-manager/mysqlmanager.cc index d0b2cf2666c..177b761b419 100644 --- a/server-tools/instance-manager/mysqlmanager.cc +++ b/server-tools/instance-manager/mysqlmanager.cc @@ -15,25 +15,30 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <my_global.h> -#include "manager.h" - -#include "options.h" -#include "log.h" - #include <my_sys.h> + #include <string.h> #include <signal.h> +#include <sys/types.h> +#include <sys/stat.h> + #ifndef __WIN__ #include <pwd.h> #include <grp.h> #include <sys/wait.h> #endif -#include <sys/types.h> -#include <sys/stat.h> + +#include "log.h" +#include "manager.h" +#include "options.h" +#include "user_management_commands.h" + #ifdef __WIN__ -#include "windowsservice.h" +#include "IMService.h" +#include "WindowsService.h" #endif + /* Few notes about Instance Manager architecture: Instance Manager consisits of two processes: the angel process, and the @@ -59,13 +64,12 @@ */ static void init_environment(char *progname); + #ifndef __WIN__ static void daemonize(const char *log_file_name); -static void angel(const Options &options); +static void angel(); static struct passwd *check_user(const char *user); static int set_user(const char *user, struct passwd *user_info); -#else -int HandleServiceOptions(Options options); #endif @@ -81,41 +85,61 @@ int main(int argc, char *argv[]) { int return_value= 1; init_environment(argv[0]); - Options options; - if (options.load(argc, argv)) - goto err; + if ((return_value= Options::load(argc, argv))) + goto main_end; + + if (Options::User_management::cmd) + { + return_value= Options::User_management::cmd->execute(); + + goto main_end; + } #ifndef __WIN__ + struct passwd *user_info; - if ((user_info= check_user(options.user))) + if ((user_info= check_user(Options::Daemon::user))) { - if (set_user(options.user, user_info)) - goto err; + if (set_user(Options::Daemon::user, user_info)) + { + return_value= 1; + goto main_end; + } } - if (options.run_as_service) + if (Options::Daemon::run_as_service) { /* forks, and returns only in child */ - daemonize(options.log_file_name); + daemonize(Options::Daemon::log_file_name); /* forks again, and returns only in child: parent becomes angel */ - angel(options); + angel(); } + + manager(); + #else - if (!options.stand_alone) + + if (!Options::Service::stand_alone) { - if (HandleServiceOptions(options)) - goto err; + if (HandleServiceOptions()) + { + return_value= 1; + goto main_end; + } } else + { + manager(); + } + #endif - manager(options); return_value= 0; -err: - options.cleanup(); +main_end: + Options::cleanup(); my_end(0); return return_value; } @@ -200,7 +224,7 @@ static void init_environment(char *progname) MY_INIT(progname); log_init(); umask(0117); - srand(time(0)); + srand((unsigned int) time(0)); } @@ -298,7 +322,7 @@ void terminate(int signo) Angel process will exit silently if mysqlmanager exits normally. */ -static void angel(const Options &options) +static void angel() { /* install signal handlers */ sigset_t zeromask; // to sigsuspend in parent @@ -338,6 +362,14 @@ spawn: /* Here we return to main, and fall into manager */ break; default: // parent, success + pid= getpid(); /* Get our pid. */ + + log_info("Angel pid file: '%s'; PID: %d.", + (const char *) Options::Daemon::angel_pid_file_name, + (int) pid); + + create_pid_file(Options::Daemon::angel_pid_file_name, pid); + while (child_status == CHILD_OK && is_terminated == 0) sigsuspend(&zeromask); diff --git a/server-tools/instance-manager/options.cc b/server-tools/instance-manager/options.cc index 85fea76c079..31ce5b00190 100644 --- a/server-tools/instance-manager/options.cc +++ b/server-tools/instance-manager/options.cc @@ -20,70 +20,128 @@ #include "options.h" -#include "priv.h" -#include "portability.h" +#include <my_global.h> #include <my_sys.h> #include <my_getopt.h> -#include <m_string.h> #include <mysql_com.h> +#include "exit_codes.h" +#include "log.h" +#include "portability.h" +#include "priv.h" +#include "user_management_commands.h" + #define QUOTE2(x) #x #define QUOTE(x) QUOTE2(x) #ifdef __WIN__ -char Options::install_as_service; -char Options::remove_service; -char Options::stand_alone; -char windows_config_file[FN_REFLEN]; -char default_password_file_name[FN_REFLEN]; -char default_log_file_name[FN_REFLEN]; -const char *Options::config_file= windows_config_file; -#else -char Options::run_as_service; -const char *Options::user= 0; /* No default value */ -const char *default_password_file_name= QUOTE(DEFAULT_PASSWORD_FILE_NAME); -const char *default_log_file_name= QUOTE(DEFAULT_LOG_FILE_NAME); -const char *Options::config_file= QUOTE(DEFAULT_CONFIG_FILE); + +/* Define holders for default values. */ + +static char win_dflt_config_file_name[FN_REFLEN]; +static char win_dflt_password_file_name[FN_REFLEN]; +static char win_dflt_pid_file_name[FN_REFLEN]; +static char win_dflt_socket_file_name[FN_REFLEN]; + +static char win_dflt_mysqld_path[FN_REFLEN]; + +/* Define and initialize Windows-specific options. */ + +my_bool Options::Service::install_as_service; +my_bool Options::Service::remove_service; +my_bool Options::Service::stand_alone; + +const char *Options::Main::config_file= win_dflt_config_file_name; +const char *Options::Main::password_file_name= win_dflt_password_file_name; +const char *Options::Main::pid_file_name= win_dflt_pid_file_name; +const char *Options::Main::socket_file_name= win_dflt_socket_file_name; + +const char *Options::Main::default_mysqld_path= win_dflt_mysqld_path; + +static int setup_windows_defaults(); + +#else /* UNIX */ + +/* Define and initialize UNIX-specific options. */ + +my_bool Options::Daemon::run_as_service= FALSE; +const char *Options::Daemon::log_file_name= QUOTE(DEFAULT_LOG_FILE_NAME); +const char *Options::Daemon::user= NULL; /* No default value */ +const char *Options::Daemon::angel_pid_file_name= NULL; + +const char *Options::Main::config_file= QUOTE(DEFAULT_CONFIG_FILE); +const char * +Options::Main::password_file_name= QUOTE(DEFAULT_PASSWORD_FILE_NAME); +const char *Options::Main::pid_file_name= QUOTE(DEFAULT_PID_FILE_NAME); +const char *Options::Main::socket_file_name= QUOTE(DEFAULT_SOCKET_FILE_NAME); + +const char *Options::Main::default_mysqld_path= QUOTE(DEFAULT_MYSQLD_PATH); + #endif -const char *Options::log_file_name= default_log_file_name; -const char *Options::pid_file_name= QUOTE(DEFAULT_PID_FILE_NAME); -const char *Options::socket_file_name= QUOTE(DEFAULT_SOCKET_FILE_NAME); -const char *Options::password_file_name= default_password_file_name; -const char *Options::default_mysqld_path= QUOTE(DEFAULT_MYSQLD_PATH); -const char *Options::bind_address= 0; /* No default value */ -uint Options::monitoring_interval= DEFAULT_MONITORING_INTERVAL; -uint Options::port_number= DEFAULT_PORT; -/* just to declare */ + +/* Remember if the config file was forced. */ + +bool Options::Main::is_forced_default_file= FALSE; + +/* Define and initialize common options. */ + +const char *Options::Main::bind_address= NULL; /* No default value */ +uint Options::Main::monitoring_interval= DEFAULT_MONITORING_INTERVAL; +uint Options::Main::port_number= DEFAULT_PORT; +my_bool Options::Main::mysqld_safe_compatible= FALSE; + +/* Options::User_management */ + +char *Options::User_management::user_name= NULL; +char *Options::User_management::password= NULL; + +User_management_cmd *Options::User_management::cmd= NULL; + +/* Private members. */ + char **Options::saved_argv= NULL; -/* Remember if the config file was forced */ -bool Options::is_forced_default_file= 0; + #ifndef DBUG_OFF -const char *Options::default_dbug_option= "d:t:i:O,im.trace"; +const char *Options::Debug::config_str= "d:t:i:O,im.trace"; #endif +static const char * const ANGEL_PID_FILE_SUFFIX= ".angel.pid"; +static const int ANGEL_PID_FILE_SUFFIX_LEN= strlen(ANGEL_PID_FILE_SUFFIX); + /* List of options, accepted by the instance manager. List must be closed with empty option. */ enum options { + OPT_PASSWD= 'P', + OPT_USERNAME= 'u', + OPT_PASSWORD= 'p', OPT_LOG= 256, OPT_PID_FILE, OPT_SOCKET, OPT_PASSWORD_FILE, OPT_MYSQLD_PATH, -#ifndef __WIN__ - OPT_RUN_AS_SERVICE, - OPT_USER, -#else +#ifdef __WIN__ OPT_INSTALL_SERVICE, OPT_REMOVE_SERVICE, OPT_STAND_ALONE, +#else + OPT_RUN_AS_SERVICE, + OPT_USER, + OPT_ANGEL_PID_FILE, #endif OPT_MONITORING_INTERVAL, OPT_PORT, OPT_WAIT_TIMEOUT, - OPT_BIND_ADDRESS + OPT_BIND_ADDRESS, + OPT_ADD_USER, + OPT_DROP_USER, + OPT_EDIT_USER, + OPT_CLEAN_PASSWORD_FILE, + OPT_CHECK_PASSWORD_FILE, + OPT_LIST_USERS, + OPT_MYSQLD_SAFE_COMPATIBLE }; static struct my_option my_long_options[] = @@ -91,94 +149,158 @@ static struct my_option my_long_options[] = { "help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }, + { "add-user", OPT_ADD_USER, + "Add a user to the password file", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }, + +#ifndef __WIN__ + { "angel-pid-file", OPT_ANGEL_PID_FILE, "Pid file for angel process.", + (gptr *) &Options::Daemon::angel_pid_file_name, + (gptr *) &Options::Daemon::angel_pid_file_name, + 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, +#endif + { "bind-address", OPT_BIND_ADDRESS, "Bind address to use for connection.", - (gptr *) &Options::bind_address, (gptr *) &Options::bind_address, + (gptr *) &Options::Main::bind_address, + (gptr *) &Options::Main::bind_address, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, + { "check-password-file", OPT_CHECK_PASSWORD_FILE, + "Check the password file for consistency", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }, + + { "clean-password-file", OPT_CLEAN_PASSWORD_FILE, + "Clean the password file", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }, + #ifndef DBUG_OFF {"debug", '#', "Debug log.", - (gptr*) &Options::default_dbug_option, (gptr*) &Options::default_dbug_option, + (gptr *) &Options::Debug::config_str, + (gptr *) &Options::Debug::config_str, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, #endif { "default-mysqld-path", OPT_MYSQLD_PATH, "Where to look for MySQL" " Server binary.", - (gptr *) &Options::default_mysqld_path, - (gptr *) &Options::default_mysqld_path, + (gptr *) &Options::Main::default_mysqld_path, + (gptr *) &Options::Main::default_mysqld_path, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0 }, + + { "drop-user", OPT_DROP_USER, + "Drop existing user from the password file", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }, + + { "edit-user", OPT_EDIT_USER, + "Edit existing user in the password file", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }, + #ifdef __WIN__ { "install", OPT_INSTALL_SERVICE, "Install as system service.", - (gptr *) &Options::install_as_service, (gptr*) &Options::install_as_service, + (gptr *) &Options::Service::install_as_service, + (gptr *) &Options::Service::install_as_service, 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 0, 0 }, #endif + { "list-users", OPT_LIST_USERS, + "Print out a list of registered users", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }, + +#ifndef __WIN__ { "log", OPT_LOG, "Path to log file. Used only with --run-as-service.", - (gptr *) &Options::log_file_name, (gptr *) &Options::log_file_name, + (gptr *) &Options::Daemon::log_file_name, + (gptr *) &Options::Daemon::log_file_name, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, +#endif { "monitoring-interval", OPT_MONITORING_INTERVAL, "Interval to monitor" " instances in seconds.", - (gptr *) &Options::monitoring_interval, - (gptr *) &Options::monitoring_interval, + (gptr *) &Options::Main::monitoring_interval, + (gptr *) &Options::Main::monitoring_interval, 0, GET_UINT, REQUIRED_ARG, DEFAULT_MONITORING_INTERVAL, 0, 0, 0, 0, 0 }, - { "passwd", 'P', "Prepare entry for passwd file and exit.", 0, 0, 0, - GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }, + { "mysqld-safe-compatible", OPT_MYSQLD_SAFE_COMPATIBLE, + "Start Instance Manager in mysqld_safe compatible manner", + (gptr *) &Options::Main::mysqld_safe_compatible, + (gptr *) &Options::Main::mysqld_safe_compatible, + 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 0, 0 }, - { "password-file", OPT_PASSWORD_FILE, "Look for Instance Manager users" - " and passwords here.", - (gptr *) &Options::password_file_name, - (gptr *) &Options::password_file_name, + { "passwd", OPT_PASSWD, + "Prepare an entry for the password file and exit.", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }, + + { "password", OPT_PASSWORD, "Password to update the password file", + (gptr *) &Options::User_management::password, + (gptr *) &Options::User_management::password, + 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, + + { "password-file", OPT_PASSWORD_FILE, + "Look for Instance Manager users and passwords here.", + (gptr *) &Options::Main::password_file_name, + (gptr *) &Options::Main::password_file_name, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, { "pid-file", OPT_PID_FILE, "Pid file to use.", - (gptr *) &Options::pid_file_name, (gptr *) &Options::pid_file_name, + (gptr *) &Options::Main::pid_file_name, + (gptr *) &Options::Main::pid_file_name, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, { "port", OPT_PORT, "Port number to use for connections", - (gptr *) &Options::port_number, (gptr *) &Options::port_number, + (gptr *) &Options::Main::port_number, + (gptr *) &Options::Main::port_number, 0, GET_UINT, REQUIRED_ARG, DEFAULT_PORT, 0, 0, 0, 0, 0 }, #ifdef __WIN__ { "remove", OPT_REMOVE_SERVICE, "Remove system service.", - (gptr *)&Options::remove_service, (gptr*) &Options::remove_service, + (gptr *) &Options::Service::remove_service, + (gptr *) &Options::Service::remove_service, 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 0, 0}, #else { "run-as-service", OPT_RUN_AS_SERVICE, - "Daemonize and start angel process.", (gptr *) &Options::run_as_service, + "Daemonize and start angel process.", + (gptr *) &Options::Daemon::run_as_service, 0, 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 0, 0 }, #endif { "socket", OPT_SOCKET, "Socket file to use for connection.", - (gptr *) &Options::socket_file_name, (gptr *) &Options::socket_file_name, + (gptr *) &Options::Main::socket_file_name, + (gptr *) &Options::Main::socket_file_name, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, #ifdef __WIN__ { "standalone", OPT_STAND_ALONE, "Run the application in stand alone mode.", - (gptr *)&Options::stand_alone, (gptr*) &Options::stand_alone, + (gptr *) &Options::Service::stand_alone, + (gptr *) &Options::Service::stand_alone, 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 0, 0}, #else { "user", OPT_USER, "Username to start mysqlmanager", - (gptr *) &Options::user, - (gptr *) &Options::user, + (gptr *) &Options::Daemon::user, + (gptr *) &Options::Daemon::user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, #endif + { "username", OPT_USERNAME, + "Username to update the password file", + (gptr *) &Options::User_management::user_name, + (gptr *) &Options::User_management::user_name, + 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, + { "version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }, { "wait-timeout", OPT_WAIT_TIMEOUT, "The number of seconds IM waits " "for activity on a connection before closing it.", - (gptr *) &net_read_timeout, (gptr *) &net_read_timeout, 0, GET_ULONG, - REQUIRED_ARG, NET_WAIT_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0 }, + (gptr *) &net_read_timeout, + (gptr *) &net_read_timeout, + 0, GET_ULONG, REQUIRED_ARG, NET_WAIT_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0 }, { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 } }; static void version() { - printf("%s Ver %s for %s on %s\n", my_progname, mysqlmanager_version, + printf("%s Ver %s for %s on %s\n", my_progname, + (const char *) mysqlmanager_version.str, SYSTEM_TYPE, MACHINE_TYPE); } @@ -206,37 +328,6 @@ static void usage() } -static void passwd() -{ - char user[1024], *p; - const char *pw1, *pw2; - char pw1msg[]= "Enter password: "; - char pw2msg[]= "Re-type password: "; - char crypted_pw[SCRAMBLED_PASSWORD_CHAR_LENGTH + 1]; - - fprintf(stderr, "Creating record for new user.\n"); - fprintf(stderr, "Enter user name: "); - if (!fgets(user, sizeof(user), stdin)) - { - fprintf(stderr, "Unable to read user.\n"); - return; - } - if ((p= strchr(user, '\n'))) *p= 0; - - pw1= get_tty_password(pw1msg); - pw2= get_tty_password(pw2msg); - - if (strcmp(pw1, pw2)) - { - fprintf(stderr, "Sorry, passwords do not match.\n"); - return; - } - - make_scrambled_password(crypted_pw, pw1); - printf("%s:%s\n", user, crypted_pw); -} - - C_MODE_START static my_bool @@ -248,16 +339,52 @@ get_one_option(int optid, case 'V': version(); exit(0); - case 'P': - passwd(); - exit(0); + case OPT_PASSWD: + case OPT_ADD_USER: + case OPT_DROP_USER: + case OPT_EDIT_USER: + case OPT_CLEAN_PASSWORD_FILE: + case OPT_CHECK_PASSWORD_FILE: + case OPT_LIST_USERS: + if (Options::User_management::cmd) + { + fprintf(stderr, "Error: only one password-management command " + "can be specified at a time.\n"); + exit(ERR_INVALID_USAGE); + } + + switch (optid) { + case OPT_PASSWD: + Options::User_management::cmd= new Passwd_cmd(); + break; + case OPT_ADD_USER: + Options::User_management::cmd= new Add_user_cmd(); + break; + case OPT_DROP_USER: + Options::User_management::cmd= new Drop_user_cmd(); + break; + case OPT_EDIT_USER: + Options::User_management::cmd= new Edit_user_cmd(); + break; + case OPT_CLEAN_PASSWORD_FILE: + Options::User_management::cmd= new Clean_db_cmd(); + break; + case OPT_CHECK_PASSWORD_FILE: + Options::User_management::cmd= new Check_db_cmd(); + break; + case OPT_LIST_USERS: + Options::User_management::cmd= new List_users_cmd(); + break; + } + + break; case '?': usage(); exit(0); case '#': #ifndef DBUG_OFF - DBUG_SET(argument ? argument : Options::default_dbug_option); - DBUG_SET_INITIAL(argument ? argument : Options::default_dbug_option); + DBUG_SET(argument ? argument : Options::Debug::config_str); + DBUG_SET_INITIAL(argument ? argument : Options::Debug::config_str); #endif break; } @@ -283,8 +410,8 @@ int Options::load(int argc, char **argv) { if (is_prefix(argv[1], "--defaults-file=")) { - Options::config_file= strchr(argv[1], '=') + 1; - Options::is_forced_default_file= 1; + Main::config_file= strchr(argv[1], '=') + 1; + Main::is_forced_default_file= TRUE; } if (is_prefix(argv[1], "--defaults-extra-file=") || is_prefix(argv[1], "--no-defaults")) @@ -293,59 +420,139 @@ int Options::load(int argc, char **argv) fprintf(stderr, "The --defaults-extra-file and --no-defaults options" " are not supported by\n" "Instance Manager. Program aborted.\n"); - goto err; + return ERR_INVALID_USAGE; } } #ifdef __WIN__ if (setup_windows_defaults()) - goto err; + { + fprintf(stderr, "Internal error: could not setup default values.\n"); + return ERR_OUT_OF_MEMORY; + } #endif + /* load_defaults will reset saved_argv with a new allocated list */ saved_argv= argv; /* config-file options are prepended to command-line ones */ - load_defaults(config_file, default_groups, &argc, - &saved_argv); - if ((handle_options(&argc, &saved_argv, my_long_options, - get_one_option)) != 0) - goto err; + log_info("Loading config file '%s'...", + (const char *) Main::config_file); - return 0; + load_defaults(Main::config_file, default_groups, &argc, &saved_argv); + + if ((handle_options(&argc, &saved_argv, my_long_options, get_one_option))) + return ERR_INVALID_USAGE; + + if (!User_management::cmd && + (User_management::user_name || User_management::password)) + { + fprintf(stderr, + "--username and/or --password options have been specified, " + "but no password-management command has been given.\n"); + return ERR_INVALID_USAGE; + } + +#ifndef __WIN__ + if (Options::Daemon::run_as_service) + { + if (Options::Daemon::angel_pid_file_name == NULL) + { + /* + Calculate angel pid file on the IM pid file basis: replace the + extension (everything after the last dot) of the pid file basename to + '.angel.pid'. + */ + + char *angel_pid_file_name; + char *base_name_ptr; + char *ext_ptr; + + angel_pid_file_name= + (char *) malloc(strlen(Options::Main::pid_file_name) + + ANGEL_PID_FILE_SUFFIX_LEN); + + strcpy(angel_pid_file_name, Options::Main::pid_file_name); + + base_name_ptr= strrchr(angel_pid_file_name, '/'); + + if (!base_name_ptr) + base_name_ptr= angel_pid_file_name + 1; + + ext_ptr= strrchr(base_name_ptr, '.'); + if (ext_ptr) + *ext_ptr= 0; + + strcat(angel_pid_file_name, ANGEL_PID_FILE_SUFFIX); -err: - return 1; + Options::Daemon::angel_pid_file_name= angel_pid_file_name; + } + else + { + Options::Daemon::angel_pid_file_name= + strdup(Options::Daemon::angel_pid_file_name); + } + } +#endif + + return 0; } void Options::cleanup() { - /* free_defaults returns nothing */ - if (Options::saved_argv != NULL) - free_defaults(Options::saved_argv); + if (saved_argv) + free_defaults(saved_argv); + + delete User_management::cmd; + +#ifndef __WIN__ + if (Options::Daemon::run_as_service) + free((void *) Options::Daemon::angel_pid_file_name); +#endif } #ifdef __WIN__ -int Options::setup_windows_defaults() +static int setup_windows_defaults() { - if (!GetModuleFileName(NULL, default_password_file_name, - sizeof(default_password_file_name))) - return 1; - char *filename= strstr(default_password_file_name, ".exe"); - strcpy(filename, ".passwd"); - - if (!GetModuleFileName(NULL, default_log_file_name, - sizeof(default_log_file_name))) + char module_full_name[FN_REFLEN]; + char dir_name[FN_REFLEN]; + char base_name[FN_REFLEN]; + char im_name[FN_REFLEN]; + char *base_name_ptr; + char *ptr; + + /* Determine dirname and basename. */ + + if (!GetModuleFileName(NULL, module_full_name, sizeof (module_full_name)) || + !GetFullPathName(module_full_name, sizeof (dir_name), dir_name, + &base_name_ptr)) + { return 1; - filename= strstr(default_log_file_name, ".exe"); - strcpy(filename, ".log"); + } + + strmake(base_name, base_name_ptr, FN_REFLEN); + *base_name_ptr= 0; + + strmake(im_name, base_name, FN_REFLEN); + ptr= strrchr(im_name, '.'); + + if (!ptr) + return 1; + + *ptr= 0; + + /* Initialize the defaults. */ + + strxmov(win_dflt_config_file_name, dir_name, DFLT_CONFIG_FILE_NAME, NullS); + strxmov(win_dflt_mysqld_path, dir_name, DFLT_MYSQLD_PATH, NullS); + strxmov(win_dflt_password_file_name, dir_name, im_name, DFLT_PASSWD_FILE_EXT, + NullS); + strxmov(win_dflt_pid_file_name, dir_name, im_name, DFLT_PID_FILE_EXT, NullS); + strxmov(win_dflt_socket_file_name, dir_name, im_name, DFLT_SOCKET_FILE_EXT, + NullS); - if (!GetModuleFileName(NULL, windows_config_file, - sizeof(windows_config_file))) - return 1; - char *slash= strrchr(windows_config_file, '\\'); - strcpy(slash, "\\my.ini"); return 0; } diff --git a/server-tools/instance-manager/options.h b/server-tools/instance-manager/options.h index 06818288606..5c54ff201b2 100644 --- a/server-tools/instance-manager/options.h +++ b/server-tools/instance-manager/options.h @@ -17,49 +17,87 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* - Options - all possible options for the instance manager grouped in one - struct. + Options - all possible command-line options for the Instance Manager grouped + in one struct. */ + #include <my_global.h> #if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE) #pragma interface #endif +class User_management_cmd; + struct Options { -#ifdef __WIN__ - static char install_as_service; - static char remove_service; - static char stand_alone; -#else - static char run_as_service; /* handle_options doesn't support bool */ - static const char *user; -#endif - static bool is_forced_default_file; - static const char *log_file_name; - static const char *pid_file_name; - static const char *socket_file_name; - static const char *password_file_name; - static const char *default_mysqld_path; - /* the option which should be passed to process_default_option_files */ - static uint monitoring_interval; - static uint port_number; - static const char *bind_address; - static const char *config_file; + /* + NOTE: handle_options() expects value of my_bool type for GET_BOOL + accessor (i.e. bool must not be used). + */ - /* argv pointer returned by load_defaults() to be used by free_defaults() */ - static char **saved_argv; + struct User_management + { + static User_management_cmd *cmd; + + static char *user_name; + static char *password; + }; + + struct Main + { + /* this is not an option parsed by handle_options(). */ + static bool is_forced_default_file; + + static const char *pid_file_name; + static const char *socket_file_name; + static const char *password_file_name; + static const char *default_mysqld_path; + static uint monitoring_interval; + static uint port_number; + static const char *bind_address; + static const char *config_file; + static my_bool mysqld_safe_compatible; + }; #ifndef DBUG_OFF - static const char *default_dbug_option; + struct Debug + { + static const char *config_str; + }; #endif - int load(int argc, char **argv); - void cleanup(); -#ifdef __WIN__ - int setup_windows_defaults(); +#ifndef __WIN__ + + struct Daemon + { + static my_bool run_as_service; + static const char *log_file_name; + static const char *user; + static const char *angel_pid_file_name; + }; + +#else + + struct Service + { + static my_bool install_as_service; + static my_bool remove_service; + static my_bool stand_alone; + }; + #endif + +public: + static int load(int argc, char **argv); + static void cleanup(); + +private: + Options(); /* Deny instantiation of this class. */ + +private: + /* argv pointer returned by load_defaults() to be used by free_defaults() */ + static char **saved_argv; }; #endif // INCLUDES_MYSQL_INSTANCE_MANAGER_OPTIONS_H diff --git a/server-tools/instance-manager/parse.cc b/server-tools/instance-manager/parse.cc index 14b3db16b45..4e931488fce 100644 --- a/server-tools/instance-manager/parse.cc +++ b/server-tools/instance-manager/parse.cc @@ -17,12 +17,12 @@ #include "parse.h" #include "commands.h" -#include <string.h> - enum Token { - TOK_ERROR= 0, /* Encodes the "ERROR" word, it doesn't indicate error. */ + TOK_CREATE= 0, + TOK_DROP, + TOK_ERROR, /* Encodes the "ERROR" word, it doesn't indicate error. */ TOK_FILES, TOK_FLUSH, TOK_GENERAL, @@ -50,6 +50,8 @@ struct tokens_st static struct tokens_st tokens[]= { + {6, "CREATE"}, + {4, "DROP"}, {5, "ERROR"}, {5, "FILES"}, {5, "FLUSH"}, @@ -67,6 +69,37 @@ static struct tokens_st tokens[]= { {5, "UNSET"} }; +/************************************************************************/ + +Named_value_arr::Named_value_arr() : + initialized(FALSE) +{ +} + + +bool Named_value_arr::init() +{ + if (my_init_dynamic_array(&arr, sizeof(Named_value), 0, 32)) + return TRUE; + + initialized= TRUE; + + return FALSE; +} + + +Named_value_arr::~Named_value_arr() +{ + if (!initialized) + return; + + for (int i= 0; i < get_size(); ++i) + get_element(i).free(); + + delete_dynamic(&arr); +} + +/************************************************************************/ /* Returns token no if word corresponds to some token, otherwise returns @@ -104,53 +137,200 @@ Token shift_token(const char **text, uint *word_len) } -int get_text_id(const char **text, uint *word_len, const char **id) +int get_text_id(const char **text, LEX_STRING *token) { - get_word(text, word_len); - if (*word_len == 0) + get_word(text, &token->length); + if (token->length == 0) return 1; - *id= *text; + token->str= (char *) *text; return 0; } +static bool parse_long(const LEX_STRING *token, long *value) +{ + int err_code; + char *end_ptr= token->str + token->length; + + *value= my_strtoll10(token->str, &end_ptr, &err_code); + + return err_code != 0; +} + + +bool parse_option_value(const char *text, uint *text_len, char **value) +{ + char beginning_quote; + const char *text_start_ptr; + char *v; + bool escape_mode= FALSE; + + if (!*text || (*text != '\'' && *text != '"')) + return TRUE; /* syntax error: string expected. */ + + beginning_quote= *text; + + ++text; /* skip the beginning quote. */ + + text_start_ptr= text; + + if (!(v= Named_value::alloc_str(text))) + return TRUE; + + *value= v; + + while (TRUE) + { + if (!*text) + { + Named_value::free_str(value); + return TRUE; /* syntax error: missing terminating ' character. */ + } + + if (*text == '\n' || *text == '\r') + { + Named_value::free_str(value); + return TRUE; /* syntax error: option value should be a single line. */ + } + + if (!escape_mode && *text == beginning_quote) + break; + + if (escape_mode) + { + switch (*text) + { + case 'b': /* \b -- backspace */ + if (v > *value) + --v; + break; + + case 't': /* \t -- tab */ + *v= '\t'; + ++v; + break; + + case 'n': /* \n -- newline */ + *v= '\n'; + ++v; + break; + + case 'r': /* \r -- carriage return */ + *v= '\r'; + ++v; + break; + + case '\\': /* \\ -- back slash */ + *v= '\\'; + ++v; + break; + + case 's': /* \s -- space */ + *v= ' '; + ++v; + break; + + default: /* Unknown escape sequence. Treat as error. */ + Named_value::free_str(value); + return TRUE; + } + + escape_mode= FALSE; + } + else + { + if (*text == '\\') + { + escape_mode= TRUE; + } + else + { + *v= *text; + ++v; + } + } + + ++text; + } + + *v= 0; + + /* "2" below stands for beginning and ending quotes. */ + *text_len= text - text_start_ptr + 2; + + return FALSE; +} + + +void skip_spaces(const char **text) +{ + while (**text && my_isspace(default_charset_info, **text)) + ++(*text); +} + + Command *parse_command(Instance_map *map, const char *text) { uint word_len; - const char *instance_name; - uint instance_name_len; - const char *option; - uint option_len; - const char *option_value; - uint option_value_len; - const char *log_size; + LEX_STRING instance_name; Command *command; const char *saved_text= text; - bool skip= false; - const char *tmp; Token tok1= shift_token(&text, &word_len); switch (tok1) { case TOK_START: // fallthrough case TOK_STOP: + case TOK_CREATE: + case TOK_DROP: if (shift_token(&text, &word_len) != TOK_INSTANCE) goto syntax_error; get_word(&text, &word_len); if (word_len == 0) goto syntax_error; - instance_name= text; - instance_name_len= word_len; + instance_name.str= (char *) text; + instance_name.length= word_len; text+= word_len; - /* it should be the end of command */ - get_word(&text, &word_len, NONSPACE); - if (word_len) - goto syntax_error; - if (tok1 == TOK_START) - command= new Start_instance(map, instance_name, instance_name_len); + if (tok1 == TOK_CREATE) + { + Create_instance *cmd= new Create_instance(map, &instance_name); + + if (!cmd) + return NULL; /* Report ER_OUT_OF_RESOURCES. */ + + if (cmd->init(&text)) + { + delete cmd; + goto syntax_error; + } + + command= cmd; + } else - command= new Stop_instance(map, instance_name, instance_name_len); + { + /* it should be the end of command */ + get_word(&text, &word_len, NONSPACE); + if (word_len) + goto syntax_error; + } + + switch (tok1) { + case TOK_START: + command= new Start_instance(map, &instance_name); + break; + case TOK_STOP: + command= new Stop_instance(map, &instance_name); + break; + case TOK_CREATE: + ; /* command already initialized. */ + break; + case TOK_DROP: + command= new Drop_instance(map, &instance_name); + break; + default: /* this is impossible, but nevertheless... */ + DBUG_ASSERT(0); + } break; case TOK_FLUSH: if (shift_token(&text, &word_len) != TOK_INSTANCES) @@ -163,53 +343,28 @@ Command *parse_command(Instance_map *map, const char *text) command= new Flush_instances(map); break; case TOK_UNSET: - skip= true; case TOK_SET: + { + Abstract_option_cmd *cmd; - if (get_text_id(&text, &instance_name_len, &instance_name)) - goto syntax_error; - text+= instance_name_len; - - /* the next token should be a dot */ - get_word(&text, &word_len); - if (*text != '.') - goto syntax_error; - text++; + if (tok1 == TOK_SET) + cmd= new Set_option(map); + else + cmd= new Unset_option(map); - get_word(&text, &option_len, NONSPACE); - option= text; - if ((tmp= strchr(text, '=')) != NULL) - option_len= tmp - text; - text+= option_len; + if (!cmd) + return NULL; /* Report ER_OUT_OF_RESOURCES. */ - get_word(&text, &word_len); - if (*text == '=') - { - text++; /* skip '=' */ - get_word(&text, &option_value_len, NONSPACE); - option_value= text; - text+= option_value_len; - } - else - { - option_value= ""; - option_value_len= 0; - } + if (cmd->init(&text)) + { + delete cmd; + goto syntax_error; + } - /* should be empty */ - get_word(&text, &word_len, NONSPACE); - if (word_len) - goto syntax_error; + command= cmd; - if (skip) - command= new Unset_option(map, instance_name, instance_name_len, - option, option_len, option_value, - option_value_len); - else - command= new Set_option(map, instance_name, instance_name_len, - option, option_len, option_value, - option_value_len); - break; + break; + } case TOK_SHOW: switch (shift_token(&text, &word_len)) { case TOK_INSTANCES: @@ -222,30 +377,35 @@ Command *parse_command(Instance_map *map, const char *text) switch (Token tok2= shift_token(&text, &word_len)) { case TOK_OPTIONS: case TOK_STATUS: - if (get_text_id(&text, &instance_name_len, &instance_name)) + if (get_text_id(&text, &instance_name)) goto syntax_error; - text+= instance_name_len; + text+= instance_name.length; /* check that this is the end of the command */ get_word(&text, &word_len, NONSPACE); if (word_len) goto syntax_error; if (tok2 == TOK_STATUS) - command= new Show_instance_status(map, instance_name, - instance_name_len); + command= new Show_instance_status(map, &instance_name); else - command= new Show_instance_options(map, instance_name, - instance_name_len); + command= new Show_instance_options(map, &instance_name); break; default: goto syntax_error; } break; default: - instance_name= text - word_len; - instance_name_len= word_len; - if (instance_name_len) + instance_name.str= (char *) text - word_len; + instance_name.length= word_len; + if (instance_name.length) { Log_type log_type; + + long log_size; + LEX_STRING log_size_str; + + long log_offset= 0; + LEX_STRING log_offset_str= { NULL, 0 }; + switch (shift_token(&text, &word_len)) { case TOK_LOG: switch (Token tok3= shift_token(&text, &word_len)) { @@ -254,8 +414,7 @@ Command *parse_command(Instance_map *map, const char *text) /* check that this is the end of the command */ if (word_len) goto syntax_error; - command= new Show_instance_log_files(map, instance_name, - instance_name_len); + command= new Show_instance_log_files(map, &instance_name); break; case TOK_ERROR: case TOK_GENERAL: @@ -275,12 +434,14 @@ Command *parse_command(Instance_map *map, const char *text) goto syntax_error; } /* get the size of the log we want to retrieve */ - if (get_text_id(&text, &word_len, &log_size)) + if (get_text_id(&text, &log_size_str)) goto syntax_error; - text+= word_len; + text+= log_size_str.length; + /* this parameter is required */ - if (!word_len) + if (!log_size_str.length) goto syntax_error; + /* the next token should be comma, or nothing */ get_word(&text, &word_len); switch (*text) { @@ -290,23 +451,41 @@ Command *parse_command(Instance_map *map, const char *text) get_word(&text, &word_len); if (!word_len) goto syntax_error; + log_offset_str.str= (char *) text; + log_offset_str.length= word_len; text+= word_len; - command= new Show_instance_log(map, instance_name, - instance_name_len, log_type, - log_size, text); get_word(&text, &word_len, NONSPACE); /* check that this is the end of the command */ if (word_len) goto syntax_error; break; case '\0': - command= new Show_instance_log(map, instance_name, - instance_name_len, log_type, - log_size, NULL); break; /* this is ok */ default: + goto syntax_error; + } + + /* Parse size parameter. */ + + if (parse_long(&log_size_str, &log_size)) + goto syntax_error; + + if (log_size <= 0) goto syntax_error; + + /* Parse offset parameter (if specified). */ + + if (log_offset_str.length) + { + if (parse_long(&log_offset_str, &log_offset)) + goto syntax_error; + + if (log_offset <= 0) + goto syntax_error; } + + command= new Show_instance_log(map, &instance_name, + log_type, log_size, log_offset); break; default: goto syntax_error; diff --git a/server-tools/instance-manager/parse.h b/server-tools/instance-manager/parse.h index 3da53e3a61e..ae29c7eb64a 100644 --- a/server-tools/instance-manager/parse.h +++ b/server-tools/instance-manager/parse.h @@ -18,6 +18,7 @@ #include <my_global.h> #include <my_sys.h> +#include <m_string.h> class Command; class Instance_map; @@ -29,10 +30,148 @@ enum Log_type IM_LOG_SLOW }; -Command *parse_command(Instance_map *instance_map, const char *text); +Command *parse_command(Instance_map *map, const char *text); + +bool parse_option_value(const char *text, uint *text_len, char **value); + +void skip_spaces(const char **text); /* define kinds of the word seek method */ -enum { ALPHANUM= 1, NONSPACE }; +enum enum_seek_method { ALPHANUM= 1, NONSPACE, OPTION_NAME }; + +/************************************************************************/ + +class Named_value +{ +public: + /* + The purpose of these methods is just to have one method for + allocating/deallocating memory for strings for Named_value. + */ + + static inline char *alloc_str(const LEX_STRING *str); + static inline char *alloc_str(const char *str); + static inline void free_str(char **str); + +public: + inline Named_value(); + inline Named_value(char *name_arg, char *value_arg); + + inline char *get_name(); + inline char *get_value(); + + inline void free(); + +private: + char *name; + char *value; +}; + +inline char *Named_value::alloc_str(const LEX_STRING *str) +{ + return my_strndup((const byte *) str->str, str->length, MYF(0)); +} + +inline char *Named_value::alloc_str(const char *str) +{ + return my_strdup(str, MYF(0)); +} + +inline void Named_value::free_str(char **str) +{ + my_free(*str, MYF(MY_ALLOW_ZERO_PTR)); + *str= NULL; +} + +inline Named_value::Named_value() + :name(NULL), value(NULL) +{ } + +inline Named_value::Named_value(char *name_arg, char *value_arg) + :name(name_arg), value(value_arg) +{ } + +inline char *Named_value::get_name() +{ + return name; +} + +inline char *Named_value::get_value() +{ + return value; +} + +void Named_value::free() +{ + free_str(&name); + free_str(&value); +} + +/************************************************************************/ + +class Named_value_arr +{ +public: + Named_value_arr(); + ~Named_value_arr(); + + bool init(); + + inline int get_size() const; + inline Named_value get_element(int idx) const; + inline void remove_element(int idx); + inline bool add_element(Named_value *option); + inline bool replace_element(int idx, Named_value *option); + +private: + bool initialized; + DYNAMIC_ARRAY arr; +}; + + +inline int Named_value_arr::get_size() const +{ + return arr.elements; +} + + +inline Named_value Named_value_arr::get_element(int idx) const +{ + DBUG_ASSERT(0 <= idx && (uint) idx < arr.elements); + + Named_value option; + get_dynamic((DYNAMIC_ARRAY *) &arr, (gptr) &option, idx); + + return option; +} + + +inline void Named_value_arr::remove_element(int idx) +{ + DBUG_ASSERT(0 <= idx && (uint) idx < arr.elements); + + get_element(idx).free(); + + delete_dynamic_element(&arr, idx); +} + + +inline bool Named_value_arr::add_element(Named_value *option) +{ + return insert_dynamic(&arr, (gptr) option); +} + + +inline bool Named_value_arr::replace_element(int idx, Named_value *option) +{ + DBUG_ASSERT(0 <= idx && (uint) idx < arr.elements); + + get_element(idx).free(); + + return set_dynamic(&arr, (gptr) option, idx); +} + +/************************************************************************/ /* tries to find next word in the text @@ -41,7 +180,7 @@ enum { ALPHANUM= 1, NONSPACE }; */ inline void get_word(const char **text, uint *word_len, - int seek_method= ALPHANUM) + enum_seek_method seek_method= ALPHANUM) { const char *word_end; @@ -51,13 +190,23 @@ inline void get_word(const char **text, uint *word_len, word_end= *text; - if (seek_method == ALPHANUM) + switch (seek_method) { + case ALPHANUM: while (my_isalnum(default_charset_info, *word_end)) ++word_end; - else + break; + case NONSPACE: while (!my_isspace(default_charset_info, *word_end) && (*word_end != '\0')) ++word_end; + break; + case OPTION_NAME: + while (my_isalnum(default_charset_info, *word_end) || + *word_end == '-' || + *word_end == '_') + ++word_end; + break; + } *word_len= word_end - *text; } diff --git a/server-tools/instance-manager/parse_output.cc b/server-tools/instance-manager/parse_output.cc index 64bb6a6485f..643a50625a1 100644 --- a/server-tools/instance-manager/parse_output.cc +++ b/server-tools/instance-manager/parse_output.cc @@ -14,13 +14,15 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <my_global.h> -#include "parse.h" #include "parse_output.h" -#include <stdio.h> +#include <my_global.h> #include <my_sys.h> #include <m_string.h> + +#include <stdio.h> + +#include "parse.h" #include "portability.h" diff --git a/server-tools/instance-manager/parse_output.h b/server-tools/instance-manager/parse_output.h index 6a84fabbf17..b86363a4452 100644 --- a/server-tools/instance-manager/parse_output.h +++ b/server-tools/instance-manager/parse_output.h @@ -16,6 +16,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <my_global.h> + #define GET_VALUE 1 #define GET_LINE 2 diff --git a/server-tools/instance-manager/portability.h b/server-tools/instance-manager/portability.h index 1a3be5705e3..a76cff58893 100644 --- a/server-tools/instance-manager/portability.h +++ b/server-tools/instance-manager/portability.h @@ -16,11 +16,25 @@ /*TODO: fix this */ #define PROTOCOL_VERSION 10 +#define DFLT_CONFIG_FILE_NAME "my.ini" +#define DFLT_MYSQLD_PATH "mysqld" +#define DFLT_PASSWD_FILE_EXT ".passwd" +#define DFLT_PID_FILE_EXT ".pid" +#define DFLT_SOCKET_FILE_EXT ".sock" + typedef int pid_t; #undef popen #define popen(A,B) _popen(A,B) +#define NEWLINE "\r\n" +#define NEWLINE_LEN 2 + +#else /* ! __WIN__ */ + +#define NEWLINE "\n" +#define NEWLINE_LEN 1 + #endif /* __WIN__ */ #endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_PORTABILITY_H */ diff --git a/server-tools/instance-manager/priv.cc b/server-tools/instance-manager/priv.cc index d2d6a3f636c..d3cc52ec638 100644 --- a/server-tools/instance-manager/priv.cc +++ b/server-tools/instance-manager/priv.cc @@ -14,10 +14,10 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "priv.h" + #include <my_global.h> #include <mysql_com.h> -#include "priv.h" -#include "portability.h" #if defined(__ia64__) || defined(__ia64) /* @@ -43,9 +43,7 @@ bool linuxthreads; The following string must be less then 80 characters, as mysql_connection.cc relies on it */ -const char mysqlmanager_version[] = "0.2-alpha"; - -const int mysqlmanager_version_length= sizeof(mysqlmanager_version) - 1; +const LEX_STRING mysqlmanager_version= { C_STRING_WITH_SIZE("1.0-beta") }; const unsigned char protocol_version= PROTOCOL_VERSION; diff --git a/server-tools/instance-manager/priv.h b/server-tools/instance-manager/priv.h index 52d7aa1d23d..0b393c17ac2 100644 --- a/server-tools/instance-manager/priv.h +++ b/server-tools/instance-manager/priv.h @@ -16,13 +16,17 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <my_global.h> +#include <m_string.h> +#include <my_pthread.h> + #include <sys/types.h> -#ifdef __WIN__ -#include "portability.h" -#else + +#ifndef __WIN__ #include <unistd.h> #endif -#include "my_pthread.h" + +#include "portability.h" /* IM-wide platform-independent defines */ #define SERVER_DEFAULT_PORT 3306 @@ -31,6 +35,21 @@ /* three-week timeout should be enough */ #define LONG_TIMEOUT ((ulong) 3600L*24L*21L) +const int MEM_ROOT_BLOCK_SIZE= 512; + +/* The maximal length of option name and option value. */ +const int MAX_OPTION_LEN= 1024; + +/* + The maximal length of whole option string: + --<option name>=<option value> +*/ +const int MAX_OPTION_STR_LEN= 2 + MAX_OPTION_LEN + 1 + MAX_OPTION_LEN + 1; + +const int MAX_VERSION_LENGTH= 160; + +const int MAX_INSTANCE_NAME_SIZE= FN_REFLEN; + /* the pid of the manager process (of the signal thread on the LinuxThreads) */ extern pid_t manager_pid; @@ -42,8 +61,7 @@ extern pid_t manager_pid; extern bool linuxthreads; #endif -extern const char mysqlmanager_version[]; -extern const int mysqlmanager_version_length; +extern const LEX_STRING mysqlmanager_version; /* MySQL client-server protocol version: substituted from configure */ extern const unsigned char protocol_version; diff --git a/server-tools/instance-manager/protocol.cc b/server-tools/instance-manager/protocol.cc index 73e07f993ae..4a8c4d0b88d 100644 --- a/server-tools/instance-manager/protocol.cc +++ b/server-tools/instance-manager/protocol.cc @@ -163,7 +163,7 @@ int send_fields(struct st_net *net, LIST *fields) Buffer send_buff; char small_buff[4]; uint position= 0; - NAME_WITH_LENGTH *field; + LEX_STRING *field; /* send the number of fileds */ net_store_length(small_buff, (uint) list_length(fields)); @@ -173,7 +173,7 @@ int send_fields(struct st_net *net, LIST *fields) while (tmp) { position= 0; - field= (NAME_WITH_LENGTH *) tmp->data; + field= (LEX_STRING *) tmp->data; store_to_protocol_packet(&send_buff, (char*) "", &position); /* catalog name */ @@ -184,9 +184,9 @@ int send_fields(struct st_net *net, LIST *fields) store_to_protocol_packet(&send_buff, (char*) "", &position); /* table name alias */ store_to_protocol_packet(&send_buff, - field->name, &position); /* column name */ + field->str, &position); /* column name */ store_to_protocol_packet(&send_buff, - field->name, &position); /* column name alias */ + field->str, &position); /* column name alias */ send_buff.reserve(position, 12); if (send_buff.is_error()) goto err; diff --git a/server-tools/instance-manager/protocol.h b/server-tools/instance-manager/protocol.h index f38eac6b079..2c84ad394b4 100644 --- a/server-tools/instance-manager/protocol.h +++ b/server-tools/instance-manager/protocol.h @@ -20,11 +20,6 @@ #include <my_list.h> -typedef struct field { - char *name; - uint length; -} NAME_WITH_LENGTH; - /* default field length to be used in various field-realted functions */ enum { DEFAULT_FIELD_LENGTH= 20 }; diff --git a/server-tools/instance-manager/thread_registry.cc b/server-tools/instance-manager/thread_registry.cc index 0091d713a91..a424860548d 100644 --- a/server-tools/instance-manager/thread_registry.cc +++ b/server-tools/instance-manager/thread_registry.cc @@ -20,11 +20,12 @@ #include "thread_registry.h" -#include "log.h" +#include <my_global.h> +#include <thr_alarm.h> -#include <assert.h> #include <signal.h> -#include <thr_alarm.h> + +#include "log.h" #ifndef __WIN__ @@ -52,7 +53,7 @@ Thread_info::Thread_info(pthread_t thread_id_arg) : */ Thread_registry::Thread_registry() : - shutdown_in_progress(false) + shutdown_in_progress(FALSE) ,sigwait_thread_pid(pthread_self()) { pthread_mutex_init(&LOCK_thread_registry, 0); @@ -186,7 +187,7 @@ void Thread_registry::deliver_shutdown() set_timespec(shutdown_time, 1); pthread_mutex_lock(&LOCK_thread_registry); - shutdown_in_progress= true; + shutdown_in_progress= TRUE; #ifndef __WIN__ /* to stop reading from the network we need to flush alarm queue */ diff --git a/server-tools/instance-manager/user_management_commands.cc b/server-tools/instance-manager/user_management_commands.cc new file mode 100644 index 00000000000..03a3f9814e3 --- /dev/null +++ b/server-tools/instance-manager/user_management_commands.cc @@ -0,0 +1,406 @@ +#if defined(__GNUC__) && defined(USE_PRAGMA_IMPLEMENTATION) +#pragma implementation +#endif + +#include "user_management_commands.h" + +#include "exit_codes.h" +#include "options.h" +#include "user_map.h" + +/************************************************************************* + Module-specific (internal) functions. +*************************************************************************/ + +/* + The function returns user name. The user name is retrieved from command-line + options (if specified) or from console. + + NOTE + This function must not be used in user-management command implementations. + Use get_user_name() instead. + + SYNOPSYS + get_user_name_impl() + + RETURN + NULL on error + valid pointer on success +*/ + +static char *get_user_name_impl() +{ + static char user_name_buf[1024]; + char *ptr; + + if (Options::User_management::user_name) + return Options::User_management::user_name; + + printf("Enter user name: "); + fflush(stdout); + + if (!fgets(user_name_buf, sizeof (user_name_buf), stdin)) + return NULL; + + if ((ptr= strchr(user_name_buf, '\n'))) + *ptr= 0; + + if ((ptr= strchr(user_name_buf, '\r'))) + *ptr= 0; + + return user_name_buf; +} + + +/* + The function is intended to provide user name for user-management + operations. It also checks that length of the specified user name is correct + (not empty, not exceeds USERNAME_LENGTH). Report to stderr if something is + wrong. + + SYNOPSYS + get_user_name() + user_name [OUT] on success contains user name + + RETURN + TRUE on error + FALSE on success +*/ + +static bool get_user_name(LEX_STRING *user_name) +{ + char *user_name_str= get_user_name_impl(); + + if (!user_name_str) + { + fprintf(stderr, "Error: unable to read user name from stdin.\n"); + return TRUE; + } + + user_name->str= user_name_str; + user_name->length= strlen(user_name->str); + + if (user_name->length == 0) + { + fprintf(stderr, "Error: user name can not be empty.\n"); + return TRUE; + } + + if (user_name->length > USERNAME_LENGTH) + { + fprintf(stderr, "Error: user name must not exceed %d characters.\n", + (int) USERNAME_LENGTH); + return TRUE; + } + + return FALSE; +} + + +/* + The function is intended to provide password for user-management operations. + The password is retrieved from command-line options (if specified) or from + console. + + SYNOPSYS + get_password() + + RETURN + NULL on error + valid pointer on success +*/ + +static const char *get_password() +{ + if (Options::User_management::password) + return Options::User_management::password; + + const char *passwd1= get_tty_password("Enter password: "); + const char *passwd2= get_tty_password("Re-type password: "); + + if (strcmp(passwd1, passwd2)) + { + fprintf(stderr, "Error: passwords do not match.\n"); + return 0; + } + + return passwd1; +} + + +/* + Load password file into user map. + + SYNOPSYS + load_password_file() + user_map target user map + + RETURN + See exit_codes.h for possible values. +*/ + +static int load_password_file(User_map *user_map) +{ + int err_code; + const char *err_msg; + + if (user_map->init()) + { + fprintf(stderr, "Error: can not initialize user map.\n"); + return ERR_OUT_OF_MEMORY; + } + + if ((err_code= user_map->load(Options::Main::password_file_name, &err_msg))) + fprintf(stderr, "Error: %s.\n", (const char *) err_msg); + + return err_code; +} + + +/* + Save user map into password file. + + SYNOPSYS + save_password_file() + user_map user map + + RETURN + See exit_codes.h for possible values. +*/ + +static int save_password_file(User_map *user_map) +{ + int err_code; + const char *err_msg; + + if ((err_code= user_map->save(Options::Main::password_file_name, &err_msg))) + fprintf(stderr, "Error: %s.\n", (const char *) err_msg); + + return err_code; +} + +/************************************************************************* + Passwd_cmd +*************************************************************************/ + +int Passwd_cmd::execute() +{ + LEX_STRING user_name; + const char *password; + + printf("Creating record for new user.\n"); + + if (get_user_name(&user_name)) + return ERR_CAN_NOT_READ_USER_NAME; + + if (!(password= get_password())) + return ERR_CAN_NOT_READ_PASSWORD; + + { + User user(&user_name, password); + + printf("%s:%s\n", + (const char *) user.user, + (const char *) user.scrambled_password); + } + + return ERR_OK; +} + + +/************************************************************************* + Add_user_cmd +*************************************************************************/ + +int Add_user_cmd::execute() +{ + LEX_STRING user_name; + const char *password; + + User_map user_map; + User *new_user; + + int err_code; + + if (get_user_name(&user_name)) + return ERR_CAN_NOT_READ_USER_NAME; + + /* Load the password file. */ + + if ((err_code= load_password_file(&user_map)) != ERR_OK) + return err_code; + + /* Check that the user does not exist. */ + + if (user_map.find_user(&user_name)) + { + fprintf(stderr, "Error: user '%s' already exists.\n", + (const char *) user_name.str); + return ERR_USER_ALREADY_EXISTS; + } + + /* Add the user. */ + + if (!(password= get_password())) + return ERR_CAN_NOT_READ_PASSWORD; + + if (!(new_user= new User(&user_name, password))) + return ERR_OUT_OF_MEMORY; + + if (user_map.add_user(new_user)) + { + delete new_user; + return ERR_OUT_OF_MEMORY; + } + + /* Save the password file. */ + + return save_password_file(&user_map); +} + + +/************************************************************************* + Drop_user_cmd +*************************************************************************/ + +int Drop_user_cmd::execute() +{ + LEX_STRING user_name; + + User_map user_map; + User *user; + + int err_code; + + if (get_user_name(&user_name)) + return ERR_CAN_NOT_READ_USER_NAME; + + /* Load the password file. */ + + if ((err_code= load_password_file(&user_map)) != ERR_OK) + return err_code; + + /* Find the user. */ + + user= user_map.find_user(&user_name); + + if (!user) + { + fprintf(stderr, "Error: user '%s' does not exist.\n", + (const char *) user_name.str); + return ERR_USER_NOT_FOUND; + } + + /* Remove the user (ignore possible errors). */ + + user_map.remove_user(user); + + /* Save the password file. */ + + return save_password_file(&user_map); +} + + +/************************************************************************* + Edit_user_cmd +*************************************************************************/ + +int Edit_user_cmd::execute() +{ + LEX_STRING user_name; + const char *password; + + User_map user_map; + User *user; + + int err_code; + + if (get_user_name(&user_name)) + return ERR_CAN_NOT_READ_USER_NAME; + + /* Load the password file. */ + + if ((err_code= load_password_file(&user_map)) != ERR_OK) + return err_code; + + /* Find the user. */ + + user= user_map.find_user(&user_name); + + if (!user) + { + fprintf(stderr, "Error: user '%s' does not exist.\n", + (const char *) user_name.str); + return ERR_USER_NOT_FOUND; + } + + /* Modify user's password. */ + + if (!(password= get_password())) + return ERR_CAN_NOT_READ_PASSWORD; + + user->set_password(password); + + /* Save the password file. */ + + return save_password_file(&user_map); +} + + +/************************************************************************* + Clean_db_cmd +*************************************************************************/ + +int Clean_db_cmd::execute() +{ + User_map user_map; + + if (user_map.init()) + { + fprintf(stderr, "Error: can not initialize user map.\n"); + return ERR_OUT_OF_MEMORY; + } + + return save_password_file(&user_map); +} + + +/************************************************************************* + Check_db_cmd +*************************************************************************/ + +int Check_db_cmd::execute() +{ + User_map user_map; + + return load_password_file(&user_map); +} + + +/************************************************************************* + List_users_cmd +*************************************************************************/ + +int List_users_cmd::execute() +{ + User_map user_map; + + int err_code; + + /* Load the password file. */ + + if ((err_code= load_password_file(&user_map))) + return err_code; + + /* Print out registered users. */ + + { + User_map::Iterator it(&user_map); + User *user; + + while ((user= it.next())) + fprintf(stderr, "%s\n", (const char *) user->user); + } + + return ERR_OK; +} diff --git a/server-tools/instance-manager/user_management_commands.h b/server-tools/instance-manager/user_management_commands.h new file mode 100644 index 00000000000..4bf3546f0a6 --- /dev/null +++ b/server-tools/instance-manager/user_management_commands.h @@ -0,0 +1,167 @@ +#ifndef INCLUDES_MYSQL_INSTANCE_MANAGER_USER_MANAGEMENT_CMD_H +#define INCLUDES_MYSQL_INSTANCE_MANAGER_USER_MANAGEMENT_CMD_H + +/* + Copyright (C) 2006 MySQL 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 +*/ + +/* + This header contains declarations of classes inteded to support + user-management commands (such as add user, get list of users, etc). + + The general idea is to have one interface (pure abstract class) for such a + command. Each concrete user-management command is implemented in concrete + class, derived from the common interface. +*/ + +#if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE) +#pragma interface +#endif + +/************************************************************************* + User_management_cmd -- base class for User-management commands. +*************************************************************************/ + +class User_management_cmd +{ +public: + User_management_cmd() + { } + + virtual ~User_management_cmd() + { } + +public: + /* + Executes user-management command. + + SYNOPSYS + execute() + + RETURN + See exit_codes.h for possible values. + */ + + virtual int execute() = 0; +}; + + +/************************************************************************* + Passwd_cmd: support for --passwd command-line option. +*************************************************************************/ + +class Passwd_cmd : public User_management_cmd +{ +public: + Passwd_cmd() + { } + +public: + virtual int execute(); +}; + + +/************************************************************************* + Add_user_cmd: support for --add-user command-line option. +*************************************************************************/ + +class Add_user_cmd : public User_management_cmd +{ +public: + Add_user_cmd() + { } + +public: + virtual int execute(); +}; + + +/************************************************************************* + Drop_user_cmd: support for --drop-user command-line option. +*************************************************************************/ + +class Drop_user_cmd : public User_management_cmd +{ +public: + Drop_user_cmd() + { } + +public: + virtual int execute(); +}; + + +/************************************************************************* + Edit_user_cmd: support for --edit-user command-line option. +*************************************************************************/ + +class Edit_user_cmd : public User_management_cmd +{ +public: + Edit_user_cmd() + { } + +public: + virtual int execute(); +}; + + +/************************************************************************* + Clean_db_cmd: support for --clean-db command-line option. +*************************************************************************/ + +class Clean_db_cmd : public User_management_cmd +{ +public: + Clean_db_cmd() + { } + +public: + virtual int execute(); +}; + + +/************************************************************************* + Check_db_cmd: support for --check-db command-line option. +*************************************************************************/ + +class Check_db_cmd : public User_management_cmd +{ +public: + Check_db_cmd() + { } + +public: + virtual int execute(); +}; + + +/************************************************************************* + List_users_cmd: support for --list-users command-line option. +*************************************************************************/ + +class List_users_cmd : public User_management_cmd +{ +public: + List_users_cmd() + { } + +public: + virtual int execute(); +}; + +#endif // INCLUDES_MYSQL_INSTANCE_MANAGER_USER_MANAGEMENT_CMD_H diff --git a/server-tools/instance-manager/user_map.cc b/server-tools/instance-manager/user_map.cc index 9cb15307131..e8128cf015b 100644 --- a/server-tools/instance-manager/user_map.cc +++ b/server-tools/instance-manager/user_map.cc @@ -19,32 +19,32 @@ #endif #include "user_map.h" - -#include <mysql_com.h> -#include <m_string.h> - +#include "exit_codes.h" #include "log.h" +#include "portability.h" -struct User +User::User(const LEX_STRING *user_name_arg, const char *password) { - char user[USERNAME_LENGTH + 1]; - uint8 user_length; - uint8 salt[SCRAMBLE_LENGTH]; - int init(const char *line); -}; + user_length= strmake(user, user_name_arg->str, USERNAME_LENGTH + 1) - user; + set_password(password); +} int User::init(const char *line) { const char *name_begin, *name_end, *password; - int line_ending_len= 1; + int password_length; if (line[0] == '\'' || line[0] == '"') { name_begin= line + 1; name_end= strchr(name_begin, line[0]); if (name_end == 0 || name_end[1] != ':') - goto err; + { + log_info("Error: invalid format (unmatched quote) of user line (%s).", + (const char *) line); + return 1; + } password= name_end + 2; } else @@ -52,33 +52,47 @@ int User::init(const char *line) name_begin= line; name_end= strchr(name_begin, ':'); if (name_end == 0) - goto err; + { + log_info("Error: invalid format (no delimiter) of user line (%s).", + (const char *) line); + return 1; + } password= name_end + 1; } + user_length= name_end - name_begin; if (user_length > USERNAME_LENGTH) - goto err; - - /* - assume that newline characater is present - we support reading password files that end in \n or \r\n on - either platform. - */ - if (password[strlen(password)-2] == '\r') - line_ending_len= 2; - if (strlen(password) != (uint) (SCRAMBLED_PASSWORD_CHAR_LENGTH + - line_ending_len)) - goto err; + { + log_info("Error: user name is too long (%d). Max length: %d. " + "User line: '%s'.", + (int) user_length, + (int) USERNAME_LENGTH, + (const char *) line); + return 1; + } + + password_length= strlen(password); + if (password_length > SCRAMBLED_PASSWORD_CHAR_LENGTH) + { + log_info("Error: password is too long (%d). Max length: %d. ", + "User line: '%s'.", + (int) password_length, + (int) SCRAMBLED_PASSWORD_CHAR_LENGTH, + (const char *) line); + return 1; + } memcpy(user, name_begin, user_length); user[user_length]= 0; + + memcpy(scrambled_password, password, password_length); + scrambled_password[password_length]= 0; + get_salt_from_password(salt, password); - log_info("loaded user %s", user); + + log_info("loaded user '%s'.", user); return 0; -err: - log_error("error parsing user and password at line %s", line); - return 1; } @@ -101,30 +115,70 @@ static void delete_user(void *u) C_MODE_END +void User_map::Iterator::reset() +{ + cur_idx= 0; +} + + +User *User_map::Iterator::next() +{ + if (cur_idx < user_map->hash.records) + return (User *) hash_element(&user_map->hash, cur_idx++); + + return NULL; +} + + int User_map::init() { enum { START_HASH_SIZE= 16 }; if (hash_init(&hash, default_charset_info, START_HASH_SIZE, 0, 0, get_user_key, delete_user, 0)) return 1; + + initialized= TRUE; + return 0; } +User_map::User_map() + :initialized(FALSE) +{ +} + + User_map::~User_map() { - hash_free(&hash); + if (initialized) + hash_free(&hash); } /* - Load all users from the password file. Must be called once right after - construction. - In case of failure, puts error message to the log file and returns 1 + Load password database. + + SYNOPSYS + load() + password_file_name [IN] password file path + err_msg [OUT] error message + + DESCRIPTION + Load all users from the password file. Must be called once right after + construction. In case of failure, puts error message to the log file and + returns specific error code. + + RETURN + 0 on success + !0 on error */ -int User_map::load(const char *password_file_name) +int User_map::load(const char *password_file_name, const char **err_msg) { + static const int ERR_MSG_BUF_SIZE = 255; + static char err_msg_buf[ERR_MSG_BUF_SIZE]; + FILE *file; char line[USERNAME_LENGTH + SCRAMBLED_PASSWORD_CHAR_LENGTH + 2 + /* for possible quotes */ @@ -134,33 +188,172 @@ int User_map::load(const char *password_file_name) User *user; int rc= 1; + if (my_access(password_file_name, F_OK) != 0) + { + if (err_msg) + { + snprintf(err_msg_buf, ERR_MSG_BUF_SIZE, + "password file (%s) does not exist", + (const char *) password_file_name); + *err_msg= err_msg_buf; + } + + return ERR_PASSWORD_FILE_DOES_NOT_EXIST; + } + if ((file= my_fopen(password_file_name, O_RDONLY | O_BINARY, MYF(0))) == 0) { - /* Probably the password file wasn't specified. Try to leave without it */ - log_info("[WARNING] can't open password file %s: errno=%d, %s", password_file_name, - errno, strerror(errno)); - return 0; + if (err_msg) + { + snprintf(err_msg_buf, ERR_MSG_BUF_SIZE, + "can not open password file (%s): %s", + (const char *) password_file_name, + (const char *) strerror(errno)); + *err_msg= err_msg_buf; + } + + return ERR_IO_ERROR; } + log_info("loading the password database..."); + while (fgets(line, sizeof(line), file)) { + char *user_line= line; + + /* + We need to skip EOL-symbols also from the beginning of the line, because + if the previous line was ended by \n\r sequence, we get \r in our line. + */ + + while (user_line[0] == '\r' || user_line[0] == '\n') + ++user_line; + + /* Skip EOL-symbols in the end of the line. */ + + { + char *ptr; + + if ((ptr= strchr(user_line, '\n'))) + *ptr= 0; + + if ((ptr= strchr(user_line, '\r'))) + *ptr= 0; + } + /* skip comments and empty lines */ - if (line[0] == '#' || line[0] == '\n' && - (line[1] == '\0' || line[1] == '\r')) + if (!user_line[0] || user_line[0] == '#') continue; + if ((user= new User) == 0) - goto done; - if (user->init(line) || my_hash_insert(&hash, (byte *) user)) - goto err_init_user; + { + my_fclose(file, MYF(0)); + + if (err_msg) + { + snprintf(err_msg_buf, ERR_MSG_BUF_SIZE, + "out of memory while parsing password file (%s)", + (const char *) password_file_name); + *err_msg= err_msg_buf; + } + + return ERR_OUT_OF_MEMORY; + } + + if (user->init(user_line)) + { + delete user; + my_fclose(file, MYF(0)); + + if (err_msg) + { + snprintf(err_msg_buf, ERR_MSG_BUF_SIZE, + "password file (%s) corrupted", + (const char *) password_file_name); + *err_msg= err_msg_buf; + } + + return ERR_PASSWORD_FILE_CORRUPTED; + } + + if (my_hash_insert(&hash, (byte *) user)) + { + delete user; + my_fclose(file, MYF(0)); + + if (err_msg) + { + snprintf(err_msg_buf, ERR_MSG_BUF_SIZE, + "out of memory while parsing password file (%s)", + (const char *) password_file_name); + *err_msg= err_msg_buf; + } + + return ERR_OUT_OF_MEMORY; + } } - if (feof(file)) - rc= 0; - goto done; -err_init_user: - delete user; -done: + + log_info("the password database loaded successfully."); + my_fclose(file, MYF(0)); - return rc; + + if (err_msg) + *err_msg= NULL; + + return ERR_OK; +} + + +int User_map::save(const char *password_file_name, const char **err_msg) +{ + static const int ERR_MSG_BUF_SIZE = 255; + static char err_msg_buf[ERR_MSG_BUF_SIZE]; + + FILE *file; + + if ((file= my_fopen(password_file_name, O_WRONLY | O_TRUNC | O_BINARY, + MYF(0))) == 0) + { + if (err_msg) + { + snprintf(err_msg_buf, ERR_MSG_BUF_SIZE, + "can not open password file (%s) for writing: %s", + (const char *) password_file_name, + (const char *) strerror(errno)); + *err_msg= err_msg_buf; + } + + return ERR_IO_ERROR; + } + + { + User_map::Iterator it(this); + User *user; + + while ((user= it.next())) + { + if (fprintf(file, "%s:%s\n", (const char *) user->user, + (const char *) user->scrambled_password) < 0) + { + if (err_msg) + { + snprintf(err_msg_buf, ERR_MSG_BUF_SIZE, + "can not write to password file (%s): %s", + (const char *) password_file_name, + (const char *) strerror(errno)); + *err_msg= err_msg_buf; + } + + my_fclose(file, MYF(0)); + + return ERR_IO_ERROR; + } + } + } + + my_fclose(file, MYF(0)); + + return ERR_OK; } @@ -172,13 +365,33 @@ done: 2 - user not found */ -int User_map::authenticate(const char *user_name, uint length, +int User_map::authenticate(const LEX_STRING *user_name, const char *scrambled_password, const char *scramble) const { - const User *user= (const User *) hash_search((HASH *) &hash, - (byte *) user_name, length); - if (user) - return check_scramble(scrambled_password, scramble, user->salt); - return 2; + const User *user= find_user(user_name); + return user ? check_scramble(scrambled_password, scramble, user->salt) : 2; +} + + +User *User_map::find_user(const LEX_STRING *user_name) +{ + return (User*) hash_search(&hash, (byte*) user_name->str, user_name->length); +} + +const User *User_map::find_user(const LEX_STRING *user_name) const +{ + return const_cast<User_map *> (this)->find_user(user_name); +} + + +bool User_map::add_user(User *user) +{ + return my_hash_insert(&hash, (byte*) user) == 0 ? FALSE : TRUE; +} + + +bool User_map::remove_user(User *user) +{ + return hash_delete(&hash, (byte*) user) == 0 ? FALSE : TRUE; } diff --git a/server-tools/instance-manager/user_map.h b/server-tools/instance-manager/user_map.h index 4134017dd9b..de207c11e65 100644 --- a/server-tools/instance-manager/user_map.h +++ b/server-tools/instance-manager/user_map.h @@ -18,14 +18,35 @@ #include <my_global.h> - #include <my_sys.h> +#include <mysql_com.h> +#include <m_string.h> #include <hash.h> #if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE) #pragma interface #endif +struct User +{ + User() + {} + + User(const LEX_STRING *user_name_arg, const char *password); + + int init(const char *line); + + inline void set_password(const char *password) + { + make_scrambled_password(scrambled_password, password); + } + + char user[USERNAME_LENGTH + 1]; + char scrambled_password[SCRAMBLED_PASSWORD_CHAR_LENGTH + 1]; + uint8 user_length; + uint8 salt[SCRAMBLE_LENGTH]; +}; + /* User_map -- all users and passwords */ @@ -33,15 +54,51 @@ class User_map { public: + /* User_map iterator */ + + class Iterator + { + public: + Iterator(User_map *user_map_arg) : + cur_idx(0), user_map(user_map_arg) + { } + + public: + void reset(); + + User *next(); + + private: + User_map *user_map; + uint cur_idx; + }; + +public: + User_map(); ~User_map(); int init(); - int load(const char *password_file_name); - int authenticate(const char *user_name, uint length, + int load(const char *password_file_name, const char **err_msg); + int save(const char *password_file_name, const char **err_msg); + int authenticate(const LEX_STRING *user_name, const char *scrambled_password, const char *scramble) const; + + const User *find_user(const LEX_STRING *user_name) const; + User *find_user(const LEX_STRING *user_name); + + bool add_user(User *user); + bool remove_user(User *user); + +private: + User_map(const User_map &); + User_map &operator =(const User_map &); + private: HASH hash; + bool initialized; + + friend class Iterator; }; #endif // INCLUDES_MYSQL_INSTANCE_MANAGER_USER_MAP_H diff --git a/sql-common/client.c b/sql-common/client.c index 32672ce1201..08d87f9d083 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -1495,6 +1495,7 @@ mysql_ssl_set(MYSQL *mysql __attribute__((unused)) , mysql->options.ssl_ca= strdup_if_not_null(ca); mysql->options.ssl_capath= strdup_if_not_null(capath); mysql->options.ssl_cipher= strdup_if_not_null(cipher); + mysql->options.ssl_verify_server_cert= FALSE; /* Off by default */ #endif /* HAVE_OPENSSL */ DBUG_RETURN(0); } @@ -1509,17 +1510,16 @@ mysql_ssl_set(MYSQL *mysql __attribute__((unused)) , static void mysql_ssl_free(MYSQL *mysql __attribute__((unused))) { - struct st_VioSSLConnectorFd *st= - (struct st_VioSSLConnectorFd*) mysql->connector_fd; + struct st_VioSSLFd *ssl_fd= (struct st_VioSSLFd*) mysql->connector_fd; DBUG_ENTER("mysql_ssl_free"); my_free(mysql->options.ssl_key, MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->options.ssl_cert, MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->options.ssl_ca, MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->options.ssl_capath, MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.ssl_cipher, MYF(MY_ALLOW_ZERO_PTR)); - if (st) - SSL_CTX_free(st->ssl_context); + my_free(mysql->options.ssl_cipher, MYF(MY_ALLOW_ZERO_PTR)); + if (ssl_fd) + SSL_CTX_free(ssl_fd->ssl_context); my_free(mysql->connector_fd,MYF(MY_ALLOW_ZERO_PTR)); mysql->options.ssl_key = 0; mysql->options.ssl_cert = 0; @@ -1551,6 +1551,77 @@ mysql_get_ssl_cipher(MYSQL *mysql) DBUG_RETURN(NULL); } + +/* + Check the server's (subject) Common Name against the + hostname we connected to + + SYNOPSIS + ssl_verify_server_cert() + vio pointer to a SSL connected vio + server_hostname name of the server that we connected to + + RETURN VALUES + 0 Success + 1 Failed to validate server + + */ +static int ssl_verify_server_cert(Vio *vio, const char* server_hostname) +{ + SSL *ssl; + X509 *server_cert; + char *cp1, *cp2; + char buf[256]; + DBUG_ENTER("ssl_verify_server_cert"); + DBUG_PRINT("enter", ("server_hostname: %s", server_hostname)); + + if (!(ssl= (SSL*)vio->ssl_arg)) + { + DBUG_PRINT("error", ("No SSL pointer found")); + DBUG_RETURN(1); + } + + if (!server_hostname) + { + DBUG_PRINT("error", ("No server hostname supplied")); + DBUG_RETURN(1); + } + + if (!(server_cert= SSL_get_peer_certificate(ssl))) + { + DBUG_PRINT("error", ("Could not get server certificate")); + DBUG_RETURN(1); + } + + /* + We already know that the certificate exchanged was valid; the SSL library + handled that. Now we need to verify that the contents of the certificate + are what we expect. + */ + + X509_NAME_oneline(X509_get_subject_name(server_cert), buf, sizeof(buf)); + X509_free (server_cert); + + DBUG_PRINT("info", ("hostname in cert: %s", buf)); + cp1= strstr(buf, "/CN="); + if (cp1) + { + cp1+= 4; /* Skip the "/CN=" that we found */ + /* Search for next / which might be the delimiter for email */ + cp2= strchr(cp1, '/'); + if (cp2) + *cp2= '\0'; + DBUG_PRINT("info", ("Server hostname in cert: %s", cp1)); + if (!strcmp(cp1, server_hostname)) + { + /* Success */ + DBUG_RETURN(0); + } + } + DBUG_PRINT("error", ("SSL certificate validation failure")); + DBUG_RETURN(1); +} + #endif /* HAVE_OPENSSL */ @@ -1584,7 +1655,6 @@ static MYSQL_METHODS client_methods= #endif }; - MYSQL * CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, const char *passwd, const char *db, @@ -2029,37 +2099,52 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, mysql->client_flag=client_flag; #ifdef HAVE_OPENSSL - /* - Oops.. are we careful enough to not send ANY information without - encryption? - */ if (client_flag & CLIENT_SSL) { + /* Do the SSL layering. */ struct st_mysql_options *options= &mysql->options; + struct st_VioSSLFd *ssl_fd; + + /* + Send client_flag, max_packet_size - unencrypted otherwise + the server does not know we want to do SSL + */ if (my_net_write(net,buff,(uint) (end-buff)) || net_flush(net)) { set_mysql_error(mysql, CR_SERVER_LOST, unknown_sqlstate); goto error; } - /* Do the SSL layering. */ - if (!(mysql->connector_fd= - (gptr) new_VioSSLConnectorFd(options->ssl_key, - options->ssl_cert, - options->ssl_ca, - options->ssl_capath, - options->ssl_cipher))) + + /* Create the VioSSLConnectorFd - init SSL and load certs */ + if (!(ssl_fd= new_VioSSLConnectorFd(options->ssl_key, + options->ssl_cert, + options->ssl_ca, + options->ssl_capath, + options->ssl_cipher))) { set_mysql_error(mysql, CR_SSL_CONNECTION_ERROR, unknown_sqlstate); goto error; } + mysql->connector_fd= (void*)ssl_fd; + + /* Connect to the server */ DBUG_PRINT("info", ("IO layer change in progress...")); - if (sslconnect((struct st_VioSSLConnectorFd*)(mysql->connector_fd), - mysql->net.vio, (long) (mysql->options.connect_timeout))) + if (sslconnect(ssl_fd, mysql->net.vio, + (long) (mysql->options.connect_timeout))) { set_mysql_error(mysql, CR_SSL_CONNECTION_ERROR, unknown_sqlstate); goto error; } DBUG_PRINT("info", ("IO layer change done!")); + + /* Verify server cert */ + if (mysql->options.ssl_verify_server_cert && + ssl_verify_server_cert(mysql->net.vio, mysql->host)) + { + set_mysql_error(mysql, CR_SSL_CONNECTION_ERROR, unknown_sqlstate); + goto error; + } + } #endif /* HAVE_OPENSSL */ @@ -2799,6 +2884,9 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg) case MYSQL_OPT_RECONNECT: mysql->reconnect= *(my_bool *) arg; break; + case MYSQL_OPT_SSL_VERIFY_SERVER_CERT: + mysql->options.ssl_verify_server_cert= *(my_bool *) arg; + break; default: DBUG_RETURN(1); } diff --git a/sql-common/my_time.c b/sql-common/my_time.c index c9d39260761..f75298e4f5d 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -689,7 +689,7 @@ long calc_daynr(uint year,uint month,uint day) if (year == 0 && month == 0 && day == 0) DBUG_RETURN(0); /* Skip errors */ - if (year < 200) + if (year < YY_MAGIC_BELOW) { if ((year=year+1900) < 1900+YY_PART_YEAR) year+=100; diff --git a/sql/cmakelists.txt b/sql/CMakeLists.txt index 05b1efdbe51..2b44fbdcc79 100644 --- a/sql/cmakelists.txt +++ b/sql/CMakeLists.txt @@ -51,7 +51,7 @@ ADD_EXECUTABLE(mysqld ../sql-common/client.c derror.cc des_key_file.cc sql_table.cc sql_test.cc sql_trigger.cc sql_udf.cc sql_union.cc sql_update.cc sql_view.cc strfunc.cc table.cc thr_malloc.cc time.cc tztime.cc uniques.cc unireg.cc item_xmlfunc.cc - rpl_tblmap.cc sql_binlog.cc event_executor.cc event_timed.cc + rpl_tblmap.cc sql_binlog.cc event_scheduler.cc event_timed.cc sql_tablespace.cc event.cc ../sql-common/my_user.c partition_info.cc ${PROJECT_SOURCE_DIR}/sql/sql_yacc.cc diff --git a/sql/Makefile.am b/sql/Makefile.am index ba9b58c0c5e..d7a6eac72cc 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -35,7 +35,7 @@ LDADD = $(top_builddir)/vio/libvio.a \ $(top_builddir)/dbug/libdbug.a \ $(top_builddir)/regex/libregex.a \ $(top_builddir)/strings/libmystrings.a @ZLIB_LIBS@ - +mysqld_DEPENDENCIES= @mysql_plugin_libs@ $(LDADD) mysqld_LDADD = @MYSQLD_EXTRA_LDFLAGS@ \ @pstack_libs@ \ @mysql_plugin_libs@ \ @@ -66,7 +66,8 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \ parse_file.h sql_view.h sql_trigger.h \ sql_array.h sql_cursor.h event.h event_priv.h \ sql_plugin.h authors.h sql_partition.h \ - partition_info.h partition_element.h + partition_info.h partition_element.h event_scheduler.h \ + contributors.h mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \ item.cc item_sum.cc item_buff.cc item_func.cc \ item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \ @@ -103,7 +104,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \ tztime.cc my_time.c my_user.c my_decimal.cc\ sp_head.cc sp_pcontext.cc sp_rcontext.cc sp.cc \ sp_cache.cc parse_file.cc sql_trigger.cc \ - event_executor.cc event.cc event_timed.cc \ + event_scheduler.cc event.cc event_timed.cc \ sql_plugin.cc sql_binlog.cc \ sql_builtin.cc sql_tablespace.cc partition_info.cc @@ -122,7 +123,7 @@ DEFS = -DMYSQL_SERVER \ BUILT_SOURCES = sql_yacc.cc sql_yacc.h lex_hash.h EXTRA_DIST = udf_example.cc $(BUILT_SOURCES) \ - nt_servc.cc nt_servc.h message.mc cmakelists.txt + nt_servc.cc nt_servc.h message.mc CMakeLists.txt CLEANFILES = lex_hash.h sql_yacc.cc sql_yacc.h AM_YFLAGS = -d diff --git a/sql/authors.h b/sql/authors.h index 595d14c6e0b..618c6305f6b 100644 --- a/sql/authors.h +++ b/sql/authors.h @@ -57,7 +57,8 @@ struct show_table_authors_st show_table_authors[]= { { "Yves Carlier", "", "mysqlaccess" }, { "Joshua Chamas", "Cupertino, CA, USA", "Concurrent insert, extended date syntax" }, - { "Petr Chardin", "Moscow, Russia", "Instance Manager (5.0)" }, + { "Petr Chardin", "Moscow, Russia", + "Instance Manager (5.0), Server log tables (5.1)" }, { "Wei-Jou Chen", "", "Chinese (Big5) character set" }, { "Albert Chin-A-Young", "", "Tru64 port, large file support, better TCP wrappers support" }, @@ -73,6 +74,7 @@ struct show_table_authors_st show_table_authors[]= { { "Nikolay Grishakin", "Austin, TX, USA", "Testing - Server" }, { "Wei He", "", "Chinese (GBK) character set" }, { "Eric Herman", "Amsterdam, Netherlands", "Bug fixing - federated" }, + { "Andrey Hristov", "Walldorf, Germany", "Event scheduler (5.1)" }, { "Alexander (Alexi) Ivanov", "St. Petersburg, Russia", "Replication" }, { "Alexander (Salle) Keremidarski", "Sofia, Bulgaria", "Bug fixing" }, diff --git a/sql/contributors.h b/sql/contributors.h new file mode 100644 index 00000000000..dca232b9b69 --- /dev/null +++ b/sql/contributors.h @@ -0,0 +1,40 @@ +/* Copyright (C) 2005 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 */ + +/* Structure of the name list */ + +struct show_table_contributors_st { + const char *name; + const char *location; + const char *comment; +}; + +/* + Output from "SHOW CONTRIBUTORS" + + Get permission before editing. + + IMPORTANT: Names should be left in historical order. + + Names should be encoded using UTF-8. +*/ + +struct show_table_contributors_st show_table_contributors[]= { + {"Ronald Bradford", "Brisbane, Australia", "EFF contribution for UC2006 Auction"}, + {"Sheeri Kritzer", "Boston, Mass. USA", "EFF contribution for UC2006 Auction"}, + {"Mark Shuttleworth", "London, UK.", "EFF contribution for UC2006 Auction"}, + {NULL, NULL, NULL} +}; diff --git a/sql/discover.cc b/sql/discover.cc index 2a3da55f154..938a05ff4a7 100644 --- a/sql/discover.cc +++ b/sql/discover.cc @@ -119,8 +119,8 @@ int writefrm(const char *name, const void *frmdata, uint len) { if (my_write(file,(byte*)frmdata,len,MYF(MY_WME | MY_NABP))) error= 2; + VOID(my_close(file,MYF(0))); } - VOID(my_close(file,MYF(0))); DBUG_RETURN(error); } /* writefrm */ diff --git a/sql/event.cc b/sql/event.cc index c049fdc6c61..9ca5c62fc1c 100644 --- a/sql/event.cc +++ b/sql/event.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2005 MySQL AB +/* Copyright (C) 2004-2006 MySQL 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 @@ -16,13 +16,12 @@ #include "event_priv.h" #include "event.h" +#include "event_scheduler.h" #include "sp.h" +#include "sp_head.h" /* TODO list : - - The default value of created/modified should not be 0000-00-00 because of - STRICT mode restricions. - - CREATE EVENT should not go into binary log! Does it now? The SQL statements issued by the EVENT are replicated. I have an idea how to solve the problem at failover. So the status field @@ -38,23 +37,8 @@ ENABLED to DISABLED status change and this is safe for replicating. As well an event may be deleted which is also safe for RBR. - - Maybe move all allocations during parsing to evex_mem_root thus saving - double parsing in evex_create_event! - - - If the server is killed (stopping) try to kill executing events? - - - What happens if one renames an event in the DB while it is in memory? - Or even deleting it? - - - Consider using conditional variable when doing shutdown instead of - waiting till all worker threads end. - - - Make Event_timed::get_show_create_event() work - - Add logging to file - - Move comparison code to class Event_timed - Warning: - For now parallel execution is not possible because the same sp_head cannot be executed few times!!! There is still no lock attached to particular @@ -62,12 +46,26 @@ Warning: */ -QUEUE EVEX_EQ_NAME; MEM_ROOT evex_mem_root; time_t mysql_event_last_create_time= 0L; -static TABLE_FIELD_W_TYPE event_table_fields[EVEX_FIELD_COUNT] = { +const char *event_scheduler_state_names[]= + { "OFF", "0", "ON", "1", "SUSPEND", "2", NullS }; + +TYPELIB Events::opt_typelib= +{ + array_elements(event_scheduler_state_names)-1, + "", + event_scheduler_state_names, + NULL +}; + + +ulong Events::opt_event_scheduler= 2; + +static +TABLE_FIELD_W_TYPE event_table_fields[Events::FIELD_COUNT] = { { {(char *) STRING_WITH_LEN("db")}, {(char *) STRING_WITH_LEN("char(64)")}, @@ -186,41 +184,17 @@ LEX_STRING interval_type_to_name[] = { }; - -/* - Inits the scheduler queue - prioritized queue from mysys/queue.c - - Synopsis - evex_queue_init() - - queue - pointer the the memory to be initialized as queue. has to be - allocated from the caller - - Notes - During initialization the queue is sized for 30 events, and when is full - will auto extent with 30. -*/ - -void -evex_queue_init(EVEX_QUEUE_TYPE *queue) -{ - if (init_queue_ex(queue, 30 /*num_el*/, 0 /*offset*/, 0 /*smallest_on_top*/, - event_timed_compare_q, NULL, 30 /*auto_extent*/)) - sql_print_error("Insufficient memory to initialize executing queue."); -} - - /* Compares 2 LEX strings regarding case. - Synopsis + SYNOPSIS my_time_compare() s - first LEX_STRING t - second LEX_STRING cs - charset - RETURNS: + RETURN VALUE -1 - s < t 0 - s == t 1 - s > t @@ -239,32 +213,26 @@ int sortcmp_lex_string(LEX_STRING s, LEX_STRING t, CHARSET_INFO *cs) /* Compares 2 TIME structures - Synopsis + SYNOPSIS my_time_compare() a - first TIME b - second time - RETURNS: + RETURN VALUE -1 - a < b 0 - a == b 1 - a > b - Notes + NOTES TIME.second_part is not considered during comparison */ int my_time_compare(TIME *a, TIME *b) { - -#ifdef ENABLE_WHEN_WE_HAVE_MILLISECOND_IN_TIMESTAMPS - my_ulonglong a_t= TIME_to_ulonglong_datetime(a)*100L + a->second_part; - my_ulonglong b_t= TIME_to_ulonglong_datetime(b)*100L + b->second_part; -#else my_ulonglong a_t= TIME_to_ulonglong_datetime(a); my_ulonglong b_t= TIME_to_ulonglong_datetime(b); -#endif if (a_t > b_t) return 1; @@ -276,36 +244,11 @@ my_time_compare(TIME *a, TIME *b) /* - Compares the execute_at members of 2 Event_timed instances - - Synopsis - event_timed_compare() - - a - first Event_timed object - b - second Event_timed object - - RETURNS: - -1 - a->execute_at < b->execute_at - 0 - a->execute_at == b->execute_at - 1 - a->execute_at > b->execute_at - - Notes - execute_at.second_part is not considered during comparison -*/ - -int -event_timed_compare(Event_timed *a, Event_timed *b) -{ - return my_time_compare(&a->execute_at, &b->execute_at); -} - - -/* Compares the execute_at members of 2 Event_timed instances. Used as callback for the prioritized queue when shifting elements inside. - Synopsis + SYNOPSIS event_timed_compare() vptr - not used (set it to NULL) @@ -324,7 +267,8 @@ event_timed_compare(Event_timed *a, Event_timed *b) int event_timed_compare_q(void *vptr, byte* a, byte *b) { - return event_timed_compare((Event_timed *)a, (Event_timed *)b); + return my_time_compare(&((Event_timed *)a)->execute_at, + &((Event_timed *)b)->execute_at); } @@ -335,8 +279,8 @@ event_timed_compare_q(void *vptr, byte* a, byte *b) YEAR_MONTH - expression is in months DAY_MINUTE - expression is in minutes - Synopsis - event_reconstruct_interval_expression() + SYNOPSIS + Events::reconstruct_interval_expression() buf - preallocated String buffer to add the value to interval - the interval type (for instance YEAR_MONTH) expression - the value in the lowest entity @@ -347,9 +291,9 @@ event_timed_compare_q(void *vptr, byte* a, byte *b) */ int -event_reconstruct_interval_expression(String *buf, - interval_type interval, - longlong expression) +Events::reconstruct_interval_expression(String *buf, + interval_type interval, + longlong expression) { ulonglong expr= expression; char tmp_buff[128], *end; @@ -466,22 +410,23 @@ common_1_lev_code: Open mysql.event table for read SYNOPSIS - evex_open_event_table() + Events::open_event_table() thd Thread context lock_type How to lock the table table We will store the open table here - RETURN + RETURN VALUE 1 Cannot lock table 2 The table is corrupted - different number of fields 0 OK */ int -evex_open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table) +Events::open_event_table(THD *thd, enum thr_lock_type lock_type, + TABLE **table) { TABLE_LIST tables; - DBUG_ENTER("open_proc_table"); + DBUG_ENTER("open_events_table"); bzero((char*) &tables, sizeof(tables)); tables.db= (char*) "mysql"; @@ -491,7 +436,8 @@ evex_open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table) if (simple_open_n_lock_tables(thd, &tables)) DBUG_RETURN(1); - if (table_check_intact(tables.table, EVEX_FIELD_COUNT, event_table_fields, + if (table_check_intact(tables.table, Events::FIELD_COUNT, + event_table_fields, &mysql_event_last_create_time, ER_CANNOT_LOAD_FROM_TABLE)) { @@ -510,7 +456,7 @@ evex_open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table) SYNOPSIS evex_db_find_event_aux() thd Thread context - et evet_timed object containing dbname, name & definer + et event_timed object containing dbname & name table TABLE object for open mysql.event table. RETURN VALUE @@ -521,8 +467,7 @@ evex_open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table) inline int evex_db_find_event_aux(THD *thd, Event_timed *et, TABLE *table) { - return evex_db_find_event_by_name(thd, et->dbname, et->name, - et->definer, table); + return evex_db_find_event_by_name(thd, et->dbname, et->name, table); } @@ -544,7 +489,6 @@ evex_db_find_event_aux(THD *thd, Event_timed *et, TABLE *table) int evex_db_find_event_by_name(THD *thd, const LEX_STRING dbname, const LEX_STRING ev_name, - const LEX_STRING user_name, TABLE *table) { byte key[MAX_KEY_LENGTH]; @@ -558,16 +502,14 @@ evex_db_find_event_by_name(THD *thd, const LEX_STRING dbname, 'db' and 'name' and the first key is the primary key over the same fields. */ - if (dbname.length > table->field[EVEX_FIELD_DB]->field_length || - ev_name.length > table->field[EVEX_FIELD_NAME]->field_length || - user_name.length > table->field[EVEX_FIELD_DEFINER]->field_length) + if (dbname.length > table->field[Events::FIELD_DB]->field_length || + ev_name.length > table->field[Events::FIELD_NAME]->field_length) DBUG_RETURN(EVEX_KEY_NOT_FOUND); - table->field[EVEX_FIELD_DB]->store(dbname.str, dbname.length, &my_charset_bin); - table->field[EVEX_FIELD_NAME]->store(ev_name.str, ev_name.length, - &my_charset_bin); - table->field[EVEX_FIELD_DEFINER]->store(user_name.str, user_name.length, + table->field[Events::FIELD_DB]->store(dbname.str, dbname.length, + &my_charset_bin); + table->field[Events::FIELD_NAME]->store(ev_name.str, ev_name.length, &my_charset_bin); key_copy(key, table->record[0], table->key_info, @@ -576,34 +518,39 @@ evex_db_find_event_by_name(THD *thd, const LEX_STRING dbname, if (table->file->index_read_idx(table->record[0], 0, key, table->key_info->key_length, HA_READ_KEY_EXACT)) + { + DBUG_PRINT("info", ("Row not found")); DBUG_RETURN(EVEX_KEY_NOT_FOUND); + } + DBUG_PRINT("info", ("Row found!")); DBUG_RETURN(0); } /* - Puts some data common to CREATE and ALTER EVENT into a row. + Puts some data common to CREATE and ALTER EVENT into a row. - SYNOPSIS - evex_fill_row() - thd THD - table the row to fill out - et Event's data + SYNOPSIS + evex_fill_row() + thd THD + table the row to fill out + et Event's data - Returns - 0 - ok - EVEX_GENERAL_ERROR - bad data - EVEX_GET_FIELD_FAILED - field count does not match. table corrupted? + RETURN VALUE + 0 - OK + EVEX_GENERAL_ERROR - bad data + EVEX_GET_FIELD_FAILED - field count does not match. table corrupted? - DESCRIPTION - Used both when an event is created and when it is altered. + DESCRIPTION + Used both when an event is created and when it is altered. */ static int evex_fill_row(THD *thd, TABLE *table, Event_timed *et, my_bool is_update) { - enum evex_table_field field_num; + CHARSET_INFO *scs= system_charset_info; + enum Events::enum_table_field field_num; DBUG_ENTER("evex_fill_row"); @@ -611,19 +558,23 @@ evex_fill_row(THD *thd, TABLE *table, Event_timed *et, my_bool is_update) DBUG_PRINT("info", ("name =[%s]", et->name.str)); DBUG_PRINT("info", ("body =[%s]", et->body.str)); - if (table->field[field_num= EVEX_FIELD_DB]-> - store(et->dbname.str, et->dbname.length, system_charset_info)) - goto trunc_err; + if (table->field[field_num= Events::FIELD_DEFINER]-> + store(et->definer.str, et->definer.length, scs)) + goto err_truncate; + + if (table->field[field_num= Events::FIELD_DB]-> + store(et->dbname.str, et->dbname.length, scs)) + goto err_truncate; - if (table->field[field_num= EVEX_FIELD_NAME]-> - store(et->name.str, et->name.length, system_charset_info)) - goto trunc_err; + if (table->field[field_num= Events::FIELD_NAME]-> + store(et->name.str, et->name.length, scs)) + goto err_truncate; - /* both ON_COMPLETION and STATUS are NOT NULL thus not calling set_notnull() */ - table->field[EVEX_FIELD_ON_COMPLETION]->store((longlong)et->on_completion, - true); + /* both ON_COMPLETION and STATUS are NOT NULL thus not calling set_notnull()*/ + table->field[Events::FIELD_ON_COMPLETION]-> + store((longlong)et->on_completion, true); - table->field[EVEX_FIELD_STATUS]->store((longlong)et->status, true); + table->field[Events::FIELD_STATUS]->store((longlong)et->status, true); /* Change the SQL_MODE only if body was present in an ALTER EVENT and of course @@ -631,53 +582,54 @@ evex_fill_row(THD *thd, TABLE *table, Event_timed *et, my_bool is_update) */ if (et->body.str) { - table->field[EVEX_FIELD_SQL_MODE]->store((longlong)thd->variables.sql_mode, - true); + table->field[Events::FIELD_SQL_MODE]-> + store((longlong)thd->variables.sql_mode, true); - if (table->field[field_num= EVEX_FIELD_BODY]-> - store(et->body.str, et->body.length, system_charset_info)) - goto trunc_err; + if (table->field[field_num= Events::FIELD_BODY]-> + store(et->body.str, et->body.length, scs)) + goto err_truncate; } if (et->expression) { - table->field[EVEX_FIELD_INTERVAL_EXPR]->set_notnull(); - table->field[EVEX_FIELD_INTERVAL_EXPR]->store((longlong)et->expression,true); + table->field[Events::FIELD_INTERVAL_EXPR]->set_notnull(); + table->field[Events::FIELD_INTERVAL_EXPR]-> + store((longlong)et->expression, true); - table->field[EVEX_FIELD_TRANSIENT_INTERVAL]->set_notnull(); + table->field[Events::FIELD_TRANSIENT_INTERVAL]->set_notnull(); /* In the enum (C) intervals start from 0 but in mysql enum valid values start from 1. Thus +1 offset is needed! */ - table->field[EVEX_FIELD_TRANSIENT_INTERVAL]->store((longlong)et->interval+1, - true); + table->field[Events::FIELD_TRANSIENT_INTERVAL]-> + store((longlong)et->interval+1, true); - table->field[EVEX_FIELD_EXECUTE_AT]->set_null(); + table->field[Events::FIELD_EXECUTE_AT]->set_null(); if (!et->starts_null) { - table->field[EVEX_FIELD_STARTS]->set_notnull(); - table->field[EVEX_FIELD_STARTS]-> + table->field[Events::FIELD_STARTS]->set_notnull(); + table->field[Events::FIELD_STARTS]-> store_time(&et->starts, MYSQL_TIMESTAMP_DATETIME); } if (!et->ends_null) { - table->field[EVEX_FIELD_ENDS]->set_notnull(); - table->field[EVEX_FIELD_ENDS]-> + table->field[Events::FIELD_ENDS]->set_notnull(); + table->field[Events::FIELD_ENDS]-> store_time(&et->ends, MYSQL_TIMESTAMP_DATETIME); } } else if (et->execute_at.year) { - table->field[EVEX_FIELD_INTERVAL_EXPR]->set_null(); - table->field[EVEX_FIELD_TRANSIENT_INTERVAL]->set_null(); - table->field[EVEX_FIELD_STARTS]->set_null(); - table->field[EVEX_FIELD_ENDS]->set_null(); + table->field[Events::FIELD_INTERVAL_EXPR]->set_null(); + table->field[Events::FIELD_TRANSIENT_INTERVAL]->set_null(); + table->field[Events::FIELD_STARTS]->set_null(); + table->field[Events::FIELD_ENDS]->set_null(); - table->field[EVEX_FIELD_EXECUTE_AT]->set_notnull(); - table->field[EVEX_FIELD_EXECUTE_AT]->store_time(&et->execute_at, - MYSQL_TIMESTAMP_DATETIME); + table->field[Events::FIELD_EXECUTE_AT]->set_notnull(); + table->field[Events::FIELD_EXECUTE_AT]-> + store_time(&et->execute_at, MYSQL_TIMESTAMP_DATETIME); } else { @@ -688,46 +640,47 @@ evex_fill_row(THD *thd, TABLE *table, Event_timed *et, my_bool is_update) */ } - ((Field_timestamp *)table->field[EVEX_FIELD_MODIFIED])->set_time(); + ((Field_timestamp *)table->field[Events::FIELD_MODIFIED])->set_time(); if (et->comment.str) { - if (table->field[field_num= EVEX_FIELD_COMMENT]->store(et->comment.str, - et->comment.length, - system_charset_info)) - goto trunc_err; + if (table->field[field_num= Events::FIELD_COMMENT]-> + store(et->comment.str, et->comment.length, scs)) + goto err_truncate; } DBUG_RETURN(0); -trunc_err: +err_truncate: my_error(ER_EVENT_DATA_TOO_LONG, MYF(0), table->field[field_num]->field_name); DBUG_RETURN(EVEX_GENERAL_ERROR); } /* - Creates an event in mysql.event - - SYNOPSIS - db_create_event() - thd THD - et Event_timed object containing information for the event - create_if_not - if an warning should be generated in case event exists - rows_affected - how many rows were affected - - Return value - 0 - OK - EVEX_GENERAL_ERROR - Failure - DESCRIPTION - Creates an event. Relies on evex_fill_row which is shared with - db_update_event. The name of the event is inside "et". + Creates an event in mysql.event + + SYNOPSIS + db_create_event() + thd THD + et Event_timed object containing information for the event + create_if_not If an warning should be generated in case event exists + rows_affected How many rows were affected + + RETURN VALUE + 0 - OK + EVEX_GENERAL_ERROR - Failure + + DESCRIPTION + Creates an event. Relies on evex_fill_row which is shared with + db_update_event. The name of the event is inside "et". */ -static int +int db_create_event(THD *thd, Event_timed *et, my_bool create_if_not, uint *rows_affected) { int ret= 0; + CHARSET_INFO *scs= system_charset_info; TABLE *table; char olddb[128]; bool dbchanged= false; @@ -736,7 +689,7 @@ db_create_event(THD *thd, Event_timed *et, my_bool create_if_not, *rows_affected= 0; DBUG_PRINT("info", ("open mysql.event for update")); - if (evex_open_event_table(thd, TL_WRITE, &table)) + if (Events::open_event_table(thd, TL_WRITE, &table)) { my_error(ER_EVENT_OPEN_TABLE_FAILED, MYF(0)); goto err; @@ -781,7 +734,7 @@ db_create_event(THD *thd, Event_timed *et, my_bool create_if_not, goto err; } - if (et->body.length > table->field[EVEX_FIELD_BODY]->field_length) + if (et->body.length > table->field[Events::FIELD_BODY]->field_length) { my_error(ER_TOO_LONG_BODY, MYF(0), et->name.str); goto err; @@ -794,15 +747,7 @@ db_create_event(THD *thd, Event_timed *et, my_bool create_if_not, goto err; } - if ((ret=table->field[EVEX_FIELD_DEFINER]->store(et->definer.str, - et->definer.length, - system_charset_info))) - { - my_error(ER_EVENT_STORE_FAILED, MYF(0), et->name.str, ret); - goto err; - } - - ((Field_timestamp *)table->field[EVEX_FIELD_CREATED])->set_time(); + ((Field_timestamp *)table->field[Events::FIELD_CREATED])->set_time(); /* evex_fill_row() calls my_error() in case of error so no need to @@ -822,8 +767,8 @@ db_create_event(THD *thd, Event_timed *et, my_bool create_if_not, { thd->clear_error(); /* Such a statement can always go directly to binlog, no trans cache */ - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); + thd->binlog_query(THD::MYSQL_QUERY_TYPE, thd->query, thd->query_length, + FALSE, FALSE); } #endif @@ -845,33 +790,38 @@ err: /* - Used to execute ALTER EVENT. Pendant to evex_update_event(). + Used to execute ALTER EVENT. Pendant to Events::update_event(). - SYNOPSIS - db_update_event() - thd THD - sp_name the name of the event to alter - et event's data + SYNOPSIS + db_update_event() + thd THD + sp_name the name of the event to alter + et event's data + + RETURN VALUE + 0 OK + EVEX_GENERAL_ERROR Error occured (my_error() called) - NOTES - sp_name is passed since this is the name of the event to - alter in case of RENAME TO. + NOTES + sp_name is passed since this is the name of the event to + alter in case of RENAME TO. */ static int db_update_event(THD *thd, Event_timed *et, sp_name *new_name) { + CHARSET_INFO *scs= system_charset_info; TABLE *table; int ret= EVEX_OPEN_TABLE_FAILED; DBUG_ENTER("db_update_event"); DBUG_PRINT("enter", ("dbname: %.*s", et->dbname.length, et->dbname.str)); DBUG_PRINT("enter", ("name: %.*s", et->name.length, et->name.str)); - DBUG_PRINT("enter", ("user: %.*s", et->name.length, et->name.str)); + DBUG_PRINT("enter", ("user: %.*s", et->definer.length, et->definer.str)); if (new_name) DBUG_PRINT("enter", ("rename to: %.*s", new_name->m_name.length, new_name->m_name.str)); - if (evex_open_event_table(thd, TL_WRITE, &table)) + if (Events::open_event_table(thd, TL_WRITE, &table)) { my_error(ER_EVENT_OPEN_TABLE_FAILED, MYF(0)); goto err; @@ -880,22 +830,21 @@ db_update_event(THD *thd, Event_timed *et, sp_name *new_name) /* first look whether we overwrite */ if (new_name) { - if (!sortcmp_lex_string(et->name, new_name->m_name, system_charset_info) && - !sortcmp_lex_string(et->dbname, new_name->m_db, system_charset_info)) + if (!sortcmp_lex_string(et->name, new_name->m_name, scs) && + !sortcmp_lex_string(et->dbname, new_name->m_db, scs)) { my_error(ER_EVENT_SAME_NAME, MYF(0), et->name.str); goto err; } - if (!evex_db_find_event_by_name(thd, new_name->m_db, new_name->m_name, - et->definer, table)) + if (!evex_db_find_event_by_name(thd,new_name->m_db,new_name->m_name,table)) { my_error(ER_EVENT_ALREADY_EXISTS, MYF(0), new_name->m_name.str); goto err; } } /* - ...and then whether there is such an event. don't exchange the blocks + ...and then if there is such an event. Don't exchange the blocks because you will get error 120 from table handler because new_name will overwrite the key and SE will tell us that it cannot find the already found row (copied into record[1] later @@ -911,16 +860,19 @@ db_update_event(THD *thd, Event_timed *et, sp_name *new_name) /* Don't update create on row update. */ table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET; - /* evex_fill_row() calls my_error() in case of error so no need to handle it here */ + /* + evex_fill_row() calls my_error() in case of error so no need to + handle it here + */ if ((ret= evex_fill_row(thd, table, et, true))) goto err; if (new_name) { - table->field[EVEX_FIELD_DB]-> - store(new_name->m_db.str, new_name->m_db.length, system_charset_info); - table->field[EVEX_FIELD_NAME]-> - store(new_name->m_name.str, new_name->m_name.length, system_charset_info); + table->field[Events::FIELD_DB]-> + store(new_name->m_db.str, new_name->m_db.length, scs); + table->field[Events::FIELD_NAME]-> + store(new_name->m_name.str, new_name->m_name.length, scs); } if ((ret= table->file->ha_update_row(table->record[1], table->record[0]))) @@ -941,33 +893,32 @@ err: /* - Looks for a named event in mysql.event and in case of success returns - an object will data loaded from the table. - - SYNOPSIS - db_find_event() - thd THD - name the name of the event to find - definer who owns the event - ett event's data if event is found - tbl TABLE object to use when not NULL - - NOTES - 1) Use sp_name for look up, return in **ett if found - 2) tbl is not closed at exit - - RETURN - 0 ok In this case *ett is set to the event - # error *ett == 0 + Looks for a named event in mysql.event and in case of success returns + an object will data loaded from the table. + + SYNOPSIS + db_find_event() + thd THD + name the name of the event to find + ett event's data if event is found + tbl TABLE object to use when not NULL + + NOTES + 1) Use sp_name for look up, return in **ett if found + 2) tbl is not closed at exit + + RETURN VALUE + 0 ok In this case *ett is set to the event + # error *ett == 0 */ -static int -db_find_event(THD *thd, sp_name *name, LEX_STRING *definer, Event_timed **ett, - TABLE *tbl, MEM_ROOT *root) +int +db_find_event(THD *thd, sp_name *name, Event_timed **ett, TABLE *tbl, + MEM_ROOT *root) { TABLE *table; int ret; - Event_timed *et= 0; + Event_timed *et= NULL; DBUG_ENTER("db_find_event"); DBUG_PRINT("enter", ("name: %*s", name->m_name.length, name->m_name.str)); @@ -976,15 +927,14 @@ db_find_event(THD *thd, sp_name *name, LEX_STRING *definer, Event_timed **ett, if (tbl) table= tbl; - else if (evex_open_event_table(thd, TL_READ, &table)) + else if (Events::open_event_table(thd, TL_READ, &table)) { my_error(ER_EVENT_OPEN_TABLE_FAILED, MYF(0)); ret= EVEX_GENERAL_ERROR; goto done; } - if ((ret= evex_db_find_event_by_name(thd, name->m_db, name->m_name, *definer, - table))) + if ((ret= evex_db_find_event_by_name(thd, name->m_db, name->m_name, table))) { my_error(ER_EVENT_DOES_NOT_EXIST, MYF(0), name->m_name.str); goto done; @@ -1018,179 +968,43 @@ done: /* - Looks for a named event in mysql.event and then loads it from - the table, compiles it and insert it into the cache. - - SYNOPSIS - evex_load_and_compile_event() - thd THD - spn the name of the event to alter - definer who is the owner - use_lock whether to obtain a lock on LOCK_event_arrays or not - - RETURN VALUE - 0 - OK - < 0 - error (in this case underlying functions call my_error()). -*/ - -static int -evex_load_and_compile_event(THD * thd, sp_name *spn, LEX_STRING definer, - bool use_lock) -{ - int ret= 0; - MEM_ROOT *tmp_mem_root; - Event_timed *ett; - Open_tables_state backup; - - DBUG_ENTER("db_load_and_compile_event"); - DBUG_PRINT("enter", ("name: %*s", spn->m_name.length, spn->m_name.str)); + The function exported to the world for creating of events. - tmp_mem_root= thd->mem_root; - thd->mem_root= &evex_mem_root; - - thd->reset_n_backup_open_tables_state(&backup); - /* no need to use my_error() here because db_find_event() has done it */ - ret= db_find_event(thd, spn, &definer, &ett, NULL, NULL); - thd->restore_backup_open_tables_state(&backup); - if (ret) - goto done; - - ett->compute_next_execution_time(); - if (use_lock) - VOID(pthread_mutex_lock(&LOCK_event_arrays)); - - evex_queue_insert(&EVEX_EQ_NAME, (EVEX_PTOQEL) ett); - - /* - There is a copy in the array which we don't need. sphead won't be - destroyed. - */ - - if (use_lock) - VOID(pthread_mutex_unlock(&LOCK_event_arrays)); - -done: - if (thd->mem_root != tmp_mem_root) - thd->mem_root= tmp_mem_root; - - DBUG_RETURN(ret); -} - - -/* - Removes from queue in memory the event which is identified by the tupple - (db, name). - - SYNOPSIS - evex_remove_from_cache() - - db - db name - name - event name - use_lock - whether to lock the mutex LOCK_event_arrays or not in case it - has been already locked outside - is_drop - if an event is currently being executed then we can also delete - the Event_timed instance, so we alarm the event that it should - drop itself if this parameter is set to TRUE. It's false on - ALTER EVENT. - - RETURNS - 0 OK (always) -*/ - -static int -evex_remove_from_cache(LEX_STRING *db, LEX_STRING *name, bool use_lock, - bool is_drop) -{ - //ToDo : Add definer to the tuple (db, name) to become triple - uint i; - int ret= 0; - - DBUG_ENTER("evex_remove_from_cache"); - /* - It is possible that 2 (or 1) pass(es) won't find the event in memory. - The reason is that DISABLED events are not cached. - */ - - if (use_lock) - VOID(pthread_mutex_lock(&LOCK_event_arrays)); - - for (i= 0; i < evex_queue_num_elements(EVEX_EQ_NAME); ++i) - { - Event_timed *et= evex_queue_element(&EVEX_EQ_NAME, i, Event_timed*); - DBUG_PRINT("info", ("[%s.%s]==[%s.%s]?",db->str,name->str, et->dbname.str, - et->name.str)); - if (!sortcmp_lex_string(*name, et->name, system_charset_info) && - !sortcmp_lex_string(*db, et->dbname, system_charset_info)) - { - if (et->can_spawn_now()) - { - DBUG_PRINT("evex_remove_from_cache", ("not running - free and delete")); - et->free_sp(); - delete et; - } - else - { - DBUG_PRINT("evex_remove_from_cache", - ("running.defer mem free. is_drop=%d", is_drop)); - et->flags|= EVENT_EXEC_NO_MORE; - et->dropped= is_drop; - } - DBUG_PRINT("evex_remove_from_cache", ("delete from queue")); - evex_queue_delete_element(&EVEX_EQ_NAME, i); - /* ok, we have cleaned */ - ret= 0; - goto done; - } - } - -done: - if (use_lock) - VOID(pthread_mutex_unlock(&LOCK_event_arrays)); - - DBUG_RETURN(ret); -} + SYNOPSIS + Events::create_event() + thd THD + et event's data + create_options Options specified when in the query. We are + interested whether there is IF NOT EXISTS + rows_affected How many rows were affected + RETURN VALUE + 0 OK + !0 Error -/* - The function exported to the world for creating of events. - - SYNOPSIS - evex_create_event() - thd THD - et event's data - create_options Options specified when in the query. We are - interested whether there is IF NOT EXISTS - rows_affected How many rows were affected - - NOTES - - in case there is an event with the same name (db) and - IF NOT EXISTS is specified, an warning is put into the W stack. + NOTES + - in case there is an event with the same name (db) and + IF NOT EXISTS is specified, an warning is put into the W stack. */ int -evex_create_event(THD *thd, Event_timed *et, uint create_options, - uint *rows_affected) +Events::create_event(THD *thd, Event_timed *et, uint create_options, + uint *rows_affected) { - int ret = 0; + int ret; - DBUG_ENTER("evex_create_event"); + DBUG_ENTER("Events::create_event"); DBUG_PRINT("enter", ("name: %*s options:%d", et->name.length, et->name.str, create_options)); - if ((ret = db_create_event(thd, et, + if (!(ret = db_create_event(thd, et, create_options & HA_LEX_CREATE_IF_NOT_EXISTS, rows_affected))) - goto done; - - VOID(pthread_mutex_lock(&LOCK_evex_running)); - if (evex_is_running && et->status == MYSQL_EVENT_ENABLED) { - sp_name spn(et->dbname, et->name); - ret= evex_load_and_compile_event(thd, &spn, et->definer, true); + Event_scheduler *scheduler= Event_scheduler::get_instance(); + if (scheduler->initialized() && (ret= scheduler->add_event(thd, et, true))) + my_error(ER_EVENT_MODIFY_QUEUE_ERROR, MYF(0), ret); } - VOID(pthread_mutex_unlock(&LOCK_evex_running)); - -done: /* No need to close the table, it will be closed in sql_parse::do_command */ DBUG_RETURN(ret); @@ -1198,73 +1012,63 @@ done: /* - The function exported to the world for alteration of events. - - SYNOPSIS - evex_update_event() - thd THD - et event's data - new_name set in case of RENAME TO. - - NOTES - et contains data about dbname and event name. - new_name is the new name of the event, if not null (this means - that RENAME TO was specified in the query) + The function exported to the world for alteration of events. + + SYNOPSIS + Events::update_event() + thd THD + et event's data + new_name set in case of RENAME TO. + + RETURN VALUE + 0 OK + !0 Error + + NOTES + et contains data about dbname and event name. + new_name is the new name of the event, if not null (this means + that RENAME TO was specified in the query) */ int -evex_update_event(THD *thd, Event_timed *et, sp_name *new_name, - uint *rows_affected) +Events::update_event(THD *thd, Event_timed *et, sp_name *new_name, + uint *rows_affected) { int ret; - bool need_second_pass= true; - DBUG_ENTER("evex_update_event"); + DBUG_ENTER("Events::update_event"); DBUG_PRINT("enter", ("name: %*s", et->name.length, et->name.str)); - /* db_update_event() opens & closes the table to prevent crash later in the code when loading and compiling the new definition. Also on error conditions my_error() is called so no need to handle here */ - if ((ret= db_update_event(thd, et, new_name))) - goto done; - - VOID(pthread_mutex_lock(&LOCK_evex_running)); - if (!evex_is_running) - UNLOCK_MUTEX_AND_BAIL_OUT(LOCK_evex_running, done); - - VOID(pthread_mutex_lock(&LOCK_event_arrays)); - evex_remove_from_cache(&et->dbname, &et->name, false, false); - if (et->status == MYSQL_EVENT_ENABLED) + if (!(ret= db_update_event(thd, et, new_name))) { - if (new_name) - ret= evex_load_and_compile_event(thd, new_name, et->definer, false); - else - { - sp_name spn(et->dbname, et->name); - ret= evex_load_and_compile_event(thd, &spn, et->definer, false); - } - if (ret == EVEX_COMPILE_ERROR) - my_error(ER_EVENT_COMPILE_ERROR, MYF(0)); + Event_scheduler *scheduler= Event_scheduler::get_instance(); + if (scheduler->initialized() && + (ret= scheduler->replace_event(thd, et, + new_name? &new_name->m_db: NULL, + new_name? &new_name->m_name: NULL))) + my_error(ER_EVENT_MODIFY_QUEUE_ERROR, MYF(0), ret); } - VOID(pthread_mutex_unlock(&LOCK_event_arrays)); - VOID(pthread_mutex_unlock(&LOCK_evex_running)); - -done: DBUG_RETURN(ret); } /* - Drops an event - - SYNOPSIS - db_drop_event() - thd THD - et event's name - drop_if_exists if set and the event not existing => warning onto the stack - rows_affected affected number of rows is returned heres + Drops an event + + SYNOPSIS + db_drop_event() + thd THD + et event's name + drop_if_exists if set and the event not existing => warning onto the stack + rows_affected affected number of rows is returned heres + + RETURN VALUE + 0 OK + !0 Error (my_error() called) */ int db_drop_event(THD *thd, Event_timed *et, bool drop_if_exists, @@ -1278,7 +1082,7 @@ int db_drop_event(THD *thd, Event_timed *et, bool drop_if_exists, ret= EVEX_OPEN_TABLE_FAILED; thd->reset_n_backup_open_tables_state(&backup); - if (evex_open_event_table(thd, TL_WRITE, &table)) + if (Events::open_event_table(thd, TL_WRITE, &table)) { my_error(ER_EVENT_OPEN_TABLE_FAILED, MYF(0)); goto done; @@ -1318,58 +1122,53 @@ done: /* - Drops an event - - SYNOPSIS - evex_drop_event() - thd THD - et event's name - drop_if_exists if set and the event not existing => warning onto the stack - rows_affected affected number of rows is returned heres - + Drops an event + + SYNOPSIS + Events::drop_event() + thd THD + et event's name + drop_if_exists if set and the event not existing => warning onto the stack + rows_affected affected number of rows is returned heres + + RETURN VALUE + 0 OK + !0 Error (reported) */ int -evex_drop_event(THD *thd, Event_timed *et, bool drop_if_exists, - uint *rows_affected) +Events::drop_event(THD *thd, Event_timed *et, bool drop_if_exists, + uint *rows_affected) { - int ret= 0; - - DBUG_ENTER("evex_drop_event"); - - - VOID(pthread_mutex_lock(&LOCK_evex_running)); - if (evex_is_running) - ret= evex_remove_from_cache(&et->dbname, &et->name, true, true); - VOID(pthread_mutex_unlock(&LOCK_evex_running)); + int ret; - if (ret == 1) - ret= 0; - else if (ret == 0) - ret= db_drop_event(thd, et, drop_if_exists, rows_affected); - else - my_error(ER_UNKNOWN_ERROR, MYF(0)); + DBUG_ENTER("Events::drop_event"); + if (!(ret= db_drop_event(thd, et, drop_if_exists, rows_affected))) + { + Event_scheduler *scheduler= Event_scheduler::get_instance(); + if (scheduler->initialized() && (ret= scheduler->drop_event(thd, et))) + my_error(ER_EVENT_MODIFY_QUEUE_ERROR, MYF(0), ret); + } DBUG_RETURN(ret); } /* - SHOW CREATE EVENT + SHOW CREATE EVENT - SYNOPSIS - evex_show_create_event() - thd THD - spn the name of the event (db, name) - definer the definer of the event + SYNOPSIS + Events::show_create_event() + thd THD + spn the name of the event (db, name) - RETURNS - 0 - OK - 1 - Error during writing to the wire + RETURN VALUE + 0 OK + 1 Error during writing to the wire */ int -evex_show_create_event(THD *thd, sp_name *spn, LEX_STRING definer) +Events::show_create_event(THD *thd, sp_name *spn) { int ret; Event_timed *et= NULL; @@ -1379,10 +1178,10 @@ evex_show_create_event(THD *thd, sp_name *spn, LEX_STRING definer) DBUG_PRINT("enter", ("name: %*s", spn->m_name.length, spn->m_name.str)); thd->reset_n_backup_open_tables_state(&backup); - ret= db_find_event(thd, spn, &definer, &et, NULL, thd->mem_root); + ret= db_find_event(thd, spn, &et, NULL, thd->mem_root); thd->restore_backup_open_tables_state(&backup); - if (et) + if (!ret) { Protocol *protocol= thd->protocol; char show_str_buf[768]; @@ -1392,12 +1191,10 @@ evex_show_create_event(THD *thd, sp_name *spn, LEX_STRING definer) ulong sql_mode_len=0; show_str.length(0); + show_str.set_charset(system_charset_info); if (et->get_create_event(thd, &show_str)) - { - delete et; - DBUG_RETURN(1); - } + goto err; field_list.push_back(new Item_empty_string("Event", NAME_LEN)); @@ -1411,203 +1208,218 @@ evex_show_create_event(THD *thd, sp_name *spn, LEX_STRING definer) show_str.length())); if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - { - delete et; - DBUG_RETURN(1); - } + goto err; + protocol->prepare_for_resend(); protocol->store(et->name.str, et->name.length, system_charset_info); protocol->store((char*) sql_mode_str, sql_mode_len, system_charset_info); - protocol->store(show_str.ptr(), show_str.length(), system_charset_info); + protocol->store(show_str.c_ptr(), show_str.length(), system_charset_info); ret= protocol->write(); send_eof(thd); - delete et; } - + delete et; DBUG_RETURN(ret); +err: + delete et; + DBUG_RETURN(1); } /* - evex_drop_db_events - Drops all events in the selected database + Drops all events from a schema - thd - Thread - db - ASCIIZ the name of the database - - Returns: - 0 - OK - 1 - Failed to delete a specific row - 2 - Got NULL while reading db name from a row - - Note: - The algo is the following - 1. Go through the in-memory cache, if the scheduler is working - and for every event whose dbname matches the database we drop - check whether is currently in execution: - - Event_timed::can_spawn() returns true -> the event is not - being executed in a child thread. The reason not to use - Event_timed::is_running() is that the latter shows only if - it is being executed, which is 99% of the time in the thread - but there are some initiliazations before and after the - anonymous SP is being called. So if we delete in this moment - -=> *boom*, so we have to check whether the thread has been - spawned and can_spawn() is the right method. - - Event_timed::can_spawn() returns false -> being runned ATM - just set the flags so it should drop itself. + SYNOPSIS + Events::drop_schema_events() + thd Thread + db ASCIIZ schema name + + RETURN VALUE + 0 OK + !0 Error */ int -evex_drop_db_events(THD *thd, char *db) +Events::drop_schema_events(THD *thd, char *db) { - TABLE *table; - READ_RECORD read_record_info; int ret= 0; - uint i; LEX_STRING db_lex= {db, strlen(db)}; DBUG_ENTER("evex_drop_db_events"); - DBUG_PRINT("info",("dropping events from %s", db)); + DBUG_PRINT("enter", ("dropping events from %s", db)); - VOID(pthread_mutex_lock(&LOCK_event_arrays)); + Event_scheduler *scheduler= Event_scheduler::get_instance(); + if (scheduler->initialized()) + ret= scheduler->drop_schema_events(thd, &db_lex); + else + ret= db_drop_events_from_table(thd, &db_lex); - if ((ret= evex_open_event_table(thd, TL_WRITE, &table))) - { - if (errno != ENOENT) - sql_print_error("Table mysql.event is damaged. Got errno: %d on open", - my_errno); - VOID(pthread_mutex_unlock(&LOCK_event_arrays)); - DBUG_RETURN(SP_OPEN_TABLE_FAILED); - } + DBUG_RETURN(ret); +} - DBUG_PRINT("info",("%d elements in the queue", - evex_queue_num_elements(EVEX_EQ_NAME))); - VOID(pthread_mutex_lock(&LOCK_evex_running)); - if (!evex_is_running) - goto skip_memory; - for (i= 0; i < evex_queue_num_elements(EVEX_EQ_NAME); ++i) - { - Event_timed *et= evex_queue_element(&EVEX_EQ_NAME, i, Event_timed*); - if (sortcmp_lex_string(et->dbname, db_lex, system_charset_info)) - continue; +/* + Drops all events in the selected database, from mysql.event. - if (et->can_spawn_now_n_lock(thd)) - { - DBUG_PRINT("info",("event %s not running - direct delete", et->name.str)); - if (!(ret= evex_db_find_event_aux(thd, et, table))) - { - DBUG_PRINT("info",("event %s found on disk", et->name.str)); - if ((ret= table->file->ha_delete_row(table->record[0]))) - { - sql_print_error("Error while deleting a row - dropping " - "a database. Skipping the rest."); - my_error(ER_EVENT_DROP_FAILED, MYF(0), et->name.str); - goto end; - } - DBUG_PRINT("info",("deleted event [%s] num [%d]. Time to free mem", - et->name.str, i)); - } - else if (ret == EVEX_KEY_NOT_FOUND) - { - sql_print_error("Expected to find event %s.%s of %s on disk-not there.", - et->dbname.str, et->name.str, et->definer.str); - } - et->free_sp(); - delete et; - et= 0; - /* no need to call et->spawn_unlock because we already cleaned et */ - } - else - { - DBUG_PRINT("info",("event %s is running. setting exec_no_more and dropped", - et->name.str)); - et->flags|= EVENT_EXEC_NO_MORE; - et->dropped= TRUE; - } - DBUG_PRINT("info",("%d elements in the queue", - evex_queue_num_elements(EVEX_EQ_NAME))); - evex_queue_delete_element(&EVEX_EQ_NAME, i);// 0 is top - DBUG_PRINT("info",("%d elements in the queue", - evex_queue_num_elements(EVEX_EQ_NAME))); - /* - decrease so we start at the same position, there will be - less elements in the queue, it will still be ordered so on - next iteration it will be again i the current element or if - no more we finish. - */ - --i; - } + SYNOPSIS + evex_drop_db_events_from_table() + thd Thread + db Schema name -skip_memory: - /* - The reasoning behind having two loops is the following: - If there was only one loop, the table-scan, then for every element which - matches, the queue in memory has to be searched to remove the element. - While if we go first over the queue and remove what's in there we have only - one pass over it and after finishing it, moving to table-scan for the disabled - events. This needs quite less time and means quite less locking on - LOCK_event_arrays. - */ - DBUG_PRINT("info",("Mem-cache checked, now going to db for disabled events")); + RETURN VALUE + 0 OK + !0 Error from ha_delete_row +*/ + +int +db_drop_events_from_table(THD *thd, LEX_STRING *db) +{ + int ret; + TABLE *table; + READ_RECORD read_record_info; + DBUG_ENTER("db_drop_events_from_table"); + DBUG_PRINT("info", ("dropping events from %s", db->str)); + + if ((ret= Events::open_event_table(thd, TL_WRITE, &table))) + { + if (my_errno != ENOENT) + sql_print_error("Table mysql.event is damaged. Got error %d on open", + my_errno); + DBUG_RETURN(ret); + } /* only enabled events are in memory, so we go now and delete the rest */ - init_read_record(&read_record_info, thd, table ,NULL,1,0); + init_read_record(&read_record_info, thd, table, NULL, 1, 0); while (!(read_record_info.read_record(&read_record_info)) && !ret) { - char *et_db; + char *et_db= get_field(thd->mem_root, + table->field[Events::FIELD_DB]); - if ((et_db= get_field(thd->mem_root, table->field[EVEX_FIELD_DB])) == NULL) - { - ret= 2; - break; - } - LEX_STRING et_db_lex= {et_db, strlen(et_db)}; - if (!sortcmp_lex_string(et_db_lex, db_lex, system_charset_info)) + DBUG_PRINT("info", ("Current event %s.%s", et_db, + get_field(thd->mem_root, + table->field[Events::FIELD_NAME]))); + + if (!sortcmp_lex_string(et_db_lex, *db, system_charset_info)) { - Event_timed ett; - char *ptr; - - if ((ptr= get_field(thd->mem_root, table->field[EVEX_FIELD_STATUS])) - == NullS) - { - sql_print_error("Error while loading from mysql.event. " - "Table probably corrupted"); - goto end; - } - /* - When not running nothing is in memory so we have to clean - everything. - We don't delete EVENT_ENABLED events when the scheduler is running - because maybe this is an event which we asked to drop itself when - it is finished and it hasn't finished yet, so we don't touch it. - It will drop itself. The not running ENABLED events has been already - deleted from ha_delete_row() above in the loop over the QUEUE - (in case the executor is running). - 'D' stands for DISABLED, 'E' for ENABLED - it's an enum - */ - if ((evex_is_running && ptr[0] == 'D') || !evex_is_running) - { - DBUG_PRINT("info", ("Dropping %s.%s", et_db, ett.name.str)); - if ((ret= table->file->ha_delete_row(table->record[0]))) - { - my_error(ER_EVENT_DROP_FAILED, MYF(0), ett.name.str); - goto end; - } - } + DBUG_PRINT("info", ("Dropping")); + if ((ret= table->file->ha_delete_row(table->record[0]))) + my_error(ER_EVENT_DROP_FAILED, MYF(0), + get_field(thd->mem_root, + table->field[Events::FIELD_NAME])); } } - DBUG_PRINT("info",("Disk checked for disabled events. Finishing.")); - -end: - VOID(pthread_mutex_unlock(&LOCK_evex_running)); - VOID(pthread_mutex_unlock(&LOCK_event_arrays)); end_read_record(&read_record_info); - thd->version--; /* Force close to free memory */ close_thread_tables(thd); DBUG_RETURN(ret); } + + + +/* + Inits the scheduler's structures. + + SYNOPSIS + Events::init() + + NOTES + This function is not synchronized. + + RETURN VALUE + 0 OK + 1 Error +*/ + +int +Events::init() +{ + int ret= 0; + DBUG_ENTER("Events::init"); + + /* it should be an assignment! */ + if (opt_event_scheduler) + { + Event_scheduler *scheduler= Event_scheduler::get_instance(); + DBUG_ASSERT(opt_event_scheduler == 1 || opt_event_scheduler == 2); + DBUG_RETURN(scheduler->init() || + (opt_event_scheduler == 1? scheduler->start(): + scheduler->start_suspended())); + } + DBUG_RETURN(0); +} + + +/* + Cleans up scheduler's resources. Called at server shutdown. + + SYNOPSIS + Events::shutdown() + + NOTES + This function is not synchronized. +*/ + +void +Events::shutdown() +{ + DBUG_ENTER("Events::shutdown"); + Event_scheduler *scheduler= Event_scheduler::get_instance(); + if (scheduler->initialized()) + { + scheduler->stop(); + scheduler->destroy(); + } + + DBUG_VOID_RETURN; +} + + +/* + Proxy for Event_scheduler::dump_internal_status + + SYNOPSIS + Events::dump_internal_status() + thd Thread + + RETURN VALUE + 0 OK + !0 Error +*/ + +int +Events::dump_internal_status(THD *thd) +{ + return Event_scheduler::dump_internal_status(thd); +} + + +/* + Inits Events mutexes + + SYNOPSIS + Events::init_mutexes() + thd Thread +*/ + +void +Events::init_mutexes() +{ + Event_scheduler::init_mutexes(); +} + + +/* + Destroys Events mutexes + + SYNOPSIS + Events::destroy_mutexes() +*/ + +void +Events::destroy_mutexes() +{ + Event_scheduler::destroy_mutexes(); +} diff --git a/sql/event.h b/sql/event.h index 27de8b46e32..02c5fa78150 100644 --- a/sql/event.h +++ b/sql/event.h @@ -1,4 +1,6 @@ -/* Copyright (C) 2004-2005 MySQL AB +#ifndef _EVENT_H_ +#define _EVENT_H_ +/* Copyright (C) 2004-2006 MySQL 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 @@ -14,66 +16,109 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _EVENT_H_ -#define _EVENT_H_ -#include "sp.h" -#include "sp_head.h" - -#define EVEX_OK SP_OK -#define EVEX_KEY_NOT_FOUND SP_KEY_NOT_FOUND -#define EVEX_OPEN_TABLE_FAILED SP_OPEN_TABLE_FAILED -#define EVEX_WRITE_ROW_FAILED SP_WRITE_ROW_FAILED -#define EVEX_DELETE_ROW_FAILED SP_DELETE_ROW_FAILED -#define EVEX_GET_FIELD_FAILED SP_GET_FIELD_FAILED -#define EVEX_PARSE_ERROR SP_PARSE_ERROR -#define EVEX_INTERNAL_ERROR SP_INTERNAL_ERROR -#define EVEX_NO_DB_ERROR SP_NO_DB_ERROR + +#define EVEX_OK 0 +#define EVEX_KEY_NOT_FOUND -1 +#define EVEX_OPEN_TABLE_FAILED -2 +#define EVEX_WRITE_ROW_FAILED -3 +#define EVEX_DELETE_ROW_FAILED -4 +#define EVEX_GET_FIELD_FAILED -5 +#define EVEX_PARSE_ERROR -6 +#define EVEX_INTERNAL_ERROR -7 +#define EVEX_NO_DB_ERROR -8 #define EVEX_COMPILE_ERROR -19 #define EVEX_GENERAL_ERROR -20 -#define EVEX_BAD_IDENTIFIER SP_BAD_IDENTIFIER -#define EVEX_BODY_TOO_LONG SP_BODY_TOO_LONG -#define EVEX_BAD_PARAMS -21 -#define EVEX_NOT_RUNNING -22 -#define EVEX_MICROSECOND_UNSUP -23 +#define EVEX_BAD_IDENTIFIER -21 +#define EVEX_BODY_TOO_LONG -22 +#define EVEX_BAD_PARAMS -23 +#define EVEX_NOT_RUNNING -24 +#define EVEX_MICROSECOND_UNSUP -25 +#define EVEX_CANT_KILL -26 #define EVENT_EXEC_NO_MORE (1L << 0) #define EVENT_NOT_USED (1L << 1) +#define EVENT_FREE_WHEN_FINISHED (1L << 2) -extern ulong opt_event_executor; +class Event_timed; -enum enum_event_on_completion +class Events { - MYSQL_EVENT_ON_COMPLETION_DROP = 1, - MYSQL_EVENT_ON_COMPLETION_PRESERVE -}; +public: + static ulong opt_event_scheduler; + static TYPELIB opt_typelib; -enum enum_event_status -{ - MYSQL_EVENT_ENABLED = 1, - MYSQL_EVENT_DISABLED + enum enum_table_field + { + FIELD_DB = 0, + FIELD_NAME, + FIELD_BODY, + FIELD_DEFINER, + FIELD_EXECUTE_AT, + FIELD_INTERVAL_EXPR, + FIELD_TRANSIENT_INTERVAL, + FIELD_CREATED, + FIELD_MODIFIED, + FIELD_LAST_EXECUTED, + FIELD_STARTS, + FIELD_ENDS, + FIELD_STATUS, + FIELD_ON_COMPLETION, + FIELD_SQL_MODE, + FIELD_COMMENT, + FIELD_COUNT /* a cool trick to count the number of fields :) */ + }; + + static int + create_event(THD *thd, Event_timed *et, uint create_options, + uint *rows_affected); + + static int + update_event(THD *thd, Event_timed *et, sp_name *new_name, + uint *rows_affected); + + static int + drop_event(THD *thd, Event_timed *et, bool drop_if_exists, + uint *rows_affected); + + static int + open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table); + + static int + show_create_event(THD *thd, sp_name *spn); + + static int + reconstruct_interval_expression(String *buf, interval_type interval, + longlong expression); + + static int + drop_schema_events(THD *thd, char *db); + + static int + dump_internal_status(THD *thd); + + static int + init(); + + static void + shutdown(); + + static void + init_mutexes(); + + static void + destroy_mutexes(); + + +private: + /* Prevent use of these */ + Events(const Events &); + void operator=(Events &); }; -enum evex_table_field -{ - EVEX_FIELD_DB = 0, - EVEX_FIELD_NAME, - EVEX_FIELD_BODY, - EVEX_FIELD_DEFINER, - EVEX_FIELD_EXECUTE_AT, - EVEX_FIELD_INTERVAL_EXPR, - EVEX_FIELD_TRANSIENT_INTERVAL, - EVEX_FIELD_CREATED, - EVEX_FIELD_MODIFIED, - EVEX_FIELD_LAST_EXECUTED, - EVEX_FIELD_STARTS, - EVEX_FIELD_ENDS, - EVEX_FIELD_STATUS, - EVEX_FIELD_ON_COMPLETION, - EVEX_FIELD_SQL_MODE, - EVEX_FIELD_COMMENT, - EVEX_FIELD_COUNT /* a cool trick to count the number of fields :) */ -} ; + + +class sp_head; class Event_timed { @@ -82,12 +127,26 @@ class Event_timed my_bool in_spawned_thread; ulong locked_by_thread_id; my_bool running; + ulong thread_id; pthread_mutex_t LOCK_running; + pthread_cond_t COND_finished; bool status_changed; bool last_executed_changed; public: + enum enum_status + { + ENABLED = 1, + DISABLED + }; + + enum enum_on_completion + { + ON_COMPLETION_DROP = 1, + ON_COMPLETION_PRESERVE + }; + TIME last_executed; LEX_STRING dbname; @@ -111,8 +170,8 @@ public: ulonglong created; ulonglong modified; - enum enum_event_on_completion on_completion; - enum enum_event_status status; + enum enum_on_completion on_completion; + enum enum_status status; sp_head *sphead; ulong sql_mode; const uchar *body_begin; @@ -153,36 +212,15 @@ public: DBUG_ASSERT(0); } + Event_timed(); - Event_timed():in_spawned_thread(0),locked_by_thread_id(0), - running(0), status_changed(false), - last_executed_changed(false), expression(0), created(0), - modified(0), on_completion(MYSQL_EVENT_ON_COMPLETION_DROP), - status(MYSQL_EVENT_ENABLED), sphead(0), sql_mode(0), - body_begin(0), dropped(false), - free_sphead_on_delete(true), flags(0) - - { - pthread_mutex_init(&this->LOCK_running, MY_MUTEX_INIT_FAST); - init(); - } - - ~Event_timed() - { - deinit_mutexes(); - - if (free_sphead_on_delete) - free_sp(); - } + ~Event_timed(); void init(); - + void - deinit_mutexes() - { - pthread_mutex_destroy(&this->LOCK_running); - } + deinit_mutexes(); int init_definer(THD *thd); @@ -214,12 +252,12 @@ public: bool compute_next_execution_time(); - void - mark_last_executed(THD *thd); - int drop(THD *thd); + void + mark_last_executed(THD *thd); + bool update_fields(THD *thd); @@ -227,142 +265,32 @@ public: get_create_event(THD *thd, String *buf); int - execute(THD *thd, MEM_ROOT *mem_root= NULL); + execute(THD *thd, MEM_ROOT *mem_root); int - compile(THD *thd, MEM_ROOT *mem_root= NULL); - - my_bool - is_running() - { - my_bool ret; - - VOID(pthread_mutex_lock(&this->LOCK_running)); - ret= running; - VOID(pthread_mutex_unlock(&this->LOCK_running)); - - return ret; - } - - /* - Checks whether the object is being used in a spawned thread. - This method is for very basic checking. Use ::can_spawn_now_n_lock() - for most of the cases. - */ - - my_bool - can_spawn_now() - { - my_bool ret; - VOID(pthread_mutex_lock(&this->LOCK_running)); - ret= !in_spawned_thread; - VOID(pthread_mutex_unlock(&this->LOCK_running)); - return ret; - } + compile(THD *thd, MEM_ROOT *mem_root); - /* - Checks whether this thread can lock the object for modification -> - preventing being spawned for execution, and locks if possible. - use ::can_spawn_now() only for basic checking because a race - condition may occur between the check and eventual modification (deletion) - of the object. - */ - - my_bool - can_spawn_now_n_lock(THD *thd); - - int - spawn_unlock(THD *thd); + bool + is_running(); int - spawn_now(void * (*thread_func)(void*)); + spawn_now(void * (*thread_func)(void*), void *arg); - void + bool spawn_thread_finish(THD *thd); void - free_sp() - { - delete sphead; - sphead= 0; - } -protected: + free_sp(); + bool - change_security_context(THD *thd, Security_context *s_ctx, - Security_context **backup); + has_equal_db(Event_timed *etn); + + int + kill_thread(THD *thd); void - restore_security_context(THD *thd, Security_context *backup); + set_thread_id(ulong tid) { thread_id= tid; } }; -int -evex_create_event(THD *thd, Event_timed *et, uint create_options, - uint *rows_affected); - -int -evex_update_event(THD *thd, Event_timed *et, sp_name *new_name, - uint *rows_affected); - -int -evex_drop_event(THD *thd, Event_timed *et, bool drop_if_exists, - uint *rows_affected); - -int -evex_open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table); - -int -evex_show_create_event(THD *thd, sp_name *spn, LEX_STRING definer); - -int sortcmp_lex_string(LEX_STRING s, LEX_STRING t, CHARSET_INFO *cs); - -int -event_reconstruct_interval_expression(String *buf, - interval_type interval, - longlong expression); - -int -evex_drop_db_events(THD *thd, char *db); - - -int -init_events(); - -void -shutdown_events(); - - -// auxiliary -int -event_timed_compare(Event_timed **a, Event_timed **b); - - - -/* -CREATE TABLE event ( - db char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', - name char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', - body longblob NOT NULL, - definer char(77) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', - execute_at DATETIME default NULL, - interval_value int(11) default NULL, - interval_field ENUM('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK', - 'SECOND','MICROSECOND', 'YEAR_MONTH','DAY_HOUR', - 'DAY_MINUTE','DAY_SECOND', - 'HOUR_MINUTE','HOUR_SECOND', - 'MINUTE_SECOND','DAY_MICROSECOND', - 'HOUR_MICROSECOND','MINUTE_MICROSECOND', - 'SECOND_MICROSECOND') default NULL, - created TIMESTAMP NOT NULL, - modified TIMESTAMP NOT NULL, - last_executed DATETIME default NULL, - starts DATETIME default NULL, - ends DATETIME default NULL, - status ENUM('ENABLED','DISABLED') NOT NULL default 'ENABLED', - on_completion ENUM('DROP','PRESERVE') NOT NULL default 'DROP', - comment varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', - PRIMARY KEY (definer,db,name) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT 'Events'; -*/ - #endif /* _EVENT_H_ */ diff --git a/sql/event_executor.cc b/sql/event_executor.cc index 21464dd777b..f236fb47771 100644 --- a/sql/event_executor.cc +++ b/sql/event_executor.cc @@ -13,998 +13,3 @@ 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 */ - -#include "event_priv.h" -#include "event.h" -#include "sp.h" - -#define WAIT_STATUS_READY 0 -#define WAIT_STATUS_EMPTY_QUEUE 1 -#define WAIT_STATUS_NEW_TOP_EVENT 2 -#define WAIT_STATUS_STOP_EXECUTOR 3 - - -/* - Make this define DBUG_FAULTY_THR to be able to put breakpoints inside - code used by the scheduler's thread(s). In this case user connections - are not possible because the scheduler thread code is ran inside the - main thread (no spawning takes place. If you want to debug client - connection then start with --one-thread and make the define - DBUG_FAULTY_THR ! -*/ -#define DBUG_FAULTY_THR2 - -extern ulong thread_created; -extern const char *my_localhost; -extern pthread_attr_t connection_attrib; - -pthread_mutex_t LOCK_event_arrays, // mutex for when working with the queue - LOCK_workers_count, // mutex for when inc/dec uint workers_count - LOCK_evex_running; // mutes for managing bool evex_is_running - -static pthread_mutex_t LOCK_evex_main_thread; // mutex for when working with the queue -bool scheduler_main_thread_running= false; - -bool evex_is_running= false; - -ulonglong evex_main_thread_id= 0; -ulong opt_event_executor; -my_bool event_executor_running_global_var; -static my_bool evex_mutexes_initted= FALSE; -static uint workers_count; - -static int -evex_load_events_from_db(THD *thd); - -bool -evex_print_warnings(THD *thd, Event_timed *et); - -/* - TODO Andrey: Check for command line option whether to start - the main thread or not. -*/ - -pthread_handler_t -event_executor_worker(void *arg); - -pthread_handler_t -event_executor_main(void *arg); - - -/* - Returns the seconds difference of 2 TIME structs - - SYNOPSIS - evex_time_diff() - a - TIME struct 1 - b - TIME struct 2 - - Returns: - the seconds difference -*/ - -static int -evex_time_diff(TIME *a, TIME *b) -{ - return sec_since_epoch_TIME(a) - sec_since_epoch_TIME(b); -} - - -/* - Inits the mutexes used by the scheduler module - - SYNOPSIS - evex_init_mutexes() - - NOTES - The mutexes are : - LOCK_event_arrays - LOCK_workers_count - LOCK_evex_running -*/ - -static void -evex_init_mutexes() -{ - if (evex_mutexes_initted) - return; - - evex_mutexes_initted= TRUE; - pthread_mutex_init(&LOCK_event_arrays, MY_MUTEX_INIT_FAST); - pthread_mutex_init(&LOCK_workers_count, MY_MUTEX_INIT_FAST); - pthread_mutex_init(&LOCK_evex_running, MY_MUTEX_INIT_FAST); - pthread_mutex_init(&LOCK_evex_main_thread, MY_MUTEX_INIT_FAST); - - event_executor_running_global_var= opt_event_executor; -} - -extern TABLE_FIELD_W_TYPE mysql_db_table_fields[]; -extern time_t mysql_db_table_last_check; - -/* - Opens mysql.db and mysql.user and checks whether - 1. mysql.db has column Event_priv at column 20 (0 based); - 2. mysql.user has column Event_priv at column 29 (0 based); - - Synopsis - evex_check_system_tables() -*/ - -void -evex_check_system_tables() -{ - THD *thd= current_thd; - TABLE_LIST tables; - Open_tables_state backup; - - /* thd is 0x0 during boot of the server. Later it's !=0x0 */ - if (!thd) - return; - - thd->reset_n_backup_open_tables_state(&backup); - - bzero((char*) &tables, sizeof(tables)); - tables.db= (char*) "mysql"; - tables.table_name= tables.alias= (char*) "db"; - tables.lock_type= TL_READ; - - if (simple_open_n_lock_tables(thd, &tables)) - sql_print_error("Cannot open mysql.db"); - else - { - table_check_intact(tables.table, MYSQL_DB_FIELD_COUNT, mysql_db_table_fields, - &mysql_db_table_last_check,ER_CANNOT_LOAD_FROM_TABLE); - close_thread_tables(thd); - } - - bzero((char*) &tables, sizeof(tables)); - tables.db= (char*) "mysql"; - tables.table_name= tables.alias= (char*) "user"; - tables.lock_type= TL_READ; - - if (simple_open_n_lock_tables(thd, &tables)) - sql_print_error("Cannot open mysql.db"); - else - { - if (tables.table->s->fields < 29 || - strncmp(tables.table->field[29]->field_name, - STRING_WITH_LEN("Event_priv"))) - sql_print_error("mysql.user has no `Event_priv` column at position 29"); - - close_thread_tables(thd); - } - - thd->restore_backup_open_tables_state(&backup); -} - - -/* - Inits the scheduler. Called on server start and every time the scheduler - is started with switching the event_scheduler global variable to TRUE - - SYNOPSIS - init_events() - - NOTES - Inits the mutexes used by the scheduler. Done at server start. -*/ - -int -init_events() -{ - pthread_t th; - DBUG_ENTER("init_events"); - - DBUG_PRINT("info",("Starting events main thread")); - - evex_check_system_tables(); - - evex_init_mutexes(); - - VOID(pthread_mutex_lock(&LOCK_evex_running)); - evex_is_running= false; - VOID(pthread_mutex_unlock(&LOCK_evex_running)); - - if (event_executor_running_global_var) - { -#ifndef DBUG_FAULTY_THR - /* TODO Andrey: Change the error code returned! */ - if (pthread_create(&th, &connection_attrib, event_executor_main,(void*)NULL)) - DBUG_RETURN(ER_SLAVE_THREAD); -#else - event_executor_main(NULL); -#endif - } - - DBUG_RETURN(0); -} - - -/* - Cleans up scheduler memory. Called on server shutdown. - - SYNOPSIS - shutdown_events() - - NOTES - Destroys the mutexes. -*/ - -void -shutdown_events() -{ - DBUG_ENTER("shutdown_events"); - - if (evex_mutexes_initted) - { - evex_mutexes_initted= FALSE; - VOID(pthread_mutex_lock(&LOCK_evex_running)); - VOID(pthread_mutex_unlock(&LOCK_evex_running)); - - pthread_mutex_destroy(&LOCK_event_arrays); - pthread_mutex_destroy(&LOCK_workers_count); - pthread_mutex_destroy(&LOCK_evex_running); - pthread_mutex_destroy(&LOCK_evex_main_thread); - } - DBUG_VOID_RETURN; -} - - -/* - Inits an scheduler thread handler, both the main and a worker - - SYNOPSIS - init_event_thread() - thd - the THD of the thread. Has to be allocated by the caller. - - NOTES - 1. The host of the thead is my_localhost - 2. thd->net is initted with NULL - no communication. - - Returns - 0 - OK - -1 - Error -*/ - -static int -init_event_thread(THD* thd) -{ - DBUG_ENTER("init_event_thread"); - thd->client_capabilities= 0; - thd->security_ctx->master_access= 0; - thd->security_ctx->db_access= 0; - thd->security_ctx->host_or_ip= (char*)my_localhost; - my_net_init(&thd->net, 0); - thd->net.read_timeout = slave_net_timeout; - thd->slave_thread= 0; - thd->options|= OPTION_AUTO_IS_NULL; - thd->client_capabilities= CLIENT_LOCAL_FILES; - thd->real_id=pthread_self(); - VOID(pthread_mutex_lock(&LOCK_thread_count)); - thd->thread_id= thread_id++; - VOID(pthread_mutex_unlock(&LOCK_thread_count)); - - if (init_thr_lock() || thd->store_globals()) - { - thd->cleanup(); - delete thd; - DBUG_RETURN(-1); - } - -#if !defined(__WIN__) && !defined(__NETWARE__) - sigset_t set; - VOID(sigemptyset(&set)); // Get mask in use - VOID(pthread_sigmask(SIG_UNBLOCK,&set,&thd->block_signals)); -#endif - - thd->proc_info= "Initialized"; - thd->version= refresh_version; - thd->set_time(); - DBUG_RETURN(0); -} - - -/* - This function waits till the time next event in the queue should be - executed. - - Returns - WAIT_STATUS_READY There is an event to be executed right now - WAIT_STATUS_EMPTY_QUEUE No events or the last event was dropped. - WAIT_STATUS_NEW_TOP_EVENT New event has entered the queue and scheduled - on top. Restart ticking. - WAIT_STATUS_STOP_EXECUTOR The thread was killed or SET global event_scheduler=0; -*/ - -static int -executor_wait_till_next_event_exec(THD *thd) -{ - Event_timed *et; - TIME time_now; - int t2sleep; - - DBUG_ENTER("executor_wait_till_next_event_exec"); - /* - now let's see how much time to sleep, we know there is at least 1 - element in the queue. - */ - VOID(pthread_mutex_lock(&LOCK_event_arrays)); - if (!evex_queue_num_elements(EVEX_EQ_NAME)) - { - VOID(pthread_mutex_unlock(&LOCK_event_arrays)); - DBUG_RETURN(WAIT_STATUS_EMPTY_QUEUE); - } - et= evex_queue_first_element(&EVEX_EQ_NAME, Event_timed*); - DBUG_ASSERT(et); - if (et->status == MYSQL_EVENT_DISABLED) - { - DBUG_PRINT("evex main thread",("Now it is disabled-exec no more")); - if (et->dropped) - et->drop(thd); - delete et; - evex_queue_delete_element(&EVEX_EQ_NAME, 0);// 0 is top, internally 1 - VOID(pthread_mutex_unlock(&LOCK_event_arrays)); - sql_print_information("Event found disabled, dropping."); - DBUG_RETURN(1); - } - - DBUG_PRINT("evex main thread",("computing time to sleep till next exec")); - /* set the internal clock of thd */ - thd->end_time(); - my_tz_UTC->gmt_sec_to_TIME(&time_now, thd->query_start()); - t2sleep= evex_time_diff(&et->execute_at, &time_now); - VOID(pthread_mutex_unlock(&LOCK_event_arrays)); - - t2sleep*=20; - DBUG_PRINT("evex main thread",("unlocked LOCK_event_arrays")); - if (t2sleep > 0) - { - ulonglong modified= et->modified; - /* - We sleep t2sleep seconds but we check every second whether this thread - has been killed, or there is a new candidate - */ - while (t2sleep-- && !thd->killed && event_executor_running_global_var && - evex_queue_num_elements(EVEX_EQ_NAME) && - (evex_queue_first_element(&EVEX_EQ_NAME, Event_timed*) == et && - evex_queue_first_element(&EVEX_EQ_NAME, Event_timed*)->modified == - modified)) - { - DBUG_PRINT("evex main thread",("will sleep a bit more.")); - my_sleep(50000); - } - DBUG_PRINT("info",("saved_modified=%llu current=%llu", modified, - evex_queue_num_elements(EVEX_EQ_NAME)? - evex_queue_first_element(&EVEX_EQ_NAME, Event_timed*)->modified: - (ulonglong)~0)); - } - - int ret= WAIT_STATUS_READY; - if (!evex_queue_num_elements(EVEX_EQ_NAME)) - ret= WAIT_STATUS_EMPTY_QUEUE; - else if (evex_queue_first_element(&EVEX_EQ_NAME, Event_timed*) != et) - ret= WAIT_STATUS_NEW_TOP_EVENT; - if (thd->killed && event_executor_running_global_var) - ret= WAIT_STATUS_STOP_EXECUTOR; - - DBUG_RETURN(ret); -} - - -/* - The main scheduler thread. Inits the priority queue on start and - destroys it on thread shutdown. Forks child threads for every event - execution. Sleeps between thread forking and does not do a busy wait. - - SYNOPSIS - event_executor_main() - arg unused - - NOTES - 1. The host of the thead is my_localhost - 2. thd->net is initted with NULL - no communication. - -*/ - -pthread_handler_t -event_executor_main(void *arg) -{ - THD *thd; /* needs to be first for thread_stack */ - uint i=0, j=0; - my_ulonglong cnt= 0; - - DBUG_ENTER("event_executor_main"); - DBUG_PRINT("event_executor_main", ("EVEX thread started")); - - pthread_mutex_lock(&LOCK_evex_main_thread); - if (!scheduler_main_thread_running) - scheduler_main_thread_running= true; - else - { - DBUG_PRINT("event_executor_main", ("already running. thd_id=%d", - evex_main_thread_id)); - pthread_mutex_unlock(&LOCK_evex_main_thread); - my_thread_end(); - pthread_exit(0); - DBUG_RETURN(0); // Can't return anything here - } - pthread_mutex_unlock(&LOCK_evex_main_thread); - - /* init memory root */ - init_alloc_root(&evex_mem_root, MEM_ROOT_BLOCK_SIZE, MEM_ROOT_PREALLOC); - - /* needs to call my_thread_init(), otherwise we get a coredump in DBUG_ stuff*/ - my_thread_init(); - - if (sizeof(my_time_t) != sizeof(time_t)) - { - sql_print_error("SCHEDULER: sizeof(my_time_t) != sizeof(time_t) ." - "The scheduler will not work correctly. Stopping."); - DBUG_ASSERT(0); - goto err_no_thd; - } - - /* note that contructor of THD uses DBUG_ ! */ - if (!(thd = new THD)) - { - sql_print_error("SCHEDULER: Cannot create THD for the main thread."); - goto err_no_thd; - } - thd->thread_stack = (char*)&thd; // remember where our stack is - - pthread_detach_this_thread(); - - if (init_event_thread(thd)) - goto finish; - - /* - make this thread visible it has no vio -> show processlist won't see it - unless it's marked as system thread - */ - thd->system_thread= 1; - - VOID(pthread_mutex_lock(&LOCK_thread_count)); - threads.append(thd); - thread_count++; - thread_running++; - VOID(pthread_mutex_unlock(&LOCK_thread_count)); - - DBUG_PRINT("EVEX main thread", ("Initing events_queue")); - - /* - eventually manifest that we are running, not to crashe because of - usage of non-initialized memory structures. - */ - VOID(pthread_mutex_lock(&LOCK_evex_running)); - VOID(pthread_mutex_lock(&LOCK_event_arrays)); - evex_queue_init(&EVEX_EQ_NAME); - VOID(pthread_mutex_unlock(&LOCK_event_arrays)); - evex_is_running= true; - VOID(pthread_mutex_unlock(&LOCK_evex_running)); - - thd->security_ctx->user= my_strdup("event_scheduler", MYF(0)); - - if (evex_load_events_from_db(thd)) - goto finish; - - evex_main_thread_id= thd->thread_id; - - sql_print_information("SCHEDULER: Main thread started"); - while (!thd->killed) - { - TIME time_now; - Event_timed *et; - - cnt++; - DBUG_PRINT("info", ("EVEX External Loop %d thd->k", cnt)); - - thd->proc_info = "Sleeping"; - if (!event_executor_running_global_var) - { - sql_print_information("SCHEDULER: Asked to stop."); - break; - } - - if (!evex_queue_num_elements(EVEX_EQ_NAME)) - { - my_sleep(100000);// sleep 0.1s - continue; - } - -restart_ticking: - switch (executor_wait_till_next_event_exec(thd)) { - case WAIT_STATUS_READY: // time to execute the event on top - DBUG_PRINT("evex main thread",("time to execute an event")); - break; - case WAIT_STATUS_EMPTY_QUEUE: // no more events - DBUG_PRINT("evex main thread",("no more events")); - continue; - break; - case WAIT_STATUS_NEW_TOP_EVENT: // new event on top in the queue - DBUG_PRINT("evex main thread",("restart ticking")); - goto restart_ticking; - case WAIT_STATUS_STOP_EXECUTOR: - sql_print_information("SCHEDULER: Asked to stop."); - goto finish; - break; - default: - DBUG_ASSERT(0); - } - - - VOID(pthread_mutex_lock(&LOCK_event_arrays)); - thd->end_time(); - my_tz_UTC->gmt_sec_to_TIME(&time_now, thd->query_start()); - - if (!evex_queue_num_elements(EVEX_EQ_NAME)) - { - VOID(pthread_mutex_unlock(&LOCK_event_arrays)); - DBUG_PRINT("evex main thread",("empty queue")); - continue; - } - et= evex_queue_first_element(&EVEX_EQ_NAME, Event_timed*); - DBUG_PRINT("evex main thread",("got event from the queue")); - - if (!et->execute_at_null && my_time_compare(&time_now,&et->execute_at) == -1) - { - DBUG_PRINT("evex main thread",("still not the time for execution")); - VOID(pthread_mutex_unlock(&LOCK_event_arrays)); - continue; - } - - DBUG_PRINT("evex main thread",("it's right time")); - if (et->status == MYSQL_EVENT_ENABLED) - { - int fork_ret_code; - - DBUG_PRINT("evex main thread", ("[%10s] this exec at [%llu]", et->name.str, - TIME_to_ulonglong_datetime(&et->execute_at))); - et->mark_last_executed(thd); - if (et->compute_next_execution_time()) - { - sql_print_error("SCHEDULER: Error while computing time of %s.%s . " - "Disabling after execution.", - et->dbname.str, et->name.str); - et->status= MYSQL_EVENT_DISABLED; - } - DBUG_PRINT("evex main thread", ("[%10s] next exec at [%llu]", et->name.str, - TIME_to_ulonglong_datetime(&et->execute_at))); - - et->update_fields(thd); -#ifndef DBUG_FAULTY_THR - thread_safe_increment(workers_count, &LOCK_workers_count); - switch ((fork_ret_code= et->spawn_now(event_executor_worker))) { - case EVENT_EXEC_CANT_FORK: - thread_safe_decrement(workers_count, &LOCK_workers_count); - sql_print_error("SCHEDULER: Problem while trying to create a thread"); - UNLOCK_MUTEX_AND_BAIL_OUT(LOCK_event_arrays, finish); - case EVENT_EXEC_ALREADY_EXEC: - thread_safe_decrement(workers_count, &LOCK_workers_count); - sql_print_information("SCHEDULER: %s.%s in execution. Skip this time.", - et->dbname.str, et->name.str); - break; - default: - DBUG_ASSERT(!fork_ret_code); - if (fork_ret_code) - thread_safe_decrement(workers_count, &LOCK_workers_count); - break; - } -#else - event_executor_worker((void *) et); -#endif - /* - 1. For one-time event : year is > 0 and expression is 0 - 2. For recurring, expression is != -=> check execute_at_null in this case - */ - if ((et->execute_at.year && !et->expression) || et->execute_at_null) - et->flags |= EVENT_EXEC_NO_MORE; - - if ((et->flags & EVENT_EXEC_NO_MORE) || et->status == MYSQL_EVENT_DISABLED) - evex_queue_delete_element(&EVEX_EQ_NAME, 0);// 0 is top, internally 1 - else - evex_queue_first_updated(&EVEX_EQ_NAME); - } - DBUG_PRINT("evex main thread",("unlocking")); - VOID(pthread_mutex_unlock(&LOCK_event_arrays)); - }/* while */ -finish: - - /* First manifest that this thread does not work and then destroy */ - VOID(pthread_mutex_lock(&LOCK_evex_running)); - evex_is_running= false; - evex_main_thread_id= 0; - VOID(pthread_mutex_unlock(&LOCK_evex_running)); - - - /* - TODO: A better will be with a conditional variable - */ - /* - Read workers_count without lock, no need for locking. - In the worst case we have to wait 1sec more. - */ - sql_print_information("SCHEDULER: Stopping. Waiting for worker threads to finish."); - while (1) - { - VOID(pthread_mutex_lock(&LOCK_workers_count)); - if (!workers_count) - { - VOID(pthread_mutex_unlock(&LOCK_workers_count)); - break; - } - VOID(pthread_mutex_unlock(&LOCK_workers_count)); - my_sleep(1000000);// 1s - } - - /* - First we free all objects ... - Lock because a DROP DATABASE could be running in parallel and it locks on these - */ - sql_print_information("SCHEDULER: Emptying the queue."); - VOID(pthread_mutex_lock(&LOCK_event_arrays)); - for (i= 0; i < evex_queue_num_elements(EVEX_EQ_NAME); ++i) - { - Event_timed *et= evex_queue_element(&EVEX_EQ_NAME, i, Event_timed*); - et->free_sp(); - delete et; - } - VOID(pthread_mutex_unlock(&LOCK_event_arrays)); - /* ... then we can thrash the whole queue at once */ - evex_queue_destroy(&EVEX_EQ_NAME); - - thd->proc_info = "Clearing"; - DBUG_ASSERT(thd->net.buff != 0); - net_end(&thd->net); // destructor will not free it, because we are weird - THD_CHECK_SENTRY(thd); - - pthread_mutex_lock(&LOCK_thread_count); - thread_count--; - thread_running--; -#ifndef DBUG_FAULTY_THR - THD_CHECK_SENTRY(thd); - delete thd; -#endif - pthread_mutex_unlock(&LOCK_thread_count); - - -err_no_thd: - VOID(pthread_mutex_lock(&LOCK_evex_running)); - evex_is_running= false; - event_executor_running_global_var= false; - VOID(pthread_mutex_unlock(&LOCK_evex_running)); - - free_root(&evex_mem_root, MYF(0)); - sql_print_information("SCHEDULER: Stopped."); - -#ifndef DBUG_FAULTY_THR - pthread_mutex_lock(&LOCK_evex_main_thread); - scheduler_main_thread_running= false; - pthread_mutex_unlock(&LOCK_evex_main_thread); - - my_thread_end(); - pthread_exit(0); -#endif - DBUG_RETURN(0); // Can't return anything here -} - - -/* - Function that executes an event in a child thread. Setups the - environment for the event execution and cleans after that. - - SYNOPSIS - event_executor_worker() - arg The Event_timed object to be processed -*/ - -pthread_handler_t -event_executor_worker(void *event_void) -{ - THD *thd; /* needs to be first for thread_stack */ - Event_timed *event = (Event_timed *) event_void; - MEM_ROOT worker_mem_root; - - DBUG_ENTER("event_executor_worker"); - - init_alloc_root(&worker_mem_root, MEM_ROOT_BLOCK_SIZE, MEM_ROOT_PREALLOC); - -#ifndef DBUG_FAULTY_THR - my_thread_init(); - - if (!(thd = new THD)) /* note that contructor of THD uses DBUG_ ! */ - { - sql_print_error("SCHEDULER: Cannot create a THD structure in an worker."); - goto err_no_thd; - } - thd->thread_stack = (char*)&thd; // remember where our stack is - thd->mem_root= &worker_mem_root; - - pthread_detach_this_thread(); - - if (init_event_thread(thd)) - goto err; - - thd->init_for_queries(); - - /* make this thread visible it has no vio -> show processlist needs this flag */ - thd->system_thread= 1; - - VOID(pthread_mutex_lock(&LOCK_thread_count)); - threads.append(thd); - thread_count++; - thread_running++; - VOID(pthread_mutex_unlock(&LOCK_thread_count)); -#else - thd= current_thd; -#endif - - thd->enable_slow_log= TRUE; - { - int ret; - sql_print_information("SCHEDULER: Executing event %s.%s of %s [EXPR:%d]", - event->dbname.str, event->name.str, - event->definer.str, (int) event->expression); - - ret= event->execute(thd, &worker_mem_root); - - evex_print_warnings(thd, event); - sql_print_information("SCHEDULER: Executed event %s.%s of %s [EXPR:%d]. " - "RetCode=%d", event->dbname.str, event->name.str, - event->definer.str, (int) event->expression, ret); - if (ret == EVEX_COMPILE_ERROR) - sql_print_information("SCHEDULER: COMPILE ERROR for event %s.%s of", - event->dbname.str, event->name.str, - event->definer.str); - else if (ret == EVEX_MICROSECOND_UNSUP) - sql_print_information("SCHEDULER: MICROSECOND is not supported"); - } - event->spawn_thread_finish(thd); - - -err: - VOID(pthread_mutex_lock(&LOCK_thread_count)); -#ifndef DBUG_FAULTY_THR - thread_count--; - thread_running--; - /* - Some extra safety, which should not been needed (normally, event deletion - should already have done these assignments (each event which sets these - variables is supposed to set them to 0 before terminating)). - */ - VOID(pthread_mutex_unlock(&LOCK_thread_count)); - - thd->proc_info = "Clearing"; - DBUG_ASSERT(thd->net.buff != 0); - net_end(&thd->net); // destructor will not free it, because we are weird - THD_CHECK_SENTRY(thd); - - VOID(pthread_mutex_lock(&LOCK_thread_count)); - THD_CHECK_SENTRY(thd); - delete thd; -#endif - VOID(pthread_mutex_unlock(&LOCK_thread_count)); - -err_no_thd: - - free_root(&worker_mem_root, MYF(0)); - thread_safe_decrement(workers_count, &LOCK_workers_count); - -#ifndef DBUG_FAULTY_THR - my_thread_end(); - pthread_exit(0); -#endif - DBUG_RETURN(0); // Can't return anything here -} - - -/* - Loads all ENABLED events from mysql.event into the prioritized - queue. Called during scheduler main thread initialization. Compiles - the events. Creates Event_timed instances for every ENABLED event - from mysql.event. - - SYNOPSIS - evex_load_events_from_db() - thd - Thread context. Used for memory allocation in some cases. - - RETURNS - 0 OK - !0 Error - - NOTES - Reports the error to the console -*/ - -static int -evex_load_events_from_db(THD *thd) -{ - TABLE *table; - READ_RECORD read_record_info; - int ret= -1; - uint count= 0; - - DBUG_ENTER("evex_load_events_from_db"); - - if ((ret= evex_open_event_table(thd, TL_READ, &table))) - { - sql_print_error("SCHEDULER: Table mysql.event is damaged. Can not open."); - DBUG_RETURN(SP_OPEN_TABLE_FAILED); - } - - VOID(pthread_mutex_lock(&LOCK_event_arrays)); - - init_read_record(&read_record_info, thd, table ,NULL,1,0); - while (!(read_record_info.read_record(&read_record_info))) - { - Event_timed *et; - if (!(et= new Event_timed)) - { - DBUG_PRINT("evex_load_events_from_db", ("Out of memory")); - ret= -1; - goto end; - } - DBUG_PRINT("evex_load_events_from_db", ("Loading event from row.")); - - if ((ret= et->load_from_row(&evex_mem_root, table))) - { - sql_print_error("SCHEDULER: Error while loading from mysql.event. " - "Table probably corrupted"); - goto end; - } - if (et->status != MYSQL_EVENT_ENABLED) - { - DBUG_PRINT("evex_load_events_from_db",("%s is disabled",et->name.str)); - delete et; - continue; - } - - DBUG_PRINT("evex_load_events_from_db", - ("Event %s loaded from row. Time to compile", et->name.str)); - - switch (ret= et->compile(thd, &evex_mem_root)) { - case EVEX_MICROSECOND_UNSUP: - sql_print_error("SCHEDULER: mysql.event is tampered. MICROSECOND is not " - "supported but found in mysql.event"); - goto end; - case EVEX_COMPILE_ERROR: - sql_print_error("SCHEDULER: Error while compiling %s.%s. Aborting load.", - et->dbname.str, et->name.str); - goto end; - default: - break; - } - - /* let's find when to be executed */ - if (et->compute_next_execution_time()) - { - sql_print_error("SCHEDULER: Error while computing execution time of %s.%s." - " Skipping", et->dbname.str, et->name.str); - continue; - } - - DBUG_PRINT("evex_load_events_from_db", ("Adding to the exec list.")); - - evex_queue_insert(&EVEX_EQ_NAME, (EVEX_PTOQEL) et); - DBUG_PRINT("evex_load_events_from_db", ("%p %*s", - et, et->name.length,et->name.str)); - count++; - } - - ret= 0; - -end: - VOID(pthread_mutex_unlock(&LOCK_event_arrays)); - end_read_record(&read_record_info); - - /* Force close to free memory */ - thd->version--; - - close_thread_tables(thd); - if (!ret) - sql_print_information("SCHEDULER: Loaded %d event%s", count, (count == 1)?"":"s"); - DBUG_PRINT("info", ("Status code %d. Loaded %d event(s)", ret, count)); - - DBUG_RETURN(ret); -} - - -/* - The update method of the global variable event_scheduler. - If event_scheduler is switched from 0 to 1 then the scheduler main - thread is started. - - SYNOPSIS - event_executor_worker() - thd - Thread context (unused) - car - the new value - - Returns - 0 OK (always) -*/ - -bool -sys_var_event_executor::update(THD *thd, set_var *var) -{ - /* here start the thread if not running. */ - DBUG_ENTER("sys_var_event_executor::update"); - VOID(pthread_mutex_lock(&LOCK_evex_running)); - *value= var->save_result.ulong_value; - - DBUG_PRINT("new_value", ("%d", *value)); - if ((my_bool) *value && !evex_is_running) - { - VOID(pthread_mutex_unlock(&LOCK_evex_running)); - init_events(); - } else - VOID(pthread_mutex_unlock(&LOCK_evex_running)); - - DBUG_RETURN(0); -} - - -extern LEX_STRING warning_level_names[]; - -typedef void (*sql_print_xxx_func)(const char *format, ...); -static sql_print_xxx_func sql_print_xxx_handlers[3] = -{ - sql_print_information, - sql_print_warning, - sql_print_error -}; - - -/* - Prints the stack of infos, warnings, errors from thd to - the console so it can be fetched by the logs-into-tables and - checked later. - - Synopsis - evex_print_warnings - thd - thread used during the execution of the event - et - the event itself - - Returns - 0 - OK (always) - -*/ - -bool -evex_print_warnings(THD *thd, Event_timed *et) -{ - MYSQL_ERROR *err; - DBUG_ENTER("evex_show_warnings"); - char msg_buf[1024]; - char prefix_buf[512]; - String prefix(prefix_buf, sizeof(prefix_buf), system_charset_info); - prefix.length(0); - - List_iterator_fast<MYSQL_ERROR> it(thd->warn_list); - while ((err= it++)) - { - String err_msg(msg_buf, sizeof(msg_buf), system_charset_info); - /* set it to 0 or we start adding at the end. That's the trick ;) */ - err_msg.length(0); - if (!prefix.length()) - { - prefix.append("SCHEDULER: ["); - - append_identifier(thd,&prefix,et->definer_user.str,et->definer_user.length); - prefix.append('@'); - append_identifier(thd,&prefix,et->definer_host.str,et->definer_host.length); - prefix.append("][", 2); - append_identifier(thd,&prefix, et->dbname.str, et->dbname.length); - prefix.append('.'); - append_identifier(thd,&prefix, et->name.str, et->name.length); - prefix.append("] ", 2); - } - - err_msg.append(prefix); - err_msg.append(err->msg, strlen(err->msg), system_charset_info); - err_msg.append("]"); - DBUG_ASSERT(err->level < 3); - (sql_print_xxx_handlers[err->level])("%*s", err_msg.length(), err_msg.c_ptr()); - } - - - DBUG_RETURN(FALSE); -} diff --git a/sql/event_priv.h b/sql/event_priv.h index 6b23136847e..43ef30a659f 100644 --- a/sql/event_priv.h +++ b/sql/event_priv.h @@ -1,4 +1,6 @@ -/* Copyright (C) 2004-2005 MySQL AB +#ifndef _EVENT_PRIV_H_ +#define _EVENT_PRIV_H_ +/* Copyright (C) 2004-2006 MySQL 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 @@ -14,8 +16,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _EVENT_PRIV_H_ -#define _EVENT_PRIV_H_ #include "mysql_priv.h" @@ -23,11 +23,6 @@ #define EVENT_EXEC_ALREADY_EXEC 1 #define EVENT_EXEC_CANT_FORK 2 -#define EVEX_USE_QUEUE - -#define UNLOCK_MUTEX_AND_BAIL_OUT(__mutex, __label) \ - { VOID(pthread_mutex_unlock(&__mutex)); goto __label; } - #define EVEX_DB_FIELD_LEN 64 #define EVEX_NAME_FIELD_LEN 64 #define EVEX_MAX_INTERVAL_VALUE 2147483647L @@ -38,45 +33,54 @@ my_time_compare(TIME *a, TIME *b); int evex_db_find_event_by_name(THD *thd, const LEX_STRING dbname, const LEX_STRING ev_name, - const LEX_STRING user_name, TABLE *table); int event_timed_compare_q(void *vptr, byte* a, byte *b); -int db_drop_event(THD *thd, Event_timed *et, bool drop_if_exists, - uint *rows_affected); - +int +db_drop_event(THD *thd, Event_timed *et, bool drop_if_exists, + uint *rows_affected); +int +db_find_event(THD *thd, sp_name *name, Event_timed **ett, TABLE *tbl, + MEM_ROOT *root); -#define EXEC_QUEUE_QUEUE_NAME executing_queue -#define EXEC_QUEUE_DARR_NAME evex_executing_queue +int +db_create_event(THD *thd, Event_timed *et, my_bool create_if_not, + uint *rows_affected); +int +db_drop_events_from_table(THD *thd, LEX_STRING *db); -#define EVEX_QUEUE_TYPE QUEUE -#define EVEX_PTOQEL byte * +int +sortcmp_lex_string(LEX_STRING s, LEX_STRING t, CHARSET_INFO *cs); -#define EVEX_EQ_NAME executing_queue -#define evex_queue_first_element(queue, __cast) ((__cast)queue_top(queue)) -#define evex_queue_element(queue, idx, __cast) ((__cast)queue_element(queue, idx)) -#define evex_queue_delete_element(queue, idx) queue_remove(queue, idx) -#define evex_queue_destroy(queue) delete_queue(queue) -#define evex_queue_first_updated(queue) queue_replaced(queue) -#define evex_queue_insert(queue, element) queue_insert_safe(queue, element); +/* Compares only the name part of the identifier */ +bool +event_timed_name_equal(Event_timed *et, LEX_STRING *name); +/* Compares only the schema part of the identifier */ +bool +event_timed_db_equal(Event_timed *et, LEX_STRING *db); +/* + Compares only the definer part of the identifier. Use during DROP USER + to drop user's events. (Still not implemented) +*/ +bool +event_timed_definer_equal(Event_timed *et, LEX_STRING *definer); -void -evex_queue_init(EVEX_QUEUE_TYPE *queue); +/* Compares the whole identifier*/ +bool +event_timed_identifier_equal(Event_timed *a, Event_timed *b); -#define evex_queue_num_elements(queue) queue.elements +bool +change_security_context(THD *thd, LEX_STRING user, LEX_STRING host, + LEX_STRING db, Security_context *s_ctx, + Security_context **backup); -extern bool evex_is_running; -extern MEM_ROOT evex_mem_root; -extern pthread_mutex_t LOCK_event_arrays, - LOCK_workers_count, - LOCK_evex_running; -extern ulonglong evex_main_thread_id; -extern QUEUE EVEX_EQ_NAME; +void +restore_security_context(THD *thd, Security_context *backup); #endif /* _EVENT_PRIV_H_ */ diff --git a/sql/event_scheduler.cc b/sql/event_scheduler.cc new file mode 100644 index 00000000000..e360254fdd2 --- /dev/null +++ b/sql/event_scheduler.cc @@ -0,0 +1,2426 @@ +/* Copyright (C) 2004-2006 MySQL 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 */ + +#include "event_priv.h" +#include "event.h" +#include "event_scheduler.h" +#include "sp_head.h" + +/* + ToDo: + 1. Talk to Alik to get a check for configure.in for my_time_t and time_t + 2. Look at guardian.h|cc to see its life cycle, has similarities. +*/ + + +/* + The scheduler is implemented as class Event_scheduler. Only one instance is + kept during the runtime of the server, by implementing the Singleton DP. + Object instance is always there because the memory is allocated statically + and initialized when the OS loader loads mysqld. This initialization is + bare. Extended initialization is done during the call to + Event_scheduler::init() in Events::init(). The reason for that late initialization + is that some subsystems needed to boot the Scheduler are not available at + earlier stages of the mysqld boot procedure. Events::init() is called in + mysqld.cc . If the mysqld is started with --event-scheduler=0 then + no initialization takes place and the scheduler is unavailable during this + server run. The server should be started with --event-scheduler=1 to have + the scheduler initialized and able to execute jobs. This starting alwa + s implies that the jobs execution will start immediately. If the server + is started with --event-scheduler=2 then the scheduler is started in suspended + state. Default state, if --event-scheduler is not specified is 2. + + The scheduler only manages execution of the events. Their creation, + alteration and deletion is delegated to other routines found in event.cc . + These routines interact with the scheduler : + - CREATE EVENT -> Event_scheduler::add_event() + - ALTER EVENT -> Event_scheduler::replace_event() + - DROP EVENT -> Event_scheduler::drop_event() + + There is one mutex in the single Event_scheduler object which controls + the simultaneous access to the objects invariants. Using one lock makes + it easy to follow the workflow. This mutex is LOCK_scheduler_data. It is + initialized in Event_scheduler::init(). Which in turn is called by the + Facade class Events in event.cc, coming from init_thread_environment() from + mysqld.cc -> no concurrency at this point. It's destroyed in + Events::destroy_mutexes() called from clean_up_mutexes() in mysqld.cc . + + The full initialization is done in Event_scheduler::init() called from + Events::init(). It's done before any requests coming in, so this is a + guarantee for not having concurrency. + + The scheduler is started with Event_scheduler::start() and stopped with + Event_scheduler::stop(). When the scheduler starts it loads all events + from mysql.event table. Unfortunately, there is a race condition between + the event disk management functions and the scheduler ones + (add/replace/drop_event & load_events_from_db()), because the operations + do not happen under one global lock but the disk operations are guarded + by the MYISAM lock on mysql.event. In the same time, the queue operations + are guarded by LOCK_scheduler_data. If the scheduler is start()-ed during + server startup and stopped()-ed during server shutdown (in Events::shutdown() + called by kill_server() in mysqld.cc) these races does not exist. + + Since the user may want to temporarily inhibit execution of events the + scheduler can be suspended and then it can be forced to resume its + operations. The API call to perform these is + Event_scheduler::suspend_or_resume(enum enum_suspend_or_resume) . + When the scheduler is suspended the main scheduler thread, which ATM + happens to have thread_id 1, locks on a condition COND_suspend_or_resume. + When this is signal is sent for the reverse operation the main scheduler + loops continues to roll and execute events. + + When the scheduler is suspended all add/replace/drop_event() operations + work as expected and the modify the queue but no events execution takes + place. + + In contrast to the previous scheduler implementation, found in + event_executor.cc, the start, shutdown, suspend and resume are synchronous + operations. As a whole all operations are synchronized and no busy waits + are used except in stop_all_running_events(), which waits until all + running event worker threads have finished. It would have been nice to + use a conditional on which this method will wait and the last thread to + finish would signal it but this implies subclassing THD. + + The scheduler does not keep a counter of how many event worker threads are + running, at any specific moment, because this will copy functionality + already existing in the server. Namely, all THDs are registered in the + global `threads` array. THD has member variable system_thread which + identifies the type of thread. Connection threads being NON_SYSTEM_THREAD, + all other have their enum value. Important for the scheduler are + SYSTEM_THREAD_EVENT_SCHEDULER and SYSTEM_THREAD_EVENT_WORKER. + + Class THD subclasses class ilink, which is the linked list of all threads. + When a THD instance is destroyed it's being removed from threads, thus + no manual intervention is needed. On the contrary registering is manual + with threads.append() . Traversing the threads array every time a subclass + of THD, for instance if we would have had THD_scheduler_worker to see + how many events we have and whether the scheduler is shutting down will + take much time and lead to a deadlock. stop_all_running_events() is called + under LOCK_scheduler_data. If the THD_scheduler_worker was aware of + the single Event_scheduler instance it will try to check + Event_scheduler::state but for this it would need to acquire + LOCK_scheduler_data => deadlock. Thus stop_all_running_events() uses a + busy wait. + + DROP DATABASE DDL should drop all events defined in a specific schema. + DROP USER also should drop all events who has as definer the user being + dropped (this one is not addressed at the moment but a hook exists). For + this specific needs Event_scheduler::drop_matching_events() is + implemented. Which expects a callback to be applied on every object in + the queue. Thus events that match specific schema or user, will be + removed from the queue. The exposed interface is : + - Event_scheduler::drop_schema_events() + - Event_scheduler::drop_user_events() + + This bulk dropping happens under LOCK_scheduler_data, thus no two or + more threads can execute it in parallel. However, DROP DATABASE is also + synchronized, currently, in the server thus this does not impact the + overall performance. In addition, DROP DATABASE is not that often + executed DDL. + + Though the interface to the scheduler is only through the public methods + of class Event_scheduler, there are currently few functions which are + used during its operations. Namely : + - static evex_print_warnings() + After every event execution all errors/warnings are dumped, so the user + can see in case of a problem what the problem was. + + - static init_event_thread() + This function is both used by event_scheduler_thread() and + event_worker_thread(). It initializes the THD structure. The + initialization looks pretty similar to the one in slave.cc done for the + replication threads. However, though the similarities it cannot be + factored out to have one routine. + + - static event_scheduler_thread() + Because our way to register functions to be used by the threading library + does not allow usage of static methods this function is used to start the + scheduler in it. It does THD initialization and then calls + Event_scheduler::run(). + + - static event_worker_thread() + With already stated the reason for not being able to use methods, this + function executes the worker threads. + + The execution of events is, to some extent, synchronized to inhibit race + conditions when Event_timed::thread_id is being updated with the thread_id of + the THD in which the event is being executed. The thread_id is in the + Event_timed object because we need to be able to kill quickly a specific + event during ALTER/DROP EVENT without traversing the global `threads` array. + However, this makes the scheduler's code more complicated. The event worker + thread is started by Event_timed::spawn_now(), which in turn calls + pthread_create(). The thread_id which will be associated in init_event_thread + is not known in advance thus the registering takes place in + event_worker_thread(). This registering has to be synchronized under + LOCK_scheduler_data, so no kill_event() on a object in + replace_event/drop_event/drop_matching_events() could take place. + + This synchronization is done through class Worker_thread_param that is + local to this file. Event_scheduler::execute_top() is called under + LOCK_scheduler_data. This method : + 1. Creates an instance of Worker_thread_param on the stack + 2. Locks Worker_thread_param::LOCK_started + 3. Calls Event_timed::spawn_now() which in turn creates a new thread. + 4. Locks on Worker_thread_param::COND_started_or_stopped and waits till the + worker thread send signal. The code is spurious wake-up safe because + Worker_thread_param::started is checked. + 5. The worker thread initializes its THD, then sets Event_timed::thread_id, + sets Worker_thread_param::started to TRUE and sends back + Worker_thread_param::COND_started. From this moment on, the event + is being executed and could be killed by using Event_timed::thread_id. + When Event_timed::spawn_thread_finish() is called in the worker thread, + it sets thread_id to 0. From this moment on, the worker thread should not + touch the Event_timed instance. + + + The life-cycle of the server is a FSA. + enum enum_state Event_scheduler::state keeps the state of the scheduler. + + The states are: + + |---UNINITIALIZED + | + | |------------------> IN_SHUTDOWN + --> INITIALIZED -> COMMENCING ---> RUNNING ----------| + ^ ^ | | ^ | + | |- CANTSTART <--| | |- SUSPENDED <-| + |______________________________| + + - UNINITIALIZED :The object is created and only the mutex is initialized + - INITIALIZED :All member variables are initialized + - COMMENCING :The scheduler is starting, no other attempt to start + should succeed before the state is back to INITIALIZED. + - CANTSTART :Set by the ::run() method in case it can't start for some + reason. In this case the connection thread that tries to + start the scheduler sees that some error has occurred and + returns an error to the user. Finally, the connection + thread sets the state to INITIALIZED, so further attempts + to start the scheduler could be made. + - RUNNING :The scheduler is running. New events could be added, + dropped, altered. The scheduler could be stopped. + - SUSPENDED :Like RUNNING but execution of events does not take place. + Operations on the memory queue are possible. + - IN_SHUTDOWN :The scheduler is shutting down, due to request by setting + the global event_scheduler to 0/FALSE, or because of a + KILL command sent by a user to the master thread. + + In every method the macros LOCK_SCHEDULER_DATA() and UNLOCK_SCHEDULER_DATA() + are used for (un)locking purposes. They are used to save the programmer + from typing everytime + lock_data(__FUNCTION__, __LINE__); + All locking goes through Event_scheduler::lock_data() and ::unlock_data(). + These two functions then record in variables where for last time + LOCK_scheduler_data was locked and unlocked (two different variables). In + multithreaded environment, in some cases they make no sense but are useful for + inspecting deadlocks without having the server debug log turned on and the + server is still running. + + The same strategy is used for conditional variables. + Event_scheduler::cond_wait() is invoked from all places with parameter + an enum enum_cond_vars. In this manner, it's possible to inspect the last + on which condition the last call to cond_wait() was waiting. If the server + was started with debug trace switched on, the trace file also holds information + about conditional variables used. +*/ + +#ifdef __GNUC__ +#if __GNUC__ >= 2 +#define SCHED_FUNC __FUNCTION__ +#endif +#else +#define SCHED_FUNC "<unknown>" +#endif + +#define LOCK_SCHEDULER_DATA() lock_data(SCHED_FUNC, __LINE__) +#define UNLOCK_SCHEDULER_DATA() unlock_data(SCHED_FUNC, __LINE__) + + +#ifndef DBUG_OFF +static +LEX_STRING states_names[] = +{ + {(char*) STRING_WITH_LEN("UNINITIALIZED")}, + {(char*) STRING_WITH_LEN("INITIALIZED")}, + {(char*) STRING_WITH_LEN("COMMENCING")}, + {(char*) STRING_WITH_LEN("CANTSTART")}, + {(char*) STRING_WITH_LEN("RUNNING")}, + {(char*) STRING_WITH_LEN("SUSPENDED")}, + {(char*) STRING_WITH_LEN("IN_SHUTDOWN")} +}; +#endif + + +Event_scheduler +Event_scheduler::singleton; + + +const char * const +Event_scheduler::cond_vars_names[Event_scheduler::COND_LAST] = +{ + "new work", + "started or stopped", + "suspend or resume" +}; + + +class Worker_thread_param +{ +public: + Event_timed *et; + pthread_mutex_t LOCK_started; + pthread_cond_t COND_started; + bool started; + + Worker_thread_param(Event_timed *etn):et(etn), started(FALSE) + { + pthread_mutex_init(&LOCK_started, MY_MUTEX_INIT_FAST); + pthread_cond_init(&COND_started, NULL); + } + + ~Worker_thread_param() + { + pthread_mutex_destroy(&LOCK_started); + pthread_cond_destroy(&COND_started); + } +}; + + +/* + Prints the stack of infos, warnings, errors from thd to + the console so it can be fetched by the logs-into-tables and + checked later. + + SYNOPSIS + evex_print_warnings + thd - thread used during the execution of the event + et - the event itself +*/ + +static void +evex_print_warnings(THD *thd, Event_timed *et) +{ + MYSQL_ERROR *err; + DBUG_ENTER("evex_print_warnings"); + if (!thd->warn_list.elements) + DBUG_VOID_RETURN; + + char msg_buf[10 * STRING_BUFFER_USUAL_SIZE]; + char prefix_buf[5 * STRING_BUFFER_USUAL_SIZE]; + String prefix(prefix_buf, sizeof(prefix_buf), system_charset_info); + prefix.length(0); + prefix.append("SCHEDULER: ["); + + append_identifier(thd, &prefix, et->definer_user.str, et->definer_user.length); + prefix.append('@'); + append_identifier(thd, &prefix, et->definer_host.str, et->definer_host.length); + prefix.append("][", 2); + append_identifier(thd,&prefix, et->dbname.str, et->dbname.length); + prefix.append('.'); + append_identifier(thd,&prefix, et->name.str, et->name.length); + prefix.append("] ", 2); + + List_iterator_fast<MYSQL_ERROR> it(thd->warn_list); + while ((err= it++)) + { + String err_msg(msg_buf, sizeof(msg_buf), system_charset_info); + /* set it to 0 or we start adding at the end. That's the trick ;) */ + err_msg.length(0); + err_msg.append(prefix); + err_msg.append(err->msg, strlen(err->msg), system_charset_info); + err_msg.append("]"); + DBUG_ASSERT(err->level < 3); + (sql_print_message_handlers[err->level])("%*s", err_msg.length(), + err_msg.c_ptr()); + } + DBUG_VOID_RETURN; +} + + +/* + Inits an scheduler thread handler, both the main and a worker + + SYNOPSIS + init_event_thread() + thd - the THD of the thread. Has to be allocated by the caller. + + NOTES + 1. The host of the thead is my_localhost + 2. thd->net is initted with NULL - no communication. + + RETURN VALUE + 0 OK + -1 Error +*/ + +static int +init_event_thread(THD** t, enum enum_thread_type thread_type) +{ + THD *thd= *t; + thd->thread_stack= (char*)t; // remember where our stack is + DBUG_ENTER("init_event_thread"); + thd->client_capabilities= 0; + thd->security_ctx->master_access= 0; + thd->security_ctx->db_access= 0; + thd->security_ctx->host_or_ip= (char*)my_localhost; + my_net_init(&thd->net, 0); + thd->net.read_timeout= slave_net_timeout; + thd->slave_thread= 0; + thd->options|= OPTION_AUTO_IS_NULL; + thd->client_capabilities|= CLIENT_MULTI_RESULTS; + thd->real_id=pthread_self(); + VOID(pthread_mutex_lock(&LOCK_thread_count)); + thd->thread_id= thread_id++; + threads.append(thd); + thread_count++; + thread_running++; + VOID(pthread_mutex_unlock(&LOCK_thread_count)); + + if (init_thr_lock() || thd->store_globals()) + { + thd->cleanup(); + DBUG_RETURN(-1); + } + +#if !defined(__WIN__) && !defined(OS2) && !defined(__NETWARE__) + sigset_t set; + VOID(sigemptyset(&set)); // Get mask in use + VOID(pthread_sigmask(SIG_UNBLOCK,&set,&thd->block_signals)); +#endif + + /* + Guarantees that we will see the thread in SHOW PROCESSLIST though its + vio is NULL. + */ + thd->system_thread= thread_type; + + thd->proc_info= "Initialized"; + thd->version= refresh_version; + thd->set_time(); + + DBUG_RETURN(0); +} + + +/* + Inits the main scheduler thread and then calls Event_scheduler::run() + of arg. + + SYNOPSIS + event_scheduler_thread() + arg void* ptr to Event_scheduler + + NOTES + 1. The host of the thead is my_localhost + 2. thd->net is initted with NULL - no communication. + 3. The reason to have a proxy function is that it's not possible to + use a method as function to be executed in a spawned thread: + - our pthread_hander_t macro uses extern "C" + - separating thread setup from the real execution loop is also to be + considered good. + + RETURN VALUE + 0 OK +*/ + +pthread_handler_t +event_scheduler_thread(void *arg) +{ + /* needs to be first for thread_stack */ + THD *thd= NULL; + Event_scheduler *scheduler= (Event_scheduler *) arg; + + DBUG_ENTER("event_scheduler_thread"); + + my_thread_init(); + pthread_detach_this_thread(); + + /* note that constructor of THD uses DBUG_ ! */ + if (!(thd= new THD) || init_event_thread(&thd, SYSTEM_THREAD_EVENT_SCHEDULER)) + { + sql_print_error("SCHEDULER: Cannot init manager event thread."); + scheduler->report_error_during_start(); + } + else + { + thd->security_ctx->set_user((char*)"event_scheduler"); + + sql_print_information("SCHEDULER: Manager thread booting"); + if (Event_scheduler::check_system_tables(thd)) + scheduler->report_error_during_start(); + else + scheduler->run(thd); + + /* + NOTE: Don't touch `scheduler` after this point because we have notified + the + thread which shuts us down that we have finished cleaning. In this + very moment a new scheduler thread could be started and a crash is + not welcome. + */ + } + + /* + If we cannot create THD then don't decrease because we haven't touched + thread_count and thread_running in init_event_thread() which was never + called. In init_event_thread() thread_count and thread_running are + always increased even in the case the method returns an error. + */ + if (thd) + { + thd->proc_info= "Clearing"; + DBUG_ASSERT(thd->net.buff != 0); + net_end(&thd->net); + pthread_mutex_lock(&LOCK_thread_count); + thread_count--; + thread_running--; + delete thd; + pthread_mutex_unlock(&LOCK_thread_count); + } + my_thread_end(); + DBUG_RETURN(0); // Can't return anything here +} + + +/* + Function that executes an event in a child thread. Setups the + environment for the event execution and cleans after that. + + SYNOPSIS + event_worker_thread() + arg The Event_timed object to be processed + + RETURN VALUE + 0 OK +*/ + +pthread_handler_t +event_worker_thread(void *arg) +{ + THD *thd; /* needs to be first for thread_stack */ + Worker_thread_param *param= (Worker_thread_param *) arg; + Event_timed *event= param->et; + int ret; + bool startup_error= FALSE; + Security_context *save_ctx; + /* this one is local and not needed after exec */ + Security_context security_ctx; + + DBUG_ENTER("event_worker_thread"); + DBUG_PRINT("enter", ("event=[%s.%s]", event->dbname.str, event->name.str)); + + my_thread_init(); + pthread_detach_this_thread(); + + if (!(thd= new THD) || init_event_thread(&thd, SYSTEM_THREAD_EVENT_WORKER)) + { + sql_print_error("SCHEDULER: Startup failure."); + startup_error= TRUE; + event->spawn_thread_finish(thd); + } + else + event->set_thread_id(thd->thread_id); + + DBUG_PRINT("info", ("master_access=%d db_access=%d", + thd->security_ctx->master_access, thd->security_ctx->db_access)); + /* + If we don't change it before we send the signal back, then an intermittent + DROP EVENT will take LOCK_scheduler_data and try to kill this thread, because + event->thread_id is already real. However, because thd->security_ctx->user + is not initialized then a crash occurs in kill_one_thread(). Thus, we have + to change the context before sending the signal. We are under + LOCK_scheduler_data being held by Event_scheduler::run() -> ::execute_top(). + */ + change_security_context(thd, event->definer_user, event->definer_host, + event->dbname, &security_ctx, &save_ctx); + DBUG_PRINT("info", ("master_access=%d db_access=%d", + thd->security_ctx->master_access, thd->security_ctx->db_access)); + + /* Signal the scheduler thread that we have started successfully */ + pthread_mutex_lock(¶m->LOCK_started); + param->started= TRUE; + pthread_cond_signal(¶m->COND_started); + pthread_mutex_unlock(¶m->LOCK_started); + + if (!startup_error) + { + thd->init_for_queries(); + thd->enable_slow_log= TRUE; + + event->set_thread_id(thd->thread_id); + sql_print_information("SCHEDULER: [%s.%s of %s] executing in thread %lu", + event->dbname.str, event->name.str, + event->definer.str, thd->thread_id); + + ret= event->execute(thd, thd->mem_root); + evex_print_warnings(thd, event); + sql_print_information("SCHEDULER: [%s.%s of %s] executed. RetCode=%d", + event->dbname.str, event->name.str, + event->definer.str, ret); + if (ret == EVEX_COMPILE_ERROR) + sql_print_information("SCHEDULER: COMPILE ERROR for event %s.%s of %s", + event->dbname.str, event->name.str, + event->definer.str); + else if (ret == EVEX_MICROSECOND_UNSUP) + sql_print_information("SCHEDULER: MICROSECOND is not supported"); + + DBUG_PRINT("info", ("master_access=%d db_access=%d", + thd->security_ctx->master_access, thd->security_ctx->db_access)); + + /* If true is returned, we are expected to free it */ + if (event->spawn_thread_finish(thd)) + { + DBUG_PRINT("info", ("Freeing object pointer")); + delete event; + } + } + + if (thd) + { + thd->proc_info= "Clearing"; + DBUG_ASSERT(thd->net.buff != 0); + /* + Free it here because net.vio is NULL for us => THD::~THD will check it + and won't call net_end(&net); See also replication code. + */ + net_end(&thd->net); + DBUG_PRINT("info", ("Worker thread %lu exiting", thd->thread_id)); + VOID(pthread_mutex_lock(&LOCK_thread_count)); + thread_count--; + thread_running--; + delete thd; + VOID(pthread_mutex_unlock(&LOCK_thread_count)); + } + + my_thread_end(); + DBUG_RETURN(0); // Can't return anything here +} + + +/* + Constructor of class Event_scheduler. + + SYNOPSIS + Event_scheduler::Event_scheduler() +*/ + +Event_scheduler::Event_scheduler() + :state(UNINITIALIZED), start_scheduler_suspended(FALSE), + thread_id(0), mutex_last_locked_at_line(0), + mutex_last_unlocked_at_line(0), mutex_last_locked_in_func(""), + mutex_last_unlocked_in_func(""), cond_waiting_on(COND_NONE), + mutex_scheduler_data_locked(FALSE) +{ +} + + +/* + Returns the singleton instance of the class. + + SYNOPSIS + Event_scheduler::get_instance() + + RETURN VALUE + address +*/ + +Event_scheduler* +Event_scheduler::get_instance() +{ + DBUG_ENTER("Event_scheduler::get_instance"); + DBUG_RETURN(&singleton); +} + + +/* + The implementation of full-fledged initialization. + + SYNOPSIS + Event_scheduler::init() + + RETURN VALUE + FALSE OK + TRUE Error +*/ + +bool +Event_scheduler::init() +{ + int i= 0; + bool ret= FALSE; + DBUG_ENTER("Event_scheduler::init"); + DBUG_PRINT("enter", ("this=%p", this)); + + LOCK_SCHEDULER_DATA(); + for (;i < COND_LAST; i++) + if (pthread_cond_init(&cond_vars[i], NULL)) + { + sql_print_error("SCHEDULER: Unable to initalize conditions"); + ret= TRUE; + goto end; + } + + /* init memory root */ + init_alloc_root(&scheduler_root, MEM_ROOT_BLOCK_SIZE, MEM_ROOT_PREALLOC); + + if (init_queue_ex(&queue, 30 /*num_el*/, 0 /*offset*/, 0 /*smallest_on_top*/, + event_timed_compare_q, NULL, 30 /*auto_extent*/)) + { + sql_print_error("SCHEDULER: Can't initialize the execution queue"); + ret= TRUE; + goto end; + } + + if (sizeof(my_time_t) != sizeof(time_t)) + { + sql_print_error("SCHEDULER: sizeof(my_time_t) != sizeof(time_t) ." + "The scheduler may not work correctly. Stopping."); + DBUG_ASSERT(0); + ret= TRUE; + goto end; + } + + state= INITIALIZED; +end: + UNLOCK_SCHEDULER_DATA(); + DBUG_RETURN(ret); +} + + +/* + Frees all memory allocated by the scheduler object. + + SYNOPSIS + Event_scheduler::destroy() + + RETURN VALUE + FALSE OK + TRUE Error +*/ + +void +Event_scheduler::destroy() +{ + DBUG_ENTER("Event_scheduler"); + + LOCK_SCHEDULER_DATA(); + switch (state) { + case UNINITIALIZED: + break; + case INITIALIZED: + delete_queue(&queue); + free_root(&scheduler_root, MYF(0)); + int i; + for (i= 0; i < COND_LAST; i++) + pthread_cond_destroy(&cond_vars[i]); + state= UNINITIALIZED; + break; + default: + sql_print_error("SCHEDULER: Destroying while state is %d", state); + /* I trust my code but ::safe() > ::sorry() */ + DBUG_ASSERT(0); + break; + } + UNLOCK_SCHEDULER_DATA(); + + DBUG_VOID_RETURN; +} + + +/* + Adds an event to the scheduler queue + + SYNOPSIS + Event_scheduler::add_event() + et The event to add + check_existence Whether to check if already loaded. + + RETURN VALUE + OP_OK OK or scheduler not working + OP_LOAD_ERROR Error during loading from disk +*/ + +enum Event_scheduler::enum_error_code +Event_scheduler::add_event(THD *thd, Event_timed *et, bool check_existence) +{ + enum enum_error_code res; + Event_timed *et_new; + DBUG_ENTER("Event_scheduler::add_event"); + DBUG_PRINT("enter", ("thd=%p et=%p lock=%p",thd,et,&LOCK_scheduler_data)); + + LOCK_SCHEDULER_DATA(); + if (!is_running_or_suspended()) + { + DBUG_PRINT("info", ("scheduler not running but %d. doing nothing", state)); + UNLOCK_SCHEDULER_DATA(); + DBUG_RETURN(OP_OK); + } + if (check_existence && find_event(et, FALSE)) + { + res= OP_ALREADY_EXISTS; + goto end; + } + + /* We need to load the event on scheduler_root */ + if (!(res= load_named_event(thd, et, &et_new))) + { + queue_insert_safe(&queue, (byte *) et_new); + DBUG_PRINT("info", ("Sending COND_new_work")); + pthread_cond_signal(&cond_vars[COND_new_work]); + } + else if (res == OP_DISABLED_EVENT) + res= OP_OK; +end: + UNLOCK_SCHEDULER_DATA(); + DBUG_RETURN(res); +} + + +/* + Drops an event from the scheduler queue + + SYNOPSIS + Event_scheduler::drop_event() + etn The event to drop + state Wait the event or kill&drop + + RETURN VALUE + FALSE OK (replaced or scheduler not working) + TRUE Failure +*/ + +bool +Event_scheduler::drop_event(THD *thd, Event_timed *et) +{ + int res; + Event_timed *et_old; + DBUG_ENTER("Event_scheduler::drop_event"); + DBUG_PRINT("enter", ("thd=%p et=%p lock=%p",thd,et,&LOCK_scheduler_data)); + + LOCK_SCHEDULER_DATA(); + if (!is_running_or_suspended()) + { + DBUG_PRINT("info", ("scheduler not running but %d. doing nothing", state)); + UNLOCK_SCHEDULER_DATA(); + DBUG_RETURN(OP_OK); + } + + if (!(et_old= find_event(et, TRUE))) + DBUG_PRINT("info", ("No such event found, probably DISABLED")); + + UNLOCK_SCHEDULER_DATA(); + + /* See comments in ::replace_event() why this is split in two parts. */ + if (et_old) + { + switch ((res= et_old->kill_thread(thd))) { + case EVEX_CANT_KILL: + /* Don't delete but continue */ + et_old->flags |= EVENT_FREE_WHEN_FINISHED; + break; + case 0: + /* + kill_thread() waits till the spawned thread finishes after it's + killed. Hence, we delete here memory which is no more referenced from + a running thread. + */ + delete et_old; + /* + We don't signal COND_new_work here because: + 1. Even if the dropped event is on top of the queue this will not + move another one to be executed before the time the one on the + top (but could be at the same second as the dropped one) + 2. If this was the last event on the queue, then pthread_cond_timedwait + in ::run() will finish and then see that the queue is empty and + call cond_wait(). Hence, no need to interrupt the blocked + ::run() thread. + */ + break; + default: + sql_print_error("SCHEDULER: Got unexpected error %d", res); + DBUG_ASSERT(0); + } + } + + DBUG_RETURN(FALSE); +} + + +/* + Replaces an event in the scheduler queue + + SYNOPSIS + Event_scheduler::replace_event() + et The event to replace(add) into the queue + state Async or sync stopping + + RETURN VALUE + OP_OK OK or scheduler not working + OP_LOAD_ERROR Error during loading from disk + OP_ALREADY_EXISTS Event already in the queue +*/ + +enum Event_scheduler::enum_error_code +Event_scheduler::replace_event(THD *thd, Event_timed *et, LEX_STRING *new_schema, + LEX_STRING *new_name) +{ + enum enum_error_code res; + Event_timed *et_old, *et_new= NULL; + LEX_STRING old_schema, old_name; + + DBUG_ENTER("Event_scheduler::replace_event"); + DBUG_PRINT("enter", ("thd=%p et=%p et=[%s.%s] lock=%p", + thd, et, et->dbname.str, et->name.str, &LOCK_scheduler_data)); + + LOCK_SCHEDULER_DATA(); + if (!is_running_or_suspended()) + { + DBUG_PRINT("info", ("scheduler not running but %d. doing nothing", state)); + UNLOCK_SCHEDULER_DATA(); + DBUG_RETURN(OP_OK); + } + + if (!(et_old= find_event(et, TRUE))) + DBUG_PRINT("info", ("%s.%s not found cached, probably was DISABLED", + et->dbname.str, et->name.str)); + + if (new_schema && new_name) + { + old_schema= et->dbname; + old_name= et->name; + et->dbname= *new_schema; + et->name= *new_name; + } + /* + We need to load the event (it's strings but on the object itself) + on scheduler_root. et_new could be NULL : + 1. Error occured + 2. If the replace is DISABLED, we don't load it into the queue. + */ + if (!(res= load_named_event(thd, et, &et_new))) + { + queue_insert_safe(&queue, (byte *) et_new); + DBUG_PRINT("info", ("Sending COND_new_work")); + pthread_cond_signal(&cond_vars[COND_new_work]); + } + else if (res == OP_DISABLED_EVENT) + res= OP_OK; + + if (new_schema && new_name) + { + et->dbname= old_schema; + et->name= old_name; + } + + UNLOCK_SCHEDULER_DATA(); + /* + Andrey: Is this comment still truthful ??? + + We don't move this code above because a potential kill_thread will call + THD::awake(). Which in turn will try to acqure mysys_var->current_mutex, + which is LOCK_scheduler_data on which the COND_new_work in ::run() locks. + Hence, we try to acquire a lock which we have already acquired and we run + into an assert. Holding LOCK_scheduler_data however is not needed because + we don't touch any invariant of the scheduler anymore. ::drop_event() does + the same. + */ + if (et_old) + { + switch (et_old->kill_thread(thd)) { + case EVEX_CANT_KILL: + /* Don't delete but continue */ + et_old->flags |= EVENT_FREE_WHEN_FINISHED; + break; + case 0: + /* + kill_thread() waits till the spawned thread finishes after it's + killed. Hence, we delete here memory which is no more referenced from + a running thread. + */ + delete et_old; + /* + We don't signal COND_new_work here because: + 1. Even if the dropped event is on top of the queue this will not + move another one to be executed before the time the one on the + top (but could be at the same second as the dropped one) + 2. If this was the last event on the queue, then pthread_cond_timedwait + in ::run() will finish and then see that the queue is empty and + call cond_wait(). Hence, no need to interrupt the blocked + ::run() thread. + */ + break; + default: + DBUG_ASSERT(0); + } + } + + DBUG_RETURN(res); +} + + +/* + Searches for an event in the scheduler queue + + SYNOPSIS + Event_scheduler::find_event() + etn The event to find + comparator The function to use for comparing + remove_from_q If found whether to remove from the Q + + RETURN VALUE + NULL Not found + otherwise Address + + NOTE + The caller should do the locking also the caller is responsible for + actual signalling in case an event is removed from the queue + (signalling COND_new_work for instance). +*/ + +Event_timed * +Event_scheduler::find_event(Event_timed *etn, bool remove_from_q) +{ + uint i; + DBUG_ENTER("Event_scheduler::find_event"); + + for (i= 0; i < queue.elements; ++i) + { + Event_timed *et= (Event_timed *) queue_element(&queue, i); + DBUG_PRINT("info", ("[%s.%s]==[%s.%s]?", etn->dbname.str, etn->name.str, + et->dbname.str, et->name.str)); + if (event_timed_identifier_equal(etn, et)) + { + if (remove_from_q) + queue_remove(&queue, i); + DBUG_RETURN(et); + } + } + + DBUG_RETURN(NULL); +} + + +/* + Drops all events from the in-memory queue and disk that match + certain pattern evaluated by a comparator function + + SYNOPSIS + Event_scheduler::drop_matching_events() + thd THD + pattern A pattern string + comparator The function to use for comparing + + RETURN VALUE + -1 Scheduler not working + >=0 Number of dropped events + + NOTE + Expected is the caller to acquire lock on LOCK_scheduler_data +*/ + +void +Event_scheduler::drop_matching_events(THD *thd, LEX_STRING *pattern, + bool (*comparator)(Event_timed *,LEX_STRING *)) +{ + DBUG_ENTER("Event_scheduler::drop_matching_events"); + DBUG_PRINT("enter", ("pattern=%*s state=%d", pattern->length, pattern->str, + state)); + if (is_running_or_suspended()) + { + uint i= 0, dropped= 0; + while (i < queue.elements) + { + Event_timed *et= (Event_timed *) queue_element(&queue, i); + DBUG_PRINT("info", ("[%s.%s]?", et->dbname.str, et->name.str)); + if (comparator(et, pattern)) + { + /* + The queue is ordered. If we remove an element, then all elements after + it will shift one position to the left, if we imagine it as an array + from left to the right. In this case we should not increment the + counter and the (i < queue.elements) condition is ok. + */ + queue_remove(&queue, i); + + /* See replace_event() */ + switch (et->kill_thread(thd)) { + case EVEX_CANT_KILL: + /* Don't delete but continue */ + et->flags |= EVENT_FREE_WHEN_FINISHED; + ++dropped; + break; + case 0: + delete et; + ++dropped; + break; + default: + DBUG_ASSERT(0); + } + } + else + i++; + } + DBUG_PRINT("info", ("Dropped %lu", dropped)); + } + /* + Don't send COND_new_work because no need to wake up the scheduler thread. + When it wakes next time up it will recalculate how much more it should + sleep if the top of the queue has been changed by this method. + */ + + DBUG_VOID_RETURN; +} + + +/* + Drops all events from the in-memory queue and disk that are from + certain schema. + + SYNOPSIS + Event_scheduler::drop_schema_events() + thd THD + db The schema name + + RETURN VALUE + -1 Scheduler not working + >=0 Number of dropped events +*/ + +int +Event_scheduler::drop_schema_events(THD *thd, LEX_STRING *schema) +{ + int ret; + DBUG_ENTER("Event_scheduler::drop_schema_events"); + LOCK_SCHEDULER_DATA(); + if (is_running_or_suspended()) + drop_matching_events(thd, schema, event_timed_db_equal); + + ret= db_drop_events_from_table(thd, schema); + UNLOCK_SCHEDULER_DATA(); + + DBUG_RETURN(ret); +} + + +extern pthread_attr_t connection_attrib; + + +/* + Starts the event scheduler + + SYNOPSIS + Event_scheduler::start() + + RETURN VALUE + FALSE OK + TRUE Error +*/ + +bool +Event_scheduler::start() +{ + bool ret= FALSE; + pthread_t th; + DBUG_ENTER("Event_scheduler::start"); + + LOCK_SCHEDULER_DATA(); + /* If already working or starting don't make another attempt */ + DBUG_ASSERT(state == INITIALIZED); + if (state > INITIALIZED) + { + DBUG_PRINT("info", ("scheduler is already running or starting")); + ret= TRUE; + goto end; + } + + /* + Now if another thread calls start it will bail-out because the branch + above will be executed. Thus no two or more child threads will be forked. + If the child thread cannot start for some reason then `state` is set + to CANTSTART and COND_started is also signaled. In this case we + set `state` back to INITIALIZED so another attempt to start the scheduler + can be made. + */ + state= COMMENCING; + /* Fork */ + if (pthread_create(&th, &connection_attrib, event_scheduler_thread, + (void*)this)) + { + DBUG_PRINT("error", ("cannot create a new thread")); + state= INITIALIZED; + ret= TRUE; + goto end; + } + + /* Wait till the child thread has booted (w/ or wo success) */ + while (!is_running_or_suspended() && state != CANTSTART) + cond_wait(COND_started_or_stopped, &LOCK_scheduler_data); + + /* + If we cannot start for some reason then don't prohibit further attempts. + Set back to INITIALIZED. + */ + if (state == CANTSTART) + { + state= INITIALIZED; + ret= TRUE; + goto end; + } + +end: + UNLOCK_SCHEDULER_DATA(); + DBUG_RETURN(ret); +} + + +/* + Starts the event scheduler in suspended mode. + + SYNOPSIS + Event_scheduler::start_suspended() + + RETURN VALUE + TRUE OK + FALSE Error +*/ + +bool +Event_scheduler::start_suspended() +{ + DBUG_ENTER("Event_scheduler::start_suspended"); + start_scheduler_suspended= TRUE; + DBUG_RETURN(start()); +} + + + +/* + Report back that we cannot start. Used for ocasions where + we can't go into ::run() and have to report externally. + + SYNOPSIS + Event_scheduler::report_error_during_start() +*/ + +inline void +Event_scheduler::report_error_during_start() +{ + DBUG_ENTER("Event_scheduler::report_error_during_start"); + + LOCK_SCHEDULER_DATA(); + state= CANTSTART; + DBUG_PRINT("info", ("Sending back COND_started_or_stopped")); + pthread_cond_signal(&cond_vars[COND_started_or_stopped]); + UNLOCK_SCHEDULER_DATA(); + + DBUG_VOID_RETURN; +} + + +/* + The internal loop of the event scheduler + + SYNOPSIS + Event_scheduler::run() + thd Thread + + RETURN VALUE + FALSE OK + TRUE Failure +*/ + +bool +Event_scheduler::run(THD *thd) +{ + int ret; + struct timespec abstime; + DBUG_ENTER("Event_scheduler::run"); + DBUG_PRINT("enter", ("thd=%p", thd)); + + LOCK_SCHEDULER_DATA(); + ret= load_events_from_db(thd); + + if (!ret) + { + thread_id= thd->thread_id; + state= start_scheduler_suspended? SUSPENDED:RUNNING; + start_scheduler_suspended= FALSE; + } + else + state= CANTSTART; + + DBUG_PRINT("info", ("Sending back COND_started_or_stopped")); + pthread_cond_signal(&cond_vars[COND_started_or_stopped]); + if (ret) + { + UNLOCK_SCHEDULER_DATA(); + DBUG_RETURN(TRUE); + } + if (!check_n_suspend_if_needed(thd)) + UNLOCK_SCHEDULER_DATA(); + + sql_print_information("SCHEDULER: Manager thread started with id %lu", + thd->thread_id); + abstime.tv_nsec= 0; + while (is_running_or_suspended()) + { + Event_timed *et; + + LOCK_SCHEDULER_DATA(); + if (check_n_wait_for_non_empty_queue(thd)) + continue; + + /* On TRUE data is unlocked, go back to the beginning */ + if (check_n_suspend_if_needed(thd)) + continue; + + /* Guaranteed locked here */ + if (state == IN_SHUTDOWN || shutdown_in_progress) + { + UNLOCK_SCHEDULER_DATA(); + break; + } + DBUG_ASSERT(state == RUNNING); + + et= (Event_timed *)queue_top(&queue); + + /* Skip disabled events */ + if (et->status != Event_timed::ENABLED) + { + /* + It could be a one-timer scheduled for a time, already in the past when the + scheduler was suspended. + */ + sql_print_information("SCHEDULER: Found a disabled event %*s.%*s in the queue", + et->dbname.length, et->dbname.str, et->name.length, + et->name.str); + queue_remove(&queue, 0); + /* ToDo: check this again */ + if (et->dropped) + et->drop(thd); + delete et; + UNLOCK_SCHEDULER_DATA(); + continue; + } + thd->proc_info= (char *)"Computing"; + DBUG_PRINT("evex manager",("computing time to sleep till next exec")); + /* Timestamp is in UTC */ + abstime.tv_sec= sec_since_epoch_TIME(&et->execute_at); + + thd->end_time(); + if (abstime.tv_sec > thd->query_start()) + { + /* Event trigger time is in the future */ + thd->proc_info= (char *)"Sleep"; + DBUG_PRINT("info", ("Going to sleep. Should wakeup after approx %d secs", + abstime.tv_sec - thd->query_start())); + DBUG_PRINT("info", ("Entering condition because waiting for activation")); + /* + Use THD::enter_cond()/exit_cond() or we won't be able to kill a + sleeping thread. Though ::stop() can do it by sending COND_new_work + an user can't by just issuing 'KILL x'; . In the latter case + pthread_cond_timedwait() will wait till `abstime`. + "Sleeping until next time" + */ + thd->enter_cond(&cond_vars[COND_new_work],&LOCK_scheduler_data,"Sleeping"); + + pthread_cond_timedwait(&cond_vars[COND_new_work], &LOCK_scheduler_data, + &abstime); + + DBUG_PRINT("info", ("Manager woke up. state is %d", state)); + /* + If we get signal we should recalculate the whether it's the right time + because there could be : + 1. Spurious wake-up + 2. The top of the queue was changed (new one becase of add/drop/replace) + */ + /* This will do implicit UNLOCK_SCHEDULER_DATA() */ + thd->exit_cond(""); + } + else + { + thd->proc_info= (char *)"Executing"; + /* + Execute the event. An error may occur if a thread cannot be forked. + In this case stop the manager. + We should enter ::execute_top() with locked LOCK_scheduler_data. + */ + int ret= execute_top(thd); + UNLOCK_SCHEDULER_DATA(); + if (ret) + break; + } + } + + thd->proc_info= (char *)"Cleaning"; + + LOCK_SCHEDULER_DATA(); + /* + It's possible that a user has used (SQL)COM_KILL. Hence set the appropriate + state because it is only set by ::stop(). + */ + if (state != IN_SHUTDOWN) + { + DBUG_PRINT("info", ("We got KILL but the but not from ::stop()")); + state= IN_SHUTDOWN; + } + UNLOCK_SCHEDULER_DATA(); + + sql_print_information("SCHEDULER: Shutting down"); + + thd->proc_info= (char *)"Cleaning queue"; + clean_queue(thd); + THD_CHECK_SENTRY(thd); + + /* free mamager_root memory but don't destroy the root */ + thd->proc_info= (char *)"Cleaning memory root"; + free_root(&scheduler_root, MYF(0)); + THD_CHECK_SENTRY(thd); + + /* + We notify the waiting thread which shutdowns us that we have cleaned. + There are few more instructions to be executed in this pthread but + they don't affect manager structures thus it's safe to signal already + at this point. + */ + LOCK_SCHEDULER_DATA(); + thd->proc_info= (char *)"Sending shutdown signal"; + DBUG_PRINT("info", ("Sending COND_started_or_stopped")); + if (state == IN_SHUTDOWN) + pthread_cond_signal(&cond_vars[COND_started_or_stopped]); + + state= INITIALIZED; + /* + We set it here because ::run() can stop not only because of ::stop() + call but also because of `KILL x` + */ + thread_id= 0; + sql_print_information("SCHEDULER: Stopped"); + UNLOCK_SCHEDULER_DATA(); + + /* We have modified, we set back */ + thd->query= NULL; + thd->query_length= 0; + + DBUG_RETURN(FALSE); +} + + +/* + Executes the top element of the queue. Auxiliary method for ::run(). + + SYNOPSIS + Event_scheduler::execute_top() + + RETURN VALUE + FALSE OK + TRUE Failure + + NOTE + NO locking is done. EXPECTED is that the caller should have locked + the queue (w/ LOCK_scheduler_data). +*/ + +bool +Event_scheduler::execute_top(THD *thd) +{ + int spawn_ret_code; + bool ret= FALSE; + DBUG_ENTER("Event_scheduler::execute_top"); + DBUG_PRINT("enter", ("thd=%p", thd)); + + Event_timed *et= (Event_timed *)queue_top(&queue); + + /* Is it good idea to pass a stack address ?*/ + Worker_thread_param param(et); + + pthread_mutex_lock(¶m.LOCK_started); + /* + We don't lock LOCK_scheduler_data fpr workers_increment() because it's a + pre-requisite for calling the current_method. + */ + switch ((spawn_ret_code= et->spawn_now(event_worker_thread, ¶m))) { + case EVENT_EXEC_CANT_FORK: + /* + We don't lock LOCK_scheduler_data here because it's a pre-requisite + for calling the current_method. + */ + sql_print_error("SCHEDULER: Problem while trying to create a thread"); + ret= TRUE; + break; + case EVENT_EXEC_ALREADY_EXEC: + /* + We don't lock LOCK_scheduler_data here because it's a pre-requisite + for calling the current_method. + */ + sql_print_information("SCHEDULER: %s.%s in execution. Skip this time.", + et->dbname.str, et->name.str); + if ((et->flags & EVENT_EXEC_NO_MORE) || et->status == Event_timed::DISABLED) + queue_remove(&queue, 0);// 0 is top, internally 1 + else + queue_replaced(&queue); + break; + default: + DBUG_ASSERT(!spawn_ret_code); + if ((et->flags & EVENT_EXEC_NO_MORE) || et->status == Event_timed::DISABLED) + queue_remove(&queue, 0);// 0 is top, internally 1 + else + queue_replaced(&queue); + /* + We don't lock LOCK_scheduler_data here because it's a pre-requisite + for calling the current_method. + */ + if (likely(!spawn_ret_code)) + { + /* Wait the forked thread to start */ + do { + pthread_cond_wait(¶m.COND_started, ¶m.LOCK_started); + } while (!param.started); + } + /* + param was allocated on the stack so no explicit delete as well as + in this moment it's no more used in the spawned thread so it's safe + to be deleted. + */ + break; + } + pthread_mutex_unlock(¶m.LOCK_started); + /* `param` is on the stack and will be destructed by the compiler */ + + DBUG_RETURN(ret); +} + + +/* + Cleans the scheduler's queue. Auxiliary method for ::run(). + + SYNOPSIS + Event_scheduler::clean_queue() + thd Thread +*/ + +void +Event_scheduler::clean_queue(THD *thd) +{ + CHARSET_INFO *scs= system_charset_info; + uint i; + DBUG_ENTER("Event_scheduler::clean_queue"); + DBUG_PRINT("enter", ("thd=%p", thd)); + + LOCK_SCHEDULER_DATA(); + stop_all_running_events(thd); + UNLOCK_SCHEDULER_DATA(); + + sql_print_information("SCHEDULER: Emptying the queue"); + + /* empty the queue */ + for (i= 0; i < queue.elements; ++i) + { + Event_timed *et= (Event_timed *) queue_element(&queue, i); + et->free_sp(); + delete et; + } + resize_queue(&queue, 0); + + DBUG_VOID_RETURN; +} + + +/* + Stops all running events + + SYNOPSIS + Event_scheduler::stop_all_running_events() + thd Thread + + NOTE + LOCK_scheduler data must be acquired prior to call to this method +*/ + +void +Event_scheduler::stop_all_running_events(THD *thd) +{ + CHARSET_INFO *scs= system_charset_info; + uint i; + DYNAMIC_ARRAY running_threads; + THD *tmp; + DBUG_ENTER("Event_scheduler::stop_all_running_events"); + DBUG_PRINT("enter", ("workers_count=%d", workers_count())); + + my_init_dynamic_array(&running_threads, sizeof(ulong), 10, 10); + + bool had_super= FALSE; + VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list + I_List_iterator<THD> it(threads); + while ((tmp=it++)) + { + if (tmp->command == COM_DAEMON) + continue; + if (tmp->system_thread == SYSTEM_THREAD_EVENT_WORKER) + push_dynamic(&running_threads, (gptr) &tmp->thread_id); + } + VOID(pthread_mutex_unlock(&LOCK_thread_count)); + + /* We need temporarily SUPER_ACL to be able to kill our offsprings */ + if (!(thd->security_ctx->master_access & SUPER_ACL)) + thd->security_ctx->master_access|= SUPER_ACL; + else + had_super= TRUE; + + char tmp_buff[10*STRING_BUFFER_USUAL_SIZE]; + char int_buff[STRING_BUFFER_USUAL_SIZE]; + String tmp_string(tmp_buff, sizeof(tmp_buff), scs); + String int_string(int_buff, sizeof(int_buff), scs); + tmp_string.length(0); + + for (i= 0; i < running_threads.elements; ++i) + { + int ret; + ulong thd_id= *dynamic_element(&running_threads, i, ulong*); + + int_string.set((longlong) thd_id,scs); + tmp_string.append(int_string); + if (i < running_threads.elements - 1) + tmp_string.append(' '); + + if ((ret= kill_one_thread(thd, thd_id, FALSE))) + { + sql_print_error("SCHEDULER: Error killing %lu code=%d", thd_id, ret); + break; + } + } + if (running_threads.elements) + sql_print_information("SCHEDULER: Killing workers :%s", tmp_string.c_ptr()); + + if (!had_super) + thd->security_ctx->master_access &= ~SUPER_ACL; + + delete_dynamic(&running_threads); + + sql_print_information("SCHEDULER: Waiting for worker threads to finish"); + + while (workers_count()) + my_sleep(100000); + + DBUG_VOID_RETURN; +} + + +/* + Stops the event scheduler + + SYNOPSIS + Event_scheduler::stop() + + RETURN VALUE + OP_OK OK + OP_CANT_KILL Error during stopping of manager thread + OP_NOT_RUNNING Manager not working + + NOTE + The caller must have acquited LOCK_scheduler_data. +*/ + +enum Event_scheduler::enum_error_code +Event_scheduler::stop() +{ + THD *thd= current_thd; + DBUG_ENTER("Event_scheduler::stop"); + DBUG_PRINT("enter", ("thd=%p", current_thd)); + + LOCK_SCHEDULER_DATA(); + if (!is_running_or_suspended()) + { + /* + One situation to be here is if there was a start that forked a new + thread but the new thread did not acquire yet LOCK_scheduler_data. + Hence, in this case return an error. + */ + DBUG_PRINT("info", ("manager not running but %d. doing nothing", state)); + UNLOCK_SCHEDULER_DATA(); + DBUG_RETURN(OP_NOT_RUNNING); + } + state= IN_SHUTDOWN; + + DBUG_PRINT("info", ("Manager thread has id %d", thread_id)); + sql_print_information("SCHEDULER: Killing manager thread %lu", thread_id); + + /* + Sending the COND_new_work to ::run() is a way to get this working without + race conditions. If we use kill_one_thread() it will call THD::awake() and + because in ::run() both THD::enter_cond()/::exit_cond() are used, + THD::awake() will try to lock LOCK_scheduler_data. If we UNLOCK it before, + then the pthread_cond_signal(COND_started_or_stopped) could be signaled in + ::run() and we can miss the signal before we relock. A way is to use + another mutex for this shutdown procedure but better not. + */ + pthread_cond_signal(&cond_vars[COND_new_work]); + /* Or we are suspended - then we should wake up */ + pthread_cond_signal(&cond_vars[COND_suspend_or_resume]); + + /* Guarantee we don't catch spurious signals */ + sql_print_information("SCHEDULER: Waiting the manager thread to reply"); + while (state != INITIALIZED) + { + DBUG_PRINT("info", ("Waiting for COND_started_or_stopped from the manager " + "thread. Current value of state is %d . " + "workers count=%d", state, workers_count())); + cond_wait(COND_started_or_stopped, &LOCK_scheduler_data); + } + DBUG_PRINT("info", ("Manager thread has cleaned up. Set state to INIT")); + UNLOCK_SCHEDULER_DATA(); + + DBUG_RETURN(OP_OK); +} + + +/* + Suspends or resumes the scheduler. + SUSPEND - it won't execute any event till resumed. + RESUME - it will resume if suspended. + + SYNOPSIS + Event_scheduler::suspend_or_resume() + + RETURN VALUE + OP_OK OK +*/ + +enum Event_scheduler::enum_error_code +Event_scheduler::suspend_or_resume( + enum Event_scheduler::enum_suspend_or_resume action) +{ + DBUG_ENTER("Event_scheduler::suspend_or_resume"); + DBUG_PRINT("enter", ("action=%d", action)); + + LOCK_SCHEDULER_DATA(); + + if ((action == SUSPEND && state == SUSPENDED) || + (action == RESUME && state == RUNNING)) + { + DBUG_PRINT("info", ("Either trying to suspend suspended or resume " + "running scheduler. Doing nothing.")); + } + else + { + /* Wake the main thread up if he is asleep */ + DBUG_PRINT("info", ("Sending signal")); + if (action==SUSPEND) + { + state= SUSPENDED; + pthread_cond_signal(&cond_vars[COND_new_work]); + } + else + { + state= RUNNING; + pthread_cond_signal(&cond_vars[COND_suspend_or_resume]); + } + DBUG_PRINT("info", ("Waiting on COND_suspend_or_resume")); + cond_wait(COND_suspend_or_resume, &LOCK_scheduler_data); + DBUG_PRINT("info", ("Got response")); + } + UNLOCK_SCHEDULER_DATA(); + DBUG_RETURN(OP_OK); +} + + +/* + Returns the number of executing events. + + SYNOPSIS + Event_scheduler::workers_count() +*/ + +uint +Event_scheduler::workers_count() +{ + THD *tmp; + uint count= 0; + + DBUG_ENTER("Event_scheduler::workers_count"); + VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list + I_List_iterator<THD> it(threads); + while ((tmp=it++)) + { + if (tmp->command == COM_DAEMON) + continue; + if (tmp->system_thread == SYSTEM_THREAD_EVENT_WORKER) + ++count; + } + VOID(pthread_mutex_unlock(&LOCK_thread_count)); + DBUG_PRINT("exit", ("%d", count)); + DBUG_RETURN(count); +} + + +/* + Checks and suspends if needed + + SYNOPSIS + Event_scheduler::check_n_suspend_if_needed() + thd Thread + + RETURN VALUE + FALSE Not suspended, we haven't slept + TRUE We were suspended. LOCK_scheduler_data is unlocked. + + NOTE + The caller should have locked LOCK_scheduler_data! + The mutex will be unlocked in case this function returns TRUE +*/ + +bool +Event_scheduler::check_n_suspend_if_needed(THD *thd) +{ + bool was_suspended= FALSE; + DBUG_ENTER("Event_scheduler::check_n_suspend_if_needed"); + if (thd->killed && !shutdown_in_progress) + { + state= SUSPENDED; + thd->killed= THD::NOT_KILLED; + } + if (state == SUSPENDED) + { + thd->enter_cond(&cond_vars[COND_suspend_or_resume], &LOCK_scheduler_data, + "Suspended"); + /* Send back signal to the thread that asked us to suspend operations */ + pthread_cond_signal(&cond_vars[COND_suspend_or_resume]); + sql_print_information("SCHEDULER: Suspending operations"); + was_suspended= TRUE; + } + while (state == SUSPENDED) + { + cond_wait(COND_suspend_or_resume, &LOCK_scheduler_data); + DBUG_PRINT("info", ("Woke up after waiting on COND_suspend_or_resume")); + if (state != SUSPENDED) + { + pthread_cond_signal(&cond_vars[COND_suspend_or_resume]); + sql_print_information("SCHEDULER: Resuming operations"); + } + } + if (was_suspended) + { + if (queue.elements) + { + uint i; + DBUG_PRINT("info", ("We have to recompute the execution times")); + + for (i= 0; i < queue.elements; i++) + { + ((Event_timed*)queue_element(&queue, i))->compute_next_execution_time(); + ((Event_timed*)queue_element(&queue, i))->update_fields(thd); + } + queue_fix(&queue); + } + /* This will implicitly unlock LOCK_scheduler_data */ + thd->exit_cond(""); + } + DBUG_RETURN(was_suspended); +} + + +/* + Checks for empty queue and waits till new element gets in + + SYNOPSIS + Event_scheduler::check_n_wait_for_non_empty_queue() + thd Thread + + RETURN VALUE + FALSE Did not wait - LOCK_scheduler_data still locked. + TRUE Waited - LOCK_scheduler_data unlocked. + + NOTE + The caller should have locked LOCK_scheduler_data! +*/ + +bool +Event_scheduler::check_n_wait_for_non_empty_queue(THD *thd) +{ + bool slept= FALSE; + DBUG_ENTER("Event_scheduler::check_n_wait_for_non_empty_queue"); + DBUG_PRINT("enter", ("q.elements=%lu state=%s", + queue.elements, states_names[state])); + + if (!queue.elements) + thd->enter_cond(&cond_vars[COND_new_work], &LOCK_scheduler_data, + "Empty queue, sleeping"); + + /* Wait in a loop protecting against catching spurious signals */ + while (!queue.elements && state == RUNNING) + { + slept= TRUE; + DBUG_PRINT("info", ("Entering condition because of empty queue")); + cond_wait(COND_new_work, &LOCK_scheduler_data); + DBUG_PRINT("info", ("Manager woke up. Hope we have events now. state=%d", + state)); + /* + exit_cond does implicit mutex_UNLOCK, we needed it locked if + 1. we loop again + 2. end the current loop and start doing calculations + */ + } + if (slept) + thd->exit_cond(""); + + DBUG_PRINT("exit", ("q.elements=%lu state=%s thd->killed=%d", + queue.elements, states_names[state], thd->killed)); + + DBUG_RETURN(slept); +} + + +/* + Wrapper for pthread_mutex_lock + + SYNOPSIS + Event_scheduler::lock_data() + mutex Mutex to lock + line The line number on which the lock is done + + RETURN VALUE + Error code of pthread_mutex_lock() +*/ + +inline void +Event_scheduler::lock_data(const char *func, uint line) +{ + DBUG_ENTER("Event_scheduler::lock_mutex"); + DBUG_PRINT("enter", ("mutex_lock=%p func=%s line=%u", + &LOCK_scheduler_data, func, line)); + pthread_mutex_lock(&LOCK_scheduler_data); + mutex_last_locked_in_func= func; + mutex_last_locked_at_line= line; + mutex_scheduler_data_locked= TRUE; + DBUG_VOID_RETURN; +} + + +/* + Wrapper for pthread_mutex_unlock + + SYNOPSIS + Event_scheduler::unlock_data() + mutex Mutex to unlock + line The line number on which the unlock is done +*/ + +inline void +Event_scheduler::unlock_data(const char *func, uint line) +{ + DBUG_ENTER("Event_scheduler::UNLOCK_mutex"); + DBUG_PRINT("enter", ("mutex_unlock=%p func=%s line=%u", + &LOCK_scheduler_data, func, line)); + mutex_last_unlocked_at_line= line; + mutex_scheduler_data_locked= FALSE; + mutex_last_unlocked_in_func= func; + pthread_mutex_unlock(&LOCK_scheduler_data); + DBUG_VOID_RETURN; +} + + +/* + Wrapper for pthread_cond_wait + + SYNOPSIS + Event_scheduler::cond_wait() + cond Conditional to wait for + mutex Mutex of the conditional + + RETURN VALUE + Error code of pthread_cond_wait() +*/ + +inline int +Event_scheduler::cond_wait(enum Event_scheduler::enum_cond_vars cond, + pthread_mutex_t *mutex) +{ + int ret; + DBUG_ENTER("Event_scheduler::cond_wait"); + DBUG_PRINT("enter", ("cond=%s mutex=%p", cond_vars_names[cond], mutex)); + ret= pthread_cond_wait(&cond_vars[cond_waiting_on=cond], mutex); + cond_waiting_on= COND_NONE; + DBUG_RETURN(ret); +} + + +/* + Checks whether the scheduler is in a running or suspended state. + + SYNOPSIS + Event_scheduler::is_running_or_suspended() + + RETURN VALUE + TRUE Either running or suspended + FALSE IN_SHUTDOWN, not started, etc. +*/ + +inline bool +Event_scheduler::is_running_or_suspended() +{ + return (state == SUSPENDED || state == RUNNING); +} + + +/* + Returns the current state of the scheduler + + SYNOPSIS + Event_scheduler::get_state() +*/ + +enum Event_scheduler::enum_state +Event_scheduler::get_state() +{ + enum Event_scheduler::enum_state ret; + DBUG_ENTER("Event_scheduler::get_state"); + /* lock_data & unlock_data are not static */ + pthread_mutex_lock(&singleton.LOCK_scheduler_data); + ret= singleton.state; + pthread_mutex_unlock(&singleton.LOCK_scheduler_data); + DBUG_RETURN(ret); +} + + +/* + Returns whether the scheduler was initialized. + + SYNOPSIS + Event_scheduler::initialized() + + RETURN VALUE + FALSE Was not initialized so far + TRUE Was initialized +*/ + +bool +Event_scheduler::initialized() +{ + DBUG_ENTER("Event_scheduler::initialized"); + DBUG_RETURN(Event_scheduler::get_state() != UNINITIALIZED); +} + + +/* + Returns the number of elements in the queue + + SYNOPSIS + Event_scheduler::events_count() + + RETURN VALUE + 0 Number of Event_timed objects in the queue +*/ + +uint +Event_scheduler::events_count() +{ + uint n; + DBUG_ENTER("Event_scheduler::events_count"); + LOCK_SCHEDULER_DATA(); + n= queue.elements; + UNLOCK_SCHEDULER_DATA(); + + DBUG_RETURN(n); +} + + +/* + Looks for a named event in mysql.event and then loads it from + the table, compiles and inserts it into the cache. + + SYNOPSIS + Event_scheduler::load_named_event() + thd THD + etn The name of the event to load and compile on scheduler's root + etn_new The loaded event + + RETURN VALUE + NULL Error during compile or the event is non-enabled. + otherwise Address +*/ + +enum Event_scheduler::enum_error_code +Event_scheduler::load_named_event(THD *thd, Event_timed *etn, Event_timed **etn_new) +{ + int ret= 0; + MEM_ROOT *tmp_mem_root; + Event_timed *et_loaded= NULL; + Open_tables_state backup; + + DBUG_ENTER("Event_scheduler::load_and_compile_event"); + DBUG_PRINT("enter",("thd=%p name:%*s",thd, etn->name.length, etn->name.str)); + + thd->reset_n_backup_open_tables_state(&backup); + /* No need to use my_error() here because db_find_event() has done it */ + { + sp_name spn(etn->dbname, etn->name); + ret= db_find_event(thd, &spn, &et_loaded, NULL, &scheduler_root); + } + thd->restore_backup_open_tables_state(&backup); + /* In this case no memory was allocated so we don't need to clean */ + if (ret) + DBUG_RETURN(OP_LOAD_ERROR); + + if (et_loaded->status != Event_timed::ENABLED) + { + /* + We don't load non-enabled events. + In db_find_event() `et_new` was allocated on the heap and not on + scheduler_root therefore we delete it here. + */ + delete et_loaded; + DBUG_RETURN(OP_DISABLED_EVENT); + } + + et_loaded->compute_next_execution_time(); + *etn_new= et_loaded; + + DBUG_RETURN(OP_OK); +} + + +/* + Loads all ENABLED events from mysql.event into the prioritized + queue. Called during scheduler main thread initialization. Compiles + the events. Creates Event_timed instances for every ENABLED event + from mysql.event. + + SYNOPSIS + Event_scheduler::load_events_from_db() + thd - Thread context. Used for memory allocation in some cases. + + RETURN VALUE + 0 OK + !0 Error (EVEX_OPEN_TABLE_FAILED, EVEX_MICROSECOND_UNSUP, + EVEX_COMPILE_ERROR) - in all these cases mysql.event was + tampered. + + NOTES + Reports the error to the console +*/ + +int +Event_scheduler::load_events_from_db(THD *thd) +{ + TABLE *table; + READ_RECORD read_record_info; + int ret= -1; + uint count= 0; + bool clean_the_queue= FALSE; + /* Compile the events on this root but only for syntax check, then discard */ + MEM_ROOT boot_root; + + DBUG_ENTER("Event_scheduler::load_events_from_db"); + DBUG_PRINT("enter", ("thd=%p", thd)); + + if (state > COMMENCING) + { + DBUG_ASSERT(0); + sql_print_error("SCHEDULER: Trying to load events while already running."); + DBUG_RETURN(EVEX_GENERAL_ERROR); + } + + if ((ret= Events::open_event_table(thd, TL_READ, &table))) + { + sql_print_error("SCHEDULER: Table mysql.event is damaged. Can not open."); + DBUG_RETURN(EVEX_OPEN_TABLE_FAILED); + } + + init_alloc_root(&boot_root, MEM_ROOT_BLOCK_SIZE, MEM_ROOT_PREALLOC); + init_read_record(&read_record_info, thd, table ,NULL,1,0); + while (!(read_record_info.read_record(&read_record_info))) + { + Event_timed *et; + if (!(et= new Event_timed)) + { + DBUG_PRINT("info", ("Out of memory")); + clean_the_queue= TRUE; + break; + } + DBUG_PRINT("info", ("Loading event from row.")); + + if ((ret= et->load_from_row(&scheduler_root, table))) + { + clean_the_queue= TRUE; + sql_print_error("SCHEDULER: Error while loading from mysql.event. " + "Table probably corrupted"); + break; + } + if (et->status != Event_timed::ENABLED) + { + DBUG_PRINT("info",("%s is disabled",et->name.str)); + delete et; + continue; + } + + DBUG_PRINT("info", ("Event %s loaded from row. ", et->name.str)); + + /* We load only on scheduler root just to check whether the body compiles */ + switch (ret= et->compile(thd, &boot_root)) { + case EVEX_MICROSECOND_UNSUP: + et->free_sp(); + sql_print_error("SCHEDULER: mysql.event is tampered. MICROSECOND is not " + "supported but found in mysql.event"); + goto end; + case EVEX_COMPILE_ERROR: + sql_print_error("SCHEDULER: Error while compiling %s.%s. Aborting load.", + et->dbname.str, et->name.str); + goto end; + default: + /* Free it, it will be compiled again on the worker thread */ + et->free_sp(); + break; + } + + /* let's find when to be executed */ + if (et->compute_next_execution_time()) + { + sql_print_error("SCHEDULER: Error while computing execution time of %s.%s." + " Skipping", et->dbname.str, et->name.str); + continue; + } + + DBUG_PRINT("load_events_from_db", ("Adding %p to the exec list.")); + queue_insert_safe(&queue, (byte *) et); + count++; + } +end: + end_read_record(&read_record_info); + free_root(&boot_root, MYF(0)); + + if (clean_the_queue) + { + for (count= 0; count < queue.elements; ++count) + queue_remove(&queue, 0); + ret= -1; + } + else + { + ret= 0; + sql_print_information("SCHEDULER: Loaded %d event%s", count, (count == 1)?"":"s"); + } + + /* Force close to free memory */ + thd->version--; + + close_thread_tables(thd); + + DBUG_PRINT("info", ("Status code %d. Loaded %d event(s)", ret, count)); + DBUG_RETURN(ret); +} + + +/* + Opens mysql.db and mysql.user and checks whether: + 1. mysql.db has column Event_priv at column 20 (0 based); + 2. mysql.user has column Event_priv at column 29 (0 based); + + SYNOPSIS + Event_scheduler::check_system_tables() +*/ + +bool +Event_scheduler::check_system_tables(THD *thd) +{ + TABLE_LIST tables; + bool not_used; + Open_tables_state backup; + bool ret; + + DBUG_ENTER("Event_scheduler::check_system_tables"); + DBUG_PRINT("enter", ("thd=%p", thd)); + + thd->reset_n_backup_open_tables_state(&backup); + + bzero((char*) &tables, sizeof(tables)); + tables.db= (char*) "mysql"; + tables.table_name= tables.alias= (char*) "db"; + tables.lock_type= TL_READ; + + if ((ret= simple_open_n_lock_tables(thd, &tables))) + sql_print_error("Cannot open mysql.db"); + else + { + ret= table_check_intact(tables.table, MYSQL_DB_FIELD_COUNT, + mysql_db_table_fields, &mysql_db_table_last_check, + ER_CANNOT_LOAD_FROM_TABLE); + close_thread_tables(thd); + } + if (ret) + DBUG_RETURN(TRUE); + + bzero((char*) &tables, sizeof(tables)); + tables.db= (char*) "mysql"; + tables.table_name= tables.alias= (char*) "user"; + tables.lock_type= TL_READ; + + if ((ret= simple_open_n_lock_tables(thd, &tables))) + sql_print_error("Cannot open mysql.db"); + else + { + if (tables.table->s->fields < 29 || + strncmp(tables.table->field[29]->field_name, + STRING_WITH_LEN("Event_priv"))) + { + sql_print_error("mysql.user has no `Event_priv` column at position 29"); + ret= TRUE; + } + close_thread_tables(thd); + } + + thd->restore_backup_open_tables_state(&backup); + + DBUG_RETURN(ret); +} + + +/* + Inits mutexes. + + SYNOPSIS + Event_scheduler::init_mutexes() +*/ + +void +Event_scheduler::init_mutexes() +{ + pthread_mutex_init(&singleton.LOCK_scheduler_data, MY_MUTEX_INIT_FAST); +} + + +/* + Destroys mutexes. + + SYNOPSIS + Event_scheduler::destroy_mutexes() +*/ + +void +Event_scheduler::destroy_mutexes() +{ + pthread_mutex_destroy(&singleton.LOCK_scheduler_data); +} + + +/* + Dumps some data about the internal status of the scheduler. + + SYNOPSIS + Event_scheduler::dump_internal_status() + thd THD + + RETURN VALUE + 0 OK + 1 Error +*/ + +int +Event_scheduler::dump_internal_status(THD *thd) +{ + DBUG_ENTER("dump_internal_status"); +#ifndef DBUG_OFF + CHARSET_INFO *scs= system_charset_info; + Protocol *protocol= thd->protocol; + List<Item> field_list; + int ret; + char tmp_buff[5*STRING_BUFFER_USUAL_SIZE]; + char int_buff[STRING_BUFFER_USUAL_SIZE]; + String tmp_string(tmp_buff, sizeof(tmp_buff), scs); + String int_string(int_buff, sizeof(int_buff), scs); + tmp_string.length(0); + int_string.length(0); + + field_list.push_back(new Item_empty_string("Name", 20)); + field_list.push_back(new Item_empty_string("Value",20)); + if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | + Protocol::SEND_EOF)) + DBUG_RETURN(1); + + protocol->prepare_for_resend(); + protocol->store(STRING_WITH_LEN("state"), scs); + protocol->store(states_names[singleton.state].str, + states_names[singleton.state].length, + scs); + + ret= protocol->write(); + /* + If not initialized - don't show anything else. get_instance() + will otherwise implicitly initialize it. We don't want that. + */ + if (singleton.state >= INITIALIZED) + { + /* last locked at*/ + /* + The first thing to do, or get_instance() will overwrite the values. + mutex_last_locked_at_line / mutex_last_unlocked_at_line + */ + protocol->prepare_for_resend(); + protocol->store(STRING_WITH_LEN("last locked at"), scs); + tmp_string.length(scs->cset->snprintf(scs, (char*) tmp_string.ptr(), + tmp_string.alloced_length(), "%s::%d", + singleton.mutex_last_locked_in_func, + singleton.mutex_last_locked_at_line)); + protocol->store(&tmp_string); + ret= protocol->write(); + + /* last unlocked at*/ + protocol->prepare_for_resend(); + protocol->store(STRING_WITH_LEN("last unlocked at"), scs); + tmp_string.length(scs->cset->snprintf(scs, (char*) tmp_string.ptr(), + tmp_string.alloced_length(), "%s::%d", + singleton.mutex_last_unlocked_in_func, + singleton.mutex_last_unlocked_at_line)); + protocol->store(&tmp_string); + ret= protocol->write(); + + /* waiting on */ + protocol->prepare_for_resend(); + protocol->store(STRING_WITH_LEN("waiting on condition"), scs); + tmp_string.length(scs->cset-> + snprintf(scs, (char*) tmp_string.ptr(), + tmp_string.alloced_length(), "%s", + (singleton.cond_waiting_on != COND_NONE) ? + cond_vars_names[singleton.cond_waiting_on]: + "NONE")); + protocol->store(&tmp_string); + ret= protocol->write(); + + Event_scheduler *scheduler= get_instance(); + + /* workers_count */ + protocol->prepare_for_resend(); + protocol->store(STRING_WITH_LEN("workers_count"), scs); + int_string.set((longlong) scheduler->workers_count(), scs); + protocol->store(&int_string); + ret= protocol->write(); + + /* queue.elements */ + protocol->prepare_for_resend(); + protocol->store(STRING_WITH_LEN("queue.elements"), scs); + int_string.set((longlong) scheduler->queue.elements, scs); + protocol->store(&int_string); + ret= protocol->write(); + + /* scheduler_data_locked */ + protocol->prepare_for_resend(); + protocol->store(STRING_WITH_LEN("scheduler data locked"), scs); + int_string.set((longlong) scheduler->mutex_scheduler_data_locked, scs); + protocol->store(&int_string); + ret= protocol->write(); + } + send_eof(thd); +#endif + DBUG_RETURN(0); +} diff --git a/sql/event_scheduler.h b/sql/event_scheduler.h new file mode 100644 index 00000000000..dffd47539fa --- /dev/null +++ b/sql/event_scheduler.h @@ -0,0 +1,254 @@ +#ifndef _EVENT_SCHEDULER_H_ +#define _EVENT_SCHEDULER_H_ +/* Copyright (C) 2004-2006 MySQL 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 */ + + +class THD; +typedef bool * (*event_timed_identifier_comparator)(Event_timed*, Event_timed*); + +int +events_init(); + +void +events_shutdown(); + + +class Event_scheduler +{ +public: + /* Return codes */ + enum enum_error_code + { + OP_OK= 0, + OP_NOT_RUNNING, + OP_CANT_KILL, + OP_CANT_INIT, + OP_DISABLED_EVENT, + OP_LOAD_ERROR, + OP_ALREADY_EXISTS + }; + + enum enum_state + { + UNINITIALIZED= 0, + INITIALIZED, + COMMENCING, + CANTSTART, + RUNNING, + SUSPENDED, + IN_SHUTDOWN + }; + + enum enum_suspend_or_resume + { + SUSPEND= 1, + RESUME= 2 + }; + + /* Singleton access */ + static Event_scheduler* + get_instance(); + + /* Methods for queue management follow */ + + enum enum_error_code + add_event(THD *thd, Event_timed *et, bool check_existence); + + bool + drop_event(THD *thd, Event_timed *et); + + enum enum_error_code + replace_event(THD *thd, Event_timed *et, LEX_STRING *new_schema, + LEX_STRING *new_name); + + int + drop_schema_events(THD *thd, LEX_STRING *schema); + + int + drop_user_events(THD *thd, LEX_STRING *definer, uint *dropped_num) + { DBUG_ASSERT(0); return 0;} + + uint + events_count(); + + /* State changing methods follow */ + + bool + start(); + + enum enum_error_code + stop(); + + bool + start_suspended(); + + bool + run(THD *thd); + + enum enum_error_code + suspend_or_resume(enum enum_suspend_or_resume action); + + bool + init(); + + void + destroy(); + + static void + init_mutexes(); + + static void + destroy_mutexes(); + + void + report_error_during_start(); + + /* Information retrieving methods follow */ + + enum enum_state + get_state(); + + bool + initialized(); + + static int + dump_internal_status(THD *thd); + + static bool + check_system_tables(THD *thd); + +private: + Event_timed * + find_event(Event_timed *etn, bool remove_from_q); + + uint + workers_count(); + + bool + is_running_or_suspended(); + + /* helper functions */ + bool + execute_top(THD *thd); + + void + clean_queue(THD *thd); + + void + stop_all_running_events(THD *thd); + + enum enum_error_code + load_named_event(THD *thd, Event_timed *etn, Event_timed **etn_new); + + int + load_events_from_db(THD *thd); + + void + drop_matching_events(THD *thd, LEX_STRING *pattern, + bool (*)(Event_timed *,LEX_STRING *)); + + bool + check_n_suspend_if_needed(THD *thd); + + bool + check_n_wait_for_non_empty_queue(THD *thd); + + /* Singleton DP is used */ + Event_scheduler(); + + enum enum_cond_vars + { + COND_NONE= -1, + /* + COND_new_work is a conditional used to signal that there is a change + of the queue that should inform the executor thread that new event should + be executed sooner than previously expected, because of add/replace event. + */ + COND_new_work= 0, + /* + COND_started is a conditional used to synchronize the thread in which + ::start() was called and the spawned thread. ::start() spawns a new thread + and then waits on COND_started but also checks when awaken that `state` is + either RUNNING or CANTSTART. Then it returns back. + */ + COND_started_or_stopped, + /* + Conditional used for signalling from the scheduler thread back to the + thread that calls ::suspend() or ::resume. Synchronizing the calls. + */ + COND_suspend_or_resume, + /* Must be always last */ + COND_LAST + }; + + /* Singleton instance */ + static Event_scheduler singleton; + + /* This is the current status of the life-cycle of the manager. */ + enum enum_state state; + + /* Set to start the scheduler in suspended state */ + bool start_scheduler_suspended; + + /* + LOCK_scheduler_data is the mutex which protects the access to the + manager's queue as well as used when signalling COND_new_work, + COND_started and COND_shutdown. + */ + pthread_mutex_t LOCK_scheduler_data; + + /* + Holds the thread id of the executor thread or 0 if the executor is not + running. It is used by ::shutdown() to know which thread to kill with + kill_one_thread(). The latter wake ups a thread if it is waiting on a + conditional variable and sets thd->killed to non-zero. + */ + ulong thread_id; + + pthread_cond_t cond_vars[COND_LAST]; + static const char * const cond_vars_names[COND_LAST]; + + /* The MEM_ROOT of the object */ + MEM_ROOT scheduler_root; + + /* The sorted queue with the Event_timed objects */ + QUEUE queue; + + uint mutex_last_locked_at_line; + uint mutex_last_unlocked_at_line; + const char* mutex_last_locked_in_func; + const char* mutex_last_unlocked_in_func; + enum enum_cond_vars cond_waiting_on; + bool mutex_scheduler_data_locked; + + /* helper functions for working with mutexes & conditionals */ + void + lock_data(const char *func, uint line); + + void + unlock_data(const char *func, uint line); + + int + cond_wait(enum enum_cond_vars, pthread_mutex_t *mutex); + +private: + /* Prevent use of these */ + Event_scheduler(const Event_scheduler &); + void operator=(Event_scheduler &); +}; + +#endif /* _EVENT_SCHEDULER_H_ */ diff --git a/sql/event_timed.cc b/sql/event_timed.cc index 879f4d6a3c9..d6d6dddf971 100644 --- a/sql/event_timed.cc +++ b/sql/event_timed.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2005 MySQL AB +/* Copyright (C) 2004-2006 MySQL 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 @@ -17,7 +17,82 @@ #define MYSQL_LEX 1 #include "event_priv.h" #include "event.h" -#include "sp.h" +#include "sp_head.h" + + +/* + Constructor + + SYNOPSIS + Event_timed::Event_timed() +*/ + +Event_timed::Event_timed():in_spawned_thread(0),locked_by_thread_id(0), + running(0), thread_id(0), status_changed(false), + last_executed_changed(false), expression(0), + created(0), modified(0), + on_completion(Event_timed::ON_COMPLETION_DROP), + status(Event_timed::ENABLED), sphead(0), + sql_mode(0), body_begin(0), dropped(false), + free_sphead_on_delete(true), flags(0) + +{ + pthread_mutex_init(&this->LOCK_running, MY_MUTEX_INIT_FAST); + pthread_cond_init(&this->COND_finished, NULL); + init(); +} + + +/* + Destructor + + SYNOPSIS + Event_timed::~Event_timed() +*/ + +Event_timed::~Event_timed() +{ + deinit_mutexes(); + + if (free_sphead_on_delete) + free_sp(); +} + + +/* + Destructor + + SYNOPSIS + Event_timed::~deinit_mutexes() +*/ + +void +Event_timed::deinit_mutexes() +{ + pthread_mutex_destroy(&this->LOCK_running); + pthread_cond_destroy(&this->COND_finished); +} + + +/* + Checks whether the event is running + + SYNOPSIS + Event_timed::is_running() +*/ + +bool +Event_timed::is_running() +{ + bool ret; + + VOID(pthread_mutex_lock(&this->LOCK_running)); + ret= running; + VOID(pthread_mutex_unlock(&this->LOCK_running)); + + return ret; +} + /* Init all member variables @@ -238,7 +313,7 @@ Event_timed::init_execute_at(THD *thd, Item *expr) expr how much? new_interval what is the interval - RETURNS + RETURN VALUE 0 OK EVEX_PARSE_ERROR fix_fields failed EVEX_BAD_PARAMS Interval is not positive @@ -249,7 +324,7 @@ int Event_timed::init_interval(THD *thd, Item *expr, interval_type new_interval) { String value; - INTERVAL interval; + INTERVAL interval_tmp; DBUG_ENTER("Event_timed::init_interval"); @@ -257,71 +332,74 @@ Event_timed::init_interval(THD *thd, Item *expr, interval_type new_interval) DBUG_RETURN(EVEX_PARSE_ERROR); value.alloc(MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN); - if (get_interval_value(expr, new_interval, &value, &interval)) + if (get_interval_value(expr, new_interval, &value, &interval_tmp)) DBUG_RETURN(EVEX_PARSE_ERROR); expression= 0; switch (new_interval) { case INTERVAL_YEAR: - expression= interval.year; + expression= interval_tmp.year; break; case INTERVAL_QUARTER: case INTERVAL_MONTH: - expression= interval.month; + expression= interval_tmp.month; break; case INTERVAL_WEEK: case INTERVAL_DAY: - expression= interval.day; + expression= interval_tmp.day; break; case INTERVAL_HOUR: - expression= interval.hour; + expression= interval_tmp.hour; break; case INTERVAL_MINUTE: - expression= interval.minute; + expression= interval_tmp.minute; break; case INTERVAL_SECOND: - expression= interval.second; + expression= interval_tmp.second; break; case INTERVAL_YEAR_MONTH: // Allow YEAR-MONTH YYYYYMM - expression= interval.year* 12 + interval.month; + expression= interval_tmp.year* 12 + interval_tmp.month; break; case INTERVAL_DAY_HOUR: - expression= interval.day* 24 + interval.hour; + expression= interval_tmp.day* 24 + interval_tmp.hour; break; case INTERVAL_DAY_MINUTE: - expression= (interval.day* 24 + interval.hour) * 60 + interval.minute; + expression= (interval_tmp.day* 24 + interval_tmp.hour) * 60 + + interval_tmp.minute; break; case INTERVAL_HOUR_SECOND: /* day is anyway 0 */ case INTERVAL_DAY_SECOND: /* DAY_SECOND having problems because of leap seconds? */ - expression= ((interval.day* 24 + interval.hour) * 60 + interval.minute)*60 - + interval.second; + expression= ((interval_tmp.day* 24 + interval_tmp.hour) * 60 + + interval_tmp.minute)*60 + + interval_tmp.second; break; case INTERVAL_MINUTE_MICROSECOND: /* day and hour are 0 */ case INTERVAL_HOUR_MICROSECOND: /* day is anyway 0 */ case INTERVAL_DAY_MICROSECOND: DBUG_RETURN(EVEX_MICROSECOND_UNSUP); - expression= ((((interval.day*24) + interval.hour)*60+interval.minute)*60 + - interval.second) * 1000000L + interval.second_part; + expression= ((((interval_tmp.day*24) + interval_tmp.hour)*60+ + interval_tmp.minute)*60 + + interval_tmp.second) * 1000000L + interval_tmp.second_part; break; case INTERVAL_HOUR_MINUTE: - expression= interval.hour * 60 + interval.minute; + expression= interval_tmp.hour * 60 + interval_tmp.minute; break; case INTERVAL_MINUTE_SECOND: - expression= interval.minute * 60 + interval.second; + expression= interval_tmp.minute * 60 + interval_tmp.second; break; case INTERVAL_SECOND_MICROSECOND: DBUG_RETURN(EVEX_MICROSECOND_UNSUP); - expression= interval.second * 1000000L + interval.second_part; + expression= interval_tmp.second * 1000000L + interval_tmp.second_part; break; case INTERVAL_MICROSECOND: DBUG_RETURN(EVEX_MICROSECOND_UNSUP); } - if (interval.neg || expression > EVEX_MAX_INTERVAL_VALUE) + if (interval_tmp.neg || expression > EVEX_MAX_INTERVAL_VALUE) DBUG_RETURN(EVEX_BAD_PARAMS); - this->interval= new_interval; + interval= new_interval; DBUG_RETURN(0); } @@ -342,7 +420,7 @@ Event_timed::init_interval(THD *thd, Item *expr, interval_type new_interval) DATE_ADD(NOW(), INTERVAL 1 DAY) -- start tommorow at same time. - RETURNS + RETURN VALUE 0 OK EVEX_PARSE_ERROR fix_fields failed EVEX_BAD_PARAMS starts before now @@ -408,7 +486,7 @@ Event_timed::init_starts(THD *thd, Item *new_starts) DATE_ADD(NOW(), INTERVAL 1 DAY) -- end tommorow at same time. - RETURNS + RETURN VALUE 0 OK EVEX_PARSE_ERROR fix_fields failed ER_WRONG_VALUE starts distant date (after year 2037) @@ -492,6 +570,9 @@ Event_timed::init_comment(THD *thd, LEX_STRING *set_comment) SYNOPSIS Event_timed::init_definer() + + RETURN VALUE + 0 OK */ int @@ -534,6 +615,10 @@ Event_timed::init_definer(THD *thd) SYNOPSIS Event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table) + RETURN VALUE + 0 OK + EVEX_GET_FIELD_FAILED Error + NOTES This method is silent on errors and should behave like that. Callers should handle throwing of error messages. The reason is that the class @@ -555,29 +640,29 @@ Event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table) et= this; - if (table->s->fields != EVEX_FIELD_COUNT) + if (table->s->fields != Events::FIELD_COUNT) goto error; if ((et->dbname.str= get_field(mem_root, - table->field[EVEX_FIELD_DB])) == NULL) + table->field[Events::FIELD_DB])) == NULL) goto error; et->dbname.length= strlen(et->dbname.str); if ((et->name.str= get_field(mem_root, - table->field[EVEX_FIELD_NAME])) == NULL) + table->field[Events::FIELD_NAME])) == NULL) goto error; et->name.length= strlen(et->name.str); if ((et->body.str= get_field(mem_root, - table->field[EVEX_FIELD_BODY])) == NULL) + table->field[Events::FIELD_BODY])) == NULL) goto error; et->body.length= strlen(et->body.str); if ((et->definer.str= get_field(mem_root, - table->field[EVEX_FIELD_DEFINER])) == NullS) + table->field[Events::FIELD_DEFINER])) == NullS) goto error; et->definer.length= strlen(et->definer.str); @@ -594,69 +679,71 @@ Event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table) et->definer_host.str= strmake_root(mem_root, ptr + 1, len);/* 1:because of @*/ et->definer_host.length= len; - et->starts_null= table->field[EVEX_FIELD_STARTS]->is_null(); - res1= table->field[EVEX_FIELD_STARTS]->get_date(&et->starts,TIME_NO_ZERO_DATE); + et->starts_null= table->field[Events::FIELD_STARTS]->is_null(); + res1= table->field[Events::FIELD_STARTS]-> + get_date(&et->starts,TIME_NO_ZERO_DATE); - et->ends_null= table->field[EVEX_FIELD_ENDS]->is_null(); - res2= table->field[EVEX_FIELD_ENDS]->get_date(&et->ends, TIME_NO_ZERO_DATE); + et->ends_null= table->field[Events::FIELD_ENDS]->is_null(); + res2= table->field[Events::FIELD_ENDS]->get_date(&et->ends, TIME_NO_ZERO_DATE); - if (!table->field[EVEX_FIELD_INTERVAL_EXPR]->is_null()) - et->expression= table->field[EVEX_FIELD_INTERVAL_EXPR]->val_int(); + if (!table->field[Events::FIELD_INTERVAL_EXPR]->is_null()) + et->expression= table->field[Events::FIELD_INTERVAL_EXPR]->val_int(); else et->expression= 0; /* If res1 and res2 are true then both fields are empty. - Hence if EVEX_FIELD_EXECUTE_AT is empty there is an error. + Hence if Events::FIELD_EXECUTE_AT is empty there is an error. */ - et->execute_at_null= table->field[EVEX_FIELD_EXECUTE_AT]->is_null(); + et->execute_at_null= + table->field[Events::FIELD_EXECUTE_AT]->is_null(); DBUG_ASSERT(!(et->starts_null && et->ends_null && !et->expression && et->execute_at_null)); if (!et->expression && - table->field[EVEX_FIELD_EXECUTE_AT]->get_date(&et->execute_at, - TIME_NO_ZERO_DATE)) + table->field[Events::FIELD_EXECUTE_AT]-> get_date(&et->execute_at, + TIME_NO_ZERO_DATE)) goto error; /* In DB the values start from 1 but enum interval_type starts from 0 */ - if (!table->field[EVEX_FIELD_TRANSIENT_INTERVAL]->is_null()) - et->interval= (interval_type) - ((ulonglong) table->field[EVEX_FIELD_TRANSIENT_INTERVAL]->val_int() - 1); + if (!table->field[Events::FIELD_TRANSIENT_INTERVAL]->is_null()) + et->interval= (interval_type) ((ulonglong) + table->field[Events::FIELD_TRANSIENT_INTERVAL]->val_int() - 1); else et->interval= (interval_type) 0; - et->created= table->field[EVEX_FIELD_CREATED]->val_int(); - et->modified= table->field[EVEX_FIELD_MODIFIED]->val_int(); + et->created= table->field[Events::FIELD_CREATED]->val_int(); + et->modified= table->field[Events::FIELD_MODIFIED]->val_int(); - table->field[EVEX_FIELD_LAST_EXECUTED]-> + table->field[Events::FIELD_LAST_EXECUTED]-> get_date(&et->last_executed, TIME_NO_ZERO_DATE); last_executed_changed= false; /* ToDo : Andrey . Find a way not to allocate ptr on event_mem_root */ - if ((ptr= get_field(mem_root, table->field[EVEX_FIELD_STATUS])) == NullS) + if ((ptr= get_field(mem_root, table->field[Events::FIELD_STATUS])) == NullS) goto error; DBUG_PRINT("load_from_row", ("Event [%s] is [%s]", et->name.str, ptr)); - et->status= (ptr[0]=='E'? MYSQL_EVENT_ENABLED:MYSQL_EVENT_DISABLED); + et->status= (ptr[0]=='E'? Event_timed::ENABLED:Event_timed::DISABLED); /* ToDo : Andrey . Find a way not to allocate ptr on event_mem_root */ if ((ptr= get_field(mem_root, - table->field[EVEX_FIELD_ON_COMPLETION])) == NullS) + table->field[Events::FIELD_ON_COMPLETION])) == NullS) goto error; - et->on_completion= (ptr[0]=='D'? MYSQL_EVENT_ON_COMPLETION_DROP: - MYSQL_EVENT_ON_COMPLETION_PRESERVE); + et->on_completion= (ptr[0]=='D'? Event_timed::ON_COMPLETION_DROP: + Event_timed::ON_COMPLETION_PRESERVE); - et->comment.str= get_field(mem_root, table->field[EVEX_FIELD_COMMENT]); + et->comment.str= get_field(mem_root, table->field[Events::FIELD_COMMENT]); if (et->comment.str != NullS) et->comment.length= strlen(et->comment.str); else et->comment.length= 0; - et->sql_mode= (ulong) table->field[EVEX_FIELD_SQL_MODE]->val_int(); + et->sql_mode= (ulong) table->field[Events::FIELD_SQL_MODE]->val_int(); DBUG_RETURN(0); error: @@ -676,7 +763,7 @@ error: i_value quantity of time type interval to add i_type type of interval to add (SECOND, MINUTE, HOUR, WEEK ...) - RETURNS + RETURN VALUE 0 OK 1 Error @@ -834,6 +921,10 @@ done: SYNOPSIS Event_timed::compute_next_execution_time() + RETURN VALUE + FALSE OK + TRUE Error + NOTES The time is set in execute_at, if no more executions the latter is set to 0000-00-00. @@ -843,7 +934,6 @@ bool Event_timed::compute_next_execution_time() { TIME time_now; - my_time_t now; int tmp; DBUG_ENTER("Event_timed::compute_next_execution_time"); @@ -852,7 +942,7 @@ Event_timed::compute_next_execution_time() TIME_to_ulonglong_datetime(&ends), TIME_to_ulonglong_datetime(&last_executed))); - if (status == MYSQL_EVENT_DISABLED) + if (status == Event_timed::DISABLED) { DBUG_PRINT("compute_next_execution_time", ("Event %s is DISABLED", name.str)); @@ -866,14 +956,15 @@ Event_timed::compute_next_execution_time() { DBUG_PRINT("info",("One-time event %s.%s of was already executed", dbname.str, name.str, definer.str)); - dropped= (on_completion == MYSQL_EVENT_ON_COMPLETION_DROP); + dropped= (on_completion == Event_timed::ON_COMPLETION_DROP); DBUG_PRINT("info",("One-time event will be dropped=%d.", dropped)); - status= MYSQL_EVENT_DISABLED; + status= Event_timed::DISABLED; status_changed= true; } goto ret; } + my_tz_UTC->gmt_sec_to_TIME(&time_now, current_thd->query_start()); DBUG_PRINT("info",("NOW=[%llu]", TIME_to_ulonglong_datetime(&time_now))); @@ -885,9 +976,10 @@ Event_timed::compute_next_execution_time() /* time_now is after ends. don't execute anymore */ set_zero_time(&execute_at, MYSQL_TIMESTAMP_DATETIME); execute_at_null= TRUE; - if (on_completion == MYSQL_EVENT_ON_COMPLETION_DROP) + if (on_completion == Event_timed::ON_COMPLETION_DROP) dropped= true; - status= MYSQL_EVENT_DISABLED; + DBUG_PRINT("info", ("Dropped=%d", dropped)); + status= Event_timed::DISABLED; status_changed= true; goto ret; @@ -937,7 +1029,6 @@ Event_timed::compute_next_execution_time() { TIME next_exec; - DBUG_PRINT("info", ("Executed at least once")); if (get_next_time(&next_exec, &starts, &time_now, last_executed.year? &last_executed:&starts, expression, interval)) @@ -946,12 +1037,15 @@ Event_timed::compute_next_execution_time() /* There was previous execution */ if (my_time_compare(&ends, &next_exec) == -1) { - DBUG_PRINT("info", ("Next execution after ENDS. Stop executing.")); + DBUG_PRINT("info", ("Next execution of %s after ENDS. Stop executing.", + name.str)); /* Next execution after ends. No more executions */ set_zero_time(&execute_at, MYSQL_TIMESTAMP_DATETIME); execute_at_null= TRUE; - if (on_completion == MYSQL_EVENT_ON_COMPLETION_DROP) + if (on_completion == Event_timed::ON_COMPLETION_DROP) dropped= true; + status= Event_timed::DISABLED; + status_changed= true; } else { @@ -1006,7 +1100,6 @@ Event_timed::compute_next_execution_time() { TIME next_exec; - DBUG_PRINT("info", ("Executed at least once.")); if (get_next_time(&next_exec, &starts, &time_now, last_executed.year? &last_executed:&starts, expression, interval)) @@ -1042,7 +1135,9 @@ Event_timed::compute_next_execution_time() DBUG_PRINT("info", ("Next execution after ENDS. Stop executing.")); set_zero_time(&execute_at, MYSQL_TIMESTAMP_DATETIME); execute_at_null= TRUE; - if (on_completion == MYSQL_EVENT_ON_COMPLETION_DROP) + status= Event_timed::DISABLED; + status_changed= true; + if (on_completion == Event_timed::ON_COMPLETION_DROP) dropped= true; } else @@ -1083,9 +1178,6 @@ Event_timed::mark_last_executed(THD *thd) my_tz_UTC->gmt_sec_to_TIME(&time_now, (my_time_t) thd->query_start()); last_executed= time_now; /* was execute_at */ -#ifdef ANDREY_0 - last_executed= execute_at; -#endif last_executed_changed= true; } @@ -1125,7 +1217,7 @@ Event_timed::drop(THD *thd) RETURN VALUE 0 OK - SP_OPEN_TABLE_FAILED Error while opening mysql.event for writing + EVEX_OPEN_TABLE_FAILED Error while opening mysql.event for writing EVEX_WRITE_ROW_FAILED On error to write to disk others return code from SE in case deletion of the event @@ -1137,7 +1229,7 @@ Event_timed::update_fields(THD *thd) { TABLE *table; Open_tables_state backup; - int ret= 0; + int ret; DBUG_ENTER("Event_timed::update_time_fields"); @@ -1145,18 +1237,18 @@ Event_timed::update_fields(THD *thd) /* No need to update if nothing has changed */ if (!(status_changed || last_executed_changed)) - goto done; + DBUG_RETURN(0); thd->reset_n_backup_open_tables_state(&backup); - if (evex_open_event_table(thd, TL_WRITE, &table)) + if (Events::open_event_table(thd, TL_WRITE, &table)) { - ret= SP_OPEN_TABLE_FAILED; + ret= EVEX_OPEN_TABLE_FAILED; goto done; } - if ((ret= evex_db_find_event_by_name(thd, dbname, name, definer, table))) + if ((ret= evex_db_find_event_by_name(thd, dbname, name, table))) goto done; store_record(table,record[1]); @@ -1165,15 +1257,15 @@ Event_timed::update_fields(THD *thd) if (last_executed_changed) { - table->field[EVEX_FIELD_LAST_EXECUTED]->set_notnull(); - table->field[EVEX_FIELD_LAST_EXECUTED]->store_time(&last_executed, - MYSQL_TIMESTAMP_DATETIME); + table->field[Events::FIELD_LAST_EXECUTED]->set_notnull(); + table->field[Events::FIELD_LAST_EXECUTED]->store_time(&last_executed, + MYSQL_TIMESTAMP_DATETIME); last_executed_changed= false; } if (status_changed) { - table->field[EVEX_FIELD_STATUS]->set_notnull(); - table->field[EVEX_FIELD_STATUS]->store((longlong)status, true); + table->field[Events::FIELD_STATUS]->set_notnull(); + table->field[Events::FIELD_STATUS]->store((longlong)status, true); status_changed= false; } @@ -1215,8 +1307,8 @@ Event_timed::get_create_event(THD *thd, String *buf) DBUG_ENTER("get_create_event"); DBUG_PRINT("ret_info",("body_len=[%d]body=[%s]", body.length, body.str)); - if (expression && - event_reconstruct_interval_expression(&expr_buf, interval, expression)) + if (expression && Events::reconstruct_interval_expression(&expr_buf, interval, + expression)) DBUG_RETURN(EVEX_MICROSECOND_UNSUP); buf->append(STRING_WITH_LEN("CREATE EVENT ")); @@ -1243,12 +1335,12 @@ Event_timed::get_create_event(THD *thd, String *buf) buf->append(STRING_WITH_LEN("'")); } - if (on_completion == MYSQL_EVENT_ON_COMPLETION_DROP) + if (on_completion == Event_timed::ON_COMPLETION_DROP) buf->append(STRING_WITH_LEN(" ON COMPLETION NOT PRESERVE ")); else buf->append(STRING_WITH_LEN(" ON COMPLETION PRESERVE ")); - if (status == MYSQL_EVENT_ENABLED) + if (status == Event_timed::ENABLED) buf->append(STRING_WITH_LEN("ENABLE")); else buf->append(STRING_WITH_LEN("DISABLE")); @@ -1273,7 +1365,7 @@ Event_timed::get_create_event(THD *thd, String *buf) thd THD mem_root If != NULL use it to compile the event on it - RETURNS + RETURN VALUE 0 success -99 No rights on this.dbname.str -100 event in execution (parallel execution is impossible) @@ -1283,7 +1375,6 @@ Event_timed::get_create_event(THD *thd, String *buf) int Event_timed::execute(THD *thd, MEM_ROOT *mem_root) { - Security_context *save_ctx; /* this one is local and not needed after exec */ Security_context security_ctx; int ret= 0; @@ -1301,16 +1392,8 @@ Event_timed::execute(THD *thd, MEM_ROOT *mem_root) running= true; VOID(pthread_mutex_unlock(&this->LOCK_running)); - DBUG_PRINT("info", ("master_access=%d db_access=%d", - thd->security_ctx->master_access, thd->security_ctx->db_access)); - change_security_context(thd, &security_ctx, &save_ctx); - DBUG_PRINT("info", ("master_access=%d db_access=%d", - thd->security_ctx->master_access, thd->security_ctx->db_access)); - if (!sphead && (ret= compile(thd, mem_root))) goto done; - /* Now we are sure we have valid this->sphead so we can copy the context */ - sphead->m_security_ctx= security_ctx; /* THD::~THD will clean this or if there is DROP DATABASE in the SP then it will be free there. It should not point to our buffer which is allocated @@ -1334,12 +1417,11 @@ Event_timed::execute(THD *thd, MEM_ROOT *mem_root) definer_host.str, dbname.str)); ret= -99; } - restore_security_context(thd, save_ctx); - DBUG_PRINT("info", ("master_access=%d db_access=%d", - thd->security_ctx->master_access, thd->security_ctx->db_access)); VOID(pthread_mutex_lock(&this->LOCK_running)); running= false; + /* Will compile every time a new sp_head on different root */ + free_sp(); VOID(pthread_mutex_unlock(&this->LOCK_running)); done: @@ -1361,55 +1443,16 @@ done: /* - Switches the security context - Synopsis - Event_timed::change_security_context() - thd - thread - backup - where to store the old context - - RETURN - 0 - OK - 1 - Error (generates error too) -*/ -bool -Event_timed::change_security_context(THD *thd, Security_context *s_ctx, - Security_context **backup) -{ - DBUG_ENTER("Event_timed::change_security_context"); - DBUG_PRINT("info",("%s@%s@%s",definer_user.str,definer_host.str, dbname.str)); -#ifndef NO_EMBEDDED_ACCESS_CHECKS - s_ctx->init(); - *backup= 0; - if (acl_getroot_no_password(s_ctx, definer_user.str, definer_host.str, - definer_host.str, dbname.str)) - { - my_error(ER_NO_SUCH_USER, MYF(0), definer_user.str, definer_host.str); - DBUG_RETURN(true); - } - *backup= thd->security_ctx; - thd->security_ctx= s_ctx; -#endif - DBUG_RETURN(false); -} - - -/* - Restores the security context - Synopsis - Event_timed::restore_security_context() - thd - thread - backup - switch to this context + Frees the memory of the sp_head object we hold + SYNOPSIS + Event_timed::free_sp() */ void -Event_timed::restore_security_context(THD *thd, Security_context *backup) +Event_timed::free_sp() { - DBUG_ENTER("Event_timed::restore_security_context"); -#ifndef NO_EMBEDDED_ACCESS_CHECKS - if (backup) - thd->security_ctx= backup; -#endif - DBUG_VOID_RETURN; + delete sphead; + sphead= 0; } @@ -1445,6 +1488,9 @@ Event_timed::compile(THD *thd, MEM_ROOT *mem_root) CHARSET_INFO *old_character_set_client, *old_collation_connection, *old_character_set_results; + Security_context *save_ctx; + /* this one is local and not needed after exec */ + Security_context security_ctx; DBUG_ENTER("Event_timed::compile"); @@ -1488,8 +1534,10 @@ Event_timed::compile(THD *thd, MEM_ROOT *mem_root) thd->query= show_create.c_ptr(); thd->query_length= show_create.length(); - DBUG_PRINT("Event_timed::compile", ("query:%s",thd->query)); + DBUG_PRINT("info", ("query:%s",thd->query)); + change_security_context(thd, definer_user, definer_host, dbname, + &security_ctx, &save_ctx); thd->lex= &lex; lex_start(thd, (uchar*)thd->query, thd->query_length); lex.et_compile_phase= TRUE; @@ -1527,6 +1575,7 @@ done: lex.et->deinit_mutexes(); lex_end(&lex); + restore_security_context(thd, save_ctx); DBUG_PRINT("note", ("return old data on its place. set back NAMES")); thd->lex= old_lex; @@ -1548,72 +1597,63 @@ done: } -/* - Checks whether this thread can lock the object for modification -> - preventing being spawned for execution, and locks if possible. - use ::can_spawn_now() only for basic checking because a race - condition may occur between the check and eventual modification (deletion) - of the object. - - Returns - true - locked - false - cannot lock -*/ - -my_bool -Event_timed::can_spawn_now_n_lock(THD *thd) -{ - my_bool ret= FALSE; - VOID(pthread_mutex_lock(&this->LOCK_running)); - if (!in_spawned_thread) - { - in_spawned_thread= TRUE; - ret= TRUE; - locked_by_thread_id= thd->thread_id; - } - VOID(pthread_mutex_unlock(&this->LOCK_running)); - return ret; -} - - extern pthread_attr_t connection_attrib; /* Checks whether is possible and forks a thread. Passes self as argument. - Returns - EVENT_EXEC_STARTED - OK - EVENT_EXEC_ALREADY_EXEC - Thread not forked, already working - EVENT_EXEC_CANT_FORK - Unable to spawn thread (error) + RETURN VALUE + EVENT_EXEC_STARTED OK + EVENT_EXEC_ALREADY_EXEC Thread not forked, already working + EVENT_EXEC_CANT_FORK Unable to spawn thread (error) */ int -Event_timed::spawn_now(void * (*thread_func)(void*)) +Event_timed::spawn_now(void * (*thread_func)(void*), void *arg) { + THD *thd= current_thd; int ret= EVENT_EXEC_STARTED; - static uint exec_num= 0; DBUG_ENTER("Event_timed::spawn_now"); - DBUG_PRINT("info", ("this=0x%lx", this)); DBUG_PRINT("info", ("[%s.%s]", dbname.str, name.str)); VOID(pthread_mutex_lock(&this->LOCK_running)); + + DBUG_PRINT("info", ("SCHEDULER: execute_at of %s is %lld", name.str, + TIME_to_ulonglong_datetime(&execute_at))); + mark_last_executed(thd); + if (compute_next_execution_time()) + { + sql_print_error("SCHEDULER: Error while computing time of %s.%s . " + "Disabling after execution.", dbname.str, name.str); + status= DISABLED; + } + DBUG_PRINT("evex manager", ("[%10s] next exec at [%llu]", name.str, + TIME_to_ulonglong_datetime(&execute_at))); + /* + 1. For one-time event : year is > 0 and expression is 0 + 2. For recurring, expression is != -=> check execute_at_null in this case + */ + if ((execute_at.year && !expression) || execute_at_null) + { + sql_print_information("SCHEDULER: [%s.%s of %s] no more executions " + "after this one", dbname.str, name.str, + definer.str); + flags |= EVENT_EXEC_NO_MORE | EVENT_FREE_WHEN_FINISHED; + } + + update_fields(thd); + if (!in_spawned_thread) { pthread_t th; in_spawned_thread= true; - if (pthread_create(&th, &connection_attrib, thread_func, (void*)this)) + + if (pthread_create(&th, &connection_attrib, thread_func, arg)) { DBUG_PRINT("info", ("problem while spawning thread")); ret= EVENT_EXEC_CANT_FORK; in_spawned_thread= false; } -#ifndef DBUG_OFF - else - { - sql_print_information("SCHEDULER: Started thread %d", ++exec_num); - DBUG_PRINT("info", ("thread spawned")); - } -#endif } else { @@ -1626,55 +1666,207 @@ Event_timed::spawn_now(void * (*thread_func)(void*)) } -void +bool Event_timed::spawn_thread_finish(THD *thd) { + bool should_free; DBUG_ENTER("Event_timed::spawn_thread_finish"); - VOID(pthread_mutex_lock(&this->LOCK_running)); + VOID(pthread_mutex_lock(&LOCK_running)); in_spawned_thread= false; - if ((flags & EVENT_EXEC_NO_MORE) || status == MYSQL_EVENT_DISABLED) + DBUG_PRINT("info", ("Sending COND_finished for thread %d", thread_id)); + thread_id= 0; + if (dropped) + drop(thd); + pthread_cond_broadcast(&COND_finished); + should_free= flags & EVENT_FREE_WHEN_FINISHED; + VOID(pthread_mutex_unlock(&LOCK_running)); + DBUG_RETURN(should_free); +} + + +/* + Kills a running event + SYNOPSIS + Event_timed::kill_thread() + + RETURN VALUE + 0 OK + -1 EVEX_CANT_KILL + !0 Error +*/ + +int +Event_timed::kill_thread(THD *thd) +{ + int ret= 0; + DBUG_ENTER("Event_timed::kill_thread"); + pthread_mutex_lock(&LOCK_running); + DBUG_PRINT("info", ("thread_id=%lu", thread_id)); + + if (thread_id == thd->thread_id) { - DBUG_PRINT("info", ("%s exec no more. to drop=%d", name.str, dropped)); - if (dropped) - drop(thd); - VOID(pthread_mutex_unlock(&this->LOCK_running)); - delete this; - DBUG_VOID_RETURN; + /* + We don't kill ourselves in cases like : + alter event e_43 do alter event e_43 do set @a = 4 because + we will never receive COND_finished. + */ + DBUG_PRINT("info", ("It's not safe to kill ourselves in self altering queries")); + ret= EVEX_CANT_KILL; } - VOID(pthread_mutex_unlock(&this->LOCK_running)); - DBUG_VOID_RETURN; + else if (thread_id && !(ret= kill_one_thread(thd, thread_id, false))) + { + thd->enter_cond(&COND_finished, &LOCK_running, "Waiting for finished"); + DBUG_PRINT("info", ("Waiting for COND_finished from thread %d", thread_id)); + while (thread_id) + pthread_cond_wait(&COND_finished, &LOCK_running); + + DBUG_PRINT("info", ("Got COND_finished")); + /* This will implicitly unlock LOCK_running. Hence we return before that */ + thd->exit_cond(""); + + DBUG_RETURN(0); + } + else if (!thread_id && in_spawned_thread) + { + /* + Because the manager thread waits for the forked thread to update thread_id + this situation is impossible. + */ + DBUG_ASSERT(0); + } + pthread_mutex_unlock(&LOCK_running); + DBUG_PRINT("exit", ("%d", ret)); + DBUG_RETURN(ret); +} + + +/* + Checks whether two events have the same name + + SYNOPSIS + event_timed_name_equal() + + RETURN VALUE + TRUE names are equal + FALSE names are not equal +*/ + +bool +event_timed_name_equal(Event_timed *et, LEX_STRING *name) +{ + return !sortcmp_lex_string(et->name, *name, system_charset_info); } /* - Unlocks the object after it has been locked with ::can_spawn_now_n_lock() + Checks whether two events are in the same schema + + SYNOPSIS + event_timed_db_equal() + + RETURN VALUE + TRUE schemas are equal + FALSE schemas are not equal +*/ + +bool +event_timed_db_equal(Event_timed *et, LEX_STRING *db) +{ + return !sortcmp_lex_string(et->dbname, *db, system_charset_info); +} + + +/* + Checks whether two events have the same definer + + SYNOPSIS + event_timed_definer_equal() Returns - 0 - ok - 1 - not locked by this thread + TRUE definers are equal + FALSE definers are not equal */ -int -Event_timed::spawn_unlock(THD *thd) +bool +event_timed_definer_equal(Event_timed *et, LEX_STRING *definer) { - int ret= 0; - VOID(pthread_mutex_lock(&this->LOCK_running)); - if (!in_spawned_thread) + return !sortcmp_lex_string(et->definer, *definer, system_charset_info); +} + + +/* + Checks whether two events are equal by identifiers + + SYNOPSIS + event_timed_identifier_equal() + + RETURN VALUE + TRUE equal + FALSE not equal +*/ + +bool +event_timed_identifier_equal(Event_timed *a, Event_timed *b) +{ + return event_timed_name_equal(a, &b->name) && + event_timed_db_equal(a, &b->dbname) && + event_timed_definer_equal(a, &b->definer); +} + + +/* + Switches the security context + SYNOPSIS + change_security_context() + thd Thread + user The user + host The host of the user + db The schema for which the security_ctx will be loaded + s_ctx Security context to load state into + backup Where to store the old context + + RETURN VALUE + 0 - OK + 1 - Error (generates error too) +*/ + +bool +change_security_context(THD *thd, LEX_STRING user, LEX_STRING host, + LEX_STRING db, Security_context *s_ctx, + Security_context **backup) +{ + DBUG_ENTER("change_security_context"); + DBUG_PRINT("info",("%s@%s@%s", user.str, host.str, db.str)); +#ifndef NO_EMBEDDED_ACCESS_CHECKS + s_ctx->init(); + *backup= 0; + if (acl_getroot_no_password(s_ctx, user.str, host.str, host.str, db.str)) { - if (locked_by_thread_id == thd->thread_id) - { - in_spawned_thread= FALSE; - locked_by_thread_id= 0; - } - else - { - sql_print_error("A thread tries to unlock when he hasn't locked. " - "thread_id=%ld locked by %ld", - thd->thread_id, locked_by_thread_id); - DBUG_ASSERT(0); - ret= 1; - } + my_error(ER_NO_SUCH_USER, MYF(0), user.str, host.str); + DBUG_RETURN(TRUE); } - VOID(pthread_mutex_unlock(&this->LOCK_running)); - return ret; + *backup= thd->security_ctx; + thd->security_ctx= s_ctx; +#endif + DBUG_RETURN(FALSE); +} + + +/* + Restores the security context + SYNOPSIS + restore_security_context() + thd - thread + backup - switch to this context +*/ + +void +restore_security_context(THD *thd, Security_context *backup) +{ + DBUG_ENTER("restore_security_context"); +#ifndef NO_EMBEDDED_ACCESS_CHECKS + if (backup) + thd->security_ctx= backup; +#endif + DBUG_VOID_RETURN; } diff --git a/sql/field.cc b/sql/field.cc index 4818ad47151..1f65adca2d5 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -1223,12 +1223,12 @@ String *Field::val_int_as_str(String *val_buffer, my_bool unsigned_val) Field::Field(char *ptr_arg,uint32 length_arg,uchar *null_ptr_arg, uchar null_bit_arg, utype unireg_check_arg, const char *field_name_arg) - :ptr(ptr_arg),null_ptr(null_ptr_arg), + :ptr(ptr_arg), null_ptr(null_ptr_arg), table(0), orig_table(0), table_name(0), field_name(field_name_arg), key_start(0), part_of_key(0), part_of_key_not_clustered(0), part_of_sortkey(0), unireg_check(unireg_check_arg), - field_length(length_arg),null_bit(null_bit_arg) + field_length(length_arg), null_bit(null_bit_arg) { flags=null_ptr ? 0: NOT_NULL_FLAG; comment.str= (char*) ""; @@ -9184,14 +9184,15 @@ create_field::create_field(Field *old_field,Field *orig_field) diff= (my_ptrdiff_t) (orig_field->table->s->default_values- orig_field->table->record[0]); orig_field->move_field_offset(diff); // Points now at default_values - is_null= orig_field->is_real_null(); - res= orig_field->val_str(&tmp); - orig_field->move_field_offset(-diff); // Back to record[0] - if (!is_null) + if (!orig_field->is_real_null()) { + char buff[MAX_FIELD_WIDTH], *pos; + String tmp(buff, sizeof(buff), charset), *res; + res= orig_field->val_str(&tmp); pos= (char*) sql_strmake(res->ptr(), res->length()); def= new Item_string(pos, res->length(), charset); } + orig_field->move_field_offset(-diff); // Back to record[0] } } diff --git a/sql/field_conv.cc b/sql/field_conv.cc index f718a3d778c..3eab782d167 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -641,7 +641,8 @@ void (*Copy_field::get_copy_func(Field *to,Field *from))(Copy_field*) void field_conv(Field *to,Field *from) { - if (to->real_type() == from->real_type()) + if (to->real_type() == from->real_type() && + !(to->type() == FIELD_TYPE_BLOB && to->table->copy_blobs)) { if (to->pack_length() == from->pack_length() && !(to->flags & UNSIGNED_FLAG && !(from->flags & UNSIGNED_FLAG)) && diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc index 1f9336d81f7..6f5f9f32e76 100644 --- a/sql/ha_berkeley.cc +++ b/sql/ha_berkeley.cc @@ -98,6 +98,9 @@ pthread_mutex_t bdb_mutex; static DB_ENV *db_env; static HASH bdb_open_tables; +static const char berkeley_hton_name[]= "BerkeleyDB"; +static const int berkeley_hton_name_length=sizeof(berkeley_hton_name)-1; + const char *berkeley_lock_names[] = { "DEFAULT", "OLDEST", "RANDOM", "YOUNGEST", "EXPIRE", "MAXLOCKS", "MAXWRITE", "MINLOCKS", "MINWRITE", 0 }; @@ -127,47 +130,7 @@ static int berkeley_release_savepoint(THD* thd, void *savepoint); static handler *berkeley_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root); -static const char berkeley_hton_name[]= "BerkeleyDB"; -static const char berkeley_hton_comment[]= - "Supports transactions and page-level locking"; - -handlerton berkeley_hton = { - MYSQL_HANDLERTON_INTERFACE_VERSION, - berkeley_hton_name, - SHOW_OPTION_YES, - berkeley_hton_comment, - DB_TYPE_BERKELEY_DB, - berkeley_init, - 0, /* slot */ - sizeof(DB_TXN *), /* savepoint size */ - berkeley_close_connection, - berkeley_savepoint, /* savepoint_set */ - berkeley_rollback_to_savepoint, /* savepoint_rollback */ - berkeley_release_savepoint, /* savepoint_release */ - berkeley_commit, - berkeley_rollback, - NULL, /* prepare */ - NULL, /* recover */ - NULL, /* commit_by_xid */ - NULL, /* rollback_by_xid */ - NULL, /* create_cursor_read_view */ - NULL, /* set_cursor_read_view */ - NULL, /* close_cursor_read_view */ - berkeley_create_handler, /* Create a new handler */ - NULL, /* Drop a database */ - berkeley_end, /* Panic call */ - NULL, /* Start Consistent Snapshot */ - berkeley_flush_logs, /* Flush logs */ - berkeley_show_status, /* Show status */ - NULL, /* Partition flags */ - NULL, /* Alter table flags */ - NULL, /* Alter Tablespace */ - NULL, /* Fill Files Table */ - HTON_CLOSE_CURSORS_AT_COMMIT | HTON_FLUSH_AFTER_RENAME, - NULL, /* binlog_func */ - NULL, /* binlog_log_query */ - NULL /* release_temporary_latches */ -}; +handlerton berkeley_hton; static handler *berkeley_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root) { @@ -183,12 +146,27 @@ typedef struct st_berkeley_trx_data { /* General functions */ -bool berkeley_init(void) +int berkeley_init(void) { DBUG_ENTER("berkeley_init"); + berkeley_hton.state=SHOW_OPTION_YES; + berkeley_hton.db_type=DB_TYPE_BERKELEY_DB; + berkeley_hton.savepoint_offset=sizeof(DB_TXN *); + berkeley_hton.close_connection=berkeley_close_connection; + berkeley_hton.savepoint_set=berkeley_savepoint; + berkeley_hton.savepoint_rollback=berkeley_rollback_to_savepoint; + berkeley_hton.savepoint_release=berkeley_release_savepoint; + berkeley_hton.commit=berkeley_commit; + berkeley_hton.rollback=berkeley_rollback; + berkeley_hton.create=berkeley_create_handler; + berkeley_hton.panic=berkeley_end; + berkeley_hton.flush_logs=berkeley_flush_logs; + berkeley_hton.show_status=berkeley_show_status; + berkeley_hton.flags=HTON_CLOSE_CURSORS_AT_COMMIT | HTON_FLUSH_AFTER_RENAME; + if (have_berkeley_db != SHOW_OPTION_YES) - goto error; + return 0; // nothing else to do if (!berkeley_tmpdir) berkeley_tmpdir=mysql_tmpdir; @@ -375,7 +353,6 @@ static int berkeley_release_savepoint(THD* thd, void *savepoint) 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; @@ -403,15 +380,15 @@ static bool berkeley_show_logs(THD *thd, stat_print_fn *stat_print) if (f && *f && strcmp(*a, *f) == 0) { f++; - if ((error= stat_print(thd, berkeley_hton.name, hton_name_len, - *a, strlen(*a), + if ((error= stat_print(thd, berkeley_hton_name, + berkeley_hton_name_length, *a, strlen(*a), STRING_WITH_LEN(SHOW_LOG_STATUS_FREE)))) break; } else { - if ((error= stat_print(thd, berkeley_hton.name, hton_name_len, - *a, strlen(*a), + if ((error= stat_print(thd, berkeley_hton_name, + berkeley_hton_name_length, *a, strlen(*a), STRING_WITH_LEN(SHOW_LOG_STATUS_INUSE)))) break; } @@ -2262,8 +2239,12 @@ ha_rows ha_berkeley::records_in_range(uint keynr, key_range *start_key, } -ulonglong ha_berkeley::get_auto_increment() +void ha_berkeley::get_auto_increment(ulonglong offset, ulonglong increment, + ulonglong nb_desired_values, + ulonglong *first_value, + ulonglong *nb_reserved_values) { + /* Ideally in case of real error (not "empty table") nr should be ~ULL(0) */ ulonglong nr=1; // Default if error or new key int error; (void) ha_berkeley::extra(HA_EXTRA_KEYREAD); @@ -2274,9 +2255,18 @@ ulonglong ha_berkeley::get_auto_increment() if (!table_share->next_number_key_offset) { // Autoincrement at key-start error=ha_berkeley::index_last(table->record[1]); + /* has taken read lock on page of max key so reserves to infinite */ + *nb_reserved_values= ULONGLONG_MAX; } else { + /* + MySQL needs to call us for next row: assume we are inserting ("a",null) + here, we return 3, and next this statement will want to insert ("b",null): + there is no reason why ("b",3+1) would be the good row to insert: maybe it + already exists, maybe 3+1 is too large... + */ + *nb_reserved_values= 1; DBT row,old_key; bzero((char*) &row,sizeof(row)); KEY *key_info= &table->key_info[active_index]; @@ -2317,7 +2307,7 @@ ulonglong ha_berkeley::get_auto_increment() table->next_number_field->val_int_offset(table_share->rec_buff_length)+1; ha_berkeley::index_end(); (void) ha_berkeley::extra(HA_EXTRA_NO_KEYREAD); - return nr; + *first_value= nr; } void ha_berkeley::print_error(int error, myf errflag) @@ -2739,15 +2729,17 @@ bool ha_berkeley::check_if_incompatible_data(HA_CREATE_INFO *info, return COMPATIBLE_DATA_YES; } +struct st_mysql_storage_engine berkeley_storage_engine= +{ MYSQL_HANDLERTON_INTERFACE_VERSION, &berkeley_hton }; mysql_declare_plugin(berkeley) { MYSQL_STORAGE_ENGINE_PLUGIN, - &berkeley_hton, + &berkeley_storage_engine, berkeley_hton_name, "Sleepycat Software", - berkeley_hton_comment, - NULL, /* Plugin Init */ + "Supports transactions and page-level locking", + berkeley_init, /* Plugin Init */ NULL, /* Plugin Deinit */ 0x0100, /* 1.0 */ 0 diff --git a/sql/ha_berkeley.h b/sql/ha_berkeley.h index c7c2f135bbd..47aab1fbb68 100644 --- a/sql/ha_berkeley.h +++ b/sql/ha_berkeley.h @@ -148,7 +148,10 @@ class ha_berkeley: public handler int5store(to,share->auto_ident); pthread_mutex_unlock(&share->mutex); } - ulonglong get_auto_increment(); + virtual void get_auto_increment(ulonglong offset, ulonglong increment, + ulonglong nb_desired_values, + ulonglong *first_value, + ulonglong *nb_reserved_values); void print_error(int error, myf errflag); uint8 table_cache_type() { return HA_CACHE_TBL_TRANSACT; } bool primary_key_is_clustered() { return true; } @@ -171,7 +174,7 @@ extern char *berkeley_home, *berkeley_tmpdir, *berkeley_logdir; extern long berkeley_lock_scan_time; extern TYPELIB berkeley_lock_typelib; -bool berkeley_init(void); +int berkeley_init(void); int berkeley_end(ha_panic_function type); bool berkeley_flush_logs(void); bool berkeley_show_status(THD *thd, stat_print_fn *print, enum ha_stat_type); diff --git a/sql/ha_federated.cc b/sql/ha_federated.cc index 1471b25f7b6..91111a433dc 100644 --- a/sql/ha_federated.cc +++ b/sql/ha_federated.cc @@ -371,47 +371,7 @@ static int federated_rollback(THD *thd, bool all); /* Federated storage engine handlerton */ -static const char federated_hton_name[]= "FEDERATED"; -static const char federated_hton_comment[]= "Federated MySQL storage engine"; - -handlerton federated_hton= { - MYSQL_HANDLERTON_INTERFACE_VERSION, - federated_hton_name, - SHOW_OPTION_YES, - federated_hton_comment, - DB_TYPE_FEDERATED_DB, - federated_db_init, - 0, /* slot */ - 0, /* savepoint size. */ - NULL, /* close_connection */ - NULL, /* savepoint */ - NULL, /* rollback to savepoint */ - NULL, /* release savepoint */ - federated_commit, /* commit */ - federated_rollback, /* rollback */ - NULL, /* prepare */ - NULL, /* recover */ - NULL, /* commit_by_xid */ - NULL, /* rollback_by_xid */ - NULL, /* create_cursor_read_view */ - NULL, /* set_cursor_read_view */ - NULL, /* close_cursor_read_view */ - federated_create_handler, /* Create a new handler */ - NULL, /* Drop a database */ - federated_db_end, /* Panic call */ - NULL, /* Start Consistent Snapshot */ - NULL, /* Flush logs */ - NULL, /* Show status */ - NULL, /* Partition flags */ - NULL, /* Alter table flags */ - NULL, /* Alter Tablespace */ - NULL, /* Fill FILES table */ - HTON_ALTER_NOT_SUPPORTED, - NULL, /* binlog_func */ - NULL, /* binlog_log_query */ - NULL /* release_temporary_latches */ -}; - +handlerton federated_hton; static handler *federated_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root) @@ -441,9 +401,18 @@ static byte *federated_get_key(FEDERATED_SHARE *share, uint *length, TRUE Error */ -bool federated_db_init() +int federated_db_init() { DBUG_ENTER("federated_db_init"); + + federated_hton.state= SHOW_OPTION_YES; + federated_hton.db_type= DB_TYPE_FEDERATED_DB; + federated_hton.commit= federated_commit; + federated_hton.rollback= federated_rollback; + federated_hton.create= federated_create_handler; + federated_hton.panic= federated_db_end; + federated_hton.flags= HTON_ALTER_NOT_SUPPORTED; + if (pthread_mutex_init(&federated_mutex, MY_MUTEX_INIT_FAST)) goto error; if (!hash_init(&federated_open_tables, system_charset_info, 32, 0, 0, @@ -2825,7 +2794,7 @@ int ha_federated::connection_autocommit(bool state) DBUG_ENTER("ha_federated::connection_autocommit"); text= (state == true) ? "SET AUTOCOMMIT=1" : "SET AUTOCOMMIT=0"; DBUG_RETURN(execute_simple_query(text, 16)); -} +} int ha_federated::execute_simple_query(const char *query, int len) @@ -2839,15 +2808,17 @@ int ha_federated::execute_simple_query(const char *query, int len) DBUG_RETURN(0); } +struct st_mysql_storage_engine federated_storage_engine= +{ MYSQL_HANDLERTON_INTERFACE_VERSION, &federated_hton }; mysql_declare_plugin(federated) { MYSQL_STORAGE_ENGINE_PLUGIN, - &federated_hton, - federated_hton_name, + &federated_storage_engine, + "FEDERATED", "Patrick Galbraith and Brian Aker, MySQL AB", - federated_hton_comment, - NULL, /* Plugin Init */ + "Federated MySQL storage engine", + federated_db_init, /* Plugin Init */ NULL, /* Plugin Deinit */ 0x0100 /* 1.0 */, 0 diff --git a/sql/ha_federated.h b/sql/ha_federated.h index 1d8bda43e24..4a4561ba274 100644 --- a/sql/ha_federated.h +++ b/sql/ha_federated.h @@ -306,6 +306,6 @@ public: int execute_simple_query(const char *query, int len); }; -bool federated_db_init(void); +int federated_db_init(void); int federated_db_end(ha_panic_function type); diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc index 7b2d83cbc8d..3a2027afaba 100644 --- a/sql/ha_heap.cc +++ b/sql/ha_heap.cc @@ -26,47 +26,17 @@ static handler *heap_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root); -static const char heap_hton_name[]= "MEMORY"; -static const char heap_hton_comment[]= - "Hash based, stored in memory, useful for temporary tables"; - -handlerton heap_hton= { - MYSQL_HANDLERTON_INTERFACE_VERSION, - heap_hton_name, - SHOW_OPTION_YES, - heap_hton_comment, - DB_TYPE_HEAP, - NULL, - 0, /* slot */ - 0, /* savepoint size. */ - NULL, /* close_connection */ - NULL, /* savepoint */ - NULL, /* rollback to savepoint */ - NULL, /* release savepoint */ - NULL, /* commit */ - NULL, /* rollback */ - NULL, /* prepare */ - NULL, /* recover */ - NULL, /* commit_by_xid */ - NULL, /* rollback_by_xid */ - NULL, /* create_cursor_read_view */ - NULL, /* set_cursor_read_view */ - NULL, /* close_cursor_read_view */ - heap_create_handler, /* Create a new handler */ - NULL, /* Drop a database */ - heap_panic, /* Panic call */ - NULL, /* Start Consistent Snapshot */ - NULL, /* Flush logs */ - NULL, /* Show status */ - NULL, /* Partition flags */ - NULL, /* Alter table flags */ - NULL, /* Alter Tablespace */ - NULL, /* Fill Files Table */ - HTON_CAN_RECREATE, - NULL, /* binlog_func */ - NULL, /* binlog_log_query */ - NULL /* release_temporary_latches */ -}; +handlerton heap_hton; + +int heap_init() +{ + heap_hton.state= SHOW_OPTION_YES; + heap_hton.db_type= DB_TYPE_HEAP; + heap_hton.create= heap_create_handler; + heap_hton.panic= heap_panic; + heap_hton.flags= HTON_CAN_RECREATE; + return 0; +} static handler *heap_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root) { @@ -701,10 +671,15 @@ void ha_heap::update_create_info(HA_CREATE_INFO *create_info) create_info->auto_increment_value= stats.auto_increment_value; } -ulonglong ha_heap::get_auto_increment() +void ha_heap::get_auto_increment(ulonglong offset, ulonglong increment, + ulonglong nb_desired_values, + ulonglong *first_value, + ulonglong *nb_reserved_values) { ha_heap::info(HA_STATUS_AUTO); - return stats.auto_increment_value; + *first_value= stats.auto_increment_value; + /* such table has only table-level locking so reserves up to +inf */ + *nb_reserved_values= ULONGLONG_MAX; } @@ -719,14 +694,17 @@ bool ha_heap::check_if_incompatible_data(HA_CREATE_INFO *info, return COMPATIBLE_DATA_YES; } +struct st_mysql_storage_engine heap_storage_engine= +{ MYSQL_HANDLERTON_INTERFACE_VERSION, &heap_hton}; + mysql_declare_plugin(heap) { MYSQL_STORAGE_ENGINE_PLUGIN, - &heap_hton, - heap_hton_name, + &heap_storage_engine, + "MEMORY", "MySQL AB", - heap_hton_comment, - NULL, + "Hash based, stored in memory, useful for temporary tables", + heap_init, NULL, 0x0100, /* 1.0 */ 0 diff --git a/sql/ha_heap.h b/sql/ha_heap.h index 5933f6a0ff1..00e59856f26 100644 --- a/sql/ha_heap.h +++ b/sql/ha_heap.h @@ -72,7 +72,10 @@ public: int write_row(byte * buf); int update_row(const byte * old_data, byte * new_data); int delete_row(const byte * buf); - ulonglong get_auto_increment(); + virtual void get_auto_increment(ulonglong offset, ulonglong increment, + ulonglong nb_desired_values, + ulonglong *first_value, + ulonglong *nb_reserved_values); int index_read(byte * buf, const byte * key, uint key_len, enum ha_rkey_function find_flag); int index_read_idx(byte * buf, uint idx, const byte * key, diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index 8811cbdce33..742f9ce7631 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -43,6 +43,7 @@ have disables the InnoDB inlining in this file. */ #define MAX_ULONG_BIT ((ulong) 1 << (sizeof(ulong)*8-1)) #ifdef WITH_INNOBASE_STORAGE_ENGINE + #include "ha_innodb.h" pthread_mutex_t innobase_share_mutex, /* to protect innobase_open_files */ @@ -207,47 +208,7 @@ static handler *innobase_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root); static const char innobase_hton_name[]= "InnoDB"; -static const char innobase_hton_comment[]= - "Supports transactions, row-level locking, and foreign keys"; - -handlerton innobase_hton = { - MYSQL_HANDLERTON_INTERFACE_VERSION, - innobase_hton_name, - SHOW_OPTION_YES, - innobase_hton_comment, - DB_TYPE_INNODB, - innobase_init, - 0, /* slot */ - sizeof(trx_named_savept_t), /* savepoint size. TODO: use it */ - innobase_close_connection, - innobase_savepoint, - innobase_rollback_to_savepoint, - innobase_release_savepoint, - innobase_commit, /* commit */ - innobase_rollback, /* rollback */ - innobase_xa_prepare, /* prepare */ - innobase_xa_recover, /* recover */ - innobase_commit_by_xid, /* commit_by_xid */ - innobase_rollback_by_xid, /* rollback_by_xid */ - innobase_create_cursor_view, - innobase_set_cursor_view, - innobase_close_cursor_view, - innobase_create_handler, /* Create a new handler */ - innobase_drop_database, /* Drop a database */ - innobase_end, /* Panic call */ - innobase_start_trx_and_assign_read_view, /* Start Consistent Snapshot */ - innobase_flush_logs, /* Flush logs */ - innobase_show_status, /* Show status */ - NULL, /* Partition flags */ - NULL, /* Alter table flags */ - NULL, /* alter_tablespace */ - NULL, /* Fill FILES table */ - HTON_NO_FLAGS, - NULL, /* binlog_func */ - NULL, /* binlog_log_query */ - innobase_release_temporary_latches -}; - +handlerton innobase_hton; static handler *innobase_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root) { @@ -1230,10 +1191,9 @@ ha_innobase::init_table_handle_for_HANDLER(void) /************************************************************************* Opens an InnoDB database. */ -bool +int innobase_init(void) /*===============*/ - /* out: &innobase_hton, or NULL on error */ { static char current_dir[3]; /* Set if using current lib */ int err; @@ -1242,8 +1202,33 @@ innobase_init(void) DBUG_ENTER("innobase_init"); + innobase_hton.state=have_innodb; + innobase_hton.db_type= DB_TYPE_INNODB; + innobase_hton.savepoint_offset=sizeof(trx_named_savept_t); + innobase_hton.close_connection=innobase_close_connection; + innobase_hton.savepoint_set=innobase_savepoint; + innobase_hton.savepoint_rollback=innobase_rollback_to_savepoint; + innobase_hton.savepoint_release=innobase_release_savepoint; + innobase_hton.commit=innobase_commit; + innobase_hton.rollback=innobase_rollback; + innobase_hton.prepare=innobase_xa_prepare; + innobase_hton.recover=innobase_xa_recover; + innobase_hton.commit_by_xid=innobase_commit_by_xid; + innobase_hton.rollback_by_xid=innobase_rollback_by_xid; + innobase_hton.create_cursor_read_view=innobase_create_cursor_view; + innobase_hton.set_cursor_read_view=innobase_set_cursor_view; + innobase_hton.close_cursor_read_view=innobase_close_cursor_view; + innobase_hton.create=innobase_create_handler; + innobase_hton.drop_database=innobase_drop_database; + innobase_hton.panic=innobase_end; + innobase_hton.start_consistent_snapshot=innobase_start_trx_and_assign_read_view; + innobase_hton.flush_logs=innobase_flush_logs; + innobase_hton.show_status=innobase_show_status; + innobase_hton.flags=HTON_NO_FLAGS; + innobase_hton.release_temporary_latches=innobase_release_temporary_latches; + if (have_innodb != SHOW_OPTION_YES) - goto error; + DBUG_RETURN(0); // nothing else to do ut_a(DATA_MYSQL_TRUE_VARCHAR == (ulint)MYSQL_TYPE_VARCHAR); @@ -6466,7 +6451,7 @@ innodb_show_status( bool result = FALSE; - if (stat_print(thd, innobase_hton.name, strlen(innobase_hton.name), + if (stat_print(thd, innobase_hton_name, strlen(innobase_hton_name), STRING_WITH_LEN(""), str, flen)) { result= TRUE; } @@ -6493,7 +6478,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; + uint hton_name_len= strlen(innobase_hton_name), buf1len, buf2len; DBUG_ENTER("innodb_mutex_show_status"); #ifdef MUTEX_PROTECT_TO_BE_ADDED_LATER @@ -6520,7 +6505,7 @@ innodb_mutex_show_status( mutex->count_os_yield, mutex->lspent_time/1000); - if (stat_print(thd, innobase_hton.name, + if (stat_print(thd, innobase_hton_name, hton_name_len, buf1, buf1len, buf2, buf2len)) { #ifdef MUTEX_PROTECT_TO_BE_ADDED_LATER @@ -6550,7 +6535,7 @@ innodb_mutex_show_status( rw_lock_count_os_wait, rw_lock_count_os_yield, rw_lock_wait_time/1000); - if (stat_print(thd, innobase_hton.name, hton_name_len, + if (stat_print(thd, innobase_hton_name, hton_name_len, STRING_WITH_LEN("rw_lock_mutexes"), buf2, buf2len)) { DBUG_RETURN(1); } @@ -6956,17 +6941,21 @@ func_exit_early: return(error); } -/*********************************************************************** +/******************************************************************************* This function initializes the auto-inc counter if it has not been initialized yet. This function does not change the value of the auto-inc counter if it already has been initialized. Returns the value of the -auto-inc counter. */ +auto-inc counter in *first_value, and ULONGLONG_MAX in *nb_reserved_values (as +we have a table-level lock). offset, increment, nb_desired_values are ignored. +*first_value is set to -1 if error (deadlock or lock wait timeout) */ -ulonglong -ha_innobase::get_auto_increment() -/*=============================*/ - /* out: auto-increment column value, -1 if error - (deadlock or lock wait timeout) */ +void ha_innobase::get_auto_increment( +/*=================================*/ + ulonglong offset, /* in */ + ulonglong increment, /* in */ + ulonglong nb_desired_values, /* in */ + ulonglong *first_value, /* out */ + ulonglong *nb_reserved_values) /* out */ { longlong nr; int error; @@ -6981,10 +6970,13 @@ ha_innobase::get_auto_increment() ut_print_timestamp(stderr); sql_print_error("Error %lu in ::get_auto_increment()", (ulong) error); - return(~(ulonglong) 0); + *first_value= (~(ulonglong) 0); + return; } - return((ulonglong) nr); + *first_value= (ulonglong) nr; + /* table-level autoinc lock reserves up to +inf */ + *nb_reserved_values= ULONGLONG_MAX; } /* See comment in handler.h */ @@ -7452,15 +7444,17 @@ bool ha_innobase::check_if_incompatible_data( return COMPATIBLE_DATA_YES; } +struct st_mysql_storage_engine innobase_storage_engine= +{ MYSQL_HANDLERTON_INTERFACE_VERSION, &innobase_hton}; mysql_declare_plugin(innobase) { MYSQL_STORAGE_ENGINE_PLUGIN, - &innobase_hton, + &innobase_storage_engine, innobase_hton_name, "Innobase OY", - innobase_hton_comment, - NULL, /* Plugin Init */ + "Supports transactions, row-level locking, and foreign keys", + innobase_init, /* Plugin Init */ NULL, /* Plugin Deinit */ 0x0100 /* 1.0 */, 0 @@ -7468,3 +7462,4 @@ mysql_declare_plugin(innobase) mysql_declare_plugin_end; #endif + diff --git a/sql/ha_innodb.h b/sql/ha_innodb.h index c84aff63e81..c7d698cbcf4 100644 --- a/sql/ha_innodb.h +++ b/sql/ha_innodb.h @@ -172,7 +172,10 @@ class ha_innobase: public handler THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type); void init_table_handle_for_HANDLER(); - ulonglong get_auto_increment(); + virtual void get_auto_increment(ulonglong offset, ulonglong increment, + ulonglong nb_desired_values, + ulonglong *first_value, + ulonglong *nb_reserved_values); int reset_auto_increment(ulonglong value); virtual bool get_error_message(int error, String *buf); @@ -242,7 +245,7 @@ extern ulong srv_thread_concurrency; extern ulong srv_commit_concurrency; } -bool innobase_init(void); +int innobase_init(void); int innobase_end(ha_panic_function type); bool innobase_flush_logs(void); uint innobase_get_free_space(void); diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index fcb15a46661..2d097c34f97 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -52,63 +52,11 @@ TYPELIB myisam_stats_method_typelib= { ** MyISAM tables *****************************************************************************/ -static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root); - -/* MyISAM handlerton */ - -static const char myisam_hton_name[]= "MyISAM"; -static const char myisam_hton_comment[]= - "Default engine as of MySQL 3.23 with great performance"; - -handlerton myisam_hton= { - MYSQL_HANDLERTON_INTERFACE_VERSION, - myisam_hton_name, - SHOW_OPTION_YES, - myisam_hton_comment, - DB_TYPE_MYISAM, - NULL, - 0, /* slot */ - 0, /* savepoint size. */ - NULL, /* close_connection */ - NULL, /* savepoint */ - NULL, /* rollback to savepoint */ - NULL, /* release savepoint */ - NULL, /* commit */ - NULL, /* rollback */ - NULL, /* prepare */ - NULL, /* recover */ - NULL, /* commit_by_xid */ - NULL, /* rollback_by_xid */ - NULL, /* create_cursor_read_view */ - NULL, /* set_cursor_read_view */ - NULL, /* close_cursor_read_view */ - /* - MyISAM doesn't support transactions and doesn't have - transaction-dependent context: cursors can survive a commit. - */ - myisam_create_handler, /* Create a new handler */ - NULL, /* Drop a database */ - mi_panic,/* Panic call */ - NULL, /* Start Consistent Snapshot */ - NULL, /* Flush logs */ - NULL, /* Show status */ - NULL, /* Partition flags */ - NULL, /* Alter table flags */ - NULL, /* Alter Tablespace */ - NULL, /* Fill Files Table */ - HTON_CAN_RECREATE, - NULL, /* binlog_func */ - NULL, /* binlog_log_query */ - NULL /* release_temporary_latches */ -}; - - static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root) { return new (mem_root) ha_myisam(table); } - // collect errors printed by mi_check routines static void mi_check_print_msg(MI_CHECK *param, const char* msg_type, @@ -1694,7 +1642,10 @@ int ha_myisam::rename_table(const char * from, const char * to) } -ulonglong ha_myisam::get_auto_increment() +void ha_myisam::get_auto_increment(ulonglong offset, ulonglong increment, + ulonglong nb_desired_values, + ulonglong *first_value, + ulonglong *nb_reserved_values) { ulonglong nr; int error; @@ -1703,7 +1654,10 @@ ulonglong ha_myisam::get_auto_increment() if (!table->s->next_number_key_offset) { // Autoincrement at key-start ha_myisam::info(HA_STATUS_AUTO); - return stats.auto_increment_value; + *first_value= stats.auto_increment_value; + /* MyISAM has only table-level lock, so reserves to +inf */ + *nb_reserved_values= ULONGLONG_MAX; + return; } /* it's safe to call the following if bulk_insert isn't on */ @@ -1724,7 +1678,14 @@ ulonglong ha_myisam::get_auto_increment() val_int_offset(table->s->rec_buff_length)+1); } extra(HA_EXTRA_NO_KEYREAD); - return nr; + *first_value= nr; + /* + MySQL needs to call us for next row: assume we are inserting ("a",null) + here, we return 3, and next this statement will want to insert ("b",null): + there is no reason why ("b",3+1) would be the good row to insert: maybe it + already exists, maybe 3+1 is too large... + */ + *nb_reserved_values= 1; } @@ -1790,7 +1751,8 @@ bool ha_myisam::check_if_incompatible_data(HA_CREATE_INFO *info, if (info->auto_increment_value != stats.auto_increment_value || info->data_file_name != data_file_name || info->index_file_name != index_file_name || - table_changes == IS_EQUAL_NO) + table_changes == IS_EQUAL_NO || + table_changes & IS_EQUAL_PACK_LENGTH) // Not implemented yet return COMPATIBLE_DATA_NO; if ((options & (HA_OPTION_PACK_RECORD | HA_OPTION_CHECKSUM | @@ -1801,17 +1763,32 @@ bool ha_myisam::check_if_incompatible_data(HA_CREATE_INFO *info, return COMPATIBLE_DATA_YES; } +handlerton myisam_hton; + +static int myisam_init() +{ + myisam_hton.state=SHOW_OPTION_YES; + myisam_hton.db_type=DB_TYPE_MYISAM; + myisam_hton.create=myisam_create_handler; + myisam_hton.panic=mi_panic; + myisam_hton.flags=HTON_CAN_RECREATE; + return 0; +} + +struct st_mysql_storage_engine myisam_storage_engine= +{ MYSQL_HANDLERTON_INTERFACE_VERSION, &myisam_hton }; mysql_declare_plugin(myisam) { MYSQL_STORAGE_ENGINE_PLUGIN, - &myisam_hton, - myisam_hton_name, + &myisam_storage_engine, + "MyISAM", "MySQL AB", - myisam_hton_comment, - NULL, /* Plugin Init */ + "Default engine as of MySQL 3.23 with great performance", + myisam_init, /* Plugin Init */ NULL, /* Plugin Deinit */ 0x0100, /* 1.0 */ 0 } mysql_declare_plugin_end; + diff --git a/sql/ha_myisam.h b/sql/ha_myisam.h index 0b37f181396..5544e5040b3 100644 --- a/sql/ha_myisam.h +++ b/sql/ha_myisam.h @@ -114,7 +114,10 @@ class ha_myisam: public handler int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type); - ulonglong get_auto_increment(); + virtual void get_auto_increment(ulonglong offset, ulonglong increment, + ulonglong nb_desired_values, + ulonglong *first_value, + ulonglong *nb_reserved_values); int rename_table(const char * from, const char * to); int delete_table(const char *name); int check(THD* thd, HA_CHECK_OPT* check_opt); diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc index 17c0751e747..afeed5f79df 100644 --- a/sql/ha_myisammrg.cc +++ b/sql/ha_myisammrg.cc @@ -39,47 +39,7 @@ static handler *myisammrg_create_handler(TABLE_SHARE *table, /* MyISAM MERGE handlerton */ -static const char myisammrg_hton_name[]= "MRG_MYISAM"; -static const char myisammrg_hton_comment[]= - "Collection of identical MyISAM tables"; - -handlerton myisammrg_hton= { - MYSQL_HANDLERTON_INTERFACE_VERSION, - myisammrg_hton_name, - SHOW_OPTION_YES, - myisammrg_hton_comment, - DB_TYPE_MRG_MYISAM, - NULL, - 0, /* slot */ - 0, /* savepoint size. */ - NULL, /* close_connection */ - NULL, /* savepoint */ - NULL, /* rollback to savepoint */ - NULL, /* release savepoint */ - NULL, /* commit */ - NULL, /* rollback */ - NULL, /* prepare */ - NULL, /* recover */ - NULL, /* commit_by_xid */ - NULL, /* rollback_by_xid */ - NULL, /* create_cursor_read_view */ - NULL, /* set_cursor_read_view */ - NULL, /* close_cursor_read_view */ - myisammrg_create_handler, /* Create a new handler */ - NULL, /* Drop a database */ - myrg_panic, /* Panic call */ - NULL, /* Start Consistent Snapshot */ - NULL, /* Flush logs */ - NULL, /* Show status */ - NULL, /* Partition flags */ - NULL, /* Alter table flags */ - NULL, /* Alter Tablespace */ - NULL, /* Fill Files Table */ - HTON_CAN_RECREATE, - NULL, /* binlog_func */ - NULL, /* binlog_log_query */ - NULL /* release_temporary_latches */ -}; +handlerton myisammrg_hton; static handler *myisammrg_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root) @@ -589,14 +549,27 @@ bool ha_myisammrg::check_if_incompatible_data(HA_CREATE_INFO *info, return COMPATIBLE_DATA_NO; } +static int myisammrg_init() +{ + myisammrg_hton.state=SHOW_OPTION_YES; + myisammrg_hton.db_type=DB_TYPE_MRG_MYISAM; + myisammrg_hton.create=myisammrg_create_handler; + myisammrg_hton.panic=myrg_panic; + myisammrg_hton.flags= HTON_CAN_RECREATE | HTON_ALTER_CANNOT_CREATE; + return 0; +} + +struct st_mysql_storage_engine myisammrg_storage_engine= +{ MYSQL_HANDLERTON_INTERFACE_VERSION, &myisammrg_hton }; + mysql_declare_plugin(myisammrg) { MYSQL_STORAGE_ENGINE_PLUGIN, - &myisammrg_hton, - myisammrg_hton_name, + &myisammrg_storage_engine, + "MRG_MYISAM", "MySQL AB", - myisammrg_hton_comment, - NULL, /* Plugin Init */ + "Collection of identical MyISAM tables", + myisammrg_init, /* Plugin Init */ NULL, /* Plugin Deinit */ 0x0100, /* 1.0 */ 0 diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 119171d1229..8c4d6d18b9b 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -63,26 +63,13 @@ static const int max_transactions= 3; // should really be 2 but there is a trans static uint ndbcluster_partition_flags(); static uint ndbcluster_alter_table_flags(uint flags); -static bool ndbcluster_init(void); +static int ndbcluster_init(void); static int ndbcluster_end(ha_panic_function flag); static bool ndbcluster_show_status(THD*,stat_print_fn *,enum ha_stat_type); static int ndbcluster_alter_tablespace(THD* thd, st_alter_tablespace *info); static int ndbcluster_fill_files_table(THD *thd, TABLE_LIST *tables, COND *cond); -static const char ndbcluster_hton_name[]= "ndbcluster"; -static const char ndbcluster_hton_comment[]= "Clustered, fault-tolerant tables"; - -handlerton ndbcluster_hton = { - MYSQL_HANDLERTON_INTERFACE_VERSION, - "ndbcluster", - SHOW_OPTION_YES, - "Clustered, fault-tolerant tables", - DB_TYPE_NDBCLUSTER, - ndbcluster_init, - ~(uint)0, /* slot */ - /* below are initialized by name in ndbcluster_init() */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -}; +handlerton ndbcluster_hton; static handler *ndbcluster_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root) @@ -107,7 +94,6 @@ static uint ndbcluster_alter_table_flags(uint flags) } -#define NDB_FAILED_AUTO_INCREMENT ~(Uint64)0 #define NDB_AUTO_INCREMENT_RETRIES 10 #define ERR_PRINT(err) \ @@ -183,6 +169,8 @@ static const char * ndb_connected_host= 0; static long ndb_connected_port= 0; static long ndb_number_of_replicas= 0; long ndb_number_of_storage_nodes= 0; +long ndb_number_of_ready_storage_nodes= 0; +long ndb_connect_count= 0; static int update_status_variables(Ndb_cluster_connection *c) { @@ -191,6 +179,8 @@ static int update_status_variables(Ndb_cluster_connection *c) ndb_connected_host= c->get_connected_host(); ndb_number_of_replicas= 0; ndb_number_of_storage_nodes= c->no_db_nodes(); + ndb_number_of_ready_storage_nodes= c->get_no_ready(); + ndb_connect_count= c->get_connect_count(); return 0; } @@ -2464,14 +2454,16 @@ int ha_ndbcluster::write_row(byte *record) { // Table has hidden primary key Ndb *ndb= get_ndb(); - Uint64 auto_value= NDB_FAILED_AUTO_INCREMENT; + int ret; + Uint64 auto_value; uint retries= NDB_AUTO_INCREMENT_RETRIES; do { - auto_value= ndb->getAutoIncrementValue(m_table); - } while (auto_value == NDB_FAILED_AUTO_INCREMENT && + Ndb_tuple_id_range_guard g(m_share); + ret= ndb->getAutoIncrementValue(m_table, g.range, auto_value, 1); + } while (ret == -1 && --retries && ndb->getNdbError().status == NdbError::TemporaryError); - if (auto_value == NDB_FAILED_AUTO_INCREMENT) + if (ret == -1) ERR_RETURN(ndb->getNdbError()); if (set_hidden_key(op, table_share->fields, (const byte*)&auto_value)) ERR_RETURN(op->getNdbError()); @@ -2568,11 +2560,12 @@ int ha_ndbcluster::write_row(byte *record) Ndb *ndb= get_ndb(); Uint64 next_val= (Uint64) table->next_number_field->val_int() + 1; DBUG_PRINT("info", - ("Trying to set next auto increment value to %lu", - (ulong) next_val)); - if (ndb->setAutoIncrementValue(m_table, next_val, TRUE)) - DBUG_PRINT("info", - ("Setting next auto increment value to %u", next_val)); + ("Trying to set next auto increment value to %llu", + (ulonglong) next_val)); + Ndb_tuple_id_range_guard g(m_share); + if (ndb->setAutoIncrementValue(m_table, g.range, next_val, TRUE) + == -1) + ERR_RETURN(ndb->getNdbError()); } m_skip_auto_increment= TRUE; @@ -2885,7 +2878,7 @@ void ndb_unpack_record(TABLE *table, NdbValue *value, MY_BITMAP *defined, byte *buf) { Field **p_field= table->field, *field= *p_field; - uint row_offset= (uint) (buf - table->record[0]); + my_ptrdiff_t row_offset= (my_ptrdiff_t) (buf - table->record[0]); my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set); DBUG_ENTER("ndb_unpack_record"); @@ -2917,24 +2910,34 @@ void ndb_unpack_record(TABLE *table, NdbValue *value, } else if (field->type() == MYSQL_TYPE_BIT) { - byte *save_field_ptr= field->ptr; - field->ptr= save_field_ptr + row_offset; + Field_bit *field_bit= static_cast<Field_bit*>(field); + + /* + Move internal field pointer to point to 'buf'. Calling + the correct member function directly since we know the + type of the object. + */ + field_bit->Field_bit::move_field_offset(row_offset); if (field->pack_length() < 5) { DBUG_PRINT("info", ("bit field H'%.8X", (*value).rec->u_32_value())); - ((Field_bit*) field)->store((longlong) - (*value).rec->u_32_value(), FALSE); + field_bit->Field_bit::store((longlong) (*value).rec->u_32_value(), + FALSE); } else { DBUG_PRINT("info", ("bit field H'%.8X%.8X", *(Uint32*) (*value).rec->aRef(), *((Uint32*) (*value).rec->aRef()+1))); - ((Field_bit*) field)->store((longlong) - (*value).rec->u_64_value(),TRUE); + field_bit->Field_bit::store((longlong) (*value).rec->u_64_value(), + TRUE); } - field->ptr= save_field_ptr; + /* + Move back internal field pointer to point to original + value (usually record[0]). + */ + field_bit->Field_bit::move_field_offset(-row_offset); DBUG_PRINT("info",("[%u] SET", (*value).rec->getColumn()->getColumnNo())); DBUG_DUMP("info", (const char*) field->ptr, field->pack_length()); @@ -3540,8 +3543,19 @@ void ha_ndbcluster::info(uint flag) if (m_table) { Ndb *ndb= get_ndb(); + Ndb_tuple_id_range_guard g(m_share); - stats.auto_increment_value= ndb->readAutoIncrementValue(m_table); + Uint64 auto_increment_value64; + if (ndb->readAutoIncrementValue(m_table, g.range, + auto_increment_value64) == -1) + { + const NdbError err= ndb->getNdbError(); + sql_print_error("Error %lu in readAutoIncrementValue(): %s", + (ulong) err.code, err.message); + stats.auto_increment_value= ~(ulonglong)0; + } + else + stats.auto_increment_value= (ulonglong)auto_increment_value64; } } DBUG_VOID_RETURN; @@ -4447,8 +4461,11 @@ int ha_ndbcluster::create(const char *name, if (readfrm(name, &data, &length)) DBUG_RETURN(1); if (packfrm(data, length, &pack_data, &pack_length)) + { + my_free((char*)data, MYF(0)); DBUG_RETURN(2); - + } + DBUG_PRINT("info", ("setFrm data=%lx len=%d", pack_data, pack_length)); tab.setFrm(pack_data, pack_length); my_free((char*)data, MYF(0)); @@ -4648,7 +4665,7 @@ int ha_ndbcluster::create(const char *name, share->db, share->table_name, m_table->getObjectId(), m_table->getObjectVersion(), - SOT_CREATE_TABLE); + SOT_CREATE_TABLE, 0, 0, 1); break; } } @@ -4921,13 +4938,17 @@ int ha_ndbcluster::rename_table(const char *from, const char *to) { NDBDICT *dict; char old_dbname[FN_HEADLEN]; + char new_dbname[FN_HEADLEN]; char new_tabname[FN_HEADLEN]; const NDBTAB *orig_tab; int result; + bool recreate_indexes= FALSE; + NDBDICT::List index_list; DBUG_ENTER("ha_ndbcluster::rename_table"); DBUG_PRINT("info", ("Renaming %s to %s", from, to)); set_dbname(from, old_dbname); + set_dbname(to, new_dbname); set_tabname(from); set_tabname(to, new_tabname); @@ -4952,6 +4973,11 @@ int ha_ndbcluster::rename_table(const char *from, const char *to) DBUG_ASSERT(r == 0); } #endif + if (my_strcasecmp(system_charset_info, new_dbname, old_dbname)) + { + dict->listIndexes(index_list, *orig_tab); + recreate_indexes= TRUE; + } // Change current database to that of target table set_dbname(to); ndb->setDatabaseName(m_dbname); @@ -5030,7 +5056,33 @@ int ha_ndbcluster::rename_table(const char *from, const char *to) old_dbname, m_tabname, ndb_table_id, ndb_table_version, SOT_RENAME_TABLE, - m_dbname, new_tabname); + m_dbname, new_tabname, 1); + } + + // If we are moving tables between databases, we need to recreate + // indexes + if (recreate_indexes) + { + for (unsigned i = 0; i < index_list.count; i++) + { + NDBDICT::List::Element& index_el = index_list.elements[i]; + // Recreate any indexes not stored in the system database + if (my_strcasecmp(system_charset_info, + index_el.database, NDB_SYSTEM_DATABASE)) + { + set_dbname(from); + ndb->setDatabaseName(m_dbname); + const NDBINDEX * index= dict->getIndexGlobal(index_el.name, new_tab); + DBUG_PRINT("info", ("Creating index %s/%s", + index_el.database, index->getName())); + dict->createIndex(*index, new_tab); + DBUG_PRINT("info", ("Dropping index %s/%s", + index_el.database, index->getName())); + set_dbname(from); + ndb->setDatabaseName(m_dbname); + dict->dropIndexGlobal(*index); + } + } } if (share) free_share(&share); @@ -5053,6 +5105,7 @@ ha_ndbcluster::delete_table(ha_ndbcluster *h, Ndb *ndb, const char *db, const char *table_name) { + THD *thd= current_thd; DBUG_ENTER("ha_ndbcluster::ndbcluster_delete_table"); NDBDICT *dict= ndb->getDictionary(); #ifdef HAVE_NDB_BINLOG @@ -5084,7 +5137,7 @@ ha_ndbcluster::delete_table(ha_ndbcluster *h, Ndb *ndb, ndb_table_version= h->m_table->getObjectVersion(); } #endif - h->release_metadata(current_thd, ndb); + h->release_metadata(thd, ndb); } else { @@ -5149,11 +5202,11 @@ ha_ndbcluster::delete_table(ha_ndbcluster *h, Ndb *ndb, if (!IS_TMP_PREFIX(table_name) && share) { - ndbcluster_log_schema_op(current_thd, share, - current_thd->query, current_thd->query_length, + ndbcluster_log_schema_op(thd, share, + thd->query, thd->query_length, share->db, share->table_name, ndb_table_id, ndb_table_version, - SOT_DROP_TABLE); + SOT_DROP_TABLE, 0, 0, 1); } else if (table_dropped && share && share->op) /* ndbcluster_log_schema_op will do a force GCP */ @@ -5216,7 +5269,10 @@ int ha_ndbcluster::delete_table(const char *name) } -ulonglong ha_ndbcluster::get_auto_increment() +void ha_ndbcluster::get_auto_increment(ulonglong offset, ulonglong increment, + ulonglong nb_desired_values, + ulonglong *first_value, + ulonglong *nb_reserved_values) { int cache_size; Uint64 auto_value; @@ -5234,24 +5290,29 @@ ulonglong ha_ndbcluster::get_auto_increment() m_rows_to_insert - m_rows_inserted : ((m_rows_to_insert > m_autoincrement_prefetch) ? m_rows_to_insert : m_autoincrement_prefetch)); - auto_value= NDB_FAILED_AUTO_INCREMENT; + int ret; uint retries= NDB_AUTO_INCREMENT_RETRIES; do { - auto_value= - (m_skip_auto_increment) ? - ndb->readAutoIncrementValue(m_table) - : ndb->getAutoIncrementValue(m_table, cache_size); - } while (auto_value == NDB_FAILED_AUTO_INCREMENT && + Ndb_tuple_id_range_guard g(m_share); + ret= + m_skip_auto_increment ? + ndb->readAutoIncrementValue(m_table, g.range, auto_value) : + ndb->getAutoIncrementValue(m_table, g.range, auto_value, cache_size); + } while (ret == -1 && --retries && ndb->getNdbError().status == NdbError::TemporaryError); - if (auto_value == NDB_FAILED_AUTO_INCREMENT) + if (ret == -1) { const NdbError err= ndb->getNdbError(); sql_print_error("Error %lu in ::get_auto_increment(): %s", (ulong) err.code, err.message); - DBUG_RETURN(~(ulonglong) 0); + *first_value= ~(ulonglong) 0; + DBUG_VOID_RETURN; } - DBUG_RETURN((longlong)auto_value); + *first_value= (longlong)auto_value; + /* From the point of view of MySQL, NDB reserves one row at a time */ + *nb_reserved_values= 1; + DBUG_VOID_RETURN; } @@ -5732,6 +5793,7 @@ int ndbcluster_drop_database_impl(const char *path) static void ndbcluster_drop_database(char *path) { + THD *thd= current_thd; DBUG_ENTER("ndbcluster_drop_database"); #ifdef HAVE_NDB_BINLOG /* @@ -5749,9 +5811,9 @@ static void ndbcluster_drop_database(char *path) #ifdef HAVE_NDB_BINLOG char db[FN_REFLEN]; ha_ndbcluster::set_dbname(path, db); - ndbcluster_log_schema_op(current_thd, 0, - current_thd->query, current_thd->query_length, - db, "", 0, 0, SOT_DROP_DB); + ndbcluster_log_schema_op(thd, 0, + thd->query, thd->query_length, + db, "", 0, 0, SOT_DROP_DB, 0, 0, 0); #endif DBUG_VOID_RETURN; } @@ -6095,17 +6157,18 @@ static int connect_callback() } extern int ndb_dictionary_is_mysqld; -static bool ndbcluster_init() + +static int ndbcluster_init() { int res; DBUG_ENTER("ndbcluster_init"); ndb_dictionary_is_mysqld= 1; - if (have_ndbcluster != SHOW_OPTION_YES) - goto ndbcluster_init_error; { handlerton &h= ndbcluster_hton; + h.state= have_ndbcluster; + h.db_type= DB_TYPE_NDBCLUSTER; h.close_connection= ndbcluster_close_connection; h.commit= ndbcluster_commit; h.rollback= ndbcluster_rollback; @@ -6123,6 +6186,9 @@ static bool ndbcluster_init() h.flags= HTON_TEMPORARY_NOT_SUPPORTED; } + if (have_ndbcluster != SHOW_OPTION_YES) + DBUG_RETURN(0); // nothing else to do + // Set connectstring if specified if (opt_ndbcluster_connectstring != 0) DBUG_PRINT("connectstring", ("%s", opt_ndbcluster_connectstring)); @@ -6194,7 +6260,7 @@ static bool ndbcluster_init() if (ndbcluster_binlog_start()) goto ndbcluster_init_error; #endif /* HAVE_NDB_BINLOG */ - + pthread_mutex_init(&LOCK_ndb_util_thread, MY_MUTEX_INIT_FAST); pthread_cond_init(&COND_ndb_util_thread, NULL); @@ -6210,7 +6276,7 @@ static bool ndbcluster_init() pthread_cond_destroy(&COND_ndb_util_thread); goto ndbcluster_init_error; } - + ndbcluster_inited= 1; DBUG_RETURN(FALSE); @@ -6825,6 +6891,7 @@ static void dbug_print_open_tables() */ int handle_trailing_share(NDB_SHARE *share) { + THD *thd= current_thd; static ulong trailing_share_id= 0; DBUG_ENTER("handle_trailing_share"); @@ -6835,7 +6902,7 @@ int handle_trailing_share(NDB_SHARE *share) bzero((char*) &table_list,sizeof(table_list)); table_list.db= share->db; table_list.alias= table_list.table_name= share->table_name; - close_cached_tables(current_thd, 0, &table_list, TRUE); + close_cached_tables(thd, 0, &table_list, TRUE); pthread_mutex_lock(&ndbcluster_mutex); if (!--share->use_count) @@ -7130,10 +7197,6 @@ void ndbcluster_real_free_share(NDB_SHARE **share) #ifndef DBUG_OFF bzero((gptr)(*share)->table_share, sizeof(*(*share)->table_share)); bzero((gptr)(*share)->table, sizeof(*(*share)->table)); -#endif - my_free((gptr) (*share)->table_share, MYF(0)); - my_free((gptr) (*share)->table, MYF(0)); -#ifndef DBUG_OFF (*share)->table_share= 0; (*share)->table= 0; #endif @@ -9363,14 +9426,17 @@ ndbcluster_show_status(THD* thd, stat_print_fn *stat_print, "cluster_node_id=%u, " "connected_host=%s, " "connected_port=%u, " - "number_of_storage_nodes=%u", + "number_of_storage_nodes=%u, " + "number_of_ready_storage_nodes=%u, " + "connect_count=%u", ndb_cluster_node_id, ndb_connected_host, ndb_connected_port, - ndb_number_of_storage_nodes); - if (stat_print(thd, ndbcluster_hton.name, strlen(ndbcluster_hton.name), - "connection", strlen("connection"), - buf, buflen)) + ndb_number_of_storage_nodes, + ndb_number_of_ready_storage_nodes, + ndb_connect_count); + if (stat_print(thd, ndbcluster_hton_name, ndbcluster_hton_name_length, + STRING_WITH_LEN("connection"), buf, buflen)) DBUG_RETURN(TRUE); if (get_thd_ndb(thd) && get_thd_ndb(thd)->ndb) @@ -9384,7 +9450,7 @@ ndbcluster_show_status(THD* thd, stat_print_fn *stat_print, 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, strlen(ndbcluster_hton.name), + if (stat_print(thd, ndbcluster_hton_name, ndbcluster_hton_name_length, tmp.m_name, strlen(tmp.m_name), buf, buflen)) DBUG_RETURN(TRUE); } @@ -9939,13 +10005,13 @@ int ndbcluster_alter_tablespace(THD* thd, st_alter_tablespace *info) thd->query, thd->query_length, "", info->tablespace_name, 0, 0, - SOT_TABLESPACE); + SOT_TABLESPACE, 0, 0, 0); else ndbcluster_log_schema_op(thd, 0, thd->query, thd->query_length, "", info->logfile_group_name, 0, 0, - SOT_LOGFILE_GROUP); + SOT_LOGFILE_GROUP, 0, 0, 0); #endif DBUG_RETURN(FALSE); @@ -10049,8 +10115,8 @@ static int ndbcluster_fill_files_table(THD *thd, TABLE_LIST *tables, strlen(ts.getDefaultLogfileGroup()), system_charset_info); table->field[c++]->set_null(); // LOGFILE_GROUP_NUMBER - table->field[c++]->store(ndbcluster_hton.name, - strlen(ndbcluster_hton.name), + table->field[c++]->store(ndbcluster_hton_name, + ndbcluster_hton_name_length, system_charset_info); // ENGINE table->field[c++]->set_null(); // FULLTEXT_KEYS @@ -10143,8 +10209,8 @@ static int ndbcluster_fill_files_table(THD *thd, TABLE_LIST *tables, strlen(uf.getLogfileGroup()), system_charset_info); table->field[c++]->store(uf.getLogfileGroupId()); // LOGFILE_GROUP_NUMBER - table->field[c++]->store(ndbcluster_hton.name, - strlen(ndbcluster_hton.name), + table->field[c++]->store(ndbcluster_hton_name, + ndbcluster_hton_name_length, system_charset_info); // ENGINE table->field[c++]->set_null(); // FULLTEXT_KEYS @@ -10190,15 +10256,17 @@ static int ndbcluster_fill_files_table(THD *thd, TABLE_LIST *tables, DBUG_RETURN(0); } +struct st_mysql_storage_engine ndbcluster_storage_engine= +{ MYSQL_HANDLERTON_INTERFACE_VERSION, &ndbcluster_hton }; mysql_declare_plugin(ndbcluster) { MYSQL_STORAGE_ENGINE_PLUGIN, - &ndbcluster_hton, + &ndbcluster_storage_engine, ndbcluster_hton_name, "MySQL AB", - ndbcluster_hton_comment, - NULL, /* Plugin Init */ + "Clustered, fault-tolerant tables", + ndbcluster_init, /* Plugin Init */ NULL, /* Plugin Deinit */ 0x0100 /* 1.0 */, 0 diff --git a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h index aa6ac2024fc..a5215ee3a04 100644 --- a/sql/ha_ndbcluster.h +++ b/sql/ha_ndbcluster.h @@ -106,6 +106,7 @@ typedef struct st_ndbcluster_share { ulonglong commit_count; char *db; char *table_name; + Ndb::TupleIdRange tuple_id_range; #ifdef HAVE_NDB_BINLOG uint32 flags; NdbEventOperation *op; @@ -113,6 +114,7 @@ typedef struct st_ndbcluster_share { char *old_names; // for rename table TABLE_SHARE *table_share; TABLE *table; + byte *record[2]; // pointer to allocated records for receiving data NdbValue *ndb_value[2]; MY_BITMAP *subscriber_bitmap; #endif @@ -138,6 +140,19 @@ set_ndb_share_state(NDB_SHARE *share, NDB_SHARE_STATE state) pthread_mutex_unlock(&share->mutex); } +struct Ndb_tuple_id_range_guard { + Ndb_tuple_id_range_guard(NDB_SHARE* _share) : + share(_share), + range(share->tuple_id_range) { + pthread_mutex_lock(&share->mutex); + } + ~Ndb_tuple_id_range_guard() { + pthread_mutex_unlock(&share->mutex); + } + NDB_SHARE* share; + Ndb::TupleIdRange& range; +}; + #ifdef HAVE_NDB_BINLOG /* NDB_SHARE.flags */ #define NSF_HIDDEN_PK 1 /* table has hidden primary key */ @@ -730,7 +745,6 @@ private: int drop_indexes(Ndb *ndb, TABLE *tab); int add_index_handle(THD *thd, NdbDictionary::Dictionary *dict, KEY *key_info, const char *index_name, uint index_no); - int initialize_autoincrement(const void *table); int get_metadata(const char* path); void release_metadata(THD *thd, Ndb *ndb); NDB_INDEX_TYPE get_index_type(uint idx_no) const; @@ -794,7 +808,10 @@ private: int set_index_key(NdbOperation *, const KEY *key_info, const byte *key_ptr); void print_results(); - ulonglong get_auto_increment(); + virtual void get_auto_increment(ulonglong offset, ulonglong increment, + ulonglong nb_desired_values, + ulonglong *first_value, + ulonglong *nb_reserved_values); int ndb_err(NdbTransaction*); bool uses_blob_value(); @@ -856,7 +873,7 @@ private: bool m_primary_key_update; bool m_write_op; bool m_ignore_no_key; - ha_rows m_rows_to_insert; + ha_rows m_rows_to_insert; // TODO: merge it with handler::estimation_rows_to_insert? ha_rows m_rows_inserted; ha_rows m_bulk_insert_rows; ha_rows m_rows_changed; @@ -894,3 +911,7 @@ int ndbcluster_find_files(THD *thd,const char *db,const char *path, int ndbcluster_table_exists_in_engine(THD* thd, const char *db, const char *name); void ndbcluster_print_error(int error, const NdbOperation *error_op); + +static const char ndbcluster_hton_name[]= "ndbcluster"; +static const int ndbcluster_hton_name_length=sizeof(ndbcluster_hton_name)-1; + diff --git a/sql/ha_ndbcluster_binlog.cc b/sql/ha_ndbcluster_binlog.cc index 47fe2796aac..3b93eb4b4c9 100644 --- a/sql/ha_ndbcluster_binlog.cc +++ b/sql/ha_ndbcluster_binlog.cc @@ -25,6 +25,7 @@ #include "slave.h" #include "ha_ndbcluster_binlog.h" #include "NdbDictionary.hpp" +#include <util/NdbAutoPtr.hpp> #ifdef ndb_dynamite #undef assert @@ -39,6 +40,12 @@ #define NDB_SCHEMA_TABLE_FILE "./" NDB_REP_DB "/" NDB_SCHEMA_TABLE /* + Timeout for syncing schema events between + mysql servers, and between mysql server and the binlog +*/ +const int opt_ndb_sync_timeout= 120; + +/* Flag showing if the ndb injector thread is running, if so == 1 -1 if it was started but later stopped for some reason 0 if never started @@ -255,7 +262,7 @@ ndbcluster_binlog_close_table(THD *thd, NDB_SHARE *share) DBUG_ENTER("ndbcluster_binlog_close_table"); if (share->table_share) { - free_table_share(share->table_share); + closefrm(share->table, 1); share->table_share= 0; share->table= 0; } @@ -273,7 +280,8 @@ ndbcluster_binlog_close_table(THD *thd, NDB_SHARE *share) static int ndbcluster_binlog_open_table(THD *thd, NDB_SHARE *share, - TABLE_SHARE *table_share, TABLE *table) + TABLE_SHARE *table_share, TABLE *table, + int reopen) { int error; DBUG_ENTER("ndbcluster_binlog_open_table"); @@ -286,27 +294,34 @@ ndbcluster_binlog_open_table(THD *thd, NDB_SHARE *share, share->key, error); DBUG_PRINT("error", ("open_table_def failed %d", error)); free_table_share(table_share); - my_free((gptr) table_share, MYF(0)); - my_free((gptr) table, MYF(0)); DBUG_RETURN(error); } - if ((error= open_table_from_share(thd, table_share, "", 0, + if ((error= open_table_from_share(thd, table_share, "", 0 /* fon't allocate buffers */, (uint) READ_ALL, 0, table, FALSE))) { sql_print_error("Unable to open table for %s, error=%d(%d)", share->key, error, my_errno); DBUG_PRINT("error", ("open_table_from_share failed %d", error)); free_table_share(table_share); - my_free((gptr) table_share, MYF(0)); - my_free((gptr) table, MYF(0)); DBUG_RETURN(error); } assign_new_table_id(table_share); - if (!table->record[1] || table->record[1] == table->record[0]) + + if (!reopen) { - table->record[1]= alloc_root(&table->mem_root, - table->s->rec_buff_length); + // allocate memory on ndb share so it can be reused after online alter table + share->record[0]= (byte*) alloc_root(&share->mem_root, table->s->rec_buff_length); + share->record[1]= (byte*) alloc_root(&share->mem_root, table->s->rec_buff_length); } + { + my_ptrdiff_t row_offset= share->record[0] - table->record[0]; + Field **p_field; + for (p_field= table->field; *p_field; p_field++) + (*p_field)->move_field_offset(row_offset); + table->record[0]= share->record[0]; + table->record[1]= share->record[1]; + } + table->in_use= injector_thd; table->s->db.str= share->db; @@ -376,10 +391,9 @@ void ndbcluster_binlog_init_share(NDB_SHARE *share, TABLE *_table) while (1) { int error; - TABLE_SHARE *table_share= - (TABLE_SHARE *) my_malloc(sizeof(*table_share), MYF(MY_WME)); - TABLE *table= (TABLE*) my_malloc(sizeof(*table), MYF(MY_WME)); - if ((error= ndbcluster_binlog_open_table(thd, share, table_share, table))) + TABLE_SHARE *table_share= (TABLE_SHARE *) alloc_root(mem_root, sizeof(*table_share)); + TABLE *table= (TABLE*) alloc_root(mem_root, sizeof(*table)); + if ((error= ndbcluster_binlog_open_table(thd, share, table_share, table, 0))) break; /* ! do not touch the contents of the table @@ -500,6 +514,7 @@ ndbcluster_binlog_log_query(THD *thd, enum_binlog_command binlog_command, { case LOGCOM_CREATE_TABLE: type= SOT_CREATE_TABLE; + DBUG_ASSERT(FALSE); break; case LOGCOM_ALTER_TABLE: type= SOT_ALTER_TABLE; @@ -507,9 +522,11 @@ ndbcluster_binlog_log_query(THD *thd, enum_binlog_command binlog_command, break; case LOGCOM_RENAME_TABLE: type= SOT_RENAME_TABLE; + DBUG_ASSERT(FALSE); break; case LOGCOM_DROP_TABLE: type= SOT_DROP_TABLE; + DBUG_ASSERT(FALSE); break; case LOGCOM_CREATE_DB: type= SOT_CREATE_DB; @@ -521,12 +538,14 @@ ndbcluster_binlog_log_query(THD *thd, enum_binlog_command binlog_command, break; case LOGCOM_DROP_DB: type= SOT_DROP_DB; + DBUG_ASSERT(FALSE); break; } if (log) { ndbcluster_log_schema_op(thd, 0, query, query_length, - db, table_name, 0, 0, type); + db, table_name, 0, 0, type, + 0, 0, 0); } DBUG_VOID_RETURN; } @@ -966,6 +985,154 @@ static char *ndb_pack_varchar(const NDBCOL *col, char *buf, } /* + acknowledge handling of schema operation +*/ +static int +ndbcluster_update_slock(THD *thd, + const char *db, + const char *table_name) +{ + DBUG_ENTER("ndbcluster_update_slock"); + if (!schema_share) + { + DBUG_RETURN(0); + } + + const NdbError *ndb_error= 0; + uint32 node_id= g_ndb_cluster_connection->node_id(); + Ndb *ndb= check_ndb_in_thd(thd); + char save_db[FN_HEADLEN]; + strcpy(save_db, ndb->getDatabaseName()); + + char tmp_buf[FN_REFLEN]; + NDBDICT *dict= ndb->getDictionary(); + ndb->setDatabaseName(NDB_REP_DB); + Ndb_table_guard ndbtab_g(dict, NDB_SCHEMA_TABLE); + const NDBTAB *ndbtab= ndbtab_g.get_table(); + NdbTransaction *trans= 0; + int retries= 100; + const NDBCOL *col[SCHEMA_SIZE]; + unsigned sz[SCHEMA_SIZE]; + + MY_BITMAP slock; + uint32 bitbuf[SCHEMA_SLOCK_SIZE/4]; + bitmap_init(&slock, bitbuf, sizeof(bitbuf)*8, false); + + if (ndbtab == 0) + { + abort(); + DBUG_RETURN(0); + } + + { + uint i; + for (i= 0; i < SCHEMA_SIZE; i++) + { + col[i]= ndbtab->getColumn(i); + if (i != SCHEMA_QUERY_I) + { + sz[i]= col[i]->getLength(); + DBUG_ASSERT(sz[i] <= sizeof(tmp_buf)); + } + } + } + + while (1) + { + if ((trans= ndb->startTransaction()) == 0) + goto err; + { + NdbOperation *op= 0; + int r= 0; + + /* read the bitmap exlusive */ + r|= (op= trans->getNdbOperation(ndbtab)) == 0; + DBUG_ASSERT(r == 0); + r|= op->readTupleExclusive(); + DBUG_ASSERT(r == 0); + + /* db */ + ndb_pack_varchar(col[SCHEMA_DB_I], tmp_buf, db, strlen(db)); + r|= op->equal(SCHEMA_DB_I, tmp_buf); + DBUG_ASSERT(r == 0); + /* name */ + ndb_pack_varchar(col[SCHEMA_NAME_I], tmp_buf, table_name, + strlen(table_name)); + r|= op->equal(SCHEMA_NAME_I, tmp_buf); + DBUG_ASSERT(r == 0); + /* slock */ + r|= op->getValue(SCHEMA_SLOCK_I, (char*)slock.bitmap) == 0; + DBUG_ASSERT(r == 0); + } + if (trans->execute(NdbTransaction::NoCommit)) + goto err; + bitmap_clear_bit(&slock, node_id); + { + NdbOperation *op= 0; + int r= 0; + + /* now update the tuple */ + r|= (op= trans->getNdbOperation(ndbtab)) == 0; + DBUG_ASSERT(r == 0); + r|= op->updateTuple(); + DBUG_ASSERT(r == 0); + + /* db */ + ndb_pack_varchar(col[SCHEMA_DB_I], tmp_buf, db, strlen(db)); + r|= op->equal(SCHEMA_DB_I, tmp_buf); + DBUG_ASSERT(r == 0); + /* name */ + ndb_pack_varchar(col[SCHEMA_NAME_I], tmp_buf, table_name, + strlen(table_name)); + r|= op->equal(SCHEMA_NAME_I, tmp_buf); + DBUG_ASSERT(r == 0); + /* slock */ + r|= op->setValue(SCHEMA_SLOCK_I, (char*)slock.bitmap); + DBUG_ASSERT(r == 0); + /* node_id */ + r|= op->setValue(SCHEMA_NODE_ID_I, node_id); + DBUG_ASSERT(r == 0); + /* type */ + r|= op->setValue(SCHEMA_TYPE_I, (uint32)SOT_CLEAR_SLOCK); + DBUG_ASSERT(r == 0); + } + if (trans->execute(NdbTransaction::Commit) == 0) + { + dict->forceGCPWait(); + DBUG_PRINT("info", ("node %d cleared lock on '%s.%s'", + node_id, db, table_name)); + break; + } + err: + const NdbError *this_error= trans ? + &trans->getNdbError() : &ndb->getNdbError(); + if (this_error->status == NdbError::TemporaryError) + { + if (retries--) + { + if (trans) + ndb->closeTransaction(trans); + continue; // retry + } + } + ndb_error= this_error; + break; + } +end: + if (ndb_error) + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, + ER_GET_ERRMSG, ER(ER_GET_ERRMSG), + ndb_error->code, + ndb_error->message, + "Could not release lock on '%s.%s'", + db, table_name); + if (trans) + ndb->closeTransaction(trans); + ndb->setDatabaseName(save_db); + DBUG_RETURN(0); +} + +/* log query in schema table */ static void ndb_report_waiting(const char *key, @@ -999,7 +1166,8 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, uint32 ndb_table_id, uint32 ndb_table_version, enum SCHEMA_OP_TYPE type, - const char *new_db, const char *new_table_name) + const char *new_db, const char *new_table_name, + int have_lock_open) { DBUG_ENTER("ndbcluster_log_schema_op"); Thd_ndb *thd_ndb= get_thd_ndb(thd); @@ -1080,8 +1248,8 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, Uint64 epoch= 0; MY_BITMAP schema_subscribers; uint32 bitbuf[sizeof(ndb_schema_object->slock)/4]; - uint32 bitbuf_e[sizeof(bitbuf)]; - bzero((char *)bitbuf_e, sizeof(bitbuf_e)); + char bitbuf_e[sizeof(bitbuf)]; + bzero(bitbuf_e, sizeof(bitbuf_e)); { int i, updated= 0; int no_storage_nodes= g_ndb_cluster_connection->no_db_nodes(); @@ -1100,7 +1268,17 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, } (void) pthread_mutex_unlock(&schema_share->mutex); if (updated) + { bitmap_clear_bit(&schema_subscribers, node_id); + /* + if setting own acknowledge bit it is important that + no other mysqld's are registred, as subsequent code + will cause the original event to be hidden (by blob + merge event code) + */ + if (bitmap_is_clear_all(&schema_subscribers)) + bitmap_set_bit(&schema_subscribers, node_id); + } else bitmap_clear_all(&schema_subscribers); @@ -1213,7 +1391,7 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, { log_db= new_db; log_tab= new_table_name; - log_subscribers= (const char *)bitbuf_e; // no ack expected on this + log_subscribers= bitbuf_e; // no ack expected on this log_type= (uint32)SOT_RENAME_TABLE_NEW; continue; } @@ -1221,7 +1399,6 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, } if (trans->execute(NdbTransaction::Commit) == 0) { - dict->forceGCPWait(); DBUG_PRINT("info", ("logged: %s", query)); break; } @@ -1242,7 +1419,7 @@ err: } end: if (ndb_error) - push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, ER_GET_ERRMSG, ER(ER_GET_ERRMSG), ndb_error->code, ndb_error->message, @@ -1258,8 +1435,22 @@ end: if (ndb_error == 0 && !bitmap_is_clear_all(&schema_subscribers)) { - int max_timeout= 10; + /* + if own nodeid is set we are a single mysqld registred + as an optimization we update the slock directly + */ + if (bitmap_is_set(&schema_subscribers, node_id)) + ndbcluster_update_slock(thd, db, table_name); + else + dict->forceGCPWait(); + + int max_timeout= opt_ndb_sync_timeout; (void) pthread_mutex_lock(&ndb_schema_object->mutex); + if (have_lock_open) + { + safe_mutex_assert_owner(&LOCK_open); + (void) pthread_mutex_unlock(&LOCK_open); + } while (1) { struct timespec abstime; @@ -1269,7 +1460,8 @@ end: int ret= pthread_cond_timedwait(&injector_cond, &ndb_schema_object->mutex, &abstime); - + if (thd->killed) + break; (void) pthread_mutex_lock(&schema_share->mutex); for (i= 0; i < no_storage_nodes; i++) { @@ -1304,6 +1496,10 @@ end: "distributing", ndb_schema_object->key); } } + if (have_lock_open) + { + (void) pthread_mutex_lock(&LOCK_open); + } (void) pthread_mutex_unlock(&ndb_schema_object->mutex); } @@ -1314,154 +1510,6 @@ end: } /* - acknowledge handling of schema operation -*/ -static int -ndbcluster_update_slock(THD *thd, - const char *db, - const char *table_name) -{ - DBUG_ENTER("ndbcluster_update_slock"); - if (!schema_share) - { - DBUG_RETURN(0); - } - - const NdbError *ndb_error= 0; - uint32 node_id= g_ndb_cluster_connection->node_id(); - Ndb *ndb= check_ndb_in_thd(thd); - char save_db[FN_HEADLEN]; - strcpy(save_db, ndb->getDatabaseName()); - - char tmp_buf[FN_REFLEN]; - NDBDICT *dict= ndb->getDictionary(); - ndb->setDatabaseName(NDB_REP_DB); - Ndb_table_guard ndbtab_g(dict, NDB_SCHEMA_TABLE); - const NDBTAB *ndbtab= ndbtab_g.get_table(); - NdbTransaction *trans= 0; - int retries= 100; - const NDBCOL *col[SCHEMA_SIZE]; - unsigned sz[SCHEMA_SIZE]; - - MY_BITMAP slock; - uint32 bitbuf[SCHEMA_SLOCK_SIZE/4]; - bitmap_init(&slock, bitbuf, sizeof(bitbuf)*8, FALSE); - - if (ndbtab == 0) - { - abort(); - DBUG_RETURN(0); - } - - { - uint i; - for (i= 0; i < SCHEMA_SIZE; i++) - { - col[i]= ndbtab->getColumn(i); - if (i != SCHEMA_QUERY_I) - { - sz[i]= col[i]->getLength(); - DBUG_ASSERT(sz[i] <= sizeof(tmp_buf)); - } - } - } - - while (1) - { - if ((trans= ndb->startTransaction()) == 0) - goto err; - { - NdbOperation *op= 0; - int r= 0; - - /* read the bitmap exlusive */ - r|= (op= trans->getNdbOperation(ndbtab)) == 0; - DBUG_ASSERT(r == 0); - r|= op->readTupleExclusive(); - DBUG_ASSERT(r == 0); - - /* db */ - ndb_pack_varchar(col[SCHEMA_DB_I], tmp_buf, db, strlen(db)); - r|= op->equal(SCHEMA_DB_I, tmp_buf); - DBUG_ASSERT(r == 0); - /* name */ - ndb_pack_varchar(col[SCHEMA_NAME_I], tmp_buf, table_name, - strlen(table_name)); - r|= op->equal(SCHEMA_NAME_I, tmp_buf); - DBUG_ASSERT(r == 0); - /* slock */ - r|= op->getValue(SCHEMA_SLOCK_I, (char*)slock.bitmap) == 0; - DBUG_ASSERT(r == 0); - } - if (trans->execute(NdbTransaction::NoCommit)) - goto err; - bitmap_clear_bit(&slock, node_id); - { - NdbOperation *op= 0; - int r= 0; - - /* now update the tuple */ - r|= (op= trans->getNdbOperation(ndbtab)) == 0; - DBUG_ASSERT(r == 0); - r|= op->updateTuple(); - DBUG_ASSERT(r == 0); - - /* db */ - ndb_pack_varchar(col[SCHEMA_DB_I], tmp_buf, db, strlen(db)); - r|= op->equal(SCHEMA_DB_I, tmp_buf); - DBUG_ASSERT(r == 0); - /* name */ - ndb_pack_varchar(col[SCHEMA_NAME_I], tmp_buf, table_name, - strlen(table_name)); - r|= op->equal(SCHEMA_NAME_I, tmp_buf); - DBUG_ASSERT(r == 0); - /* slock */ - r|= op->setValue(SCHEMA_SLOCK_I, (char*)slock.bitmap); - DBUG_ASSERT(r == 0); - /* node_id */ - r|= op->setValue(SCHEMA_NODE_ID_I, node_id); - DBUG_ASSERT(r == 0); - /* type */ - r|= op->setValue(SCHEMA_TYPE_I, (uint32)SOT_CLEAR_SLOCK); - DBUG_ASSERT(r == 0); - } - if (trans->execute(NdbTransaction::Commit) == 0) - { - dict->forceGCPWait(); - DBUG_PRINT("info", ("node %d cleared lock on '%s.%s'", - node_id, db, table_name)); - break; - } - err: - const NdbError *this_error= trans ? - &trans->getNdbError() : &ndb->getNdbError(); - if (this_error->status == NdbError::TemporaryError) - { - if (retries--) - { - if (trans) - ndb->closeTransaction(trans); - continue; // retry - } - } - ndb_error= this_error; - break; - } -end: - if (ndb_error) - push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, - ER_GET_ERRMSG, ER(ER_GET_ERRMSG), - ndb_error->code, - ndb_error->message, - "Could not release lock on '%s.%s'", - db, table_name); - if (trans) - ndb->closeTransaction(trans); - ndb->setDatabaseName(save_db); - DBUG_RETURN(0); -} - -/* Handle _non_ data events from the storage nodes */ int @@ -1470,7 +1518,7 @@ ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp, { DBUG_ENTER("ndb_handle_schema_change"); TABLE* table= share->table; - TABLE_SHARE *table_share= table->s; + TABLE_SHARE *table_share= share->table_share; const char *dbname= table_share->db.str; const char *tabname= table_share->table_name.str; bool do_close_cached_tables= FALSE; @@ -1539,12 +1587,18 @@ ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp, old->getObjectVersion() != altered_table->getObjectVersion()) dict->putTable(altered_table); + my_free((char*)data, MYF(MY_ALLOW_ZERO_PTR)); + data= NULL; if ((error= unpackfrm(&data, &length, altered_table->getFrmData())) || (error= writefrm(key, data, length))) { sql_print_information("NDB: Failed write frm for %s.%s, error %d", dbname, tabname, error); } + + // copy names as memory will be freed + NdbAutoPtr<char> a1((char *)(dbname= strdup(dbname))); + NdbAutoPtr<char> a2((char *)(tabname= strdup(tabname))); ndbcluster_binlog_close_table(thd, share); TABLE_LIST table_list; @@ -1553,12 +1607,20 @@ ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp, table_list.alias= table_list.table_name= (char *)tabname; close_cached_tables(thd, 0, &table_list, TRUE); - if ((error= ndbcluster_binlog_open_table(thd, share, - table_share, table))) + if ((error= ndbcluster_binlog_open_table(thd, share, + table_share, table, 1))) sql_print_information("NDB: Failed to re-open table %s.%s", dbname, tabname); + + table= share->table; + table_share= share->table_share; + dbname= table_share->db.str; + tabname= table_share->table_name.str; + pthread_mutex_unlock(&LOCK_open); } + my_free((char*)data, MYF(MY_ALLOW_ZERO_PTR)); + my_free((char*)pack_data, MYF(MY_ALLOW_ZERO_PTR)); } // If only frm was changed continue replicating @@ -1670,17 +1732,26 @@ ndb_binlog_thread_handle_schema_event(THD *thd, Ndb *ndb, bitmap_init(&slock, schema->slock, 8*SCHEMA_SLOCK_SIZE, FALSE); uint node_id= g_ndb_cluster_connection->node_id(); ndbcluster_get_schema(tmp_share, schema); + enum SCHEMA_OP_TYPE schema_type= (enum SCHEMA_OP_TYPE)schema->type; + DBUG_PRINT("info", + ("%s.%s: log query_length: %d query: '%s' type: %d", + schema->db, schema->name, + schema->query_length, schema->query, + schema_type)); + if (schema_type == SOT_CLEAR_SLOCK) + { + /* + handle slock after epoch is completed to ensure that + schema events get inserted in the binlog after any data + events + */ + post_epoch_log_list->push_back(schema, mem_root); + DBUG_RETURN(0); + } if (schema->node_id != node_id) { int log_query= 0, post_epoch_unlock= 0; - DBUG_PRINT("info", - ("%s.%s: log query_length: %d query: '%s' type: %d", - schema->db, schema->name, - schema->query_length, schema->query, - schema->type)); - char key[FN_REFLEN]; - build_table_filename(key, sizeof(key), schema->db, schema->name, ""); - switch ((enum SCHEMA_OP_TYPE)schema->type) + switch (schema_type) { case SOT_DROP_TABLE: // fall through @@ -1697,10 +1768,15 @@ ndb_binlog_thread_handle_schema_event(THD *thd, Ndb *ndb, pthread_mutex_lock(&LOCK_open); if (ndb_create_table_from_engine(thd, schema->db, schema->name)) { - sql_print_error("Could not discover table '%s.%s' from " - "binlog schema event '%s' from node %d", + sql_print_error("NDB binlog: Could not discover table '%s.%s' from " + "binlog schema event '%s' from node %d. " + "my_errno: %d", schema->db, schema->name, schema->query, - schema->node_id); + schema->node_id, my_errno); + List_iterator_fast<MYSQL_ERROR> it(thd->warn_list); + MYSQL_ERROR *err; + while ((err= it++)) + sql_print_warning("NDB binlog: (%d)%s", err->code, err->msg); } pthread_mutex_unlock(&LOCK_open); log_query= 1; @@ -1723,30 +1799,12 @@ ndb_binlog_thread_handle_schema_event(THD *thd, Ndb *ndb, TRUE, /* print error */ FALSE); /* binlog the query */ break; - case SOT_CLEAR_SLOCK: - { - pthread_mutex_lock(&ndbcluster_mutex); - NDB_SCHEMA_OBJECT *ndb_schema_object= - (NDB_SCHEMA_OBJECT*) hash_search(&ndb_schema_objects, - (byte*) key, strlen(key)); - if (ndb_schema_object) - { - pthread_mutex_lock(&ndb_schema_object->mutex); - memcpy(ndb_schema_object->slock, schema->slock, - sizeof(ndb_schema_object->slock)); - DBUG_DUMP("ndb_schema_object->slock_bitmap.bitmap", - (char*)ndb_schema_object->slock_bitmap.bitmap, - no_bytes_in_map(&ndb_schema_object->slock_bitmap)); - pthread_mutex_unlock(&ndb_schema_object->mutex); - pthread_cond_signal(&injector_cond); - } - pthread_mutex_unlock(&ndbcluster_mutex); - DBUG_RETURN(0); - } case SOT_TABLESPACE: case SOT_LOGFILE_GROUP: log_query= 1; break; + case SOT_CLEAR_SLOCK: + abort(); } if (log_query && ndb_binlog_running) { @@ -1778,6 +1836,9 @@ ndb_binlog_thread_handle_schema_event(THD *thd, Ndb *ndb, // skip break; case NDBEVENT::TE_CLUSTER_FAILURE: + if (ndb_extra_logging) + sql_print_information("NDB Binlog: cluster failure for %s at epoch %u.", + schema_share->key, (unsigned) pOp->getGCI()); // fall through case NDBEVENT::TE_DROP: if (ndb_extra_logging && @@ -1786,7 +1847,7 @@ ndb_binlog_thread_handle_schema_event(THD *thd, Ndb *ndb, "read only on reconnect."); free_share(&schema_share); schema_share= 0; - ndb_binlog_tables_inited= FALSE; + close_cached_tables((THD*) 0, 0, (TABLE_LIST*) 0, FALSE); // fall through case NDBEVENT::TE_ALTER: ndb_handle_schema_change(thd, ndb, pOp, tmp_share); @@ -1884,10 +1945,30 @@ ndb_binlog_thread_handle_schema_event_post_epoch(THD *thd, schema->type)); int log_query= 0; { + enum SCHEMA_OP_TYPE schema_type= (enum SCHEMA_OP_TYPE)schema->type; char key[FN_REFLEN]; build_table_filename(key, sizeof(key), schema->db, schema->name, ""); + if (schema_type == SOT_CLEAR_SLOCK) + { + pthread_mutex_lock(&ndbcluster_mutex); + NDB_SCHEMA_OBJECT *ndb_schema_object= + (NDB_SCHEMA_OBJECT*) hash_search(&ndb_schema_objects, + (byte*) key, strlen(key)); + if (ndb_schema_object) + { + pthread_mutex_lock(&ndb_schema_object->mutex); + memcpy(ndb_schema_object->slock, schema->slock, + sizeof(ndb_schema_object->slock)); + DBUG_DUMP("ndb_schema_object->slock_bitmap.bitmap", + (char*)ndb_schema_object->slock_bitmap.bitmap, + no_bytes_in_map(&ndb_schema_object->slock_bitmap)); + pthread_mutex_unlock(&ndb_schema_object->mutex); + pthread_cond_signal(&injector_cond); + } + pthread_mutex_unlock(&ndbcluster_mutex); + continue; + } NDB_SHARE *share= get_share(key, 0, FALSE, FALSE); - enum SCHEMA_OP_TYPE schema_type= (enum SCHEMA_OP_TYPE)schema->type; switch (schema_type) { case SOT_DROP_DB: @@ -1924,7 +2005,7 @@ ndb_binlog_thread_handle_schema_event_post_epoch(THD *thd, // fall through case SOT_RENAME_TABLE_NEW: log_query= 1; - if (ndb_binlog_running) + if (ndb_binlog_running && (!share || !share->op)) { /* we need to free any share here as command below @@ -1938,10 +2019,14 @@ ndb_binlog_thread_handle_schema_event_post_epoch(THD *thd, pthread_mutex_lock(&LOCK_open); if (ndb_create_table_from_engine(thd, schema->db, schema->name)) { - sql_print_error("Could not discover table '%s.%s' from " - "binlog schema event '%s' from node %d", + sql_print_error("NDB binlog: Could not discover table '%s.%s' from " + "binlog schema event '%s' from node %d. my_errno: %d", schema->db, schema->name, schema->query, - schema->node_id); + schema->node_id, my_errno); + List_iterator_fast<MYSQL_ERROR> it(thd->warn_list); + MYSQL_ERROR *err; + while ((err= it++)) + sql_print_warning("NDB binlog: (%d)%s", err->code, err->msg); } pthread_mutex_unlock(&LOCK_open); } @@ -2101,7 +2186,14 @@ add_binlog_index_err: Functions for start, stop, wait for ndbcluster binlog thread *********************************************************************/ -static int do_ndbcluster_binlog_close_connection= 0; +enum Binlog_thread_state +{ + BCCC_running= 0, + BCCC_exit= 1, + BCCC_restart= 2 +}; + +static enum Binlog_thread_state do_ndbcluster_binlog_close_connection= BCCC_restart; int ndbcluster_binlog_start() { @@ -2139,7 +2231,7 @@ static void ndbcluster_binlog_close_connection(THD *thd) DBUG_ENTER("ndbcluster_binlog_close_connection"); const char *save_info= thd->proc_info; thd->proc_info= "ndbcluster_binlog_close_connection"; - do_ndbcluster_binlog_close_connection= 1; + do_ndbcluster_binlog_close_connection= BCCC_exit; while (ndb_binlog_thread_running > 0) sleep(1); thd->proc_info= save_info; @@ -2300,6 +2392,7 @@ ndbcluster_create_event(Ndb *ndb, const NDBTAB *ndbtab, const char *event_name, NDB_SHARE *share, int push_warning) { + THD *thd= current_thd; DBUG_ENTER("ndbcluster_create_event"); DBUG_PRINT("info", ("table=%s version=%d event=%s share=%s", ndbtab->getName(), ndbtab->getObjectVersion(), @@ -2329,12 +2422,12 @@ ndbcluster_create_event(Ndb *ndb, const NDBTAB *ndbtab, "with BLOB attribute and no PK is not supported", share->key); if (push_warning) - push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, ER_ILLEGAL_HA_CREATE_OPTION, ER(ER_ILLEGAL_HA_CREATE_OPTION), - ndbcluster_hton.name, + ndbcluster_hton_name, "Binlog of table with BLOB attribute and no PK"); - + share->flags|= NSF_NO_BINLOG; DBUG_RETURN(-1); } @@ -2373,7 +2466,7 @@ ndbcluster_create_event(Ndb *ndb, const NDBTAB *ndbtab, failed, print a warning */ if (push_warning) - push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, ER_GET_ERRMSG, ER(ER_GET_ERRMSG), dict->getNdbError().code, dict->getNdbError().message, "NDB"); @@ -2401,7 +2494,7 @@ ndbcluster_create_event(Ndb *ndb, const NDBTAB *ndbtab, dict->dropEvent(my_event.getName())) { if (push_warning) - push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, ER_GET_ERRMSG, ER(ER_GET_ERRMSG), dict->getNdbError().code, dict->getNdbError().message, "NDB"); @@ -2420,7 +2513,7 @@ ndbcluster_create_event(Ndb *ndb, const NDBTAB *ndbtab, if (dict->createEvent(my_event)) { if (push_warning) - push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, ER_GET_ERRMSG, ER(ER_GET_ERRMSG), dict->getNdbError().code, dict->getNdbError().message, "NDB"); @@ -2433,7 +2526,7 @@ ndbcluster_create_event(Ndb *ndb, const NDBTAB *ndbtab, DBUG_RETURN(-1); } #ifdef NDB_BINLOG_EXTRA_WARNINGS - push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, ER_GET_ERRMSG, ER(ER_GET_ERRMSG), 0, "NDB Binlog: Removed trailing event", "NDB"); @@ -2462,6 +2555,7 @@ int ndbcluster_create_event_ops(NDB_SHARE *share, const NDBTAB *ndbtab, const char *event_name) { + THD *thd= current_thd; /* we are in either create table or rename table so table should be locked, hence we can work with the share without locks @@ -2535,7 +2629,7 @@ ndbcluster_create_event_ops(NDB_SHARE *share, const NDBTAB *ndbtab, { sql_print_error("NDB Binlog: Creating NdbEventOperation failed for" " %s",event_name); - push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, ER_GET_ERRMSG, ER(ER_GET_ERRMSG), ndb->getNdbError().code, ndb->getNdbError().message, @@ -2585,7 +2679,7 @@ ndbcluster_create_event_ops(NDB_SHARE *share, const NDBTAB *ndbtab, sql_print_error("NDB Binlog: Creating NdbEventOperation" " blob field %u handles failed (code=%d) for %s", j, op->getNdbError().code, event_name); - push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, ER_GET_ERRMSG, ER(ER_GET_ERRMSG), op->getNdbError().code, op->getNdbError().message, @@ -2622,7 +2716,7 @@ ndbcluster_create_event_ops(NDB_SHARE *share, const NDBTAB *ndbtab, retries= 0; if (retries == 0) { - push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, ER_GET_ERRMSG, ER(ER_GET_ERRMSG), op->getNdbError().code, op->getNdbError().message, "NDB"); @@ -2670,6 +2764,7 @@ ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name, NDB_SHARE *share, const char *type_str) { DBUG_ENTER("ndbcluster_handle_drop_table"); + THD *thd= current_thd; NDBDICT *dict= ndb->getDictionary(); if (event_name && dict->dropEvent(event_name)) @@ -2677,7 +2772,7 @@ ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name, if (dict->getNdbError().code != 4710) { /* drop event failed for some reason, issue a warning */ - push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, ER_GET_ERRMSG, ER(ER_GET_ERRMSG), dict->getNdbError().code, dict->getNdbError().message, "NDB"); @@ -2715,10 +2810,14 @@ ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name, these out of order, thus we are keeping the SYNC_DROP_ defined for now. */ + const char *save_proc_info= thd->proc_info; #define SYNC_DROP_ #ifdef SYNC_DROP_ + thd->proc_info= "Syncing ndb table schema operation and binlog"; (void) pthread_mutex_lock(&share->mutex); - int max_timeout= 10; + safe_mutex_assert_owner(&LOCK_open); + (void) pthread_mutex_unlock(&LOCK_open); + int max_timeout= opt_ndb_sync_timeout; while (share->op) { struct timespec abstime; @@ -2726,7 +2825,8 @@ ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name, int ret= pthread_cond_timedwait(&injector_cond, &share->mutex, &abstime); - if (share->op == 0) + if (thd->killed || + share->op == 0) break; if (ret) { @@ -2742,6 +2842,7 @@ ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name, type_str, share->key); } } + (void) pthread_mutex_lock(&LOCK_open); (void) pthread_mutex_unlock(&share->mutex); #else (void) pthread_mutex_lock(&share->mutex); @@ -2749,6 +2850,7 @@ ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name, share->op= 0; (void) pthread_mutex_unlock(&share->mutex); #endif + thd->proc_info= save_proc_info; DBUG_RETURN(0); } @@ -2819,7 +2921,8 @@ ndb_binlog_thread_handle_non_data_event(THD *thd, Ndb *ndb, { case NDBEVENT::TE_CLUSTER_FAILURE: if (ndb_extra_logging) - sql_print_information("NDB Binlog: cluster failure for %s.", share->key); + sql_print_information("NDB Binlog: cluster failure for %s at epoch %u.", + share->key, (unsigned) pOp->getGCI()); if (apply_status_share == share) { if (ndb_extra_logging && @@ -2828,7 +2931,6 @@ ndb_binlog_thread_handle_non_data_event(THD *thd, Ndb *ndb, "read only on reconnect."); free_share(&apply_status_share); apply_status_share= 0; - ndb_binlog_tables_inited= FALSE; } DBUG_PRINT("info", ("CLUSTER FAILURE EVENT: " "%s received share: 0x%lx op: %lx share op: %lx " @@ -2844,7 +2946,6 @@ ndb_binlog_thread_handle_non_data_event(THD *thd, Ndb *ndb, "read only on reconnect."); free_share(&apply_status_share); apply_status_share= 0; - ndb_binlog_tables_inited= FALSE; } /* ToDo: remove printout */ if (ndb_extra_logging) @@ -3257,37 +3358,73 @@ pthread_handler_t ndb_binlog_thread_func(void *arg) pthread_mutex_unlock(&injector_mutex); pthread_cond_signal(&injector_cond); - thd->proc_info= "Waiting for ndbcluster to start"; - - pthread_mutex_lock(&injector_mutex); - while (!schema_share || - (ndb_binlog_running && !apply_status_share)) +restart: + /* + Main NDB Injector loop + */ { - /* ndb not connected yet */ - struct timespec abstime; - set_timespec(abstime, 1); - pthread_cond_timedwait(&injector_cond, &injector_mutex, &abstime); - if (abort_loop) + thd->proc_info= "Waiting for ndbcluster to start"; + + pthread_mutex_lock(&injector_mutex); + while (!schema_share || + (ndb_binlog_running && !apply_status_share)) { - pthread_mutex_unlock(&injector_mutex); - goto err; + /* ndb not connected yet */ + struct timespec abstime; + set_timespec(abstime, 1); + pthread_cond_timedwait(&injector_cond, &injector_mutex, &abstime); + if (abort_loop) + { + pthread_mutex_unlock(&injector_mutex); + goto err; + } } - } - pthread_mutex_unlock(&injector_mutex); + pthread_mutex_unlock(&injector_mutex); - /* - Main NDB Injector loop - */ + if (thd_ndb == NULL) + { + DBUG_ASSERT(ndbcluster_hton.slot != ~(uint)0); + if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb())) + { + sql_print_error("Could not allocate Thd_ndb object"); + goto err; + } + set_thd_ndb(thd, thd_ndb); + thd_ndb->options|= TNO_NO_LOG_SCHEMA_OP; + thd->query_id= 0; // to keep valgrind quiet + } + } - DBUG_ASSERT(ndbcluster_hton.slot != ~(uint)0); - if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb())) { - sql_print_error("Could not allocate Thd_ndb object"); - goto err; + // wait for the first event + thd->proc_info= "Waiting for first event from ndbcluster"; + DBUG_PRINT("info", ("Waiting for the first event")); + int schema_res= 0; + Uint64 schema_gci= 0; + while (schema_res == 0 && !abort_loop) + { + schema_res= s_ndb->pollEvents(100, &schema_gci); + } + // now check that we have epochs consistant with what we had before the restart + DBUG_PRINT("info", ("schema_res: %d schema_gci: %d", schema_res, schema_gci)); + if (schema_res > 0) + { + i_ndb->pollEvents(0); + i_ndb->flushIncompleteEvents(schema_gci); + s_ndb->flushIncompleteEvents(schema_gci); + if (schema_gci < ndb_latest_handled_binlog_epoch) + { + sql_print_error("NDB Binlog: cluster has been restarted --initial or with older filesystem. " + "ndb_latest_handled_binlog_epoch: %u, while current epoch: %u. " + "RESET MASTER should be issued. Resetting ndb_latest_handled_binlog_epoch.", + (unsigned) ndb_latest_handled_binlog_epoch, (unsigned) schema_gci); + g_latest_trans_gci= 0; + ndb_latest_handled_binlog_epoch= 0; + ndb_latest_applied_binlog_epoch= 0; + ndb_latest_received_binlog_epoch= 0; + } + } } - set_thd_ndb(thd, thd_ndb); - thd_ndb->options|= TNO_NO_LOG_SCHEMA_OP; - thd->query_id= 0; // to keep valgrind quiet { static char db[]= ""; thd->db= db; @@ -3295,11 +3432,20 @@ pthread_handler_t ndb_binlog_thread_func(void *arg) open_binlog_index(thd, &binlog_tables, &binlog_index); thd->db= db; } - + do_ndbcluster_binlog_close_connection= BCCC_running; for ( ; !((abort_loop || do_ndbcluster_binlog_close_connection) && - ndb_latest_handled_binlog_epoch >= g_latest_trans_gci); ) + ndb_latest_handled_binlog_epoch >= g_latest_trans_gci) && + do_ndbcluster_binlog_close_connection != BCCC_restart; ) { - +#ifndef DBUG_OFF + if (do_ndbcluster_binlog_close_connection) + { + DBUG_PRINT("info", ("do_ndbcluster_binlog_close_connection: %d, " + "ndb_latest_handled_binlog_epoch: %llu, " + "g_latest_trans_gci: %llu", do_ndbcluster_binlog_close_connection, + ndb_latest_handled_binlog_epoch, g_latest_trans_gci)); + } +#endif #ifdef RUN_NDB_BINLOG_TIMER main_timer.stop(); sql_print_information("main_timer %ld ms", main_timer.elapsed_ms()); @@ -3324,7 +3470,13 @@ pthread_handler_t ndb_binlog_thread_func(void *arg) ndb_latest_received_binlog_epoch= gci; while (gci > schema_gci && schema_res >= 0) + { + static char buf[64]; + thd->proc_info= "Waiting for schema epoch"; + my_snprintf(buf, sizeof(buf), "%s %u(%u)", thd->proc_info, (unsigned) schema_gci, (unsigned) gci); + thd->proc_info= buf; schema_res= s_ndb->pollEvents(10, &schema_gci); + } if ((abort_loop || do_ndbcluster_binlog_close_connection) && (ndb_latest_handled_binlog_epoch >= g_latest_trans_gci || @@ -3360,10 +3512,31 @@ pthread_handler_t ndb_binlog_thread_func(void *arg) while (pOp != NULL) { if (!pOp->hasError()) + { ndb_binlog_thread_handle_schema_event(thd, s_ndb, pOp, &post_epoch_log_list, &post_epoch_unlock_list, &mem_root); + DBUG_PRINT("info", ("s_ndb first: %s", s_ndb->getEventOperation() ? + s_ndb->getEventOperation()->getEvent()->getTable()->getName() : + "<empty>")); + DBUG_PRINT("info", ("i_ndb first: %s", i_ndb->getEventOperation() ? + i_ndb->getEventOperation()->getEvent()->getTable()->getName() : + "<empty>")); + if (i_ndb->getEventOperation() == NULL && + s_ndb->getEventOperation() == NULL && + do_ndbcluster_binlog_close_connection == BCCC_running) + { + DBUG_PRINT("info", ("do_ndbcluster_binlog_close_connection= BCCC_restart")); + do_ndbcluster_binlog_close_connection= BCCC_restart; + if (ndb_latest_received_binlog_epoch < g_latest_trans_gci && ndb_binlog_running) + { + sql_print_error("NDB Binlog: latest transaction in epoch %lld not in binlog " + "as latest received epoch is %lld", + g_latest_trans_gci, ndb_latest_received_binlog_epoch); + } + } + } else sql_print_error("NDB: error %lu (%s) on handling " "binlog schema event", @@ -3526,6 +3699,25 @@ pthread_handler_t ndb_binlog_thread_func(void *arg) ndb_binlog_thread_handle_non_data_event(thd, i_ndb, pOp, row); // reset to catch errors i_ndb->setDatabaseName(""); + DBUG_PRINT("info", ("s_ndb first: %s", s_ndb->getEventOperation() ? + s_ndb->getEventOperation()->getEvent()->getTable()->getName() : + "<empty>")); + DBUG_PRINT("info", ("i_ndb first: %s", i_ndb->getEventOperation() ? + i_ndb->getEventOperation()->getEvent()->getTable()->getName() : + "<empty>")); + if (i_ndb->getEventOperation() == NULL && + s_ndb->getEventOperation() == NULL && + do_ndbcluster_binlog_close_connection == BCCC_running) + { + DBUG_PRINT("info", ("do_ndbcluster_binlog_close_connection= BCCC_restart")); + do_ndbcluster_binlog_close_connection= BCCC_restart; + if (ndb_latest_received_binlog_epoch < g_latest_trans_gci && ndb_binlog_running) + { + sql_print_error("NDB Binlog: latest transaction in epoch %lld not in binlog " + "as latest received epoch is %lld", + g_latest_trans_gci, ndb_latest_received_binlog_epoch); + } + } } pOp= i_ndb->nextEvent(); @@ -3581,6 +3773,13 @@ pthread_handler_t ndb_binlog_thread_func(void *arg) *root_ptr= old_root; ndb_latest_handled_binlog_epoch= ndb_latest_received_binlog_epoch; } + if (do_ndbcluster_binlog_close_connection == BCCC_restart) + { + ndb_binlog_tables_inited= FALSE; + close_thread_tables(thd); + binlog_index= 0; + goto restart; + } err: DBUG_PRINT("info",("Shutting down cluster binlog thread")); thd->proc_info= "Shutting down"; @@ -3691,7 +3890,7 @@ ndbcluster_show_status_binlog(THD* thd, stat_print_fn *stat_print, ndb_latest_received_binlog_epoch, ndb_latest_handled_binlog_epoch, ndb_latest_applied_binlog_epoch); - if (stat_print(thd, ndbcluster_hton.name, strlen(ndbcluster_hton.name), + if (stat_print(thd, ndbcluster_hton_name, ndbcluster_hton_name_length, "binlog", strlen("binlog"), buf, buflen)) DBUG_RETURN(TRUE); diff --git a/sql/ha_ndbcluster_binlog.h b/sql/ha_ndbcluster_binlog.h index d82cdccb1b9..7c45dee59d0 100644 --- a/sql/ha_ndbcluster_binlog.h +++ b/sql/ha_ndbcluster_binlog.h @@ -138,8 +138,9 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, uint32 ndb_table_id, uint32 ndb_table_version, enum SCHEMA_OP_TYPE type, - const char *new_db= 0, - const char *new_table_name= 0); + const char *new_db, + const char *new_table_name, + int have_lock_open); int ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name, NDB_SHARE *share, const char *type_str); diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 1d12d1967d3..11f890082e3 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -74,46 +74,18 @@ static handler *partition_create_handler(TABLE_SHARE *share, static uint partition_flags(); static uint alter_table_flags(uint flags); -static const char partition_hton_name[]= "partition"; -static const char partition_hton_comment[]= "Partition Storage Engine Helper"; - -handlerton partition_hton = { - MYSQL_HANDLERTON_INTERFACE_VERSION, - partition_hton_name, - SHOW_OPTION_YES, - partition_hton_comment, /* A comment used by SHOW to describe an engine */ - DB_TYPE_PARTITION_DB, - 0, /* Method that initializes a storage engine */ - 0, /* slot */ - 0, /* savepoint size */ - NULL /*ndbcluster_close_connection*/, - NULL, /* savepoint_set */ - NULL, /* savepoint_rollback */ - NULL, /* savepoint_release */ - NULL /*ndbcluster_commit*/, - NULL /*ndbcluster_rollback*/, - NULL, /* prepare */ - NULL, /* recover */ - NULL, /* commit_by_xid */ - NULL, /* rollback_by_xid */ - NULL, - NULL, - NULL, - partition_create_handler, /* Create a new handler */ - NULL, /* Drop a database */ - NULL, /* Panic call */ - NULL, /* Start Consistent Snapshot */ - NULL, /* Flush logs */ - NULL, /* Show status */ - partition_flags, /* Partition flags */ - alter_table_flags, /* Partition flags */ - NULL, /* Alter Tablespace */ - NULL, /* Fill FILES table */ - HTON_NOT_USER_SELECTABLE | HTON_HIDDEN, - NULL, /* binlog_func */ - NULL, /* binlog_log_query */ - NULL /* release_temporary_latches */ -}; +handlerton partition_hton; + +static int partition_initialize() +{ + partition_hton.state= SHOW_OPTION_YES; + partition_hton.db_type= DB_TYPE_PARTITION_DB; + partition_hton.create= partition_create_handler; + partition_hton.partition_flags= partition_flags; + partition_hton.alter_table_flags= alter_table_flags; + partition_hton.flags= HTON_NOT_USER_SELECTABLE | HTON_HIDDEN; + return 0; +} /* Create new partition handler @@ -1113,8 +1085,7 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt, part)); if ((error= handle_opt_part(thd, check_opt, m_file[part], flag))) { - my_error(ER_GET_ERRNO, MYF(0), error); - DBUG_RETURN(TRUE); + DBUG_RETURN(error); } } while (++j < no_subparts); } @@ -1123,8 +1094,7 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt, DBUG_PRINT("info", ("Optimize partition %u", i)); if ((error= handle_opt_part(thd, check_opt, m_file[i], flag))) { - my_error(ER_GET_ERRNO, MYF(0), error); - DBUG_RETURN(TRUE); + DBUG_RETURN(error); } } } @@ -2821,7 +2791,7 @@ void ha_partition::start_bulk_insert(ha_rows rows) file= m_file; do { - (*file)->start_bulk_insert(rows); + (*file)->ha_start_bulk_insert(rows); } while (*(++file)); DBUG_VOID_RETURN; } @@ -2848,7 +2818,7 @@ int ha_partition::end_bulk_insert() do { int tmp; - if ((tmp= (*file)->end_bulk_insert())) + if ((tmp= (*file)->ha_end_bulk_insert())) error= tmp; } while (*(++file)); DBUG_RETURN(error); @@ -4173,8 +4143,11 @@ void ha_partition::info(uint flag) if (flag & HA_STATUS_AUTO) { + ulonglong nb_reserved_values; DBUG_PRINT("info", ("HA_STATUS_AUTO")); - stats.auto_increment_value= get_auto_increment(); + /* we don't want to reserve any values, it's pure information */ + get_auto_increment(0, 0, 0, &stats.auto_increment_value, &nb_reserved_values); + release_auto_increment(); } if (flag & HA_STATUS_VARIABLE) { @@ -4191,6 +4164,8 @@ void ha_partition::info(uint flag) index_file_length: Length of index file, in principle bytes in indexes in the table We report sum + delete_length: Length of free space easily used by new records in table + We report sum mean_record_length:Mean record length in the table We calculate this check_time: Time of last check (only applicable to MyISAM) @@ -4201,6 +4176,7 @@ void ha_partition::info(uint flag) stats.data_file_length= 0; stats.index_file_length= 0; stats.check_time= 0; + stats.delete_length= 0; file_array= m_file; do { @@ -4212,6 +4188,7 @@ void ha_partition::info(uint flag) stats.deleted+= file->stats.deleted; stats.data_file_length+= file->stats.data_file_length; stats.index_file_length+= file->stats.index_file_length; + stats.delete_length+= file->delete_length; if (file->stats.check_time > stats.check_time) stats.check_time= file->stats.check_time; } @@ -5299,21 +5276,54 @@ void ha_partition::restore_auto_increment() partitions. */ -ulonglong ha_partition::get_auto_increment() +void ha_partition::get_auto_increment(ulonglong offset, ulonglong increment, + ulonglong nb_desired_values, + ulonglong *first_value, + ulonglong *nb_reserved_values) { - ulonglong max_auto_inc= 0; + ulonglong first_value_part, last_value_part, nb_reserved_values_part, + last_value; handler **pos, **end; DBUG_ENTER("ha_partition::get_auto_increment"); for (pos=m_file, end= m_file+ m_tot_parts; pos != end ; pos++) { - ulonglong auto_inc; - auto_inc= (*pos)->get_auto_increment(); - set_if_bigger(max_auto_inc, auto_inc); + (*pos)->get_auto_increment(offset, increment, nb_desired_values, + &first_value_part, &nb_reserved_values_part); + if (first_value_part == ~(ulonglong)(0)) // error in one partition + { + *first_value= first_value_part; + break; + } + /* + Partition has reserved an interval. Intersect it with the intervals + already reserved for the previous partitions. + */ + last_value_part= (nb_reserved_values_part == ULONGLONG_MAX) ? + ULONGLONG_MAX : (first_value_part + nb_reserved_values_part * increment); + set_if_bigger(*first_value, first_value_part); + set_if_smaller(last_value, last_value_part); + } + if (last_value < *first_value) /* empty intersection, error */ + { + *first_value= ~(ulonglong)(0); } - DBUG_RETURN(max_auto_inc); + *nb_reserved_values= (last_value == ULONGLONG_MAX) ? + ULONGLONG_MAX : ((last_value - *first_value) / increment); + + DBUG_VOID_RETURN; } +void ha_partition::release_auto_increment() +{ + DBUG_ENTER("ha_partition::release_auto_increment"); + + for (uint i= 0; i < m_tot_parts; i++) + { + m_file[i]->release_auto_increment(); + } + DBUG_VOID_RETURN; +} /**************************************************************************** MODULE initialise handler for HANDLER call @@ -5326,6 +5336,82 @@ void ha_partition::init_table_handle_for_HANDLER() /**************************************************************************** + MODULE enable/disable indexes +****************************************************************************/ + +/* + Disable indexes for a while + SYNOPSIS + disable_indexes() + mode Mode + RETURN VALUES + 0 Success + != 0 Error +*/ + +int ha_partition::disable_indexes(uint mode) +{ + handler **file; + int error= 0; + + for (file= m_file; *file; file++) + { + if ((error= (*file)->disable_indexes(mode))) + break; + } + return error; +} + + +/* + Enable indexes again + SYNOPSIS + enable_indexes() + mode Mode + RETURN VALUES + 0 Success + != 0 Error +*/ + +int ha_partition::enable_indexes(uint mode) +{ + handler **file; + int error= 0; + + for (file= m_file; *file; file++) + { + if ((error= (*file)->enable_indexes(mode))) + break; + } + return error; +} + + +/* + Check if indexes are disabled + SYNOPSIS + indexes_are_disabled() + + RETURN VALUES + 0 Indexes are enabled + != 0 Indexes are disabled +*/ + +int ha_partition::indexes_are_disabled(void) +{ + handler **file; + int error= 0; + + for (file= m_file; *file; file++) + { + if ((error= (*file)->indexes_are_disabled())) + break; + } + return error; +} + + +/**************************************************************************** MODULE Partition Share ****************************************************************************/ /* @@ -5446,15 +5532,17 @@ static int free_share(PARTITION_SHARE *share) } #endif /* NOT_USED */ +struct st_mysql_storage_engine partition_storage_engine= +{ MYSQL_HANDLERTON_INTERFACE_VERSION, &partition_hton }; mysql_declare_plugin(partition) { MYSQL_STORAGE_ENGINE_PLUGIN, - &partition_hton, - partition_hton_name, + &partition_storage_engine, + "partition", "Mikael Ronstrom, MySQL AB", - partition_hton_comment, - NULL, /* Plugin Init */ + "Partition Storage Engine Helper", + partition_initialize, /* Plugin Init */ NULL, /* Plugin Deinit */ 0x0100, /* 1.0 */ 0 diff --git a/sql/ha_partition.h b/sql/ha_partition.h index 13a1e5cf6e6..b52c8d92164 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -805,7 +805,11 @@ public: ------------------------------------------------------------------------- */ virtual void restore_auto_increment(); - virtual ulonglong get_auto_increment(); + virtual void get_auto_increment(ulonglong offset, ulonglong increment, + ulonglong nb_desired_values, + ulonglong *first_value, + ulonglong *nb_reserved_values); + virtual void release_auto_increment(); /* ------------------------------------------------------------------------- @@ -928,17 +932,18 @@ public: virtual uint checksum() const; virtual bool is_crashed() const; virtual bool auto_repair() const; + */ + /* ------------------------------------------------------------------------- MODULE enable/disable indexes ------------------------------------------------------------------------- - Enable/Disable Indexes are not supported currently (Heap, MyISAM) - This means that the following methods are not implemented: + Enable/Disable Indexes are only supported by HEAP and MyISAM. ------------------------------------------------------------------------- + */ virtual int disable_indexes(uint mode); virtual int enable_indexes(uint mode); virtual int indexes_are_disabled(void); - */ /* ------------------------------------------------------------------------- diff --git a/sql/handler.cc b/sql/handler.cc index 927a8eb8ed5..81f4772e844 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -49,6 +49,7 @@ check for dups and to find handlerton from legacy_db_type. Remove when legacy_db_type is finally gone */ +st_plugin_int *hton2plugin[MAX_HA]; static handlerton *installed_htons[128]; @@ -58,35 +59,14 @@ KEY_CREATE_INFO default_key_create_info= { HA_KEY_ALG_UNDEF, 0, {NullS,0} }; static handler *create_default(TABLE_SHARE *table, MEM_ROOT *mem_root); -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, NULL, NULL, - NULL, /* alter_tablespace */ - NULL, /* fill_files_table */ - HTON_NO_FLAGS, /* flags */ - NULL, /* binlog_func */ - NULL, /* binlog_log_query */ - NULL /* release_temporary_latches */ -}; - static SHOW_COMP_OPTION have_yes= SHOW_OPTION_YES; /* number of entries in handlertons[] */ -ulong total_ha; +ulong total_ha= 0; /* number of storage engines (from handlertons[]) that support 2pc */ -ulong total_ha_2pc; +ulong total_ha_2pc= 0; /* size of savepoint storage area (see ha_init) */ -ulong savepoint_alloc_size; +ulong savepoint_alloc_size= 0; struct show_table_alias_st sys_table_aliases[]= { @@ -123,7 +103,7 @@ handlerton *ha_resolve_by_name(THD *thd, LEX_STRING *name) if ((plugin= plugin_lock(name, MYSQL_STORAGE_ENGINE_PLUGIN))) { - handlerton *hton= (handlerton *) plugin->plugin->info; + handlerton *hton= (handlerton *)plugin->data; if (!(hton->flags & HTON_NOT_USER_SELECTABLE)) return hton; plugin_unlock(plugin); @@ -155,7 +135,7 @@ const char *ha_get_storage_engine(enum legacy_db_type db_type) default: if (db_type > DB_TYPE_UNKNOWN && db_type < DB_TYPE_DEFAULT && installed_htons[db_type]) - return installed_htons[db_type]->name; + return hton2plugin[installed_htons[db_type]->slot]->name.str; return "*NONE*"; } } @@ -163,9 +143,7 @@ const char *ha_get_storage_engine(enum legacy_db_type db_type) static handler *create_default(TABLE_SHARE *table, MEM_ROOT *mem_root) { - handlerton *hton= ha_resolve_by_legacy_type(current_thd, DB_TYPE_DEFAULT); - return (hton && hton != &default_hton && hton->create) ? - hton->create(table, mem_root) : NULL; + return (hton && hton->create) ? hton->create(table, mem_root) : NULL; } @@ -182,7 +160,7 @@ handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type) default: if (db_type > DB_TYPE_UNKNOWN && db_type < DB_TYPE_DEFAULT) return installed_htons[db_type]; - return NULL; + return NULL; } } @@ -360,22 +338,19 @@ static int ha_finish_errors(void) int ha_finalize_handlerton(st_plugin_int *plugin) { - handlerton *hton; + handlerton *hton= (handlerton *)plugin->data; DBUG_ENTER("ha_finalize_handlerton"); - if (!(hton= (handlerton *) plugin->plugin->info)) - DBUG_RETURN(1); - switch (hton->state) { case SHOW_OPTION_NO: case SHOW_OPTION_DISABLED: break; case SHOW_OPTION_YES: - if (hton->panic && hton->panic(HA_PANIC_CLOSE)) - DBUG_RETURN(1); if (installed_htons[hton->db_type] == hton) installed_htons[hton->db_type]= NULL; + if (hton->panic && hton->panic(HA_PANIC_CLOSE)) + DBUG_RETURN(1); break; }; DBUG_RETURN(0); @@ -384,37 +359,28 @@ int ha_finalize_handlerton(st_plugin_int *plugin) int ha_initialize_handlerton(st_plugin_int *plugin) { - handlerton *hton; + handlerton *hton= ((st_mysql_storage_engine *)plugin->plugin->info)->handlerton; DBUG_ENTER("ha_initialize_handlerton"); - if (!(hton= (handlerton *) plugin->plugin->info)) - DBUG_RETURN(1); - - /* for the sake of sanity, we set the handlerton name to be the - same as the plugin name */ - hton->name= plugin->name.str; - + plugin->data= hton; // shortcut for the future + /* + the switch below and hton->state should be removed when + command-line options for plugins will be implemented + */ switch (hton->state) { case SHOW_OPTION_NO: break; case SHOW_OPTION_YES: - if (!hton->init || !hton->init()) { - uint tmp= hton->savepoint_offset; - hton->savepoint_offset= savepoint_alloc_size; - savepoint_alloc_size+= tmp; - hton->slot= total_ha++; - if (hton->prepare) - total_ha_2pc++; - + uint tmp; /* now check the db_type for conflict */ - if (hton->db_type <= DB_TYPE_UNKNOWN || + if (hton->db_type <= DB_TYPE_UNKNOWN || hton->db_type >= DB_TYPE_DEFAULT || installed_htons[hton->db_type]) { int idx= (int) DB_TYPE_FIRST_DYNAMIC; - + while (idx < (int) DB_TYPE_DEFAULT && installed_htons[idx]) idx++; @@ -425,10 +391,17 @@ int ha_initialize_handlerton(st_plugin_int *plugin) } if (hton->db_type != DB_TYPE_UNKNOWN) sql_print_warning("Storage engine '%s' has conflicting typecode. " - "Assigning value %d.", hton->name, idx); + "Assigning value %d.", plugin->plugin->name, idx); hton->db_type= (enum legacy_db_type) idx; } installed_htons[hton->db_type]= hton; + tmp= hton->savepoint_offset; + hton->savepoint_offset= savepoint_alloc_size; + savepoint_alloc_size+= tmp; + hton->slot= total_ha++; + hton2plugin[hton->slot]=plugin; + if (hton->prepare) + total_ha_2pc++; break; } /* fall through */ @@ -439,33 +412,14 @@ int ha_initialize_handlerton(st_plugin_int *plugin) 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(plugin); - plugin->state= PLUGIN_IS_READY; - } - return FALSE; -} - - int ha_init() { int error= 0; - total_ha= savepoint_alloc_size= 0; DBUG_ENTER("ha_init"); - bzero(installed_htons, sizeof(installed_htons)); - if (ha_init_errors()) DBUG_RETURN(1); - if (plugin_foreach(NULL, init_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, 0)) - DBUG_RETURN(1); - DBUG_ASSERT(total_ha < MAX_HA); /* Check if there is a transaction-capable storage engine besides the @@ -477,16 +431,14 @@ int ha_init() DBUG_RETURN(error); } +/* + close, flush or restart databases + Ignore this for other databases than ours +*/ - - - /* close, flush or restart databases */ - /* Ignore this for other databases than ours */ - -static my_bool panic_handlerton(THD *unused1, st_plugin_int *plugin, - void *arg) +static my_bool panic_handlerton(THD *unused1, st_plugin_int *plugin, void *arg) { - handlerton *hton= (handlerton *) plugin->plugin->info; + handlerton *hton= (handlerton *)plugin->data; if (hton->state == SHOW_OPTION_YES && hton->panic) ((int*)arg)[0]|= hton->panic((enum ha_panic_function)((int*)arg)[1]); return FALSE; @@ -496,10 +448,10 @@ static my_bool panic_handlerton(THD *unused1, st_plugin_int *plugin, 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]; @@ -508,7 +460,7 @@ int ha_panic(enum ha_panic_function flag) static my_bool dropdb_handlerton(THD *unused1, st_plugin_int *plugin, void *path) { - handlerton *hton= (handlerton *) plugin->plugin->info; + handlerton *hton= (handlerton *)plugin->data; if (hton->state == SHOW_OPTION_YES && hton->drop_database) hton->drop_database((char *)path); return FALSE; @@ -524,9 +476,11 @@ void ha_drop_database(char* 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 */ + handlerton *hton= (handlerton *)plugin->data; + /* + 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); @@ -616,7 +570,8 @@ int ha_prepare(THD *thd) else { push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, - ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA), (*ht)->name); + ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA), + hton2plugin[(*ht)->slot]->name.str); } } } @@ -855,7 +810,7 @@ struct xahton_st { static my_bool xacommit_handlerton(THD *unused1, st_plugin_int *plugin, void *arg) { - handlerton *hton= (handlerton *) plugin->plugin->info; + handlerton *hton= (handlerton *)plugin->data; if (hton->state == SHOW_OPTION_YES && hton->recover) { hton->commit_by_xid(((struct xahton_st *)arg)->xid); @@ -867,7 +822,7 @@ static my_bool xacommit_handlerton(THD *unused1, st_plugin_int *plugin, static my_bool xarollback_handlerton(THD *unused1, st_plugin_int *plugin, void *arg) { - handlerton *hton= (handlerton *) plugin->plugin->info; + handlerton *hton= (handlerton *)plugin->data; if (hton->state == SHOW_OPTION_YES && hton->recover) { hton->rollback_by_xid(((struct xahton_st *)arg)->xid); @@ -882,7 +837,7 @@ 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); @@ -974,16 +929,16 @@ struct xarecover_st static my_bool xarecover_handlerton(THD *unused, st_plugin_int *plugin, void *arg) { - handlerton *hton= (handlerton *) plugin->plugin->info; + handlerton *hton= (handlerton *)plugin->data; struct xarecover_st *info= (struct xarecover_st *) arg; int got; - + if (hton->state == SHOW_OPTION_YES && hton->recover) { while ((got= hton->recover(info->list, info->len)) > 0 ) { sql_print_information("Found %d prepared transaction(s) in %s", - got, hton->name); + got, hton2plugin[hton->slot]->name.str); for (int i=0; i < got; i ++) { my_xid x=info->list[i].get_my_xid(); @@ -1163,7 +1118,7 @@ bool mysql_xa_recover(THD *thd) static my_bool release_temporary_latches(THD *thd, st_plugin_int *plugin, void *unused) { - handlerton *hton= (handlerton *) plugin->plugin->info; + handlerton *hton= (handlerton *)plugin->data; if (hton->state == SHOW_OPTION_YES && hton->release_temporary_latches) hton->release_temporary_latches(thd); @@ -1288,7 +1243,7 @@ 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; + handlerton *hton= (handlerton *)plugin->data; if (hton->state == SHOW_OPTION_YES && hton->start_consistent_snapshot) { @@ -1319,7 +1274,7 @@ int ha_start_consistent_snapshot(THD *thd) static my_bool flush_handlerton(THD *thd, st_plugin_int *plugin, void *arg) { - handlerton *hton= (handlerton *) plugin->plugin->info; + handlerton *hton= (handlerton *)plugin->data; if (hton->state == SHOW_OPTION_YES && hton->flush_logs && hton->flush_logs()) return TRUE; return FALSE; @@ -1545,7 +1500,7 @@ next_insert_id(ulonglong nr,struct system_variables *variables) Update the auto_increment field if necessary SYNOPSIS - update_auto_increment() + update_auto_increment() RETURN 0 ok @@ -1574,8 +1529,9 @@ next_insert_id(ulonglong nr,struct system_variables *variables) statement. For the following rows we generate new numbers based on the last used number. - - thd->next_insert_id != 0. This happens when we have read a statement - from the binary log or when one has used SET LAST_INSERT_ID=#. + - thd->next_insert_id != 0. This happens when we have read an Intvar event + of type INSERT_ID_EVENT from the binary log or when one has used SET + INSERT_ID=#. In this case we will set the column to the value of next_insert_id. The next row will be given the id @@ -1591,8 +1547,20 @@ next_insert_id(ulonglong nr,struct system_variables *variables) start counting from the inserted value. thd->next_insert_id is cleared after it's been used for a statement. + + TODO + + Replace all references to "next number" or NEXT_NUMBER to + "auto_increment", everywhere (see below: there is + table->auto_increment_field_not_null, and there also exists + table->next_number_field, it's not consistent). + */ +#define AUTO_INC_DEFAULT_NB_ROWS 1 // Some prefer 1024 here +#define AUTO_INC_DEFAULT_NB_MAX_BITS 16 +#define AUTO_INC_DEFAULT_NB_MAX ((1 << AUTO_INC_DEFAULT_NB_MAX_BITS) - 1) + bool handler::update_auto_increment() { ulonglong nr; @@ -1608,17 +1576,24 @@ bool handler::update_auto_increment() */ thd->prev_insert_id= thd->next_insert_id; auto_increment_field_not_null= table->auto_increment_field_not_null; - table->auto_increment_field_not_null= FALSE; + table->auto_increment_field_not_null= FALSE; // to reset for next row if ((nr= table->next_number_field->val_int()) != 0 || auto_increment_field_not_null && thd->variables.sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO) { - /* Clear flag for next row */ - /* Mark that we didn't generate a new value **/ + /* + The user did specify a value for the auto_inc column, we don't generate + a new value, write it down. + */ auto_increment_column_changed=0; - /* Update next_insert_id if we have already generated a value */ + /* + Update next_insert_id if we had already generated a value in this + statement (case of INSERT VALUES(null),(3763),(null): + the last NULL needs to insert 3764, not the value of the first NULL plus + 1). + */ if (thd->clear_next_insert_id && nr >= thd->next_insert_id) { if (variables->auto_increment_increment != 1) @@ -1632,9 +1607,53 @@ bool handler::update_auto_increment() } if (!(nr= thd->next_insert_id)) { - if ((nr= get_auto_increment()) == ~(ulonglong) 0) + ulonglong nb_desired_values= 1, nb_reserved_values; +#ifdef TO_BE_ENABLED_SOON + /* + Reserved intervals will be stored in "THD::auto_inc_intervals". + handler::estimation_rows_to_insert will be the argument passed by + handler::ha_start_bulk_insert(). + */ + uint estimation_known= test(estimation_rows_to_insert > 0); + uint nb_already_reserved_intervals= thd->auto_inc_intervals.nb_elements(); + /* + If an estimation was given to the engine: + - use it. + - if we already reserved numbers, it means the estimation was + not accurate, then we'll reserve 2*AUTO_INC_DEFAULT_NB_VALUES the 2nd + time, twice that the 3rd time etc. + If no estimation was given, use those increasing defaults from the + start, starting from AUTO_INC_DEFAULT_NB_VALUES. + Don't go beyond a max to not reserve "way too much" (because reservation + means potentially losing unused values). + */ + if (nb_already_reserved_intervals == 0 && estimation_known) + nb_desired_values= estimation_rows_to_insert; + else /* go with the increasing defaults */ + { + /* avoid overflow in formula, with this if() */ + if (nb_already_reserved_intervals <= AUTO_INC_DEFAULT_NB_MAX_BITS) + { + nb_desired_values= AUTO_INC_DEFAULT_NB_VALUES * + (1 << nb_already_reserved_intervals); + set_if_smaller(nb_desired_values, AUTO_INC_DEFAULT_NB_MAX); + } + else + nb_desired_values= AUTO_INC_DEFAULT_NB_MAX; + } +#endif + /* This call ignores all its parameters but nr, currently */ + get_auto_increment(variables->auto_increment_offset, + variables->auto_increment_increment, + nb_desired_values, &nr, + &nb_reserved_values); + if (nr == ~(ulonglong) 0) result= 1; // Mark failure + /* + That should not be needed when engines actually use offset and increment + above. + */ if (variables->auto_increment_increment != 1) nr= next_insert_id(nr-1, variables); /* @@ -1715,7 +1734,28 @@ void handler::column_bitmaps_signal() } -ulonglong handler::get_auto_increment() +/* + Reserves an interval of auto_increment values from the handler. + + SYNOPSIS + get_auto_increment() + offset + increment + nb_desired_values how many values we want + first_value (OUT) the first value reserved by the handler + nb_reserved_values (OUT) how many values the handler reserved + + offset and increment means that we want values to be of the form + offset + N * increment, where N>=0 is integer. + If the function sets *first_value to ~(ulonglong)0 it means an error. + If the function sets *nb_reserved_values to ULONGLONG_MAX it means it has + reserved to "positive infinite". +*/ + +void handler::get_auto_increment(ulonglong offset, ulonglong increment, + ulonglong nb_desired_values, + ulonglong *first_value, + ulonglong *nb_reserved_values) { ulonglong nr; int error; @@ -1728,6 +1768,12 @@ ulonglong handler::get_auto_increment() if (!table->s->next_number_key_offset) { // Autoincrement at key-start error=index_last(table->record[1]); + /* + MySQL implicitely assumes such method does locking (as MySQL decides to + use nr+increment without checking again with the handler, in + handler::update_auto_increment()), so reserves to infinite. + */ + *nb_reserved_values= ULONGLONG_MAX; } else { @@ -1737,6 +1783,13 @@ ulonglong handler::get_auto_increment() table->s->next_number_key_offset); error= index_read(table->record[1], key, table->s->next_number_key_offset, HA_READ_PREFIX_LAST); + /* + MySQL needs to call us for next row: assume we are inserting ("a",null) + here, we return 3, and next this statement will want to insert + ("b",null): there is no reason why ("b",3+1) would be the good row to + insert: maybe it already exists, maybe 3+1 is too large... + */ + *nb_reserved_values= 1; } if (error) @@ -1746,7 +1799,25 @@ ulonglong handler::get_auto_increment() val_int_offset(table->s->rec_buff_length)+1); index_end(); (void) extra(HA_EXTRA_NO_KEYREAD); - return nr; + *first_value= nr; +} + + +void handler::print_keydup_error(uint key_nr, const char *msg) +{ + /* Write the duplicated key in the error message */ + char key[MAX_KEY_LENGTH]; + String str(key,sizeof(key),system_charset_info); + /* Table is opened and defined at this point */ + key_unpack(&str,table,(uint) key_nr); + uint max_length=MYSQL_ERRMSG_SIZE-(uint) strlen(msg); + if (str.length() >= max_length) + { + str.length(max_length-4); + str.append(STRING_WITH_LEN("...")); + } + my_printf_error(ER_DUP_ENTRY, msg, + MYF(0), str.c_ptr(), table->key_info[key_nr].name); } @@ -1789,20 +1860,7 @@ void handler::print_error(int error, myf errflag) uint key_nr=get_dup_key(error); if ((int) key_nr >= 0) { - uint max_length; - /* Write the duplicated key in the error message */ - char key[MAX_KEY_LENGTH]; - String str(key,sizeof(key),system_charset_info); - /* Table is opened and defined at this point */ - key_unpack(&str,table,(uint) key_nr); - max_length= MYSQL_ERRMSG_SIZE-(uint) strlen(ER(ER_DUP_ENTRY)); - if (str.length() >= max_length) - { - str.length(max_length-4); - str.append(STRING_WITH_LEN("...")); - } - my_error(ER_DUP_ENTRY, MYF(0), str.c_ptr(), - table->key_info[key_nr].name); + print_keydup_error(key_nr, ER(ER_DUP_ENTRY)); DBUG_VOID_RETURN; } textno=ER_DUP_KEY; @@ -2255,11 +2313,11 @@ void handler::get_dynamic_partition_info(PARTITION_INFO *stat_info, ****************************************************************************/ /* - Initiates table-file and calls apropriate database-creator + Initiates table-file and calls appropriate database-creator NOTES We must have a write lock on LOCK_open to be sure no other thread - interfers with table + interferes with table RETURN 0 ok @@ -2503,7 +2561,7 @@ int ha_discover(THD *thd, const char *db, const char *name, /* - Call this function in order to give the handler the possiblity + Call this function in order to give the handler the possibility to ask engine if there are any new tables that should be written to disk or any dropped tables that need to be removed from disk */ @@ -2572,7 +2630,7 @@ struct binlog_func_st static my_bool binlog_func_list(THD *thd, st_plugin_int *plugin, void *arg) { hton_list_st *hton_list= (hton_list_st *)arg; - handlerton *hton= (handlerton *) plugin->plugin->info; + handlerton *hton= (handlerton *)plugin->data; if (hton->state == SHOW_OPTION_YES && hton->binlog_func) { uint sz= hton_list->sz; @@ -2662,7 +2720,7 @@ static my_bool binlog_log_query_handlerton(THD *thd, st_plugin_int *plugin, void *args) { - return binlog_log_query_handlerton2(thd, (const handlerton *) plugin->plugin->info, args); + return binlog_log_query_handlerton2(thd, (const handlerton *)plugin->data, args); } void ha_binlog_log_query(THD *thd, const handlerton *hton, @@ -2946,7 +3004,7 @@ int handler::index_read_idx(byte * buf, uint index, const byte * key, SYNOPSIS ha_known_exts() - + NOTES No mutexes, worst case race is a minor surplus memory allocation We have to recreate the extension map if mysqld is restarted (for example @@ -2960,14 +3018,14 @@ 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; + handlerton *hton= (handlerton *)plugin->data; handler *file; if (hton->state == SHOW_OPTION_YES && hton->create && (file= hton->create((TABLE_SHARE*) 0, current_thd->mem_root))) { List_iterator_fast<char> it(*found_exts); const char **ext, *old_ext; - + for (ext= file->bas_ext(); *ext; ext++) { while ((old_ext= it++)) @@ -2996,14 +3054,14 @@ TYPELIB *ha_known_exts(void) known_extensions_id= mysys_usage_id; found_exts.push_back((char*) triggers_file_ext); found_exts.push_back((char*) trigname_file_ext); - - plugin_foreach(NULL, exts_handlerton, + + 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)); - + DBUG_ASSERT(ext != 0); known_extensions.count= found_exts.elements; known_extensions.type_names= ext; @@ -3036,7 +3094,7 @@ 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; + handlerton *hton= (handlerton *)plugin->data; if (hton->state == SHOW_OPTION_YES && hton->show_status && hton->show_status(thd, stat_print, stat)) return TRUE; @@ -3059,16 +3117,19 @@ bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat) if (db_type == NULL) { - result= plugin_foreach(thd, showstat_handlerton, + 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), + { + const LEX_STRING *name=&hton2plugin[db_type->slot]->name; + result= stat_print(thd, name->str, name->length, "", 0, "DISABLED", 8) ? 1 : 0; + } else - result= db_type->show_status && + result= db_type->show_status && db_type->show_status(thd, stat_print, stat) ? 1 : 0; } @@ -3280,6 +3341,7 @@ int handler::ha_delete_row(const byte *buf) } + /* use_hidden_primary_key() is called in case of an update/delete when (table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined @@ -3291,3 +3353,186 @@ void handler::use_hidden_primary_key() /* fallback to use all columns in the table to identify row */ table->use_all_columns(); } + + +/* + Dummy function which accept information about log files which is not need + by handlers +*/ + +void signal_log_not_needed(struct handlerton, char *log_file) +{ + DBUG_ENTER("signal_log_not_needed"); + DBUG_PRINT("enter", ("logfile '%s'", log_file)); + DBUG_VOID_RETURN; +} + + +#ifdef TRANS_LOG_MGM_EXAMPLE_CODE +/* + Example of transaction log management functions based on assumption that logs + placed into a directory +*/ +#include <my_dir.h> +#include <my_sys.h> +int example_of_iterator_using_for_logs_cleanup(handlerton *hton) +{ + void *buffer; + int res= 1; + struct handler_iterator iterator; + struct handler_log_file_data data; + + if (!hton->create_iterator) + return 1; /* iterator creator is not supported */ + + if ((*hton->create_iterator)(HA_TRANSACTLOG_ITERATOR, &iterator) != + HA_ITERATOR_OK) + { + /* error during creation of log iterator or iterator is not supported */ + return 1; + } + while((*iterator.next)(&iterator, (void*)&data) == 0) + { + printf("%s\n", data.filename.str); + if (data.status == HA_LOG_STATUS_FREE && + my_delete(data.filename.str, MYF(MY_WME))) + goto err; + } + res= 0; +err: + (*iterator.destroy)(&iterator); + return res; +} + + +/* + Here we should get info from handler where it save logs but here is + just example, so we use constant. + IMHO FN_ROOTDIR ("/") is safe enough for example, because nobody has + rights on it except root and it consist of directories only at lest for + *nix (sorry, can't find windows-safe solution here, but it is only example). +*/ +#define fl_dir FN_ROOTDIR + + +/* + Dummy function to return log status should be replaced by function which + really detect the log status and check that the file is a log of this + handler. +*/ + +enum log_status fl_get_log_status(char *log) +{ + MY_STAT stat_buff; + if (my_stat(log, &stat_buff, MYF(0))) + return HA_LOG_STATUS_INUSE; + return HA_LOG_STATUS_NOSUCHLOG; +} + + +struct fl_buff +{ + LEX_STRING *names; + enum log_status *statuses; + uint32 entries; + uint32 current; +}; + + +int fl_log_iterator_next(struct handler_iterator *iterator, + void *iterator_object) +{ + struct fl_buff *buff= (struct fl_buff *)iterator->buffer; + struct handler_log_file_data *data= + (struct handler_log_file_data *) iterator_object; + if (buff->current >= buff->entries) + return 1; + data->filename= buff->names[buff->current]; + data->status= buff->statuses[buff->current]; + buff->current++; + return 0; +} + + +void fl_log_iterator_destroy(struct handler_iterator *iterator) +{ + my_free((gptr)iterator->buffer, MYF(MY_ALLOW_ZERO_PTR)); +} + + +/* + returns buffer, to be assigned in handler_iterator struct +*/ +enum handler_create_iterator_result +fl_log_iterator_buffer_init(struct handler_iterator *iterator) +{ + MY_DIR *dirp; + struct fl_buff *buff; + char *name_ptr; + byte *ptr; + FILEINFO *file; + uint32 i; + + /* to be able to make my_free without crash in case of error */ + iterator->buffer= 0; + + if (!(dirp = my_dir(fl_dir, MYF(0)))) + { + return HA_ITERATOR_ERROR; + } + if ((ptr= (byte*)my_malloc(ALIGN_SIZE(sizeof(fl_buff)) + + ((ALIGN_SIZE(sizeof(LEX_STRING)) + + sizeof(enum log_status) + + + FN_REFLEN) * + (uint) dirp->number_off_files), + MYF(0))) == 0) + { + return HA_ITERATOR_ERROR; + } + buff= (struct fl_buff *)ptr; + buff->entries= buff->current= 0; + ptr= ptr + (ALIGN_SIZE(sizeof(fl_buff))); + buff->names= (LEX_STRING*) (ptr); + ptr= ptr + ((ALIGN_SIZE(sizeof(LEX_STRING)) * + (uint) dirp->number_off_files)); + buff->statuses= (enum log_status *)(ptr); + name_ptr= (char *)(ptr + (sizeof(enum log_status) * + (uint) dirp->number_off_files)); + for (i=0 ; i < (uint) dirp->number_off_files ; i++) + { + enum log_status st; + file= dirp->dir_entry + i; + if ((file->name[0] == '.' && + ((file->name[1] == '.' && file->name[2] == '\0') || + file->name[1] == '\0'))) + continue; + if ((st= fl_get_log_status(file->name)) == HA_LOG_STATUS_NOSUCHLOG) + continue; + name_ptr= strxnmov(buff->names[buff->entries].str= name_ptr, + FN_REFLEN, fl_dir, file->name, NullS); + buff->names[buff->entries].length= (name_ptr - + buff->names[buff->entries].str) - 1; + buff->statuses[buff->entries]= st; + buff->entries++; + } + + iterator->buffer= buff; + iterator->next= &fl_log_iterator_next; + iterator->destroy= &fl_log_iterator_destroy; + return HA_ITERATOR_OK; +} + + +/* An example of a iterator creator */ +enum handler_create_iterator_result +fl_create_iterator(enum handler_iterator_type type, + struct handler_iterator *iterator) +{ + switch(type) { + case HA_TRANSACTLOG_ITERATOR: + return fl_log_iterator_buffer_init(iterator); + default: + return HA_ITERATOR_UNSUPPORTED; + } +} +#endif /*TRANS_LOG_MGM_EXAMPLE_CODE*/ diff --git a/sql/handler.h b/sql/handler.h index 04b0086d58d..f459d52fdeb 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -195,6 +195,7 @@ so: innodb + bdb + ndb + binlog + myisam + myisammrg + archive + example + csv + heap + blackhole + federated + 0 (yes, the sum is deliberately inaccurate) + TODO remove the limit, use dynarrays */ #define MAX_HA 15 @@ -478,6 +479,73 @@ 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 }; +extern st_plugin_int *hton2plugin[MAX_HA]; + +/* Transaction log maintains type definitions */ +enum log_status +{ + HA_LOG_STATUS_FREE= 0, /* log is free and can be deleted */ + HA_LOG_STATUS_INUSE= 1, /* log can't be deleted because it is in use */ + HA_LOG_STATUS_NOSUCHLOG= 2 /* no such log (can't be returned by + the log iterator status) */ +}; +/* + Function for signaling that the log file changed its state from + LOG_STATUS_INUSE to LOG_STATUS_FREE + + Now it do nothing, will be implemented as part of new transaction + log management for engines. + TODO: implement the function. +*/ +void signal_log_not_needed(struct handlerton, char *log_file); +/* + Data of transaction log iterator. +*/ +struct handler_log_file_data { + LEX_STRING filename; + enum log_status status; +}; + + +enum handler_iterator_type +{ + /* request of transaction log iterator */ + HA_TRANSACTLOG_ITERATOR= 1 +}; +enum handler_create_iterator_result +{ + HA_ITERATOR_OK, /* iterator created */ + HA_ITERATOR_UNSUPPORTED, /* such type of iterator is not supported */ + HA_ITERATOR_ERROR /* error during iterator creation */ +}; + +/* + Iterator structure. Can be used by handler/handlerton for different purposes. + + Iterator should be created in the way to point "before" the first object + it iterate, so next() call move it to the first object or return !=0 if + there is nothing to iterate through. +*/ +struct handler_iterator { + /* + Moves iterator to next record and return 0 or return !=0 + if there is no records. + iterator_object will be filled by this function if next() returns 0. + Content of the iterator_object depend on iterator type. + */ + int (*next)(struct handler_iterator *, void *iterator_object); + /* + Free resources allocated by iterator, after this call iterator + is not usable. + */ + void (*destroy)(struct handler_iterator *); + /* + Pointer to buffer for the iterator to use. + Should be allocated by function which created the iterator and + destroied by freed by above "destroy" call + */ + void *buffer; +}; /* handlerton is a singleton structure - one instance per storage engine - @@ -493,38 +561,15 @@ enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX }; struct handlerton { /* - handlerton structure version - */ - const int interface_version; -/* last version change: 0x0001 in 5.1.6 */ -#define MYSQL_HANDLERTON_INTERFACE_VERSION 0x0001 - - - /* - storage engine name as it should be printed to a user - */ - const char *name; - - /* - Historical marker for if the engine is available of not + Historical marker for if the engine is available of not */ SHOW_COMP_OPTION state; /* - A comment used by SHOW to describe an engine. - */ - const char *comment; - - /* 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 legacy_db_type db_type; - /* - Method that initizlizes a storage engine - */ - bool (*init)(); - /* each storage engine has it's own memory area (actually a pointer) in the thd, for storing per-connection information. @@ -603,9 +648,24 @@ struct handlerton const char *query, uint query_length, const char *db, const char *table_name); int (*release_temporary_latches)(THD *thd); -}; -extern const handlerton default_hton; + /* + Get log status. + If log_status is null then the handler do not support transaction + log information (i.e. log iterator can't be created). + (see example of implementation in handler.cc, TRANS_LOG_MGM_EXAMPLE_CODE) + + */ + enum log_status (*get_log_status)(char *log); + + /* + Iterators creator. + Presence of the pointer should be checked before using + */ + enum handler_create_iterator_result + (*create_iterator)(enum handler_iterator_type type, + struct handler_iterator *fill_this_in); +}; struct show_table_alias_st { const char *alias; @@ -621,6 +681,7 @@ struct show_table_alias_st { #define HTON_FLUSH_AFTER_RENAME (1 << 4) #define HTON_NOT_USER_SELECTABLE (1 << 5) #define HTON_TEMPORARY_NOT_SUPPORTED (1 << 6) //Having temporary tables not supported +#define HTON_ALTER_CANNOT_CREATE (1 << 7) //Cannot use alter to create typedef struct st_thd_trans { @@ -818,6 +879,9 @@ class handler :public Sql_alloc virtual ulonglong table_flags(void) const =0; void ha_statistic_increment(ulong SSV::*offset) const; + ha_rows estimation_rows_to_insert; + virtual void start_bulk_insert(ha_rows rows) {} + virtual int end_bulk_insert() {return 0; } public: const handlerton *ht; /* storage engine of this handler */ byte *ref; /* Pointer to current row */ @@ -849,7 +913,7 @@ public: const COND *pushed_cond; handler(const handlerton *ht_arg, TABLE_SHARE *share_arg) - :table_share(share_arg), ht(ht_arg), + :table_share(share_arg), estimation_rows_to_insert(0), ht(ht_arg), ref(0), key_used_on_scan(MAX_KEY), active_index(MAX_KEY), ref_length(sizeof(my_off_t)), ft_handler(0), inited(NONE), implicit_emptied(0), @@ -893,6 +957,7 @@ public: } int ha_open(TABLE *table, const char *name, int mode, int test_if_locked); bool update_auto_increment(); + void print_keydup_error(uint key_nr, const char *msg); virtual void print_error(int error, myf errflag); virtual bool get_error_message(int error, String *buf); uint get_dup_key(int error); @@ -1166,7 +1231,11 @@ public: */ virtual int delete_all_rows() { return (my_errno=HA_ERR_WRONG_COMMAND); } - virtual ulonglong get_auto_increment(); + virtual void get_auto_increment(ulonglong offset, ulonglong increment, + ulonglong nb_desired_values, + ulonglong *first_value, + ulonglong *nb_reserved_values); + virtual void release_auto_increment() { return; }; virtual void restore_auto_increment(); /* @@ -1227,8 +1296,16 @@ public: virtual int disable_indexes(uint mode) { return HA_ERR_WRONG_COMMAND; } virtual int enable_indexes(uint mode) { return HA_ERR_WRONG_COMMAND; } virtual int indexes_are_disabled(void) {return 0;} - virtual void start_bulk_insert(ha_rows rows) {} - virtual int end_bulk_insert() {return 0; } + void ha_start_bulk_insert(ha_rows rows) + { + estimation_rows_to_insert= rows; + start_bulk_insert(rows); + } + int ha_end_bulk_insert() + { + estimation_rows_to_insert= 0; + return end_bulk_insert(); + } virtual int discard_or_import_tablespace(my_bool discard) {return HA_ERR_WRONG_COMMAND;} virtual int net_read_dump(NET* net) { return HA_ERR_WRONG_COMMAND; } @@ -1484,7 +1561,7 @@ static inline enum legacy_db_type ha_legacy_type(const handlerton *db_type) static inline const char *ha_resolve_storage_engine_name(const handlerton *db_type) { - return db_type == NULL ? "UNKNOWN" : db_type->name; + return db_type == NULL ? "UNKNOWN" : hton2plugin[db_type->slot]->name.str; } static inline bool ha_check_storage_engine_flag(const handlerton *db_type, uint32 flag) diff --git a/sql/item.cc b/sql/item.cc index b663018faac..5fa3ad61c15 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -304,6 +304,7 @@ Item::Item(): marker= 0; maybe_null=null_value=with_sum_func=unsigned_flag=0; decimals= 0; max_length= 0; + with_subselect= 0; /* Put item in free list so that we can free all items at end */ THD *thd= current_thd; @@ -989,6 +990,12 @@ void Item_splocal::print(String *str) } +bool Item_splocal::set_value(THD *thd, sp_rcontext *ctx, Item **it) +{ + return ctx->set_variable(thd, get_var_idx(), it); +} + + /***************************************************************************** Item_case_expr methods *****************************************************************************/ @@ -1918,7 +1925,6 @@ Item_decimal::Item_decimal(const char *str_arg, uint length, name= (char*) str_arg; decimals= (uint8) decimal_value.frac; fixed= 1; - unsigned_flag= !decimal_value.sign(); max_length= my_decimal_precision_to_length(decimal_value.intg + decimals, decimals, unsigned_flag); } @@ -1928,7 +1934,6 @@ Item_decimal::Item_decimal(longlong val, bool unsig) int2my_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value); decimals= (uint8) decimal_value.frac; fixed= 1; - unsigned_flag= !decimal_value.sign(); max_length= my_decimal_precision_to_length(decimal_value.intg + decimals, decimals, unsigned_flag); } @@ -1939,7 +1944,6 @@ Item_decimal::Item_decimal(double val, int precision, int scale) double2my_decimal(E_DEC_FATAL_ERROR, val, &decimal_value); decimals= (uint8) decimal_value.frac; fixed= 1; - unsigned_flag= !decimal_value.sign(); max_length= my_decimal_precision_to_length(decimal_value.intg + decimals, decimals, unsigned_flag); } @@ -1952,7 +1956,6 @@ Item_decimal::Item_decimal(const char *str, const my_decimal *val_arg, name= (char*) str; decimals= (uint8) decimal_par; max_length= length; - unsigned_flag= !decimal_value.sign(); fixed= 1; } @@ -1962,7 +1965,6 @@ Item_decimal::Item_decimal(my_decimal *value_par) my_decimal2decimal(value_par, &decimal_value); decimals= (uint8) decimal_value.frac; fixed= 1; - unsigned_flag= !decimal_value.sign(); max_length= my_decimal_precision_to_length(decimal_value.intg + decimals, decimals, unsigned_flag); } @@ -1974,7 +1976,6 @@ Item_decimal::Item_decimal(const char *bin, int precision, int scale) &decimal_value, precision, scale); decimals= (uint8) decimal_value.frac; fixed= 1; - unsigned_flag= !decimal_value.sign(); max_length= my_decimal_precision_to_length(precision, decimals, unsigned_flag); } @@ -4922,7 +4923,16 @@ void Item_ref::cleanup() void Item_ref::print(String *str) { if (ref) - (*ref)->print(str); + { + if ((*ref)->type() != Item::CACHE_ITEM && ref_type() != VIEW_REF && + name && alias_name_used) + { + THD *thd= current_thd; + append_identifier(thd, str, name, (uint) strlen(name)); + } + else + (*ref)->print(str); + } else Item_ident::print(str); } @@ -5454,6 +5464,25 @@ bool Item_trigger_field::eq(const Item *item, bool binary_cmp) const } +void Item_trigger_field::set_required_privilege(bool rw) +{ + /* + Require SELECT and UPDATE privilege if this field will be read and + set, and only UPDATE privilege for setting the field. + */ + want_privilege= (rw ? SELECT_ACL | UPDATE_ACL : UPDATE_ACL); +} + + +bool Item_trigger_field::set_value(THD *thd, sp_rcontext */*ctx*/, Item **it) +{ + Item *item= sp_prepare_func_item(thd, it); + + return (!item || (!fixed && fix_fields(thd, 0)) || + (item->save_in_field(field, 0) < 0)); +} + + bool Item_trigger_field::fix_fields(THD *thd, Item **items) { /* @@ -5476,8 +5505,7 @@ bool Item_trigger_field::fix_fields(THD *thd, Item **items) if (table_grants) { - table_grants->want_privilege= - access_type == AT_READ ? SELECT_ACL : UPDATE_ACL; + table_grants->want_privilege= want_privilege; if (check_grant_column(thd, table_grants, triggers->table->s->db.str, triggers->table->s->table_name.str, field_name, @@ -5509,6 +5537,7 @@ void Item_trigger_field::print(String *str) void Item_trigger_field::cleanup() { + want_privilege= original_privilege; /* Since special nature of Item_trigger_field we should not do most of things from Item_field::cleanup() or Item_ident::cleanup() here. diff --git a/sql/item.h b/sql/item.h index 64989725e31..54cab34eb78 100644 --- a/sql/item.h +++ b/sql/item.h @@ -401,6 +401,44 @@ typedef enum monotonicity_info /*************************************************************************/ +class sp_rcontext; + + +class Settable_routine_parameter +{ +public: + /* + Set required privileges for accessing the parameter. + + SYNOPSIS + set_required_privilege() + rw if 'rw' is true then we are going to read and set the + parameter, so SELECT and UPDATE privileges might be + required, otherwise we only reading it and SELECT + privilege might be required. + */ + Settable_routine_parameter() {} + virtual ~Settable_routine_parameter() {} + virtual void set_required_privilege(bool rw) {}; + + /* + Set parameter value. + + SYNOPSIS + set_value() + thd thread handle + ctx context to which parameter belongs (if it is local + variable). + it item which represents new value + + RETURN + FALSE if parameter value has been set, + TRUE if error has occured. + */ + virtual bool set_value(THD *thd, sp_rcontext *ctx, Item **it)= 0; +}; + + typedef bool (Item::*Item_processor)(byte *arg); typedef Item* (Item::*Item_transformer) (byte *arg); typedef void (*Cond_traverser) (const Item *item, void *arg); @@ -454,6 +492,9 @@ public: my_bool is_autogenerated_name; /* indicate was name of this Item autogenerated or set by user */ DTCollation collation; + my_bool with_subselect; /* If this item is a subselect or some + of its arguments is or contains a + subselect */ // alloc & destruct is done as start of select using sql_alloc Item(); @@ -744,6 +785,29 @@ public: virtual bool find_item_in_field_list_processor(byte *arg) { return 0; } virtual bool change_context_processor(byte *context) { return 0; } virtual bool register_field_in_read_map(byte *arg) { return 0; } + /* + Check if a partition function is allowed + SYNOPSIS + check_partition_func_processor() + bool_arg Return argument + RETURN VALUE + 0 + DESCRIPTION + check_partition_func_processor is used to check if a partition function + uses an allowed function. The default is that an item is not allowed + in a partition function. However all mathematical functions, string + manipulation functions, date functions are allowed. Allowed functions + can never depend on server version, they cannot depend on anything + related to the environment. They can also only depend on a set of + fields in the table itself. They cannot depend on other tables and + cannot contain any queries and cannot contain udf's or similar. + If a new Item class is defined and it inherits from a class that is + allowed in a partition function then it is very important to consider + whether this should be inherited to the new class. If not the function + below should be defined in the new Item class. + */ + virtual bool check_partition_func_processor(byte *bool_arg) + { *(bool *)bool_arg= FALSE; return 0; } virtual Item *equal_fields_propagator(byte * arg) { return this; } virtual Item *set_no_const_sub(byte *arg) { return this; } @@ -784,6 +848,15 @@ public: } virtual bool is_splocal() { return 0; } /* Needed for error checking */ + + /* + Return Settable_routine_parameter interface of the Item. Return 0 + if this Item is not Settable_routine_parameter. + */ + virtual Settable_routine_parameter *get_settable_routine_parameter() + { + return 0; + } }; @@ -882,7 +955,8 @@ inline bool Item_sp_variable::send(Protocol *protocol, String *str) runtime. *****************************************************************************/ -class Item_splocal :public Item_sp_variable +class Item_splocal :public Item_sp_variable, + private Settable_routine_parameter { uint m_var_idx; @@ -920,6 +994,15 @@ public: inline enum Type type() const; inline Item_result result_type() const; + +private: + bool set_value(THD *thd, sp_rcontext *ctx, Item **it); + +public: + Settable_routine_parameter *get_settable_routine_parameter() + { + return this; + } }; /***************************************************************************** @@ -1015,6 +1098,7 @@ public: Item::maybe_null= TRUE; } + bool check_partition_func_processor(byte *bool_arg) { return 0; } bool fix_fields(THD *, Item **); enum Type type() const; @@ -1061,6 +1145,7 @@ public: Item_num() {} /* Remove gcc warning */ virtual Item_num *neg()= 0; Item *safe_charset_converter(CHARSET_INFO *tocs); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; #define NO_CACHED_FIELD_INDEX ((uint)(-1)) @@ -1196,6 +1281,7 @@ public: bool collect_item_field_processor(byte * arg); bool find_item_in_field_list_processor(byte *arg); bool register_field_in_read_map(byte *arg); + bool check_partition_func_processor(byte *bool_arg) { return 0; } void cleanup(); Item_equal *find_item_equal(COND_EQUAL *cond_equal); Item *equal_fields_propagator(byte *arg); @@ -1239,6 +1325,7 @@ public: bool is_null() { return 1; } void print(String *str) { str->append(STRING_WITH_LEN("NULL")); } Item *safe_charset_converter(CHARSET_INFO *tocs); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_null_result :public Item_null @@ -1251,6 +1338,8 @@ public: { save_in_field(result_field, no_conversions); } + bool check_partition_func_processor(byte *bool_arg) + { *(bool *)bool_arg= FALSE; return 0; } }; /* Item represents one placeholder ('?') of prepared statement */ @@ -1541,6 +1630,8 @@ public: {} void print(String *str) { str->append(func_name); } Item *safe_charset_converter(CHARSET_INFO *tocs); + bool check_partition_func_processor(byte *bool_arg) + { *(bool *)bool_arg= FALSE; return 0; } }; @@ -1618,6 +1709,7 @@ public: void print(String *str); // to prevent drop fixed flag (no need parent cleanup call) void cleanup() {} + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -1632,6 +1724,8 @@ public: {} Item *safe_charset_converter(CHARSET_INFO *tocs); void print(String *str) { str->append(func_name); } + bool check_partition_func_processor(byte *bool_arg) + { *(bool *)bool_arg= FALSE; return 0; } }; @@ -1644,6 +1738,8 @@ public: &my_charset_bin) { max_length=19;} enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; } + bool check_partition_func_processor(byte *bool_arg) + { *(bool *)bool_arg= FALSE; return 0; } }; class Item_empty_string :public Item_string @@ -1666,6 +1762,8 @@ public: unsigned_flag=1; } enum_field_types field_type() const { return int_field_type; } + bool check_partition_func_processor(byte *bool_arg) + { *(bool *)bool_arg= FALSE; return 0; } }; @@ -1689,6 +1787,7 @@ public: void cleanup() {} bool eq(const Item *item, bool binary_cmp) const; virtual Item *safe_charset_converter(CHARSET_INFO *tocs); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -1911,6 +2010,8 @@ public: } Item *new_item(); virtual Item *real_item() { return ref; } + bool check_partition_func_processor(byte *bool_arg) + { *(bool *)bool_arg= FALSE; return 0; } }; #ifdef MYSQL_SERVER @@ -2140,14 +2241,13 @@ class Table_triggers_list; two Field instances representing either OLD or NEW version of this field. */ -class Item_trigger_field : public Item_field +class Item_trigger_field : public Item_field, + private Settable_routine_parameter { public: /* Is this item represents row from NEW or OLD row ? */ enum row_version_type {OLD_ROW, NEW_ROW}; row_version_type row_version; - /* Is this item used for reading or updating the value? */ - enum access_types { AT_READ = 0x1, AT_UPDATE = 0x2 }; /* Next in list of all Item_trigger_field's in trigger */ Item_trigger_field *next_trg_field; /* Index of the field in the TABLE::field array */ @@ -2158,11 +2258,11 @@ public: Item_trigger_field(Name_resolution_context *context_arg, row_version_type row_ver_arg, const char *field_name_arg, - access_types access_type_arg) + ulong priv, const bool ro) :Item_field(context_arg, (const char *)NULL, (const char *)NULL, field_name_arg), - row_version(row_ver_arg), field_idx((uint)-1), - access_type(access_type_arg), table_grants(NULL) + row_version(row_ver_arg), field_idx((uint)-1), original_privilege(priv), + want_privilege(priv), table_grants(NULL), read_only (ro) {} void setup_field(THD *thd, TABLE *table, GRANT_INFO *table_grant_info); enum Type type() const { return TRIGGER_FIELD_ITEM; } @@ -2173,8 +2273,39 @@ public: void cleanup(); private: - access_types access_type; + void set_required_privilege(bool rw); + bool set_value(THD *thd, sp_rcontext *ctx, Item **it); + +public: + Settable_routine_parameter *get_settable_routine_parameter() + { + return (read_only ? 0 : this); + } + + bool set_value(THD *thd, Item **it) + { + return set_value(thd, NULL, it); + } + +private: + /* + 'want_privilege' holds privileges required to perform operation on + this trigger field (SELECT_ACL if we are going to read it and + UPDATE_ACL if we are going to update it). It is initialized at + parse time but can be updated later if this trigger field is used + as OUT or INOUT parameter of stored routine (in this case + set_required_privilege() is called to appropriately update + want_privilege and cleanup() is responsible for restoring of + original want_privilege once parameter's value is updated). + */ + ulong original_privilege; + ulong want_privilege; GRANT_INFO *table_grants; + /* + Trigger field is read-only unless it belongs to the NEW row in a + BEFORE INSERT of BEFORE UPDATE trigger. + */ + bool read_only; }; @@ -2195,6 +2326,7 @@ public: max_length= item->max_length; decimals= item->decimals; collation.set(item->collation); + unsigned_flag= item->unsigned_flag; return 0; }; virtual void store(Item *)= 0; diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index ed08e413875..3a1f4b50458 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -204,10 +204,28 @@ longlong Item_func_nop_all::val_int() /* - Convert a constant expression or string to an integer. - This is done when comparing DATE's of different formats and - also when comparing bigint to strings (in which case the string - is converted once to a bigint). + Convert a constant item to an int and replace the original item + + SYNOPSIS + convert_constant_item() + thd thread handle + field item will be converted using the type of this field + item [in/out] reference to the item to convert + + DESCRIPTION + The function converts a constant expression or string to an integer. + On successful conversion the original item is substituted for the + result of the item evaluation. + This is done when comparing DATE/TIME of different formats and + also when comparing bigint to strings (in which case strings + are converted to bigints). + + NOTES + This function is called only at prepare stage. + As all derived tables are filled only after all derived tables + are prepared we do not evaluate items with subselects here because + they can contain derived tables and thus we may attempt to use a + table that has not been populated yet. RESULT VALUES 0 Can't convert item @@ -217,7 +235,7 @@ longlong Item_func_nop_all::val_int() static bool convert_constant_item(THD *thd, Field *field, Item **item) { int result= 0; - if ((*item)->const_item()) + if (!(*item)->with_subselect && (*item)->const_item()) { /* For comparison purposes allow invalid dates like 2000-01-32 */ TABLE *table= field->table; @@ -2578,7 +2596,9 @@ Item_cond::fix_fields(THD *thd, Item **ref) (item= *li.ref())->check_cols(1)) return TRUE; /* purecov: inspected */ used_tables_cache|= item->used_tables(); - if (!item->const_item()) + if (item->const_item()) + and_tables_cache= (table_map) 0; + else { tmp_table_map= item->not_null_tables(); not_null_tables_cache|= tmp_table_map; @@ -2586,6 +2606,7 @@ Item_cond::fix_fields(THD *thd, Item **ref) const_item_cache= FALSE; } with_sum_func= with_sum_func || item->with_sum_func; + with_subselect|= item->with_subselect; if (item->maybe_null) maybe_null=1; } diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index c0a76d6f1e7..8bd1b53e226 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -239,6 +239,7 @@ public: } Item *neg_transformer(THD *thd); virtual Item *negated_item(); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_not :public Item_bool_func @@ -249,6 +250,7 @@ public: enum Functype functype() const { return NOT_FUNC; } const char *func_name() const { return "not"; } Item *neg_transformer(THD *thd); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_maxmin_subselect; @@ -463,6 +465,7 @@ public: bool is_bool_func() { return 1; } CHARSET_INFO *compare_collation() { return cmp_collation.collation; } uint decimal_precision() const { return 1; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -474,6 +477,7 @@ public: optimize_type select_optimize() const { return OPTIMIZE_NONE; } const char *func_name() const { return "strcmp"; } void print(String *str) { Item_func::print(str); } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -536,6 +540,7 @@ public: const char *func_name() const { return "ifnull"; } Field *tmp_table_field(TABLE *table); uint decimal_precision() const; + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -576,6 +581,7 @@ public: void print(String *str) { Item_func::print(str); } table_map not_null_tables() const { return 0; } bool is_null(); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -618,6 +624,7 @@ public: void print(String *str); Item *find_item(String *str); CHARSET_INFO *compare_collation() { return cmp_collation.collation; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -968,6 +975,7 @@ public: bool nulls_in_row(); bool is_bool_func() { return 1; } CHARSET_INFO *compare_collation() { return cmp_collation.collation; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; /* Functions used by where clause */ @@ -1009,6 +1017,7 @@ public: optimize_type select_optimize() const { return OPTIMIZE_NULL; } Item *neg_transformer(THD *thd); CHARSET_INFO *compare_collation() { return args[0]->collation.collation; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; /* Functions used by HAVING for rewriting IN subquery */ @@ -1030,6 +1039,8 @@ public: */ table_map used_tables() const { return used_tables_cache | RAND_TABLE_BIT; } + bool check_partition_func_processor(byte *bool_arg) + { *(bool *)bool_arg= FALSE; return 0; } }; @@ -1052,6 +1063,7 @@ public: void print(String *str); CHARSET_INFO *compare_collation() { return args[0]->collation.collation; } void top_level_item() { abort_on_null=1; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -1090,6 +1102,7 @@ public: const char *func_name() const { return "like"; } bool fix_fields(THD *thd, Item **ref); void cleanup(); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; #ifdef USE_REGEX @@ -1112,6 +1125,7 @@ public: const char *func_name() const { return "regexp"; } void print(String *str) { print_op(str); } CHARSET_INFO *compare_collation() { return cmp_collation.collation; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; #else @@ -1168,6 +1182,7 @@ public: Item *transform(Item_transformer transformer, byte *arg); void traverse_cond(Cond_traverser, void *arg, traverse_order order); void neg_arguments(THD *thd); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; diff --git a/sql/item_func.cc b/sql/item_func.cc index 6bec261882f..3b633295f20 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -184,6 +184,7 @@ Item_func::fix_fields(THD *thd, Item **ref) used_tables_cache|= item->used_tables(); not_null_tables_cache|= item->not_null_tables(); const_item_cache&= item->const_item(); + with_subselect|= item->with_subselect; } } fix_length_and_dec(); @@ -2738,9 +2739,10 @@ String *udf_handler::val_str(String *str,String *save_str) { uchar is_null_tmp=0; ulong res_length; + DBUG_ENTER("udf_handler::val_str"); if (get_arguments()) - return 0; + DBUG_RETURN(0); char * (*func)(UDF_INIT *, UDF_ARGS *, char *, ulong *, uchar *, uchar *)= (char* (*)(UDF_INIT *, UDF_ARGS *, char *, ulong *, uchar *, uchar *)) u_d->func; @@ -2750,22 +2752,26 @@ String *udf_handler::val_str(String *str,String *save_str) if (str->alloc(MAX_FIELD_WIDTH)) { error=1; - return 0; + DBUG_RETURN(0); } } char *res=func(&initid, &f_args, (char*) str->ptr(), &res_length, &is_null_tmp, &error); + DBUG_PRINT("info", ("udf func returned, res_length: %lu", res_length)); if (is_null_tmp || !res || error) // The !res is for safety { - return 0; + DBUG_PRINT("info", ("Null or error")); + DBUG_RETURN(0); } if (res == str->ptr()) { str->length(res_length); - return str; + DBUG_PRINT("exit", ("str: %s", str->ptr())); + DBUG_RETURN(str); } save_str->set(res, res_length, str->charset()); - return save_str; + DBUG_PRINT("exit", ("save_str: %s", save_str->ptr())); + DBUG_RETURN(save_str); } @@ -3015,6 +3021,7 @@ void item_user_lock_free(void) void item_user_lock_release(User_level_lock *ull) { ull->locked=0; + ull->thread_id= 0; if (--ull->count) pthread_cond_signal(&ull->cond); else @@ -3222,6 +3229,7 @@ longlong Item_func_get_lock::val_int() { ull->locked=1; ull->thread=thd->real_id; + ull->thread_id= thd->thread_id; thd->ull=ull; error=0; } @@ -3948,14 +3956,24 @@ int get_var_with_binlog(THD *thd, enum_sql_command sql_command, sql_set_variables(), we could instead manually call check() and update(); this would save memory and time; but calling sql_set_variables() makes one unique place to maintain (sql_set_variables()). + + Manipulation with lex is necessary since free_underlaid_joins + is going to release memory belonging to the main query. */ List<set_var_base> tmp_var_list; + LEX *sav_lex= thd->lex, lex_tmp; + thd->lex= &lex_tmp; + lex_start(thd, NULL, 0); tmp_var_list.push_back(new set_var_user(new Item_func_set_user_var(name, new Item_null()))); /* Create the variable */ if (sql_set_variables(thd, &tmp_var_list)) + { + thd->lex= sav_lex; goto err; + } + thd->lex= sav_lex; if (!(var_entry= get_variable(&thd->user_vars, name, 0))) goto err; } @@ -4107,6 +4125,18 @@ bool Item_func_get_user_var::eq(const Item *item, bool binary_cmp) const } +bool Item_func_get_user_var::set_value(THD *thd, + sp_rcontext */*ctx*/, Item **it) +{ + Item_func_set_user_var *suv= new Item_func_set_user_var(get_name(), *it); + /* + Item_func_set_user_var is not fixed after construction, call + fix_fields(). + */ + return (!suv || suv->fix_fields(thd, it) || suv->check() || suv->update()); +} + + bool Item_user_var_as_out_param::fix_fields(THD *thd, Item **ref) { DBUG_ASSERT(fixed == 0); @@ -4739,6 +4769,7 @@ Item_func_sp::sp_result_field(void) const dummy_table->alias= empty_name; dummy_table->maybe_null= maybe_null; dummy_table->in_use= current_thd; + dummy_table->copy_blobs= TRUE; dummy_table->s->table_cache_key.str = empty_name; dummy_table->s->table_name.str= empty_name; dummy_table->s->db.str= empty_name; diff --git a/sql/item_func.h b/sql/item_func.h index 4ccffe461bb..0aedae73bdc 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -247,6 +247,7 @@ public: void fix_num_length_and_dec(); void find_num_type(); String *str_op(String *str) { DBUG_ASSERT(0); return 0; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -259,6 +260,7 @@ class Item_num_op :public Item_func_numhybrid void print(String *str) { print_op(str); } void find_num_type(); String *str_op(String *str) { DBUG_ASSERT(0); return 0; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -309,7 +311,7 @@ public: { max_length=args[0]->max_length; unsigned_flag=0; } void print(String *str); uint decimal_precision() const { return args[0]->decimal_precision(); } - + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -343,6 +345,7 @@ public: void fix_length_and_dec() {}; const char *func_name() const { return "decimal_typecast"; } void print(String *); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -411,6 +414,7 @@ public: const char *func_name() const { return "DIV"; } void fix_length_and_dec(); void print(String *str) { print_op(str); } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -483,6 +487,7 @@ public: Item_func_exp(Item *a) :Item_dec_func(a) {} double val_real(); const char *func_name() const { return "exp"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -492,6 +497,7 @@ public: Item_func_ln(Item *a) :Item_dec_func(a) {} double val_real(); const char *func_name() const { return "ln"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -502,6 +508,7 @@ public: Item_func_log(Item *a,Item *b) :Item_dec_func(a,b) {} double val_real(); const char *func_name() const { return "log"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -511,6 +518,7 @@ public: Item_func_log2(Item *a) :Item_dec_func(a) {} double val_real(); const char *func_name() const { return "log2"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -520,6 +528,7 @@ public: Item_func_log10(Item *a) :Item_dec_func(a) {} double val_real(); const char *func_name() const { return "log10"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -529,6 +538,7 @@ public: Item_func_sqrt(Item *a) :Item_dec_func(a) {} double val_real(); const char *func_name() const { return "sqrt"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -538,6 +548,7 @@ public: Item_func_pow(Item *a,Item *b) :Item_dec_func(a,b) {} double val_real(); const char *func_name() const { return "pow"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -547,6 +558,7 @@ public: Item_func_acos(Item *a) :Item_dec_func(a) {} double val_real(); const char *func_name() const { return "acos"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_asin :public Item_dec_func @@ -555,6 +567,7 @@ public: Item_func_asin(Item *a) :Item_dec_func(a) {} double val_real(); const char *func_name() const { return "asin"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_atan :public Item_dec_func @@ -564,6 +577,7 @@ public: Item_func_atan(Item *a,Item *b) :Item_dec_func(a,b) {} double val_real(); const char *func_name() const { return "atan"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_cos :public Item_dec_func @@ -572,6 +586,7 @@ public: Item_func_cos(Item *a) :Item_dec_func(a) {} double val_real(); const char *func_name() const { return "cos"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_sin :public Item_dec_func @@ -580,6 +595,7 @@ public: Item_func_sin(Item *a) :Item_dec_func(a) {} double val_real(); const char *func_name() const { return "sin"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_tan :public Item_dec_func @@ -588,6 +604,7 @@ public: Item_func_tan(Item *a) :Item_dec_func(a) {} double val_real(); const char *func_name() const { return "tan"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_integer :public Item_int_func @@ -664,6 +681,7 @@ public: Item_func_sign(Item *a) :Item_int_func(a) {} const char *func_name() const { return "sign"; } longlong val_int(); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -678,6 +696,7 @@ public: const char *func_name() const { return name; } void fix_length_and_dec() { decimals= NOT_FIXED_DEC; max_length= float_length(decimals); } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -695,6 +714,7 @@ public: my_decimal *val_decimal(my_decimal *); void fix_length_and_dec(); enum Item_result result_type () const { return cmp_type; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_min :public Item_func_min_max @@ -720,6 +740,7 @@ public: longlong val_int(); const char *func_name() const { return "length"; } void fix_length_and_dec() { max_length=10; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_bit_length :public Item_func_length @@ -739,6 +760,7 @@ public: longlong val_int(); const char *func_name() const { return "char_length"; } void fix_length_and_dec() { max_length=10; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_coercibility :public Item_int_func @@ -749,6 +771,7 @@ public: const char *func_name() const { return "coercibility"; } void fix_length_and_dec() { max_length=10; maybe_null= 0; } table_map not_null_tables() const { return 0; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_locate :public Item_int_func @@ -762,6 +785,7 @@ public: longlong val_int(); void fix_length_and_dec(); void print(String *str); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -786,6 +810,7 @@ public: longlong val_int(); const char *func_name() const { return "ascii"; } void fix_length_and_dec() { max_length=3; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_ord :public Item_int_func @@ -795,6 +820,7 @@ public: Item_func_ord(Item *a) :Item_int_func(a) {} longlong val_int(); const char *func_name() const { return "ord"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_find_in_set :public Item_int_func @@ -808,6 +834,7 @@ public: longlong val_int(); const char *func_name() const { return "find_in_set"; } void fix_length_and_dec(); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; /* Base class for all bit functions: '~', '|', '^', '&', '>>', '<<' */ @@ -819,6 +846,7 @@ public: Item_func_bit(Item *a) :Item_int_func(a) {} void fix_length_and_dec() { unsigned_flag= 1; } void print(String *str) { print_op(str); } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_bit_or :public Item_func_bit @@ -844,6 +872,7 @@ public: longlong val_int(); const char *func_name() const { return "bit_count"; } void fix_length_and_dec() { max_length=2; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_shift_left :public Item_func_bit @@ -1179,7 +1208,8 @@ public: }; -class Item_func_get_user_var :public Item_func +class Item_func_get_user_var :public Item_func, + private Settable_routine_parameter { user_var_entry *var_entry; @@ -1206,6 +1236,15 @@ public: table_map used_tables() const { return const_item() ? 0 : RAND_TABLE_BIT; } bool eq(const Item *item, bool binary_cmp) const; + +private: + bool set_value(THD *thd, sp_rcontext *ctx, Item **it); + +public: + Settable_routine_parameter *get_settable_routine_parameter() + { + return this; + } }; @@ -1270,6 +1309,7 @@ public: longlong val_int(); const char *func_name() const { return "inet_aton"; } void fix_length_and_dec() { decimals = 0; max_length = 21; maybe_null=1;} + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 1e483f32b02..eb1fbf4855d 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2579,7 +2579,7 @@ String *Item_load_file::val_str(String *str) (void) fn_format(path, file_name->c_ptr(), mysql_real_data_home, "", MY_RELATIVE_PATH | MY_UNPACK_FILENAME); - if (!my_stat(path, &stat_info, MYF(MY_WME))) + if (!my_stat(path, &stat_info, MYF(0))) goto err; if (!(stat_info.st_mode & S_IROTH)) diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 7b4b7fe8fa5..35d8ac1873b 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -47,6 +47,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "md5"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -57,6 +58,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "sha"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_aes_encrypt :public Item_str_func @@ -87,6 +89,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "concat"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_concat_ws :public Item_str_func @@ -107,6 +110,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "reverse"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -144,6 +148,7 @@ protected: public: Item_str_conv(Item *item) :Item_str_func(item) {} String *val_str(String *); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -207,6 +212,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "substr"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -218,6 +224,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "substring_index"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -232,6 +239,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "trim"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -411,6 +419,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "soundex"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -518,6 +527,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "rpad"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -530,6 +540,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "lpad"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -542,8 +553,9 @@ public: void fix_length_and_dec() { collation.set(default_charset()); - decimals=0; max_length=64; + max_length= 64; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -560,6 +572,7 @@ public: decimals=0; max_length=args[0]->max_length*2*collation.collation->mbmaxlen; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_unhex :public Item_str_func @@ -575,6 +588,7 @@ public: decimals=0; max_length=(1+args[0]->max_length)/2; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -598,6 +612,7 @@ public: } void print(String *str); const char *func_name() const { return "cast_as_binary"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -637,6 +652,7 @@ public: String* val_str(String* str); const char *func_name() const { return "inet_ntoa"; } void fix_length_and_dec() { decimals = 0; max_length=3*8+7; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_quote :public Item_str_func @@ -651,6 +667,7 @@ public: collation.set(args[0]->collation); max_length= args[0]->max_length * 2 + 2; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_conv_charset :public Item_str_func @@ -693,6 +710,7 @@ public: void fix_length_and_dec(); const char *func_name() const { return "convert"; } void print(String *str); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_set_collation :public Item_str_func @@ -725,6 +743,7 @@ public: maybe_null= 0; }; table_map not_null_tables() const { return 0; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_collation :public Item_str_func @@ -740,6 +759,7 @@ public: maybe_null= 0; }; table_map not_null_tables() const { return 0; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_crc32 :public Item_int_func @@ -750,6 +770,7 @@ public: const char *func_name() const { return "crc32"; } void fix_length_and_dec() { max_length=10; } longlong val_int(); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_uncompressed_length : public Item_int_func @@ -760,6 +781,7 @@ public: const char *func_name() const{return "uncompressed_length";} void fix_length_and_dec() { max_length=10; } longlong val_int(); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; #ifdef HAVE_COMPRESS @@ -776,6 +798,7 @@ public: void fix_length_and_dec(){max_length= (args[0]->max_length*120)/100+12;} const char *func_name() const{return "compress";} String *val_str(String *) ZLIB_DEPENDED_FUNCTION + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_uncompress: public Item_str_func @@ -786,6 +809,7 @@ public: void fix_length_and_dec(){max_length= MAX_BLOB_WIDTH;} const char *func_name() const{return "uncompress";} String *val_str(String *) ZLIB_DEPENDED_FUNCTION + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; #define UUID_LENGTH (8+1+4+1+4+1+4+1+12) diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index c3e826af27e..a08ac5d5f6a 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -39,6 +39,7 @@ Item_subselect::Item_subselect(): engine(0), old_engine(0), used_tables_cache(0), have_to_be_excluded(0), const_item_cache(1), engine_changed(0), changed(0) { + with_subselect= 1; reset(); /* item value is NULL if select_subselect not changed this value @@ -446,6 +447,7 @@ void Item_singlerow_subselect::fix_length_and_dec() engine->fix_length_and_dec(row); value= *row; } + unsigned_flag= value->unsigned_flag; /* If there are not tables in subquery then ability to have NULL value depends on SELECT list (if single row subquery have tables then it @@ -1394,6 +1396,17 @@ void Item_in_subselect::print(String *str) } +bool Item_in_subselect::fix_fields(THD *thd, Item **ref) +{ + bool result = 0; + + if(thd->lex->view_prepare_mode && left_expr && !left_expr->fixed) + result = left_expr->fix_fields(thd, &left_expr); + + return result || Item_subselect::fix_fields(thd, ref); +} + + Item_subselect::trans_res Item_allany_subselect::select_transformer(JOIN *join) { diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 16966718c2f..85bd7a1139d 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -259,6 +259,7 @@ public: void top_level_item() { abort_on_null=1; } bool test_limit(st_select_lex_unit *unit); void print(String *str); + bool fix_fields(THD *thd, Item **ref); friend class Item_ref_null_helper; friend class Item_is_not_null_test; diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 34e8b585dcc..a2c7af79ef3 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -631,7 +631,8 @@ bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time, case 'r': length= my_sprintf(intbuff, (intbuff, - (l_time->hour < 12) ? "%02d:%02d:%02d AM" : "%02d:%02d:%02d PM", + ((l_time->hour % 24) < 12) ? + "%02d:%02d:%02d AM" : "%02d:%02d:%02d PM", (l_time->hour+11)%12+1, l_time->minute, l_time->second)); @@ -869,9 +870,9 @@ String* Item_func_monthname::val_str(String* str) { DBUG_ASSERT(fixed == 1); const char *month_name; - uint month=(uint) Item_func_month::val_int(); + uint month= (uint) val_int(); - if (!month) // This is also true for NULL + if (null_value || !month) { null_value=1; return (String*) 0; @@ -1962,6 +1963,9 @@ bool Item_date_add_interval::get_date(TIME *ltime, uint fuzzy_date) if (date_sub_interval) interval.neg = !interval.neg; + if (ltime->year < YY_MAGIC_BELOW) + return (null_value=1); + return (null_value= date_add_interval(ltime, int_type, interval)); } @@ -2006,34 +2010,11 @@ longlong Item_date_add_interval::val_int() bool Item_date_add_interval::eq(const Item *item, bool binary_cmp) const { - INTERVAL interval, other_interval; - String val= value; // Because of const - - if (this == item) - return TRUE; - - if ((item->type() != FUNC_ITEM) || - (arg_count != ((Item_func*) item)->arg_count) || - (func_name() != ((Item_func*) item)->func_name())) - return FALSE; - Item_date_add_interval *other= (Item_date_add_interval*) item; - - if ((int_type != other->int_type) || - (!args[0]->eq(other->args[0], binary_cmp)) || - (get_interval_value(args[1], int_type, &val, &interval))) - return FALSE; - - val= other->value; - - if ((get_interval_value(other->args[1], other->int_type, &val, - &other_interval)) || - ((date_sub_interval ^ interval.neg) ^ - (other->date_sub_interval ^ other_interval.neg))) - return FALSE; - - // Assume comparing same types here due to earlier check - return memcmp(&interval, &other_interval, sizeof(INTERVAL)) == 0; + if (!Item_func::eq(item, binary_cmp)) + return 0; + return ((int_type == other->int_type) && + (date_sub_interval == other->date_sub_interval)); } diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index ae0ca1a0445..69c8ec5959a 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -39,6 +39,7 @@ public: { max_length=6*MY_CHARSET_BIN_MB_MAXLEN; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -53,6 +54,7 @@ public: decimals=0; max_length=6*MY_CHARSET_BIN_MB_MAXLEN; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -69,6 +71,7 @@ public: maybe_null=1; } enum_monotonicity_info get_monotonicity_info() const; + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -84,6 +87,7 @@ public: max_length=2*MY_CHARSET_BIN_MB_MAXLEN; maybe_null=1; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -108,6 +112,7 @@ public: max_length=2*MY_CHARSET_BIN_MB_MAXLEN; maybe_null=1; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -140,6 +145,7 @@ public: max_length=3*MY_CHARSET_BIN_MB_MAXLEN; maybe_null=1; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -155,6 +161,7 @@ public: max_length=2*MY_CHARSET_BIN_MB_MAXLEN; maybe_null=1; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -170,6 +177,7 @@ public: max_length=2*MY_CHARSET_BIN_MB_MAXLEN; maybe_null=1; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -185,6 +193,7 @@ public: max_length=1*MY_CHARSET_BIN_MB_MAXLEN; maybe_null=1; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -200,6 +209,7 @@ public: max_length=2*MY_CHARSET_BIN_MB_MAXLEN; maybe_null=1; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -215,6 +225,7 @@ public: max_length=2*MY_CHARSET_BIN_MB_MAXLEN; maybe_null=1; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_yearweek :public Item_int_func @@ -229,6 +240,7 @@ public: max_length=6*MY_CHARSET_BIN_MB_MAXLEN; maybe_null=1; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -245,6 +257,7 @@ public: max_length=4*MY_CHARSET_BIN_MB_MAXLEN; maybe_null=1; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -274,6 +287,7 @@ public: max_length=1*MY_CHARSET_BIN_MB_MAXLEN; maybe_null=1; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_dayname :public Item_func_weekday @@ -306,6 +320,7 @@ public: decimals=0; max_length=10*MY_CHARSET_BIN_MB_MAXLEN; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -320,6 +335,7 @@ public: decimals=0; max_length=10*MY_CHARSET_BIN_MB_MAXLEN; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -526,6 +542,7 @@ public: Item_func_from_days(Item *a) :Item_date(a) {} const char *func_name() const { return "from_days"; } bool get_date(TIME *res, uint fuzzy_date); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -543,6 +560,7 @@ public: void fix_length_and_dec(); uint format_length(const String *format); bool eq(const Item *item, bool binary_cmp) const; + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -561,6 +579,7 @@ class Item_func_from_unixtime :public Item_date_func const char *func_name() const { return "from_unixtime"; } void fix_length_and_dec(); bool get_date(TIME *res, uint fuzzy_date); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -627,6 +646,7 @@ public: { return tmp_table_field_from_field_type(table, 0); } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -649,6 +669,7 @@ public: bool get_date(TIME *res, uint fuzzy_date); bool eq(const Item *item, bool binary_cmp) const; void print(String *str); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -666,6 +687,7 @@ class Item_extract :public Item_int_func void fix_length_and_dec(); bool eq(const Item *item, bool binary_cmp) const; void print(String *str); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -702,6 +724,7 @@ public: max_length=args[0]->max_length; maybe_null= 1; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -721,6 +744,7 @@ public: String *val_str(String *a); void fix_length_and_dec(); void print(String *str); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -792,6 +816,7 @@ public: { return tmp_table_field_from_field_type(table, 0); } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -814,6 +839,7 @@ public: } void print(String *str); const char *func_name() const { return "add_time"; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_timediff :public Item_str_func @@ -853,6 +879,7 @@ public: { return tmp_table_field_from_field_type(table, 0); } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; class Item_func_microsecond :public Item_int_func @@ -866,6 +893,7 @@ public: decimals=0; maybe_null=1; } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -883,6 +911,7 @@ public: maybe_null=1; } void print(String *str); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; @@ -929,6 +958,7 @@ public: { return tmp_table_field_from_field_type(table, 1); } + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; diff --git a/sql/item_xmlfunc.h b/sql/item_xmlfunc.h index bc47e9c5bb1..e11b4eac1e2 100644 --- a/sql/item_xmlfunc.h +++ b/sql/item_xmlfunc.h @@ -42,6 +42,7 @@ public: Item_func_xml_extractvalue(Item *a,Item *b) :Item_xml_str_func(a,b) {} const char *func_name() const { return "extractvalue"; } String *val_str(String *); + bool check_partition_func_processor(byte *bool_arg) { return 0;} }; diff --git a/sql/lex.h b/sql/lex.h index 555a68dc388..67daf4566f8 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -133,6 +133,7 @@ static SYMBOL symbols[] = { { "CONSTRAINT", SYM(CONSTRAINT)}, { "CONTAINS", SYM(CONTAINS_SYM)}, { "CONTINUE", SYM(CONTINUE_SYM)}, + { "CONTRIBUTORS", SYM(CONTRIBUTORS_SYM)}, { "CONVERT", SYM(CONVERT_SYM)}, { "CREATE", SYM(CREATE)}, { "CROSS", SYM(CROSS)}, @@ -453,6 +454,7 @@ static SYMBOL symbols[] = { { "RTREE", SYM(RTREE_SYM)}, { "SAVEPOINT", SYM(SAVEPOINT_SYM)}, { "SCHEDULE", SYM(SCHEDULE_SYM)}, + { "SCHEDULER", SYM(SCHEDULER_SYM)}, { "SCHEMA", SYM(DATABASE)}, { "SCHEMAS", SYM(DATABASES)}, { "SECOND", SYM(SECOND_SYM)}, diff --git a/sql/lock.cc b/sql/lock.cc index 5a6cd58dd56..80861e3beb5 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -1174,16 +1174,17 @@ bool lock_global_read_lock(THD *thd) if (!thd->global_read_lock) { + const char *old_message; (void) pthread_mutex_lock(&LOCK_global_read_lock); - const char *old_message=thd->enter_cond(&COND_refresh, &LOCK_global_read_lock, - "Waiting to get readlock"); + old_message=thd->enter_cond(&COND_global_read_lock, &LOCK_global_read_lock, + "Waiting to get readlock"); DBUG_PRINT("info", ("waiting_for: %d protect_against: %d", waiting_for_read_lock, protect_against_global_read_lock)); waiting_for_read_lock++; while (protect_against_global_read_lock && !thd->killed) - pthread_cond_wait(&COND_refresh, &LOCK_global_read_lock); + pthread_cond_wait(&COND_global_read_lock, &LOCK_global_read_lock); waiting_for_read_lock--; if (thd->killed) { @@ -1205,9 +1206,15 @@ bool lock_global_read_lock(THD *thd) DBUG_RETURN(0); } + void unlock_global_read_lock(THD *thd) { uint tmp; + DBUG_ENTER("unlock_global_read_lock"); + DBUG_PRINT("info", + ("global_read_lock: %u global_read_lock_blocks_commit: %u", + global_read_lock, global_read_lock_blocks_commit)); + pthread_mutex_lock(&LOCK_global_read_lock); tmp= --global_read_lock; if (thd->global_read_lock == MADE_GLOBAL_READ_LOCK_BLOCK_COMMIT) @@ -1215,8 +1222,13 @@ void unlock_global_read_lock(THD *thd) pthread_mutex_unlock(&LOCK_global_read_lock); /* Send the signal outside the mutex to avoid a context switch */ if (!tmp) - pthread_cond_broadcast(&COND_refresh); + { + DBUG_PRINT("signal", ("Broadcasting COND_global_read_lock")); + pthread_cond_broadcast(&COND_global_read_lock); + } thd->global_read_lock= 0; + + DBUG_VOID_RETURN; } #define must_wait (global_read_lock && \ @@ -1254,11 +1266,15 @@ bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh, */ DBUG_RETURN(is_not_commit); } - old_message=thd->enter_cond(&COND_refresh, &LOCK_global_read_lock, + old_message=thd->enter_cond(&COND_global_read_lock, &LOCK_global_read_lock, "Waiting for release of readlock"); while (must_wait && ! thd->killed && (!abort_on_refresh || thd->version == refresh_version)) - (void) pthread_cond_wait(&COND_refresh,&LOCK_global_read_lock); + { + DBUG_PRINT("signal", ("Waiting for COND_global_read_lock")); + (void) pthread_cond_wait(&COND_global_read_lock, &LOCK_global_read_lock); + DBUG_PRINT("signal", ("Got COND_global_read_lock")); + } if (thd->killed) result=1; } @@ -1287,7 +1303,7 @@ void start_waiting_global_read_lock(THD *thd) (waiting_for_read_lock || global_read_lock_blocks_commit)); (void) pthread_mutex_unlock(&LOCK_global_read_lock); if (tmp) - pthread_cond_broadcast(&COND_refresh); + pthread_cond_broadcast(&COND_global_read_lock); DBUG_VOID_RETURN; } @@ -1309,10 +1325,10 @@ bool make_global_read_lock_block_commit(THD *thd) /* For testing we set up some blocking, to see if we can be killed */ DBUG_EXECUTE_IF("make_global_read_lock_block_commit_loop", protect_against_global_read_lock++;); - old_message= thd->enter_cond(&COND_refresh, &LOCK_global_read_lock, + old_message= thd->enter_cond(&COND_global_read_lock, &LOCK_global_read_lock, "Waiting for all running commits to finish"); while (protect_against_global_read_lock && !thd->killed) - pthread_cond_wait(&COND_refresh, &LOCK_global_read_lock); + pthread_cond_wait(&COND_global_read_lock, &LOCK_global_read_lock); DBUG_EXECUTE_IF("make_global_read_lock_block_commit_loop", protect_against_global_read_lock--;); if ((error= test(thd->killed))) diff --git a/sql/log.cc b/sql/log.cc index a90240ce19d..24d26662176 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -47,7 +47,7 @@ ulong sync_binlog_counter= 0; static bool test_if_number(const char *str, long *res, bool allow_wildcards); -static bool binlog_init(); +static int binlog_init(); static int binlog_close_connection(THD *thd); static int binlog_savepoint_set(THD *thd, void *sv); static int binlog_savepoint_rollback(THD *thd, void *sv); @@ -55,6 +55,14 @@ static int binlog_commit(THD *thd, bool all); static int binlog_rollback(THD *thd, bool all); static int binlog_prepare(THD *thd, bool all); +sql_print_message_func sql_print_message_handlers[3] = +{ + sql_print_information, + sql_print_warning, + sql_print_error +}; + + /* This is a POD. Please keep it that way! @@ -70,49 +78,7 @@ struct binlog_trx_data { Rows_log_event *pending; // The pending binrows event }; -static const char binlog_hton_name[]= "binlog"; -static const char binlog_hton_comment[]= - "This is a meta storage engine to represent the binlog in a transaction"; - -handlerton binlog_hton = { - MYSQL_HANDLERTON_INTERFACE_VERSION, - binlog_hton_name, - SHOW_OPTION_YES, - binlog_hton_comment, - DB_TYPE_BINLOG, /* IGNORE for now */ - binlog_init, - 0, - sizeof(my_off_t), /* savepoint size = binlog offset */ - binlog_close_connection, - binlog_savepoint_set, - binlog_savepoint_rollback, - NULL, /* savepoint_release */ - binlog_commit, - binlog_rollback, - binlog_prepare, - NULL, /* recover */ - NULL, /* commit_by_xid */ - NULL, /* rollback_by_xid */ - NULL, /* create_cursor_read_view */ - NULL, /* set_cursor_read_view */ - NULL, /* close_cursor_read_view */ - NULL, /* Create a new handler */ - NULL, /* Drop a database */ - NULL, /* Panic call */ - NULL, /* Start Consistent Snapshot */ - NULL, /* Flush logs */ - NULL, /* Show status */ - NULL, /* Partition flags */ - NULL, /* Alter table flags */ - NULL, /* Alter Tablespace */ - NULL, /* Fill FILES table */ - HTON_NOT_USER_SELECTABLE | HTON_HIDDEN, - NULL, /* binlog_func */ - NULL, /* binlog_log_query */ - NULL /* release_temporary_latches */ -}; - - +handlerton binlog_hton; /* Open log table of a given type (general or slow log) @@ -1060,9 +1026,20 @@ void Log_to_csv_event_handler:: should be moved here. */ -bool binlog_init() +int binlog_init() { - return !opt_bin_log; + + binlog_hton.state=opt_bin_log ? SHOW_OPTION_YES : SHOW_OPTION_NO; + binlog_hton.db_type=DB_TYPE_BINLOG; + binlog_hton.savepoint_offset= sizeof(my_off_t); + binlog_hton.close_connection= binlog_close_connection; + binlog_hton.savepoint_set= binlog_savepoint_set; + binlog_hton.savepoint_rollback= binlog_savepoint_rollback; + binlog_hton.commit= binlog_commit; + binlog_hton.rollback= binlog_rollback; + binlog_hton.prepare= binlog_prepare; + binlog_hton.flags= HTON_NOT_USER_SELECTABLE | HTON_HIDDEN; + return 0; } static int binlog_close_connection(THD *thd) @@ -1092,12 +1069,16 @@ binlog_end_trans(THD *thd, binlog_trx_data *trx_data, Log_event *end_ev) were, we would have to ensure that we're not ending a statement inside a stored function. */ +#ifdef HAVE_ROW_BASED_REPLICATION thd->binlog_flush_pending_rows_event(TRUE); +#endif error= mysql_bin_log.write(thd, trans_log, end_ev); } else { +#ifdef HAVE_ROW_BASED_REPLICATION thd->binlog_delete_pending_rows_event(); +#endif } /* @@ -2624,6 +2605,7 @@ bool MYSQL_LOG::is_query_in_union(THD *thd, query_id_t query_id_param) } +#ifdef HAVE_ROW_BASED_REPLICATION /* These functions are placed in this file since they need access to binlog_hton, which has internal linkage. @@ -2803,6 +2785,7 @@ int MYSQL_LOG::flush_and_set_pending_rows_event(THD *thd, Rows_log_event* event) DBUG_RETURN(error); } +#endif /*HAVE_ROW_BASED_REPLICATION*/ /* Write an event to the binary log @@ -2837,7 +2820,9 @@ bool MYSQL_LOG::write(Log_event *event_info) */ bool const end_stmt= thd->prelocked_mode && thd->lex->requires_prelocking(); +#ifdef HAVE_ROW_BASED_REPLICATION thd->binlog_flush_pending_rows_event(end_stmt); +#endif /*HAVE_ROW_BASED_REPLICATION*/ pthread_mutex_lock(&LOCK_log); @@ -2879,8 +2864,10 @@ bool MYSQL_LOG::write(Log_event *event_info) */ if (opt_using_transactions && thd) { +#ifdef HAVE_ROW_BASED_REPLICATION if (thd->binlog_setup_trx_data()) goto err; +#endif /*HAVE_ROW_BASED_REPLICATION*/ binlog_trx_data *const trx_data= (binlog_trx_data*) thd->ha_data[binlog_hton.slot]; @@ -2934,6 +2921,11 @@ bool MYSQL_LOG::write(Log_event *event_info) } if (thd->insert_id_used) { + /* + If the auto_increment was second in a table's index (possible with + MyISAM or BDB) (table->next_number_key_offset != 0), such event is + in fact not necessary. We could avoid logging it. + */ Intvar_log_event e(thd,(uchar) INSERT_ID_EVENT,thd->last_insert_id); if (e.write(file)) goto err; @@ -4360,15 +4352,17 @@ err1: return 1; } +struct st_mysql_storage_engine binlog_storage_engine= +{ MYSQL_HANDLERTON_INTERFACE_VERSION, &binlog_hton }; mysql_declare_plugin(binlog) { MYSQL_STORAGE_ENGINE_PLUGIN, - &binlog_hton, - binlog_hton_name, + &binlog_storage_engine, + "binlog", "MySQL AB", - binlog_hton_comment, - NULL, /* Plugin Init */ + "This is a pseudo storage engine to represent the binlog in a transaction", + binlog_init, /* Plugin Init */ NULL, /* Plugin Deinit */ 0x0100 /* 1.0 */, 0 diff --git a/sql/log_event.cc b/sql/log_event.cc index 79c7d394276..78ab54aeb79 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -3482,24 +3482,12 @@ int Rand_log_event::exec_event(struct st_relay_log_info* rli) Xid_log_event methods **************************************************************************/ -#if !defined(DBUG_OFF) && !defined(MYSQL_CLIENT) -/* - This static class member could be removed when mysqltest is made to support - a --replace-regex command: then tests which have XIDs in their output can - use this command to suppress non-deterministic XID values. -*/ -my_bool Xid_log_event::show_xid; -#endif - #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) void Xid_log_event::pack_info(Protocol *protocol) { char buf[128], *pos; pos= strmov(buf, "COMMIT /* xid="); -#if !defined(DBUG_OFF) && !defined(MYSQL_CLIENT) - if (show_xid) -#endif - pos= longlong10_to_str(xid, pos, 10); + pos= longlong10_to_str(xid, pos, 10); pos= strmov(pos, " */"); protocol->store(buf, (uint) (pos-buf), &my_charset_bin); } @@ -5352,6 +5340,7 @@ int Rows_log_event::exec_event(st_relay_log_info *rli) slave_print_msg(ERROR_LEVEL, rli, error, "Error in %s event: when locking tables", get_type_str()); + rli->clear_tables_to_lock(); DBUG_RETURN(error); } @@ -5387,6 +5376,7 @@ int Rows_log_event::exec_event(st_relay_log_info *rli) "unexpected success or fatal error")); thd->query_error= 1; } + rli->clear_tables_to_lock(); DBUG_RETURN(error); } } @@ -5395,19 +5385,17 @@ int Rows_log_event::exec_event(st_relay_log_info *rli) the table map and remove them from tables to lock. */ - TABLE_LIST *ptr= rli->tables_to_lock; - while (ptr) + TABLE_LIST *ptr; + for (ptr= rli->tables_to_lock ; ptr ; ptr= ptr->next_global) { rli->m_table_map.set_table(ptr->table_id, ptr->table); rli->touching_table(ptr->db, ptr->table_name, ptr->table_id); - char *to_free= reinterpret_cast<char*>(ptr); - ptr= ptr->next_global; - my_free(to_free, MYF(MY_WME)); } - rli->tables_to_lock= 0; - rli->tables_to_lock_count= 0; + rli->clear_tables_to_lock(); } + DBUG_ASSERT(rli->tables_to_lock == NULL && rli->tables_to_lock_count == 0); + TABLE* table= rli->m_table_map.get_table(m_table_id); if (table) @@ -5821,12 +5809,8 @@ int Table_map_log_event::exec_event(st_relay_log_info *rli) &tname_mem, NAME_LEN + 1, NULL); - /* - If memory is allocated, it the pointer to it should be stored in - table_list. If this is not true, the memory will not be correctly - free:ed later. - */ - DBUG_ASSERT(memory == NULL || memory == table_list); + if (memory == NULL) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); uint32 dummy_len; bzero(table_list, sizeof(*table_list)); @@ -5841,8 +5825,12 @@ int Table_map_log_event::exec_event(st_relay_log_info *rli) int error= 0; - if (rpl_filter->db_ok(table_list->db) && - (!rpl_filter->is_on() || rpl_filter->tables_ok("", table_list))) + if (!rpl_filter->db_ok(table_list->db) || + (rpl_filter->is_on() && !rpl_filter->tables_ok("", table_list))) + { + my_free((gptr) memory, MYF(MY_WME)); + } + else { /* Check if the slave is set to use SBR. If so, it should switch @@ -6147,7 +6135,7 @@ int Write_rows_log_event::do_before_row_operations(TABLE *table) how many rows are going to be inserted, then it can allocate needed memory from the start. */ - table->file->start_bulk_insert(0); + table->file->ha_start_bulk_insert(0); /* We need TIMESTAMP_NO_AUTO_SET otherwise ha_write_row() will not use fill any TIMESTAMP column with data from the row but instead will use @@ -6170,7 +6158,7 @@ int Write_rows_log_event::do_before_row_operations(TABLE *table) int Write_rows_log_event::do_after_row_operations(TABLE *table, int error) { if (error == 0) - error= table->file->end_bulk_insert(); + error= table->file->ha_end_bulk_insert(); return error; } @@ -6423,11 +6411,15 @@ static int find_and_fetch_row(TABLE *table, byte *key) if (table->s->keys > 0) { int error; + /* We have a key: search the table using the index */ + if (!table->file->inited && (error= table->file->ha_index_init(0, FALSE))) + return error; + /* - We need to set the null bytes to ensure that the filler bit - are all set when returning. There are storage engines that - just set the necessary bits on the bytes and don't set the - filler bits correctly. + We need to set the null bytes to ensure that the filler bit are + all set when returning. There are storage engines that just set + the necessary bits on the bytes and don't set the filler bits + correctly. */ my_ptrdiff_t const pos= table->s->null_bytes > 0 ? table->s->null_bytes - 1 : 0; @@ -6437,6 +6429,7 @@ static int find_and_fetch_row(TABLE *table, byte *key) HA_READ_KEY_EXACT))) { table->file->print_error(error, MYF(0)); + table->file->ha_index_end(); DBUG_RETURN(error); } @@ -6455,7 +6448,10 @@ static int find_and_fetch_row(TABLE *table, byte *key) chose the row to change only using a PK or an UNNI. */ if (table->key_info->flags & HA_NOSAME) + { + table->file->ha_index_end(); DBUG_RETURN(0); + } while (record_compare(table)) { @@ -6472,15 +6468,26 @@ static int find_and_fetch_row(TABLE *table, byte *key) if ((error= table->file->index_next(table->record[1]))) { table->file->print_error(error, MYF(0)); + table->file->ha_index_end(); DBUG_RETURN(error); } } + + /* + Have to restart the scan to be able to fetch the next row. + */ + table->file->ha_index_end(); } else { - /* Continue until we find the right record or have made a full loop */ int restart_count= 0; // Number of times scanning has restarted from top - int error= 0; + int error; + + /* We don't have a key: search the table using rnd_next() */ + if ((error= table->file->ha_rnd_init(1))) + return error; + + /* Continue until we find the right record or have made a full loop */ do { /* @@ -6506,11 +6513,17 @@ static int find_and_fetch_row(TABLE *table, byte *key) default: table->file->print_error(error, MYF(0)); + table->file->ha_rnd_end(); DBUG_RETURN(error); } } while (restart_count < 2 && record_compare(table)); + /* + Have to restart the scan to be able to fetch the next row. + */ + table->file->ha_rnd_end(); + DBUG_ASSERT(error == HA_ERR_END_OF_FILE || error == 0); DBUG_RETURN(error); } @@ -6634,34 +6647,15 @@ int Delete_rows_log_event::do_exec_row(TABLE *table) int error; DBUG_ASSERT(table != NULL); - if (table->s->keys > 0) - { - /* We have a key: search the table using the index */ - if (!table->file->inited && (error= table->file->ha_index_init(0, FALSE))) - return error; - } - else - { - /* We doesn't have a key: search the table using rnd_next() */ - if ((error= table->file->ha_rnd_init(1))) - return error; + if (!(error= find_and_fetch_row(table, m_key))) + { + /* + Now we should have the right row to delete. We are using + record[0] since it is guaranteed to point to a record with the + correct value. + */ + error= table->file->ha_delete_row(table->record[0]); } - - if ((error= find_and_fetch_row(table, m_key))) - return error; - - /* - Now we should have the right row to delete. We are using - record[0] since it is guaranteed to point to a record with the - correct value. - */ - error= table->file->ha_delete_row(table->record[0]); - - /* - Have to restart the scan to be able to fetch the next row. - */ - table->file->ha_index_or_rnd_end(); - return error; } @@ -6742,17 +6736,6 @@ int Update_rows_log_event::do_before_row_operations(TABLE *table) if (!m_memory) return HA_ERR_OUT_OF_MEM; - if (table->s->keys > 0) - { - /* We have a key: search the table using the index */ - if (!table->file->inited) - error= table->file->ha_index_init(0, FALSE); - } - else - { - /* We doesn't have a key: search the table using rnd_next() */ - error= table->file->ha_rnd_init(1); - } table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET; return error; diff --git a/sql/log_event.h b/sql/log_event.h index b24686514e3..36933f4a7dd 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -1221,9 +1221,6 @@ class Xid_log_event: public Log_event bool write(IO_CACHE* file); #endif bool is_valid() const { return 1; } -#if !defined(DBUG_OFF) && !defined(MYSQL_CLIENT) - static my_bool show_xid; -#endif }; /***************************************************************************** @@ -1635,6 +1632,8 @@ public: #endif char *str_to_hex(char *to, const char *from, uint len); +#ifdef HAVE_ROW_BASED_REPLICATION + /***************************************************************************** Table map log event class @@ -1643,7 +1642,6 @@ char *str_to_hex(char *to, const char *from, uint len); identifier (an integer number). ****************************************************************************/ - class Table_map_log_event : public Log_event { public: @@ -1750,6 +1748,7 @@ private: ****************************************************************************/ + class Rows_log_event : public Log_event { public: @@ -2121,5 +2120,6 @@ private: #endif }; +#endif /* HAVE_ROW_BASED_REPLICATION */ #endif /* _log_event_h */ diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 7789df0da3d..76d8aa18f59 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -79,7 +79,8 @@ char *sql_strmake_with_convert(const char *str, uint32 arg_length, CHARSET_INFO *from_cs, uint32 max_res_length, CHARSET_INFO *to_cs, uint32 *result_length); -void kill_one_thread(THD *thd, ulong id, bool only_kill_query); +uint kill_one_thread(THD *thd, ulong id, bool only_kill_query); +void sql_kill(THD *thd, ulong id, bool only_kill_query); bool net_request_file(NET* net, const char* fname); char* query_table_status(THD *thd,const char *db,const char *table_name); @@ -488,6 +489,7 @@ inline THD *_current_thd(void) my_bool thd_in_lock_tables(const THD *thd); my_bool thd_tablespace_op(const THD *thd); const char *thd_proc_info(THD *thd, const char *info); +void **thd_ha_data(const THD *thd, const struct handlerton *hton); /* External variables @@ -502,13 +504,13 @@ typedef my_bool (*qc_engine_callback)(THD *thd, char *table_key, #include "sql_list.h" #include "sql_map.h" #include "my_decimal.h" +#include "sql_plugin.h" #include "handler.h" #include "parse_file.h" #include "table.h" #include "sql_error.h" #include "field.h" /* Field definitions */ #include "protocol.h" -#include "sql_plugin.h" #include "sql_udf.h" #include "sql_partition.h" @@ -847,6 +849,7 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *t); bool mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *t); Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, Item ***copy_func, Field **from_field, + Field **def_field, bool group, bool modify_item, bool table_cant_handle_bit_fields, bool make_copy_field, @@ -861,13 +864,6 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, List<create_field> &fields, List<Key> &keys, bool tmp_table, uint select_field_count); -TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, - TABLE_LIST *create_table, - List<create_field> *extra_fields, - List<Key> *keys, - List<Item> *items, - MYSQL_LOCK **lock, - TABLEOP_HOOKS *hooks); bool mysql_alter_table(THD *thd, char *new_db, char *new_name, HA_CREATE_INFO *create_info, TABLE_LIST *table_list, @@ -1005,6 +1001,7 @@ int mysql_find_files(THD *thd,List<char> *files, const char *db, const char *path, const char *wild, bool dir); bool mysqld_show_storage_engines(THD *thd); bool mysqld_show_authors(THD *thd); +bool mysqld_show_contributors(THD *thd); bool mysqld_show_privileges(THD *thd); bool mysqld_show_column_types(THD *thd); bool mysqld_help (THD *thd, const char *text); @@ -1110,6 +1107,13 @@ bool insert_fields(THD *thd, Name_resolution_context *context, bool setup_tables(THD *thd, Name_resolution_context *context, List<TABLE_LIST> *from_clause, TABLE_LIST *tables, TABLE_LIST **leaves, bool select_insert); +bool setup_tables_and_check_access(THD *thd, + Name_resolution_context *context, + List<TABLE_LIST> *from_clause, + TABLE_LIST *tables, + TABLE_LIST **leaves, + bool select_insert, + ulong want_access); int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields, List<Item> *sum_func_list, uint wild_num); bool setup_fields(THD *thd, Item** ref_pointer_array, @@ -1386,10 +1390,13 @@ bool init_errmessage(void); #endif /* MYSQL_SERVER */ void sql_perror(const char *message); + int vprint_msg_to_log(enum loglevel level, const char *format, va_list args); void sql_print_error(const char *format, ...); void sql_print_warning(const char *format, ...); void sql_print_information(const char *format, ...); +typedef void (*sql_print_message_func)(const char *format, ...); +extern sql_print_message_func sql_print_message_handlers[]; /* type of the log table */ #define QUERY_LOG_SLOW 1 @@ -1506,6 +1513,7 @@ extern my_bool locked_in_memory; extern bool opt_using_transactions, mysqld_embedded; extern bool using_update_log, opt_large_files, server_id_supplied; extern bool opt_log, opt_update_log, opt_bin_log, opt_slow_log, opt_error_log; +extern my_bool opt_log_queries_not_using_indexes; extern bool opt_disable_networking, opt_skip_show_db; extern my_bool opt_character_set_client_handshake; extern bool volatile abort_loop, shutdown_in_progress, grant_option; @@ -1550,6 +1558,7 @@ extern pthread_cond_t COND_server_started; extern int mysqld_server_started; extern rw_lock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave; extern pthread_cond_t COND_refresh, COND_thread_count, COND_manager; +extern pthread_cond_t COND_global_read_lock; extern pthread_attr_t connection_attrib; extern I_List<THD> threads; extern I_List<NAMED_LIST> key_caches; @@ -1645,15 +1654,16 @@ extern pthread_t signal_thread; #endif #ifdef HAVE_OPENSSL -extern struct st_VioSSLAcceptorFd * ssl_acceptor_fd; +extern struct st_VioSSLFd * ssl_acceptor_fd; #endif /* HAVE_OPENSSL */ MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **table, uint count, uint flags, bool *need_reopen); -/* mysql_lock_tables() flags bits */ +/* mysql_lock_tables() and open_table() flags bits */ #define MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK 0x0001 #define MYSQL_LOCK_IGNORE_FLUSH 0x0002 #define MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN 0x0004 +#define MYSQL_OPEN_IGNORE_LOCKED_TABLES 0x0008 void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock); void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock); @@ -1944,7 +1954,6 @@ inline int hexchar_to_int(char c) return -1; } - /* Some functions that are different in the embedded library and the normal server diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 7f57b3fc425..876485ef35c 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -318,7 +318,6 @@ static bool volatile ready_to_exit; static my_bool opt_debugging= 0, opt_external_locking= 0, opt_console= 0; static my_bool opt_bdb, opt_isam, opt_ndbcluster; static my_bool opt_short_log_format= 0; -static my_bool opt_log_queries_not_using_indexes= 0; static uint kill_cached_threads, wake_thread; static ulong killed_threads, thread_created; static ulong max_used_connections; @@ -330,7 +329,7 @@ static char *opt_init_slave, *language_ptr, *opt_init_connect; static char *default_character_set_name; static char *character_set_filesystem_name; static char *my_bind_addr_str; -static char *default_collation_name; +static char *default_collation_name, *default_storage_engine_str; static char mysql_data_home_buff[2]; static struct passwd *user_info; static I_List<THD> thread_cache; @@ -344,6 +343,7 @@ static my_bool opt_sync_bdb_logs; /* Global variables */ bool opt_log, opt_update_log, opt_bin_log, opt_slow_log; +my_bool opt_log_queries_not_using_indexes= 0; bool opt_error_log= IF_WIN(1,0); bool opt_disable_networking=0, opt_skip_show_db=0; my_bool opt_character_set_client_handshake= 1; @@ -605,7 +605,7 @@ pthread_mutex_t LOCK_prepared_stmt_count; pthread_mutex_t LOCK_des_key_file; #endif rw_lock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave; -pthread_cond_t COND_refresh,COND_thread_count; +pthread_cond_t COND_refresh, COND_thread_count, COND_global_read_lock; pthread_t signal_thread; pthread_attr_t connection_attrib; pthread_mutex_t LOCK_server_started; @@ -693,6 +693,7 @@ my_bool opt_enable_shared_memory; HANDLE smem_event_connect_request= 0; #endif +#define SSL_VARS_NOT_STATIC #include "sslopt-vars.h" #ifdef HAVE_OPENSSL #include <openssl/crypto.h> @@ -710,7 +711,7 @@ static void openssl_lock(int, openssl_lock_t *, const char *, int); static unsigned long openssl_id_function(); #endif char *des_key_file; -struct st_VioSSLAcceptorFd *ssl_acceptor_fd; +struct st_VioSSLFd *ssl_acceptor_fd; #endif /* HAVE_OPENSSL */ @@ -863,8 +864,8 @@ static void close_connections(void) { DBUG_PRINT("quit",("Informing thread %ld that it's time to die", tmp->thread_id)); - /* We skip slave threads on this first loop through. */ - if (tmp->slave_thread) + /* We skip slave threads & scheduler on this first loop through. */ + if (tmp->slave_thread || tmp->system_thread == SYSTEM_THREAD_EVENT_SCHEDULER) continue; tmp->killed= THD::KILL_CONNECTION; @@ -883,6 +884,7 @@ static void close_connections(void) } (void) pthread_mutex_unlock(&LOCK_thread_count); // For unlink from list + Events::shutdown(); end_slave(); if (thread_count) @@ -1022,7 +1024,20 @@ void kill_mysql(void) DBUG_VOID_RETURN; } - /* Force server down. kill all connections and threads and exit */ +/* + Force server down. Kill all connections and threads and exit + + SYNOPSIS + kill_server + + sig_ptr Signal number that caused kill_server to be called. + + NOTE! + A signal number of 0 mean that the function was not called + from a signal handler and there is thus no signal to block + or stop, we just want to kill the server. + +*/ #if defined(__NETWARE__) extern "C" void kill_server(int sig_ptr) @@ -1043,7 +1058,8 @@ static void __cdecl kill_server(int sig_ptr) RETURN_FROM_KILL_SERVER; kill_in_progress=TRUE; abort_loop=1; // This should be set - my_sigset(sig,SIG_IGN); + if (sig != 0) // 0 is not a valid signal number + my_sigset(sig,SIG_IGN); if (sig == MYSQL_KILL_SIGNAL || sig == 0) sql_print_information(ER(ER_NORMAL_SHUTDOWN),my_progname); else @@ -1075,6 +1091,10 @@ static void __cdecl kill_server(int sig_ptr) pthread_join(select_thread, NULL); // wait for main thread #endif /* __NETWARE__ */ +#if defined(__NETWARE__) || (defined(USE_ONE_SIGNAL_HAND) && !defined(__WIN__) && !defined(OS2)) + my_thread_end(); +#endif + pthread_exit(0); /* purecov: deadcode */ #endif /* EMBEDDED_LIBRARY */ @@ -1219,6 +1239,7 @@ void clean_up(bool print_message) delete binlog_filter; delete rpl_filter; end_ssl(); + vio_end(); #ifdef USE_REGEX my_regex_end(); #endif @@ -1292,6 +1313,7 @@ static void clean_up_mutexes() (void) pthread_mutex_destroy(&LOCK_bytes_sent); (void) pthread_mutex_destroy(&LOCK_bytes_received); (void) pthread_mutex_destroy(&LOCK_user_conn); + Events::destroy_mutexes(); #ifdef HAVE_OPENSSL (void) pthread_mutex_destroy(&LOCK_des_key_file); #ifndef HAVE_YASSL @@ -1313,6 +1335,7 @@ static void clean_up_mutexes() (void) pthread_mutex_destroy(&LOCK_prepared_stmt_count); (void) pthread_cond_destroy(&COND_thread_count); (void) pthread_cond_destroy(&COND_refresh); + (void) pthread_cond_destroy(&COND_global_read_lock); (void) pthread_cond_destroy(&COND_thread_cache); (void) pthread_cond_destroy(&COND_flush_thread_cache); (void) pthread_cond_destroy(&COND_manager); @@ -1735,13 +1758,11 @@ void end_thread(THD *thd, bool put_in_cache) } } - DBUG_PRINT("info", ("sending a broadcast")); - /* Tell main we are ready */ (void) pthread_mutex_unlock(&LOCK_thread_count); /* It's safe to broadcast outside a lock (COND... is not deleted here) */ + DBUG_PRINT("signal", ("Broadcasting COND_thread_count")); (void) pthread_cond_broadcast(&COND_thread_count); - DBUG_PRINT("info", ("unlocked thread_count mutex")); #ifdef ONE_THREAD if (!(test_flags & TEST_NO_THREADS)) // For debugging under Linux #endif @@ -2631,12 +2652,6 @@ static int init_common_variables(const char *conf_file_name, int argc, if (add_status_vars(status_vars)) return 1; // an error was already reported - if (plugin_init()) - { - sql_print_error("Failed to init plugins."); - return 1; - } - load_defaults(conf_file_name, groups, &argc, &argv); defaults_argv=argv; get_options(argc,argv); @@ -2839,6 +2854,7 @@ static int init_thread_environment() (void) my_rwlock_init(&LOCK_grant, NULL); (void) pthread_cond_init(&COND_thread_count,NULL); (void) pthread_cond_init(&COND_refresh,NULL); + (void) pthread_cond_init(&COND_global_read_lock,NULL); (void) pthread_cond_init(&COND_thread_cache,NULL); (void) pthread_cond_init(&COND_flush_thread_cache,NULL); (void) pthread_cond_init(&COND_manager,NULL); @@ -2849,6 +2865,7 @@ static int init_thread_environment() (void) pthread_mutex_init(&LOCK_server_started, MY_MUTEX_INIT_FAST); (void) pthread_cond_init(&COND_server_started,NULL); sp_cache_init(); + Events::init_mutexes(); /* Parameter for threads created for connections */ (void) pthread_attr_init(&connection_attrib); (void) pthread_attr_setdetachstate(&connection_attrib, @@ -2994,7 +3011,6 @@ static int init_server_components() #ifdef HAVE_REPLICATION init_slave_list(); #endif - init_events(); /* Setup logs */ @@ -3092,7 +3108,7 @@ with --log-bin instead."); } if (global_system_variables.binlog_format == BINLOG_FORMAT_UNSPEC) { -#ifdef HAVE_NDB_BINLOG +#if defined(HAVE_NDB_BINLOG) && defined(HAVE_ROW_BASED_REPLICATION) if (opt_bin_log && have_ndbcluster == SHOW_OPTION_YES) global_system_variables.binlog_format= BINLOG_FORMAT_ROW; else @@ -3152,6 +3168,12 @@ server."); using_update_log=1; } + if (plugin_init()) + { + sql_print_error("Failed to init plugins."); + return 1; + } + /* We have to initialize the storage engines before CSV logging */ if (ha_init()) { @@ -3198,15 +3220,27 @@ server."); /* Check that the default storage engine is actually available. */ - if (!ha_storage_engine_is_enabled(global_system_variables.table_type)) { - if (!opt_bootstrap) + LEX_STRING name= { default_storage_engine_str, + strlen(default_storage_engine_str) }; + handlerton *hton= ha_resolve_by_name(0, &name); + if (hton == NULL) { - sql_print_error("Default storage engine (%s) is not available", - global_system_variables.table_type->name); + sql_print_error("Unknown/unsupported table type: %s", + default_storage_engine_str); unireg_abort(1); } - global_system_variables.table_type= &myisam_hton; + if (!ha_storage_engine_is_enabled(hton)) + { + if (!opt_bootstrap) + { + sql_print_error("Default storage engine (%s) is not available", + default_storage_engine_str); + unireg_abort(1); + } + hton= &myisam_hton; + } + global_system_variables.table_type= hton; } tc_log= (total_ha_2pc > 1 ? (opt_bin_log ? @@ -3618,6 +3652,10 @@ we force server id to 2, but this MySQL server will not act as a slave."); mysqld_server_started= 1; pthread_cond_signal(&COND_server_started); + if (!opt_noacl) + { + Events::init(); + } #if defined(__NT__) || defined(HAVE_SMEM) handle_connections_methods(); #else @@ -3669,7 +3707,6 @@ we force server id to 2, but this MySQL server will not act as a slave."); clean_up(1); wait_for_signal_thread_to_end(); clean_up_mutexes(); - shutdown_events(); my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); exit(0); @@ -4660,7 +4697,7 @@ enum options_mysqld OPT_MAX_BINLOG_DUMP_EVENTS, OPT_SPORADIC_BINLOG_DUMP_FAIL, OPT_SAFE_USER_CREATE, OPT_SQL_MODE, OPT_HAVE_NAMED_PIPE, - OPT_DO_PSTACK, OPT_EVENT_EXECUTOR, OPT_REPORT_HOST, + OPT_DO_PSTACK, OPT_EVENT_SCHEDULER, OPT_REPORT_HOST, OPT_REPORT_USER, OPT_REPORT_PASSWORD, OPT_REPORT_PORT, OPT_SHOW_SLAVE_AUTH_INFO, OPT_SLAVE_LOAD_TMPDIR, OPT_NO_MIX_TYPE, @@ -4878,14 +4915,6 @@ Disable with --skip-bdb (will save memory).", {"binlog-ignore-db", OPT_BINLOG_IGNORE_DB, "Tells the master that updates to the given database should not be logged tothe binary log.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, -#if !defined(DBUG_OFF) && !defined(MYSQL_CLIENT) - {"binlog-show-xid", OPT_BINLOG_SHOW_XID, - "Option used by mysql-test for debugging and testing: " - "do not display the XID in SHOW BINLOG EVENTS; " - "may be removed in future versions", - (gptr*) &Xid_log_event::show_xid, (gptr*) &Xid_log_event::show_xid, - 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0}, -#endif #ifdef HAVE_ROW_BASED_REPLICATION {"binlog-row-event-max-size", OPT_BINLOG_ROWS_EVENT_MAX_SIZE, "The maximum size of a row-based binary log event in bytes. Rows will be " @@ -4952,7 +4981,8 @@ Disable with --skip-bdb (will save memory).", "Set the default storage engine (table type) for tables.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"default-table-type", OPT_STORAGE_ENGINE, - "(deprecated) Use --default-storage-engine.", 0, 0, + "(deprecated) Use --default-storage-engine.", + (gptr*)default_storage_engine_str, (gptr*)default_storage_engine_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"default-time-zone", OPT_DEFAULT_TIME_ZONE, "Set the default time zone.", (gptr*) &default_tz_name, (gptr*) &default_tz_name, @@ -4993,12 +5023,12 @@ Disable with --skip-bdb (will save memory).", (gptr*) &global_system_variables.engine_condition_pushdown, (gptr*) &global_system_variables.engine_condition_pushdown, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"event-scheduler", OPT_EVENT_EXECUTOR, "Enable/disable the event scheduler.", - (gptr*) &opt_event_executor, (gptr*) &opt_event_executor, 0, GET_BOOL, NO_ARG, - 0/*default*/, 0/*min-value*/, 1/*max-value*/, 0, 0, 0}, + {"event-scheduler", OPT_EVENT_SCHEDULER, "Enable/disable the event scheduler.", + (gptr*) &Events::opt_event_scheduler, (gptr*) &Events::opt_event_scheduler, 0, GET_ULONG, + REQUIRED_ARG, 2/*default*/, 0/*min-value*/, 2/*max-value*/, 0, 0, 0}, {"exit-info", 'T', "Used for debugging; Use at your own risk!", 0, 0, 0, GET_LONG, OPT_ARG, 0, 0, 0, 0, 0, 0}, - {"external-locking", OPT_USE_LOCKING, "Use system (external) locking. With this option enabled you can run myisamchk to test (not repair) tables while the MySQL server is running.", + {"external-locking", OPT_USE_LOCKING, "Use system (external) locking (disabled by default). With this option enabled you can run myisamchk to test (not repair) tables while the MySQL server is running. Disable with --skip-external-locking.", (gptr*) &opt_external_locking, (gptr*) &opt_external_locking, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"flush", OPT_FLUSH, "Flush tables to disk between SQL commands.", 0, 0, 0, @@ -5831,7 +5861,7 @@ log and this option does nothing anymore.", {"innodb_thread_concurrency", OPT_INNODB_THREAD_CONCURRENCY, "Helps in performance tuning in heavily concurrent environments.", (gptr*) &srv_thread_concurrency, (gptr*) &srv_thread_concurrency, - 0, GET_LONG, REQUIRED_ARG, 20, 1, 1000, 0, 1, 0}, + 0, GET_LONG, REQUIRED_ARG, 8, 1, 1000, 0, 1, 0}, {"innodb_thread_sleep_delay", OPT_INNODB_THREAD_SLEEP_DELAY, "Time of innodb thread sleeping before joining InnoDB queue (usec). Value 0" " disable a sleep", @@ -6980,8 +7010,8 @@ static void mysql_init_variables(void) sys_charset_system.value= (char*) system_charset_info->csname; character_set_filesystem_name= (char*) "binary"; - /* Set default values for some option variables */ + default_storage_engine_str="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; @@ -7321,6 +7351,24 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), break; } #endif + case OPT_EVENT_SCHEDULER: + if (!argument) + Events::opt_event_scheduler= 2; + else + { + int type; + if ((type=find_type(argument, &Events::opt_typelib, 1)) <= 0) + { + fprintf(stderr,"Unknown option to event-scheduler: %s\n",argument); + exit(1); + } + /* + type= 1 2 3 4 5 6 + (OFF | 0) - (ON | 1) - (2 | SUSPEND) + */ + Events::opt_event_scheduler= (type-1) / 2; + } + break; case (int) OPT_SKIP_NEW: opt_specialflag|= SPECIAL_NO_NEW_FUNC; delay_key_write_options= (uint) DELAY_KEY_WRITE_NONE; @@ -7423,17 +7471,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), case OPT_BOOTSTRAP: opt_noacl=opt_bootstrap=1; break; - case OPT_STORAGE_ENGINE: - { - 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); - } - break; - } case OPT_SERVER_ID: server_id_supplied = 1; break; diff --git a/sql/net_serv.cc b/sql/net_serv.cc index 9713e4bed44..03164827e8f 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -37,9 +37,6 @@ HFTODO this must be hidden if we don't want client capabilities in embedded library */ -#ifdef __WIN__ -#include <winsock.h> -#endif #include <my_global.h> #include <mysql.h> #include <mysql_embed.h> @@ -51,6 +48,12 @@ #include <violite.h> #include <signal.h> #include <errno.h> +#ifdef __WIN__ +#include <winsock.h> +#endif +#ifdef __NETWARE__ +#include <sys/select.h> +#endif #ifdef EMBEDDED_LIBRARY #undef MYSQL_SERVER diff --git a/sql/opt_range.cc b/sql/opt_range.cc index e2b5bdeacc7..c905d8aada7 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -450,6 +450,8 @@ public: /* TRUE if last checked tree->key can be used for ROR-scan */ bool is_ror_scan; + /* Number of ranges in the last checked tree->key */ + uint n_ranges; }; class TABLE_READ_PLAN; @@ -4743,17 +4745,46 @@ static SEL_TREE *get_func_mm_tree(RANGE_OPT_PARAM *param, Item_func *cond_func, if (inv) { - /* - We get here for conditions like "t.keypart NOT IN (....)". - - If the IN-list contains only constants (and func->array is an ordered - array of them), we construct the appropriate SEL_ARG tree manually, - because constructing it using the range analyzer (as - AND_i( t.keypart != c_i)) will cause lots of memory to be consumed - (see BUG#15872). - */ if (func->array && func->cmp_type != ROW_RESULT) { + /* + We get here for conditions in form "t.key NOT IN (c1, c2, ...)" + (where c{i} are constants). + Our goal is to produce a SEL_ARG graph that represents intervals: + + ($MIN<t.key<c1) OR (c1<t.key<c2) OR (c2<t.key<c3) OR ... (*) + + where $MIN is either "-inf" or NULL. + + The most straightforward way to handle NOT IN would be to convert + it to "(t.key != c1) AND (t.key != c2) AND ..." and let the range + optimizer to build SEL_ARG graph from that. However that will cause + the range optimizer to use O(N^2) memory (it's a bug, not filed), + and people do use big NOT IN lists (see BUG#15872). Also, for big + NOT IN lists constructing/using graph (*) does not make the query + faster. + + So, we will handle NOT IN manually in the following way: + * if the number of entries in the NOT IN list is less then + NOT_IN_IGNORE_THRESHOLD, we will construct SEL_ARG graph (*) + manually. + * Otherwise, we will construct a smaller graph: for + "t.key NOT IN (c1,...cN)" we construct a graph representing + ($MIN < t.key) OR (cN < t.key) // here sequence of c_i is + // ordered. + + A note about partially-covering indexes: for those (e.g. for + "a CHAR(10), KEY(a(5))") the handling is correct (albeit not very + efficient): + Instead of "t.key < c1" we get "t.key <= prefix-val(c1)". + Combining the intervals in (*) together, we get: + (-inf<=t.key<=c1) OR (c1<=t.key<=c2) OR (c2<=t.key<=c3) OR ... + i.e. actually we get intervals combined into one interval: + (-inf<=t.key<=+inf). This doesn't make much sense but it doesn't + cause any problems. + */ + MEM_ROOT *tmp_root= param->mem_root; + param->thd->mem_root= param->old_root; /* Create one Item_type constant object. We'll need it as get_mm_parts only accepts constant values wrapped in Item_Type @@ -4762,25 +4793,35 @@ static SEL_TREE *get_func_mm_tree(RANGE_OPT_PARAM *param, Item_func *cond_func, per-statement mem_root (while thd->mem_root is currently pointing to mem_root local to range optimizer). */ - MEM_ROOT *tmp_root= param->mem_root; - param->thd->mem_root= param->old_root; Item *value_item= func->array->create_item(); param->thd->mem_root= tmp_root; if (!value_item) break; - /* Get a SEL_TREE for "-inf < X < c_0" interval */ - func->array->value_to_item(0, value_item); - tree= get_mm_parts(param, cond_func, field, Item_func::LT_FUNC, - value_item, cmp_type); - if (!tree) + /* Get a SEL_TREE for "(-inf|NULL) < X < c_0" interval. */ + uint i=0; + do + { + func->array->value_to_item(i, value_item); + tree= get_mm_parts(param, cond_func, field, Item_func::LT_FUNC, + value_item, cmp_type); + if (!tree) + break; + i++; + } while (i < func->array->count && tree->type == SEL_TREE::IMPOSSIBLE); + + if (!tree || tree->type == SEL_TREE::IMPOSSIBLE) + { + /* We get here in cases like "t.unsigned NOT IN (-1,-2,-3) */ + tree= NULL; break; + } #define NOT_IN_IGNORE_THRESHOLD 1000 SEL_TREE *tree2; if (func->array->count < NOT_IN_IGNORE_THRESHOLD) { - for (uint i=1; i < func->array->count; i++) + for (; i < func->array->count; i++) { if (func->array->compare_elems(i, i-1)) { @@ -4788,32 +4829,44 @@ static SEL_TREE *get_func_mm_tree(RANGE_OPT_PARAM *param, Item_func *cond_func, func->array->value_to_item(i, value_item); tree2= get_mm_parts(param, cond_func, field, Item_func::LT_FUNC, value_item, cmp_type); - + if (!tree2) + { + tree= NULL; + break; + } + /* Change all intervals to be "c_{i-1} < X < c_i" */ for (uint idx= 0; idx < param->keys; idx++) { - SEL_ARG *new_interval; - if ((new_interval= tree2->keys[idx])) + SEL_ARG *new_interval, *last_val; + if (((new_interval= tree2->keys[idx])) && + ((last_val= tree->keys[idx]->last()))) { - SEL_ARG *last_val= tree->keys[idx]->last(); new_interval->min_value= last_val->max_value; new_interval->min_flag= NEAR_MIN; } } + /* + The following doesn't try to allocate memory so no need to + check for NULL. + */ tree= tree_or(param, tree, tree2); } } } else func->array->value_to_item(func->array->count - 1, value_item); - - /* - Get the SEL_TREE for the last "c_last < X < +inf" interval - (value_item cotains c_last already) - */ - tree2= get_mm_parts(param, cond_func, field, Item_func::GT_FUNC, - value_item, cmp_type); - tree= tree_or(param, tree, tree2); + + if (tree && tree->type != SEL_TREE::IMPOSSIBLE) + { + /* + Get the SEL_TREE for the last "c_last < X < +inf" interval + (value_item cotains c_last already) + */ + tree2= get_mm_parts(param, cond_func, field, Item_func::GT_FUNC, + value_item, cmp_type); + tree= tree_or(param, tree, tree2); + } } else { @@ -6629,6 +6682,7 @@ check_quick_select(PARAM *param,uint idx,SEL_ARG *tree) param->table->file->primary_key_is_clustered()); param->is_ror_scan= !cpk_scan; } + param->n_ranges= 0; records=check_quick_keys(param,idx,tree,param->min_key,0,param->max_key,0); if (records != HA_POS_ERROR) @@ -6636,7 +6690,7 @@ check_quick_select(PARAM *param,uint idx,SEL_ARG *tree) param->table->quick_keys.set_bit(key); param->table->quick_rows[key]=records; param->table->quick_key_parts[key]=param->max_key_part+1; - + param->table->quick_n_ranges[key]= param->n_ranges; if (cpk_scan) param->is_ror_scan= TRUE; } @@ -6772,7 +6826,10 @@ check_quick_keys(PARAM *param,uint idx,SEL_ARG *key_tree, HA_NOSAME && min_key_length == max_key_length && !memcmp(param->min_key,param->max_key,min_key_length)) + { tmp=1; // Max one record + param->n_ranges++; + } else { if (param->is_ror_scan) @@ -6792,6 +6849,7 @@ check_quick_keys(PARAM *param,uint idx,SEL_ARG *key_tree, is_key_scan_ror(param, keynr, key_tree->part + 1))) param->is_ror_scan= FALSE; } + param->n_ranges++; if (tmp_min_flag & GEOM_FLAG) { @@ -7430,66 +7488,65 @@ int QUICK_ROR_INTERSECT_SELECT::get_next() uint last_rowid_count=0; DBUG_ENTER("QUICK_ROR_INTERSECT_SELECT::get_next"); - /* Get a rowid for first quick and save it as a 'candidate' */ - quick= quick_it++; - if (cpk_quick) + do { - do - { - error= quick->get_next(); - } while (!error && !cpk_quick->row_in_ranges()); - } - else + /* Get a rowid for first quick and save it as a 'candidate' */ + quick= quick_it++; error= quick->get_next(); - - if (error) - DBUG_RETURN(error); - - quick->file->position(quick->record); - memcpy(last_rowid, quick->file->ref, head->file->ref_length); - last_rowid_count= 1; - - while (last_rowid_count < quick_selects.elements) - { - if (!(quick= quick_it++)) + if (cpk_quick) { - quick_it.rewind(); - quick= quick_it++; + while (!error && !cpk_quick->row_in_ranges()) + error= quick->get_next(); } + if (error) + DBUG_RETURN(error); - do - { - if ((error= quick->get_next())) - DBUG_RETURN(error); - quick->file->position(quick->record); - cmp= head->file->cmp_ref(quick->file->ref, last_rowid); - } while (cmp < 0); + quick->file->position(quick->record); + memcpy(last_rowid, quick->file->ref, head->file->ref_length); + last_rowid_count= 1; - /* Ok, current select 'caught up' and returned ref >= cur_ref */ - if (cmp > 0) + while (last_rowid_count < quick_selects.elements) { - /* Found a row with ref > cur_ref. Make it a new 'candidate' */ - if (cpk_quick) + if (!(quick= quick_it++)) + { + quick_it.rewind(); + quick= quick_it++; + } + + do + { + if ((error= quick->get_next())) + DBUG_RETURN(error); + quick->file->position(quick->record); + cmp= head->file->cmp_ref(quick->file->ref, last_rowid); + } while (cmp < 0); + + /* Ok, current select 'caught up' and returned ref >= cur_ref */ + if (cmp > 0) { - while (!cpk_quick->row_in_ranges()) + /* Found a row with ref > cur_ref. Make it a new 'candidate' */ + if (cpk_quick) { - if ((error= quick->get_next())) - DBUG_RETURN(error); + while (!cpk_quick->row_in_ranges()) + { + if ((error= quick->get_next())) + DBUG_RETURN(error); + } } + memcpy(last_rowid, quick->file->ref, head->file->ref_length); + last_rowid_count= 1; + } + else + { + /* current 'candidate' row confirmed by this select */ + last_rowid_count++; } - memcpy(last_rowid, quick->file->ref, head->file->ref_length); - last_rowid_count= 1; - } - else - { - /* current 'candidate' row confirmed by this select */ - last_rowid_count++; } - } - /* We get here if we got the same row ref in all scans. */ - if (need_to_fetch_row) - error= head->file->rnd_pos(head->record[0], last_rowid); + /* We get here if we got the same row ref in all scans. */ + if (need_to_fetch_row) + error= head->file->rnd_pos(head->record[0], last_rowid); + } while (error == HA_ERR_RECORD_DELETED); DBUG_RETURN(error); } @@ -7518,41 +7575,44 @@ int QUICK_ROR_UNION_SELECT::get_next() do { - if (!queue.elements) - DBUG_RETURN(HA_ERR_END_OF_FILE); - /* Ok, we have a queue with >= 1 scans */ + do + { + if (!queue.elements) + DBUG_RETURN(HA_ERR_END_OF_FILE); + /* Ok, we have a queue with >= 1 scans */ - quick= (QUICK_SELECT_I*)queue_top(&queue); - memcpy(cur_rowid, quick->last_rowid, rowid_length); + quick= (QUICK_SELECT_I*)queue_top(&queue); + memcpy(cur_rowid, quick->last_rowid, rowid_length); - /* put into queue rowid from the same stream as top element */ - if ((error= quick->get_next())) - { - if (error != HA_ERR_END_OF_FILE) - DBUG_RETURN(error); - queue_remove(&queue, 0); - } - else - { - quick->save_last_pos(); - queue_replaced(&queue); - } + /* put into queue rowid from the same stream as top element */ + if ((error= quick->get_next())) + { + if (error != HA_ERR_END_OF_FILE) + DBUG_RETURN(error); + queue_remove(&queue, 0); + } + else + { + quick->save_last_pos(); + queue_replaced(&queue); + } - if (!have_prev_rowid) - { - /* No rows have been returned yet */ - dup_row= FALSE; - have_prev_rowid= TRUE; - } - else - dup_row= !head->file->cmp_ref(cur_rowid, prev_rowid); - } while (dup_row); + if (!have_prev_rowid) + { + /* No rows have been returned yet */ + dup_row= FALSE; + have_prev_rowid= TRUE; + } + else + dup_row= !head->file->cmp_ref(cur_rowid, prev_rowid); + } while (dup_row); - tmp= cur_rowid; - cur_rowid= prev_rowid; - prev_rowid= tmp; + tmp= cur_rowid; + cur_rowid= prev_rowid; + prev_rowid= tmp; - error= head->file->rnd_pos(quick->record, prev_rowid); + error= head->file->rnd_pos(quick->record, prev_rowid); + } while (error == HA_ERR_RECORD_DELETED); DBUG_RETURN(error); } diff --git a/sql/partition_element.h b/sql/partition_element.h index 13693934c0f..90d0bda87c1 100644 --- a/sql/partition_element.h +++ b/sql/partition_element.h @@ -64,8 +64,20 @@ public: engine_type(NULL),part_state(PART_NORMAL), nodegroup_id(UNDEF_NODEGROUP), has_null_value(FALSE) { - subpartitions.empty(); - list_val_list.empty(); + } + partition_element(partition_element *part_elem) + : part_max_rows(part_elem->part_max_rows), + part_min_rows(part_elem->part_min_rows), + partition_name(NULL), + tablespace_name(part_elem->tablespace_name), + range_value(0), part_comment(part_elem->part_comment), + data_file_name(part_elem->data_file_name), + index_file_name(part_elem->index_file_name), + engine_type(part_elem->engine_type), + part_state(part_elem->part_state), + nodegroup_id(part_elem->nodegroup_id), + has_null_value(FALSE) + { } ~partition_element() {} }; diff --git a/sql/partition_info.cc b/sql/partition_info.cc index 6761b28331e..e5f8cd7ffac 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -267,7 +267,7 @@ bool partition_info::set_up_default_subpartitions(handler *file, j= 0; do { - partition_element *subpart_elem= new partition_element(); + partition_element *subpart_elem= new partition_element(part_elem); if (likely(subpart_elem != 0 && (!part_elem->subpartitions.push_back(subpart_elem)))) { @@ -432,18 +432,22 @@ char *partition_info::has_unique_names() bool partition_info::check_engine_mix(handlerton **engine_array, uint no_parts) { uint i= 0; - bool result= FALSE; DBUG_ENTER("partition_info::check_engine_mix"); do { if (engine_array[i] != engine_array[0]) { - result= TRUE; - break; + my_error(ER_MIX_HANDLER_ERROR, MYF(0)); + DBUG_RETURN(TRUE); } } while (++i < no_parts); - DBUG_RETURN(result); + if (engine_array[0] == &myisammrg_hton) + { + my_error(ER_PARTITION_MERGE_ERROR, MYF(0)); + DBUG_RETURN(TRUE); + } + DBUG_RETURN(FALSE); } @@ -681,8 +685,20 @@ bool partition_info::check_partition_info(handlerton **eng_type, uint i, tot_partitions; bool result= TRUE; char *same_name; + bool part_expression_ok= TRUE; DBUG_ENTER("partition_info::check_partition_info"); + if (part_type != HASH_PARTITION || !list_of_part_fields) + part_expr->walk(&Item::check_partition_func_processor, + (byte*)(&part_expression_ok)); + if (is_sub_partitioned() && !list_of_subpart_fields) + subpart_expr->walk(&Item::check_partition_func_processor, + (byte*)(&part_expression_ok)); + if (!part_expression_ok) + { + my_error(ER_PARTITION_FUNCTION_IS_NOT_ALLOWED, MYF(0)); + goto end; + } if (unlikely(!is_sub_partitioned() && !(use_default_subpartitions && use_default_no_subpartitions))) { @@ -720,6 +736,8 @@ bool partition_info::check_partition_info(handlerton **eng_type, do { partition_element *part_elem= part_it++; + if (part_elem->engine_type == NULL) + part_elem->engine_type= default_engine_type; if (!is_sub_partitioned()) { if (check_table_name(part_elem->partition_name, @@ -728,8 +746,6 @@ bool partition_info::check_partition_info(handlerton **eng_type, my_error(ER_WRONG_PARTITION_NAME, MYF(0)); goto end; } - if (part_elem->engine_type == NULL) - part_elem->engine_type= default_engine_type; DBUG_PRINT("info", ("engine = %d", ha_legacy_type(part_elem->engine_type))); engine_array[part_count++]= part_elem->engine_type; @@ -740,27 +756,24 @@ bool partition_info::check_partition_info(handlerton **eng_type, List_iterator<partition_element> sub_it(part_elem->subpartitions); do { - part_elem= sub_it++; - if (check_table_name(part_elem->partition_name, - strlen(part_elem->partition_name))) + partition_element *sub_elem= sub_it++; + if (check_table_name(sub_elem->partition_name, + strlen(sub_elem->partition_name))) { my_error(ER_WRONG_PARTITION_NAME, MYF(0)); goto end; } - if (part_elem->engine_type == NULL) - part_elem->engine_type= default_engine_type; + if (sub_elem->engine_type == NULL) + sub_elem->engine_type= default_engine_type; DBUG_PRINT("info", ("engine = %u", - ha_legacy_type(part_elem->engine_type))); - engine_array[part_count++]= part_elem->engine_type; + ha_legacy_type(sub_elem->engine_type))); + engine_array[part_count++]= sub_elem->engine_type; } while (++j < no_subparts); } } while (++i < no_parts); } if (unlikely(partition_info::check_engine_mix(engine_array, part_count))) - { - my_error(ER_MIX_HANDLER_ERROR, MYF(0)); goto end; - } if (eng_type) *eng_type= (handlerton*)engine_array[0]; diff --git a/sql/partition_info.h b/sql/partition_info.h index 3a1e6be4050..af43f7b7933 100644 --- a/sql/partition_info.h +++ b/sql/partition_info.h @@ -184,6 +184,7 @@ public: bool list_of_subpart_fields; bool linear_hash_ind; bool fixed; + bool is_auto_partitioned; bool from_openfrm; bool has_null_value; uint has_null_part_id; @@ -219,6 +220,7 @@ public: list_of_part_fields(FALSE), list_of_subpart_fields(FALSE), linear_hash_ind(FALSE), fixed(FALSE), + is_auto_partitioned(FALSE), from_openfrm(FALSE), has_null_value(FALSE), has_null_part_id(0) diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc index 9cabe1a3df0..66e2aa1c31c 100644 --- a/sql/repl_failsafe.cc +++ b/sql/repl_failsafe.cc @@ -61,12 +61,13 @@ static Slave_log_event* find_slave_event(IO_CACHE* log, static int init_failsafe_rpl_thread(THD* thd) { DBUG_ENTER("init_failsafe_rpl_thread"); + thd->system_thread = SYSTEM_THREAD_DELAYED_INSERT; /* thd->bootstrap is to report errors barely to stderr; if this code is enable again one day, one should check if bootstrap is still needed (maybe this thread has no other error reporting method). */ - thd->system_thread = thd->bootstrap = 1; + thd->bootstrap = 1; thd->security_ctx->skip_grants(); my_net_init(&thd->net, 0); thd->net.read_timeout = slave_net_timeout; diff --git a/sql/rpl_rli.h b/sql/rpl_rli.h index cacae1aa4c2..99606353080 100644 --- a/sql/rpl_rli.h +++ b/sql/rpl_rli.h @@ -309,15 +309,14 @@ typedef struct st_relay_log_info void cleanup_context(THD *, bool); void clear_tables_to_lock() { - TABLE_LIST *ptr= tables_to_lock; - while (ptr) + while (tables_to_lock) { - char *to_free= reinterpret_cast<char*>(ptr); - ptr= ptr->next_global; + char *to_free= reinterpret_cast<gptr>(tables_to_lock); + tables_to_lock= tables_to_lock->next_global; + tables_to_lock_count--; my_free(to_free, MYF(MY_WME)); } - tables_to_lock= 0; - tables_to_lock_count= 0; + DBUG_ASSERT(tables_to_lock == NULL && tables_to_lock_count == 0); } time_t unsafe_to_stop_at; diff --git a/sql/set_var.cc b/sql/set_var.cc index 179097fd958..53b4b395c37 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -56,6 +56,8 @@ #include <thr_alarm.h> #include <myisam.h> +#include "event_scheduler.h" + /* WITH_BERKELEY_STORAGE_ENGINE */ extern bool berkeley_shared_data; extern ulong berkeley_max_lock, berkeley_log_buffer_size; @@ -106,7 +108,6 @@ extern ulong ndb_report_thresh_binlog_mem_usage; -extern my_bool event_executor_running_global_var; static HASH system_variable_hash; const char *bool_type_names[]= { "OFF", "ON", NullS }; @@ -162,6 +163,7 @@ void fix_sql_mode_var(THD *thd, enum_var_type type); static byte *get_error_count(THD *thd); static byte *get_warning_count(THD *thd); static byte *get_prepared_stmt_count(THD *thd); +static byte *get_tmpdir(THD *thd); /* Variable definition list @@ -184,6 +186,7 @@ sys_var_thd_ulong sys_auto_increment_offset("auto_increment_offset", sys_var_bool_ptr sys_automatic_sp_privileges("automatic_sp_privileges", &sp_automatic_privileges); +sys_var_const_str sys_basedir("basedir", mysql_home); sys_var_long_ptr sys_binlog_cache_size("binlog_cache_size", &binlog_cache_size); sys_var_thd_binlog_format sys_binlog_format("binlog_format", @@ -209,6 +212,7 @@ sys_var_long_ptr sys_concurrent_insert("concurrent_insert", &myisam_concurrent_insert); sys_var_long_ptr sys_connect_timeout("connect_timeout", &connect_timeout); +sys_var_const_str sys_datadir("datadir", mysql_real_data_home); #ifndef DBUG_OFF sys_var_thd_dbug sys_dbug("debug"); #endif @@ -222,9 +226,8 @@ sys_var_long_ptr sys_delayed_insert_timeout("delayed_insert_timeout", &delayed_insert_timeout); sys_var_long_ptr sys_delayed_queue_size("delayed_queue_size", &delayed_queue_size); -sys_var_event_executor sys_event_executor("event_scheduler", - (my_bool *) - &event_executor_running_global_var); + +sys_var_event_scheduler sys_event_scheduler("event_scheduler"); sys_var_long_ptr sys_expire_logs_days("expire_logs_days", &expire_logs_days); sys_var_bool_ptr sys_flush("flush", &myisam_flush); @@ -262,6 +265,9 @@ sys_trust_routine_creators("log_bin_trust_routine_creators", sys_var_bool_ptr sys_trust_function_creators("log_bin_trust_function_creators", &trust_function_creators); +sys_var_bool_ptr + sys_log_queries_not_using_indexes("log_queries_not_using_indexes", + &opt_log_queries_not_using_indexes); sys_var_thd_ulong sys_log_warnings("log_warnings", &SV::log_warnings); sys_var_thd_ulong sys_long_query_time("long_query_time", &SV::long_query_time); @@ -389,6 +395,7 @@ sys_var_thd_ulong sys_query_alloc_block_size("query_alloc_block_size", sys_var_thd_ulong sys_query_prealloc_size("query_prealloc_size", &SV::query_prealloc_size, 0, fix_thd_mem_root); +sys_var_readonly sys_tmpdir("tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir); sys_var_thd_ulong sys_trans_alloc_block_size("transaction_alloc_block_size", &SV::trans_alloc_block_size, 0, fix_trans_mem_root); @@ -425,6 +432,21 @@ sys_var_thd_ulong sys_sort_buffer("sort_buffer_size", &SV::sortbuff_size); sys_var_thd_sql_mode sys_sql_mode("sql_mode", &SV::sql_mode); +#ifdef HAVE_OPENSSL +extern char *opt_ssl_ca, *opt_ssl_capath, *opt_ssl_cert, *opt_ssl_cipher, + *opt_ssl_key; +sys_var_const_str_ptr sys_ssl_ca("ssl_ca", &opt_ssl_ca); +sys_var_const_str_ptr sys_ssl_capath("ssl_capath", &opt_ssl_capath); +sys_var_const_str_ptr sys_ssl_cert("ssl_cert", &opt_ssl_cert); +sys_var_const_str_ptr sys_ssl_cipher("ssl_cipher", &opt_ssl_cipher); +sys_var_const_str_ptr sys_ssl_key("ssl_key", &opt_ssl_key); +#else +sys_var_const_str sys_ssl_ca("ssl_ca", NULL); +sys_var_const_str sys_ssl_capath("ssl_capath", NULL); +sys_var_const_str sys_ssl_cert("ssl_cert", NULL); +sys_var_const_str sys_ssl_cipher("ssl_cipher", NULL); +sys_var_const_str sys_ssl_key("ssl_key", NULL); +#endif sys_var_thd_enum sys_updatable_views_with_limit("updatable_views_with_limit", &SV::updatable_views_with_limit, @@ -696,7 +718,6 @@ static int show_slave_skip_errors(THD *thd, SHOW_VAR *var, char *buff) } #endif /* HAVE_REPLICATION */ - /* Variables shown by SHOW variables in alphabetical order */ @@ -706,7 +727,7 @@ SHOW_VAR init_vars[]= { {"auto_increment_offset", (char*) &sys_auto_increment_offset, SHOW_SYS}, {sys_automatic_sp_privileges.name,(char*) &sys_automatic_sp_privileges, SHOW_SYS}, {"back_log", (char*) &back_log, SHOW_LONG}, - {"basedir", mysql_home, SHOW_CHAR}, + {sys_basedir.name, (char*) &sys_basedir, SHOW_SYS}, {"bdb_cache_parts", (char*) &berkeley_cache_parts, SHOW_LONG}, {"bdb_cache_size", (char*) &berkeley_cache_size, SHOW_LONGLONG}, {"bdb_home", (char*) &berkeley_home, SHOW_CHAR_PTR}, @@ -733,7 +754,7 @@ SHOW_VAR init_vars[]= { {sys_completion_type.name, (char*) &sys_completion_type, SHOW_SYS}, {sys_concurrent_insert.name,(char*) &sys_concurrent_insert, SHOW_SYS}, {sys_connect_timeout.name, (char*) &sys_connect_timeout, SHOW_SYS}, - {"datadir", mysql_real_data_home, SHOW_CHAR}, + {sys_datadir.name, (char*) &sys_datadir, SHOW_SYS}, {sys_date_format.name, (char*) &sys_date_format, SHOW_SYS}, {sys_datetime_format.name, (char*) &sys_datetime_format, SHOW_SYS}, #ifndef DBUG_OFF @@ -747,7 +768,7 @@ SHOW_VAR init_vars[]= { {sys_div_precincrement.name,(char*) &sys_div_precincrement,SHOW_SYS}, {sys_engine_condition_pushdown.name, (char*) &sys_engine_condition_pushdown, SHOW_SYS}, - {sys_event_executor.name, (char*) &sys_event_executor, SHOW_SYS}, + {sys_event_scheduler.name, (char*) &sys_event_scheduler, SHOW_SYS}, {sys_expire_logs_days.name, (char*) &sys_expire_logs_days, SHOW_SYS}, {sys_flush.name, (char*) &sys_flush, SHOW_SYS}, {sys_flush_time.name, (char*) &sys_flush_time, SHOW_SYS}, @@ -833,6 +854,8 @@ SHOW_VAR init_vars[]= { {"log_bin", (char*) &opt_bin_log, SHOW_BOOL}, {sys_trust_function_creators.name,(char*) &sys_trust_function_creators, SHOW_SYS}, {"log_error", (char*) log_error_file, SHOW_CHAR}, + {sys_log_queries_not_using_indexes.name, + (char*) &sys_log_queries_not_using_indexes, SHOW_SYS}, #ifdef HAVE_REPLICATION {"log_slave_updates", (char*) &opt_log_slave_updates, SHOW_MY_BOOL}, #endif @@ -962,6 +985,11 @@ SHOW_VAR init_vars[]= { {sys_sql_mode.name, (char*) &sys_sql_mode, SHOW_SYS}, {"sql_notes", (char*) &sys_sql_notes, SHOW_SYS}, {"sql_warnings", (char*) &sys_sql_warnings, SHOW_SYS}, + {sys_ssl_ca.name, (char*) &sys_ssl_ca, SHOW_SYS}, + {sys_ssl_capath.name, (char*) &sys_ssl_capath, SHOW_SYS}, + {sys_ssl_cert.name, (char*) &sys_ssl_cert, SHOW_SYS}, + {sys_ssl_cipher.name, (char*) &sys_ssl_cipher, SHOW_SYS}, + {sys_ssl_key.name, (char*) &sys_ssl_key, SHOW_SYS}, {sys_storage_engine.name, (char*) &sys_storage_engine, SHOW_SYS}, #ifdef HAVE_REPLICATION {sys_sync_binlog_period.name,(char*) &sys_sync_binlog_period, SHOW_SYS}, @@ -983,7 +1011,7 @@ SHOW_VAR init_vars[]= { {"time_zone", (char*) &sys_time_zone, SHOW_SYS}, {sys_timed_mutexes.name, (char*) &sys_timed_mutexes, SHOW_SYS}, {sys_tmp_table_size.name, (char*) &sys_tmp_table_size, SHOW_SYS}, - {"tmpdir", (char*) &opt_mysql_tmpdir, SHOW_CHAR_PTR}, + {sys_tmpdir.name, (char*) &sys_tmpdir, SHOW_SYS}, {sys_trans_alloc_block_size.name, (char*) &sys_trans_alloc_block_size, SHOW_SYS}, {sys_trans_prealloc_size.name, (char*) &sys_trans_prealloc_size, SHOW_SYS}, @@ -1270,12 +1298,14 @@ bool sys_var_thd_binlog_format::is_readonly() const And this test will also prevent switching from RBR to RBR (a no-op which should not happen too often). */ +#ifdef HAVE_ROW_BASED_REPLICATION if ((thd->variables.binlog_format == BINLOG_FORMAT_ROW) && thd->temporary_tables) { my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0)); return 1; } +#endif /*HAVE_ROW_BASED_REPLICATION*/ /* if in a stored function, it's too late to change mode */ @@ -1299,7 +1329,9 @@ bool sys_var_thd_binlog_format::is_readonly() const void fix_binlog_format_after_update(THD *thd, enum_var_type type) { +#ifdef HAVE_ROW_BASED_REPLICATION thd->reset_current_stmt_binlog_row_based(); +#endif /*HAVE_ROW_BASED_REPLICATION*/ } static void fix_max_binlog_size(THD *thd, enum_var_type type) @@ -2852,6 +2884,31 @@ static byte *get_prepared_stmt_count(THD *thd) return (byte*) &thd->sys_var_tmp.ulong_value; } + +/* + Get the tmpdir that was specified or chosen by default + + SYNOPSIS + get_tmpdir() + thd thread handle + + DESCRIPTION + This is necessary because if the user does not specify a temporary + directory via the command line, one is chosen based on the environment + or system defaults. But we can't just always use mysql_tmpdir, because + that is actually a call to my_tmpdir() which cycles among possible + temporary directories. + + RETURN VALUES + ptr pointer to NUL-terminated string + */ +static byte *get_tmpdir(THD *thd) +{ + if (opt_mysql_tmpdir) + return (byte *)opt_mysql_tmpdir; + return (byte*)mysql_tmpdir; +} + /**************************************************************************** Main handling of variables: - Initialisation @@ -3251,7 +3308,7 @@ byte *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type, handlerton *val; val= (type == OPT_GLOBAL) ? global_system_variables.*offset : thd->variables.*offset; - return (byte *) val->name; + return (byte *) hton2plugin[val->slot]->name.str; } @@ -3414,9 +3471,9 @@ ulong fix_sql_mode(ulong sql_mode) MODE_NO_KEY_OPTIONS | MODE_NO_TABLE_OPTIONS | MODE_NO_FIELD_OPTIONS | MODE_NO_AUTO_CREATE_USER); if (sql_mode & MODE_MYSQL40) - sql_mode|= MODE_NO_FIELD_OPTIONS | MODE_HIGH_NOT_PRECEDENCE; + sql_mode|= MODE_HIGH_NOT_PRECEDENCE; if (sql_mode & MODE_MYSQL323) - sql_mode|= MODE_NO_FIELD_OPTIONS | MODE_HIGH_NOT_PRECEDENCE; + sql_mode|= MODE_HIGH_NOT_PRECEDENCE; if (sql_mode & MODE_TRADITIONAL) sql_mode|= (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES | MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | @@ -3576,6 +3633,69 @@ byte *sys_var_thd_dbug::value_ptr(THD *thd, enum_var_type type, LEX_STRING *b) return (byte*) thd->strdup(buf); } + +/* + The update method of the global variable event_scheduler. + If event_scheduler is switched from 0 to 1 then the scheduler main + thread is resumed and if from 1 to 0 the scheduler thread is suspended + + SYNOPSIS + sys_var_event_scheduler::update() + thd Thread context (unused) + var The new value + + Returns + FALSE OK + TRUE Error +*/ + +bool +sys_var_event_scheduler::update(THD *thd, set_var *var) +{ + enum Event_scheduler::enum_error_code res; + Event_scheduler *scheduler= Event_scheduler::get_instance(); + /* here start the thread if not running. */ + DBUG_ENTER("sys_var_event_scheduler::update"); + + DBUG_PRINT("new_value", ("%lu", (bool)var->save_result.ulong_value)); + if (!scheduler->initialized()) + { + my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--event-scheduler=0"); + DBUG_RETURN(true); + } + + if (var->save_result.ulonglong_value < 1 || + var->save_result.ulonglong_value > 2) + { + char buf[64]; + my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "event_scheduler", + llstr(var->save_result.ulonglong_value, buf)); + DBUG_RETURN(true); + } + if ((res= scheduler->suspend_or_resume(var->save_result.ulonglong_value == 1? + Event_scheduler::RESUME : + Event_scheduler::SUSPEND))) + my_error(ER_EVENT_SET_VAR_ERROR, MYF(0), (uint) res); + DBUG_RETURN((bool) res); +} + + +byte *sys_var_event_scheduler::value_ptr(THD *thd, enum_var_type type, + LEX_STRING *base) +{ + Event_scheduler *scheduler= Event_scheduler::get_instance(); + + if (!scheduler->initialized()) + thd->sys_var_tmp.long_value= 0; + else if (scheduler->get_state() == Event_scheduler::RUNNING) + thd->sys_var_tmp.long_value= 1; + else + thd->sys_var_tmp.long_value= 2; + + return (byte*) &thd->sys_var_tmp; +} + + /**************************************************************************** Used templates ****************************************************************************/ diff --git a/sql/set_var.h b/sql/set_var.h index 8076f10bb0a..1049b154d47 100644 --- a/sql/set_var.h +++ b/sql/set_var.h @@ -231,6 +231,35 @@ public: }; +class sys_var_const_str_ptr :public sys_var +{ +public: + char **value; // Pointer to const value + sys_var_const_str_ptr(const char *name_arg, char **value_arg) + :sys_var(name_arg),value(value_arg) + {} + bool check(THD *thd, set_var *var) + { + return 1; + } + bool update(THD *thd, set_var *var) + { + return 1; + } + SHOW_TYPE type() { return SHOW_CHAR; } + byte *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base) + { + return (byte*) *value; + } + bool check_update_type(Item_result type) + { + return 1; + } + bool check_default(enum_var_type type) { return 1; } + bool is_readonly() const { return 1; } +}; + + class sys_var_enum :public sys_var { uint *value; @@ -842,13 +871,14 @@ public: }; -class sys_var_event_executor :public sys_var_bool_ptr +class sys_var_event_scheduler :public sys_var_long_ptr { /* We need a derived class only to have a warn_deprecated() */ public: - sys_var_event_executor(const char *name_arg, my_bool *value_arg) : - sys_var_bool_ptr(name_arg, value_arg) {}; + sys_var_event_scheduler(const char *name_arg) : + sys_var_long_ptr(name_arg, NULL, NULL) {}; bool update(THD *thd, set_var *var); + byte *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base); }; extern void fix_binlog_format_after_update(THD *thd, enum_var_type type); diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index 51e765f9ba1..746f4128457 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -5020,7 +5020,7 @@ ER_OPTION_PREVENTS_STATEMENT ger "Der MySQL-Server läuft mit der Option %s und kann diese Anweisung deswegen nicht ausführen" por "O servidor MySQL está rodando com a opção %s razão pela qual não pode executar esse commando" spa "El servidor MySQL está rodando con la opción %s tal que no puede ejecutar este comando" - swe "MySQL är startad med --skip-grant-tables. Pga av detta kan du inte använda detta kommando" + swe "MySQL är startad med %s. Pga av detta kan du inte använda detta kommando" ER_DUPLICATED_VALUE_IN_TYPE eng "Column '%-.100s' has duplicated value '%-.64s' in %s" ger "Feld '%-.100s' hat doppelten Wert '%-.64s' in %s" @@ -5450,7 +5450,7 @@ ER_SP_DUP_HANDLER 42000 eng "Duplicate handler declared in the same block" ger "Doppelter Handler im selben Block deklariert" ER_SP_NOT_VAR_ARG 42000 - eng "OUT or INOUT argument %d for routine %s is not a variable" + eng "OUT or INOUT argument %d for routine %s is not a variable or NEW pseudo-variable in BEFORE trigger" ger "OUT- oder INOUT-Argument %d für Routine %s ist keine Variable" ER_SP_NO_RETSET 0A000 eng "Not allowed to return a result set from a %s" @@ -5810,6 +5810,9 @@ ER_NDB_CANT_SWITCH_BINLOG_FORMAT eng "The NDB cluster engine does not support changing the binlog format on the fly yet" ER_PARTITION_NO_TEMPORARY eng "Cannot create temporary table with partitions" +ER_PARTITION_FUNCTION_IS_NOT_ALLOWED + eng "This partition function is not allowed" + swe "Denna partitioneringsfunktion är inte tillåten" ER_DDL_LOG_ERROR eng "Error in DDL log" ER_NULL_IN_VALUES_LESS_THAN @@ -5820,3 +5823,12 @@ ER_WRONG_PARTITION_NAME swe "Felaktigt partitionsnamn" ER_CANT_CHANGE_TX_ISOLATION 25001 eng "Transaction isolation level can't be changed while a transaction is in progress" +ER_DUP_ENTRY_AUTOINCREMENT_CASE + eng "ALTER TABLE causes auto_increment resequencing, resulting in duplicate entry '%-.64s' for key '%-.64s'" +ER_EVENT_MODIFY_QUEUE_ERROR + eng "Internal scheduler error %d" +ER_EVENT_SET_VAR_ERROR + eng "Error during starting/stopping of the scheduler. Error code %u" +ER_PARTITION_MERGE_ERROR + eng "MyISAM Merge handler cannot be used in partitioned tables" + swe "MyISAM Merge kan inte anändas i en partitionerad tabell" diff --git a/sql/slave.cc b/sql/slave.cc index 4ab9e951813..5ef91b1f0d4 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -95,6 +95,8 @@ void init_thread_mask(int* mask,MASTER_INFO* mi,bool inverse) { bool set_io = mi->slave_running, set_sql = mi->rli.slave_running; register int tmp_mask=0; + DBUG_ENTER("init_thread_mask"); + if (set_io) tmp_mask |= SLAVE_IO; if (set_sql) @@ -102,6 +104,7 @@ void init_thread_mask(int* mask,MASTER_INFO* mi,bool inverse) if (inverse) tmp_mask^= (SLAVE_IO | SLAVE_SQL); *mask = tmp_mask; + DBUG_VOID_RETURN; } @@ -111,9 +114,12 @@ void init_thread_mask(int* mask,MASTER_INFO* mi,bool inverse) void lock_slave_threads(MASTER_INFO* mi) { + DBUG_ENTER("lock_slave_threads"); + //TODO: see if we can do this without dual mutex pthread_mutex_lock(&mi->run_lock); pthread_mutex_lock(&mi->rli.run_lock); + DBUG_VOID_RETURN; } @@ -123,9 +129,12 @@ void lock_slave_threads(MASTER_INFO* mi) void unlock_slave_threads(MASTER_INFO* mi) { + DBUG_ENTER("unlock_slave_threads"); + //TODO: see if we can do this without dual mutex pthread_mutex_unlock(&mi->rli.run_lock); pthread_mutex_unlock(&mi->run_lock); + DBUG_VOID_RETURN; } @@ -423,6 +432,8 @@ err: void init_slave_skip_errors(const char* arg) { const char *p; + DBUG_ENTER("init_slave_skip_errors"); + if (bitmap_init(&slave_error_mask,0,MAX_SLAVE_ERROR,0)) { fprintf(stderr, "Badly out of memory, please check your system status\n"); @@ -434,7 +445,7 @@ void init_slave_skip_errors(const char* arg) if (!my_strnncoll(system_charset_info,(uchar*)arg,4,(const uchar*)"all",4)) { bitmap_set_all(&slave_error_mask); - return; + DBUG_VOID_RETURN; } for (p= arg ; *p; ) { @@ -446,12 +457,15 @@ void init_slave_skip_errors(const char* arg) while (!my_isdigit(system_charset_info,*p) && *p) p++; } + DBUG_VOID_RETURN; } void st_relay_log_info::inc_group_relay_log_pos(ulonglong log_pos, bool skip_lock) { + DBUG_ENTER("st_relay_log_info::inc_group_relay_log_pos"); + if (!skip_lock) pthread_mutex_lock(&data_lock); inc_event_relay_log_pos(); @@ -500,12 +514,14 @@ void st_relay_log_info::inc_group_relay_log_pos(ulonglong log_pos, pthread_cond_broadcast(&data_cond); if (!skip_lock) pthread_mutex_unlock(&data_lock); + DBUG_VOID_RETURN; } void st_relay_log_info::close_temporary_tables() { TABLE *table,*next; + DBUG_ENTER("st_relay_log_info::close_temporary_tables"); for (table=save_temporary_tables ; table ; table=next) { @@ -514,10 +530,12 @@ void st_relay_log_info::close_temporary_tables() Don't ask for disk deletion. For now, anyway they will be deleted when slave restarts, but it is a better intention to not delete them. */ + DBUG_PRINT("info", ("table: %p", table)); close_temporary(table, 1, 0); } save_temporary_tables= 0; slave_open_temp_tables= 0; + DBUG_VOID_RETURN; } /* @@ -613,12 +631,13 @@ err: int terminate_slave_threads(MASTER_INFO* mi,int thread_mask,bool skip_lock) { + DBUG_ENTER("terminate_slave_threads"); + if (!mi->inited) - return 0; /* successfully do nothing */ + DBUG_RETURN(0); /* successfully do nothing */ int error,force_all = (thread_mask & SLAVE_FORCE_ALL); pthread_mutex_t *sql_lock = &mi->rli.run_lock, *io_lock = &mi->run_lock; pthread_mutex_t *sql_cond_lock,*io_cond_lock; - DBUG_ENTER("terminate_slave_threads"); sql_cond_lock=sql_lock; io_cond_lock=io_lock; @@ -704,9 +723,10 @@ int start_slave_thread(pthread_handler h_func, pthread_mutex_t *start_lock, { pthread_t th; ulong start_id; - DBUG_ASSERT(mi->inited); DBUG_ENTER("start_slave_thread"); + DBUG_ASSERT(mi->inited); + if (start_lock) pthread_mutex_lock(start_lock); if (!server_id) @@ -810,8 +830,10 @@ int start_slave_threads(bool need_slave_mutex, bool wait_for_start, #ifdef NOT_USED_YET static int end_slave_on_walk(MASTER_INFO* mi, gptr /*unused*/) { + DBUG_ENTER("end_slave_on_walk"); + end_master_info(mi); - return 0; + DBUG_RETURN(0); } #endif @@ -825,6 +847,8 @@ static int end_slave_on_walk(MASTER_INFO* mi, gptr /*unused*/) void end_slave() { + DBUG_ENTER("end_slave"); + /* This is called when the server terminates, in close_connections(). It terminates slave threads. However, some CHANGE MASTER etc may still be @@ -846,19 +870,24 @@ void end_slave() active_mi= 0; } pthread_mutex_unlock(&LOCK_active_mi); + DBUG_VOID_RETURN; } static bool io_slave_killed(THD* thd, MASTER_INFO* mi) { + DBUG_ENTER("io_slave_killed"); + DBUG_ASSERT(mi->io_thd == thd); DBUG_ASSERT(mi->slave_running); // tracking buffer overrun - return mi->abort_slave || abort_loop || thd->killed; + DBUG_RETURN(mi->abort_slave || abort_loop || thd->killed); } static bool sql_slave_killed(THD* thd, RELAY_LOG_INFO* rli) { + DBUG_ENTER("sql_slave_killed"); + DBUG_ASSERT(rli->sql_thd == thd); DBUG_ASSERT(rli->slave_running == 1);// tracking buffer overrun if (abort_loop || thd->killed || rli->abort_slave) @@ -873,7 +902,7 @@ static bool sql_slave_killed(THD* thd, RELAY_LOG_INFO* rli) is actively working. */ if (!rli->unsafe_to_stop_at) - return 1; + DBUG_RETURN(1); DBUG_PRINT("info", ("Slave SQL thread is in an unsafe situation, giving " "it some grace period")); if (difftime(time(0), rli->unsafe_to_stop_at) > 60) @@ -885,10 +914,10 @@ static bool sql_slave_killed(THD* thd, RELAY_LOG_INFO* rli) "There is a risk of duplicate updates when the slave " "SQL thread is restarted. Please check your tables' " "contents after restart."); - return 1; + DBUG_RETURN(1); } } - return 0; + DBUG_RETURN(0); } @@ -917,6 +946,8 @@ void slave_print_msg(enum loglevel level, RELAY_LOG_INFO* rli, char buff[MAX_SLAVE_ERRMSG], *pbuff= buff; uint pbuffsize= sizeof(buff); va_list args; + DBUG_ENTER("slave_print_msg"); + va_start(args,msg); switch (level) { @@ -943,7 +974,7 @@ void slave_print_msg(enum loglevel level, RELAY_LOG_INFO* rli, break; default: DBUG_ASSERT(0); // should not come here - return; // don't crash production builds, just do nothing + DBUG_VOID_RETURN; // don't crash production builds, just do nothing } my_vsnprintf(pbuff, pbuffsize, msg, args); /* If the msg string ends with '.', do not add a ',' it would be ugly */ @@ -951,6 +982,7 @@ void slave_print_msg(enum loglevel level, RELAY_LOG_INFO* rli, (*report_function)("Slave: %s Error_code: %d", pbuff, err_code); else (*report_function)("Slave: %s, Error_code: %d", pbuff, err_code); + DBUG_VOID_RETURN; } /* @@ -962,9 +994,12 @@ void slave_print_msg(enum loglevel level, RELAY_LOG_INFO* rli, void skip_load_data_infile(NET *net) { + DBUG_ENTER("skip_load_data_infile"); + (void)net_request_file(net, "/dev/null"); (void)my_net_read(net); // discard response (void)net_write_command(net, 0, "", 0, "", 0); // Send ok + DBUG_VOID_RETURN; } @@ -983,13 +1018,17 @@ bool net_request_file(NET* net, const char* fname) const char *print_slave_db_safe(const char* db) { - return (db ? db : ""); + DBUG_ENTER("*print_slave_db_safe"); + + DBUG_RETURN((db ? db : "")); } static int init_strvar_from_file(char *var, int max_size, IO_CACHE *f, const char *default_val) { uint length; + DBUG_ENTER("init_strvar_from_file"); + if ((length=my_b_gets(f,var, max_size))) { char* last_p = var + length -1; @@ -1004,32 +1043,34 @@ static int init_strvar_from_file(char *var, int max_size, IO_CACHE *f, int c; while (((c=my_b_get(f)) != '\n' && c != my_b_EOF)); } - return 0; + DBUG_RETURN(0); } else if (default_val) { strmake(var, default_val, max_size-1); - return 0; + DBUG_RETURN(0); } - return 1; + DBUG_RETURN(1); } static int init_intvar_from_file(int* var, IO_CACHE* f, int default_val) { char buf[32]; + DBUG_ENTER("init_intvar_from_file"); + if (my_b_gets(f, buf, sizeof(buf))) { *var = atoi(buf); - return 0; + DBUG_RETURN(0); } else if (default_val) { *var = default_val; - return 0; + DBUG_RETURN(0); } - return 1; + DBUG_RETURN(1); } /* @@ -1049,6 +1090,7 @@ static int init_intvar_from_file(int* var, IO_CACHE* f, int default_val) static int get_master_version_and_clock(MYSQL* mysql, MASTER_INFO* mi) { const char* errmsg= 0; + DBUG_ENTER("get_master_version_and_clock"); /* Free old description_event_for_queue (that is needed if we are in @@ -1104,14 +1146,14 @@ static int get_master_version_and_clock(MYSQL* mysql, MASTER_INFO* mi) if (errmsg) { sql_print_error(errmsg); - return 1; + DBUG_RETURN(1); } /* as we are here, we tried to allocate the event */ if (!mi->rli.relay_log.description_event_for_queue) { sql_print_error("Slave I/O thread failed to create a default Format_description_log_event"); - return 1; + DBUG_RETURN(1); } /* @@ -1227,10 +1269,10 @@ err: if (errmsg) { sql_print_error(errmsg); - return 1; + DBUG_RETURN(1); } - return 0; + DBUG_RETURN(0); } /* @@ -1257,7 +1299,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, handler *file; ulong save_options; NET *net= &mysql->net; - DBUG_ENTER("create_table_from_dump"); + DBUG_ENTER("create_table_from_dump"); packet_len= my_net_read(net); // read create table statement if (packet_len == packet_error) @@ -1666,7 +1708,6 @@ static bool wait_for_relay_log_space(RELAY_LOG_INFO* rli) MASTER_INFO* mi = rli->mi; const char *save_proc_info; THD* thd = mi->io_thd; - DBUG_ENTER("wait_for_relay_log_space"); pthread_mutex_lock(&rli->log_space_lock); @@ -1725,6 +1766,8 @@ static void write_ignored_events_info_to_relay_log(THD *thd, MASTER_INFO *mi) { RELAY_LOG_INFO *rli= &mi->rli; pthread_mutex_t *log_lock= rli->relay_log.get_log_lock(); + DBUG_ENTER("write_ignored_events_info_to_relay_log"); + DBUG_ASSERT(thd == mi->io_thd); pthread_mutex_lock(log_lock); if (rli->ign_master_log_name_end[0]) @@ -1755,11 +1798,14 @@ static void write_ignored_events_info_to_relay_log(THD *thd, MASTER_INFO *mi) } else pthread_mutex_unlock(log_lock); + DBUG_VOID_RETURN; } void init_master_info_with_options(MASTER_INFO* mi) { + DBUG_ENTER("init_master_info_with_options"); + mi->master_log_name[0] = 0; mi->master_log_pos = BIN_LOG_HEADER_SIZE; // skip magic number @@ -1783,13 +1829,17 @@ void init_master_info_with_options(MASTER_INFO* mi) strmake(mi->ssl_cipher, master_ssl_cipher, sizeof(mi->ssl_cipher)-1); if (master_ssl_key) strmake(mi->ssl_key, master_ssl_key, sizeof(mi->ssl_key)-1); + DBUG_VOID_RETURN; } void clear_slave_error(RELAY_LOG_INFO* rli) { + DBUG_ENTER("clear_slave_error"); + /* Clear the errors displayed by SHOW SLAVE STATUS */ rli->last_slave_error[0]= 0; rli->last_slave_errno= 0; + DBUG_VOID_RETURN; } /* @@ -1800,9 +1850,12 @@ void clear_slave_error(RELAY_LOG_INFO* rli) */ void clear_until_condition(RELAY_LOG_INFO* rli) { + DBUG_ENTER("clear_until_condition"); + rli->until_condition= RELAY_LOG_INFO::UNTIL_NONE; rli->until_log_name[0]= 0; rli->until_log_pos= 0; + DBUG_VOID_RETURN; } @@ -2031,9 +2084,10 @@ int register_slave_on_master(MYSQL* mysql) { char buf[1024], *pos= buf; uint report_host_len, report_user_len=0, report_password_len=0; + DBUG_ENTER("register_slave_on_master"); if (!report_host) - return 0; + DBUG_RETURN(0); report_host_len= strlen(report_host); if (report_user) report_user_len= strlen(report_user); @@ -2042,7 +2096,7 @@ int register_slave_on_master(MYSQL* mysql) /* 30 is a good safety margin */ if (report_host_len + report_user_len + report_password_len + 30 > sizeof(buf)) - return 0; // safety + DBUG_RETURN(0); // safety int4store(pos, server_id); pos+= 4; pos= net_store_data(pos, report_host, report_host_len); @@ -2059,9 +2113,9 @@ int register_slave_on_master(MYSQL* mysql) sql_print_error("Error on COM_REGISTER_SLAVE: %d '%s'", mysql_errno(mysql), mysql_error(mysql)); - return 1; + DBUG_RETURN(1); } - return 0; + DBUG_RETURN(0); } @@ -2313,6 +2367,8 @@ st_relay_log_info::st_relay_log_info() m_reload_flags(RELOAD_NONE_F), unsafe_to_stop_at(0) { + DBUG_ENTER("st_relay_log_info::st_relay_log_info"); + group_relay_log_name[0]= event_relay_log_name[0]= group_master_log_name[0]= 0; last_slave_error[0]= until_log_name[0]= ign_master_log_name_end[0]= 0; @@ -2327,11 +2383,14 @@ st_relay_log_info::st_relay_log_info() pthread_cond_init(&stop_cond, NULL); pthread_cond_init(&log_space_cond, NULL); relay_log.init_pthread_objects(); + DBUG_VOID_RETURN; } st_relay_log_info::~st_relay_log_info() { + DBUG_ENTER("st_relay_log_info::~st_relay_log_info"); + pthread_mutex_destroy(&run_lock); pthread_mutex_destroy(&data_lock); pthread_mutex_destroy(&log_space_lock); @@ -2340,6 +2399,7 @@ st_relay_log_info::~st_relay_log_info() pthread_cond_destroy(&stop_cond); pthread_cond_destroy(&log_space_cond); relay_log.cleanup(); + DBUG_VOID_RETURN; } /* @@ -2371,14 +2431,16 @@ int st_relay_log_info::wait_for_pos(THD* thd, String* log_name, longlong log_pos, longlong timeout) { - if (!inited) - return -1; int event_count = 0; ulong init_abort_pos_wait; int error=0; struct timespec abstime; // for timeout checking const char *msg; - DBUG_ENTER("wait_for_pos"); + DBUG_ENTER("st_relay_log_info::wait_for_pos"); + + if (!inited) + DBUG_RETURN(-1); + DBUG_PRINT("enter",("log_name: '%s' log_pos: %lu timeout: %lu", log_name->c_ptr(), (ulong) log_pos, (ulong) timeout)); @@ -2546,13 +2608,18 @@ improper_arguments: %d timed_out: %d", void set_slave_thread_options(THD* thd) { + DBUG_ENTER("set_slave_thread_options"); + thd->options = ((opt_log_slave_updates) ? OPTION_BIN_LOG:0) | OPTION_AUTO_IS_NULL; thd->variables.completion_type= 0; + DBUG_VOID_RETURN; } void set_slave_thread_default_charset(THD* thd, RELAY_LOG_INFO *rli) { + DBUG_ENTER("set_slave_thread_default_charset"); + thd->variables.character_set_client= global_system_variables.character_set_client; thd->variables.collation_connection= @@ -2561,6 +2628,7 @@ void set_slave_thread_default_charset(THD* thd, RELAY_LOG_INFO *rli) global_system_variables.collation_server; thd->update_charset(); rli->cached_charset_invalidate(); + DBUG_VOID_RETURN; } /* @@ -2622,6 +2690,8 @@ static int safe_sleep(THD* thd, int sec, CHECK_KILLED_FUNC thread_killed, { int nap_time; thr_alarm_t alarmed; + DBUG_ENTER("safe_sleep"); + thr_alarm_init(&alarmed); time_t start_time= time((time_t*) 0); time_t end_time= start_time+sec; @@ -2639,10 +2709,10 @@ static int safe_sleep(THD* thd, int sec, CHECK_KILLED_FUNC thread_killed, thr_end_alarm(&alarmed); if ((*thread_killed)(thd,thread_killed_arg)) - return 1; + DBUG_RETURN(1); start_time=time((time_t*) 0); } - return 0; + DBUG_RETURN(0); } @@ -2684,13 +2754,15 @@ static int request_dump(MYSQL* mysql, MASTER_INFO* mi, static int request_table_dump(MYSQL* mysql, const char* db, const char* table) { char buf[1024]; + DBUG_ENTER("request_table_dump"); + char * p = buf; uint table_len = (uint) strlen(table); uint db_len = (uint) strlen(db); if (table_len + db_len > sizeof(buf) - 2) { sql_print_error("request_table_dump: Buffer overrun"); - return 1; + DBUG_RETURN(1); } *p++ = db_len; @@ -2703,10 +2775,10 @@ static int request_table_dump(MYSQL* mysql, const char* db, const char* table) { sql_print_error("request_table_dump: Error sending the table dump \ command"); - return 1; + DBUG_RETURN(1); } - return 0; + DBUG_RETURN(0); } @@ -2730,6 +2802,7 @@ command"); static ulong read_event(MYSQL* mysql, MASTER_INFO *mi, bool* suppress_warnings) { ulong len; + DBUG_ENTER("read_event"); *suppress_warnings= 0; /* @@ -2738,7 +2811,7 @@ static ulong read_event(MYSQL* mysql, MASTER_INFO *mi, bool* suppress_warnings) */ #ifndef DBUG_OFF if (disconnect_slave_event_count && !(mi->events_till_disconnect--)) - return packet_error; + DBUG_RETURN(packet_error); #endif len = net_safe_read(mysql); @@ -2756,7 +2829,7 @@ static ulong read_event(MYSQL* mysql, MASTER_INFO *mi, bool* suppress_warnings) else sql_print_error("Error reading packet from server: %s ( server_errno=%d)", mysql_error(mysql), mysql_errno(mysql)); - return packet_error; + DBUG_RETURN(packet_error); } /* Check if eof packet */ @@ -2765,25 +2838,27 @@ static ulong read_event(MYSQL* mysql, MASTER_INFO *mi, bool* suppress_warnings) sql_print_information("Slave: received end packet from server, apparent " "master shutdown: %s", mysql_error(mysql)); - return packet_error; + DBUG_RETURN(packet_error); } DBUG_PRINT("info",( "len=%u, net->read_pos[4] = %d\n", len, mysql->net.read_pos[4])); - return len - 1; + DBUG_RETURN(len - 1); } int check_expected_error(THD* thd, RELAY_LOG_INFO* rli, int expected_error) { + DBUG_ENTER("check_expected_error"); + switch (expected_error) { case ER_NET_READ_ERROR: case ER_NET_ERROR_ON_WRITE: case ER_SERVER_SHUTDOWN: case ER_NEW_ABORTING_CONNECTION: - return 1; + DBUG_RETURN(1); default: - return 0; + DBUG_RETURN(0); } } @@ -2819,6 +2894,7 @@ bool st_relay_log_info::is_until_satisfied() { const char *log_name; ulonglong log_pos; + DBUG_ENTER("st_relay_log_info::is_until_satisfied"); DBUG_ASSERT(until_condition != UNTIL_NONE); @@ -2865,34 +2941,39 @@ bool st_relay_log_info::is_until_satisfied() /* Probably error so we aborting */ sql_print_error("Slave SQL thread is stopped because UNTIL " "condition is bad."); - return TRUE; + DBUG_RETURN(TRUE); } } else - return until_log_pos == 0; + DBUG_RETURN(until_log_pos == 0); } - return ((until_log_names_cmp_result == UNTIL_LOG_NAMES_CMP_EQUAL && + DBUG_RETURN(((until_log_names_cmp_result == UNTIL_LOG_NAMES_CMP_EQUAL && log_pos >= until_log_pos) || - until_log_names_cmp_result == UNTIL_LOG_NAMES_CMP_GREATER); + until_log_names_cmp_result == UNTIL_LOG_NAMES_CMP_GREATER)); } void st_relay_log_info::cached_charset_invalidate() { + DBUG_ENTER("st_relay_log_info::cached_charset_invalidate"); + /* Full of zeroes means uninitialized. */ bzero(cached_charset, sizeof(cached_charset)); + DBUG_VOID_RETURN; } bool st_relay_log_info::cached_charset_compare(char *charset) { + DBUG_ENTER("st_relay_log_info::cached_charset_compare"); + if (bcmp(cached_charset, charset, sizeof(cached_charset))) { memcpy(cached_charset, charset, sizeof(cached_charset)); - return 1; + DBUG_RETURN(1); } - return 0; + DBUG_RETURN(0); } /* @@ -2904,8 +2985,10 @@ bool st_relay_log_info::cached_charset_compare(char *charset) */ static int has_temporary_error(THD *thd) { + DBUG_ENTER("has_temporary_error"); + if (thd->is_fatal_error) - return 0; + DBUG_RETURN(0); /* Temporary error codes: @@ -2914,7 +2997,7 @@ static int has_temporary_error(THD *thd) */ if (thd->net.last_errno == ER_LOCK_DEADLOCK || thd->net.last_errno == ER_LOCK_WAIT_TIMEOUT) - return 1; + DBUG_RETURN(1); #ifdef HAVE_NDB_BINLOG /* @@ -2928,17 +3011,19 @@ static int has_temporary_error(THD *thd) switch (err->code) { case ER_GET_TEMPORARY_ERRMSG: - return 1; + DBUG_RETURN(1); default: break; } } #endif - return 0; + DBUG_RETURN(0); } static int exec_relay_log_event(THD* thd, RELAY_LOG_INFO* rli) { + DBUG_ENTER("exec_relay_log_event"); + /* We acquire this mutex since we need it for all operations except event execution. But we will release it in places where we will @@ -2965,7 +3050,7 @@ static int exec_relay_log_event(THD* thd, RELAY_LOG_INFO* rli) */ rli->abort_slave= 1; pthread_mutex_unlock(&rli->data_lock); - return 1; + DBUG_RETURN(1); } Log_event * ev = next_event(rli); @@ -2976,7 +3061,7 @@ static int exec_relay_log_event(THD* thd, RELAY_LOG_INFO* rli) { pthread_mutex_unlock(&rli->data_lock); delete ev; - return 1; + DBUG_RETURN(1); } if (ev) { @@ -3044,7 +3129,7 @@ static int exec_relay_log_event(THD* thd, RELAY_LOG_INFO* rli) --rli->slave_skip_counter; pthread_mutex_unlock(&rli->data_lock); delete ev; - return 0; // avoid infinite update loops + DBUG_RETURN(0); // avoid infinite update loops } pthread_mutex_unlock(&rli->data_lock); @@ -3125,13 +3210,11 @@ static int exec_relay_log_event(THD* thd, RELAY_LOG_INFO* rli) */ rli->trans_retries= 0; // restart from fresh } - } - return exec_res; + } + DBUG_RETURN(exec_res); } - else - { - pthread_mutex_unlock(&rli->data_lock); - slave_print_msg(ERROR_LEVEL, rli, 0, "\ + pthread_mutex_unlock(&rli->data_lock); + slave_print_msg(ERROR_LEVEL, rli, 0, "\ Could not parse relay log event entry. The possible reasons are: the master's \ binary log is corrupted (you can check this by running 'mysqlbinlog' on the \ binary log), the slave's relay log is corrupted (you can check this by running \ @@ -3140,8 +3223,7 @@ or slave's MySQL code. If you want to check the master's binary log or slave's \ relay log, you will be able to know their names by issuing 'SHOW SLAVE STATUS' \ on this slave.\ "); - return 1; - } + DBUG_RETURN(1); } @@ -3461,6 +3543,7 @@ pthread_handler_t handle_slave_sql(void *arg) { THD *thd; /* needs to be first for thread_stack */ char llbuff[22],llbuff1[22]; + RELAY_LOG_INFO* rli = &((MASTER_INFO*)arg)->rli; const char *errmsg; @@ -4060,16 +4143,18 @@ err: static int queue_old_event(MASTER_INFO *mi, const char *buf, ulong event_len) { + DBUG_ENTER("queue_old_event"); + switch (mi->rli.relay_log.description_event_for_queue->binlog_version) { case 1: - return queue_binlog_ver_1_event(mi,buf,event_len); + DBUG_RETURN(queue_binlog_ver_1_event(mi,buf,event_len)); case 3: - return queue_binlog_ver_3_event(mi,buf,event_len); + DBUG_RETURN(queue_binlog_ver_3_event(mi,buf,event_len)); default: /* unsupported format; eg version 2 */ DBUG_PRINT("info",("unsupported binlog format %d in queue_old_event()", mi->rli.relay_log.description_event_for_queue->binlog_version)); - return 1; + DBUG_RETURN(1); } } @@ -4282,7 +4367,9 @@ void end_relay_log_info(RELAY_LOG_INFO* rli) static int safe_connect(THD* thd, MYSQL* mysql, MASTER_INFO* mi) { - return connect_to_master(thd, mysql, mi, 0, 0); + DBUG_ENTER("safe_connect"); + + DBUG_RETURN(connect_to_master(thd, mysql, mi, 0, 0)); } @@ -4439,9 +4526,10 @@ static int safe_reconnect(THD* thd, MYSQL* mysql, MASTER_INFO* mi, bool flush_relay_log_info(RELAY_LOG_INFO* rli) { bool error=0; + DBUG_ENTER("flush_relay_log_info"); if (unlikely(rli->no_storage)) - return 0; + DBUG_RETURN(0); IO_CACHE *file = &rli->info_file; char buff[FN_REFLEN*2+22*2+4], *pos; @@ -4461,7 +4549,7 @@ bool flush_relay_log_info(RELAY_LOG_INFO* rli) error=1; /* Flushing the relay log is done by the slave I/O thread */ - return error; + DBUG_RETURN(error); } @@ -4471,9 +4559,9 @@ bool flush_relay_log_info(RELAY_LOG_INFO* rli) static IO_CACHE *reopen_relay_log(RELAY_LOG_INFO *rli, const char **errmsg) { + DBUG_ENTER("reopen_relay_log"); DBUG_ASSERT(rli->cur_log != &rli->cache_buf); DBUG_ASSERT(rli->cur_log_fd == -1); - DBUG_ENTER("reopen_relay_log"); IO_CACHE *cur_log = rli->cur_log=&rli->cache_buf; if ((rli->cur_log_fd=open_binlog(cur_log,rli->event_relay_log_name, @@ -4494,11 +4582,11 @@ static Log_event* next_event(RELAY_LOG_INFO* rli) { Log_event* ev; IO_CACHE* cur_log = rli->cur_log; - pthread_mutex_t *log_lock = rli->relay_log.get_log_lock(); + pthread_mutex_t *log_lock = rli->relay_log.get_log_lock(); const char* errmsg=0; THD* thd = rli->sql_thd; - DBUG_ENTER("next_event"); + DBUG_ASSERT(thd != 0); #ifndef DBUG_OFF @@ -4909,12 +4997,16 @@ static int reload_entry_compare(const void *lhs, const void *rhs) { const char *lstr = static_cast<const char *>(lhs); const char *rstr = static_cast<const st_reload_entry*>(rhs)->table; - return strcmp(lstr, rstr); + DBUG_ENTER("reload_entry_compare"); + + DBUG_RETURN(strcmp(lstr, rstr)); } void st_relay_log_info::touching_table(char const* db, char const* table, ulong table_id) { + DBUG_ENTER("st_relay_log_info::touching_table"); + if (strcmp(db,"mysql") == 0) { #if defined(HAVE_BSEARCH) && defined(HAVE_SIZE_T) @@ -4935,10 +5027,13 @@ void st_relay_log_info::touching_table(char const* db, char const* table, if (entry) m_reload_flags|= entry->flag; } + DBUG_VOID_RETURN; } void st_relay_log_info::transaction_end(THD* thd) { + DBUG_ENTER("st_relay_log_info::transaction_end"); + if (m_reload_flags != RELOAD_NONE_F) { if (m_reload_flags & RELOAD_ACCESS_F) @@ -4949,11 +5044,14 @@ void st_relay_log_info::transaction_end(THD* thd) m_reload_flags= RELOAD_NONE_F; } + DBUG_VOID_RETURN; } #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) void st_relay_log_info::cleanup_context(THD *thd, bool error) { + DBUG_ENTER("st_relay_log_info::cleanup_context"); + DBUG_ASSERT(sql_thd == thd); /* 1) Instances of Table_map_log_event, if ::exec_event() was called on them, @@ -4976,6 +5074,7 @@ void st_relay_log_info::cleanup_context(THD *thd, bool error) close_thread_tables(thd); clear_tables_to_lock(); unsafe_to_stop_at= 0; + DBUG_VOID_RETURN; } #endif diff --git a/sql/sp.cc b/sql/sp.cc index 2dd38429c1f..653c04ee11a 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -411,15 +411,13 @@ db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp, ulong old_sql_mode= thd->variables.sql_mode; ha_rows old_select_limit= thd->variables.select_limit; sp_rcontext *old_spcont= thd->spcont; - + char definer_user_name_holder[USERNAME_LENGTH + 1]; - LEX_STRING_WITH_INIT definer_user_name(definer_user_name_holder, - USERNAME_LENGTH); + LEX_STRING definer_user_name= { definer_user_name_holder, USERNAME_LENGTH }; char definer_host_name_holder[HOSTNAME_LENGTH + 1]; - LEX_STRING_WITH_INIT definer_host_name(definer_host_name_holder, - HOSTNAME_LENGTH); - + LEX_STRING definer_host_name= { definer_host_name_holder, HOSTNAME_LENGTH }; + int ret; thd->variables.sql_mode= sql_mode; diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 54c4ecb789f..b3c35ad5022 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -202,6 +202,7 @@ sp_get_flags_for_command(LEX *lex) case SQLCOM_SHOW_PROC_CODE: case SQLCOM_SHOW_FUNC_CODE: case SQLCOM_SHOW_AUTHORS: + case SQLCOM_SHOW_CONTRIBUTORS: case SQLCOM_REPAIR: case SQLCOM_BACKUP_TABLE: case SQLCOM_RESTORE_TABLE: @@ -249,6 +250,7 @@ sp_get_flags_for_command(LEX *lex) case SQLCOM_TRUNCATE: case SQLCOM_COMMIT: case SQLCOM_ROLLBACK: + case SQLCOM_LOAD: case SQLCOM_LOAD_MASTER_DATA: case SQLCOM_LOCK_TABLES: case SQLCOM_CREATE_PROCEDURE: @@ -315,14 +317,16 @@ sp_prepare_func_item(THD* thd, Item **it_addr) */ bool -sp_eval_expr(THD *thd, Field *result_field, Item *expr_item) +sp_eval_expr(THD *thd, Field *result_field, Item **expr_item_ptr) { + Item *expr_item; + DBUG_ENTER("sp_eval_expr"); - if (!expr_item) + if (!*expr_item_ptr) DBUG_RETURN(TRUE); - if (!(expr_item= sp_prepare_func_item(thd, &expr_item))) + if (!(expr_item= sp_prepare_func_item(thd, expr_item_ptr))) DBUG_RETURN(TRUE); bool err_status= FALSE; @@ -951,6 +955,7 @@ sp_head::execute(THD *thd) bool err_status= FALSE; uint ip= 0; ulong save_sql_mode; + bool save_abort_on_warning; Query_arena *old_arena; /* per-instruction arena */ MEM_ROOT execute_mem_root; @@ -1011,6 +1016,10 @@ sp_head::execute(THD *thd) thd->derived_tables= 0; save_sql_mode= thd->variables.sql_mode; thd->variables.sql_mode= m_sql_mode; + save_abort_on_warning= thd->abort_on_warning; + thd->abort_on_warning= + (m_sql_mode & (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)); + /* It is also more efficient to save/restore current thd->lex once when do it in each instruction @@ -1143,6 +1152,7 @@ sp_head::execute(THD *thd) DBUG_ASSERT(!thd->derived_tables); thd->derived_tables= old_derived_tables; thd->variables.sql_mode= save_sql_mode; + thd->abort_on_warning= save_abort_on_warning; thd->stmt_arena= old_arena; state= EXECUTED; @@ -1219,18 +1229,22 @@ bool sp_head::execute_function(THD *thd, Item **argp, uint argcount, Field *return_value_fld) { - Item_cache **param_values; ulonglong binlog_save_options; bool need_binlog_call; - uint params; + uint arg_no; sp_rcontext *octx = thd->spcont; sp_rcontext *nctx = NULL; + char buf[STRING_BUFFER_USUAL_SIZE]; + String binlog_buf(buf, sizeof(buf), &my_charset_bin); bool err_status= FALSE; + MEM_ROOT call_mem_root; + Query_arena call_arena(&call_mem_root, Query_arena::INITIALIZED_FOR_SP); + Query_arena backup_arena; + DBUG_ENTER("sp_head::execute_function"); DBUG_PRINT("info", ("function %s", m_name.str)); LINT_INIT(binlog_save_options); - params= m_pcont->context_var_count(); /* Check that the function is called with all specified arguments. @@ -1238,74 +1252,97 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, If it is not, use my_error() to report an error, or it will not terminate the invoking query properly. */ - - if (argcount != params) + if (argcount != m_pcont->context_var_count()) { /* Need to use my_error here, or it will not terminate the invoking query properly. */ my_error(ER_SP_WRONG_NO_OF_ARGS, MYF(0), - "FUNCTION", m_qname.str, params, argcount); + "FUNCTION", m_qname.str, m_pcont->context_var_count(), argcount); DBUG_RETURN(TRUE); } - - /* Allocate param_values to be used for dumping the call into binlog. */ - - if (!(param_values= (Item_cache**)thd->alloc(sizeof(Item_cache*)*argcount))) - DBUG_RETURN(TRUE); - - // QQ Should have some error checking here? (types, etc...) + /* + Prepare arena and memroot for objects which lifetime is whole + duration of function call (sp_rcontext, it's tables and items, + sp_cursor and Item_cache holders for case expressions). + We can't use caller's arena/memroot for those objects because + in this case some fixed amount of memory will be consumed for + each function/trigger invocation and so statements which involve + lot of them will hog memory. + TODO: we should create sp_rcontext once per command and reuse + it on subsequent executions of a function/trigger. + */ + init_sql_alloc(&call_mem_root, MEM_ROOT_BLOCK_SIZE, 0); + thd->set_n_backup_active_arena(&call_arena, &backup_arena); if (!(nctx= new sp_rcontext(m_pcont, return_value_fld, octx)) || nctx->init(thd)) { - delete nctx; /* Delete nctx if it was init() that failed. */ - DBUG_RETURN(TRUE); + thd->restore_active_arena(&call_arena, &backup_arena); + err_status= TRUE; + goto err_with_cleanup; } + /* + We have to switch temporarily back to callers arena/memroot. + Function arguments belong to the caller and so the may reference + memory which they will allocate during calculation long after + this function call will be finished (e.g. in Item::cleanup()). + */ + thd->restore_active_arena(&call_arena, &backup_arena); + #ifndef DBUG_OFF nctx->sp= this; #endif /* Pass arguments. */ - + for (arg_no= 0; arg_no < argcount; arg_no++) { - uint i; - - for (i= 0 ; i < argcount ; i++) - { - if (!argp[i]->fixed && argp[i]->fix_fields(thd, &argp[i])) - { - err_status= TRUE; - break; - } - - param_values[i]= Item_cache::get_cache(argp[i]->result_type()); - param_values[i]->store(argp[i]); - - if (nctx->set_variable(thd, i, param_values[i])) - { - err_status= TRUE; - break; - } - } - } + /* Arguments must be fixed in Item_func_sp::fix_fields */ + DBUG_ASSERT(argp[arg_no]->fixed); - if (err_status) - { - delete nctx; - DBUG_RETURN(TRUE); + if ((err_status= nctx->set_variable(thd, arg_no, &(argp[arg_no])))) + goto err_with_cleanup; } - thd->spcont= nctx; - /* If row-based binlogging, we don't need to binlog the function's call, let each substatement be binlogged its way. */ need_binlog_call= mysql_bin_log.is_open() && (thd->options & OPTION_BIN_LOG) && !thd->current_stmt_binlog_row_based; + + /* + Remember the original arguments for unrolled replication of functions + before they are changed by execution. + */ + if (need_binlog_call) + { + binlog_buf.length(0); + binlog_buf.append(STRING_WITH_LEN("SELECT ")); + append_identifier(thd, &binlog_buf, m_name.str, m_name.length); + binlog_buf.append('('); + for (arg_no= 0; arg_no < argcount; arg_no++) + { + String str_value_holder; + String *str_value; + + if (arg_no) + binlog_buf.append(','); + + str_value= sp_get_item_value(nctx->get_item(arg_no), + &str_value_holder); + + if (str_value) + binlog_buf.append(*str_value); + else + binlog_buf.append(STRING_WITH_LEN("NULL")); + } + binlog_buf.append(')'); + } + thd->spcont= nctx; + if (need_binlog_call) { reset_dynamic(&thd->user_var_events); @@ -1314,38 +1351,27 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, thd->options&= ~OPTION_BIN_LOG; } + /* + Switch to call arena/mem_root so objects like sp_cursor or + Item_cache holders for case expressions can be allocated on it. + + TODO: In future we should associate call arena/mem_root with + sp_rcontext and allocate all these objects (and sp_rcontext + itself) on it directly rather than juggle with arenas. + */ + thd->set_n_backup_active_arena(&call_arena, &backup_arena); + err_status= execute(thd); + thd->restore_active_arena(&call_arena, &backup_arena); + if (need_binlog_call) { mysql_bin_log.stop_union_events(thd); thd->options= binlog_save_options; if (thd->binlog_evt_union.unioned_events) { - char buf[256]; - String bufstr(buf, sizeof(buf), &my_charset_bin); - bufstr.length(0); - bufstr.append(STRING_WITH_LEN("SELECT ")); - append_identifier(thd, &bufstr, m_name.str, m_name.length); - bufstr.append('('); - for (uint i=0; i < argcount; i++) - { - String str_value_holder; - String *str_value; - - if (i) - bufstr.append(','); - - str_value= sp_get_item_value(param_values[i], &str_value_holder); - - if (str_value) - bufstr.append(*str_value); - else - bufstr.append(STRING_WITH_LEN("NULL")); - } - bufstr.append(')'); - - Query_log_event qinfo(thd, bufstr.ptr(), bufstr.length(), + Query_log_event qinfo(thd, binlog_buf.ptr(), binlog_buf.length(), thd->binlog_evt_union.unioned_events_trans, FALSE); if (mysql_bin_log.write(&qinfo) && thd->binlog_evt_union.unioned_events_trans) @@ -1369,27 +1395,19 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, } } + nctx->pop_all_cursors(); // To avoid memory leaks after an error + +err_with_cleanup: delete nctx; + call_arena.free_items(); + free_root(&call_mem_root, MYF(0)); thd->spcont= octx; DBUG_RETURN(err_status); } -static Item_func_get_user_var *item_is_user_var(Item *it) -{ - if (it->type() == Item::FUNC_ITEM) - { - Item_func *fi= static_cast<Item_func*>(it); - - if (fi->functype() == Item_func::GUSERVAR_FUNC) - return static_cast<Item_func_get_user_var*>(fi); - } - return NULL; -} - - /* Execute a procedure. SYNOPSIS @@ -1467,22 +1485,28 @@ sp_head::execute_procedure(THD *thd, List<Item> *args) for (uint i= 0 ; i < params ; i++) { Item *arg_item= it_args++; - sp_variable_t *spvar= m_pcont->find_variable(i); if (!arg_item) break; + sp_variable_t *spvar= m_pcont->find_variable(i); + if (!spvar) continue; if (spvar->mode != sp_param_in) { - if (!arg_item->is_splocal() && !item_is_user_var(arg_item)) + Settable_routine_parameter *srp= + arg_item->get_settable_routine_parameter(); + + if (!srp) { my_error(ER_SP_NOT_VAR_ARG, MYF(0), i+1, m_qname.str); err_status= TRUE; break; } + + srp->set_required_privilege(spvar->mode == sp_param_inout); } if (spvar->mode == sp_param_out) @@ -1490,7 +1514,7 @@ sp_head::execute_procedure(THD *thd, List<Item> *args) Item_null *null_item= new Item_null(); if (!null_item || - nctx->set_variable(thd, i, null_item)) + nctx->set_variable(thd, i, (struct Item **)&null_item)) { err_status= TRUE; break; @@ -1498,7 +1522,7 @@ sp_head::execute_procedure(THD *thd, List<Item> *args) } else { - if (nctx->set_variable(thd, i, *it_args.ref())) + if (nctx->set_variable(thd, i, it_args.ref())) { err_status= TRUE; break; @@ -1566,36 +1590,16 @@ sp_head::execute_procedure(THD *thd, List<Item> *args) if (spvar->mode == sp_param_in) continue; - if (arg_item->is_splocal()) - { - if (octx->set_variable(thd, - ((Item_splocal*) arg_item)->get_var_idx(), - nctx->get_item(i))) - { - err_status= TRUE; - break; - } - } - else + Settable_routine_parameter *srp= + arg_item->get_settable_routine_parameter(); + + DBUG_ASSERT(srp); + + if (srp->set_value(thd, octx, nctx->get_item_addr(i))) { - Item_func_get_user_var *guv= item_is_user_var(arg_item); - - if (guv) - { - Item *item= nctx->get_item(i); - Item_func_set_user_var *suv; - - suv= new Item_func_set_user_var(guv->get_name(), item); - /* - Item_func_set_user_var is not fixed after construction, - call fix_fields(). - */ - if ((err_status= test(!suv || suv->fix_fields(thd, &item) || - suv->check() || suv->update()))) - break; - } + err_status= TRUE; + break; } - } } @@ -1821,10 +1825,10 @@ void sp_head::set_definer(const char *definer, uint definerlen) { char user_name_holder[USERNAME_LENGTH + 1]; - LEX_STRING_WITH_INIT user_name(user_name_holder, USERNAME_LENGTH); + LEX_STRING user_name= { user_name_holder, USERNAME_LENGTH }; char host_name_holder[HOSTNAME_LENGTH + 1]; - LEX_STRING_WITH_INIT host_name(host_name_holder, HOSTNAME_LENGTH); + LEX_STRING host_name= { host_name_holder, HOSTNAME_LENGTH }; parse_user(definer, definerlen, user_name.str, &user_name.length, host_name.str, &host_name.length); @@ -2372,7 +2376,7 @@ sp_instr_set::execute(THD *thd, uint *nextp) int sp_instr_set::exec_core(THD *thd, uint *nextp) { - int res= thd->spcont->set_variable(thd, m_offset, m_value); + int res= thd->spcont->set_variable(thd, m_offset, &m_value); if (res && thd->spcont->found_handler_here()) { @@ -2437,12 +2441,7 @@ sp_instr_set_trigger_field::execute(THD *thd, uint *nextp) int sp_instr_set_trigger_field::exec_core(THD *thd, uint *nextp) { - int res= 0; - Item *it= sp_prepare_func_item(thd, &value); - if (!it || - !trigger_field->fixed && trigger_field->fix_fields(thd, 0) || - (it->save_in_field(trigger_field->field, 0) < 0)) - res= -1; + const int res= (trigger_field->set_value(thd, &value) ? -1 : 0); *nextp = m_ip+1; return res; } @@ -2647,7 +2646,7 @@ sp_instr_freturn::exec_core(THD *thd, uint *nextp) do it in scope of execution the current context/block. */ - return thd->spcont->set_return_value(thd, m_value); + return thd->spcont->set_return_value(thd, &m_value); } void @@ -3091,7 +3090,7 @@ sp_instr_set_case_expr::execute(THD *thd, uint *nextp) int sp_instr_set_case_expr::exec_core(THD *thd, uint *nextp) { - int res= thd->spcont->set_case_expr(thd, m_case_expr_id, m_case_expr); + int res= thd->spcont->set_case_expr(thd, m_case_expr_id, &m_case_expr); if (res && !thd->spcont->get_case_expr(m_case_expr_id) && @@ -3105,7 +3104,7 @@ sp_instr_set_case_expr::exec_core(THD *thd, uint *nextp) Item *null_item= new Item_null(); if (!null_item || - thd->spcont->set_case_expr(thd, m_case_expr_id, null_item)) + thd->spcont->set_case_expr(thd, m_case_expr_id, &null_item)) { /* If this also failed, we have to abort. */ diff --git a/sql/sp_head.h b/sql/sp_head.h index fbc277b4de8..791343f0061 100644 --- a/sql/sp_head.h +++ b/sql/sp_head.h @@ -1170,6 +1170,6 @@ Item * sp_prepare_func_item(THD* thd, Item **it_addr); bool -sp_eval_expr(THD *thd, Field *result_field, Item *expr_item); +sp_eval_expr(THD *thd, Field *result_field, Item **expr_item_ptr); #endif /* _SP_HEAD_H_ */ diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc index 38b6de0e75a..3bc27a029d0 100644 --- a/sql/sp_rcontext.cc +++ b/sql/sp_rcontext.cc @@ -150,7 +150,7 @@ sp_rcontext::init_var_items() bool -sp_rcontext::set_return_value(THD *thd, Item *return_value_item) +sp_rcontext::set_return_value(THD *thd, Item **return_value_item) { DBUG_ASSERT(m_return_value_fld); @@ -279,14 +279,14 @@ sp_rcontext::pop_cursors(uint count) int -sp_rcontext::set_variable(THD *thd, uint var_idx, Item *value) +sp_rcontext::set_variable(THD *thd, uint var_idx, Item **value) { return set_variable(thd, m_var_table->field[var_idx], value); } int -sp_rcontext::set_variable(THD *thd, Field *field, Item *value) +sp_rcontext::set_variable(THD *thd, Field *field, Item **value) { if (!value) { @@ -478,9 +478,10 @@ sp_rcontext::create_case_expr_holder(THD *thd, Item_result result_type) */ int -sp_rcontext::set_case_expr(THD *thd, int case_expr_id, Item *case_expr_item) +sp_rcontext::set_case_expr(THD *thd, int case_expr_id, Item **case_expr_item_ptr) { - if (!(case_expr_item= sp_prepare_func_item(thd, &case_expr_item))) + Item *case_expr_item= sp_prepare_func_item(thd, case_expr_item_ptr); + if (!case_expr_item) return TRUE; if (!m_case_expr_holders[case_expr_id] || @@ -542,7 +543,7 @@ bool Select_fetch_into_spvars::send_data(List<Item> &items) */ for (; spvar= spvar_iter++, item= item_iter++; ) { - if (thd->spcont->set_variable(thd, spvar->offset, item)) + if (thd->spcont->set_variable(thd, spvar->offset, &item)) return TRUE; } return FALSE; diff --git a/sql/sp_rcontext.h b/sql/sp_rcontext.h index 20aaea3b7c1..30521f6da84 100644 --- a/sql/sp_rcontext.h +++ b/sql/sp_rcontext.h @@ -91,7 +91,7 @@ class sp_rcontext : public Sql_alloc ~sp_rcontext(); int - set_variable(THD *thd, uint var_idx, Item *value); + set_variable(THD *thd, uint var_idx, Item **value); Item * get_item(uint var_idx); @@ -100,7 +100,7 @@ class sp_rcontext : public Sql_alloc get_item_addr(uint var_idx); bool - set_return_value(THD *thd, Item *return_value_item); + set_return_value(THD *thd, Item **return_value_item); inline bool is_return_value_set() const @@ -200,7 +200,7 @@ class sp_rcontext : public Sql_alloc */ int - set_case_expr(THD *thd, int case_expr_id, Item *case_expr_item); + set_case_expr(THD *thd, int case_expr_id, Item **case_expr_item_ptr); Item * get_case_expr(int case_expr_id); @@ -254,7 +254,7 @@ private: Item_cache *create_case_expr_holder(THD *thd, Item_result result_type); - int set_variable(THD *thd, Field *field, Item *value); + int set_variable(THD *thd, Field *field, Item **value); }; // class sp_rcontext : public Sql_alloc diff --git a/sql/spatial.cc b/sql/spatial.cc index bcc92e75435..02f1525f2ad 100644 --- a/sql/spatial.cc +++ b/sql/spatial.cc @@ -34,8 +34,11 @@ static Geometry::Class_info **ci_collection_end= Geometry::Class_info::Class_info(const char *name, int type_id, void(*create_func)(void *)): - m_name(name, strlen(name)), m_type_id(type_id), m_create_func(create_func) + m_type_id(type_id), m_create_func(create_func) { + m_name.str= (char *) name; + m_name.length= strlen(name); + ci_collection[type_id]= this; } diff --git a/sql/spatial.h b/sql/spatial.h index a6f74a1ada0..36949ff5014 100644 --- a/sql/spatial.h +++ b/sql/spatial.h @@ -200,7 +200,7 @@ public: class Class_info { public: - LEX_STRING_WITH_INIT m_name; + LEX_STRING m_name; int m_type_id; void (*m_create_func)(void *); Class_info(const char *name, int type_id, void(*create_func)(void *)); diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index a35c69b668f..8eb7242dfab 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -990,8 +990,8 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh, if (acl_user->x509_issuer) { DBUG_PRINT("info",("checkpoint 3")); - char *ptr = X509_NAME_oneline(X509_get_issuer_name(cert), 0, 0); - DBUG_PRINT("info",("comparing issuers: '%s' and '%s'", + char *ptr = X509_NAME_oneline(X509_get_issuer_name(cert), 0, 0); + DBUG_PRINT("info",("comparing issuers: '%s' and '%s'", acl_user->x509_issuer, ptr)); if (strcmp(acl_user->x509_issuer, ptr)) { @@ -1091,6 +1091,8 @@ bool acl_getroot_no_password(Security_context *sctx, char *user, char *host, sctx->master_access= 0; sctx->db_access= 0; + sctx->priv_user= (char *) ""; + *sctx->priv_host= 0; /* Find acl entry in user database. @@ -1159,6 +1161,8 @@ static void acl_update_user(const char *user, const char *host, USER_RESOURCES *mqh, ulong privileges) { + safe_mutex_assert_owner(&acl_cache->lock); + for (uint i=0 ; i < acl_users.elements ; i++) { ACL_USER *acl_user=dynamic_element(&acl_users,i,ACL_USER*); @@ -1209,6 +1213,9 @@ static void acl_insert_user(const char *user, const char *host, ulong privileges) { ACL_USER acl_user; + + safe_mutex_assert_owner(&acl_cache->lock); + acl_user.user=*user ? strdup_root(&mem,user) : 0; update_hostname(&acl_user.host, *host ? strdup_root(&mem, host): 0); acl_user.access=privileges; @@ -1238,6 +1245,8 @@ static void acl_insert_user(const char *user, const char *host, static void acl_update_db(const char *user, const char *host, const char *db, ulong privileges) { + safe_mutex_assert_owner(&acl_cache->lock); + for (uint i=0 ; i < acl_dbs.elements ; i++) { ACL_DB *acl_db=dynamic_element(&acl_dbs,i,ACL_DB*); @@ -1663,6 +1672,9 @@ find_acl_user(const char *host, const char *user, my_bool exact) { DBUG_ENTER("find_acl_user"); DBUG_PRINT("enter",("host: '%s' user: '%s'",host,user)); + + safe_mutex_assert_owner(&acl_cache->lock); + for (uint i=0 ; i < acl_users.elements ; i++) { ACL_USER *acl_user=dynamic_element(&acl_users,i,ACL_USER*); @@ -1675,7 +1687,7 @@ find_acl_user(const char *host, const char *user, my_bool exact) if (!acl_user->user && !user[0] || acl_user->user && !strcmp(user,acl_user->user)) { - if (exact ? !my_strcasecmp(&my_charset_latin1, host, + if (exact ? !my_strcasecmp(system_charset_info, host, acl_user->host.hostname ? acl_user->host.hostname : "") : compare_hostname(&acl_user->host,host,host)) @@ -2989,7 +3001,6 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list, some kind of updates to the mysql.% tables. */ if (thd->slave_thread && rpl_filter->is_on()) - if (thd->slave_thread && rpl_filter->is_on()) { /* The tables must be marked "updating" so that tables_ok() takes them into @@ -3011,6 +3022,7 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list, create_new_users= test_if_create_new_users(thd); bool result= FALSE; rw_wrlock(&LOCK_grant); + pthread_mutex_lock(&acl_cache->lock); MEM_ROOT *old_root= thd->mem_root; thd->mem_root= &memex; grant_version++; @@ -3028,12 +3040,10 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list, continue; } /* Create user if needed */ - pthread_mutex_lock(&acl_cache->lock); error=replace_user_table(thd, tables[0].table, *Str, 0, revoke_grant, create_new_users, test(thd->variables.sql_mode & MODE_NO_AUTO_CREATE_USER)); - pthread_mutex_unlock(&acl_cache->lock); if (error) { result= TRUE; // Remember error @@ -3125,6 +3135,7 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list, } grant_option=TRUE; thd->mem_root= old_root; + pthread_mutex_unlock(&acl_cache->lock); rw_unlock(&LOCK_grant); if (!result) send_ok(thd); @@ -3217,6 +3228,7 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc, if (!revoke_grant) create_new_users= test_if_create_new_users(thd); rw_wrlock(&LOCK_grant); + pthread_mutex_lock(&acl_cache->lock); MEM_ROOT *old_root= thd->mem_root; thd->mem_root= &memex; @@ -3236,12 +3248,10 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc, continue; } /* Create user if needed */ - pthread_mutex_lock(&acl_cache->lock); error=replace_user_table(thd, tables[0].table, *Str, 0, revoke_grant, create_new_users, test(thd->variables.sql_mode & MODE_NO_AUTO_CREATE_USER)); - pthread_mutex_unlock(&acl_cache->lock); if (error) { result= TRUE; // Remember error @@ -3283,6 +3293,7 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc, } grant_option=TRUE; thd->mem_root= old_root; + pthread_mutex_unlock(&acl_cache->lock); rw_unlock(&LOCK_grant); if (!result && !no_error) send_ok(thd); @@ -3699,6 +3710,7 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables, TABLE_LIST *table, *first_not_own_table= thd->lex->first_not_own_table(); Security_context *sctx= thd->security_ctx; uint i; + ulong orig_want_access= want_access; DBUG_ENTER("check_grant"); DBUG_ASSERT(number > 0); @@ -3720,18 +3732,22 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables, table->grant.orig_want_privilege= (want_access & ~SHOW_VIEW_ACL); } - want_access&= ~sctx->master_access; - if (!want_access) - DBUG_RETURN(0); // ok - rw_rdlock(&LOCK_grant); for (table= tables; table && number-- && table != first_not_own_table; table= table->next_global) { GRANT_TABLE *grant_table; + sctx = test(table->security_ctx) ? + table->security_ctx : thd->security_ctx; + + want_access= orig_want_access; + want_access&= ~sctx->master_access; + if (!want_access) + continue; // ok + if (!(~table->grant.privilege & want_access) || - table->derived || table->schema_table || table->belong_to_view) + table->derived || table->schema_table) { /* It is subquery in the FROM clause. VIEW set table->derived after @@ -4263,20 +4279,15 @@ bool mysql_show_grants(THD *thd,LEX_USER *lex_user) DBUG_RETURN(TRUE); } - for (counter=0 ; counter < acl_users.elements ; counter++) - { - const char *user,*host; - acl_user=dynamic_element(&acl_users,counter,ACL_USER*); - if (!(user=acl_user->user)) - user= ""; - if (!(host=acl_user->host.hostname)) - host= ""; - if (!strcmp(lex_user->user.str,user) && - !my_strcasecmp(system_charset_info, lex_user->host.str, host)) - break; - } - if (counter == acl_users.elements) + rw_rdlock(&LOCK_grant); + VOID(pthread_mutex_lock(&acl_cache->lock)); + + acl_user= find_acl_user(lex_user->host.str, lex_user->user.str, TRUE); + if (!acl_user) { + VOID(pthread_mutex_unlock(&acl_cache->lock)); + rw_unlock(&LOCK_grant); + my_error(ER_NONEXISTING_GRANT, MYF(0), lex_user->user.str, lex_user->host.str); DBUG_RETURN(TRUE); @@ -4291,10 +4302,12 @@ bool mysql_show_grants(THD *thd,LEX_USER *lex_user) field_list.push_back(field); if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(TRUE); + { + VOID(pthread_mutex_unlock(&acl_cache->lock)); + rw_unlock(&LOCK_grant); - rw_wrlock(&LOCK_grant); - VOID(pthread_mutex_lock(&acl_cache->lock)); + DBUG_RETURN(TRUE); + } /* Add first global access grants */ { @@ -4702,10 +4715,15 @@ void get_privilege_desc(char *to, uint max_length, ulong access) void get_mqh(const char *user, const char *host, USER_CONN *uc) { ACL_USER *acl_user; + + pthread_mutex_lock(&acl_cache->lock); + if (initialized && (acl_user= find_acl_user(host,user, FALSE))) uc->user_resources= acl_user->user_resource; else bzero((char*) &uc->user_resources, sizeof(uc->user_resources)); + + pthread_mutex_unlock(&acl_cache->lock); } /* @@ -4785,31 +4803,6 @@ int open_grant_tables(THD *thd, TABLE_LIST *tables) DBUG_RETURN(0); } -ACL_USER *check_acl_user(LEX_USER *user_name, - uint *acl_acl_userdx) -{ - ACL_USER *acl_user= 0; - uint counter; - - for (counter= 0 ; counter < acl_users.elements ; counter++) - { - const char *user,*host; - acl_user= dynamic_element(&acl_users, counter, ACL_USER*); - if (!(user=acl_user->user)) - user= ""; - if (!(host=acl_user->host.hostname)) - host= ""; - if (!strcmp(user_name->user.str,user) && - !my_strcasecmp(system_charset_info, user_name->host.str, host)) - break; - } - if (counter == acl_users.elements) - return 0; - - *acl_acl_userdx= counter; - return acl_user; -} - /* Modify a privilege table. @@ -5057,6 +5050,8 @@ static int handle_grant_struct(uint struct_no, bool drop, LINT_INIT(user); LINT_INIT(host); + safe_mutex_assert_owner(&acl_cache->lock); + /* Get the number of elements in the in-memory structure. */ switch (struct_no) { case 0: @@ -5519,7 +5514,7 @@ bool mysql_revoke_all(THD *thd, List <LEX_USER> &list) List_iterator <LEX_USER> user_list(list); while ((lex_user=user_list++)) { - if (!check_acl_user(lex_user, &counter)) + if (!find_acl_user(lex_user->host.str, lex_user->user.str, TRUE)) { sql_print_error("REVOKE ALL PRIVILEGES, GRANT: User '%s'@'%s' does not " "exists", lex_user->user.str, lex_user->host.str); @@ -5756,6 +5751,7 @@ bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, combo->user.str= sctx->user; + VOID(pthread_mutex_lock(&acl_cache->lock)); if (!find_acl_user(combo->host.str=(char*)sctx->host_or_ip, combo->user.str, FALSE) && !find_acl_user(combo->host.str=(char*)sctx->host, combo->user.str, @@ -5763,7 +5759,11 @@ bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, !find_acl_user(combo->host.str=(char*)sctx->ip, combo->user.str, FALSE) && !find_acl_user(combo->host.str=(char*)"%", combo->user.str, FALSE)) + { + VOID(pthread_mutex_unlock(&acl_cache->lock)); DBUG_RETURN(TRUE); + } + VOID(pthread_mutex_unlock(&acl_cache->lock)); bzero((char*)tables, sizeof(TABLE_LIST)); user_list.empty(); @@ -5881,6 +5881,8 @@ int fill_schema_user_privileges(THD *thd, TABLE_LIST *tables, COND *cond) char *curr_host= thd->security_ctx->priv_host_name(); DBUG_ENTER("fill_schema_user_privileges"); + pthread_mutex_lock(&acl_cache->lock); + for (counter=0 ; counter < acl_users.elements ; counter++) { const char *user,*host, *is_grantable="YES"; @@ -5916,6 +5918,9 @@ int fill_schema_user_privileges(THD *thd, TABLE_LIST *tables, COND *cond) } } } + + pthread_mutex_unlock(&acl_cache->lock); + DBUG_RETURN(0); #else return(0); @@ -5935,6 +5940,8 @@ int fill_schema_schema_privileges(THD *thd, TABLE_LIST *tables, COND *cond) char *curr_host= thd->security_ctx->priv_host_name(); DBUG_ENTER("fill_schema_schema_privileges"); + pthread_mutex_lock(&acl_cache->lock); + for (counter=0 ; counter < acl_dbs.elements ; counter++) { const char *user, *host, *is_grantable="YES"; @@ -5973,6 +5980,9 @@ int fill_schema_schema_privileges(THD *thd, TABLE_LIST *tables, COND *cond) } } } + + pthread_mutex_unlock(&acl_cache->lock); + DBUG_RETURN(0); #else return (0); @@ -5990,6 +6000,8 @@ int fill_schema_table_privileges(THD *thd, TABLE_LIST *tables, COND *cond) char *curr_host= thd->security_ctx->priv_host_name(); DBUG_ENTER("fill_schema_table_privileges"); + rw_rdlock(&LOCK_grant); + for (index=0 ; index < column_priv_hash.records ; index++) { const char *user, *is_grantable= "YES"; @@ -6035,6 +6047,9 @@ int fill_schema_table_privileges(THD *thd, TABLE_LIST *tables, COND *cond) } } } + + rw_unlock(&LOCK_grant); + DBUG_RETURN(0); #else return (0); @@ -6052,6 +6067,8 @@ int fill_schema_column_privileges(THD *thd, TABLE_LIST *tables, COND *cond) char *curr_host= thd->security_ctx->priv_host_name(); DBUG_ENTER("fill_schema_table_privileges"); + rw_rdlock(&LOCK_grant); + for (index=0 ; index < column_priv_hash.records ; index++) { const char *user, *is_grantable= "YES"; @@ -6103,6 +6120,9 @@ int fill_schema_column_privileges(THD *thd, TABLE_LIST *tables, COND *cond) } } } + + rw_unlock(&LOCK_grant); + DBUG_RETURN(0); #else return (0); @@ -6159,20 +6179,21 @@ void fill_effective_table_privileges(THD *thd, GRANT_INFO *grant, } /* table privileges */ + rw_rdlock(&LOCK_grant); if (grant->version != grant_version) { - rw_rdlock(&LOCK_grant); grant->grant_table= table_hash_search(sctx->host, sctx->ip, db, sctx->priv_user, table, 0); /* purecov: inspected */ grant->version= grant_version; /* purecov: inspected */ - rw_unlock(&LOCK_grant); } if (grant->grant_table != 0) { grant->privilege|= grant->grant_table->privs; } + rw_unlock(&LOCK_grant); + DBUG_PRINT("info", ("privilege 0x%lx", grant->privilege)); DBUG_VOID_RETURN; } diff --git a/sql/sql_acl.h b/sql/sql_acl.h index 8c64adbbece..e1153522ed5 100644 --- a/sql/sql_acl.h +++ b/sql/sql_acl.h @@ -236,7 +236,6 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table, List <LEX_USER> &user_list, bool mysql_routine_grant(THD *thd, TABLE_LIST *table, bool is_proc, List <LEX_USER> &user_list, ulong rights, bool revoke, bool no_error); -ACL_USER *check_acl_user(LEX_USER *user_name, uint *acl_acl_userdx); my_bool grant_init(); void grant_free(void); my_bool grant_reload(THD *thd); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index aa571497683..085f45193b5 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -25,7 +25,7 @@ #include <m_ctype.h> #include <my_dir.h> #include <hash.h> -#ifdef __WIN__ +#ifdef __WIN__ #include <io.h> #endif @@ -879,7 +879,7 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh, bool found=1; /* Wait until all threads has closed all the tables we had locked */ DBUG_PRINT("info", - ("Waiting for others threads to close their open tables")); + ("Waiting for other threads to close their open tables")); while (found && ! thd->killed) { found=0; @@ -890,6 +890,7 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh, ((table->s->version) < refresh_version && table->db_stat)) { found=1; + DBUG_PRINT("signal", ("Waiting for COND_refresh")); pthread_cond_wait(&COND_refresh,&LOCK_open); break; } @@ -1066,7 +1067,9 @@ void close_thread_tables(THD *thd, bool lock_in_use, bool skip_derived) handled either before writing a query log event (inside binlog_query()) or when preparing a pending event. */ +#ifdef HAVE_ROW_BASED_REPLICATION thd->binlog_flush_pending_rows_event(TRUE); +#endif /*HAVE_ROW_BASED_REPLICATION*/ mysql_unlock_tables(thd, thd->lock); thd->lock=0; } @@ -1280,7 +1283,7 @@ void close_temporary_tables(THD *thd) table= next) { end_cur= strxmov(end_cur, "`", table->s->db.str, "`.`", - table->s->table_name.str, "`,", NullS); + table->s->table_name.str, "`,", NullS); next= table->next; close_temporary(table, 1, 1); } @@ -1308,7 +1311,6 @@ void close_temporary_tables(THD *thd) thd->temporary_tables=0; } - /* Find table in list. @@ -1676,6 +1678,7 @@ void wait_for_condition(THD *thd, pthread_mutex_t *mutex, pthread_cond_t *cond) thd->mysys_var->current_cond= cond; proc_info=thd->proc_info; thd->proc_info="Waiting for table"; + DBUG_ENTER("wait_for_condition"); if (!thd->killed) (void) pthread_cond_wait(cond, mutex); @@ -1696,6 +1699,7 @@ void wait_for_condition(THD *thd, pthread_mutex_t *mutex, pthread_cond_t *cond) thd->mysys_var->current_cond= 0; thd->proc_info= proc_info; pthread_mutex_unlock(&thd->mysys_var->mutex); + DBUG_VOID_RETURN; } @@ -1784,6 +1788,8 @@ bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list) MYSQL_LOCK_IGNORE_FLUSH - Open table even if someone has done a flush or namelock on it. No version number checking is done. + MYSQL_OPEN_IGNORE_LOCKED_TABLES - Open table + ignoring set of locked tables and prelocked mode. IMPLEMENTATION Uses a cache of open tables to find a table not in use. @@ -1843,7 +1849,8 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, } } - if (thd->locked_tables || thd->prelocked_mode) + if (!(flags & MYSQL_OPEN_IGNORE_LOCKED_TABLES) && + (thd->locked_tables || thd->prelocked_mode)) { // Using table locks TABLE *best_table= 0; int best_distance= INT_MIN; @@ -1971,6 +1978,10 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, { if (table->s->version != refresh_version) { + DBUG_PRINT("note", + ("Found table '%s.%s' with different refresh version", + table_list->db, table_list->table_name)); + /* Don't close tables if we are working with a log table or were asked not to close the table explicitly @@ -5396,6 +5407,58 @@ bool setup_tables(THD *thd, Name_resolution_context *context, /* + prepare tables and check access for the view tables + + SYNOPSIS + setup_tables_and_check_view_access() + thd Thread handler + context name resolution contest to setup table list there + from_clause Top-level list of table references in the FROM clause + tables Table list (select_lex->table_list) + conds Condition of current SELECT (can be changed by VIEW) + leaves List of join table leaves list (select_lex->leaf_tables) + refresh It is onle refresh for subquery + select_insert It is SELECT ... INSERT command + want_access what access is needed + + NOTE + a wrapper for check_tables that will also check the resulting + table leaves list for access to all the tables that belong to a view + + RETURN + FALSE ok; In this case *map will include the chosen index + TRUE error +*/ +bool setup_tables_and_check_access(THD *thd, + Name_resolution_context *context, + List<TABLE_LIST> *from_clause, + TABLE_LIST *tables, + Item **conds, TABLE_LIST **leaves, + bool select_insert, + ulong want_access) +{ + TABLE_LIST *leaves_tmp = NULL; + + if (setup_tables (thd, context, from_clause, tables, conds, + &leaves_tmp, select_insert)) + return TRUE; + + if (leaves) + *leaves = leaves_tmp; + + for (; leaves_tmp; leaves_tmp= leaves_tmp->next_leaf) + if (leaves_tmp->belong_to_view && + check_one_table_access(thd, want_access, leaves_tmp)) + { + tables->hide_view_error(thd); + return TRUE; + } + + return FALSE; +} + + +/* Create a key_map from a list of index names SYNOPSIS @@ -6019,6 +6082,7 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name, TABLE_SHARE *share; bool result= 0, signalled= 0; DBUG_ENTER("remove_table_from_cache"); + DBUG_PRINT("enter", ("Table: '%s.%s' flags: %u", db, table_name, flags)); key_length=(uint) (strmov(strmov(key,db)+1,table_name)-key)+1; for (;;) @@ -6045,7 +6109,10 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name, DBUG_PRINT("info", ("Table was in use by other thread")); in_use->some_tables_deleted=1; if (table->db_stat) + { + DBUG_PRINT("info", ("Found another active instance of the table")); result=1; + } /* Kill delayed insert threads */ if ((in_use->system_thread & SYSTEM_THREAD_DELAYED_INSERT) && ! in_use->killed) @@ -6100,6 +6167,12 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name, if (result && (flags & RTFC_WAIT_OTHER_THREAD_FLAG)) { + /* + Signal any thread waiting for tables to be freed to + reopen their tables + */ + (void) pthread_cond_broadcast(&COND_refresh); + DBUG_PRINT("info", ("Waiting for refresh signal")); if (!(flags & RTFC_CHECK_KILLED_FLAG) || !thd->killed) { dropping_tables++; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 581f47ac7f7..94584755e86 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -186,6 +186,11 @@ const char *thd_proc_info(THD *thd, const char *info) return old_info; } +void **thd_ha_data(const THD *thd, const struct handlerton *hton) +{ + return (void **) thd->ha_data + hton->slot; +} + /* Pass nominal parameters to Statement constructor only to ensure that @@ -197,7 +202,10 @@ THD::THD() :Statement(CONVENTIONAL_EXECUTION, 0, ALLOC_ROOT_MIN_BLOCK_SIZE, 0), Open_tables_state(refresh_version), rli_fake(0), lock_id(&main_lock_id), - user_time(0), in_sub_stmt(0), binlog_table_maps(0), + user_time(0), in_sub_stmt(0), +#ifdef HAVE_ROW_BASED_REPLICATION + binlog_table_maps(0), +#endif /*HAVE_ROW_BASED_REPLICATION*/ global_read_lock(0), is_fatal_error(0), rand_used(0), time_zone_used(0), last_insert_id_used(0), insert_id_used(0), clear_next_insert_id(0), @@ -251,7 +259,8 @@ THD::THD() net.last_error[0]=0; // If error on boot net.query_cache_query=0; // If error on boot ull=0; - system_thread= cleanup_done= abort_on_warning= no_warnings_for_error= 0; + system_thread= NON_SYSTEM_THREAD; + cleanup_done= abort_on_warning= no_warnings_for_error= 0; peer_port= 0; // For SHOW PROCESSLIST #ifdef HAVE_ROW_BASED_REPLICATION transaction.m_pending_rows_event= 0; @@ -334,7 +343,9 @@ void THD::init(void) bzero((char*) warn_count, sizeof(warn_count)); total_warn_count= 0; update_charset(); +#ifdef HAVE_ROW_BASED_REPLICATION reset_current_stmt_binlog_row_based(); +#endif /*HAVE_ROW_BASED_REPLICATION*/ bzero((char *) &status_var, sizeof(status_var)); } @@ -508,6 +519,8 @@ void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var) void THD::awake(THD::killed_state state_to_set) { + DBUG_ENTER("THD::awake"); + DBUG_PRINT("enter", ("this=0x%lx", this)); THD_CHECK_SENTRY(this); safe_mutex_assert_owner(&LOCK_delete); @@ -551,6 +564,7 @@ void THD::awake(THD::killed_state state_to_set) } pthread_mutex_unlock(&mysys_var->mutex); } + DBUG_VOID_RETURN; } /* @@ -1926,7 +1940,7 @@ bool select_dumpvar::send_data(List<Item> &items) if ((yy=var_li++)) { if (thd->spcont->set_variable(current_thd, yy->get_var_idx(), - *it.ref())) + it.ref())) DBUG_RETURN(1); } } @@ -2027,6 +2041,13 @@ void Security_context::skip_grants() } +bool Security_context::set_user(char *user_arg) +{ + safeFree(user); + user= my_strdup(user_arg, MYF(0)); + return user == 0; +} + /**************************************************************************** Handling of open and locked tables states. @@ -2713,8 +2734,10 @@ int THD::binlog_query(THD::enum_binlog_query_type qtype, the flushing will be done inside the top-most close_thread_tables(). */ +#ifdef HAVE_ROW_BASED_REPLICATION if (this->lock) DBUG_RETURN(binlog_flush_pending_rows_event(TRUE)); +#endif /*HAVE_ROW_BASED_REPLICATION*/ DBUG_RETURN(0); } /* Otherwise, we fall through */ @@ -2733,7 +2756,9 @@ int THD::binlog_query(THD::enum_binlog_query_type qtype, table maps were written. */ int error= mysql_bin_log.write(&qinfo); +#ifdef HAVE_ROW_BASED_REPLICATION binlog_table_maps= 0; +#endif /*HAVE_ROW_BASED_REPLICATION*/ DBUG_RETURN(error); } break; diff --git a/sql/sql_class.h b/sql/sql_class.h index 510dbbbb590..03a8439db58 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -630,6 +630,8 @@ public: { return (*priv_host ? priv_host : (char *)"%"); } + + bool set_user(char *user_arg); }; @@ -771,6 +773,19 @@ public: }; +/* Flags for the THD::system_thread variable */ +enum enum_thread_type +{ + NON_SYSTEM_THREAD= 0, + SYSTEM_THREAD_DELAYED_INSERT= 1, + SYSTEM_THREAD_SLAVE_IO= 2, + SYSTEM_THREAD_SLAVE_SQL= 4, + SYSTEM_THREAD_NDBCLUSTER_BINLOG= 8, + SYSTEM_THREAD_EVENT_SCHEDULER= 16, + SYSTEM_THREAD_EVENT_WORKER= 32 +}; + + /* For each client connection we create a separate thread with THD serving as a thread/connection descriptor @@ -1104,7 +1119,8 @@ public: long dbug_thread_id; pthread_t real_id; uint tmp_table, global_read_lock; - uint server_status,open_options,system_thread; + uint server_status,open_options; + enum enum_thread_type system_thread; uint32 db_length; uint select_number; //number of select (used for EXPLAIN) /* variables.transaction_isolation is reset to this after each commit */ @@ -1381,6 +1397,7 @@ public: void restore_sub_statement_state(Sub_statement_state *backup); void set_n_backup_active_arena(Query_arena *set, Query_arena *backup); void restore_active_arena(Query_arena *set, Query_arena *backup); +#ifdef HAVE_ROW_BASED_REPLICATION inline void set_current_stmt_binlog_row_based_if_mixed() { if (variables.binlog_format == BINLOG_FORMAT_MIXED) @@ -1395,6 +1412,7 @@ public: current_stmt_binlog_row_based= test(variables.binlog_format == BINLOG_FORMAT_ROW); } +#endif /*HAVE_ROW_BASED_REPLICATION*/ }; @@ -1404,11 +1422,6 @@ public: #define reenable_binlog(A) (A)->options= tmp_disable_binlog__save_options;} -/* Flags for the THD::system_thread (bitmap) variable */ -#define SYSTEM_THREAD_DELAYED_INSERT 1 -#define SYSTEM_THREAD_SLAVE_IO 2 -#define SYSTEM_THREAD_SLAVE_SQL 4 -#define SYSTEM_THREAD_NDBCLUSTER_BINLOG 8 /* Used to hold information about file and file structure in exchainge diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 3d035359b6f..6d5362c2554 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -871,7 +871,7 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent) exit: (void)sp_drop_db_routines(thd, db); /* QQ Ignore errors for now */ - (void)evex_drop_db_events(thd, db); /* QQ Ignore errors for now */ + error= Events::drop_schema_events(thd, db); start_waiting_global_read_lock(thd); /* If this database was the client's selected database, we silently change the diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 65434c10ac6..a7a50611a02 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -395,10 +395,11 @@ bool mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds) DBUG_ENTER("mysql_prepare_delete"); thd->lex->allow_sum_func= 0; - if (setup_tables(thd, &thd->lex->select_lex.context, - &thd->lex->select_lex.top_join_list, - table_list, &select_lex->leaf_tables, - FALSE) || + if (setup_tables_and_check_access(thd, &thd->lex->select_lex.context, + &thd->lex->select_lex.top_join_list, + table_list, + &select_lex->leaf_tables, FALSE, + DELETE_ACL) || setup_conds(thd, table_list, select_lex->leaf_tables, conds) || setup_ftfuncs(select_lex)) DBUG_RETURN(TRUE); @@ -457,10 +458,11 @@ bool mysql_multi_delete_prepare(THD *thd) lex->query_tables also point on local list of DELETE SELECT_LEX */ - if (setup_tables(thd, &thd->lex->select_lex.context, - &thd->lex->select_lex.top_join_list, - lex->query_tables, - &lex->select_lex.leaf_tables, FALSE)) + if (setup_tables_and_check_access(thd, &thd->lex->select_lex.context, + &thd->lex->select_lex.top_join_list, + lex->query_tables, + &lex->select_lex.leaf_tables, FALSE, + DELETE_ACL)) DBUG_RETURN(TRUE); diff --git a/sql/sql_error.h b/sql/sql_error.h index 223b50be744..b5cac24d894 100644 --- a/sql/sql_error.h +++ b/sql/sql_error.h @@ -40,3 +40,5 @@ void push_warning_printf(THD *thd, MYSQL_ERROR::enum_warning_level level, uint code, const char *format, ...); void mysql_reset_errors(THD *thd, bool force); bool mysqld_show_warnings(THD *thd, ulong levels_to_show); + +extern LEX_STRING warning_level_names[]; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 894a2a21efb..91b71edea66 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -428,7 +428,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, the code to make the call of end_bulk_insert() below safe. */ if (lock_type != TL_WRITE_DELAYED && !thd->prelocked_mode) - table->file->start_bulk_insert(values_list.elements); + table->file->ha_start_bulk_insert(values_list.elements); thd->no_trans_update= 0; thd->abort_on_warning= (!ignore && @@ -553,7 +553,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, else #endif { - if (!thd->prelocked_mode && table->file->end_bulk_insert() && !error) + if (!thd->prelocked_mode && table->file->ha_end_bulk_insert() && !error) { table->file->print_error(my_errno,MYF(0)); error=1; @@ -644,6 +644,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, thd->row_count_func= info.copied+info.deleted+info.updated; ::send_ok(thd, (ulong) thd->row_count_func, id, buff); } + if (table != NULL) + table->file->release_auto_increment(); thd->abort_on_warning= 0; DBUG_RETURN(FALSE); @@ -652,6 +654,8 @@ abort: if (lock_type == TL_WRITE_DELAYED) end_delayed_insert(thd); #endif + if (table != NULL) + table->file->release_auto_increment(); if (!joins_freed) free_underlaid_joins(thd, &thd->lex->select_lex); thd->abort_on_warning= 0; @@ -759,10 +763,11 @@ static bool mysql_prepare_insert_check_table(THD *thd, TABLE_LIST *table_list, bool insert_into_view= (table_list->view != 0); DBUG_ENTER("mysql_prepare_insert_check_table"); - if (setup_tables(thd, &thd->lex->select_lex.context, - &thd->lex->select_lex.top_join_list, - table_list, &thd->lex->select_lex.leaf_tables, - select_insert)) + if (setup_tables_and_check_access(thd, &thd->lex->select_lex.context, + &thd->lex->select_lex.top_join_list, + table_list, + &thd->lex->select_lex.leaf_tables, + select_insert, INSERT_ACL)) DBUG_RETURN(TRUE); if (insert_into_view && !fields.elements) @@ -973,7 +978,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) uint key_nr; if (error != HA_WRITE_SKIP) goto err; - table->file->restore_auto_increment(); + table->file->restore_auto_increment(); // it's too early here! BUG#20188 if ((int) (key_nr = table->file->get_dup_key(error)) < 0) { error=HA_WRITE_SKIP; /* Database can't find key */ @@ -2275,7 +2280,7 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u) We won't start bulk inserts at all if this statement uses functions or should invoke triggers since they may access to the same table too. */ - table->file->start_bulk_insert((ha_rows) 0); + table->file->ha_start_bulk_insert((ha_rows) 0); } restore_record(table,s->default_values); // Get empty record table->next_number_field=table->found_next_number_field; @@ -2316,7 +2321,7 @@ int select_insert::prepare2(void) DBUG_ENTER("select_insert::prepare2"); if (thd->lex->current_select->options & OPTION_BUFFER_RESULT && !thd->prelocked_mode) - table->file->start_bulk_insert((ha_rows) 0); + table->file->ha_start_bulk_insert((ha_rows) 0); DBUG_RETURN(0); } @@ -2390,6 +2395,7 @@ bool select_insert::send_data(List<Item> &values) last_insert_id= thd->insert_id(); } } + table->file->release_auto_increment(); DBUG_RETURN(error); } @@ -2421,7 +2427,7 @@ void select_insert::send_error(uint errcode,const char *err) DBUG_VOID_RETURN; } if (!thd->prelocked_mode) - table->file->end_bulk_insert(); + table->file->ha_end_bulk_insert(); /* If at least one row has been inserted/modified and will stay in the table (the table doesn't have transactions) we must write to the binlog (and @@ -2474,7 +2480,7 @@ bool select_insert::send_eof() int error,error2; DBUG_ENTER("select_insert::send_eof"); - error= (!thd->prelocked_mode) ? table->file->end_bulk_insert():0; + error= (!thd->prelocked_mode) ? table->file->ha_end_bulk_insert():0; table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); if (info.copied || info.deleted || info.updated) @@ -2537,15 +2543,172 @@ bool select_insert::send_eof() CREATE TABLE (SELECT) ... ***************************************************************************/ +/* + Create table from lists of fields and items (or open existing table + with same name). + + SYNOPSIS + create_table_from_items() + thd in Thread object + create_info in Create information (like MAX_ROWS, ENGINE or + temporary table flag) + create_table in Pointer to TABLE_LIST object providing database + and name for table to be created or to be open + extra_fields in/out Initial list of fields for table to be created + keys in List of keys for table to be created + items in List of items which should be used to produce rest + of fields for the table (corresponding fields will + be added to the end of 'extra_fields' list) + lock out Pointer to the MYSQL_LOCK object for table created + (open) will be returned in this parameter. Since + this table is not included in THD::lock caller is + responsible for explicitly unlocking this table. + hooks + + NOTES + If 'create_info->options' bitmask has HA_LEX_CREATE_IF_NOT_EXISTS + flag and table with name provided already exists then this function will + simply open existing table. + Also note that create, open and lock sequence in this function is not + atomic and thus contains gap for deadlock and can cause other troubles. + Since this function contains some logic specific to CREATE TABLE ... SELECT + it should be changed before it can be used in other contexts. + + RETURN VALUES + non-zero Pointer to TABLE object for table created or opened + 0 Error +*/ + +static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, + TABLE_LIST *create_table, + List<create_field> *extra_fields, + List<Key> *keys, + List<Item> *items, + MYSQL_LOCK **lock, + TABLEOP_HOOKS *hooks) +{ + TABLE tmp_table; // Used during 'create_field()' + TABLE_SHARE share; + TABLE *table= 0; + uint select_field_count= items->elements; + /* Add selected items to field list */ + List_iterator_fast<Item> it(*items); + Item *item; + Field *tmp_field; + bool not_used; + DBUG_ENTER("create_table_from_items"); + + tmp_table.alias= 0; + tmp_table.timestamp_field= 0; + tmp_table.s= &share; + init_tmp_table_share(&share, "", 0, "", ""); + + 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 == &myisam_hton || + create_info->db_type == &heap_hton); + tmp_table.null_row=tmp_table.maybe_null=0; + + while ((item=it++)) + { + create_field *cr_field; + Field *field, *def_field; + if (item->type() == Item::FUNC_ITEM) + field= item->tmp_table_field(&tmp_table); + else + field= create_tmp_field(thd, &tmp_table, item, item->type(), + (Item ***) 0, &tmp_field, &def_field, 0, 0, 0, 0, + 0); + if (!field || + !(cr_field=new create_field(field,(item->type() == Item::FIELD_ITEM ? + ((Item_field *)item)->field : + (Field*) 0)))) + DBUG_RETURN(0); + if (item->maybe_null) + cr_field->flags &= ~NOT_NULL_FLAG; + extra_fields->push_back(cr_field); + } + /* + create and lock table + + We don't log the statement, it will be logged later. + + If this is a HEAP table, the automatic DELETE FROM which is written to the + binlog when a HEAP table is opened for the first time since startup, must + not be written: 1) it would be wrong (imagine we're in CREATE SELECT: we + don't want to delete from it) 2) it would be written before the CREATE + TABLE, which is a wrong order. So we keep binary logging disabled when we + open_table(). + NOTE: By locking table which we just have created (or for which we just + have have found that it already exists) separately from other tables used + by the statement we create potential window for deadlock. + TODO: create and open should be done atomic ! + */ + { + tmp_disable_binlog(thd); + if (!mysql_create_table(thd, create_table->db, create_table->table_name, + create_info, *extra_fields, *keys, 0, + select_field_count)) + { + /* + If we are here in prelocked mode we either create temporary table + or prelocked mode is caused by the SELECT part of this statement. + */ + DBUG_ASSERT(!thd->prelocked_mode || + create_info->options & HA_LEX_CREATE_TMP_TABLE || + thd->lex->requires_prelocking()); + + /* + NOTE: We don't want to ignore set of locked tables here if we are + under explicit LOCK TABLES since it will open gap for deadlock + too wide (and also is not backward compatible). + */ + + if (! (table= open_table(thd, create_table, thd->mem_root, (bool*) 0, + (MYSQL_LOCK_IGNORE_FLUSH | + ((thd->prelocked_mode == PRELOCKED) ? + MYSQL_OPEN_IGNORE_LOCKED_TABLES:0))))) + quick_rm_table(create_info->db_type, create_table->db, + table_case_name(create_info, create_table->table_name)); + } + reenable_binlog(thd); + if (!table) // open failed + DBUG_RETURN(0); + } + + /* + FIXME: What happens if trigger manages to be created while we are + obtaining this lock ? May be it is sensible just to disable + trigger execution in this case ? Or will MYSQL_LOCK_IGNORE_FLUSH + save us from that ? + */ + table->reginfo.lock_type=TL_WRITE; + hooks->prelock(&table, 1); // Call prelock hooks + if (! ((*lock)= mysql_lock_tables(thd, &table, 1, + MYSQL_LOCK_IGNORE_FLUSH, ¬_used))) + { + VOID(pthread_mutex_lock(&LOCK_open)); + hash_delete(&open_cache,(byte*) table); + VOID(pthread_mutex_unlock(&LOCK_open)); + quick_rm_table(create_info->db_type, create_table->db, + table_case_name(create_info, create_table->table_name)); + DBUG_RETURN(0); + } + table->file->extra(HA_EXTRA_WRITE_CACHE); + DBUG_RETURN(table); +} + + class MY_HOOKS : public TABLEOP_HOOKS { public: MY_HOOKS(select_create *x) : ptr(x) { } virtual void do_prelock(TABLE **tables, uint count) - { - if (ptr->get_thd()->current_stmt_binlog_row_based) - ptr->binlog_show_create_table(tables, count); - } + { + if (ptr->get_thd()->current_stmt_binlog_row_based) + ptr->binlog_show_create_table(tables, count); + } private: select_create *ptr; @@ -2585,7 +2748,7 @@ int select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u) if (info.ignore || info.handle_duplicates != DUP_ERROR) table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); if (!thd->prelocked_mode) - table->file->start_bulk_insert((ha_rows) 0); + table->file->ha_start_bulk_insert((ha_rows) 0); thd->no_trans_update= 0; thd->abort_on_warning= (!info.ignore && (thd->variables.sql_mode & diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 562224201e7..d45f4369095 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -152,8 +152,7 @@ void lex_start(THD *thd, const uchar *buf, uint length) lex->found_semicolon= 0; lex->safe_to_cache_query= 1; lex->time_zone_tables_used= 0; - lex->leaf_tables_insert= lex->query_tables= 0; - lex->query_tables_last= &lex->query_tables; + lex->leaf_tables_insert= 0; lex->variables_used= 0; lex->empty_field_list_on_rset= 0; lex->select_lex.select_number= 1; @@ -175,17 +174,12 @@ void lex_start(THD *thd, const uchar *buf, uint length) lex->sphead= NULL; lex->spcont= NULL; lex->proc_list.first= 0; - lex->query_tables_own_last= 0; lex->escape_used= lex->et_compile_phase= FALSE; + lex->reset_query_tables_list(FALSE); lex->name= 0; lex->et= NULL; - if (lex->sroutines.records) - my_hash_reset(&lex->sroutines); - lex->sroutines_list.empty(); - lex->sroutines_list_own_last= lex->sroutines_list.next; - lex->sroutines_list_own_elements= 0; lex->nest_level=0 ; lex->allow_sum_func= 0; lex->in_sum_func= NULL; @@ -319,18 +313,7 @@ static char *get_text(LEX *lex) found_escape=1; if (lex->ptr == lex->end_of_query) return 0; -#ifdef USE_MB - int l; - if (use_mb(cs) && - (l = my_ismbchar(cs, - (const char *)lex->ptr, - (const char *)lex->end_of_query))) { - lex->ptr += l; - continue; - } - else -#endif - yySkip(); + yySkip(); } else if (c == sep) { @@ -360,9 +343,6 @@ static char *get_text(LEX *lex) { uchar *to; - /* Re-use found_escape for tracking state of escapes */ - found_escape= 0; - for (to=start ; str != end ; str++) { #ifdef USE_MB @@ -376,8 +356,7 @@ static char *get_text(LEX *lex) continue; } #endif - if (!found_escape && - !(lex->thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) && + if (!(lex->thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) && *str == '\\' && str+1 != end) { switch(*++str) { @@ -404,20 +383,14 @@ static char *get_text(LEX *lex) *to++= '\\'; // remember prefix for wildcard /* Fall through */ default: - found_escape= 1; - str--; + *to++= *str; break; } } - else if (!found_escape && *str == sep) - { - found_escape= 1; - } + else if (*str == sep) + *to++= *str++; // Two ' or " else - { *to++ = *str; - found_escape= 0; - } } *to=0; lex->yytoklen=(uint) (to-start); @@ -1625,6 +1598,52 @@ void st_select_lex::print_limit(THD *thd, String *str) /* + Initialize (or reset) Query_tables_list object. + + SYNOPSIS + reset_query_tables_list() + init TRUE - we should perform full initialization of object with + allocating needed memory + FALSE - object is already initialized so we should only reset + its state so it can be used for parsing/processing + of new statement + + DESCRIPTION + This method initializes Query_tables_list so it can be used as part + of LEX object for parsing/processing of statement. One can also use + this method to reset state of already initialized Query_tables_list + so it can be used for processing of new statement. +*/ + +void Query_tables_list::reset_query_tables_list(bool init) +{ + query_tables= 0; + query_tables_last= &query_tables; + query_tables_own_last= 0; + if (init) + hash_init(&sroutines, system_charset_info, 0, 0, 0, sp_sroutine_key, 0, 0); + else if (sroutines.records) + my_hash_reset(&sroutines); + sroutines_list.empty(); + sroutines_list_own_last= sroutines_list.next; + sroutines_list_own_elements= 0; +} + + +/* + Destroy Query_tables_list object with freeing all resources used by it. + + SYNOPSIS + destroy_query_tables_list() +*/ + +void Query_tables_list::destroy_query_tables_list() +{ + hash_free(&sroutines); +} + + +/* Initialize LEX object. SYNOPSIS @@ -1640,12 +1659,9 @@ void st_select_lex::print_limit(THD *thd, String *str) st_lex::st_lex() :result(0), yacc_yyss(0), yacc_yyvs(0), - sql_command(SQLCOM_END), query_tables_own_last(0) + sql_command(SQLCOM_END) { - hash_init(&sroutines, system_charset_info, 0, 0, 0, sp_sroutine_key, 0, 0); - sroutines_list.empty(); - sroutines_list_own_last= sroutines_list.next; - sroutines_list_own_elements= 0; + reset_query_tables_list(TRUE); } @@ -2029,6 +2045,11 @@ void st_lex::link_first_table_back(TABLE_LIST *first, SYNOPSIS st_lex::cleanup_after_one_table_open() + + NOTE + This method is mostly responsible for cleaning up of selects lists and + derived tables state. To rollback changes in Query_tables_list one has + to call Query_tables_list::reset_query_tables_list(FALSE). */ void st_lex::cleanup_after_one_table_open() @@ -2055,11 +2076,41 @@ void st_lex::cleanup_after_one_table_open() select_lex.cut_subtree(); } time_zone_tables_used= 0; - if (sroutines.records) - my_hash_reset(&sroutines); - sroutines_list.empty(); - sroutines_list_own_last= sroutines_list.next; - sroutines_list_own_elements= 0; +} + + +/* + Save current state of Query_tables_list for this LEX, and prepare it + for processing of new statemnt. + + SYNOPSIS + reset_n_backup_query_tables_list() + backup Pointer to Query_tables_list instance to be used for backup +*/ + +void st_lex::reset_n_backup_query_tables_list(Query_tables_list *backup) +{ + backup->set_query_tables_list(this); + /* + We have to perform full initialization here since otherwise we + will damage backed up state. + */ + this->reset_query_tables_list(TRUE); +} + + +/* + Restore state of Query_tables_list for this LEX from backup. + + SYNOPSIS + restore_backup_query_tables_list() + backup Pointer to Query_tables_list instance used for backup +*/ + +void st_lex::restore_backup_query_tables_list(Query_tables_list *backup) +{ + this->destroy_query_tables_list(); + this->set_query_tables_list(backup); } diff --git a/sql/sql_lex.h b/sql/sql_lex.h index f0bd85367d0..77f79ad61f4 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -110,8 +110,10 @@ enum enum_sql_command { SQLCOM_INSTALL_PLUGIN, SQLCOM_UNINSTALL_PLUGIN, SQLCOM_SHOW_AUTHORS, SQLCOM_BINLOG_BASE64_EVENT, SQLCOM_SHOW_PLUGINS, + SQLCOM_SHOW_CONTRIBUTORS, SQLCOM_CREATE_EVENT, SQLCOM_ALTER_EVENT, SQLCOM_DROP_EVENT, - SQLCOM_SHOW_CREATE_EVENT, SQLCOM_SHOW_EVENTS, + SQLCOM_SHOW_CREATE_EVENT, SQLCOM_SHOW_EVENTS, + SQLCOM_SHOW_SCHEDULER_STATUS, /* This should be the last !!! */ @@ -750,9 +752,95 @@ extern sys_var *trg_new_row_fake_var; enum xa_option_words {XA_NONE, XA_JOIN, XA_RESUME, XA_ONE_PHASE, XA_SUSPEND, XA_FOR_MIGRATE}; + +/* + Class representing list of all tables used by statement. + It also contains information about stored functions used by statement + since during its execution we may have to add all tables used by its + stored functions/triggers to this list in order to pre-open and lock + them. + + Also used by st_lex::reset_n_backup/restore_backup_query_tables_list() + methods to save and restore this information. +*/ + +class Query_tables_list +{ +public: + /* Global list of all tables used by this statement */ + TABLE_LIST *query_tables; + /* Pointer to next_global member of last element in the previous list. */ + TABLE_LIST **query_tables_last; + /* + If non-0 then indicates that query requires prelocking and points to + next_global member of last own element in query table list (i.e. last + table which was not added to it as part of preparation to prelocking). + 0 - indicates that this query does not need prelocking. + */ + TABLE_LIST **query_tables_own_last; + /* Set of stored routines called by statement. */ + HASH sroutines; + /* + List linking elements of 'sroutines' set. Allows you to add new elements + to this set as you iterate through the list of existing elements. + 'sroutines_list_own_last' is pointer to ::next member of last element of + this list which represents routine which is explicitly used by query. + 'sroutines_list_own_elements' number of explicitly used routines. + We use these two members for restoring of 'sroutines_list' to the state + in which it was right after query parsing. + */ + SQL_LIST sroutines_list; + byte **sroutines_list_own_last; + uint sroutines_list_own_elements; + + /* + These constructor and destructor serve for creation/destruction + of Query_tables_list instances which are used as backup storage. + */ + Query_tables_list() {} + ~Query_tables_list() {} + + /* Initializes (or resets) Query_tables_list object for "real" use. */ + void reset_query_tables_list(bool init); + void destroy_query_tables_list(); + void set_query_tables_list(Query_tables_list *state) + { + *this= *state; + } + + void add_to_query_tables(TABLE_LIST *table) + { + *(table->prev_global= query_tables_last)= table; + query_tables_last= &table->next_global; + } + bool requires_prelocking() + { + return test(query_tables_own_last); + } + void mark_as_requiring_prelocking(TABLE_LIST **tables_own_last) + { + query_tables_own_last= tables_own_last; + } + /* Return pointer to first not-own table in query-tables or 0 */ + TABLE_LIST* first_not_own_table() + { + return ( query_tables_own_last ? *query_tables_own_last : 0); + } + void chop_off_not_own_tables() + { + if (query_tables_own_last) + { + *query_tables_own_last= 0; + query_tables_last= query_tables_own_last; + query_tables_own_last= 0; + } + } +}; + + /* The state of the lex parsing. This is saved in the THD struct */ -typedef struct st_lex +typedef struct st_lex : public Query_tables_list { uint yylineno,yytoklen; /* Simulate lex */ LEX_YYSTYPE yylval; @@ -785,14 +873,6 @@ typedef struct st_lex gptr yacc_yyss,yacc_yyvs; THD *thd; CHARSET_INFO *charset; - TABLE_LIST *query_tables; /* global list of all tables in this query */ - /* - last element next_global of previous list (used only for list building - during parsing and VIEW processing. This pointer could be invalid during - processing of information schema tables(see get_schema_tables_result - function) - */ - TABLE_LIST **query_tables_last; /* store original leaf_tables for INSERT SELECT and PS/SP */ TABLE_LIST *leaf_tables_insert; /* Position (first character index) of SELECT of CREATE VIEW statement */ @@ -933,20 +1013,6 @@ typedef struct st_lex bool sp_lex_in_use; /* Keep track on lex usage in SPs for error handling */ bool all_privileges; sp_pcontext *spcont; - /* Set of stored routines called by statement. */ - HASH sroutines; - /* - List linking elements of 'sroutines' set. Allows you to add new elements - to this set as you iterate through the list of existing elements. - 'sroutines_list_own_last' is pointer to ::next member of last element of - this list which represents routine which is explicitly used by query. - 'sroutines_list_own_elements' number of explicitly used routines. - We use these two members for restoring of 'sroutines_list' to the state - in which it was right after query parsing. - */ - SQL_LIST sroutines_list; - byte **sroutines_list_own_last; - uint sroutines_list_own_elements; st_sp_chistics sp_chistics; @@ -987,14 +1053,6 @@ typedef struct st_lex const char *stmt_definition_begin; /* - If non-0 then indicates that query requires prelocking and points to - next_global member of last own element in query table list (i.e. last - table which was not added to it as part of preparation to prelocking). - 0 - indicates that this query does not need prelocking. - */ - TABLE_LIST **query_tables_own_last; - - /* Pointers to part of LOAD DATA statement that should be rewritten during replication ("LOCAL 'filename' REPLACE INTO" part). */ @@ -1012,7 +1070,7 @@ typedef struct st_lex virtual ~st_lex() { - hash_free(&sroutines); + destroy_query_tables_list(); } inline void uncacheable(uint8 cause) @@ -1037,11 +1095,6 @@ typedef struct st_lex TABLE_LIST *unlink_first_table(bool *link_to_local); void link_first_table_back(TABLE_LIST *first, bool link_to_local); void first_lists_tables_same(); - inline void add_to_query_tables(TABLE_LIST *table) - { - *(table->prev_global= query_tables_last)= table; - query_tables_last= &table->next_global; - } bool add_time_zone_tables_to_query_tables(THD *thd); bool can_be_merged(); @@ -1073,28 +1126,7 @@ typedef struct st_lex return FALSE; } } - inline bool requires_prelocking() - { - return test(query_tables_own_last); - } - inline void mark_as_requiring_prelocking(TABLE_LIST **tables_own_last) - { - query_tables_own_last= tables_own_last; - } - /* Return pointer to first not-own table in query-tables or 0 */ - TABLE_LIST* first_not_own_table() - { - return ( query_tables_own_last ? *query_tables_own_last : 0); - } - void chop_off_not_own_tables() - { - if (query_tables_own_last) - { - *query_tables_own_last= 0; - query_tables_last= query_tables_own_last; - query_tables_own_last= 0; - } - } + void cleanup_after_one_table_open(); bool push_context(Name_resolution_context *context) @@ -1111,6 +1143,9 @@ typedef struct st_lex { return context_stack.head(); } + + void reset_n_backup_query_tables_list(Query_tables_list *backup); + void restore_backup_query_tables_list(Query_tables_list *backup); } LEX; struct st_lex_local: public st_lex diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 5c5ecfbbcd0..f8debbedc62 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -117,7 +117,7 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, { char name[FN_REFLEN]; File file; - TABLE *table; + TABLE *table= NULL; int error; String *field_term=ex->field_term,*escaped=ex->escaped; String *enclosed=ex->enclosed; @@ -152,10 +152,11 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, ha_enable_transaction(thd, FALSE); if (open_and_lock_tables(thd, table_list)) DBUG_RETURN(TRUE); - if (setup_tables(thd, &thd->lex->select_lex.context, - &thd->lex->select_lex.top_join_list, - table_list, - &thd->lex->select_lex.leaf_tables, FALSE)) + if (setup_tables_and_check_access(thd, &thd->lex->select_lex.context, + &thd->lex->select_lex.top_join_list, + table_list, + &thd->lex->select_lex.leaf_tables, FALSE, + INSERT_ACL | UPDATE_ACL)) DBUG_RETURN(-1); if (!table_list->table || // do not suport join view !table_list->updatable || // and derived tables @@ -362,7 +363,7 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, handle_duplicates == DUP_REPLACE) table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); if (!thd->prelocked_mode) - table->file->start_bulk_insert((ha_rows) 0); + table->file->ha_start_bulk_insert((ha_rows) 0); table->copy_blobs=1; thd->no_trans_update= 0; @@ -379,7 +380,7 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, error= read_sep_field(thd, info, table_list, fields_vars, set_fields, set_values, read_info, *enclosed, skip_lines, ignore); - if (!thd->prelocked_mode && table->file->end_bulk_insert() && !error) + if (!thd->prelocked_mode && table->file->ha_end_bulk_insert() && !error) { table->file->print_error(my_errno, MYF(0)); error= 1; @@ -501,6 +502,8 @@ err: mysql_unlock_tables(thd, thd->lock); thd->lock=0; } + if (table != NULL) + table->file->release_auto_increment(); thd->abort_on_warning= 0; DBUG_RETURN(error); } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 934faebf9a7..520684df8a8 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2051,7 +2051,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, { statistic_increment(thd->status_var.com_stat[SQLCOM_KILL], &LOCK_status); ulong id=(ulong) uint4korr(packet); - kill_one_thread(thd,id,false); + sql_kill(thd,id,false); break; } case COM_SET_OPTION: @@ -2470,8 +2470,10 @@ mysql_execute_command(THD *thd) statistic_increment(thd->status_var.com_stat[lex->sql_command], &LOCK_status); +#ifdef HAVE_ROW_BASED_REPLICATION if (lex->binlog_row_based_if_mixed) thd->set_current_stmt_binlog_row_based_if_mixed(); +#endif /*HAVE_ROW_BASED_REPLICATION*/ switch (lex->sql_command) { case SQLCOM_SELECT: @@ -2851,6 +2853,17 @@ mysql_execute_command(THD *thd) res= 1; goto end_with_restore_list; } +#ifdef WITH_PARTITION_STORAGE_ENGINE + { + partition_info *part_info= thd->lex->part_info; + if (part_info && !(part_info= thd->lex->part_info->get_clone())) + { + res= -1; + goto end_with_restore_list; + } + thd->work_part_info= part_info; + } +#endif if (select_lex->item_list.elements) // With select { select_result *result; @@ -2923,15 +2936,6 @@ mysql_execute_command(THD *thd) lex->like_name); else { -#ifdef WITH_PARTITION_STORAGE_ENGINE - partition_info *part_info= thd->lex->part_info; - if (part_info && !(part_info= thd->lex->part_info->get_clone())) - { - res= -1; - goto end_with_restore_list; - } - thd->work_part_info= part_info; -#endif res= mysql_create_table(thd, create_table->db, create_table->table_name, &lex->create_info, lex->create_list, @@ -3526,6 +3530,9 @@ end_with_restore_list: case SQLCOM_SHOW_AUTHORS: res= mysqld_show_authors(thd); break; + case SQLCOM_SHOW_CONTRIBUTORS: + res= mysqld_show_contributors(thd); + break; case SQLCOM_SHOW_PRIVILEGES: res= mysqld_show_privileges(thd); break; @@ -3831,14 +3838,17 @@ end_with_restore_list: switch (lex->sql_command) { case SQLCOM_CREATE_EVENT: - res= evex_create_event(thd, lex->et, (uint) lex->create_info.options, - &rows_affected); + res= Events::create_event(thd, lex->et, + (uint) lex->create_info.options, + &rows_affected); break; case SQLCOM_ALTER_EVENT: - res= evex_update_event(thd, lex->et, lex->spname, &rows_affected); + res= Events::update_event(thd, lex->et, lex->spname, + &rows_affected); break; case SQLCOM_DROP_EVENT: - res= evex_drop_event(thd, lex->et, lex->drop_if_exists, &rows_affected); + res= Events::drop_event(thd, lex->et, lex->drop_if_exists, + &rows_affected); default:; } DBUG_PRINT("info", ("CREATE/ALTER/DROP returned error code=%d af_rows=%d", @@ -3876,9 +3886,16 @@ end_with_restore_list: my_error(ER_TOO_LONG_IDENT, MYF(0), lex->spname->m_name.str); goto error; } - res= evex_show_create_event(thd, lex->spname, lex->et->definer); + res= Events::show_create_event(thd, lex->spname); + break; + } +#ifndef DBUG_OFF + case SQLCOM_SHOW_SCHEDULER_STATUS: + { + res= Events::dump_internal_status(thd); break; } +#endif case SQLCOM_CREATE_FUNCTION: // UDF function { if (check_access(thd,INSERT_ACL,"mysql",0,1,0,0)) @@ -3981,7 +3998,6 @@ end_with_restore_list: if (thd->security_ctx->user) // If not replication { LEX_USER *user; - uint counter; List_iterator <LEX_USER> user_list(lex->users_list); while ((user= user_list++)) @@ -3999,7 +4015,8 @@ end_with_restore_list: user->host.str, thd->security_ctx->host_or_ip)) { // TODO: use check_change_password() - if (check_acl_user(user, &counter) && user->password.str && + if (is_acl_user(user->host.str, user->user.str) && + user->password.str && check_access(thd, UPDATE_ACL,"mysql",0,1,1,0)) { my_message(ER_PASSWORD_NOT_ALLOWED, @@ -4118,7 +4135,7 @@ end_with_restore_list: MYF(0)); goto error; } - kill_one_thread(thd, (ulong)it->val_int(), lex->type & ONLY_KILL_QUERY); + sql_kill(thd, (ulong)it->val_int(), lex->type & ONLY_KILL_QUERY); break; } #ifndef NO_EMBEDDED_ACCESS_CHECKS @@ -5134,7 +5151,9 @@ end: */ if (thd->one_shot_set && lex->sql_command != SQLCOM_SET_OPTION) reset_one_shot_variables(thd); +#ifdef HAVE_ROW_BASED_REPLICATION thd->reset_current_stmt_binlog_row_based(); +#endif /*HAVE_ROW_BASED_REPLICATION*/ /* The return value for ROW_COUNT() is "implementation dependent" if the @@ -5172,23 +5191,35 @@ error: bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *all_tables) { + Security_context * backup_ctx= thd->security_ctx; + + /* we need to switch to the saved context (if any) */ + if (all_tables->security_ctx) + thd->security_ctx= all_tables->security_ctx; + if (check_access(thd, privilege, all_tables->db, &all_tables->grant.privilege, 0, 0, test(all_tables->schema_table))) - return 1; + goto deny; /* Show only 1 table for check_grant */ if (grant_option && check_grant(thd, privilege, all_tables, 0, 1, 0)) - return 1; + goto deny; + + thd->security_ctx= backup_ctx; /* Check rights on tables of subselects and implictly opened tables */ TABLE_LIST *subselects_tables; if ((subselects_tables= all_tables->next_global)) { if ((check_table_access(thd, SELECT_ACL, subselects_tables, 0))) - return 1; + goto deny; } return 0; + +deny: + thd->security_ctx= backup_ctx; + return 1; } @@ -5369,6 +5400,7 @@ check_table_access(THD *thd, ulong want_access,TABLE_LIST *tables, ulong found_access=0; TABLE_LIST *org_tables= tables; TABLE_LIST *first_not_own_table= thd->lex->first_not_own_table(); + Security_context *sctx= thd->security_ctx, *backup_ctx= thd->security_ctx; /* The check that first_not_own_table is not reached is for the case when the given table list refers to the list for prelocking (contains tables @@ -5376,12 +5408,17 @@ check_table_access(THD *thd, ulong want_access,TABLE_LIST *tables, */ for (; tables != first_not_own_table; tables= tables->next_global) { + if (tables->security_ctx) + sctx= tables->security_ctx; + else + sctx= backup_ctx; + if (tables->schema_table && (want_access & ~(SELECT_ACL | EXTRA_ACL | FILE_ACL))) { if (!no_errors) my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), - thd->security_ctx->priv_user, thd->security_ctx->priv_host, + sctx->priv_user, sctx->priv_host, information_schema_name.str); return TRUE; } @@ -5390,12 +5427,13 @@ check_table_access(THD *thd, ulong want_access,TABLE_LIST *tables, Remove SHOW_VIEW_ACL, because it will be checked during making view */ tables->grant.orig_want_privilege= (want_access & ~SHOW_VIEW_ACL); - if (tables->derived || tables->schema_table || tables->belong_to_view || + if (tables->derived || tables->schema_table || (tables->table && (int)tables->table->s->tmp_table) || my_tz_check_n_skip_implicit_tables(&tables, thd->lex->time_zone_tables_used)) continue; - if ((thd->security_ctx->master_access & want_access) == + thd->security_ctx= sctx; + if ((sctx->master_access & want_access) == (want_access & ~EXTRA_ACL) && thd->db) tables->grant.privilege= want_access; @@ -5407,19 +5445,23 @@ check_table_access(THD *thd, ulong want_access,TABLE_LIST *tables, { if (check_access(thd,want_access,tables->db,&tables->grant.privilege, 0, no_errors, test(tables->schema_table))) - return TRUE; // Access denied + goto deny; // Access denied found_access=tables->grant.privilege; found=1; } } else if (check_access(thd,want_access,tables->db,&tables->grant.privilege, 0, no_errors, test(tables->schema_table))) - return TRUE; + goto deny; } + thd->security_ctx= backup_ctx; if (grant_option) return check_grant(thd,want_access & ~EXTRA_ACL,org_tables, test(want_access & EXTRA_ACL), UINT_MAX, no_errors); return FALSE; +deny: + thd->security_ctx= backup_ctx; + return TRUE; } @@ -5899,6 +5941,7 @@ void mysql_parse(THD *thd, char *inBuf, uint length) } else { + DBUG_ASSERT(thd->net.report_error); DBUG_PRINT("info",("Command aborted. Fatal_error: %d", thd->is_fatal_error)); query_cache_abort(&thd->net); @@ -6921,22 +6964,26 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables, return result; } + /* - kill on thread + kills a thread SYNOPSIS kill_one_thread() thd Thread class id Thread id + only_kill_query Should it kill the query or the connection NOTES This is written such that we have a short lock on LOCK_thread_count */ -void kill_one_thread(THD *thd, ulong id, bool only_kill_query) +uint kill_one_thread(THD *thd, ulong id, bool only_kill_query) { THD *tmp; uint error=ER_NO_SUCH_THREAD; + DBUG_ENTER("kill_one_thread"); + DBUG_PRINT("enter", ("id=%lu only_kill=%d", id, only_kill_query)); VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list I_List_iterator<THD> it(threads); while ((tmp=it++)) @@ -6962,8 +7009,25 @@ void kill_one_thread(THD *thd, ulong id, bool only_kill_query) error=ER_KILL_DENIED_ERROR; pthread_mutex_unlock(&tmp->LOCK_delete); } + DBUG_PRINT("exit", ("%d", error)); + DBUG_RETURN(error); +} + + +/* + kills a thread and sends response + + SYNOPSIS + sql_kill() + thd Thread class + id Thread id + only_kill_query Should it kill the query or the connection +*/ - if (!error) +void sql_kill(THD *thd, ulong id, bool only_kill_query) +{ + uint error; + if (!(error= kill_one_thread(thd, id, only_kill_query))) send_ok(thd); else my_error(error, MYF(0), id); @@ -7113,7 +7177,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= (handlerton*) &default_hton; + create_info.db_type= 0; 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, @@ -7129,7 +7193,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= (handlerton*) &default_hton; + create_info.db_type= 0; create_info.default_table_charset= thd->variables.collation_database; alter_info->clear(); alter_info->flags= ALTER_DROP_INDEX; @@ -7431,7 +7495,7 @@ bool create_table_precheck(THD *thd, TABLE_LIST *tables, lex->create_info.merge_list.first)) goto err; if (grant_option && want_priv != CREATE_TMP_ACL && - check_grant(thd, want_priv, create_table, 0, UINT_MAX, 0)) + check_grant(thd, want_priv, create_table, 0, 1, 0)) goto err; if (select_lex->item_list.elements) diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 40e4cd115a1..a10a04ba9f9 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -1665,8 +1665,8 @@ static int add_keyword_int(File fptr, const char *keyword, longlong num) static int add_engine(File fptr, handlerton *engine_type) { - const char *engine_str= engine_type->name; - DBUG_PRINT("info", ("ENGINE = %s", engine_str)); + const char *engine_str= hton2plugin[engine_type->slot]->name.str; + DBUG_PRINT("info", ("ENGINE: %s", engine_str)); int err= add_string(fptr, "ENGINE = "); return err + add_string(fptr, engine_str); } @@ -1676,7 +1676,7 @@ static int add_partition_options(File fptr, partition_element *p_elem) int err= 0; if (p_elem->tablespace_name) - err+= add_keyword_string(fptr,"TABLESPACE", FALSE, + err+= add_keyword_string(fptr,"TABLESPACE", FALSE, p_elem->tablespace_name); if (p_elem->nodegroup_id != UNDEF_NODEGROUP) err+= add_keyword_int(fptr,"NODEGROUP",(longlong)p_elem->nodegroup_id); @@ -1754,7 +1754,6 @@ end: buf_length A pointer to the returned buffer length use_sql_alloc Allocate buffer from sql_alloc if true otherwise use my_malloc - write_all Write everything, also default values RETURN VALUES NULL error @@ -1782,8 +1781,7 @@ end: char *generate_partition_syntax(partition_info *part_info, uint *buf_length, - bool use_sql_alloc, - bool write_all) + bool use_sql_alloc) { uint i,j, tot_no_parts, no_subparts, no_parts; partition_element *part_elem; @@ -1843,6 +1841,8 @@ char *generate_partition_syntax(partition_info *part_info, { err+= add_subpartition_by(fptr); /* Must be hash partitioning for subpartitioning */ + if (part_info->linear_hash_ind) + err+= add_string(fptr, partition_keywords[PKW_LINEAR].str); if (part_info->list_of_subpart_fields) err+= add_key_partition(fptr, part_info->subpart_field_list); else @@ -1863,7 +1863,7 @@ char *generate_partition_syntax(partition_info *part_info, tot_no_parts= part_info->partitions.elements; no_subparts= part_info->no_subparts; - if (write_all || (!part_info->use_default_partitions)) + if (!part_info->use_default_partitions) { bool first= TRUE; err+= add_begin_parenthesis(fptr); @@ -1884,10 +1884,12 @@ char *generate_partition_syntax(partition_info *part_info, err+= add_name_string(fptr, part_elem->partition_name); err+= add_space(fptr); err+= add_partition_values(fptr, part_info, part_elem); - if (!part_info->is_sub_partitioned()) + if (!part_info->is_sub_partitioned() || + part_info->use_default_subpartitions) + { err+= add_partition_options(fptr, part_elem); - if (part_info->is_sub_partitioned() && - (write_all || (!part_info->use_default_subpartitions))) + } + else { err+= add_space(fptr); err+= add_begin_parenthesis(fptr); @@ -2194,9 +2196,11 @@ static uint32 get_part_id_linear_key(partition_info *part_info, out:part_id The partition id is returned through this pointer RETURN VALUE - part_id - return TRUE means that the fields of the partition function didn't fit - into any partition and thus the values of the PF-fields are not allowed. + part_id Partition id of partition that would contain + row with given values of PF-fields + HA_ERR_NO_PARTITION_FOUND The fields of the partition function didn't + fit into any partition and thus the values of + the PF-fields are not allowed. DESCRIPTION A routine used from write_row, update_row and delete_row from any @@ -2235,9 +2239,11 @@ static uint32 get_part_id_linear_key(partition_info *part_info, out:part_id The partition id is returned through this pointer RETURN VALUE - part_id - return TRUE means that the fields of the partition function didn't fit - into any partition and thus the values of the PF-fields are not allowed. + part_id Partition id of partition that would contain + row with given values of PF-fields + HA_ERR_NO_PARTITION_FOUND The fields of the partition function didn't + fit into any partition and thus the values of + the PF-fields are not allowed. DESCRIPTION @@ -3558,17 +3564,9 @@ static bool check_engine_condition(partition_element *p_elem, DBUG_ENTER("check_engine_condition"); DBUG_PRINT("enter", ("def_eng = %u, first = %u", default_engine, *first)); - if (*engine_type) - DBUG_PRINT("info", ("engine_type = %s", (*engine_type)->name)); - else - DBUG_PRINT("info", ("engine_type = NULL")); if (*first && default_engine) { *engine_type= p_elem->engine_type; - if (*engine_type) - DBUG_PRINT("info", ("engine_type changed to = %s", (*engine_type)->name)); - else - DBUG_PRINT("info", ("engine_type changed to = NULL")); } *first= FALSE; if ((!default_engine && @@ -3878,6 +3876,7 @@ uint prep_alter_part_table(THD *thd, TABLE *table, ALTER_INFO *alter_info, DBUG_RETURN(TRUE); } alt_part_info->part_type= tab_part_info->part_type; + alt_part_info->subpart_type= tab_part_info->subpart_type; if (alt_part_info->set_up_defaults_for_partitioning(table->file, ULL(0), tab_part_info->no_parts)) @@ -4075,6 +4074,7 @@ that are reorganised. tab_part_info->use_default_partitions= FALSE; } tab_part_info->use_default_no_partitions= FALSE; + tab_part_info->is_auto_partitioned= FALSE; } } else if (alter_info->flags == ALTER_DROP_PARTITION) @@ -4090,6 +4090,8 @@ that are reorganised. uint no_parts_dropped= alter_info->partition_names.elements; uint no_parts_found= 0; List_iterator<partition_element> part_it(tab_part_info->partitions); + + tab_part_info->is_auto_partitioned= FALSE; if (!(tab_part_info->part_type == RANGE_PARTITION || tab_part_info->part_type == LIST_PARTITION)) { @@ -4274,7 +4276,10 @@ state of p1. tab_part_info->no_parts= no_parts_remain; } if (!(alter_info->flags & ALTER_TABLE_REORG)) + { tab_part_info->use_default_no_partitions= FALSE; + tab_part_info->is_auto_partitioned= FALSE; + } } else if (alter_info->flags == ALTER_REORGANIZE_PARTITION) { @@ -4293,6 +4298,8 @@ state of p1. uint no_parts_new= thd->work_part_info->partitions.elements; partition_info *alt_part_info= thd->work_part_info; uint check_total_partitions; + + tab_part_info->is_auto_partitioned= FALSE; if (no_parts_reorged > tab_part_info->no_parts) { my_error(ER_REORG_PARTITION_NOT_EXIST, MYF(0)); @@ -4312,6 +4319,15 @@ state of p1. my_error(ER_TOO_MANY_PARTITIONS_ERROR, MYF(0)); DBUG_RETURN(TRUE); } + alt_part_info->part_type= tab_part_info->part_type; + alt_part_info->subpart_type= tab_part_info->subpart_type; + DBUG_ASSERT(!alt_part_info->use_default_partitions); + if (alt_part_info->set_up_defaults_for_partitioning(table->file, + ULL(0), + 0)) + { + DBUG_RETURN(TRUE); + } /* Online handling: REORGANIZE PARTITION: @@ -4448,7 +4464,7 @@ the generated partition syntax in a correct manner. tab_part_info->use_default_no_subpartitions= FALSE; } if (tab_part_info->check_partition_info((handlerton**)NULL, - table->file, ULL(0))) + table->file, ULL(0))) { DBUG_RETURN(TRUE); } @@ -4509,13 +4525,13 @@ the generated partition syntax in a correct manner. if (alter_info->flags & ALTER_REMOVE_PARTITIONING) { DBUG_PRINT("info", ("Remove partitioning")); - if (!(thd->lex->create_info.used_fields & HA_CREATE_USED_ENGINE)) + if (!(create_info->used_fields & HA_CREATE_USED_ENGINE)) { DBUG_PRINT("info", ("No explicit engine used")); create_info->db_type= table->part_info->default_engine_type; } - DBUG_PRINT("info", ("New engine type = %s", - create_info->db_type->name)); + DBUG_PRINT("info", ("New engine type: %s", + hton2plugin[create_info->db_type->slot]->name.str)); thd->work_part_info= NULL; *partition_changed= TRUE; } @@ -4526,14 +4542,29 @@ the generated partition syntax in a correct manner. beneath. */ thd->work_part_info= table->part_info; - if (thd->lex->create_info.used_fields & HA_CREATE_USED_ENGINE && + if (create_info->used_fields & HA_CREATE_USED_ENGINE && create_info->db_type != table->part_info->default_engine_type) { /* Make sure change of engine happens to all partitions. */ DBUG_PRINT("info", ("partition changed")); - set_engine_all_partitions(thd->work_part_info, create_info->db_type); + if (table->part_info->is_auto_partitioned) + { + /* + If the user originally didn't specify partitioning to be + used we can remove it now. + */ + thd->work_part_info= NULL; + } + else + { + /* + Ensure that all partitions have the proper engine set-up + */ + set_engine_all_partitions(thd->work_part_info, + create_info->db_type); + } *partition_changed= TRUE; } } @@ -4562,11 +4593,9 @@ the generated partition syntax in a correct manner. } if (!is_native_partitioned) { - DBUG_ASSERT(create_info->db_type != &default_hton); + DBUG_ASSERT(create_info->db_type); create_info->db_type= &partition_hton; } - DBUG_PRINT("info", ("default_engine_type = %s", - thd->work_part_info->default_engine_type->name)); } } DBUG_RETURN(FALSE); diff --git a/sql/sql_partition.h b/sql/sql_partition.h index fd2c474236f..87f9a751ca3 100644 --- a/sql/sql_partition.h +++ b/sql/sql_partition.h @@ -69,8 +69,7 @@ bool check_partition_info(partition_info *part_info,handlerton **eng_type, bool fix_partition_func(THD *thd, const char *name, TABLE *table, bool create_table_ind); char *generate_partition_syntax(partition_info *part_info, - uint *buf_length, bool use_sql_alloc, - bool write_all); + uint *buf_length, bool use_sql_alloc); bool partition_key_modified(TABLE *table, List<Item> &fields); void get_partition_set(const TABLE *table, byte *buf, const uint index, const key_range *key_spec, diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index b5050204761..f4bd65c20de 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -23,12 +23,18 @@ extern struct st_mysql_plugin *mysqld_builtins[]; char *opt_plugin_dir_ptr; char opt_plugin_dir[FN_REFLEN]; -LEX_STRING plugin_type_names[]= +LEX_STRING plugin_type_names[MYSQL_MAX_PLUGIN_TYPE_NUM]= { { (char *)STRING_WITH_LEN("UDF") }, { (char *)STRING_WITH_LEN("STORAGE ENGINE") }, { (char *)STRING_WITH_LEN("FTPARSER") } }; + +plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM]= +{ + 0,ha_initialize_handlerton,0 +}; + static const char *plugin_interface_version_sym= "_mysql_plugin_interface_version_"; static const char *sizeof_st_plugin_sym= @@ -41,8 +47,8 @@ static int min_plugin_interface_version= 0x0000; static int min_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]= { 0x0000, - 0x0000, - 0x0000 + MYSQL_HANDLERTON_INTERFACE_VERSION, + MYSQL_FTPARSER_INTERFACE_VERSION }; static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]= { @@ -50,6 +56,7 @@ static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]= MYSQL_HANDLERTON_INTERFACE_VERSION, MYSQL_FTPARSER_INTERFACE_VERSION }; + static DYNAMIC_ARRAY plugin_dl_array; static DYNAMIC_ARRAY plugin_array; static HASH plugin_hash[MYSQL_MAX_PLUGIN_TYPE_NUM]; @@ -522,27 +529,15 @@ static int plugin_initialize(struct st_plugin_int *plugin) { 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) + if (plugin_type_initialize[plugin->plugin->type] && + (*plugin_type_initialize[plugin->plugin->type])(plugin)) { - case MYSQL_STORAGE_ENGINE_PLUGIN: - if (ha_initialize_handlerton(plugin)) - { - 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; + sql_print_error("Plugin '%s' registration as a %s failed.", + plugin->name.str, plugin_type_names[plugin->plugin->type]); + goto err; } DBUG_RETURN(0); @@ -554,14 +549,14 @@ static int plugin_finalize(THD *thd, struct st_plugin_int *plugin) { int rc; DBUG_ENTER("plugin_finalize"); - + if (plugin->ref_count) { push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, "Plugin is busy and will be uninstalled on shutdown"); goto err; } - + switch (plugin->plugin->type) { case MYSQL_STORAGE_ENGINE_PLUGIN: @@ -591,7 +586,7 @@ static int plugin_finalize(THD *thd, struct st_plugin_int *plugin) goto err; } } - + DBUG_RETURN(0); err: DBUG_RETURN(1); @@ -676,7 +671,7 @@ int plugin_init(void) get_hash_key, NULL, 0)) goto err; } - + /* Register all the built-in plugins */ for (builtins= mysqld_builtins; *builtins; builtins++) { @@ -684,6 +679,12 @@ int plugin_init(void) { if (plugin_register_builtin(plugin)) goto err; + struct st_plugin_int *tmp=dynamic_element(&plugin_array, + plugin_array.elements-1, + struct st_plugin_int *); + if (plugin_initialize(tmp)) + goto err; + tmp->state= PLUGIN_IS_READY; } } diff --git a/sql/sql_plugin.h b/sql/sql_plugin.h index 672db105cd1..b013beaba1f 100644 --- a/sql/sql_plugin.h +++ b/sql/sql_plugin.h @@ -58,9 +58,12 @@ struct st_plugin_int struct st_mysql_plugin *plugin; struct st_plugin_dl *plugin_dl; enum enum_plugin_state state; - uint ref_count; /* number of threads using the plugin */ + uint ref_count; /* number of threads using the plugin */ + void *data; /* plugin type specific, e.g. handlerton */ }; +typedef int (*plugin_type_init)(struct st_plugin_int *); + extern char *opt_plugin_dir_ptr; extern char opt_plugin_dir[FN_REFLEN]; extern LEX_STRING plugin_type_names[]; diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index f6f4e5baa53..078c7e01d5a 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -2088,19 +2088,20 @@ void reinit_stmt_before_use(THD *thd, LEX *lex) sl->exclude_from_table_unique_test= FALSE; /* - Copy WHERE, HAVING clause pointers to avoid damaging them by optimisation + Copy WHERE, HAVING clause pointers to avoid damaging them + by optimisation */ - if (sl->prep_where) - { - sl->where= sl->prep_where->copy_andor_structure(thd); - sl->where->cleanup(); - } - if (sl->prep_having) - { - sl->having= sl->prep_having->copy_andor_structure(thd); - sl->having->cleanup(); - } - DBUG_ASSERT(sl->join == 0); + if (sl->prep_where) + { + sl->where= sl->prep_where->copy_andor_structure(thd); + sl->where->cleanup(); + } + if (sl->prep_having) + { + sl->having= sl->prep_having->copy_andor_structure(thd); + sl->having->cleanup(); + } + DBUG_ASSERT(sl->join == 0); ORDER *order; /* Fix GROUP list */ for (order= (ORDER *)sl->group_list.first; order; order= order->next) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 40e13762051..03ed8ce3e8c 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -337,8 +337,10 @@ JOIN::prepare(Item ***rref_pointer_array, /* Check that all tables, fields, conds and order are ok */ if ((!(select_options & OPTION_SETUP_TABLES_DONE) && - setup_tables(thd, &select_lex->context, join_list, - tables_list, &select_lex->leaf_tables, FALSE)) || + setup_tables_and_check_access(thd, &select_lex->context, join_list, + tables_list, + &select_lex->leaf_tables, FALSE, + SELECT_ACL)) || setup_wild(thd, tables_list, fields_list, &all_fields, wild_num) || select_lex->setup_ref_array(thd, og_num) || setup_fields(thd, (*rref_pointer_array), fields_list, MARK_COLUMNS_READ, @@ -2406,7 +2408,19 @@ merge_key_fields(KEY_FIELD *start,KEY_FIELD *new_fields,KEY_FIELD *end, { if (old->field == new_fields->field) { - if (new_fields->val->used_tables()) + /* + NOTE: below const_item() call really works as "!used_tables()", i.e. + it can return FALSE where it is feasible to make it return TRUE. + + The cause is as follows: Some of the tables are already known to be + const tables (the detection code is in make_join_statistics(), + above the update_ref_and_keys() call), but we didn't propagate + information about this: TABLE::const_table is not set to TRUE, and + Item::update_used_tables() hasn't been called for each item. + The result of this is that we're missing some 'ref' accesses. + TODO: OptimizerTeam: Fix this + */ + if (!new_fields->val->const_item()) { /* If the value matches, we can use the key reference. @@ -2436,7 +2450,8 @@ merge_key_fields(KEY_FIELD *start,KEY_FIELD *new_fields,KEY_FIELD *end, new_fields->null_rejecting); } else if (old->eq_func && new_fields->eq_func && - (old->val->is_null() || new_fields->val->is_null())) + ((old->val->const_item() && old->val->is_null()) || + new_fields->val->is_null())) { /* field = expression OR field IS NULL */ old->level= and_level; @@ -3352,7 +3367,10 @@ best_access_path(JOIN *join, uint key= keyuse->key; KEY *keyinfo= table->key_info+key; bool ft_key= (keyuse->keypart == FT_KEYPART); - uint found_ref_or_null= 0; + /* Bitmap of keyparts where the ref access is over 'keypart=const': */ + key_part_map const_part= 0; + /* The or-null keypart in ref-or-null access: */ + key_part_map ref_or_null_part= 0; /* Calculate how many key segments of the current key we can use */ start_key= keyuse; @@ -3364,12 +3382,14 @@ best_access_path(JOIN *join, do { if (!(remaining_tables & keyuse->used_tables) && - !(found_ref_or_null & keyuse->optimize)) + !(ref_or_null_part && (keyuse->optimize & + KEY_OPTIMIZE_REF_OR_NULL))) { found_part|= keyuse->keypart_map; - double tmp= prev_record_reads(join, - (found_ref | - keyuse->used_tables)); + if (!(keyuse->used_tables & ~join->const_table_map)) + const_part|= keyuse->keypart_map; + double tmp= prev_record_reads(join, (found_ref | + keyuse->used_tables)); if (tmp < best_prev_record_reads) { best_part_found_ref= keyuse->used_tables; @@ -3381,8 +3401,8 @@ best_access_path(JOIN *join, If there is one 'key_column IS NULL' expression, we can use this ref_or_null optimisation of this field */ - found_ref_or_null|= (keyuse->optimize & - KEY_OPTIMIZE_REF_OR_NULL); + if (keyuse->optimize & KEY_OPTIMIZE_REF_OR_NULL) + ref_or_null_part |= keyuse->keypart_map; } keyuse++; } while (keyuse->table == table && keyuse->key == key && @@ -3418,7 +3438,7 @@ best_access_path(JOIN *join, Check if we found full key */ if (found_part == PREV_BITS(uint,keyinfo->key_parts) && - !found_ref_or_null) + !ref_or_null_part) { /* use eq key */ max_key_part= (uint) ~0; if ((keyinfo->flags & (HA_NOSAME | HA_NULL_PART_KEY)) == HA_NOSAME) @@ -3430,6 +3450,23 @@ best_access_path(JOIN *join, { if (!found_ref) { /* We found a const key */ + /* + ReuseRangeEstimateForRef-1: + We get here if we've found a ref(const) (c_i are constants): + "(keypart1=c1) AND ... AND (keypartN=cN)" [ref_const_cond] + + If range optimizer was able to construct a "range" + access on this index, then its condition "quick_cond" was + eqivalent to ref_const_cond (*), and we can re-use E(#rows) + from the range optimizer. + + Proof of (*): By properties of range and ref optimizers + quick_cond will be equal or tighther than ref_const_cond. + ref_const_cond already covers "smallest" possible interval - + a singlepoint interval over all keyparts. Therefore, + quick_cond is equivalent to ref_const_cond (if it was an + empty interval we wouldn't have got here). + */ if (table->quick_keys.is_set(key)) records= (double) table->quick_rows[key]; else @@ -3450,6 +3487,23 @@ best_access_path(JOIN *join, if (records < 2.0) records=2.0; /* Can't be as good as a unique */ } + /* + ReuseRangeEstimateForRef-2: We get here if we could not reuse + E(#rows) from range optimizer. Make another try: + + If range optimizer produced E(#rows) for a prefix of the ref + access we're considering, and that E(#rows) is lower then our + current estimate, make an adjustment. The criteria of when we + can make an adjustment is a special case of the criteria used + in ReuseRangeEstimateForRef-3. + */ + if (table->quick_keys.is_set(key) && + const_part & (1 << table->quick_key_parts[key]) && + table->quick_n_ranges[key] == 1 && + records > (double) table->quick_rows[key]) + { + records= (double) table->quick_rows[key]; + } } /* Limit the number of matched rows */ tmp= records; @@ -3478,12 +3532,50 @@ best_access_path(JOIN *join, { max_key_part= max_part_bit(found_part); /* - Check if quick_range could determinate how many rows we - will match + ReuseRangeEstimateForRef-3: + We're now considering a ref[or_null] access via + (t.keypart1=e1 AND ... AND t.keypartK=eK) [ OR + (same-as-above but with one cond replaced + with "t.keypart_i IS NULL")] (**) + + Try re-using E(#rows) from "range" optimizer: + We can do so if "range" optimizer used the same intervals as + in (**). The intervals used by range optimizer may be not + available at this point (as "range" access might have choosen to + create quick select over another index), so we can't compare + them to (**). We'll make indirect judgements instead. + The sufficient conditions for re-use are: + (C1) All e_i in (**) are constants, i.e. found_ref==FALSE. (if + this is not satisfied we have no way to know which ranges + will be actually scanned by 'ref' until we execute the + join) + (C2) max #key parts in 'range' access == K == max_key_part (this + is apparently a necessary requirement) + + We also have a property that "range optimizer produces equal or + tighter set of scan intervals than ref(const) optimizer". Each + of the intervals in (**) are "tightest possible" intervals when + one limits itself to using keyparts 1..K (which we do in #2). + From here it follows that range access used either one, or + both of the (I1) and (I2) intervals: + + (t.keypart1=c1 AND ... AND t.keypartK=eK) (I1) + (same-as-above but with one cond replaced + with "t.keypart_i IS NULL") (I2) + + The remaining part is to exclude the situation where range + optimizer used one interval while we're considering + ref-or-null and looking for estimate for two intervals. This + is done by last limitation: + + (C3) "range optimizer used (have ref_or_null?2:1) intervals" */ - if (table->quick_keys.is_set(key) && - table->quick_key_parts[key] == max_key_part) + if (table->quick_keys.is_set(key) && !found_ref && //(C1) + table->quick_key_parts[key] == max_key_part && //(C2) + table->quick_n_ranges[key] == 1+test(ref_or_null_part)) //(C3) + { tmp= records= (double) table->quick_rows[key]; + } else { /* Check if we have statistic about the distribution */ @@ -3527,21 +3619,37 @@ best_access_path(JOIN *join, } records = (ulong) tmp; } + + if (ref_or_null_part) + { + /* We need to do two key searches to find key */ + tmp *= 2.0; + records *= 2.0; + } + /* - If quick_select was used on a part of this key, we know - the maximum number of rows that the key can match. + ReuseRangeEstimateForRef-4: We get here if we could not reuse + E(#rows) from range optimizer. Make another try: + + If range optimizer produced E(#rows) for a prefix of the ref + access we're considering, and that E(#rows) is lower then our + current estimate, make the adjustment. + + The decision whether we can re-use the estimate from the range + optimizer is the same as in ReuseRangeEstimateForRef-3, + applied to first table->quick_key_parts[key] key parts. */ if (table->quick_keys.is_set(key) && table->quick_key_parts[key] <= max_key_part && + const_part & (1 << table->quick_key_parts[key]) && + table->quick_n_ranges[key] == 1 + test(ref_or_null_part & + const_part) && records > (double) table->quick_rows[key]) - tmp= records= (double) table->quick_rows[key]; - else if (found_ref_or_null) { - /* We need to do two key searches to find key */ - tmp *= 2.0; - records *= 2.0; + tmp= records= (double) table->quick_rows[key]; } } + /* Limit the number of matched rows */ set_if_smaller(tmp, (double) thd->variables.max_seeks_for_key); if (table->used_keys.is_set(key)) @@ -4357,344 +4465,11 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count, if ((rest_tables & real_table_bit) && !(rest_tables & s->dependent) && (!idx|| !check_interleaving_with_nj(join->positions[idx-1].table, s))) { - double best,best_time,records; - best=best_time=records=DBL_MAX; - KEYUSE *best_key=0; - uint best_max_key_part=0; - my_bool found_constraint= 0; - - if (s->keyuse) - { /* Use key if possible */ - TABLE *table=s->table; - KEYUSE *keyuse,*start_key=0; - double best_records=DBL_MAX; - uint max_key_part=0; - - /* Test how we can use keys */ - rec= s->records/MATCHING_ROWS_IN_OTHER_TABLE; // Assumed records/key - for (keyuse=s->keyuse ; keyuse->table == table ;) - { - key_part_map found_part=0; - table_map found_ref=0; - uint key=keyuse->key; - KEY *keyinfo=table->key_info+key; - bool ft_key=(keyuse->keypart == FT_KEYPART); - uint found_ref_or_null= 0; - - /* Calculate how many key segments of the current key we can use */ - start_key=keyuse; - do - { - uint keypart=keyuse->keypart; - table_map best_part_found_ref= 0; - double best_prev_record_reads= DBL_MAX; - do - { - if (!(rest_tables & keyuse->used_tables) && - !(found_ref_or_null & keyuse->optimize)) - { - found_part|=keyuse->keypart_map; - double tmp= prev_record_reads(join, - (found_ref | - keyuse->used_tables)); - if (tmp < best_prev_record_reads) - { - best_part_found_ref= keyuse->used_tables; - best_prev_record_reads= tmp; - } - if (rec > keyuse->ref_table_rows) - rec= keyuse->ref_table_rows; - /* - If there is one 'key_column IS NULL' expression, we can - use this ref_or_null optimisation of this field - */ - found_ref_or_null|= (keyuse->optimize & - KEY_OPTIMIZE_REF_OR_NULL); - } - keyuse++; - } while (keyuse->table == table && keyuse->key == key && - keyuse->keypart == keypart); - found_ref|= best_part_found_ref; - } while (keyuse->table == table && keyuse->key == key); - - /* - Assume that that each key matches a proportional part of table. - */ - if (!found_part && !ft_key) - continue; // Nothing usable found - if (rec < MATCHING_ROWS_IN_OTHER_TABLE) - rec= MATCHING_ROWS_IN_OTHER_TABLE; // Fix for small tables - - /* - ft-keys require special treatment - */ - if (ft_key) - { - /* - Really, there should be records=0.0 (yes!) - but 1.0 would be probably safer - */ - tmp=prev_record_reads(join,found_ref); - records=1.0; - } - else - { - found_constraint= 1; - /* - Check if we found full key - */ - if (found_part == PREV_BITS(uint,keyinfo->key_parts) && - !found_ref_or_null) - { /* use eq key */ - max_key_part= (uint) ~0; - if ((keyinfo->flags & (HA_NOSAME | HA_NULL_PART_KEY | - HA_END_SPACE_KEY)) == HA_NOSAME) - { - tmp=prev_record_reads(join,found_ref); - records=1.0; - } - else - { - if (!found_ref) - { // We found a const key - if (table->quick_keys.is_set(key)) - records= (double) table->quick_rows[key]; - else - { - /* quick_range couldn't use key! */ - records= (double) s->records/rec; - } - } - else - { - if (!(records=keyinfo->rec_per_key[keyinfo->key_parts-1])) - { // Prefere longer keys - records= - ((double) s->records / (double) rec * - (1.0 + - ((double) (table->s->max_key_length-keyinfo->key_length) / - (double) table->s->max_key_length))); - if (records < 2.0) - records=2.0; // Can't be as good as a unique - } - } - /* Limit the number of matched rows */ - tmp= records; - set_if_smaller(tmp, (double) thd->variables.max_seeks_for_key); - if (table->used_keys.is_set(key)) - { - /* we can use only index tree */ - uint keys_per_block= table->file->stats.block_size/2/ - (keyinfo->key_length+table->file->ref_length)+1; - tmp=record_count*(tmp+keys_per_block-1)/keys_per_block; - } - else - tmp=record_count*min(tmp,s->worst_seeks); - } - } - else - { - /* - Use as much key-parts as possible and a uniq key is better - than a not unique key - Set tmp to (previous record count) * (records / combination) - */ - if ((found_part & 1) && - (!(table->file->index_flags(key,0,0) & HA_ONLY_WHOLE_INDEX) || - found_part == PREV_BITS(uint,keyinfo->key_parts))) - { - max_key_part=max_part_bit(found_part); - /* - Check if quick_range could determinate how many rows we - will match - */ - if (table->quick_keys.is_set(key) && - table->quick_key_parts[key] == max_key_part) - tmp=records= (double) table->quick_rows[key]; - else - { - /* Check if we have statistic about the distribution */ - if ((records=keyinfo->rec_per_key[max_key_part-1])) - tmp=records; - else - { - /* - Assume that the first key part matches 1% of the file - and that the whole key matches 10 (duplicates) or 1 - (unique) records. - Assume also that more key matches proportionally more - records - This gives the formula: - records= (x * (b-a) + a*c-b)/(c-1) - - b = records matched by whole key - a = records matched by first key part (10% of all records?) - c = number of key parts in key - x = used key parts (1 <= x <= c) - */ - double rec_per_key; - rec_per_key= keyinfo->rec_per_key[keyinfo->key_parts-1] ? - (double) keyinfo->rec_per_key[keyinfo->key_parts-1] : - (double) s->records/rec+1; - if (!s->records) - tmp=0; - else if (rec_per_key/(double) s->records >= 0.01) - tmp=rec_per_key; - else - { - double a=s->records*0.01; - tmp=(max_key_part * (rec_per_key - a) + - a*keyinfo->key_parts - rec_per_key)/ - (keyinfo->key_parts-1); - set_if_bigger(tmp,1.0); - } - records=(ulong) tmp; - } - /* - If quick_select was used on a part of this key, we know - the maximum number of rows that the key can match. - */ - if (table->quick_keys.is_set(key) && - table->quick_key_parts[key] <= max_key_part && - records > (double) table->quick_rows[key]) - tmp= records= (double) table->quick_rows[key]; - else if (found_ref_or_null) - { - /* We need to do two key searches to find key */ - tmp*= 2.0; - records*= 2.0; - } - } - /* Limit the number of matched rows */ - set_if_smaller(tmp, (double) thd->variables.max_seeks_for_key); - if (table->used_keys.is_set(key)) - { - /* we can use only index tree */ - uint keys_per_block= table->file->stats.block_size/2/ - (keyinfo->key_length+table->file->ref_length)+1; - tmp=record_count*(tmp+keys_per_block-1)/keys_per_block; - } - else - tmp=record_count*min(tmp,s->worst_seeks); - } - else - tmp=best_time; // Do nothing - } - } /* not ft_key */ - if (tmp < best_time - records/(double) TIME_FOR_COMPARE) - { - best_time=tmp + records/(double) TIME_FOR_COMPARE; - best=tmp; - best_records=records; - best_key=start_key; - best_max_key_part=max_key_part; - } - } - records=best_records; - } - - /* - Don't test table scan if it can't be better. - Prefer key lookup if we would use the same key for scanning. - - Don't do a table scan on InnoDB tables, if we can read the used - parts of the row from any of the used index. - This is because table scans uses index and we would not win - anything by using a table scan. - (see comment in best_access_path() for more details on the below - condition) - */ - if ((records >= s->found_records || best > s->read_time) && - !(s->quick && best_key && s->quick->index == best_key->key && - best_max_key_part >= s->table->quick_key_parts[best_key->key]) && - !((s->table->file->ha_table_flags() & HA_TABLE_SCAN_ON_INDEX) && - ! s->table->used_keys.is_clear_all() && best_key) && - !(s->table->force_index && best_key && !s->quick)) - { // Check full join - ha_rows rnd_records= s->found_records; - /* - If there is a restriction on the table, assume that 25% of the - rows can be skipped on next part. - This is to force tables that this table depends on before this - table - */ - if (found_constraint) - rnd_records-= rnd_records/4; - - /* - Range optimizer never proposes a RANGE if it isn't better - than FULL: so if RANGE is present, it's always preferred to FULL. - Here we estimate its cost. - */ - if (s->quick) - { - /* - For each record we: - - read record range through 'quick' - - skip rows which does not satisfy WHERE constraints - */ - tmp= record_count * - (s->quick->read_time + - (s->found_records - rnd_records)/(double) TIME_FOR_COMPARE); - } - else - { - /* Estimate cost of reading table. */ - tmp= s->table->file->scan_time(); - if (s->table->map & join->outer_join) // Can't use join cache - { - /* - For each record we have to: - - read the whole table record - - skip rows which does not satisfy join condition - */ - tmp= record_count * - (tmp + - (s->records - rnd_records)/(double) TIME_FOR_COMPARE); - } - else - { - /* We read the table as many times as join buffer becomes full. */ - tmp*= (1.0 + floor((double) cache_record_length(join,idx) * - record_count / - (double) thd->variables.join_buff_size)); - /* - We don't make full cartesian product between rows in the scanned - table and existing records because we skip all rows from the - scanned table, which does not satisfy join condition when - we read the table (see flush_cached_records for details). Here we - take into account cost to read and skip these records. - */ - tmp+= (s->records - rnd_records)/(double) TIME_FOR_COMPARE; - } - } - - /* - We estimate the cost of evaluating WHERE clause for found records - as record_count * rnd_records / TIME_FOR_COMPARE. This cost plus - tmp give us total cost of using TABLE SCAN - */ - if (best == DBL_MAX || - (tmp + record_count/(double) TIME_FOR_COMPARE*rnd_records < - best + record_count/(double) TIME_FOR_COMPARE*records)) - { - /* - If the table has a range (s->quick is set) make_join_select() - will ensure that this will be used - */ - best=tmp; - records= rows2double(rnd_records); - best_key=0; - } - } - join->positions[idx].records_read= records; - join->positions[idx].key=best_key; - join->positions[idx].table= s; - if (!best_key && idx == join->const_tables && - s->table == join->sort_by_table && - join->unit->select_limit_cnt >= records) - join->sort_by_table= (TABLE*) 1; // Must use temporary table - + double records, best; + best_access_path(join, s, thd, rest_tables, idx, record_count, + read_time); + records= join->positions[idx].records_read; + best= join->positions[idx].read_time; /* Go to the next level only if there hasn't been a better key on this level! This will cut down the search for a lot simple cases! @@ -8255,6 +8030,7 @@ Field *create_tmp_field_from_field(THD *thd, Field *org_field, item->result_field= new_field; else new_field->field_name= name; + new_field->flags|= (org_field->flags & NO_DEFAULT_VALUE_FLAG); if (org_field->maybe_null() || (item && item->maybe_null)) new_field->flags&= ~NOT_NULL_FLAG; // Because of outer join if (org_field->type() == MYSQL_TYPE_VAR_STRING || @@ -8395,6 +8171,7 @@ Field *create_tmp_field_for_schema(THD *thd, Item *item, TABLE *table) in this array from_field if field will be created using other field as example, pointer example field will be written here + default_field If field has a default value field, store it here group 1 if we are going to do a relative group by on result modify_item 1 if item->result_field should point to new item. This is relevent for how fill_record() is going to @@ -8413,11 +8190,13 @@ Field *create_tmp_field_for_schema(THD *thd, Item *item, TABLE *table) Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, Item ***copy_func, Field **from_field, + Field **default_field, bool group, bool modify_item, bool table_cant_handle_bit_fields, bool make_copy_field, uint convert_blob_length) { + Field *result; Item::Type orig_type= type; Item *orig_item= 0; @@ -8435,8 +8214,7 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, case Item::SUM_FUNC_ITEM: { Item_sum *item_sum=(Item_sum*) item; - Field *result= item_sum->create_tmp_field(group, table, - convert_blob_length); + result= item_sum->create_tmp_field(group, table, convert_blob_length); if (!result) thd->fatal_error(); return result; @@ -8446,7 +8224,6 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, { Item_field *field= (Item_field*) item; bool orig_modify= modify_item; - Field *result; if (orig_type == Item::REF_ITEM) modify_item= 0; /* @@ -8480,6 +8257,8 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, convert_blob_length); if (orig_type == Item::REF_ITEM && orig_modify) ((Item_ref*)orig_item)->set_result_field(result); + if (field->field->eq_def(result)) + *default_field= field->field; return result; } /* Fall through */ @@ -8502,10 +8281,10 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, DBUG_ASSERT(((Item_result_field*)item)->result_field); *from_field= ((Item_result_field*)item)->result_field; } - return create_tmp_field_from_item(thd, item, table, (make_copy_field ? 0 : - copy_func), modify_item, - convert_blob_length); - case Item::TYPE_HOLDER: + return create_tmp_field_from_item(thd, item, table, + (make_copy_field ? 0 : copy_func), + modify_item, convert_blob_length); + case Item::TYPE_HOLDER: return ((Item_type_holder *)item)->make_field_by_type(table); default: // Dosen't have to be stored return 0; @@ -8591,7 +8370,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, char *tmpname,path[FN_REFLEN]; byte *pos, *group_buff, *bitmaps; uchar *null_flags; - Field **reg_field, **from_field; + Field **reg_field, **from_field, **default_field; uint *blob_field; Copy_field *copy=0; KEY *keyinfo; @@ -8662,6 +8441,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, &table, sizeof(*table), &share, sizeof(*share), ®_field, sizeof(Field*) * (field_count+1), + &default_field, sizeof(Field*) * (field_count), &blob_field, sizeof(uint)*(field_count+1), &from_field, sizeof(Field*)*field_count, ©_func, sizeof(*copy_func)*(copy_func_count+1), @@ -8692,6 +8472,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, bzero((char*) table,sizeof(*table)); bzero((char*) reg_field,sizeof(Field*)*(field_count+1)); + bzero((char*) default_field, sizeof(Field*) * (field_count)); bzero((char*) from_field,sizeof(Field*)*field_count); table->mem_root= own_root; @@ -8760,7 +8541,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, { Field *new_field= create_tmp_field(thd, table, arg, arg->type(), ©_func, - tmp_from_field, group != 0,not_all_columns, + tmp_from_field, &default_field[fieldnr], + group != 0,not_all_columns, distinct, 0, param->convert_blob_length); if (!new_field) @@ -8769,7 +8551,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, reclength+=new_field->pack_length(); if (new_field->flags & BLOB_FLAG) { - *blob_field++= (uint) (reg_field - table->field); + *blob_field++= fieldnr; blob_count++; } if (new_field->type() == FIELD_TYPE_BIT) @@ -8815,7 +8597,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, Field *new_field= (param->schema_table) ? create_tmp_field_for_schema(thd, item, table) : create_tmp_field(thd, table, item, type, ©_func, - tmp_from_field, group != 0, + tmp_from_field, &default_field[fieldnr], + group != 0, !force_copy_fields && (not_all_columns || group !=0), item->marker == 4, force_copy_fields, @@ -8866,6 +8649,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, DBUG_ASSERT(fieldnr == (uint) (reg_field - table->field)); DBUG_ASSERT(field_count >= (uint) (reg_field - table->field)); field_count= fieldnr; + *reg_field= 0; *blob_field= 0; // End marker share->fields= field_count; @@ -8985,6 +8769,34 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, null_count+= (field->field_length & 7); } field->reset(); + + /* + Test if there is a default field value. The test for ->ptr is to skip + 'offset' fields generated by initalize_tables + */ + if (default_field[i] && default_field[i]->ptr) + { + /* + default_field[i] is set only in the cases when 'field' can + inherit the default value that is defined for the field referred + by the Item_field object from which 'field' has been created. + */ + my_ptrdiff_t diff; + Field *orig_field= default_field[i]; + /* Get the value from default_values */ + diff= (my_ptrdiff_t) (orig_field->table->s->default_values- + orig_field->table->record[0]); + orig_field->move_field_offset(diff); // Points now at default_values + if (orig_field->is_real_null()) + field->set_null(); + else + { + field->set_notnull(); + memcpy(field->ptr, orig_field->ptr, field->pack_length()); + } + orig_field->move_field_offset(-diff); // Back to record[0] + } + if (from_field[i]) { /* Not a table Item */ copy->set(field,from_field[i],save_sum_fields); @@ -9519,7 +9331,7 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param, all places where a corresponding end_bulk_insert() should be put. */ table->file->info(HA_STATUS_VARIABLE); /* update table->file->stats.records */ - new_table.file->start_bulk_insert(table->file->stats.records); + new_table.file->ha_start_bulk_insert(table->file->stats.records); #else /* HA_EXTRA_WRITE_CACHE can stay until close, no need to disable it */ new_table.file->extra(HA_EXTRA_WRITE_CACHE); @@ -12539,6 +12351,8 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, Item::Type order_item_type; Item **select_item; /* The corresponding item from the SELECT clause. */ Field *from_field; /* The corresponding field from the FROM clause. */ + uint counter; + bool unaliased; /* Local SP variables may be int but are expressions, not positions. @@ -12560,8 +12374,6 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, return FALSE; } /* Lookup the current GROUP/ORDER field in the SELECT clause. */ - uint counter; - bool unaliased; select_item= find_item_in_list(order_item, fields, &counter, REPORT_EXCEPT_NOT_FOUND, &unaliased); if (!select_item) @@ -12835,6 +12647,17 @@ create_distinct_group(THD *thd, Item **ref_pointer_array, { if (!item->const_item() && !item->with_sum_func && !item->marker) { + /* + Don't put duplicate columns from the SELECT list into the + GROUP BY list. + */ + ORDER *ord_iter; + for (ord_iter= group; ord_iter; ord_iter= ord_iter->next) + if ((*ord_iter->item)->eq(item, 1)) + break; + if (ord_iter) + continue; + ORDER *ord=(ORDER*) thd->calloc(sizeof(ORDER)); if (!ord) return 0; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 0eb1322396a..0125b36fcb6 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -25,6 +25,7 @@ #include "sp_head.h" #include "sql_trigger.h" #include "authors.h" +#include "contributors.h" #include "event.h" #include <my_dir.h> @@ -46,7 +47,7 @@ static void store_key_options(THD *thd, String *packet, TABLE *table, KEY *key_info); /*************************************************************************** -** List all table types supported +** List all table types supported ***************************************************************************/ static my_bool show_handlerton(THD *thd, st_plugin_int *plugin, @@ -54,25 +55,26 @@ static my_bool show_handlerton(THD *thd, st_plugin_int *plugin, { handlerton *default_type= (handlerton *) arg; Protocol *protocol= thd->protocol; - handlerton *hton= (handlerton *) plugin->plugin->info; + handlerton *hton= (handlerton *)plugin->data; if (!(hton->flags & HTON_HIDDEN)) { protocol->prepare_for_resend(); - protocol->store(hton->name, system_charset_info); + protocol->store(plugin->name.str, plugin->name.length, + 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(plugin->plugin->descr, 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; + return 0; } bool mysqld_show_storage_engines(THD *thd) @@ -92,7 +94,7 @@ bool mysqld_show_storage_engines(THD *thd) Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) DBUG_RETURN(TRUE); - if (plugin_foreach(thd, show_handlerton, + if (plugin_foreach(thd, show_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, thd->variables.table_type)) DBUG_RETURN(TRUE); @@ -229,6 +231,41 @@ bool mysqld_show_authors(THD *thd) DBUG_RETURN(FALSE); } + +/*************************************************************************** +** List all Contributors. +** Please get permission before updating +***************************************************************************/ + +bool mysqld_show_contributors(THD *thd) +{ + List<Item> field_list; + Protocol *protocol= thd->protocol; + DBUG_ENTER("mysqld_show_contributors"); + + field_list.push_back(new Item_empty_string("Name",40)); + field_list.push_back(new Item_empty_string("Location",40)); + field_list.push_back(new Item_empty_string("Comment",80)); + + if (protocol->send_fields(&field_list, + Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) + DBUG_RETURN(TRUE); + + show_table_contributors_st *contributors; + for (contributors= show_table_contributors; contributors->name; contributors++) + { + protocol->prepare_for_resend(); + protocol->store(contributors->name, system_charset_info); + protocol->store(contributors->location, system_charset_info); + protocol->store(contributors->comment, system_charset_info); + if (protocol->write()) + DBUG_RETURN(TRUE); + } + send_eof(thd); + DBUG_RETURN(FALSE); +} + + /*************************************************************************** List all privileges supported ***************************************************************************/ @@ -939,6 +976,9 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet, MODE_DB2 | MODE_MAXDB | MODE_ANSI)) != 0; + bool limited_mysql_mode= (thd->variables.sql_mode & (MODE_NO_FIELD_OPTIONS | + MODE_MYSQL323 | + MODE_MYSQL40)) != 0; my_bitmap_map *old_map; DBUG_ENTER("store_create_info"); DBUG_PRINT("enter",("table: %s", table->s->table_name.str)); @@ -1030,8 +1070,8 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet, has_default= (field->type() != FIELD_TYPE_BLOB && !(field->flags & NO_DEFAULT_VALUE_FLAG) && field->unireg_check != Field::NEXT_NUMBER && - !((thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40)) && - has_now_default)); + !((thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40)) + && has_now_default)); if (has_default) { @@ -1060,8 +1100,7 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet, packet->append(tmp); } - if (!(thd->variables.sql_mode & MODE_NO_FIELD_OPTIONS) && - table->timestamp_field == field && + if (!limited_mysql_mode && table->timestamp_field == field && field->unireg_check != Field::TIMESTAMP_DN_FIELD) packet->append(STRING_WITH_LEN(" ON UPDATE CURRENT_TIMESTAMP")); @@ -1108,12 +1147,6 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet, if (!found_primary) append_identifier(thd, packet, key_info->name, strlen(key_info->name)); -#if MYSQL_VERSION_ID < 50300 - /* Key options moved to after key parts in 5.3.0 */ - if (!thd->variables.new_mode) - store_key_options(thd, packet, table, key_info); -#endif - packet->append(STRING_WITH_LEN(" (")); for (uint j=0 ; j < key_info->key_parts ; j++,key_part++) @@ -1139,10 +1172,7 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet, } } packet->append(')'); -#if MYSQL_VERSION_ID < 50300 - if (thd->variables.new_mode) -#endif - store_key_options(thd, packet, table, key_info); + store_key_options(thd, packet, table, key_info); if (key_info->parser) { packet->append(" WITH PARSER ", 13); @@ -1199,6 +1229,25 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet, packet->append(file->table_type()); #endif } + + /* + Add AUTO_INCREMENT=... if there is an AUTO_INCREMENT column, + and NEXT_ID > 1 (the default). We must not print the clause + for engines that do not support this as it would break the + import of dumps, but as of this writing, the test for whether + AUTO_INCREMENT columns are allowed and wether AUTO_INCREMENT=... + is supported is identical, !(file->table_flags() & HA_NO_AUTO_INCREMENT)) + Because of that, we do not explicitly test for the feature, + but may extrapolate its existence from that of an AUTO_INCREMENT column. + */ + + if(create_info.auto_increment_value > 1) + { + packet->append(" AUTO_INCREMENT=", 16); + end= longlong10_to_str(create_info.auto_increment_value, buff,10); + packet->append(buff, (uint) (end - buff)); + } + if (share->table_charset && !(thd->variables.sql_mode & MODE_MYSQL323) && @@ -1283,9 +1332,10 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet, uint part_syntax_len; char *part_syntax; if (table->part_info && + (!table->part_info->is_auto_partitioned) && ((part_syntax= generate_partition_syntax(table->part_info, &part_syntax_len, - FALSE,FALSE)))) + FALSE)))) { packet->append(part_syntax, part_syntax_len); my_free(part_syntax, MYF(0)); @@ -2336,7 +2386,6 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) TABLE *table= tables->table; SELECT_LEX *select_lex= &lex->select_lex; SELECT_LEX *old_all_select_lex= lex->all_selects_list; - TABLE_LIST **save_query_tables_last= lex->query_tables_last; enum_sql_command save_sql_command= lex->sql_command; SELECT_LEX *lsel= tables->schema_select_lex; ST_SCHEMA_TABLE *schema_table= tables->schema_table; @@ -2355,6 +2404,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) enum legacy_db_type not_used; Open_tables_state open_tables_state_backup; bool save_view_prepare_mode= lex->view_prepare_mode; + Query_tables_list query_tables_list_backup; lex->view_prepare_mode= TRUE; DBUG_ENTER("get_all_tables"); @@ -2367,6 +2417,8 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) */ lex->sql_command= SQLCOM_SHOW_FIELDS; + lex->reset_n_backup_query_tables_list(&query_tables_list_backup); + /* We should not introduce deadlocks even if we already have some tables open and locked, since we won't lock tables which we will @@ -2407,8 +2459,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) show_table_list->db), show_table_list->alias)); thd->temporary_tables= 0; - close_thread_tables(thd); - show_table_list->table= 0; + close_tables_for_reopen(thd, &show_table_list); goto err; } @@ -2519,9 +2570,10 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) in this case. */ res= schema_table->process_table(thd, show_table_list, table, - res, base_name, - show_table_list->alias); - close_thread_tables(thd); + res, base_name, + show_table_list->alias); + close_tables_for_reopen(thd, &show_table_list); + DBUG_ASSERT(!lex->query_tables_own_last); if (res) goto err; } @@ -2538,11 +2590,10 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) error= 0; err: thd->restore_backup_open_tables_state(&open_tables_state_backup); + lex->restore_backup_query_tables_list(&query_tables_list_backup); lex->derived_tables= derived_tables; lex->all_selects_list= old_all_select_lex; - lex->query_tables_last= save_query_tables_last; lex->view_prepare_mode= save_view_prepare_mode; - *save_query_tables_last= 0; lex->sql_command= save_sql_command; DBUG_RETURN(error); } @@ -2935,7 +2986,7 @@ static int get_schema_column_record(THD *thd, struct st_table_list *tables, field->real_type() == MYSQL_TYPE_STRING) // For binary type { uint32 octet_max_length= field->max_length(); - if (octet_max_length != (uint32) 4294967295U) + if (is_blob && octet_max_length != (uint32) 4294967295U) octet_max_length /= field->charset()->mbmaxlen; longlong char_max_len= is_blob ? (longlong) octet_max_length / field->charset()->mbminlen : @@ -3058,7 +3109,7 @@ static my_bool iter_schema_engines(THD *thd, st_plugin_int *plugin, void *ptable) { TABLE *table= (TABLE *) ptable; - handlerton *hton= (handlerton *) plugin->plugin->info; + handlerton *hton= (handlerton *)plugin->data; const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS; CHARSET_INFO *scs= system_charset_info; DBUG_ENTER("iter_schema_engines"); @@ -3066,21 +3117,25 @@ static my_bool iter_schema_engines(THD *thd, st_plugin_int *plugin, if (!(hton->flags & HTON_HIDDEN)) { if (!(wild && wild[0] && - wild_case_compare(scs, hton->name,wild))) + wild_case_compare(scs, plugin->name.str,wild))) { - const char *tmp; + LEX_STRING state[2]={{STRING_WITH_LEN("ENABLED")}, + {STRING_WITH_LEN("DISABLED")}}; + LEX_STRING yesno[2]={{STRING_WITH_LEN("NO")}, {STRING_WITH_LEN("YES")}}; + LEX_STRING *tmp; restore_record(table, s->default_values); - table->field[0]->store(hton->name, strlen(hton->name), scs); - tmp= hton->state ? "DISABLED" : "ENABLED"; - table->field[1]->store( tmp, strlen(tmp), scs); - table->field[2]->store(hton->comment, strlen(hton->comment), scs); - tmp= hton->commit ? "YES" : "NO"; - table->field[3]->store( tmp, strlen(tmp), scs); - tmp= hton->prepare ? "YES" : "NO"; - table->field[4]->store( tmp, strlen(tmp), scs); - tmp= hton->savepoint_set ? "YES" : "NO"; - table->field[5]->store( tmp, strlen(tmp), scs); + table->field[0]->store(plugin->name.str, plugin->name.length, scs); + tmp= &state[test(hton->state)]; + table->field[1]->store(tmp->str, tmp->length, scs); + table->field[2]->store(plugin->plugin->descr, + strlen(plugin->plugin->descr), scs); + tmp= &yesno[test(hton->commit)]; + table->field[3]->store(tmp->str, tmp->length, scs); + tmp= &yesno[test(hton->prepare)]; + table->field[4]->store(tmp->str, tmp->length, scs); + tmp= &yesno[test(hton->savepoint_set)]; + table->field[5]->store(tmp->str, tmp->length, scs); if (schema_table_store_record(thd, table)) DBUG_RETURN(1); @@ -3092,7 +3147,7 @@ static my_bool iter_schema_engines(THD *thd, st_plugin_int *plugin, int fill_schema_engines(THD *thd, TABLE_LIST *tables, COND *cond) { - return plugin_foreach(thd, iter_schema_engines, + return plugin_foreach(thd, iter_schema_engines, MYSQL_STORAGE_ENGINE_PLUGIN, tables->table); } @@ -3107,7 +3162,7 @@ int fill_schema_collation(THD *thd, TABLE_LIST *tables, COND *cond) { CHARSET_INFO **cl; CHARSET_INFO *tmp_cs= cs[0]; - if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) || + if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) || (tmp_cs->state & MY_CS_HIDDEN) || !(tmp_cs->state & MY_CS_PRIMARY)) continue; @@ -3172,17 +3227,18 @@ bool store_schema_proc(THD *thd, TABLE *table, TABLE *proc_table, const char *wild, bool full_access, const char *sp_user) { String tmp_string; + String sp_db, sp_name, definer; TIME time; LEX *lex= thd->lex; CHARSET_INFO *cs= system_charset_info; - const char *sp_db, *sp_name, *definer; - sp_db= get_field(thd->mem_root, proc_table->field[0]); - sp_name= get_field(thd->mem_root, proc_table->field[1]); - definer= get_field(thd->mem_root, proc_table->field[11]); + get_field(thd->mem_root, proc_table->field[0], &sp_db); + get_field(thd->mem_root, proc_table->field[1], &sp_name); + get_field(thd->mem_root, proc_table->field[11], &definer); if (!full_access) - full_access= !strcmp(sp_user, definer); - if (!full_access && check_some_routine_access(thd, sp_db, sp_name, - proc_table->field[2]->val_int() == TYPE_ENUM_PROCEDURE)) + full_access= !strcmp(sp_user, definer.ptr()); + if (!full_access && check_some_routine_access(thd, sp_db.ptr(), sp_name.ptr(), + proc_table->field[2]->val_int() == + TYPE_ENUM_PROCEDURE)) return 0; if (lex->orig_sql_command == SQLCOM_SHOW_STATUS_PROC && @@ -3192,13 +3248,13 @@ bool store_schema_proc(THD *thd, TABLE *table, TABLE *proc_table, lex->orig_sql_command == SQLCOM_END) { restore_record(table, s->default_values); - if (!wild || !wild[0] || !wild_compare(sp_name, wild, 0)) + if (!wild || !wild[0] || !wild_compare(sp_name.ptr(), wild, 0)) { int enum_idx= proc_table->field[5]->val_int(); - table->field[3]->store(sp_name, strlen(sp_name), cs); + table->field[3]->store(sp_name.ptr(), sp_name.length(), cs); get_field(thd->mem_root, proc_table->field[3], &tmp_string); table->field[0]->store(tmp_string.ptr(), tmp_string.length(), cs); - table->field[2]->store(sp_db, strlen(sp_db), cs); + table->field[2]->store(sp_db.ptr(), sp_db.length(), cs); get_field(thd->mem_root, proc_table->field[2], &tmp_string); table->field[4]->store(tmp_string.ptr(), tmp_string.length(), cs); if (proc_table->field[2]->val_int() == TYPE_ENUM_FUNCTION) @@ -3230,7 +3286,7 @@ bool store_schema_proc(THD *thd, TABLE *table, TABLE *proc_table, table->field[17]->store(tmp_string.ptr(), tmp_string.length(), cs); get_field(thd->mem_root, proc_table->field[15], &tmp_string); table->field[18]->store(tmp_string.ptr(), tmp_string.length(), cs); - table->field[19]->store(definer, strlen(definer), cs); + table->field[19]->store(definer.ptr(), definer.length(), cs); return schema_table_store_record(thd, table); } } @@ -3393,11 +3449,33 @@ static int get_schema_views_record(THD *thd, struct st_table_list *tables, if (tables->view) { + Security_context *sctx= thd->security_ctx; + ulong grant= SHOW_VIEW_ACL; +#ifndef NO_EMBEDDED_ACCESS_CHECKS + char *save_table_name= tables->table_name; + if (!my_strcasecmp(system_charset_info, tables->definer.user.str, + sctx->priv_user) && + !my_strcasecmp(system_charset_info, tables->definer.host.str, + sctx->priv_host)) + grant= SHOW_VIEW_ACL; + else + { + tables->table_name= tables->view_name.str; + if (check_access(thd, SHOW_VIEW_ACL , base_name, + &tables->grant.privilege, 0, 1, + test(tables->schema_table))) + grant= get_table_grant(thd, tables); + else + grant= tables->grant.privilege; + } + tables->table_name= save_table_name; +#endif + restore_record(table, s->default_values); table->field[1]->store(tables->view_db.str, tables->view_db.length, cs); - table->field[2]->store(tables->view_name.str, tables->view_name.length, - cs); - table->field[3]->store(tables->query.str, tables->query.length, cs); + table->field[2]->store(tables->view_name.str, tables->view_name.length, cs); + if (grant & SHOW_VIEW_ACL) + table->field[3]->store(tables->query.str, tables->query.length, cs); if (tables->with_check != VIEW_CHECK_NONE) { @@ -3855,24 +3933,28 @@ static int get_schema_partitions_record(THD *thd, struct st_table_list *tables, { table->field[9]->store(part_info->part_func_string, part_info->part_func_len, cs); - table->field[9]->set_notnull(); } else if (part_info->list_of_part_fields) { collect_partition_expr(part_info->part_field_list, &tmp_str); table->field[9]->store(tmp_str.ptr(), tmp_str.length(), cs); - table->field[9]->set_notnull(); } + table->field[9]->set_notnull(); if (part_info->is_sub_partitioned()) { /* Subpartition method */ + tmp_res.length(0); + if (part_info->linear_hash_ind) + tmp_res.append(partition_keywords[PKW_LINEAR].str, + partition_keywords[PKW_LINEAR].length); if (part_info->list_of_subpart_fields) - table->field[8]->store(partition_keywords[PKW_KEY].str, - partition_keywords[PKW_KEY].length, cs); + tmp_res.append(partition_keywords[PKW_KEY].str, + partition_keywords[PKW_KEY].length); else - table->field[8]->store(partition_keywords[PKW_HASH].str, - partition_keywords[PKW_HASH].length, cs); + tmp_res.append(partition_keywords[PKW_HASH].str, + partition_keywords[PKW_HASH].length); + table->field[8]->store(tmp_res.ptr(), tmp_res.length(), cs); table->field[8]->set_notnull(); /* Subpartition expression */ @@ -3880,14 +3962,13 @@ static int get_schema_partitions_record(THD *thd, struct st_table_list *tables, { table->field[10]->store(part_info->subpart_func_string, part_info->subpart_func_len, cs); - table->field[10]->set_notnull(); } else if (part_info->list_of_subpart_fields) { collect_partition_expr(part_info->subpart_field_list, &tmp_str); table->field[10]->store(tmp_str.ptr(), tmp_str.length(), cs); - table->field[10]->set_notnull(); } + table->field[10]->set_notnull(); } while ((part_elem= part_it++)) @@ -4022,8 +4103,24 @@ static interval_type get_real_interval_type(interval_type i_type) extern LEX_STRING interval_type_to_name[]; + +/* + Loads an event from mysql.event and copies it's data to a row of + I_S.EVENTS + + Synopsis + copy_event_to_schema_table() + thd Thread + sch_table The schema table (information_schema.event) + event_table The event table to use for loading (mysql.event). + + Returns + 0 OK + 1 Error +*/ + static int -fill_events_copy_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table) +copy_event_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table) { const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS; CHARSET_INFO *scs= system_charset_info; @@ -4041,9 +4138,19 @@ fill_events_copy_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table) if (!(!wild || !wild[0] || !wild_compare(et.name.str, wild, 0))) DBUG_RETURN(0); - + + /* + Skip events in schemas one does not have access to. The check is + optimized. It's guaranteed in case of SHOW EVENTS that the user + has access. + */ + if (thd->lex->orig_sql_command != SQLCOM_SHOW_EVENTS && + check_access(thd, EVENT_ACL, et.dbname.str, 0, 0, 1, + is_schema_db(et.dbname.str))) + DBUG_RETURN(0); + /* ->field[0] is EVENT_CATALOG and is by default NULL */ - + sch_table->field[1]->store(et.dbname.str, et.dbname.length, scs); sch_table->field[2]->store(et.name.str, et.name.length, scs); sch_table->field[3]->store(et.definer.str, et.definer.length, scs); @@ -4055,18 +4162,18 @@ fill_events_copy_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table) ulong sql_mode_len=0; sql_mode_str= sys_var_thd_sql_mode::symbolic_mode_representation(thd, et.sql_mode, - &sql_mode_len); + &sql_mode_len); sch_table->field[9]->store((const char*)sql_mode_str, sql_mode_len, scs); } - + if (et.expression) { String show_str; /* type */ sch_table->field[5]->store(STRING_WITH_LEN("RECURRING"), scs); - if (event_reconstruct_interval_expression(&show_str, et.interval, - et.expression)) + if (Events::reconstruct_interval_expression(&show_str, et.interval, + et.expression)) DBUG_RETURN(1); sch_table->field[7]->set_notnull(); @@ -4076,7 +4183,7 @@ fill_events_copy_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table) sch_table->field[8]->set_notnull(); sch_table->field[8]->store(ival->str, ival->length, scs); - //starts & ends + /* starts & ends */ sch_table->field[10]->set_notnull(); sch_table->field[10]->store_time(&et.starts, MYSQL_TIMESTAMP_DATETIME); @@ -4095,14 +4202,14 @@ fill_events_copy_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table) sch_table->field[6]->store_time(&et.execute_at, MYSQL_TIMESTAMP_DATETIME); } - //status - if (et.status == MYSQL_EVENT_ENABLED) + /* status */ + if (et.status == Event_timed::ENABLED) sch_table->field[12]->store(STRING_WITH_LEN("ENABLED"), scs); else sch_table->field[12]->store(STRING_WITH_LEN("DISABLED"), scs); - //on_completion - if (et.on_completion == MYSQL_EVENT_ON_COMPLETION_DROP) + /* on_completion */ + if (et.on_completion == Event_timed::ON_COMPLETION_DROP) sch_table->field[13]->store(STRING_WITH_LEN("NOT PRESERVE"), scs); else sch_table->field[13]->store(STRING_WITH_LEN("PRESERVE"), scs); @@ -4131,100 +4238,179 @@ fill_events_copy_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table) } -int fill_schema_events(THD *thd, TABLE_LIST *tables, COND *cond) +/* + Performs an index scan of event_table (mysql.event) and fills schema_table. + + Synopsis + events_table_index_read_for_db() + thd Thread + schema_table The I_S.EVENTS table + event_table The event table to use for loading (mysql.event) + + Returns + 0 OK + 1 Error +*/ + +static +int events_table_index_read_for_db(THD *thd, TABLE *schema_table, + TABLE *event_table) { - TABLE *table= tables->table; - CHARSET_INFO *scs= system_charset_info; - TABLE *event_table= NULL; - Open_tables_state backup; int ret=0; - bool verbose= false; - char definer[HOSTNAME_LENGTH+USERNAME_LENGTH+2]; - bool use_prefix_scanning= true; - uint key_len= 0; + CHARSET_INFO *scs= system_charset_info; + KEY *key_info; + uint key_len; byte *key_buf= NULL; LINT_INIT(key_buf); - DBUG_ENTER("fill_schema_events"); - - strxmov(definer, thd->security_ctx->priv_user,"@",thd->security_ctx->priv_host, - NullS); + DBUG_ENTER("schema_events_do_index_scan"); - DBUG_PRINT("info",("db=%s current_user=%s", thd->lex->select_lex.db, definer)); - - thd->reset_n_backup_open_tables_state(&backup); + DBUG_PRINT("info", ("Using prefix scanning on PK")); + event_table->file->ha_index_init(0, 1); + event_table->field[Events::FIELD_DB]-> + store(thd->lex->select_lex.db, strlen(thd->lex->select_lex.db), scs); + key_info= event_table->key_info; + key_len= key_info->key_part[0].store_length; - if ((ret= evex_open_event_table(thd, TL_READ, &event_table))) + if (!(key_buf= (byte *)alloc_root(thd->mem_root, key_len))) { - sql_print_error("Table mysql.event is damaged."); ret= 1; - goto err; - } - - event_table->file->ha_index_init(0, 1); - - /* - see others' events only if you have PROCESS_ACL !! - thd->lex->verbose is set either if SHOW FULL EVENTS or - in case of SELECT FROM I_S.EVENTS - */ - verbose= (thd->lex->verbose - && (thd->security_ctx->master_access & PROCESS_ACL)); - - if (verbose && thd->security_ctx->user) - { - ret= event_table->file->index_first(event_table->record[0]); - use_prefix_scanning= false; + /* don't send error, it would be done by sql_alloc_error_handler() */ } else { - event_table->field[EVEX_FIELD_DEFINER]->store(definer, strlen(definer), scs); - key_len= event_table->key_info->key_part[0].store_length; - - if (thd->lex->select_lex.db) - { - event_table->field[EVEX_FIELD_DB]-> - store(thd->lex->select_lex.db, strlen(thd->lex->select_lex.db), scs); - key_len+= event_table->key_info->key_part[1].store_length; - } - if (!(key_buf= (byte *)alloc_root(thd->mem_root, key_len))) + key_copy(key_buf, event_table->record[0], key_info, key_len); + if (!(ret= event_table->file->index_read(event_table->record[0], key_buf, + key_len, HA_READ_PREFIX))) { - ret= 1; - goto err; + DBUG_PRINT("info",("Found rows. Let's retrieve them. ret=%d", ret)); + do + { + ret= copy_event_to_schema_table(thd, schema_table, event_table); + if (ret == 0) + ret= event_table->file->index_next_same(event_table->record[0], + key_buf, key_len); + } while (ret == 0); } - - key_copy(key_buf, event_table->record[0], event_table->key_info, key_len); - ret= event_table->file->index_read(event_table->record[0], key_buf, key_len, - HA_READ_PREFIX); + DBUG_PRINT("info", ("Scan finished. ret=%d", ret)); } + event_table->file->ha_index_end(); + /* ret is guaranteed to be != 0 */ + if (ret == HA_ERR_END_OF_FILE || ret == HA_ERR_KEY_NOT_FOUND) + DBUG_RETURN(0); + DBUG_RETURN(1); +} + + +/* + Performs a table scan of event_table (mysql.event) and fills schema_table. + + Synopsis + events_table_scan_all() + thd Thread + schema_table The I_S.EVENTS in memory table + event_table The event table to use for loading. - if (ret) + Returns + 0 OK + 1 Error +*/ + +static +int events_table_scan_all(THD *thd, TABLE *schema_table, + TABLE *event_table) +{ + int ret; + READ_RECORD read_record_info; + + DBUG_ENTER("schema_events_do_table_scan"); + init_read_record(&read_record_info, thd, event_table, NULL, 1, 0); + + /* + rr_sequential, in read_record(), returns 137==HA_ERR_END_OF_FILE, + but rr_handle_error returns -1 for that reason. Thus, read_record() + returns -1 eventually. + */ + do { - ret= (ret == HA_ERR_END_OF_FILE || ret == HA_ERR_KEY_NOT_FOUND) ? 0 : 1; - goto err; + ret= read_record_info.read_record(&read_record_info); + if (ret == 0) + ret= copy_event_to_schema_table(thd, schema_table, event_table); } + while (ret == 0); - while (!ret) - { - if ((ret= fill_events_copy_to_schema_table(thd, table, event_table))) - goto err; + DBUG_PRINT("info", ("Scan finished. ret=%d", ret)); + end_read_record(&read_record_info); - if (use_prefix_scanning) - ret= event_table->file-> - index_next_same(event_table->record[0], key_buf, key_len); - else - ret= event_table->file->index_next(event_table->record[0]); + /* ret is guaranteed to be != 0 */ + DBUG_RETURN(ret == -1? 0:1); +} + + +/* + Fills I_S.EVENTS with data loaded from mysql.event. Also used by + SHOW EVENTS + + Synopsis + fill_schema_events() + thd Thread + tables The schema table + cond Unused + + Returns + 0 OK + 1 Error +*/ + +int fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */) +{ + TABLE *schema_table= tables->table; + TABLE *event_table= NULL; + Open_tables_state backup; + int ret= 0; + + DBUG_ENTER("fill_schema_events"); + /* + If it's SHOW EVENTS then thd->lex->select_lex.db is guaranteed not to + be NULL. Let's do an assert anyway. + */ + if (thd->lex->orig_sql_command == SQLCOM_SHOW_EVENTS) + { + DBUG_ASSERT(thd->lex->select_lex.db); + if (check_access(thd, EVENT_ACL, thd->lex->select_lex.db, 0, 0, 0, + is_schema_db(thd->lex->select_lex.db))) + DBUG_RETURN(1); } - // ret is guaranteed to be != 0 - ret= (ret != HA_ERR_END_OF_FILE); -err: - if (event_table) + + DBUG_PRINT("info",("db=%s", thd->lex->select_lex.db? + thd->lex->select_lex.db:"(null)")); + + thd->reset_n_backup_open_tables_state(&backup); + if (Events::open_event_table(thd, TL_READ, &event_table)) { - event_table->file->ha_index_end(); - close_thread_tables(thd); + sql_print_error("Table mysql.event is damaged."); + thd->restore_backup_open_tables_state(&backup); + DBUG_RETURN(1); } + /* + 1. SELECT I_S => use table scan. I_S.EVENTS does not guarantee order + thus we won't order it. OTOH, SHOW EVENTS will be + ordered. + 2. SHOW EVENTS => PRIMARY KEY with prefix scanning on (db) + Reasoning: Events are per schema, therefore a scan over an index + will save use from doing a table scan and comparing + every single row's `db` with the schema which we show. + */ + if (thd->lex->orig_sql_command == SQLCOM_SHOW_EVENTS) + ret= events_table_index_read_for_db(thd, schema_table, event_table); + else + ret= events_table_scan_all(thd, schema_table, event_table); + + close_thread_tables(thd); thd->restore_backup_open_tables_state(&backup); + + DBUG_PRINT("info", ("Return code=%d", ret)); DBUG_RETURN(ret); } @@ -4842,7 +5028,7 @@ static my_bool run_hton_fill_schema_files(THD *thd, st_plugin_int *plugin, { struct run_hton_fill_schema_files_args *args= (run_hton_fill_schema_files_args *) arg; - handlerton *hton= (handlerton *) plugin->plugin->info; + handlerton *hton= (handlerton *)plugin->data; if(hton->fill_files_table) hton->fill_files_table(thd, args->tables, args->cond); return false; @@ -5186,7 +5372,7 @@ ST_FIELD_INFO partitions_fields_info[]= {"PARTITION_ORDINAL_POSITION", 21 , MYSQL_TYPE_LONG, 0, 1, 0}, {"SUBPARTITION_ORDINAL_POSITION", 21 , MYSQL_TYPE_LONG, 0, 1, 0}, {"PARTITION_METHOD", 12, MYSQL_TYPE_STRING, 0, 1, 0}, - {"SUBPARTITION_METHOD", 5, MYSQL_TYPE_STRING, 0, 1, 0}, + {"SUBPARTITION_METHOD", 12, MYSQL_TYPE_STRING, 0, 1, 0}, {"PARTITION_EXPRESSION", 65535, MYSQL_TYPE_STRING, 0, 1, 0}, {"SUBPARTITION_EXPRESSION", 65535, MYSQL_TYPE_STRING, 0, 1, 0}, {"PARTITION_DESCRIPTION", 65535, MYSQL_TYPE_STRING, 0, 1, 0}, diff --git a/sql/sql_string.h b/sql/sql_string.h index 0659f684afe..ddae6368228 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -24,8 +24,6 @@ #define NOT_FIXED_DEC 31 #endif -#define STRING_WITH_LEN(X) ((const char*) X), ((uint) (sizeof(X) - 1)) - class String; int sortcmp(const String *a,const String *b, CHARSET_INFO *cs); String *copy_if_not_alloced(String *a,String *b,uint32 arg_length); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 646acfd2908..d3b1cb852c2 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1233,7 +1233,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) { if (!(part_syntax_buf= generate_partition_syntax(part_info, &syntax_len, - TRUE, FALSE))) + TRUE))) { DBUG_RETURN(TRUE); } @@ -3082,6 +3082,7 @@ bool mysql_create_table_internal(THD *thd, } file->set_auto_partitions(part_info); part_info->default_engine_type= create_info->db_type; + part_info->is_auto_partitioned= TRUE; } if (part_info) { @@ -3109,7 +3110,8 @@ bool mysql_create_table_internal(THD *thd, } while ((key= key_iterator++)) { - if (key->type == Key::FOREIGN_KEY) + if (key->type == Key::FOREIGN_KEY && + !part_info->is_auto_partitioned) { my_error(ER_CANNOT_ADD_FOREIGN, MYF(0)); goto err; @@ -3142,8 +3144,8 @@ bool mysql_create_table_internal(THD *thd, } DBUG_PRINT("info", ("db_type = %d", ha_legacy_type(part_info->default_engine_type))); - if (part_info->check_partition_info( &engine_type, file, - create_info->max_rows)) + if (part_info->check_partition_info(&engine_type, file, + create_info->max_rows)) goto err; part_info->default_engine_type= engine_type; @@ -3153,7 +3155,7 @@ bool mysql_create_table_internal(THD *thd, */ if (!(part_syntax_buf= generate_partition_syntax(part_info, &syntax_len, - TRUE, FALSE))) + TRUE))) goto err; part_info->part_info_string= part_syntax_buf; part_info->part_info_len= syntax_len; @@ -3202,6 +3204,12 @@ bool mysql_create_table_internal(THD *thd, } else if (create_info->db_type != engine_type) { + /* + We come here when we don't use a partitioned handler. + Since we use a partitioned table it must be "native partitioned". + We have switched engine from defaults, most likely only specified + engines in partition clauses. + */ delete file; if (!(file= get_new_handler((TABLE_SHARE*) 0, thd->mem_root, engine_type))) @@ -3424,111 +3432,6 @@ make_unique_key_name(const char *field_name,KEY *start,KEY *end) /**************************************************************************** -** Create table from a list of fields and items -****************************************************************************/ - -TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, - TABLE_LIST *create_table, - List<create_field> *extra_fields, - List<Key> *keys, - List<Item> *items, - MYSQL_LOCK **lock, - TABLEOP_HOOKS *hooks) -{ - TABLE tmp_table; // Used during 'create_field()' - TABLE_SHARE share; - TABLE *table= 0; - uint select_field_count= items->elements; - /* Add selected items to field list */ - List_iterator_fast<Item> it(*items); - Item *item; - Field *tmp_field; - bool not_used; - DBUG_ENTER("create_table_from_items"); - - tmp_table.alias= 0; - tmp_table.timestamp_field= 0; - tmp_table.s= &share; - init_tmp_table_share(&share, "", 0, "", ""); - - 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 == &myisam_hton || - create_info->db_type == &heap_hton); - tmp_table.null_row=tmp_table.maybe_null=0; - - while ((item=it++)) - { - create_field *cr_field; - Field *field; - if (item->type() == Item::FUNC_ITEM) - field=item->tmp_table_field(&tmp_table); - else - field=create_tmp_field(thd, &tmp_table, item, item->type(), - (Item ***) 0, &tmp_field, 0, 0, 0, 0, 0); - if (!field || - !(cr_field=new create_field(field,(item->type() == Item::FIELD_ITEM ? - ((Item_field *)item)->field : - (Field*) 0)))) - DBUG_RETURN(0); - if (item->maybe_null) - cr_field->flags &= ~NOT_NULL_FLAG; - extra_fields->push_back(cr_field); - } - /* - create and lock table - - We don't log the statement, it will be logged later. - - If this is a HEAP table, the automatic DELETE FROM which is written to the - binlog when a HEAP table is opened for the first time since startup, must - not be written: 1) it would be wrong (imagine we're in CREATE SELECT: we - don't want to delete from it) 2) it would be written before the CREATE - TABLE, which is a wrong order. So we keep binary logging disabled when we - open_table(). - TODO: create and open should be done atomic ! - */ - { - tmp_disable_binlog(thd); - if (!mysql_create_table(thd, create_table->db, create_table->table_name, - create_info, *extra_fields, *keys, 0, - select_field_count)) - { - if (! (table= open_table(thd, create_table, thd->mem_root, (bool*) 0, - MYSQL_LOCK_IGNORE_FLUSH))) - quick_rm_table(create_info->db_type, create_table->db, - table_case_name(create_info, create_table->table_name)); - } - reenable_binlog(thd); - if (!table) // open failed - DBUG_RETURN(0); - } - - /* - FIXME: What happens if trigger manages to be created while we are - obtaining this lock ? May be it is sensible just to disable - trigger execution in this case ? Or will MYSQL_LOCK_IGNORE_FLUSH - save us from that ? - */ - table->reginfo.lock_type=TL_WRITE; - hooks->prelock(&table, 1); // Call prelock hooks - if (! ((*lock)= mysql_lock_tables(thd, &table, 1, - MYSQL_LOCK_IGNORE_FLUSH, ¬_used))) - { - VOID(pthread_mutex_lock(&LOCK_open)); - hash_delete(&open_cache,(byte*) table); - VOID(pthread_mutex_unlock(&LOCK_open)); - quick_rm_table(create_info->db_type, create_table->db, - table_case_name(create_info, create_table->table_name)); - DBUG_RETURN(0); - } - table->file->extra(HA_EXTRA_WRITE_CACHE); - DBUG_RETURN(table); -} - - -/**************************************************************************** ** Alter a table definition ****************************************************************************/ @@ -3999,6 +3902,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, */ ha_autocommit_or_rollback(thd, 1); close_thread_tables(thd); + lex->reset_query_tables_list(FALSE); if (protocol->write()) goto err; continue; @@ -4024,6 +3928,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, protocol->store(buff, length, system_charset_info); ha_autocommit_or_rollback(thd, 0); close_thread_tables(thd); + lex->reset_query_tables_list(FALSE); table->table=0; // For query cache if (protocol->write()) goto err; @@ -4776,7 +4681,8 @@ static uint compare_tables(TABLE *table, List<create_field> *create_list, HA_CREATE_INFO *create_info, ALTER_INFO *alter_info, uint order_num, uint *index_drop_buffer, uint *index_drop_count, - uint *index_add_buffer, uint *index_add_count) + uint *index_add_buffer, uint *index_add_count, + bool varchar) { Field **f_ptr, *field; uint changes= 0, tmp; @@ -4811,7 +4717,8 @@ static uint compare_tables(TABLE *table, List<create_field> *create_list, create_info->used_fields & HA_CREATE_USED_CHARSET || create_info->used_fields & HA_CREATE_USED_DEFAULT_CHARSET || (alter_info->flags & (ALTER_RECREATE | ALTER_FOREIGN_KEY)) || - order_num) + order_num || + (table->s->frm_version < FRM_VER_TRUE_VARCHAR && varchar)) DBUG_RETURN(ALTER_TABLE_DATA_CHANGED); /* @@ -4985,7 +4892,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, uint db_create_options, used_fields; handlerton *old_db_type, *new_db_type; uint need_copy_table= 0; - bool no_table_reopen= FALSE; + bool no_table_reopen= FALSE, varchar= FALSE; #ifdef WITH_PARTITION_STORAGE_ENGINE uint fast_alter_partition= 0; bool partition_changed= FALSE; @@ -5084,7 +4991,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 == (handlerton*) &default_hton) + if (!create_info->db_type) create_info->db_type= old_db_type; #ifdef WITH_PARTITION_STORAGE_ENGINE @@ -5104,7 +5011,9 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, ha_resolve_storage_engine_name(old_db_type), ha_resolve_storage_engine_name(new_db_type))); if (ha_check_storage_engine_flag(old_db_type, HTON_ALTER_NOT_SUPPORTED) || - ha_check_storage_engine_flag(new_db_type, HTON_ALTER_NOT_SUPPORTED)) + ha_check_storage_engine_flag(new_db_type, HTON_ALTER_NOT_SUPPORTED) || + (old_db_type != new_db_type && + ha_check_storage_engine_flag(new_db_type, HTON_ALTER_CANNOT_CREATE))) { DBUG_PRINT("info", ("doesn't support alter")); my_error(ER_ILLEGAL_HA, MYF(0), table_name); @@ -5219,6 +5128,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, Field **f_ptr,*field; for (f_ptr=table->field ; (field= *f_ptr) ; f_ptr++) { + if (field->type() == MYSQL_TYPE_STRING) + varchar= TRUE; /* Check if field should be dropped */ Alter_drop *drop; drop_it.rewind(); @@ -5558,7 +5469,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, key_info_buffer, key_count, create_info, alter_info, order_num, index_drop_buffer, &index_drop_count, - index_add_buffer, &index_add_count); + index_add_buffer, &index_add_count, + varchar); } /* @@ -6240,7 +6152,7 @@ copy_data_between_tables(TABLE *from,TABLE *to, MODE_STRICT_ALL_TABLES)); from->file->info(HA_STATUS_VARIABLE); - to->file->start_bulk_insert(from->file->stats.records); + to->file->ha_start_bulk_insert(from->file->stats.records); save_sql_mode= thd->variables.sql_mode; @@ -6328,6 +6240,20 @@ copy_data_between_tables(TABLE *from,TABLE *to, (error != HA_ERR_FOUND_DUPP_KEY && error != HA_ERR_FOUND_DUPP_UNIQUE)) { + if (error == HA_ERR_FOUND_DUPP_KEY) + { + uint key_nr= to->file->get_dup_key(error); + if ((int) key_nr >= 0) + { + const char *err_msg= ER(ER_DUP_ENTRY); + if (key_nr == 0 && + (to->key_info[0].key_part[0].field->flags & AUTO_INCREMENT_FLAG)) + err_msg= ER(ER_DUP_ENTRY_AUTOINCREMENT_CASE); + to->file->print_keydupp_error(key_nr, err_msg); + break; + } + } + to->file->print_error(error,MYF(0)); break; } @@ -6341,7 +6267,7 @@ copy_data_between_tables(TABLE *from,TABLE *to, free_io_cache(from); delete [] copy; // This is never 0 - if (to->file->end_bulk_insert() && error <= 0) + if (to->file->ha_end_bulk_insert() && error <= 0) { to->file->print_error(my_errno,MYF(0)); error=1; @@ -6394,7 +6320,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= (handlerton*) &default_hton; + create_info.db_type= 0; create_info.row_type=ROW_TYPE_NOT_USED; create_info.default_table_charset=default_charset_info; /* Force alter table to recreate table */ @@ -6534,7 +6460,7 @@ static bool check_engine(THD *thd, const char *table_name, no_substitution, 1))) return TRUE; - if (req_engine != (handlerton*) &default_hton && req_engine != *new_engine) + if (req_engine && req_engine != *new_engine) { push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_USING_OTHER_HANDLER, @@ -6547,7 +6473,8 @@ static bool check_engine(THD *thd, const char *table_name, { if (create_info->used_fields & HA_CREATE_USED_ENGINE) { - my_error(ER_ILLEGAL_HA_CREATE_OPTION, MYF(0), (*new_engine)->name, "TEMPORARY"); + my_error(ER_ILLEGAL_HA_CREATE_OPTION, MYF(0), + hton2plugin[(*new_engine)->slot]->name.str, "TEMPORARY"); *new_engine= 0; return TRUE; } diff --git a/sql/sql_tablespace.cc b/sql/sql_tablespace.cc index 8bc39ec82c6..94318a67575 100644 --- a/sql/sql_tablespace.cc +++ b/sql/sql_tablespace.cc @@ -28,16 +28,16 @@ int mysql_alter_tablespace(THD *thd, st_alter_tablespace *ts_info) If the user haven't defined an engine, this will fallback to using the default storage engine. */ - if (hton == NULL || hton == &default_hton || hton->state != SHOW_OPTION_YES) + if (hton == NULL || hton->state != SHOW_OPTION_YES) { hton= ha_resolve_by_legacy_type(thd, DB_TYPE_DEFAULT); if (ts_info->storage_engine != 0) push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, ER_WARN_USING_OTHER_HANDLER, ER(ER_WARN_USING_OTHER_HANDLER), - hton->name, - ts_info->tablespace_name - ? ts_info->tablespace_name : ts_info->logfile_group_name); + hton2plugin[hton->slot]->name.str, + ts_info->tablespace_name ? ts_info->tablespace_name + : ts_info->logfile_group_name); } if (hton->alter_tablespace) @@ -64,7 +64,7 @@ int mysql_alter_tablespace(THD *thd, st_alter_tablespace *ts_info) push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, ER_ILLEGAL_HA_CREATE_OPTION, ER(ER_ILLEGAL_HA_CREATE_OPTION), - hton->name, + hton2plugin[hton->slot]->name.str, "TABLESPACE or LOGFILE GROUP"); } if (mysql_bin_log.is_open()) diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index b2b6b115f7d..0ea87f3dfe4 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -1412,8 +1412,8 @@ bool Table_triggers_list::change_table_name(THD *thd, const char *db, } if (table.triggers) { - LEX_STRING_WITH_INIT old_table_name(old_table, strlen(old_table)); - LEX_STRING_WITH_INIT new_table_name(new_table, strlen(new_table)); + LEX_STRING old_table_name= { (char *) old_table, strlen(old_table) }; + LEX_STRING new_table_name= { (char *) new_table, strlen(new_table) }; /* Since triggers should be in the same schema as their subject tables moving table with them between two schemas raises too many questions. diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 8846e70bdbc..e917c1358ef 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -737,8 +737,11 @@ bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list, tables.alias= table_list->alias; thd->lex->allow_sum_func= 0; - if (setup_tables(thd, &select_lex->context, &select_lex->top_join_list, - table_list, &select_lex->leaf_tables, FALSE) || + if (setup_tables_and_check_access(thd, &select_lex->context, + &select_lex->top_join_list, + table_list, + &select_lex->leaf_tables, + FALSE, UPDATE_ACL) || setup_conds(thd, table_list, select_lex->leaf_tables, conds) || select_lex->setup_ref_array(thd, order_num) || setup_order(thd, select_lex->ref_pointer_array, @@ -829,9 +832,11 @@ reopen_tables: call in setup_tables()). */ - if (setup_tables(thd, &lex->select_lex.context, - &lex->select_lex.top_join_list, - table_list, &lex->select_lex.leaf_tables, FALSE)) + if (setup_tables_and_check_access(thd, &lex->select_lex.context, + &lex->select_lex.top_join_list, + table_list, + &lex->select_lex.leaf_tables, FALSE, + UPDATE_ACL)) DBUG_RETURN(TRUE); if (setup_fields_with_no_wrap(thd, 0, *fields, MARK_COLUMNS_WRITE, 0, 0)) diff --git a/sql/sql_view.cc b/sql/sql_view.cc index c0096bc292d..d1e7ba80ecf 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -1191,9 +1191,11 @@ ok: ok2: if (!old_lex->time_zone_tables_used && thd->lex->time_zone_tables_used) old_lex->time_zone_tables_used= thd->lex->time_zone_tables_used; + DBUG_ASSERT(lex == thd->lex); + thd->lex= old_lex; // Needed for prepare_security result= !table->prelocking_placeholder && table->prepare_security(thd); - lex_end(thd->lex); + lex_end(lex); end: if (arena) thd->restore_active_arena(arena, &backup); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 32b5bc8adb9..af2bf8231aa 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -204,6 +204,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token CONSTRAINT %token CONTAINS_SYM %token CONTINUE_SYM +%token CONTRIBUTORS_SYM %token CONVERT_SYM %token CONVERT_TZ_SYM %token COUNT_SYM @@ -475,6 +476,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token NUMERIC_SYM %token NVARCHAR_SYM %token OFFSET_SYM +%token OJ_SYM %token OLD_PASSWORD %token ON %token ONE_SHOT_SYM @@ -567,6 +569,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token RTREE_SYM %token SAVEPOINT_SYM %token SCHEDULE_SYM +%token SCHEDULER_SYM %token SECOND_MICROSECOND_SYM %token SECOND_SYM %token SECURITY_SYM @@ -796,7 +799,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); key_type opt_unique_or_fulltext constraint_key_type %type <key_alg> - opt_btree_or_rtree + btree_or_rtree %type <string_list> key_usage_list using_list @@ -887,7 +890,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); view_suid view_tail view_list_opt view_list view_select view_check_option trigger_tail sp_tail install uninstall partition_entry binlog_base64_event - init_key_options key_options key_opts key_opt + init_key_options key_options key_opts key_opt key_using_alg END_OF_INPUT %type <NONE> call sp_proc_stmts sp_proc_stmts1 sp_proc_stmt @@ -1400,7 +1403,7 @@ opt_ev_status: /* empty */ { $$= 0; } { LEX *lex=Lex; if (!lex->et_compile_phase) - lex->et->status= MYSQL_EVENT_ENABLED; + lex->et->status= Event_timed::ENABLED; $$= 1; } | DISABLE_SYM @@ -1408,7 +1411,7 @@ opt_ev_status: /* empty */ { $$= 0; } LEX *lex=Lex; if (!lex->et_compile_phase) - lex->et->status= MYSQL_EVENT_DISABLED; + lex->et->status= Event_timed::DISABLED; $$= 1; } ; @@ -1472,14 +1475,14 @@ ev_on_completion: { LEX *lex=Lex; if (!lex->et_compile_phase) - lex->et->on_completion= MYSQL_EVENT_ON_COMPLETION_PRESERVE; + lex->et->on_completion= Event_timed::ON_COMPLETION_PRESERVE; $$= 1; } | ON COMPLETION_SYM NOT_SYM PRESERVE_SYM { LEX *lex=Lex; if (!lex->et_compile_phase) - lex->et->on_completion= MYSQL_EVENT_ON_COMPLETION_DROP; + lex->et->on_completion= Event_timed::ON_COMPLETION_DROP; $$= 1; } ; @@ -3099,11 +3102,11 @@ opt_ts_engine: "STORAGE ENGINE"); YYABORT; } - lex->alter_tablespace_info->storage_engine= $4 ? $4 : &default_hton; + lex->alter_tablespace_info->storage_engine= $4; }; opt_ts_wait: - /* empty */ + /* empty */ | ts_wait ; @@ -3939,12 +3942,18 @@ storage_engines: ident_or_text { $$ = ha_resolve_by_name(YYTHD, &$1); - if ($$ == NULL && - test(YYTHD->variables.sql_mode & MODE_NO_ENGINE_SUBSTITUTION)) + if ($$ == NULL) + if (YYTHD->variables.sql_mode & MODE_NO_ENGINE_SUBSTITUTION) { my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str); YYABORT; } + else + { + push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_ERROR, + ER_UNKNOWN_STORAGE_ENGINE, + ER(ER_UNKNOWN_STORAGE_ENGINE), $1.str); + } }; row_types: @@ -4528,7 +4537,7 @@ init_key_options: key_alg: /* empty */ init_key_options - | init_key_options key_opts + | init_key_options key_using_alg ; key_options: @@ -4540,10 +4549,14 @@ key_opts: key_opt | key_opts key_opt ; - + +key_using_alg: + USING btree_or_rtree { Lex->key_create_info.algorithm= $2; } + | TYPE_SYM btree_or_rtree { Lex->key_create_info.algorithm= $2; } + ; + key_opt: - USING opt_btree_or_rtree { Lex->key_create_info.algorithm= $2; } - | TYPE_SYM opt_btree_or_rtree { Lex->key_create_info.algorithm= $2; } + key_using_alg | KEY_BLOCK_SIZE opt_equal ulong_num { Lex->key_create_info.block_size= $3; } | WITH PARSER_SYM IDENT_sys @@ -4559,7 +4572,7 @@ key_opt: ; -opt_btree_or_rtree: +btree_or_rtree: BTREE_SYM { $$= HA_KEY_ALG_BTREE; } | RTREE_SYM { @@ -4573,7 +4586,7 @@ key_list: key_part: ident { $$=new key_part_spec($1.str); } - | ident '(' NUM ')' + | ident '(' NUM ')' { int key_part_len= atoi($3.str); if (!key_part_len) @@ -4617,7 +4630,7 @@ alter: lex->select_lex.db=lex->name= 0; lex->like_name= 0; bzero((char*) &lex->create_info,sizeof(lex->create_info)); - lex->create_info.db_type= (handlerton*) &default_hton; + lex->create_info.db_type= 0; lex->create_info.default_table_charset= NULL; lex->create_info.row_type= ROW_TYPE_NOT_USED; lex->alter_info.reset(); @@ -6939,11 +6952,14 @@ table_factor: } expr '}' { + LEX *lex= Lex; YYERROR_UNLESS($3 && $7); add_join_on($7,$10); Lex->pop_context(); $7->outer_join|=JOIN_TYPE_LEFT; $$=$7; + if (!($$= lex->current_select->nest_last_join(lex->thd))) + YYABORT; } | select_derived_init get_select_lex select_derived2 { @@ -7488,7 +7504,11 @@ select_var_ident: if (lex->result) ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($2,0,0,(enum_field_types)0)); else - YYABORT; + /* + The parser won't create select_result instance only + if it's an EXPLAIN. + */ + DBUG_ASSERT(lex->describe); } | ident_or_text { @@ -7500,10 +7520,8 @@ select_var_ident: my_error(ER_SP_UNDECLARED_VAR, MYF(0), $1.str); YYABORT; } - if (! lex->result) - YYABORT; - else - { + if (lex->result) + { my_var *var; ((select_dumpvar *)lex->result)-> var_list.push_back(var= new my_var($1,1,t->offset,t->type)); @@ -7511,6 +7529,14 @@ select_var_ident: if (var) var->sp= lex->sphead; #endif + } + else + { + /* + The parser won't create select_result instance only + if it's an EXPLAIN. + */ + DBUG_ASSERT(lex->describe); } } ; @@ -8049,15 +8075,24 @@ show_param: if (prepare_schema_table(YYTHD, lex, 0, SCH_TRIGGERS)) YYABORT; } - | opt_full EVENTS_SYM opt_db wild_and_where + | EVENTS_SYM opt_db wild_and_where { LEX *lex= Lex; lex->sql_command= SQLCOM_SELECT; lex->orig_sql_command= SQLCOM_SHOW_EVENTS; - lex->select_lex.db= $3; + lex->select_lex.db= $2; if (prepare_schema_table(YYTHD, lex, 0, SCH_EVENTS)) YYABORT; } + | SCHEDULER_SYM STATUS_SYM + { +#ifndef DBUG_OFF + Lex->sql_command= SQLCOM_SHOW_SCHEDULER_STATUS; +#else + yyerror(ER(ER_SYNTAX_ERROR)); + YYABORT; +#endif + } | TABLE_SYM STATUS_SYM opt_db wild_and_where { LEX *lex= Lex; @@ -8166,6 +8201,11 @@ show_param: LEX *lex=Lex; lex->sql_command= SQLCOM_SHOW_AUTHORS; } + | CONTRIBUTORS_SYM + { + LEX *lex=Lex; + lex->sql_command= SQLCOM_SHOW_CONTRIBUTORS; + } | PRIVILEGES { LEX *lex=Lex; @@ -9006,12 +9046,18 @@ simple_ident_q: YYABORT; } + DBUG_ASSERT(!new_row || + (lex->trg_chistics.event == TRG_EVENT_INSERT || + lex->trg_chistics.event == TRG_EVENT_UPDATE)); + const bool read_only= + !(new_row && lex->trg_chistics.action_time == TRG_ACTION_BEFORE); if (!(trg_fld= new Item_trigger_field(Lex->current_context(), new_row ? Item_trigger_field::NEW_ROW: Item_trigger_field::OLD_ROW, $3.str, - Item_trigger_field::AT_READ))) + SELECT_ACL, + read_only))) YYABORT; /* @@ -9488,6 +9534,7 @@ keyword_sp: | ROW_SYM {} | RTREE_SYM {} | SCHEDULE_SYM {} + | SCHEDULER_SYM {} | SECOND_SYM {} | SERIAL_SYM {} | SERIALIZABLE_SYM {} @@ -9692,11 +9739,13 @@ sys_option_value: it= new Item_null(); } + DBUG_ASSERT(lex->trg_chistics.action_time == TRG_ACTION_BEFORE && + (lex->trg_chistics.event == TRG_EVENT_INSERT || + lex->trg_chistics.event == TRG_EVENT_UPDATE)); if (!(trg_fld= new Item_trigger_field(Lex->current_context(), Item_trigger_field::NEW_ROW, $2.base_name.str, - Item_trigger_field::AT_UPDATE) - ) || + UPDATE_ACL, FALSE)) || !(sp_fld= new sp_instr_set_trigger_field(lex->sphead-> instructions(), lex->spcont, diff --git a/sql/structs.h b/sql/structs.h index 72237887514..78f00f72df1 100644 --- a/sql/structs.h +++ b/sql/structs.h @@ -20,22 +20,6 @@ struct st_table; class Field; -typedef struct st_lex_string -{ - char *str; - uint length; -} LEX_STRING; - -typedef struct st_lex_string_with_init :public st_lex_string -{ - st_lex_string_with_init(const char *str_arg, uint length_arg) - { - str= (char*) str_arg; - length= length_arg; - } -} LEX_STRING_WITH_INIT; - - typedef struct st_date_time_format { uchar positions[8]; char time_separator; /* Separator between hour and minute */ diff --git a/sql/table.cc b/sql/table.cc index 4309695b458..39f1e1d620d 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -651,7 +651,6 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, my_free(buff, MYF(0)); goto err; } - next_chunk++; } #else if (partition_info_len) @@ -675,7 +674,15 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, */ next_chunk+= 4; } + else if (share->mysql_version >= 50110) #endif + { + /* New auto_partitioned indicator introduced in 5.1.11 */ +#ifdef WITH_PARTITION_STORAGE_ENGINE + share->auto_partitioned= *next_chunk; +#endif + next_chunk++; + } keyinfo= share->key_info; for (i= 0; i < keys; i++, keyinfo++) { @@ -1465,14 +1472,17 @@ int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias, old_root= *root_ptr; *root_ptr= &outparam->mem_root; - tmp= (mysql_unpack_partition(thd, share->partition_info, - share->partition_info_len, - (uchar*)share->part_state, - share->part_state_len, - outparam, is_create_table, - share->default_part_db_type) || - fix_partition_func(thd, share->normalized_path.str, outparam, - is_create_table)); + tmp= mysql_unpack_partition(thd, share->partition_info, + share->partition_info_len, + (uchar*)share->part_state, + share->part_state_len, + outparam, is_create_table, + share->default_part_db_type); + outparam->part_info->is_auto_partitioned= share->auto_partitioned; + DBUG_PRINT("info", ("autopartitioned: %u", share->auto_partitioned)); + if (!tmp) + tmp= fix_partition_func(thd, share->normalized_path.str, outparam, + is_create_table); *root_ptr= old_root; if (tmp) goto err; @@ -2364,12 +2374,23 @@ table_check_intact(TABLE *table, uint table_f_count, // previous MySQL version error= TRUE; if (MYSQL_VERSION_ID > table->s->mysql_version) + { my_error(ER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE, MYF(0), table->alias, table_f_count, table->s->fields, table->s->mysql_version, MYSQL_VERSION_ID); + sql_print_error(ER(ER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE), + table->alias, table_f_count, table->s->fields, + table->s->mysql_version, MYSQL_VERSION_ID); + DBUG_RETURN(error); + + } else if (MYSQL_VERSION_ID == table->s->mysql_version) + { my_error(ER_COL_COUNT_DOESNT_MATCH_CORRUPTED,MYF(0), table->alias, table_f_count, table->s->fields); + sql_print_error(ER(ER_COL_COUNT_DOESNT_MATCH_CORRUPTED), table->alias, + table_f_count, table->s->fields); + } else /* moving from newer mysql to older one -> let's say not an error but @@ -2410,9 +2431,7 @@ table_check_intact(TABLE *table, uint table_f_count, table running on a old server will be valid. */ field->sql_type(sql_type); - if (sql_type.length() < table_def->type.length - 1 || - strncmp(sql_type.ptr(), - table_def->type.str, + if (strncmp(sql_type.c_ptr_safe(), table_def->type.str, table_def->type.length - 1)) { sql_print_error("(%s) Expected field %s at position %d to have type " @@ -2832,7 +2851,8 @@ void st_table_list::hide_view_error(THD *thd) if (thd->net.last_errno == ER_BAD_FIELD_ERROR || thd->net.last_errno == ER_SP_DOES_NOT_EXIST || thd->net.last_errno == ER_PROCACCESS_DENIED_ERROR || - thd->net.last_errno == ER_COLUMNACCESS_DENIED_ERROR) + thd->net.last_errno == ER_COLUMNACCESS_DENIED_ERROR || + thd->net.last_errno == ER_TABLEACCESS_DENIED_ERROR) { TABLE_LIST *top= top_table(); thd->clear_error(); @@ -3192,8 +3212,18 @@ bool st_table_list::prepare_view_securety_context(THD *thd) definer.host.str, thd->db)) { - my_error(ER_NO_SUCH_USER, MYF(0), definer.user.str, definer.host.str); - DBUG_RETURN(TRUE); + if (thd->lex->sql_command == SQLCOM_SHOW_CREATE) + { + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, + ER_NO_SUCH_USER, + ER(ER_NO_SUCH_USER), + definer.user.str, definer.host.str); + } + else + { + my_error(ER_NO_SUCH_USER, MYF(0), definer.user.str, definer.host.str); + DBUG_RETURN(TRUE); + } } } DBUG_RETURN(FALSE); diff --git a/sql/table.h b/sql/table.h index 3058301874c..71a199d946e 100644 --- a/sql/table.h +++ b/sql/table.h @@ -216,6 +216,7 @@ typedef struct st_table_share */ bool log_table; #ifdef WITH_PARTITION_STORAGE_ENGINE + bool auto_partitioned; const uchar *partition_info; uint partition_info_len; const uchar *part_state; @@ -266,6 +267,7 @@ struct st_table { ha_rows quick_rows[MAX_KEY]; key_part_map const_key_parts[MAX_KEY]; uint quick_key_parts[MAX_KEY]; + uint quick_n_ranges[MAX_KEY]; /* If this table has TIMESTAMP field with auto-set property (pointed by diff --git a/sql/udf_example.cc b/sql/udf_example.cc index f4f936f34ef..6ad066eacc2 100644 --- a/sql/udf_example.cc +++ b/sql/udf_example.cc @@ -344,7 +344,7 @@ char *metaphon(UDF_INIT *initid, UDF_ARGS *args, char *result, KSflag = 0; /* state flag for KS translation */ for (metaph_end = result + MAXMETAPH, n_start = n; - n <= n_end && result < metaph_end; n++ ) + n < n_end && result < metaph_end; n++ ) { if ( KSflag ) diff --git a/sql/unireg.cc b/sql/unireg.cc index eb38e6c0592..11aa73bb502 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -130,8 +130,14 @@ bool mysql_create_frm(THD *thd, const char *file_name, /* str_db_type */ create_info->extra_size= (2 + str_db_type.length + 2 + create_info->connect_string.length); - /* Partition */ - create_info->extra_size+= 9; + /* + Partition: + Length of partition info = 4 byte + Potential NULL byte at end of partition info string = 1 byte + Indicator if auto-partitioned table = 1 byte + => Total 6 byte + */ + create_info->extra_size+= 6; #ifdef WITH_PARTITION_STORAGE_ENGINE if (part_info) { @@ -203,17 +209,19 @@ bool mysql_create_frm(THD *thd, const char *file_name, #ifdef WITH_PARTITION_STORAGE_ENGINE if (part_info) { + char auto_partitioned= part_info->is_auto_partitioned ? 1 : 0; int4store(buff, part_info->part_info_len); if (my_write(file, (const byte*)buff, 4, MYF_RW) || my_write(file, (const byte*)part_info->part_info_string, - part_info->part_info_len + 1, MYF_RW)) + part_info->part_info_len + 1, MYF_RW) || + my_write(file, (const byte*)&auto_partitioned, 1, MYF_RW)) goto err; } else #endif { - bzero(buff, 9); - if (my_write(file, (byte*) buff, 9, MYF_RW)) + bzero(buff, 6); + if (my_write(file, (byte*) buff, 6, MYF_RW)) goto err; } for (i= 0; i < keys; i++) diff --git a/storage/archive/cmakelists.txt b/storage/archive/CMakeLists.txt index a631f194b1a..a631f194b1a 100644 --- a/storage/archive/cmakelists.txt +++ b/storage/archive/CMakeLists.txt diff --git a/storage/archive/Makefile.am b/storage/archive/Makefile.am index 85577f406da..3d933408b0b 100644 --- a/storage/archive/Makefile.am +++ b/storage/archive/Makefile.am @@ -57,6 +57,6 @@ archive_test_LDADD = $(top_builddir)/mysys/libmysys.a \ archive_test_LDFLAGS = @NOINST_LDFLAGS@ -EXTRA_DIST = cmakelists.txt +EXTRA_DIST = CMakeLists.txt # Don't update the files from bitkeeper %::SCCS/s.% diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc index 970744566c9..e6c9c5dccd7 100644 --- a/storage/archive/ha_archive.cc +++ b/storage/archive/ha_archive.cc @@ -145,49 +145,7 @@ static handler *archive_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root); */ #define ARCHIVE_MIN_ROWS_TO_USE_BULK_INSERT 2 - -static const char archive_hton_name[]= "ARCHIVE"; -static const char archive_hton_comment[]= "Archive storage engine"; - -/* dummy handlerton - only to have something to return from archive_db_init */ -handlerton archive_hton = { - MYSQL_HANDLERTON_INTERFACE_VERSION, - archive_hton_name, - SHOW_OPTION_YES, - archive_hton_comment, - DB_TYPE_ARCHIVE_DB, - archive_db_init, - 0, /* slot */ - 0, /* savepoint size. */ - NULL, /* close_connection */ - NULL, /* savepoint */ - NULL, /* rollback to savepoint */ - NULL, /* releas savepoint */ - NULL, /* commit */ - NULL, /* rollback */ - NULL, /* prepare */ - NULL, /* recover */ - NULL, /* commit_by_xid */ - NULL, /* rollback_by_xid */ - NULL, /* create_cursor_read_view */ - NULL, /* set_cursor_read_view */ - NULL, /* close_cursor_read_view */ - archive_create_handler, /* Create a new handler */ - NULL, /* Drop a database */ - archive_db_end, /* Panic call */ - NULL, /* Start Consistent Snapshot */ - NULL, /* Flush logs */ - NULL, /* Show status */ - NULL, /* Partition flags */ - NULL, /* Alter table flags */ - NULL, /* Alter interface */ - NULL, /* fill_files_table */ - HTON_NO_FLAGS, - NULL, /* binlog_func */ - NULL, /* binlog_log_query */ - NULL /* release_temporary_latches */ - -}; +handlerton archive_hton; static handler *archive_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root) { @@ -217,11 +175,18 @@ static byte* archive_get_key(ARCHIVE_SHARE *share,uint *length, TRUE Error */ -bool archive_db_init() +int archive_db_init() { DBUG_ENTER("archive_db_init"); if (archive_inited) DBUG_RETURN(FALSE); + + archive_hton.state=SHOW_OPTION_YES; + archive_hton.db_type=DB_TYPE_ARCHIVE_DB; + archive_hton.create=archive_create_handler; + archive_hton.panic=archive_db_end; + archive_hton.flags=HTON_NO_FLAGS; + if (pthread_mutex_init(&archive_mutex, MY_MUTEX_INIT_FAST)) goto error; if (hash_init(&archive_open_tables, system_charset_info, 32, 0, 0, @@ -701,14 +666,6 @@ int ha_archive::create(const char *name, TABLE *table_arg, create_info->auto_increment_value -1 : (ulonglong) 0); - if ((create_file= my_create(fn_format(name_buff,name,"",ARM, - MY_REPLACE_EXT|MY_UNPACK_FILENAME),0, - O_RDWR | O_TRUNC,MYF(MY_WME))) < 0) - { - error= my_errno; - goto error; - } - for (uint key= 0; key < table_arg->s->keys; key++) { KEY *pos= table_arg->key_info+key; @@ -722,11 +679,20 @@ int ha_archive::create(const char *name, TABLE *table_arg, if (!(field->flags & AUTO_INCREMENT_FLAG)) { error= -1; + DBUG_PRINT("info", ("Index error in creating archive table")); goto error; } } } + if ((create_file= my_create(fn_format(name_buff,name,"",ARM, + MY_REPLACE_EXT|MY_UNPACK_FILENAME),0, + O_RDWR | O_TRUNC,MYF(MY_WME))) < 0) + { + error= my_errno; + goto error; + } + write_meta_file(create_file, 0, stats.auto_increment_value, 0, (char *)create_info->data_file_name, FALSE); @@ -946,9 +912,13 @@ error: } -ulonglong ha_archive::get_auto_increment() +void ha_archive::get_auto_increment(ulonglong offset, ulonglong increment, + ulonglong nb_desired_values, + ulonglong *first_value, + ulonglong *nb_reserved_values) { - return share->auto_increment_value + 1; + *nb_reserved_values= 1; + *first_value= share->auto_increment_value + 1; } /* Initialized at each key walk (called multiple times unlike rnd_init()) */ @@ -1242,7 +1212,7 @@ int ha_archive::repair(THD* thd, HA_CHECK_OPT* check_opt) int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt) { DBUG_ENTER("ha_archive::optimize"); - int rc; + int rc= 0; azio_stream writer; char writer_filename[FN_REFLEN]; @@ -1345,31 +1315,31 @@ int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt) azclose(&writer); share->dirty= FALSE; share->forced_flushes= 0; + + // now we close both our writer and our reader for the rename azclose(&(share->archive_write)); - DBUG_PRINT("info", ("Reopening archive data file")); - if (!(azopen(&(share->archive_write), share->data_file_name, - O_WRONLY|O_APPEND|O_BINARY))) - { - DBUG_PRINT("info", ("Could not open archive write file")); - rc= HA_ERR_CRASHED_ON_USAGE; - goto error; - } + azclose(&archive); - my_rename(writer_filename,share->data_file_name,MYF(0)); + // make the file we just wrote be our data file + rc = my_rename(writer_filename,share->data_file_name,MYF(0)); /* - Now we need to reopen our read descriptor since it has changed. + now open the shared writer back up + we don't check rc here because we want to open the file back up even + if the optimize failed but we will return rc below so that we will + know it failed. + We also need to reopen our read descriptor since it has changed. */ - azclose(&archive); - if (!(azopen(&archive, share->data_file_name, O_RDONLY|O_BINARY))) + DBUG_PRINT("info", ("Reopening archive data file")); + if (!azopen(&(share->archive_write), share->data_file_name, + O_WRONLY|O_APPEND|O_BINARY) || + !azopen(&archive, share->data_file_name, O_RDONLY|O_BINARY)) { + DBUG_PRINT("info", ("Could not open archive write file")); rc= HA_ERR_CRASHED_ON_USAGE; - goto error; } - - DBUG_RETURN(0); - + DBUG_RETURN(rc); error: azclose(&writer); @@ -1578,17 +1548,20 @@ bool ha_archive::check_and_repair(THD *thd) DBUG_RETURN(repair(thd, &check_opt)); } +struct st_mysql_storage_engine archive_storage_engine= +{ MYSQL_HANDLERTON_INTERFACE_VERSION, &archive_hton }; mysql_declare_plugin(archive) { MYSQL_STORAGE_ENGINE_PLUGIN, - &archive_hton, - archive_hton_name, + &archive_storage_engine, + "ARCHIVE", "Brian Aker, MySQL AB", - archive_hton_comment, - NULL, /* Plugin Init */ + "Archive storage engine", + archive_db_init, /* Plugin Init */ archive_db_done, /* Plugin Deinit */ 0x0100 /* 1.0 */, 0 } mysql_declare_plugin_end; + diff --git a/storage/archive/ha_archive.h b/storage/archive/ha_archive.h index f35858ff382..0485b7e9f9c 100644 --- a/storage/archive/ha_archive.h +++ b/storage/archive/ha_archive.h @@ -83,7 +83,10 @@ public: { return HA_ONLY_WHOLE_INDEX; } - ulonglong get_auto_increment(); + virtual void get_auto_increment(ulonglong offset, ulonglong increment, + ulonglong nb_desired_values, + ulonglong *first_value, + ulonglong *nb_reserved_values); uint max_supported_keys() const { return 1; } uint max_supported_key_length() const { return sizeof(ulonglong); } uint max_supported_key_part_length() const { return sizeof(ulonglong); } @@ -136,6 +139,6 @@ public: bool check_and_repair(THD *thd); }; -bool archive_db_init(void); +int archive_db_init(void); int archive_db_end(ha_panic_function type); diff --git a/storage/archive/plug.in b/storage/archive/plug.in new file mode 100644 index 00000000000..52131b12e6b --- /dev/null +++ b/storage/archive/plug.in @@ -0,0 +1,4 @@ +MYSQL_STORAGE_ENGINE(archive,, [Archive Storage Engine], + [Archive Storage Engine], [max,max-no-ndb]) +MYSQL_PLUGIN_STATIC(archive, [libarchive.a]) +MYSQL_PLUGIN_DYNAMIC(archive, [ha_archive.la]) diff --git a/storage/bdb/cmakelists.txt b/storage/bdb/CMakeLists.txt index c27665d902c..c27665d902c 100644 --- a/storage/bdb/cmakelists.txt +++ b/storage/bdb/CMakeLists.txt diff --git a/storage/bdb/Makefile.in b/storage/bdb/Makefile.in index 4e2439025f3..6d7da66edf4 100644 --- a/storage/bdb/Makefile.in +++ b/storage/bdb/Makefile.in @@ -23,7 +23,7 @@ top_srcdir = @top_srcdir@ # distdir and top_distdir are set by the calling Makefile bdb_build = build_unix -files = LICENSE Makefile Makefile.in README cmakelists.txt +files = LICENSE Makefile Makefile.in README CMakeLists.txt subdirs = btree build_win32 clib common cxx db dbinc \ dbinc_auto db185 db_archive db_checkpoint db_deadlock db_dump \ db_dump185 db_hotbackup db_load db_printlog db_recover db_stat db_upgrade \ diff --git a/storage/blackhole/cmakelists.txt b/storage/blackhole/CMakeLists.txt index ea3a7eae38e..ea3a7eae38e 100644 --- a/storage/blackhole/cmakelists.txt +++ b/storage/blackhole/CMakeLists.txt diff --git a/storage/blackhole/Makefile.am b/storage/blackhole/Makefile.am index 902d57c1668..e3e28cd75b5 100644 --- a/storage/blackhole/Makefile.am +++ b/storage/blackhole/Makefile.am @@ -47,6 +47,6 @@ libblackhole_a_CFLAGS = $(AM_CFLAGS) libblackhole_a_SOURCES= ha_blackhole.cc -EXTRA_DIST = cmakelists.txt +EXTRA_DIST = CMakeLists.txt # Don't update the files from bitkeeper %::SCCS/s.% diff --git a/storage/blackhole/ha_blackhole.cc b/storage/blackhole/ha_blackhole.cc index ffcf9536ff2..1a2bb264ef9 100644 --- a/storage/blackhole/ha_blackhole.cc +++ b/storage/blackhole/ha_blackhole.cc @@ -22,59 +22,9 @@ #include "mysql_priv.h" #include "ha_blackhole.h" -#include <mysql/plugin.h> - /* Static declarations for handlerton */ -static handler *blackhole_create_handler(TABLE_SHARE *table, - MEM_ROOT *mem_root); - - -static const char blackhole_hton_name[]= "BLACKHOLE"; -static const char blackhole_hton_comment[]= - "/dev/null storage engine (anything you write to it disappears)"; - -/* Blackhole storage engine handlerton */ - -handlerton blackhole_hton= { - MYSQL_HANDLERTON_INTERFACE_VERSION, - blackhole_hton_name, - SHOW_OPTION_YES, - blackhole_hton_comment, - DB_TYPE_BLACKHOLE_DB, - NULL, - 0, /* slot */ - 0, /* savepoint size. */ - NULL, /* close_connection */ - NULL, /* savepoint */ - NULL, /* rollback to savepoint */ - NULL, /* release savepoint */ - NULL, /* commit */ - NULL, /* rollback */ - NULL, /* prepare */ - NULL, /* recover */ - NULL, /* commit_by_xid */ - NULL, /* rollback_by_xid */ - NULL, /* create_cursor_read_view */ - NULL, /* set_cursor_read_view */ - NULL, /* close_cursor_read_view */ - blackhole_create_handler, /* Create a new handler */ - NULL, /* Drop a database */ - NULL, /* Panic call */ - NULL, /* Start Consistent Snapshot */ - NULL, /* Flush logs */ - NULL, /* Show status */ - NULL, /* Partition flags */ - NULL, /* Alter table flags */ - NULL, /* Alter Tablespace */ - NULL, /* Fill FILES table */ - HTON_CAN_RECREATE, - NULL, /* binlog_func */ - NULL, /* binlog_log_query */ - NULL /* release_temporary_latches */ -}; - - +handlerton blackhole_hton; static handler *blackhole_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root) { @@ -251,14 +201,26 @@ int ha_blackhole::index_last(byte * buf) DBUG_RETURN(HA_ERR_END_OF_FILE); } +static int blackhole_init() +{ + blackhole_hton.state= SHOW_OPTION_YES; + blackhole_hton.db_type= DB_TYPE_BLACKHOLE_DB; + blackhole_hton.create= blackhole_create_handler; + blackhole_hton.flags= HTON_CAN_RECREATE | HTON_ALTER_CANNOT_CREATE; + return 0; +} + +struct st_mysql_storage_engine blackhole_storage_engine= +{ MYSQL_HANDLERTON_INTERFACE_VERSION, &blackhole_hton }; + mysql_declare_plugin(blackhole) { MYSQL_STORAGE_ENGINE_PLUGIN, - &blackhole_hton, - blackhole_hton_name, + &blackhole_storage_engine, + "BLACKHOLE", "MySQL AB", - blackhole_hton_comment, - NULL, /* Plugin Init */ + "/dev/null storage engine (anything you write to it disappears)", + blackhole_init, /* Plugin Init */ NULL, /* Plugin Deinit */ 0x0100 /* 1.0 */, 0 diff --git a/storage/csv/cmakelists.txt b/storage/csv/CMakeLists.txt index 28748527cc3..28748527cc3 100644 --- a/storage/csv/cmakelists.txt +++ b/storage/csv/CMakeLists.txt diff --git a/storage/csv/Makefile.am b/storage/csv/Makefile.am index a2afeba137f..adebebd7cd8 100644 --- a/storage/csv/Makefile.am +++ b/storage/csv/Makefile.am @@ -41,6 +41,6 @@ noinst_LIBRARIES = @plugin_csv_static_target@ libcsv_a_CXXFLAGS = $(AM_CFLAGS) libcsv_a_SOURCES = ha_tina.cc -EXTRA_DIST = cmakelists.txt +EXTRA_DIST = CMakeLists.txt # Don't update the files from bitkeeper %::SCCS/s.% diff --git a/storage/csv/ha_tina.cc b/storage/csv/ha_tina.cc index c70e21a0be7..229d76b22df 100644 --- a/storage/csv/ha_tina.cc +++ b/storage/csv/ha_tina.cc @@ -77,46 +77,7 @@ static int tina_init= 0; static handler *tina_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root); static int tina_init_func(); -static const char tina_hton_name[]= "CSV"; -static const char tina_hton_comment[]= "CSV storage engine"; - -handlerton tina_hton= { - MYSQL_HANDLERTON_INTERFACE_VERSION, - tina_hton_name, - SHOW_OPTION_YES, - tina_hton_comment, - DB_TYPE_CSV_DB, - (bool (*)()) tina_init_func, - 0, /* slot */ - 0, /* savepoint size. */ - NULL, /* close_connection */ - NULL, /* savepoint */ - NULL, /* rollback to savepoint */ - NULL, /* release savepoint */ - NULL, /* commit */ - NULL, /* rollback */ - NULL, /* prepare */ - NULL, /* recover */ - NULL, /* commit_by_xid */ - NULL, /* rollback_by_xid */ - NULL, /* create_cursor_read_view */ - NULL, /* set_cursor_read_view */ - NULL, /* close_cursor_read_view */ - tina_create_handler, /* Create a new handler */ - NULL, /* Drop a database */ - tina_end, /* Panic call */ - NULL, /* Start Consistent Snapshot */ - NULL, /* Flush logs */ - NULL, /* Show status */ - NULL, /* Partition flags */ - NULL, /* Alter table flags */ - NULL, /* Alter Tablespace */ - NULL, /* Fill FILES Table */ - HTON_CAN_RECREATE, - NULL, /* binlog_func */ - NULL, /* binlog_log_query */ - 0 -}; +handlerton tina_hton; /***************************************************************************** ** TINA tables @@ -147,6 +108,11 @@ static byte* tina_get_key(TINA_SHARE *share,uint *length, int get_mmap(TINA_SHARE *share, int write) { DBUG_ENTER("ha_tina::get_mmap"); +#ifdef __NETWARE__ + my_message(errno, "Sorry, no mmap() on Netware", 0); + DBUG_ASSERT(0); + DBUG_RETURN(1); +#else if (share->mapped_file && my_munmap(share->mapped_file, share->file_stat.st_size)) DBUG_RETURN(1); @@ -181,6 +147,7 @@ int get_mmap(TINA_SHARE *share, int write) share->mapped_file= NULL; DBUG_RETURN(0); +#endif /* __NETWARE__ */ } @@ -192,6 +159,11 @@ static int tina_init_func() 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); + tina_hton.state= SHOW_OPTION_YES; + tina_hton.db_type= DB_TYPE_CSV_DB; + tina_hton.create= tina_create_handler; + tina_hton.panic= tina_end; + tina_hton.flags= HTON_CAN_RECREATE; } return 0; } @@ -467,14 +439,28 @@ int tina_end(ha_panic_function type) /* Finds the end of a line. - Currently only supports files written on a UNIX OS. + Supports DOS, Unix, or Mac OS line endings. */ -byte * find_eoln(byte *data, off_t begin, off_t end) +byte * find_eoln(byte *data, off_t begin, off_t end, int *eoln_len) { + off_t dataend= begin; + *eoln_len= 0; + for (off_t x= begin; x < end; x++) - if (data[x] == '\n') - return data + x; + if (data[x] == '\r' || data[x] == '\n') + (*eoln_len)++; + else if (!(*eoln_len)) + dataend++; + else + return data+dataend; + /* + if we only have one record in the file then our for loop will break + before we return. we should still have seen end of line markers and + so we just return the line here + */ + if (*eoln_len > 0) + return data+dataend; return 0; } @@ -625,6 +611,7 @@ int ha_tina::find_current_row(byte *buf) { byte *mapped_ptr; byte *end_ptr; + int eoln_len; my_bitmap_map *org_bitmap; DBUG_ENTER("ha_tina::find_current_row"); @@ -635,7 +622,7 @@ int ha_tina::find_current_row(byte *buf) not to conflict with undergoing concurrent insert. */ if ((end_ptr= find_eoln(share->mapped_file, current_position, - local_saved_data_file_length)) == 0) + local_saved_data_file_length, &eoln_len)) == 0) DBUG_RETURN(HA_ERR_END_OF_FILE); /* Avoid asserts in ::store() for columns that are not going to be updated */ @@ -687,7 +674,7 @@ int ha_tina::find_current_row(byte *buf) if (bitmap_is_set(table->read_set, (*field)->field_index)) (*field)->store(buffer.ptr(), buffer.length(), system_charset_info); } - next_position= (end_ptr - share->mapped_file)+1; + next_position= (end_ptr - share->mapped_file)+eoln_len; /* Maybe use \N for null? */ memset(buf, 0, table->s->null_bytes); /* We do not implement nulls! */ tmp_restore_column_map(table->write_set, org_bitmap); @@ -1413,14 +1400,16 @@ bool ha_tina::check_if_incompatible_data(HA_CREATE_INFO *info, return COMPATIBLE_DATA_YES; } +struct st_mysql_storage_engine csv_storage_engine= +{ MYSQL_HANDLERTON_INTERFACE_VERSION, &tina_hton }; mysql_declare_plugin(csv) { MYSQL_STORAGE_ENGINE_PLUGIN, - &tina_hton, - tina_hton_name, + &csv_storage_engine, + "CSV", "Brian Aker, MySQL AB", - tina_hton_comment, + "CSV storage engine", tina_init_func, /* Plugin Init */ tina_done_func, /* Plugin Deinit */ 0x0100 /* 1.0 */, diff --git a/storage/example/cmakelists.txt b/storage/example/CMakeLists.txt index f4579aa0c66..f4579aa0c66 100644 --- a/storage/example/cmakelists.txt +++ b/storage/example/CMakeLists.txt diff --git a/storage/example/Makefile.am b/storage/example/Makefile.am index 9c4bedb2160..db3e35e4315 100644 --- a/storage/example/Makefile.am +++ b/storage/example/Makefile.am @@ -47,6 +47,6 @@ libexample_a_CFLAGS = $(AM_CFLAGS) libexample_a_SOURCES= ha_example.cc -EXTRA_DIST = cmakelists.txt +EXTRA_DIST = CMakeLists.txt # Don't update the files from bitkeeper %::SCCS/s.% diff --git a/storage/example/ha_example.cc b/storage/example/ha_example.cc index f2f4694b54e..feabad2e356 100644 --- a/storage/example/ha_example.cc +++ b/storage/example/ha_example.cc @@ -77,46 +77,7 @@ static int example_init_func(); static bool example_init_func_for_handlerton(); static int example_panic(enum ha_panic_function flag); -static const char example_hton_name[]= "EXAMPLE"; -static const char example_hton_comment[]= "Example storage engine"; - -handlerton example_hton= { - MYSQL_HANDLERTON_INTERFACE_VERSION, - example_hton_name, - SHOW_OPTION_YES, - example_hton_comment, - DB_TYPE_EXAMPLE_DB, - example_init_func_for_handlerton, - 0, /* slot */ - 0, /* savepoint size. */ - NULL, /* close_connection */ - NULL, /* savepoint */ - NULL, /* rollback to savepoint */ - NULL, /* release savepoint */ - NULL, /* commit */ - NULL, /* rollback */ - NULL, /* prepare */ - NULL, /* recover */ - NULL, /* commit_by_xid */ - NULL, /* rollback_by_xid */ - NULL, /* create_cursor_read_view */ - NULL, /* set_cursor_read_view */ - NULL, /* close_cursor_read_view */ - example_create_handler, /* Create a new handler */ - NULL, /* Drop a database */ - example_panic, /* Panic call */ - NULL, /* Start Consistent Snapshot */ - NULL, /* Flush logs */ - NULL, /* Show status */ - NULL, /* Partition flags */ - NULL, /* Alter table flags */ - NULL, /* Alter tablespace */ - NULL, /* Fill Files table */ - HTON_CAN_RECREATE, - NULL, - NULL, - NULL, -}; +handlerton example_hton; /* Variables for example share methods */ static HASH example_open_tables; // Hash used to track open tables @@ -143,6 +104,11 @@ static int example_init_func() 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); + + example_hton.state= SHOW_OPTION_YES; + example_hton.db_type= DB_TYPE_EXAMPLE_DB; + example_hton.create= example_create_handler; + example_hton.flags= HTON_CAN_RECREATE; } DBUG_RETURN(0); } @@ -163,17 +129,6 @@ static int example_done_func() DBUG_RETURN(0); } -static bool example_init_func_for_handlerton() -{ - return example_init_func(); -} - -static int example_panic(enum ha_panic_function flag) -{ - return example_done_func(); -} - - /* 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 @@ -741,18 +696,21 @@ int ha_example::create(const char *name, TABLE *table_arg, HA_CREATE_INFO *create_info) { DBUG_ENTER("ha_example::create"); - /* This is not implemented but we want someone to be able that it works. */ + /* This is not implemented but we want someone to be able to see that it works. */ DBUG_RETURN(0); } +struct st_mysql_storage_engine example_storage_engine= +{ MYSQL_HANDLERTON_INTERFACE_VERSION, &example_hton }; + mysql_declare_plugin(example) { MYSQL_STORAGE_ENGINE_PLUGIN, - &example_hton, - example_hton_name, + &example_storage_engine, + "EXAMPLE", "Brian Aker, MySQL AB", - example_hton_comment, + "Example storage engine", example_init_func, /* Plugin Init */ example_done_func, /* Plugin Deinit */ 0x0001 /* 0.1 */, diff --git a/storage/example/plug.in b/storage/example/plug.in new file mode 100644 index 00000000000..bf5bb49b429 --- /dev/null +++ b/storage/example/plug.in @@ -0,0 +1,4 @@ +MYSQL_STORAGE_ENGINE(example,, [Example Storage Engine], + [Skeleton for Storage Engines for developers], [max,max-no-ndb]) +MYSQL_PLUGIN_STATIC(example, [libexample.a]) +MYSQL_PLUGIN_DYNAMIC(example, [ha_example.la]) diff --git a/storage/heap/cmakelists.txt b/storage/heap/CMakeLists.txt index db5fb8b2981..db5fb8b2981 100644 --- a/storage/heap/cmakelists.txt +++ b/storage/heap/CMakeLists.txt diff --git a/storage/heap/Makefile.am b/storage/heap/Makefile.am index fceaeec664a..68dce9bca5f 100644 --- a/storage/heap/Makefile.am +++ b/storage/heap/Makefile.am @@ -30,7 +30,7 @@ libheap_a_SOURCES = hp_open.c hp_extra.c hp_close.c hp_panic.c hp_info.c \ hp_rnext.c hp_rlast.c hp_rprev.c hp_clear.c \ hp_rkey.c hp_block.c \ hp_hash.c _check.c _rectest.c hp_static.c -EXTRA_DIST = cmakelists.txt +EXTRA_DIST = CMakeLists.txt # Don't update the files from bitkeeper %::SCCS/s.% diff --git a/storage/heap/hp_create.c b/storage/heap/hp_create.c index 329f4b7fa2d..8e185a60262 100644 --- a/storage/heap/hp_create.c +++ b/storage/heap/hp_create.c @@ -85,6 +85,7 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef, if (!my_binary_compare(keyinfo->seg[j].charset)) keyinfo->flag|= HA_END_SPACE_KEY; keyinfo->flag|= HA_VAR_LENGTH_KEY; + length+= 2; /* Save number of bytes used to store length */ keyinfo->seg[j].bit_start= 1; break; @@ -95,6 +96,7 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef, if (!my_binary_compare(keyinfo->seg[j].charset)) keyinfo->flag|= HA_END_SPACE_KEY; keyinfo->flag|= HA_VAR_LENGTH_KEY; + length+= 2; /* Save number of bytes used to store length */ keyinfo->seg[j].bit_start= 2; /* diff --git a/storage/heap/hp_write.c b/storage/heap/hp_write.c index a60d32eecb6..bc94e3bfae4 100644 --- a/storage/heap/hp_write.c +++ b/storage/heap/hp_write.c @@ -105,7 +105,7 @@ int hp_rb_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, const byte *record, custom_arg.key_length= hp_rb_make_key(keyinfo, info->recbuf, record, recpos); if (keyinfo->flag & HA_NOSAME) { - custom_arg.search_flag= SEARCH_FIND | SEARCH_SAME | SEARCH_UPDATE; + custom_arg.search_flag= SEARCH_FIND | SEARCH_UPDATE; keyinfo->rb_tree.flag= TREE_NO_DUPS; } else diff --git a/storage/innobase/cmakelists.txt b/storage/innobase/CMakeLists.txt index def51873725..def51873725 100644 --- a/storage/innobase/cmakelists.txt +++ b/storage/innobase/CMakeLists.txt diff --git a/storage/innobase/Makefile.am b/storage/innobase/Makefile.am index 908f5d669a2..bf41d3dca88 100644 --- a/storage/innobase/Makefile.am +++ b/storage/innobase/Makefile.am @@ -77,7 +77,7 @@ EXTRA_DIST = include/btr0btr.h include/btr0btr.ic include/btr0cur.h include/btr include/ut0byte.h include/ut0byte.ic include/ut0dbg.h include/ut0lst.h \ include/ut0mem.h include/ut0mem.ic include/ut0rnd.h include/ut0rnd.ic \ include/ut0sort.h include/ut0ut.h include/ut0ut.ic include/ut0vec.h include/ut0vec.ic \ - cmakelists.txt + CMakeLists.txt noinst_LIBRARIES = libinnobase.a libinnobase_a_LIBADD = usr/libusr.a srv/libsrv.a dict/libdict.a \ diff --git a/storage/myisam/cmakelists.txt b/storage/myisam/CMakeLists.txt index 3ba7aba4555..3ba7aba4555 100644 --- a/storage/myisam/cmakelists.txt +++ b/storage/myisam/CMakeLists.txt diff --git a/storage/myisam/Makefile.am b/storage/myisam/Makefile.am index 3c6a5c22234..081d7facf3a 100644 --- a/storage/myisam/Makefile.am +++ b/storage/myisam/Makefile.am @@ -14,7 +14,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -EXTRA_DIST = mi_test_all.sh mi_test_all.res ft_stem.c cmakelists.txt +EXTRA_DIST = mi_test_all.sh mi_test_all.res ft_stem.c CMakeLists.txt pkgdata_DATA = mi_test_all mi_test_all.res INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include diff --git a/storage/myisam/ft_boolean_search.c b/storage/myisam/ft_boolean_search.c index 4f58b44722d..cb4005d5c84 100644 --- a/storage/myisam/ft_boolean_search.c +++ b/storage/myisam/ft_boolean_search.c @@ -160,7 +160,6 @@ static int FTB_WORD_cmp_list(CHARSET_INFO *cs, FTB_WORD **a, FTB_WORD **b) typedef struct st_my_ftb_param { - MYSQL_FTPARSER_PARAM *up; FTB *ftb; FTB_EXPR *ftbe; byte *up_quot; @@ -168,10 +167,11 @@ typedef struct st_my_ftb_param } MY_FTB_PARAM; -static int ftb_query_add_word(void *param, char *word, int word_len, +static int ftb_query_add_word(MYSQL_FTPARSER_PARAM *param, + char *word, int word_len, MYSQL_FTPARSER_BOOLEAN_INFO *info) { - MY_FTB_PARAM *ftb_param= (MY_FTB_PARAM *)param; + MY_FTB_PARAM *ftb_param= param->mysql_ftparam; FTB_WORD *ftbw; FTB_EXPR *ftbe, *tmp_expr; FT_WORD *phrase_word; @@ -269,9 +269,10 @@ static int ftb_query_add_word(void *param, char *word, int word_len, } -static int ftb_parse_query_internal(void *param, char *query, int len) +static int ftb_parse_query_internal(MYSQL_FTPARSER_PARAM *param, + char *query, int len) { - MY_FTB_PARAM *ftb_param= (MY_FTB_PARAM *)param; + MY_FTB_PARAM *ftb_param= param->mysql_ftparam; MYSQL_FTPARSER_BOOLEAN_INFO info; CHARSET_INFO *cs= ftb_param->ftb->charset; char **start= &query; @@ -281,7 +282,7 @@ static int ftb_parse_query_internal(void *param, char *query, int len) info.prev= ' '; info.quot= 0; while (ft_get_word(cs, start, end, &w, &info)) - ftb_param->up->mysql_add_word(param, w.pos, w.len, &info); + param->mysql_add_word(param, w.pos, w.len, &info); return(0); } @@ -299,7 +300,6 @@ static void _ftb_parse_query(FTB *ftb, byte *query, uint len, if (! (param= ftparser_call_initializer(ftb->info, ftb->keynr, 0))) DBUG_VOID_RETURN; - ftb_param.up= param; ftb_param.ftb= ftb; ftb_param.depth= 0; ftb_param.ftbe= ftb->root; @@ -311,6 +311,7 @@ static void _ftb_parse_query(FTB *ftb, byte *query, uint len, param->cs= ftb->charset; param->doc= query; param->length= len; + param->flags= 0; param->mode= MYSQL_FTPARSER_FULL_BOOLEAN_INFO; parser->parse(param); DBUG_VOID_RETURN; @@ -571,7 +572,6 @@ err: typedef struct st_my_ftb_phrase_param { - MYSQL_FTPARSER_PARAM *up; LIST *phrase; LIST *document; CHARSET_INFO *cs; @@ -581,10 +581,11 @@ typedef struct st_my_ftb_phrase_param } MY_FTB_PHRASE_PARAM; -static int ftb_phrase_add_word(void *param, char *word, int word_len, +static int ftb_phrase_add_word(MYSQL_FTPARSER_PARAM *param, + char *word, int word_len, MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info __attribute__((unused))) { - MY_FTB_PHRASE_PARAM *phrase_param= (MY_FTB_PHRASE_PARAM *)param; + MY_FTB_PHRASE_PARAM *phrase_param= param->mysql_ftparam; FT_WORD *w= (FT_WORD *)phrase_param->document->data; LIST *phrase, *document; w->pos= word; @@ -612,14 +613,15 @@ static int ftb_phrase_add_word(void *param, char *word, int word_len, } -static int ftb_check_phrase_internal(void *param, char *document, int len) +static int ftb_check_phrase_internal(MYSQL_FTPARSER_PARAM *param, + char *document, int len) { FT_WORD word; - MY_FTB_PHRASE_PARAM *phrase_param= (MY_FTB_PHRASE_PARAM *)param; + MY_FTB_PHRASE_PARAM *phrase_param= param->mysql_ftparam; const char *docend= document + len; while (ft_simple_get_word(phrase_param->cs, &document, docend, &word, FALSE)) { - phrase_param->up->mysql_add_word(param, word.pos, word.len, 0); + param->mysql_add_word(param, word.pos, word.len, 0); if (phrase_param->match) return 1; } @@ -652,7 +654,6 @@ static int _ftb_check_phrase(FTB *ftb, const byte *document, uint len, if (! (param= ftparser_call_initializer(ftb->info, ftb->keynr, 1))) DBUG_RETURN(0); - ftb_param.up= param; ftb_param.phrase= ftbe->phrase; ftb_param.document= ftbe->document; ftb_param.cs= ftb->charset; @@ -666,6 +667,7 @@ static int _ftb_check_phrase(FTB *ftb, const byte *document, uint len, param->cs= ftb->charset; param->doc= (byte *)document; param->length= len; + param->flags= 0; param->mode= MYSQL_FTPARSER_WITH_STOPWORDS; parser->parse(param); DBUG_RETURN(ftb_param.match ? 1 : 0); @@ -821,16 +823,16 @@ err: typedef struct st_my_ftb_find_param { - MYSQL_FTPARSER_PARAM *up; FT_INFO *ftb; FT_SEG_ITERATOR *ftsi; } MY_FTB_FIND_PARAM; -static int ftb_find_relevance_add_word(void *param, char *word, int len, +static int ftb_find_relevance_add_word(MYSQL_FTPARSER_PARAM *param, + char *word, int len, MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info __attribute__((unused))) { - MY_FTB_FIND_PARAM *ftb_param= (MY_FTB_FIND_PARAM *)param; + MY_FTB_FIND_PARAM *ftb_param= param->mysql_ftparam; FT_INFO *ftb= ftb_param->ftb; FTB_WORD *ftbw; int a, b, c; @@ -860,14 +862,15 @@ static int ftb_find_relevance_add_word(void *param, char *word, int len, } -static int ftb_find_relevance_parse(void *param, char *doc, int len) +static int ftb_find_relevance_parse(MYSQL_FTPARSER_PARAM *param, + char *doc, int len) { - MY_FTB_FIND_PARAM *ftb_param=(MY_FTB_FIND_PARAM *)param; + MY_FTB_FIND_PARAM *ftb_param= param->mysql_ftparam; FT_INFO *ftb= ftb_param->ftb; char *end= doc + len; FT_WORD w; while (ft_simple_get_word(ftb->charset, &doc, end, &w, TRUE)) - ftb_param->up->mysql_add_word(param, w.pos, w.len, 0); + param->mysql_add_word(param, w.pos, w.len, 0); return(0); } @@ -911,12 +914,12 @@ float ft_boolean_find_relevance(FT_INFO *ftb, byte *record, uint length) _mi_ft_segiterator_init(ftb->info, ftb->keynr, record, &ftsi); memcpy(&ftsi2, &ftsi, sizeof(ftsi)); - ftb_param.up= param; ftb_param.ftb= ftb; ftb_param.ftsi= &ftsi2; param->mysql_parse= ftb_find_relevance_parse; param->mysql_add_word= ftb_find_relevance_add_word; param->mysql_ftparam= (void *)&ftb_param; + param->flags= 0; param->cs= ftb->charset; param->mode= MYSQL_FTPARSER_SIMPLE_MODE; while (_mi_ft_segiterator(&ftsi)) diff --git a/storage/myisam/ft_nlq_search.c b/storage/myisam/ft_nlq_search.c index b8207c1c3d0..53a01003dcd 100644 --- a/storage/myisam/ft_nlq_search.c +++ b/storage/myisam/ft_nlq_search.c @@ -235,7 +235,9 @@ FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, byte *query, NULL, NULL); ft_parse_init(&wtree, aio.charset); - if (ft_parse(&wtree, query, query_len, 0, parser, ftparser_param)) + ftparser_param->flags= 0; + if (ft_parse(&wtree, query, query_len, parser, ftparser_param, + &wtree.mem_root)) goto err; if (tree_walk(&wtree, (tree_walk_action)&walk_and_match, &aio, @@ -255,7 +257,9 @@ FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, byte *query, if (!(*info->read_record)(info,docid,record)) { info->update|= HA_STATE_AKTIV; - _mi_ft_parse(&wtree, info, keynr, record, 1, ftparser_param); + ftparser_param->flags= MYSQL_FTFLAGS_NEED_COPY; + _mi_ft_parse(&wtree, info, keynr, record, ftparser_param, + &wtree.mem_root); } } delete_queue(&best); diff --git a/storage/myisam/ft_parser.c b/storage/myisam/ft_parser.c index 89ede813a2b..38ac744d4a8 100644 --- a/storage/myisam/ft_parser.c +++ b/storage/myisam/ft_parser.c @@ -24,15 +24,12 @@ typedef struct st_ft_docstat { double sum; } FT_DOCSTAT; - typedef struct st_my_ft_parser_param { - MYSQL_FTPARSER_PARAM *up; - TREE *wtree; - my_bool with_alloc; + TREE *wtree; + MEM_ROOT *mem_root; } MY_FT_PARSER_PARAM; - static int FT_WORD_cmp(CHARSET_INFO* cs, FT_WORD *w1, FT_WORD *w2) { return mi_compare_text(cs, (uchar*) w1->pos, w1->len, @@ -49,14 +46,14 @@ static int walk_and_copy(FT_WORD *word,uint32 count,FT_DOCSTAT *docstat) /* transforms tree of words into the array, applying normalization */ -FT_WORD * ft_linearize(TREE *wtree) +FT_WORD * ft_linearize(TREE *wtree, MEM_ROOT *mem_root) { FT_WORD *wlist,*p; FT_DOCSTAT docstat; DBUG_ENTER("ft_linearize"); - if ((wlist=(FT_WORD *) my_malloc(sizeof(FT_WORD)* - (1+wtree->elements_in_tree),MYF(0)))) + if ((wlist=(FT_WORD *) alloc_root(mem_root, sizeof(FT_WORD)* + (1+wtree->elements_in_tree)))) { docstat.list=wlist; docstat.uniq=wtree->elements_in_tree; @@ -241,19 +238,20 @@ void ft_parse_init(TREE *wtree, CHARSET_INFO *cs) } -static int ft_add_word(void *param, byte *word, uint word_len, +static int ft_add_word(MYSQL_FTPARSER_PARAM *param, + char *word, int word_len, MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info __attribute__((unused))) { TREE *wtree; FT_WORD w; + MY_FT_PARSER_PARAM *ft_param=param->mysql_ftparam; DBUG_ENTER("ft_add_word"); - wtree= ((MY_FT_PARSER_PARAM *)param)->wtree; - if (((MY_FT_PARSER_PARAM *)param)->with_alloc) + wtree= ft_param->wtree; + if (param->flags & MYSQL_FTFLAGS_NEED_COPY) { byte *ptr; - /* allocating the data in the tree - to avoid mallocs and frees */ DBUG_ASSERT(wtree->with_delete == 0); - ptr= (byte *)alloc_root(&wtree->mem_root, word_len); + ptr= (byte *)alloc_root(ft_param->mem_root, word_len); memcpy(ptr, word, word_len); w.pos= ptr; } @@ -269,32 +267,32 @@ static int ft_add_word(void *param, byte *word, uint word_len, } -static int ft_parse_internal(void *param, byte *doc, int doc_len) +static int ft_parse_internal(MYSQL_FTPARSER_PARAM *param, + byte *doc, int doc_len) { byte *end=doc+doc_len; - MY_FT_PARSER_PARAM *ft_param=(MY_FT_PARSER_PARAM *)param; + MY_FT_PARSER_PARAM *ft_param=param->mysql_ftparam; TREE *wtree= ft_param->wtree; FT_WORD w; DBUG_ENTER("ft_parse_internal"); while (ft_simple_get_word(wtree->custom_arg, &doc, end, &w, TRUE)) - if (ft_param->up->mysql_add_word(param, w.pos, w.len, 0)) + if (param->mysql_add_word(param, w.pos, w.len, 0)) DBUG_RETURN(1); DBUG_RETURN(0); } -int ft_parse(TREE *wtree, byte *doc, int doclen, my_bool with_alloc, +int ft_parse(TREE *wtree, byte *doc, int doclen, struct st_mysql_ftparser *parser, - MYSQL_FTPARSER_PARAM *param) + MYSQL_FTPARSER_PARAM *param, MEM_ROOT *mem_root) { MY_FT_PARSER_PARAM my_param; DBUG_ENTER("ft_parse"); DBUG_ASSERT(parser); - my_param.up= param; my_param.wtree= wtree; - my_param.with_alloc= with_alloc; + my_param.mem_root= mem_root; param->mysql_parse= ft_parse_internal; param->mysql_add_word= ft_add_word; @@ -356,6 +354,7 @@ MYSQL_FTPARSER_PARAM *ftparser_call_initializer(MI_INFO *info, info->ftparser_param= (MYSQL_FTPARSER_PARAM *) my_malloc(MAX_PARAM_NR * sizeof(MYSQL_FTPARSER_PARAM) * info->s->ftparsers, MYF(MY_WME|MY_ZEROFILL)); + init_alloc_root(&info->ft_memroot, FTPARSER_MEMROOT_ALLOC_SIZE, 0); if (! info->ftparser_param) return 0; } @@ -387,6 +386,7 @@ MYSQL_FTPARSER_PARAM *ftparser_call_initializer(MI_INFO *info, void ftparser_call_deinitializer(MI_INFO *info) { uint i, j, keys= info->s->state.header.keys; + free_root(&info->ft_memroot, MYF(0)); if (! info->ftparser_param) return; for (i= 0; i < keys; i++) diff --git a/storage/myisam/ft_static.c b/storage/myisam/ft_static.c index 6cfb0d59e62..61bb7b3c1f7 100644 --- a/storage/myisam/ft_static.c +++ b/storage/myisam/ft_static.c @@ -629,7 +629,7 @@ const char *ft_precompiled_stopwords[] = { static int ft_default_parser_parse(MYSQL_FTPARSER_PARAM *param) { - return param->mysql_parse(param->mysql_ftparam, param->doc, param->length); + return param->mysql_parse(param, param->doc, param->length); } struct st_mysql_ftparser ft_default_parser= diff --git a/storage/myisam/ft_update.c b/storage/myisam/ft_update.c index f5501792dcd..08d605dbcc2 100644 --- a/storage/myisam/ft_update.c +++ b/storage/myisam/ft_update.c @@ -77,7 +77,7 @@ uint _mi_ft_segiterator(register FT_SEG_ITERATOR *ftsi) { uint pack_length= (ftsi->seg->bit_start); ftsi->len= (pack_length == 1 ? (uint) *(uchar*) ftsi->pos : - uint2korr(ftsi->pos)); + uint2korr(ftsi->pos)); ftsi->pos+= pack_length; /* Skip VARCHAR length */ DBUG_RETURN(1); } @@ -95,9 +95,8 @@ uint _mi_ft_segiterator(register FT_SEG_ITERATOR *ftsi) /* parses a document i.e. calls ft_parse for every keyseg */ -uint _mi_ft_parse(TREE *parsed, MI_INFO *info, uint keynr, - const byte *record, my_bool with_alloc, - MYSQL_FTPARSER_PARAM *param) +uint _mi_ft_parse(TREE *parsed, MI_INFO *info, uint keynr, const byte *record, + MYSQL_FTPARSER_PARAM *param, MEM_ROOT *mem_root) { FT_SEG_ITERATOR ftsi; struct st_mysql_ftparser *parser; @@ -110,14 +109,14 @@ uint _mi_ft_parse(TREE *parsed, MI_INFO *info, uint keynr, while (_mi_ft_segiterator(&ftsi)) { if (ftsi.pos) - if (ft_parse(parsed, (byte *)ftsi.pos, ftsi.len, with_alloc, parser, - param)) + if (ft_parse(parsed, (byte *)ftsi.pos, ftsi.len, parser, param, mem_root)) DBUG_RETURN(1); } DBUG_RETURN(0); } -FT_WORD * _mi_ft_parserecord(MI_INFO *info, uint keynr, const byte *record) +FT_WORD *_mi_ft_parserecord(MI_INFO *info, uint keynr, const byte *record, + MEM_ROOT *mem_root) { TREE ptree; MYSQL_FTPARSER_PARAM *param; @@ -125,10 +124,11 @@ FT_WORD * _mi_ft_parserecord(MI_INFO *info, uint keynr, const byte *record) if (! (param= ftparser_call_initializer(info, keynr, 0))) DBUG_RETURN(NULL); bzero((char*) &ptree, sizeof(ptree)); - if (_mi_ft_parse(&ptree, info, keynr, record, 0, param)) + param->flags= 0; + if (_mi_ft_parse(&ptree, info, keynr, record, param, mem_root)) DBUG_RETURN(NULL); - DBUG_RETURN(ft_linearize(&ptree)); + DBUG_RETURN(ft_linearize(&ptree, mem_root)); } static int _mi_ft_store(MI_INFO *info, uint keynr, byte *keybuf, @@ -206,10 +206,11 @@ int _mi_ft_update(MI_INFO *info, uint keynr, byte *keybuf, int cmp, cmp2; DBUG_ENTER("_mi_ft_update"); - if (!(old_word=oldlist=_mi_ft_parserecord(info, keynr, oldrec))) - goto err0; - if (!(new_word=newlist=_mi_ft_parserecord(info, keynr, newrec))) - goto err1; + if (!(old_word=oldlist=_mi_ft_parserecord(info, keynr, oldrec, + &info->ft_memroot)) || + !(new_word=newlist=_mi_ft_parserecord(info, keynr, newrec, + &info->ft_memroot))) + goto err; error=0; while(old_word->pos && new_word->pos) @@ -222,13 +223,13 @@ int _mi_ft_update(MI_INFO *info, uint keynr, byte *keybuf, { key_length=_ft_make_key(info,keynr,keybuf,old_word,pos); if ((error=_mi_ck_delete(info,keynr,(uchar*) keybuf,key_length))) - goto err2; + goto err; } if (cmp > 0 || cmp2) { key_length=_ft_make_key(info,keynr,keybuf,new_word,pos); if ((error=_mi_ck_write(info,keynr,(uchar*) keybuf,key_length))) - goto err2; + goto err; } if (cmp<=0) old_word++; if (cmp>=0) new_word++; @@ -238,11 +239,8 @@ int _mi_ft_update(MI_INFO *info, uint keynr, byte *keybuf, else if (new_word->pos) error=_mi_ft_store(info,keynr,keybuf,new_word,pos); -err2: - my_free((char*) newlist,MYF(0)); -err1: - my_free((char*) oldlist,MYF(0)); -err0: +err: + free_root(&info->ft_memroot, MYF(MY_MARK_BLOCKS_FREE)); DBUG_RETURN(error); } @@ -255,12 +253,13 @@ int _mi_ft_add(MI_INFO *info, uint keynr, byte *keybuf, const byte *record, int error= -1; FT_WORD *wlist; DBUG_ENTER("_mi_ft_add"); + DBUG_PRINT("enter",("keynr: %d",keynr)); - if ((wlist=_mi_ft_parserecord(info, keynr, record))) - { + if ((wlist=_mi_ft_parserecord(info, keynr, record, &info->ft_memroot))) error=_mi_ft_store(info,keynr,keybuf,wlist,pos); - my_free((char*) wlist,MYF(0)); - } + + free_root(&info->ft_memroot, MYF(MY_MARK_BLOCKS_FREE)); + DBUG_PRINT("exit",("Return: %d",error)); DBUG_RETURN(error); } @@ -275,11 +274,10 @@ int _mi_ft_del(MI_INFO *info, uint keynr, byte *keybuf, const byte *record, DBUG_ENTER("_mi_ft_del"); DBUG_PRINT("enter",("keynr: %d",keynr)); - if ((wlist=_mi_ft_parserecord(info, keynr, record))) - { + if ((wlist=_mi_ft_parserecord(info, keynr, record, &info->ft_memroot))) error=_mi_ft_erase(info,keynr,keybuf,wlist,pos); - my_free((char*) wlist,MYF(0)); - } + + free_root(&info->ft_memroot, MYF(MY_MARK_BLOCKS_FREE)); DBUG_PRINT("exit",("Return: %d",error)); DBUG_RETURN(error); } diff --git a/storage/myisam/ftdefs.h b/storage/myisam/ftdefs.h index 2c4cfa1ffd6..108faf4f1a3 100644 --- a/storage/myisam/ftdefs.h +++ b/storage/myisam/ftdefs.h @@ -30,6 +30,8 @@ #define FT_MAX_WORD_LEN_FOR_SORT 31 +#define FTPARSER_MEMROOT_ALLOC_SIZE 65536 + #define COMPILE_STOPWORDS_IN /* Interested readers may consult SMART @@ -119,12 +121,12 @@ void _mi_ft_segiterator_dummy_init(const byte *, uint, FT_SEG_ITERATOR *); uint _mi_ft_segiterator(FT_SEG_ITERATOR *); void ft_parse_init(TREE *, CHARSET_INFO *); -int ft_parse(TREE *, byte *, int, my_bool, struct st_mysql_ftparser *parser, - MYSQL_FTPARSER_PARAM *param); -FT_WORD * ft_linearize(TREE *); -FT_WORD * _mi_ft_parserecord(MI_INFO *, uint, const byte *); -uint _mi_ft_parse(TREE *, MI_INFO *, uint, const byte *, my_bool, - MYSQL_FTPARSER_PARAM *param); +int ft_parse(TREE *, byte *, int, struct st_mysql_ftparser *parser, + MYSQL_FTPARSER_PARAM *, MEM_ROOT *); +FT_WORD * ft_linearize(TREE *, MEM_ROOT *); +FT_WORD * _mi_ft_parserecord(MI_INFO *, uint, const byte *, MEM_ROOT *); +uint _mi_ft_parse(TREE *, MI_INFO *, uint, const byte *, + MYSQL_FTPARSER_PARAM *, MEM_ROOT *); FT_INFO *ft_init_nlq_search(MI_INFO *, uint, byte *, uint, uint, byte *); FT_INFO *ft_init_boolean_search(MI_INFO *, uint, byte *, uint, CHARSET_INFO *); diff --git a/storage/myisam/mi_check.c b/storage/myisam/mi_check.c index 0fa095a21db..ef7b1e6fde3 100644 --- a/storage/myisam/mi_check.c +++ b/storage/myisam/mi_check.c @@ -2117,6 +2117,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, my_seek(param->read_cache.file,0L,MY_SEEK_END,MYF(0)); sort_param.wordlist=NULL; + init_alloc_root(&sort_param.wordroot, FTPARSER_MEMROOT_ALLOC_SIZE, 0); if (share->data_file_type == DYNAMIC_RECORD) length=max(share->base.min_pack_length+1,share->base.min_block_length); @@ -2179,12 +2180,36 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, { uint ft_max_word_len_for_sort=FT_MAX_WORD_LEN_FOR_SORT* sort_param.keyinfo->seg->charset->mbmaxlen; - sort_info.max_records= - (ha_rows) (sort_info.filelength/ft_min_word_len+1); + sort_param.key_length+=ft_max_word_len_for_sort-HA_FT_MAXBYTELEN; + /* + fulltext indexes may have much more entries than the + number of rows in the table. We estimate the number here. + + Note, built-in parser is always nr. 0 - see ftparser_call_initializer() + */ + if (sort_param.keyinfo->ftparser_nr == 0) + { + /* + for built-in parser the number of generated index entries + cannot be larger than the size of the data file divided + by the minimal word's length + */ + sort_info.max_records= + (ha_rows) (sort_info.filelength/ft_min_word_len+1); + } + else + { + /* + for external plugin parser we cannot tell anything at all :( + so, we'll use all the sort memory and start from ~10 buffpeks. + (see _create_index_by_sort) + */ + sort_info.max_records= + 10*param->sort_buffer_length/sort_param.key_length; + } sort_param.key_read=sort_ft_key_read; sort_param.key_write=sort_ft_key_write; - sort_param.key_length+=ft_max_word_len_for_sort-HA_FT_MAXBYTELEN; } else { @@ -2200,6 +2225,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, goto err; } param->calc_checksum=0; /* No need to calc glob_crc */ + free_root(&sort_param.wordroot, MYF(0)); /* Set for next loop */ sort_info.max_records= (ha_rows) info->state->records; @@ -2589,6 +2615,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, uint ft_max_word_len_for_sort=FT_MAX_WORD_LEN_FOR_SORT* sort_param[i].keyinfo->seg->charset->mbmaxlen; sort_param[i].key_length+=ft_max_word_len_for_sort-HA_FT_MAXBYTELEN; + init_alloc_root(&sort_param[i].wordroot, FTPARSER_MEMROOT_ALLOC_SIZE, 0); } } sort_info.total_keys=i; @@ -2810,10 +2837,11 @@ static int sort_ft_key_read(MI_SORT_PARAM *sort_param, void *key) { for (;;) { - my_free((char*) wptr, MYF(MY_ALLOW_ZERO_PTR)); + free_root(&sort_param->wordroot, MYF(MY_MARK_BLOCKS_FREE)); if ((error=sort_get_next_record(sort_param))) DBUG_RETURN(error); - if (!(wptr=_mi_ft_parserecord(info,sort_param->key,sort_param->record))) + if (!(wptr=_mi_ft_parserecord(info,sort_param->key,sort_param->record, + &sort_param->wordroot))) DBUG_RETURN(1); if (wptr->pos) break; @@ -2837,7 +2865,7 @@ static int sort_ft_key_read(MI_SORT_PARAM *sort_param, void *key) #endif if (!wptr->pos) { - my_free((char*) sort_param->wordlist, MYF(0)); + free_root(&sort_param->wordroot, MYF(MY_MARK_BLOCKS_FREE)); sort_param->wordlist=0; error=sort_write_record(sort_param); } diff --git a/storage/myisam/myisamdef.h b/storage/myisam/myisamdef.h index 0b450de9c03..a83fbe8f759 100644 --- a/storage/myisam/myisamdef.h +++ b/storage/myisam/myisamdef.h @@ -235,13 +235,14 @@ struct st_myisam_info { /* accumulate indexfile changes between write's */ TREE *bulk_insert; DYNAMIC_ARRAY *ft1_to_ft2; /* used only in ft1->ft2 conversion */ - MYSQL_FTPARSER_PARAM *ftparser_param; /* share info between init/deinit */ - char *filename; /* parameter to open filename */ - uchar *buff, /* Temp area for key */ - *lastkey,*lastkey2; /* Last used search key */ - uchar *first_mbr_key; /* Searhed spatial key */ - byte *rec_buff; /* Tempbuff for recordpack */ - uchar *int_keypos, /* Save position for next/previous */ + MEM_ROOT ft_memroot; /* used by the parser */ + MYSQL_FTPARSER_PARAM *ftparser_param; /* share info between init/deinit */ + char *filename; /* parameter to open filename */ + uchar *buff, /* Temp area for key */ + *lastkey,*lastkey2; /* Last used search key */ + uchar *first_mbr_key; /* Searhed spatial key */ + byte *rec_buff; /* Tempbuff for recordpack */ + uchar *int_keypos, /* Save position for next/previous */ *int_maxpos; /* -""- */ uint int_nod_flag; /* -""- */ uint32 int_keytree_version; /* -""- */ @@ -325,6 +326,7 @@ typedef struct st_mi_sort_param uchar **sort_keys; byte *rec_buff; void *wordlist, *wordptr; + MEM_ROOT wordroot; char *record; MY_TMPDIR *tmpdir; int (*key_cmp)(struct st_mi_sort_param *, const void *, const void *); diff --git a/storage/myisam/sort.c b/storage/myisam/sort.c index c9562461f56..44e7e8b464e 100644 --- a/storage/myisam/sort.c +++ b/storage/myisam/sort.c @@ -447,6 +447,7 @@ err: close_cached_file(&info->tempfile_for_exceptions); ok: + free_root(&info->wordroot, MYF(0)); remove_io_thread(&info->read_cache); pthread_mutex_lock(&info->sort_info->mutex); info->sort_info->threads_running--; diff --git a/storage/myisammrg/cmakelists.txt b/storage/myisammrg/CMakeLists.txt index 83168f6c60c..83168f6c60c 100644 --- a/storage/myisammrg/cmakelists.txt +++ b/storage/myisammrg/CMakeLists.txt diff --git a/storage/myisammrg/Makefile.am b/storage/myisammrg/Makefile.am index 0719780b366..0402f2730b9 100644 --- a/storage/myisammrg/Makefile.am +++ b/storage/myisammrg/Makefile.am @@ -23,7 +23,7 @@ libmyisammrg_a_SOURCES = myrg_open.c myrg_extra.c myrg_info.c myrg_locking.c \ myrg_rkey.c myrg_rfirst.c myrg_rlast.c myrg_rnext.c \ myrg_rprev.c myrg_queue.c myrg_write.c myrg_range.c \ myrg_rnext_same.c -EXTRA_DIST = cmakelists.txt +EXTRA_DIST = CMakeLists.txt # Don't update the files from bitkeeper %::SCCS/s.% diff --git a/storage/ndb/include/mgmapi/mgmapi.h b/storage/ndb/include/mgmapi/mgmapi.h index 4585e78029a..5a0ffcfe2c6 100644 --- a/storage/ndb/include/mgmapi/mgmapi.h +++ b/storage/ndb/include/mgmapi/mgmapi.h @@ -849,16 +849,6 @@ extern "C" { enum ndb_mgm_event_category category, int level, struct ndb_mgm_reply* reply); - - /** - * Returns the port number where statistics information is sent - * - * @param handle NDB management handle. - * @param reply Reply message. - * @return -1 on error. - */ - int ndb_mgm_get_stat_port(NdbMgmHandle handle, - struct ndb_mgm_reply* reply); #endif /** diff --git a/storage/ndb/include/ndbapi/Ndb.hpp b/storage/ndb/include/ndbapi/Ndb.hpp index 010b85b03a9..c5f699dfd7d 100644 --- a/storage/ndb/include/ndbapi/Ndb.hpp +++ b/storage/ndb/include/ndbapi/Ndb.hpp @@ -986,6 +986,7 @@ class NdbBlob; class NdbReceiver; class TransporterFacade; class PollGuard; +class Ndb_local_table_info; template <class T> struct Ndb_free_list_t; typedef void (* NdbEventCallback)(NdbEventOperation*, Ndb*, void*); @@ -1001,6 +1002,9 @@ typedef void (* NdbEventCallback)(NdbEventOperation*, Ndb*, void*); #define WAITFOR_RESPONSE_TIMEOUT 120000 // Milliseconds #endif +#define NDB_SYSTEM_DATABASE "sys" +#define NDB_SYSTEM_SCHEMA "def" + /** * @class Ndb * @brief Represents the NDB kernel and is the main class of the NDB API. @@ -1262,6 +1266,7 @@ public: #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL + int flushIncompleteEvents(Uint64 gci); NdbEventOperation *getEventOperation(NdbEventOperation* eventOp= 0); Uint64 getLatestGCI(); void forceGCP(); @@ -1462,35 +1467,58 @@ public: /** * Return a unique tuple id for a table. The id sequence is - * ascending but may contain gaps. + * ascending but may contain gaps. Methods which have no + * TupleIdRange argument use NDB API dict cache. They may + * not be called from mysqld. * * @param aTableName table name * * @param cacheSize number of values to cache in this Ndb object * - * @return tuple id or 0 on error + * @return 0 or -1 on error, and tupleId in out parameter */ + struct TupleIdRange { + Uint64 m_first_tuple_id; + Uint64 m_last_tuple_id; + void reset() { + m_first_tuple_id = ~(Uint64)0; + m_last_tuple_id = ~(Uint64)0; + }; + }; + int initAutoIncrement(); - Uint64 getAutoIncrementValue(const char* aTableName, - Uint32 cacheSize = 1); - Uint64 getAutoIncrementValue(const NdbDictionary::Table * aTable, - Uint32 cacheSize = 1); - Uint64 readAutoIncrementValue(const char* aTableName); - Uint64 readAutoIncrementValue(const NdbDictionary::Table * aTable); - bool setAutoIncrementValue(const char* aTableName, Uint64 val, - bool increase = false); - bool setAutoIncrementValue(const NdbDictionary::Table * aTable, Uint64 val, - bool increase = false); - Uint64 getTupleIdFromNdb(const char* aTableName, - Uint32 cacheSize = 1000); - Uint64 getTupleIdFromNdb(Uint32 aTableId, - Uint32 cacheSize = 1000); - Uint64 readTupleIdFromNdb(Uint32 aTableId); - bool setTupleIdInNdb(const char* aTableName, Uint64 val, - bool increase); - bool setTupleIdInNdb(Uint32 aTableId, Uint64 val, bool increase); - Uint64 opTupleIdOnNdb(Uint32 aTableId, Uint64 opValue, Uint32 op); + int getAutoIncrementValue(const char* aTableName, + Uint64 & tupleId, Uint32 cacheSize); + int getAutoIncrementValue(const NdbDictionary::Table * aTable, + Uint64 & tupleId, Uint32 cacheSize); + int getAutoIncrementValue(const NdbDictionary::Table * aTable, + TupleIdRange & range, Uint64 & tupleId, + Uint32 cacheSize); + int readAutoIncrementValue(const char* aTableName, + Uint64 & tupleId); + int readAutoIncrementValue(const NdbDictionary::Table * aTable, + Uint64 & tupleId); + int readAutoIncrementValue(const NdbDictionary::Table * aTable, + TupleIdRange & range, Uint64 & tupleId); + int setAutoIncrementValue(const char* aTableName, + Uint64 tupleId, bool increase); + int setAutoIncrementValue(const NdbDictionary::Table * aTable, + Uint64 tupleId, bool increase); + int setAutoIncrementValue(const NdbDictionary::Table * aTable, + TupleIdRange & range, Uint64 tupleId, + bool increase); +private: + int getTupleIdFromNdb(const NdbTableImpl* table, + TupleIdRange & range, Uint64 & tupleId, + Uint32 cacheSize); + int readTupleIdFromNdb(const NdbTableImpl* table, + TupleIdRange & range, Uint64 & tupleId); + int setTupleIdInNdb(const NdbTableImpl* table, + TupleIdRange & range, Uint64 tupleId, bool increase); + int opTupleIdOnNdb(const NdbTableImpl* table, + TupleIdRange & range, Uint64 & opValue, Uint32 op); +public: /** */ @@ -1647,6 +1675,8 @@ private: const char * externalizeIndexName(const char * internalIndexName, bool fullyQualifiedNames); const char * externalizeIndexName(const char * internalIndexName); + const BaseString old_internalize_index_name(const NdbTableImpl * table, + const char * external_name) const; const BaseString internalize_index_name(const NdbTableImpl * table, const char * external_name) const; @@ -1693,12 +1723,8 @@ private: Uint64 the_last_check_time; Uint64 theFirstTransId; - - // The tupleId is retreived from DB the - // tupleId is unique for each tableid. + // The tupleId is retrieved from DB const NdbDictionary::Table *m_sys_tab_0; - Uint64 theFirstTupleId[2048]; - Uint64 theLastTupleId[2048]; Uint32 theRestartGCI; // the Restart GCI used by DIHNDBTAMPER diff --git a/storage/ndb/include/ndbapi/NdbDictionary.hpp b/storage/ndb/include/ndbapi/NdbDictionary.hpp index b31e2551e89..27e0aede36d 100644 --- a/storage/ndb/include/ndbapi/NdbDictionary.hpp +++ b/storage/ndb/include/ndbapi/NdbDictionary.hpp @@ -1132,7 +1132,8 @@ public: _TE_NODE_FAILURE=10, _TE_SUBSCRIBE=11, _TE_UNSUBSCRIBE=12, - _TE_NUL=13 // internal (e.g. INS o DEL within same GCI) + _TE_NUL=13, // internal (e.g. INS o DEL within same GCI) + _TE_ACTIVE=14 // internal (node becomes active) }; #endif /** @@ -1634,6 +1635,16 @@ public: int listIndexes(List & list, const char * tableName); int listIndexes(List & list, const char * tableName) const; +#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL + /** + * Fetch list of indexes of given table. + * @param list Reference to list where to store the listed indexes + * @param table Reference to table that index belongs to. + * @return 0 if successful, otherwise -1 + */ + int listIndexes(List & list, const Table &table) const; +#endif + /** @} *******************************************************************/ /** * @name Events diff --git a/storage/ndb/include/ndbapi/NdbOperation.hpp b/storage/ndb/include/ndbapi/NdbOperation.hpp index e747dedb84b..d64e86c3136 100644 --- a/storage/ndb/include/ndbapi/NdbOperation.hpp +++ b/storage/ndb/include/ndbapi/NdbOperation.hpp @@ -636,6 +636,10 @@ public: bool nopad, Uint32 Label); int branch_col_ge(Uint32 ColId, const void * val, Uint32 len, bool nopad, Uint32 Label); + /** + * The argument is always plain char, even if the field is varchar + * (changed in 5.0.22). + */ int branch_col_like(Uint32 ColId, const void *, Uint32 len, bool nopad, Uint32 Label); int branch_col_notlike(Uint32 ColId, const void *, Uint32 len, diff --git a/storage/ndb/include/ndbapi/ndb_cluster_connection.hpp b/storage/ndb/include/ndbapi/ndb_cluster_connection.hpp index 01c700d14b2..a803d010e61 100644 --- a/storage/ndb/include/ndbapi/ndb_cluster_connection.hpp +++ b/storage/ndb/include/ndbapi/ndb_cluster_connection.hpp @@ -110,6 +110,7 @@ public: unsigned no_db_nodes(); unsigned node_id(); + unsigned get_connect_count() const; void init_get_next_node(Ndb_cluster_connection_node_iter &iter); unsigned int get_next_node(Ndb_cluster_connection_node_iter &iter); diff --git a/storage/ndb/include/util/NdbSqlUtil.hpp b/storage/ndb/include/util/NdbSqlUtil.hpp index 36a75136c45..ff2d9766f81 100644 --- a/storage/ndb/include/util/NdbSqlUtil.hpp +++ b/storage/ndb/include/util/NdbSqlUtil.hpp @@ -45,14 +45,11 @@ public: typedef int Cmp(const void* info, const void* p1, unsigned n1, const void* p2, unsigned n2, bool full); /** - * Prototype for "like" comparison. Defined for string types. Second - * argument must have same type-specific format. Returns 0 on match, - * +1 on no match, and -1 on bad data. + * Prototype for "like" comparison. Defined for string types. First + * argument can be fixed or var* type, second argument is fixed. + * Returns 0 on match, +1 on no match, and -1 on bad data. * * Uses default special chars ( \ % _ ). - * - * TODO convert special chars to the cs so that ucs2 etc works - * TODO allow user-defined escape ( \ ) */ typedef int Like(const void* info, const void* p1, unsigned n1, const void* p2, unsigned n2); diff --git a/storage/ndb/include/util/SocketServer.hpp b/storage/ndb/include/util/SocketServer.hpp index e766a0b99c4..c4f7e8c0ade 100644 --- a/storage/ndb/include/util/SocketServer.hpp +++ b/storage/ndb/include/util/SocketServer.hpp @@ -106,7 +106,8 @@ public: void stopSessions(bool wait = false); void foreachSession(void (*f)(Session*, void*), void *data); - + void checkSessions(); + private: struct SessionInstance { Service * m_service; @@ -117,12 +118,13 @@ private: Service * m_service; NDB_SOCKET_TYPE m_socket; }; - MutexVector<SessionInstance> m_sessions; + NdbLockable m_session_mutex; + Vector<SessionInstance> m_sessions; MutexVector<ServiceInstance> m_services; unsigned m_maxSessions; void doAccept(); - void checkSessions(); + void checkSessionsImpl(); void startSession(SessionInstance &); /** diff --git a/storage/ndb/src/common/util/NdbSqlUtil.cpp b/storage/ndb/src/common/util/NdbSqlUtil.cpp index f2506eda6d4..f3d70a5734a 100644 --- a/storage/ndb/src/common/util/NdbSqlUtil.cpp +++ b/storage/ndb/src/common/util/NdbSqlUtil.cpp @@ -805,7 +805,9 @@ NdbSqlUtil::likeChar(const void* info, const void* p1, unsigned n1, const void* const char* v1 = (const char*)p1; const char* v2 = (const char*)p2; CHARSET_INFO* cs = (CHARSET_INFO*)(info); - int k = (cs->coll->wildcmp)(cs, v1, v1 + n1, v2, v2 + n2, ndb_wild_prefix, ndb_wild_one, ndb_wild_many); + // strip end spaces to match (incorrect) MySQL behaviour + n1 = (*cs->cset->lengthsp)(cs, v1, n1); + int k = (*cs->coll->wildcmp)(cs, v1, v1 + n1, v2, v2 + n2, ndb_wild_prefix, ndb_wild_one, ndb_wild_many); return k == 0 ? 0 : +1; } @@ -820,16 +822,16 @@ int NdbSqlUtil::likeVarchar(const void* info, const void* p1, unsigned n1, const void* p2, unsigned n2) { const unsigned lb = 1; - if (n1 >= lb && n2 >= lb) { + if (n1 >= lb) { const uchar* v1 = (const uchar*)p1; const uchar* v2 = (const uchar*)p2; unsigned m1 = *v1; - unsigned m2 = *v2; - if (lb + m1 <= n1 && lb + m2 <= n2) { + unsigned m2 = n2; + if (lb + m1 <= n1) { const char* w1 = (const char*)v1 + lb; - const char* w2 = (const char*)v2 + lb; + const char* w2 = (const char*)v2; CHARSET_INFO* cs = (CHARSET_INFO*)(info); - int k = (cs->coll->wildcmp)(cs, w1, w1 + m1, w2, w2 + m2, ndb_wild_prefix, ndb_wild_one, ndb_wild_many); + int k = (*cs->coll->wildcmp)(cs, w1, w1 + m1, w2, w2 + m2, ndb_wild_prefix, ndb_wild_one, ndb_wild_many); return k == 0 ? 0 : +1; } } @@ -847,16 +849,16 @@ int NdbSqlUtil::likeLongvarchar(const void* info, const void* p1, unsigned n1, const void* p2, unsigned n2) { const unsigned lb = 2; - if (n1 >= lb && n2 >= lb) { + if (n1 >= lb) { const uchar* v1 = (const uchar*)p1; const uchar* v2 = (const uchar*)p2; unsigned m1 = uint2korr(v1); - unsigned m2 = uint2korr(v2); - if (lb + m1 <= n1 && lb + m2 <= n2) { + unsigned m2 = n2; + if (lb + m1 <= n1) { const char* w1 = (const char*)v1 + lb; - const char* w2 = (const char*)v2 + lb; + const char* w2 = (const char*)v2; CHARSET_INFO* cs = (CHARSET_INFO*)(info); - int k = (cs->coll->wildcmp)(cs, w1, w1 + m1, w2, w2 + m2, ndb_wild_prefix, ndb_wild_one, ndb_wild_many); + int k = (*cs->coll->wildcmp)(cs, w1, w1 + m1, w2, w2 + m2, ndb_wild_prefix, ndb_wild_one, ndb_wild_many); return k == 0 ? 0 : +1; } } diff --git a/storage/ndb/src/common/util/SocketServer.cpp b/storage/ndb/src/common/util/SocketServer.cpp index f0af925cf6d..f9d2c7463be 100644 --- a/storage/ndb/src/common/util/SocketServer.cpp +++ b/storage/ndb/src/common/util/SocketServer.cpp @@ -184,9 +184,12 @@ SocketServer::doAccept(){ SessionInstance s; s.m_service = si.m_service; s.m_session = si.m_service->newSession(childSock); - if(s.m_session != 0){ + if(s.m_session != 0) + { + m_session_mutex.lock(); m_sessions.push_back(s); startSession(m_sessions.back()); + m_session_mutex.unlock(); } continue; @@ -240,10 +243,13 @@ void SocketServer::doRun(){ while(!m_stopThread){ - checkSessions(); + m_session_mutex.lock(); + checkSessionsImpl(); if(m_sessions.size() < m_maxSessions){ + m_session_mutex.unlock(); doAccept(); } else { + m_session_mutex.unlock(); NdbSleep_MilliSleep(200); } } @@ -276,17 +282,30 @@ transfer(NDB_SOCKET_TYPE sock){ void SocketServer::foreachSession(void (*func)(SocketServer::Session*, void *), void *data) { + m_session_mutex.lock(); for(int i = m_sessions.size() - 1; i >= 0; i--){ (*func)(m_sessions[i].m_session, data); } - checkSessions(); + m_session_mutex.unlock(); } void -SocketServer::checkSessions(){ - for(int i = m_sessions.size() - 1; i >= 0; i--){ - if(m_sessions[i].m_session->m_stopped){ - if(m_sessions[i].m_thread != 0){ +SocketServer::checkSessions() +{ + m_session_mutex.lock(); + checkSessionsImpl(); + m_session_mutex.unlock(); +} + +void +SocketServer::checkSessionsImpl() +{ + for(int i = m_sessions.size() - 1; i >= 0; i--) + { + if(m_sessions[i].m_session->m_stopped) + { + if(m_sessions[i].m_thread != 0) + { void* ret; NdbThread_WaitFor(m_sessions[i].m_thread, &ret); NdbThread_Destroy(&m_sessions[i].m_thread); @@ -301,19 +320,26 @@ SocketServer::checkSessions(){ void SocketServer::stopSessions(bool wait){ int i; + m_session_mutex.lock(); for(i = m_sessions.size() - 1; i>=0; i--) { m_sessions[i].m_session->stopSession(); m_sessions[i].m_session->m_stop = true; // to make sure } + m_session_mutex.unlock(); + for(i = m_services.size() - 1; i>=0; i--) m_services[i].m_service->stopSessions(); if(wait){ + m_session_mutex.lock(); while(m_sessions.size() > 0){ - checkSessions(); + checkSessionsImpl(); + m_session_mutex.unlock(); NdbSleep_MilliSleep(100); + m_session_mutex.lock(); } + m_session_mutex.unlock(); } } @@ -348,4 +374,4 @@ sessionThread_C(void* _sc){ } template class MutexVector<SocketServer::ServiceInstance>; -template class MutexVector<SocketServer::SessionInstance>; +template class Vector<SocketServer::SessionInstance>; diff --git a/storage/ndb/src/common/util/socket_io.cpp b/storage/ndb/src/common/util/socket_io.cpp index 83a546de773..58636e6663d 100644 --- a/storage/ndb/src/common/util/socket_io.cpp +++ b/storage/ndb/src/common/util/socket_io.cpp @@ -48,58 +48,66 @@ read_socket(NDB_SOCKET_TYPE socket, int timeout_millis, extern "C" int -readln_socket(NDB_SOCKET_TYPE socket, int timeout_millis, +readln_socket(NDB_SOCKET_TYPE socket, int timeout_millis, char * buf, int buflen){ if(buflen <= 1) return 0; + int sock_flags= fcntl(socket, F_GETFL); + if(fcntl(socket, F_SETFL, sock_flags | O_NONBLOCK) == -1) + return -1; + fd_set readset; FD_ZERO(&readset); FD_SET(socket, &readset); - + struct timeval timeout; timeout.tv_sec = (timeout_millis / 1000); timeout.tv_usec = (timeout_millis % 1000) * 1000; const int selectRes = select(socket + 1, &readset, 0, 0, &timeout); - if(selectRes == 0) + if(selectRes == 0){ return 0; - + } + if(selectRes == -1){ + fcntl(socket, F_SETFL, sock_flags); return -1; } - - int pos = 0; buf[pos] = 0; - while(true){ - const int t = recv(socket, &buf[pos], 1, 0); - if(t != 1){ - return -1; - } - if(buf[pos] == '\n'){ - buf[pos] = 0; - if(pos > 0 && buf[pos-1] == '\r'){ - pos--; - buf[pos] = 0; + buf[0] = 0; + const int t = recv(socket, buf, buflen, MSG_PEEK); + + if(t < 1) + { + fcntl(socket, F_SETFL, sock_flags); + return -1; + } + + for(int i=0; i< t;i++) + { + if(buf[i] == '\n'){ + recv(socket, buf, i+1, 0); + buf[i] = 0; + + if(i > 0 && buf[i-1] == '\r'){ + i--; + buf[i] = 0; } - return pos; - } - pos++; - if(pos == (buflen - 1)){ - buf[pos] = 0; - return buflen; - } - - FD_ZERO(&readset); - FD_SET(socket, &readset); - timeout.tv_sec = (timeout_millis / 1000); - timeout.tv_usec = (timeout_millis % 1000) * 1000; - const int selectRes = select(socket + 1, &readset, 0, 0, &timeout); - if(selectRes != 1){ - return -1; + fcntl(socket, F_SETFL, sock_flags); + return t; } } + + if(t == (buflen - 1)){ + recv(socket, buf, t, 0); + buf[t] = 0; + fcntl(socket, F_SETFL, sock_flags); + return buflen; + } + + return 0; } extern "C" diff --git a/storage/ndb/src/kernel/blocks/ERROR_codes.txt b/storage/ndb/src/kernel/blocks/ERROR_codes.txt index 059c80a960d..d69faa90f72 100644 --- a/storage/ndb/src/kernel/blocks/ERROR_codes.txt +++ b/storage/ndb/src/kernel/blocks/ERROR_codes.txt @@ -63,6 +63,9 @@ Delay GCP_SAVEREQ by 10 secs 7165: Delay INCL_NODE_REQ in starting node yeilding error in GCP_PREPARE +7030: Delay in GCP_PREPARE until node has completed a node failure +7031: Delay in GCP_PREPARE and die 3s later + ERROR CODES FOR TESTING NODE FAILURE, LOCAL CHECKPOINT HANDLING: ----------------------------------------------------------------- diff --git a/storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp b/storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp index 9936217bbf3..bb4c2ed197e 100644 --- a/storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp +++ b/storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp @@ -5601,6 +5601,12 @@ Dbdih::checkLocalNodefailComplete(Signal* signal, Uint32 failedNodeId, return; } + if (ERROR_INSERTED(7030)) + { + ndbout_c("Reenable GCP_PREPARE"); + CLEAR_ERROR_INSERT_VALUE; + } + NFCompleteRep * const nf = (NFCompleteRep *)&signal->theData[0]; nf->blockNo = DBDIH; nf->nodeId = cownNodeId; @@ -7733,6 +7739,16 @@ void Dbdih::execGCP_PREPARE(Signal* signal) { jamEntry(); CRASH_INSERTION(7005); + + if (ERROR_INSERTED(7030)) + { + cgckptflag = true; + ndbout_c("Delayed GCP_PREPARE 5s"); + sendSignalWithDelay(reference(), GSN_GCP_PREPARE, signal, 5000, + signal->getLength()); + return; + } + Uint32 masterNodeId = signal->theData[0]; Uint32 gci = signal->theData[1]; BlockReference retRef = calcDihBlockRef(masterNodeId); @@ -7745,6 +7761,14 @@ void Dbdih::execGCP_PREPARE(Signal* signal) cgcpParticipantState = GCP_PARTICIPANT_PREPARE_RECEIVED; cnewgcp = gci; + if (ERROR_INSERTED(7031)) + { + ndbout_c("Crashing delayed in GCP_PREPARE 3s"); + signal->theData[0] = 9999; + sendSignalWithDelay(CMVMI_REF, GSN_NDB_TAMPER, signal, 3000, 1); + return; + } + signal->theData[0] = cownNodeId; signal->theData[1] = gci; sendSignal(retRef, GSN_GCP_PREPARECONF, signal, 2, JBA); diff --git a/storage/ndb/src/kernel/blocks/dbtc/DbtcInit.cpp b/storage/ndb/src/kernel/blocks/dbtc/DbtcInit.cpp index 5a9d6b9f053..8dee75398ed 100644 --- a/storage/ndb/src/kernel/blocks/dbtc/DbtcInit.cpp +++ b/storage/ndb/src/kernel/blocks/dbtc/DbtcInit.cpp @@ -179,7 +179,7 @@ Dbtc::Dbtc(Block_context& ctx): ndb_mgm_get_int_parameter(p, CFG_DB_TRANS_BUFFER_MEM, &transactionBufferMemory); - ndb_mgm_get_int_parameter(p, CFG_DB_NO_UNIQUE_HASH_INDEXES, + ndb_mgm_get_int_parameter(p, CFG_DICT_TABLE, &maxNoOfIndexes); ndb_mgm_get_int_parameter(p, CFG_DB_NO_INDEX_OPS, &maxNoOfConcurrentIndexOperations); diff --git a/storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp b/storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp index 0989807db4a..869ae116f43 100644 --- a/storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp +++ b/storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp @@ -7076,18 +7076,20 @@ Dbtc::nodeFailCheckTransactions(Signal* signal, { jam(); Ptr<ApiConnectRecord> transPtr; + Uint32 TtcTimer = ctcTimer; + Uint32 TapplTimeout = c_appl_timeout_value; for (transPtr.i = transPtrI; transPtr.i < capiConnectFilesize; transPtr.i++) { ptrCheckGuard(transPtr, capiConnectFilesize, apiConnectRecord); if (transPtr.p->m_transaction_nodes.get(failedNodeId)) { jam(); + // Force timeout regardless of state - Uint32 save = c_appl_timeout_value; c_appl_timeout_value = 1; - setApiConTimer(transPtr.i, 0, __LINE__); + setApiConTimer(transPtr.i, TtcTimer - 2, __LINE__); timeOutFoundLab(signal, transPtr.i, ZNODEFAIL_BEFORE_COMMIT); - c_appl_timeout_value = save; + c_appl_timeout_value = TapplTimeout; } // Send CONTINUEB to continue later diff --git a/storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp b/storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp index 90abe2cb809..1b6fef9de37 100644 --- a/storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp +++ b/storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp @@ -1926,6 +1926,7 @@ int Dbtup::interpreterNextLab(Signal* signal, // word read. Thus we set the register to be a 32 bit register. /* ------------------------------------------------------------- */ TregMemBuffer[theRegister]= 0x50; + // arithmetic conversion if big-endian * (Int64*)(TregMemBuffer+theRegister+2)= TregMemBuffer[theRegister+1]; } else if (TnoDataRW == 3) { @@ -1985,6 +1986,11 @@ int Dbtup::interpreterNextLab(Signal* signal, Tlen= TattrNoOfWords + 1; if (Toptype == ZUPDATE) { if (TattrNoOfWords <= 2) { + if (TattrNoOfWords == 1) { + // arithmetic conversion if big-endian + TdataForUpdate[1] = *(Int64*)&TregMemBuffer[theRegister + 2]; + TdataForUpdate[2] = 0; + } if (TregType == 0) { /* --------------------------------------------------------- */ // Write a NULL value into the attribute diff --git a/storage/ndb/src/kernel/blocks/ndbcntr/NdbcntrMain.cpp b/storage/ndb/src/kernel/blocks/ndbcntr/NdbcntrMain.cpp index b0372ec89a2..7c48ebb5e8b 100644 --- a/storage/ndb/src/kernel/blocks/ndbcntr/NdbcntrMain.cpp +++ b/storage/ndb/src/kernel/blocks/ndbcntr/NdbcntrMain.cpp @@ -1645,10 +1645,9 @@ void Ndbcntr::systemErrorLab(Signal* signal, int line) /* |-2048| # 1 00000001 | */ /* | : | : | */ /* | -1 | # 1 00000001 | */ -/* | 0 | 0 | */ -/* | 1 | 0 | */ -/* | : | : | */ -/* | 2047| 0 | */ +/* | 1 | 0 | tupleid sequence now created on first use */ +/* | : | : | v */ +/* | 2048| 0 | v */ /*---------------------------------------------------------------------------*/ void Ndbcntr::createSystableLab(Signal* signal, unsigned index) { @@ -1859,8 +1858,7 @@ void Ndbcntr::crSystab8Lab(Signal* signal) jam(); ckey = 1; ctransidPhase = ZFALSE; - crSystab7Lab(signal); - return; + // skip 2nd loop - tupleid sequence now created on first use }//if signal->theData[0] = ctcConnectionP; signal->theData[1] = reference(); diff --git a/storage/ndb/src/kernel/blocks/qmgr/QmgrMain.cpp b/storage/ndb/src/kernel/blocks/qmgr/QmgrMain.cpp index 8772e00f027..4d5ac377a5a 100644 --- a/storage/ndb/src/kernel/blocks/qmgr/QmgrMain.cpp +++ b/storage/ndb/src/kernel/blocks/qmgr/QmgrMain.cpp @@ -827,7 +827,7 @@ void Qmgr::execCM_REGCONF(Signal* signal) ptrCheckGuard(myNodePtr, MAX_NDB_NODES, nodeRec); ndbrequire(c_start.m_gsn == GSN_CM_REGREQ); - ndbrequire(myNodePtr.p->phase = ZSTARTING); + ndbrequire(myNodePtr.p->phase == ZSTARTING); cpdistref = cmRegConf->presidentBlockRef; cpresident = cmRegConf->presidentNodeId; diff --git a/storage/ndb/src/kernel/blocks/suma/Suma.cpp b/storage/ndb/src/kernel/blocks/suma/Suma.cpp index 867b13e1e40..91f0fab06f8 100644 --- a/storage/ndb/src/kernel/blocks/suma/Suma.cpp +++ b/storage/ndb/src/kernel/blocks/suma/Suma.cpp @@ -2649,6 +2649,22 @@ Suma::reportAllSubscribers(Signal *signal, SubscriptionPtr subPtr, SubscriberPtr subbPtr) { + SubTableData * data = (SubTableData*)signal->getDataPtrSend(); + + if (table_event == NdbDictionary::Event::_TE_SUBSCRIBE) + { + data->gci = m_last_complete_gci + 1; + data->tableId = subPtr.p->m_tableId; + data->operation = NdbDictionary::Event::_TE_ACTIVE; + data->ndbd_nodeid = refToNode(reference()); + data->changeMask = 0; + data->totalLen = 0; + data->req_nodeid = refToNode(subbPtr.p->m_senderRef); + data->senderData = subbPtr.p->m_senderData; + sendSignal(subbPtr.p->m_senderRef, GSN_SUB_TABLE_DATA, signal, + SubTableData::SignalLength, JBB); + } + if (!(subPtr.p->m_options & Subscription::REPORT_SUBSCRIBE)) { return; @@ -2663,7 +2679,6 @@ Suma::reportAllSubscribers(Signal *signal, ndbout_c("reportAllSubscribers subPtr.i: %d subPtr.p->n_subscribers: %d", subPtr.i, subPtr.p->n_subscribers); //#endif - SubTableData * data = (SubTableData*)signal->getDataPtrSend(); data->gci = m_last_complete_gci + 1; data->tableId = subPtr.p->m_tableId; data->operation = table_event; diff --git a/storage/ndb/src/kernel/vm/Configuration.cpp b/storage/ndb/src/kernel/vm/Configuration.cpp index e0e414e5669..12badffe0e0 100644 --- a/storage/ndb/src/kernel/vm/Configuration.cpp +++ b/storage/ndb/src/kernel/vm/Configuration.cpp @@ -49,7 +49,9 @@ extern EventLogger g_eventLogger; enum ndbd_options { OPT_INITIAL = NDB_STD_OPTIONS_LAST, OPT_NODAEMON, - OPT_FOREGROUND + OPT_FOREGROUND, + OPT_NOWAIT_NODES, + OPT_INITIAL_START }; NDB_STD_OPTS_VARS; @@ -88,11 +90,11 @@ static struct my_option my_long_options[] = " (implies --nodaemon)", (gptr*) &_foreground, (gptr*) &_foreground, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, - { "nowait-nodes", NO_ARG, + { "nowait-nodes", OPT_NOWAIT_NODES, "Nodes that will not be waited for during start", (gptr*) &_nowait_nodes, (gptr*) &_nowait_nodes, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, - { "initial-start", NO_ARG, + { "initial-start", OPT_INITIAL_START, "Perform initial start", (gptr*) &_initialstart, (gptr*) &_initialstart, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, diff --git a/storage/ndb/src/mgmapi/mgmapi.cpp b/storage/ndb/src/mgmapi/mgmapi.cpp index 08232471474..6dfb48667aa 100644 --- a/storage/ndb/src/mgmapi/mgmapi.cpp +++ b/storage/ndb/src/mgmapi/mgmapi.cpp @@ -701,10 +701,12 @@ ndb_mgm_get_status(NdbMgmHandle handle) Vector<BaseString> split; tmp.split(split, ":"); if(split.size() != 2){ + SET_ERROR(handle, NDB_MGM_ILLEGAL_NODE_STATUS, buf); return NULL; } if(!(split[0].trim() == "nodes")){ + SET_ERROR(handle, NDB_MGM_ILLEGAL_NODE_STATUS, buf); return NULL; } @@ -752,6 +754,7 @@ ndb_mgm_get_status(NdbMgmHandle handle) if(i+1 != noOfNodes){ free(state); + SET_ERROR(handle, NDB_MGM_ILLEGAL_NODE_STATUS, "Node count mismatch"); return NULL; } @@ -1305,33 +1308,6 @@ ndb_mgm_listen_event(NdbMgmHandle handle, const int filter[]) extern "C" int -ndb_mgm_get_stat_port(NdbMgmHandle handle, struct ndb_mgm_reply* /*reply*/) -{ - SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_get_stat_port"); - const ParserRow<ParserDummy> stat_reply[] = { - MGM_CMD("error", NULL, ""), - MGM_ARG("result", String, Mandatory, "Error message"), - MGM_CMD("get statport reply", NULL, ""), - MGM_ARG("tcpport", Int, Mandatory, "TCP port for statistics"), - MGM_END() - }; - CHECK_HANDLE(handle, -1); - CHECK_CONNECTED(handle, -1); - - Properties args; - const Properties *reply; - reply = ndb_mgm_call(handle, stat_reply, "get statport", &args); - CHECK_REPLY(reply, -1); - - Uint32 port; - reply->get("tcpport", &port); - - delete reply; - return port; -} - -extern "C" -int ndb_mgm_dump_state(NdbMgmHandle handle, int nodeId, int* _args, int _num_args, struct ndb_mgm_reply* /* reply */) { diff --git a/storage/ndb/src/mgmsrv/MgmtSrvr.cpp b/storage/ndb/src/mgmsrv/MgmtSrvr.cpp index aee6d4deeb5..1e655c29517 100644 --- a/storage/ndb/src/mgmsrv/MgmtSrvr.cpp +++ b/storage/ndb/src/mgmsrv/MgmtSrvr.cpp @@ -2514,6 +2514,7 @@ int MgmtSrvr::abortBackup(Uint32 backupId) { SignalSender ss(theFacade); + ss.lock(); // lock will be released on exit bool next; NodeId nodeId = 0; diff --git a/storage/ndb/src/mgmsrv/Services.cpp b/storage/ndb/src/mgmsrv/Services.cpp index be15484688b..2731bfd422b 100644 --- a/storage/ndb/src/mgmsrv/Services.cpp +++ b/storage/ndb/src/mgmsrv/Services.cpp @@ -121,8 +121,6 @@ static const unsigned int MAX_WRITE_TIMEOUT = 100 ; const ParserRow<MgmApiSession> commands[] = { - MGM_CMD("get statport", &MgmApiSession::getStatPort, ""), - MGM_CMD("get config", &MgmApiSession::getConfig, ""), MGM_ARG("version", Int, Mandatory, "Configuration version number"), MGM_ARG("node", Int, Optional, "Node ID"), @@ -502,6 +500,7 @@ MgmApiSession::get_nodeid(Parser_t::Context &, ps.tick= tick; m_mgmsrv.get_socket_server()-> foreachSession(stop_session_if_timed_out,&ps); + m_mgmsrv.get_socket_server()->checkSessions(); error_string = ""; continue; } @@ -649,15 +648,6 @@ MgmApiSession::getConfig_common(Parser_t::Context &, } void -MgmApiSession::getStatPort(Parser_t::Context &, - const class Properties &) { - - m_output->println("get statport reply"); - m_output->println("tcpport: %d", 0); - m_output->println(""); -} - -void MgmApiSession::insertError(Parser<MgmApiSession>::Context &, Properties const &args) { Uint32 node = 0, error = 0; @@ -1559,6 +1549,7 @@ MgmApiSession::purge_stale_sessions(Parser_t::Context &ctx, ps.free_nodes.bitXORC(NodeBitmask()); // invert connected_nodes to get free nodes m_mgmsrv.get_socket_server()->foreachSession(stop_session_if_not_connected,&ps); + m_mgmsrv.get_socket_server()->checkSessions(); m_output->println("purge stale sessions reply"); if (str.length() > 0) diff --git a/storage/ndb/src/mgmsrv/Services.hpp b/storage/ndb/src/mgmsrv/Services.hpp index 975202b96df..abe0233cb33 100644 --- a/storage/ndb/src/mgmsrv/Services.hpp +++ b/storage/ndb/src/mgmsrv/Services.hpp @@ -53,7 +53,6 @@ public: virtual ~MgmApiSession(); void runSession(); - void getStatPort(Parser_t::Context &ctx, const class Properties &args); void getConfig(Parser_t::Context &ctx, const class Properties &args); #ifdef MGM_GET_CONFIG_BACKWARDS_COMPAT void getConfig_old(Parser_t::Context &ctx); diff --git a/storage/ndb/src/ndbapi/ClusterMgr.cpp b/storage/ndb/src/ndbapi/ClusterMgr.cpp index 2ff403d53b3..b108ed3fd41 100644 --- a/storage/ndb/src/ndbapi/ClusterMgr.cpp +++ b/storage/ndb/src/ndbapi/ClusterMgr.cpp @@ -70,6 +70,8 @@ ClusterMgr::ClusterMgr(TransporterFacade & _facade): noOfAliveNodes= 0; noOfConnectedNodes= 0; theClusterMgrThread= 0; + m_connect_count = 0; + m_cluster_state = CS_waiting_for_clean_cache; DBUG_VOID_RETURN; } @@ -174,6 +176,16 @@ ClusterMgr::threadMain( ){ int send_heartbeat_now= global_flag_send_heartbeat_now; global_flag_send_heartbeat_now= 0; + if (m_cluster_state == CS_waiting_for_clean_cache) + { + theFacade.m_globalDictCache.lock(); + unsigned sz= theFacade.m_globalDictCache.get_size(); + theFacade.m_globalDictCache.unlock(); + if (sz) + goto next; + m_cluster_state = CS_waiting_for_first_connect; + } + theFacade.lock_mutex(); for (int i = 1; i < MAX_NODES; i++){ /** @@ -222,6 +234,7 @@ ClusterMgr::threadMain( ){ */ theFacade.unlock_mutex(); +next: // Sleep for 100 ms between each Registration Heartbeat Uint64 before = now; NdbSleep_MilliSleep(100); @@ -445,6 +458,11 @@ ClusterMgr::reportNodeFailed(NodeId nodeId){ theNode.nfCompleteRep = false; if(noOfAliveNodes == 0) { + theFacade.m_globalDictCache.lock(); + theFacade.m_globalDictCache.invalidate_all(); + theFacade.m_globalDictCache.unlock(); + m_connect_count ++; + m_cluster_state = CS_waiting_for_clean_cache; NFCompleteRep rep; for(Uint32 i = 1; i<MAX_NODES; i++){ if(theNodes[i].defined && theNodes[i].nfCompleteRep == false){ diff --git a/storage/ndb/src/ndbapi/ClusterMgr.hpp b/storage/ndb/src/ndbapi/ClusterMgr.hpp index 31682885f90..ca879e7948e 100644 --- a/storage/ndb/src/ndbapi/ClusterMgr.hpp +++ b/storage/ndb/src/ndbapi/ClusterMgr.hpp @@ -57,6 +57,11 @@ private: class TransporterFacade & theFacade; public: + enum Cluster_state { + CS_waiting_for_clean_cache = 0, + CS_waiting_for_first_connect, + CS_connected + }; struct Node { Node(); bool defined; @@ -80,12 +85,13 @@ public: bool isClusterAlive() const; void hb_received(NodeId); + Uint32 m_connect_count; private: Uint32 noOfAliveNodes; Uint32 noOfConnectedNodes; Node theNodes[MAX_NODES]; NdbThread* theClusterMgrThread; - + enum Cluster_state m_cluster_state; /** * Used for controlling start/stop of the thread */ diff --git a/storage/ndb/src/ndbapi/DictCache.cpp b/storage/ndb/src/ndbapi/DictCache.cpp index 43913d6c5be..8a0bf2f8e8b 100644 --- a/storage/ndb/src/ndbapi/DictCache.cpp +++ b/storage/ndb/src/ndbapi/DictCache.cpp @@ -47,6 +47,7 @@ Ndb_local_table_info::Ndb_local_table_info(NdbTableImpl *table_impl) { assert(! is_ndb_blob_table(table_impl)); m_table_impl= table_impl; + m_tuple_id_range.reset(); } Ndb_local_table_info::~Ndb_local_table_info() @@ -134,8 +135,8 @@ void GlobalDictCache::printCache() const unsigned sz = vers->size(); for(unsigned i = 0; i<sz ; i++){ TableVersion tv= (*vers)[i]; - DBUG_PRINT(" ", ("vers[%d]: ver: %d, refCount: %d, status: %d", - sz, tv.m_version, tv.m_refCount, tv.m_status)); + DBUG_PRINT(" ", ("impl: %p vers[%d]: ver: %d, refCount: %d, status: %d", + tv.m_impl, i, tv.m_version, tv.m_refCount, tv.m_status)); if(tv.m_impl != 0) { DBUG_PRINT(" ", ("m_impl: internalname: %s", @@ -178,6 +179,11 @@ GlobalDictCache::get(const char * name) { ver->m_status = DROPPED; retreive = true; // Break loop + if (ver->m_refCount == 0) + { + delete ver->m_impl; + versions->erase(versions->size() - 1); + } break; } ver->m_refCount++; @@ -280,6 +286,45 @@ GlobalDictCache::put(const char * name, NdbTableImpl * tab) DBUG_RETURN(tab); } +unsigned +GlobalDictCache::get_size() +{ + NdbElement_t<Vector<TableVersion> > * curr = m_tableHash.getNext(0); + int sz = 0; + while(curr != 0){ + sz += curr->theData->size(); + curr = m_tableHash.getNext(curr); + } + if (sz) + { + printCache(); + } + return sz; +} + +void +GlobalDictCache::invalidate_all() +{ + DBUG_ENTER("GlobalDictCache::invalidate_all"); + NdbElement_t<Vector<TableVersion> > * curr = m_tableHash.getNext(0); + while(curr != 0){ + Vector<TableVersion> * vers = curr->theData; + if (vers->size()) + { + TableVersion * ver = & vers->back(); + ver->m_impl->m_status = NdbDictionary::Object::Invalid; + ver->m_status = DROPPED; + if (ver->m_refCount == 0) + { + delete ver->m_impl; + vers->erase(vers->size() - 1); + } + } + curr = m_tableHash.getNext(curr); + } + DBUG_VOID_RETURN; +} + void GlobalDictCache::release(NdbTableImpl * tab, int invalidate) { @@ -373,6 +418,11 @@ GlobalDictCache::alter_table_rep(const char * name, ver.m_status = DROPPED; ver.m_impl->m_status = altered ? NdbDictionary::Object::Altered : NdbDictionary::Object::Invalid; + if (ver.m_refCount == 0) + { + delete ver.m_impl; + vers->erase(i); + } DBUG_VOID_RETURN; } diff --git a/storage/ndb/src/ndbapi/DictCache.hpp b/storage/ndb/src/ndbapi/DictCache.hpp index f134e6b348e..e909590e03e 100644 --- a/storage/ndb/src/ndbapi/DictCache.hpp +++ b/storage/ndb/src/ndbapi/DictCache.hpp @@ -33,6 +33,10 @@ public: static Ndb_local_table_info *create(NdbTableImpl *table_impl, Uint32 sz=0); static void destroy(Ndb_local_table_info *); NdbTableImpl *m_table_impl; + + // range of cached tuple ids per thread + Ndb::TupleIdRange m_tuple_id_range; + Uint64 m_local_data[1]; // Must be last member. Used to access extra space. private: Ndb_local_table_info(NdbTableImpl *table_impl); @@ -71,6 +75,9 @@ public: void alter_table_rep(const char * name, Uint32 tableId, Uint32 tableVersion, bool altered); + + unsigned get_size(); + void invalidate_all(); public: enum Status { OK = 0, diff --git a/storage/ndb/src/ndbapi/Ndb.cpp b/storage/ndb/src/ndbapi/Ndb.cpp index b963aeeff84..5b0a9e9d330 100644 --- a/storage/ndb/src/ndbapi/Ndb.cpp +++ b/storage/ndb/src/ndbapi/Ndb.cpp @@ -747,158 +747,271 @@ Remark: Returns a new TupleId to the application. The TupleId comes from SYSTAB_0 where SYSKEY_0 = TableId. It is initialized to (TableId << 48) + 1 in NdbcntrMain.cpp. ****************************************************************************/ -Uint64 -Ndb::getAutoIncrementValue(const char* aTableName, Uint32 cacheSize) +int +Ndb::getAutoIncrementValue(const char* aTableName, + Uint64 & tupleId, Uint32 cacheSize) { - DBUG_ENTER("getAutoIncrementValue"); + DBUG_ENTER("Ndb::getAutoIncrementValue"); + ASSERT_NOT_MYSQLD; BaseString internal_tabname(internalize_table_name(aTableName)); Ndb_local_table_info *info= theDictionary->get_local_table_info(internal_tabname); - if (info == 0) - DBUG_RETURN(~(Uint64)0); - const NdbTableImpl *table= info->m_table_impl; - Uint64 tupleId = getTupleIdFromNdb(table->m_id, cacheSize); - DBUG_PRINT("info", ("value %ul", (ulong) tupleId)); - DBUG_RETURN(tupleId); + if (info == 0) { + theError.code = theDictionary->getNdbError().code; + DBUG_RETURN(-1); + } + const NdbTableImpl* table = info->m_table_impl; + TupleIdRange & range = info->m_tuple_id_range; + if (getTupleIdFromNdb(table, range, tupleId, cacheSize) == -1) + DBUG_RETURN(-1); + DBUG_PRINT("info", ("value %llu", (ulonglong)tupleId)); + DBUG_RETURN(0); } -Uint64 -Ndb::getAutoIncrementValue(const NdbDictionary::Table * aTable, Uint32 cacheSize) +int +Ndb::getAutoIncrementValue(const NdbDictionary::Table * aTable, + Uint64 & tupleId, Uint32 cacheSize) { - DBUG_ENTER("getAutoIncrementValue"); - if (aTable == 0) - DBUG_RETURN(~(Uint64)0); + DBUG_ENTER("Ndb::getAutoIncrementValue"); + ASSERT_NOT_MYSQLD; + assert(aTable != 0); const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable); - Uint64 tupleId = getTupleIdFromNdb(table->m_id, cacheSize); - DBUG_PRINT("info", ("value %ul", (ulong) tupleId)); - DBUG_RETURN(tupleId); + const BaseString& internal_tabname = table->m_internalName; + + Ndb_local_table_info *info= + theDictionary->get_local_table_info(internal_tabname); + if (info == 0) { + theError.code = theDictionary->getNdbError().code; + DBUG_RETURN(-1); + } + TupleIdRange & range = info->m_tuple_id_range; + if (getTupleIdFromNdb(table, range, tupleId, cacheSize) == -1) + DBUG_RETURN(-1); + DBUG_PRINT("info", ("value %llu", (ulonglong)tupleId)); + DBUG_RETURN(0); } -Uint64 -Ndb::getTupleIdFromNdb(const char* aTableName, Uint32 cacheSize) +int +Ndb::getAutoIncrementValue(const NdbDictionary::Table * aTable, + TupleIdRange & range, Uint64 & tupleId, + Uint32 cacheSize) { - const NdbTableImpl* table = theDictionary->getTable(aTableName); - if (table == 0) - return ~(Uint64)0; - return getTupleIdFromNdb(table->m_id, cacheSize); + DBUG_ENTER("Ndb::getAutoIncrementValue"); + assert(aTable != 0); + const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable); + + if (getTupleIdFromNdb(table, range, tupleId, cacheSize) == -1) + DBUG_RETURN(-1); + DBUG_PRINT("info", ("value %llu", (ulonglong)tupleId)); + DBUG_RETURN(0); } -Uint64 -Ndb::getTupleIdFromNdb(Uint32 aTableId, Uint32 cacheSize) +int +Ndb::getTupleIdFromNdb(const NdbTableImpl* table, + TupleIdRange & range, Uint64 & tupleId, Uint32 cacheSize) { - DBUG_ENTER("getTupleIdFromNdb"); - if ( theFirstTupleId[aTableId] != theLastTupleId[aTableId] ) + DBUG_ENTER("Ndb::getTupleIdFromNdb"); + if (range.m_first_tuple_id != range.m_last_tuple_id) { - theFirstTupleId[aTableId]++; - DBUG_PRINT("info", ("next cached value %ul", - (ulong) theFirstTupleId[aTableId])); - DBUG_RETURN(theFirstTupleId[aTableId]); + assert(range.m_first_tuple_id < range.m_last_tuple_id); + tupleId = ++range.m_first_tuple_id; + DBUG_PRINT("info", ("next cached value %llu", (ulonglong)tupleId)); } - else // theFirstTupleId == theLastTupleId + else { - DBUG_PRINT("info",("reading %u values from database", - (cacheSize == 0) ? 1 : cacheSize)); - DBUG_RETURN(opTupleIdOnNdb(aTableId, (cacheSize == 0) ? 1 : cacheSize, 0)); + if (cacheSize == 0) + cacheSize = 1; + DBUG_PRINT("info", ("reading %u values from database", (uint)cacheSize)); + /* + * reserve next cacheSize entries in db. adds cacheSize to NEXTID + * and returns first tupleId in the new range. + */ + Uint64 opValue = cacheSize; + if (opTupleIdOnNdb(table, range, opValue, 0) == -1) + DBUG_RETURN(-1); + tupleId = opValue; } + DBUG_RETURN(0); } -Uint64 -Ndb::readAutoIncrementValue(const char* aTableName) +int +Ndb::readAutoIncrementValue(const char* aTableName, + Uint64 & tupleId) { - DBUG_ENTER("readAutoIncrementValue"); - const NdbTableImpl* table = theDictionary->getTable(aTableName); - if (table == 0) { - theError= theDictionary->getNdbError(); - DBUG_RETURN(~(Uint64)0); + DBUG_ENTER("Ndb::readAutoIncrementValue"); + ASSERT_NOT_MYSQLD; + BaseString internal_tabname(internalize_table_name(aTableName)); + + Ndb_local_table_info *info= + theDictionary->get_local_table_info(internal_tabname); + if (info == 0) { + theError.code = theDictionary->getNdbError().code; + DBUG_RETURN(-1); } - Uint64 tupleId = readTupleIdFromNdb(table->m_id); - DBUG_PRINT("info", ("value %ul", (ulong) tupleId)); - DBUG_RETURN(tupleId); + const NdbTableImpl* table = info->m_table_impl; + TupleIdRange & range = info->m_tuple_id_range; + if (readTupleIdFromNdb(table, range, tupleId) == -1) + DBUG_RETURN(-1); + DBUG_PRINT("info", ("value %llu", (ulonglong)tupleId)); + DBUG_RETURN(0); } -Uint64 -Ndb::readAutoIncrementValue(const NdbDictionary::Table * aTable) +int +Ndb::readAutoIncrementValue(const NdbDictionary::Table * aTable, + Uint64 & tupleId) { - DBUG_ENTER("readAutoIncrementValue"); - if (aTable == 0) - DBUG_RETURN(~(Uint64)0); + DBUG_ENTER("Ndb::readAutoIncrementValue"); + ASSERT_NOT_MYSQLD; + assert(aTable != 0); const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable); - Uint64 tupleId = readTupleIdFromNdb(table->m_id); - DBUG_PRINT("info", ("value %ul", (ulong) tupleId)); - DBUG_RETURN(tupleId); + const BaseString& internal_tabname = table->m_internalName; + + Ndb_local_table_info *info= + theDictionary->get_local_table_info(internal_tabname); + if (info == 0) { + theError.code = theDictionary->getNdbError().code; + DBUG_RETURN(-1); + } + TupleIdRange & range = info->m_tuple_id_range; + if (readTupleIdFromNdb(table, range, tupleId) == -1) + DBUG_RETURN(-1); + DBUG_PRINT("info", ("value %llu", (ulonglong)tupleId)); + DBUG_RETURN(0); } -Uint64 -Ndb::readTupleIdFromNdb(Uint32 aTableId) +int +Ndb::readAutoIncrementValue(const NdbDictionary::Table * aTable, + TupleIdRange & range, Uint64 & tupleId) { - if ( theFirstTupleId[aTableId] == theLastTupleId[aTableId] ) - // Cache is empty, check next in database - return opTupleIdOnNdb(aTableId, 0, 3); + DBUG_ENTER("Ndb::readAutoIncrementValue"); + assert(aTable != 0); + const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable); - return theFirstTupleId[aTableId] + 1; + if (readTupleIdFromNdb(table, range, tupleId) == -1) + DBUG_RETURN(-1); + DBUG_PRINT("info", ("value %llu", (ulonglong)tupleId)); + DBUG_RETURN(0); } -bool -Ndb::setAutoIncrementValue(const char* aTableName, Uint64 val, bool increase) +int +Ndb::readTupleIdFromNdb(const NdbTableImpl* table, + TupleIdRange & range, Uint64 & tupleId) { - DBUG_ENTER("setAutoIncrementValue"); + DBUG_ENTER("Ndb::readTupleIdFromNdb"); + if (range.m_first_tuple_id != range.m_last_tuple_id) + { + assert(range.m_first_tuple_id < range.m_last_tuple_id); + tupleId = range.m_first_tuple_id + 1; + } + else + { + /* + * peek at NEXTID. does not reserve it so the value is valid + * only if no other transactions are allowed. + */ + Uint64 opValue = 0; + if (opTupleIdOnNdb(table, range, opValue, 3) == -1) + DBUG_RETURN(-1); + tupleId = opValue; + } + DBUG_RETURN(0); +} + +int +Ndb::setAutoIncrementValue(const char* aTableName, + Uint64 tupleId, bool increase) +{ + DBUG_ENTER("Ndb::setAutoIncrementValue"); + ASSERT_NOT_MYSQLD; BaseString internal_tabname(internalize_table_name(aTableName)); Ndb_local_table_info *info= theDictionary->get_local_table_info(internal_tabname); if (info == 0) { - theError= theDictionary->getNdbError(); - DBUG_RETURN(false); + theError.code = theDictionary->getNdbError().code; + DBUG_RETURN(-1); } - const NdbTableImpl* table= info->m_table_impl; - DBUG_RETURN(setTupleIdInNdb(table->m_id, val, increase)); + const NdbTableImpl* table = info->m_table_impl; + TupleIdRange & range = info->m_tuple_id_range; + if (setTupleIdInNdb(table, range, tupleId, increase) == -1) + DBUG_RETURN(-1); + DBUG_RETURN(0); } -bool -Ndb::setAutoIncrementValue(const NdbDictionary::Table * aTable, Uint64 val, bool increase) +int +Ndb::setAutoIncrementValue(const NdbDictionary::Table * aTable, + Uint64 tupleId, bool increase) { - DBUG_ENTER("setAutoIncrementValue"); - if (aTable == 0) - DBUG_RETURN(~(Uint64)0); + DBUG_ENTER("Ndb::setAutoIncrementValue"); + ASSERT_NOT_MYSQLD; + assert(aTable != 0); const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable); - DBUG_RETURN(setTupleIdInNdb(table->m_id, val, increase)); + const BaseString& internal_tabname = table->m_internalName; + + Ndb_local_table_info *info= + theDictionary->get_local_table_info(internal_tabname); + if (info == 0) { + theError.code = theDictionary->getNdbError().code; + DBUG_RETURN(-1); + } + TupleIdRange & range = info->m_tuple_id_range; + if (setTupleIdInNdb(table, range, tupleId, increase) == -1) + DBUG_RETURN(-1); + DBUG_RETURN(0); } -bool -Ndb::setTupleIdInNdb(const char* aTableName, Uint64 val, bool increase ) +int +Ndb::setAutoIncrementValue(const NdbDictionary::Table * aTable, + TupleIdRange & range, Uint64 tupleId, + bool increase) { - DBUG_ENTER("setTupleIdInNdb(const char*, ...)"); - const NdbTableImpl* table = theDictionary->getTable(aTableName); - if (table == 0) { - theError= theDictionary->getNdbError(); - DBUG_RETURN(false); - } - DBUG_RETURN(setTupleIdInNdb(table->m_id, val, increase)); + DBUG_ENTER("Ndb::setAutoIncrementValue"); + assert(aTable != 0); + const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable); + + if (setTupleIdInNdb(table, range, tupleId, increase) == -1) + DBUG_RETURN(-1); + DBUG_RETURN(0); } -bool -Ndb::setTupleIdInNdb(Uint32 aTableId, Uint64 val, bool increase ) +int +Ndb::setTupleIdInNdb(const NdbTableImpl* table, + TupleIdRange & range, Uint64 tupleId, bool increase) { - DBUG_ENTER("setTupleIdInNdb(Uint32, ...)"); + DBUG_ENTER("Ndb::setTupleIdInNdb"); if (increase) { - if (theFirstTupleId[aTableId] != theLastTupleId[aTableId]) + if (range.m_first_tuple_id != range.m_last_tuple_id) { - // We have a cache sequence - if (val <= theFirstTupleId[aTableId]+1) - DBUG_RETURN(false); - if (val <= theLastTupleId[aTableId]) + assert(range.m_first_tuple_id < range.m_last_tuple_id); + if (tupleId <= range.m_first_tuple_id + 1) + DBUG_RETURN(0); + if (tupleId <= range.m_last_tuple_id) { - theFirstTupleId[aTableId] = val - 1; - DBUG_RETURN(true); + range.m_first_tuple_id = tupleId - 1; + DBUG_PRINT("info", + ("Setting next auto increment cached value to %llu", + (ulonglong)tupleId)); + DBUG_RETURN(0); } - // else continue; } - DBUG_RETURN((opTupleIdOnNdb(aTableId, val, 2) == val)); + /* + * if tupleId <= NEXTID, do nothing. otherwise update NEXTID to + * tupleId and set cached range to first = last = tupleId - 1. + */ + if (opTupleIdOnNdb(table, range, tupleId, 2) == -1) + DBUG_RETURN(-1); } else - DBUG_RETURN((opTupleIdOnNdb(aTableId, val, 1) == val)); + { + /* + * update NEXTID to given value. reset cached range. + */ + if (opTupleIdOnNdb(table, range, tupleId, 1) == -1) + DBUG_RETURN(-1); + } + DBUG_RETURN(0); } int Ndb::initAutoIncrement() @@ -922,18 +1035,18 @@ int Ndb::initAutoIncrement() return (m_sys_tab_0 == NULL); } -Uint64 -Ndb::opTupleIdOnNdb(Uint32 aTableId, Uint64 opValue, Uint32 op) +int +Ndb::opTupleIdOnNdb(const NdbTableImpl* table, + TupleIdRange & range, Uint64 & opValue, Uint32 op) { DBUG_ENTER("Ndb::opTupleIdOnNdb"); + Uint32 aTableId = table->m_id; DBUG_PRINT("enter", ("table=%u value=%llu op=%u", aTableId, opValue, op)); NdbTransaction* tConnection; NdbOperation* tOperation= 0; // Compiler warning if not initialized Uint64 tValue; NdbRecAttr* tRecAttrResult; - int result; - Uint64 ret; CHECK_STATUS_MACRO_ZERO; @@ -961,42 +1074,44 @@ Ndb::opTupleIdOnNdb(Uint32 aTableId, Uint64 opValue, Uint32 op) tValue = tRecAttrResult->u_64_value(); - theFirstTupleId[aTableId] = tValue - opValue; - theLastTupleId[aTableId] = tValue - 1; - ret = theFirstTupleId[aTableId]; + range.m_first_tuple_id = tValue - opValue; + range.m_last_tuple_id = tValue - 1; + opValue = range.m_first_tuple_id; // out break; case 1: - tOperation->updateTuple(); + // create on first use + tOperation->writeTuple(); tOperation->equal("SYSKEY_0", aTableId ); tOperation->setValue("NEXTID", opValue); if (tConnection->execute( Commit ) == -1 ) goto error_handler; - theFirstTupleId[aTableId] = ~(Uint64)0; - theLastTupleId[aTableId] = ~(Uint64)0; - ret = opValue; + range.reset(); break; case 2: tOperation->interpretedUpdateTuple(); tOperation->equal("SYSKEY_0", aTableId ); tOperation->load_const_u64(1, opValue); tOperation->read_attr("NEXTID", 2); + // compare NEXTID >= opValue tOperation->branch_le(2, 1, 0); tOperation->write_attr("NEXTID", 1); tOperation->interpret_exit_ok(); tOperation->def_label(0); tOperation->interpret_exit_nok(9999); - if ( (result = tConnection->execute( Commit )) == -1 ) - goto error_handler; - - if (result == 9999) - ret = ~(Uint64)0; + if (tConnection->execute( Commit ) == -1) + { + if (tConnection->theError.code != 9999) + goto error_handler; + } else { - theFirstTupleId[aTableId] = theLastTupleId[aTableId] = opValue - 1; - ret = opValue; + DBUG_PRINT("info", + ("Setting next auto increment value (db) to %llu", + (ulonglong)opValue)); + range.m_first_tuple_id = range.m_last_tuple_id = opValue - 1; } break; case 3: @@ -1005,7 +1120,7 @@ Ndb::opTupleIdOnNdb(Uint32 aTableId, Uint64 opValue, Uint32 op) tRecAttrResult = tOperation->getValue("NEXTID"); if (tConnection->execute( Commit ) == -1 ) goto error_handler; - ret = tRecAttrResult->u_64_value(); + opValue = tRecAttrResult->u_64_value(); // out break; default: goto error_handler; @@ -1013,7 +1128,7 @@ Ndb::opTupleIdOnNdb(Uint32 aTableId, Uint64 opValue, Uint32 op) this->closeTransaction(tConnection); - DBUG_RETURN(ret); + DBUG_RETURN(0); error_handler: theError.code = tConnection->theError.code; @@ -1023,7 +1138,7 @@ Ndb::opTupleIdOnNdb(Uint32 aTableId, Uint64 opValue, Uint32 op) theError.code, tConnection ? tConnection->theError.code : -1, tOperation ? tOperation->theError.code : -1)); - DBUG_RETURN(~(Uint64)0); + DBUG_RETURN(-1); } Uint32 @@ -1196,6 +1311,35 @@ Ndb::internalize_table_name(const char *external_name) const DBUG_RETURN(ret); } +const BaseString +Ndb::old_internalize_index_name(const NdbTableImpl * table, + const char * external_name) const +{ + BaseString ret; + DBUG_ENTER("old_internalize_index_name"); + DBUG_PRINT("enter", ("external_name: %s, table_id: %d", + external_name, table ? table->m_id : ~0)); + if (!table) + { + DBUG_PRINT("error", ("!table")); + DBUG_RETURN(ret); + } + + if (fullyQualifiedNames) + { + /* Internal index name format <db>/<schema>/<tabid>/<table> */ + ret.assfmt("%s%d%c%s", + theImpl->m_prefix.c_str(), + table->m_id, + table_name_separator, + external_name); + } + else + ret.assign(external_name); + + DBUG_PRINT("exit", ("internal_name: %s", ret.c_str())); + DBUG_RETURN(ret); +} const BaseString Ndb::internalize_index_name(const NdbTableImpl * table, @@ -1213,9 +1357,9 @@ Ndb::internalize_index_name(const NdbTableImpl * table, if (fullyQualifiedNames) { - /* Internal index name format <db>/<schema>/<tabid>/<table> */ + /* Internal index name format sys/def/<tabid>/<table> */ ret.assfmt("%s%d%c%s", - theImpl->m_prefix.c_str(), + theImpl->m_systemPrefix.c_str(), table->m_id, table_name_separator, external_name); @@ -1287,6 +1431,7 @@ NdbEventOperation* Ndb::createEventOperation(const char* eventName) int Ndb::dropEventOperation(NdbEventOperation* tOp) { DBUG_ENTER("Ndb::dropEventOperation"); + DBUG_PRINT("info", ("name: %s", tOp->getEvent()->getTable()->getName())); // remove it from list NdbEventOperationImpl *op= NdbEventBuffer::getEventOperationImpl(tOp); @@ -1297,6 +1442,8 @@ int Ndb::dropEventOperation(NdbEventOperation* tOp) else theImpl->m_ev_op= op->m_next; + DBUG_PRINT("info", ("first: %s", + theImpl->m_ev_op ? theImpl->m_ev_op->getEvent()->getTable()->getName() : "<empty>")); assert(theImpl->m_ev_op == 0 || theImpl->m_ev_op->m_prev == 0); theEventBuffer->dropEventOperation(tOp); @@ -1321,6 +1468,12 @@ Ndb::pollEvents(int aMillisecondNumber, Uint64 *latestGCI) return theEventBuffer->pollEvents(aMillisecondNumber, latestGCI); } +int +Ndb::flushIncompleteEvents(Uint64 gci) +{ + return theEventBuffer->flushIncompleteEvents(gci); +} + NdbEventOperation *Ndb::nextEvent() { return theEventBuffer->nextEvent(); diff --git a/storage/ndb/src/ndbapi/NdbDictionary.cpp b/storage/ndb/src/ndbapi/NdbDictionary.cpp index e844dc3369e..c71689d2e81 100644 --- a/storage/ndb/src/ndbapi/NdbDictionary.cpp +++ b/storage/ndb/src/ndbapi/NdbDictionary.cpp @@ -1618,6 +1618,14 @@ NdbDictionary::Dictionary::listIndexes(List& list, return m_impl.listIndexes(list, tab->getTableId()); } +int +NdbDictionary::Dictionary::listIndexes(List& list, + const NdbDictionary::Table &table) const +{ + return m_impl.listIndexes(list, table.getTableId()); +} + + const struct NdbError & NdbDictionary::Dictionary::getNdbError() const { return m_impl.getNdbError(); diff --git a/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp b/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp index 8eb0b37120d..22a5d2f20a5 100644 --- a/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp +++ b/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp @@ -56,7 +56,6 @@ DBUG_RETURN(b);\ } -extern Uint64 g_latest_trans_gci; int ndb_dictionary_is_mysqld = 0; bool @@ -79,18 +78,26 @@ is_ndb_blob_table(const NdbTableImpl* t) NdbColumnImpl::NdbColumnImpl() : NdbDictionary::Column(* this), m_attrId(-1), m_facade(this) { + DBUG_ENTER("NdbColumnImpl::NdbColumnImpl"); + DBUG_PRINT("info", ("this: %p", this)); init(); + DBUG_VOID_RETURN; } NdbColumnImpl::NdbColumnImpl(NdbDictionary::Column & f) : NdbDictionary::Column(* this), m_attrId(-1), m_facade(&f) { + DBUG_ENTER("NdbColumnImpl::NdbColumnImpl"); + DBUG_PRINT("info", ("this: %p", this)); init(); + DBUG_VOID_RETURN; } NdbColumnImpl& NdbColumnImpl::operator=(const NdbColumnImpl& col) { + DBUG_ENTER("NdbColumnImpl::operator="); + DBUG_PRINT("info", ("this: %p &col: %p", this, &col)); m_attrId = col.m_attrId; m_name = col.m_name; m_type = col.m_type; @@ -112,13 +119,14 @@ NdbColumnImpl::operator=(const NdbColumnImpl& col) if (col.m_blobTable == NULL) m_blobTable = NULL; else { - m_blobTable = new NdbTableImpl(); + if (m_blobTable == NULL) + m_blobTable = new NdbTableImpl(); m_blobTable->assign(*col.m_blobTable); } m_column_no = col.m_column_no; // Do not copy m_facade !! - return *this; + DBUG_RETURN(*this); } void @@ -261,15 +269,19 @@ NdbColumnImpl::init(Type t) NdbColumnImpl::~NdbColumnImpl() { + DBUG_ENTER("NdbColumnImpl::~NdbColumnImpl"); + DBUG_PRINT("info", ("this: %p", this)); if (m_blobTable != NULL) delete m_blobTable; m_blobTable = NULL; + DBUG_VOID_RETURN; } bool NdbColumnImpl::equal(const NdbColumnImpl& col) const { DBUG_ENTER("NdbColumnImpl::equal"); + DBUG_PRINT("info", ("this: %p &col: %p", this, &col)); if(strcmp(m_name.c_str(), col.m_name.c_str()) != 0){ DBUG_RETURN(false); } @@ -377,24 +389,33 @@ NdbTableImpl::NdbTableImpl() : NdbDictionary::Table(* this), NdbDictObjectImpl(NdbDictionary::Object::UserTable), m_facade(this) { + DBUG_ENTER("NdbTableImpl::NdbTableImpl"); + DBUG_PRINT("info", ("this: %p", this)); init(); + DBUG_VOID_RETURN; } NdbTableImpl::NdbTableImpl(NdbDictionary::Table & f) : NdbDictionary::Table(* this), NdbDictObjectImpl(NdbDictionary::Object::UserTable), m_facade(&f) { + DBUG_ENTER("NdbTableImpl::NdbTableImpl"); + DBUG_PRINT("info", ("this: %p", this)); init(); + DBUG_VOID_RETURN; } NdbTableImpl::~NdbTableImpl() { + DBUG_ENTER("NdbTableImpl::~NdbTableImpl"); + DBUG_PRINT("info", ("this: %p", this)); if (m_index != 0) { delete m_index; m_index = 0; } for (unsigned i = 0; i < m_columns.size(); i++) - delete m_columns[i]; + delete m_columns[i]; + DBUG_VOID_RETURN; } void @@ -636,6 +657,8 @@ NdbTableImpl::equal(const NdbTableImpl& obj) const void NdbTableImpl::assign(const NdbTableImpl& org) { + DBUG_ENTER("NdbColumnImpl::assign"); + DBUG_PRINT("info", ("this: %p &org: %p", this, &org)); /* m_changeMask intentionally not copied */ m_primaryTableId = org.m_primaryTableId; m_internalName.assign(org.m_internalName); @@ -662,7 +685,14 @@ NdbTableImpl::assign(const NdbTableImpl& org) m_columnHashMask, m_columnHash, m_hashValueMask, m_hashpointerValue is state calculated by computeAggregates and buildColumnHash */ - for(unsigned i = 0; i<org.m_columns.size(); i++){ + unsigned i; + for(i = 0; i < m_columns.size(); i++) + { + delete m_columns[i]; + } + m_columns.clear(); + for(i = 0; i < org.m_columns.size(); i++) + { NdbColumnImpl * col = new NdbColumnImpl(); const NdbColumnImpl * iorg = org.m_columns[i]; (* col) = (* iorg); @@ -702,6 +732,7 @@ NdbTableImpl::assign(const NdbTableImpl& org) m_tablespace_name = org.m_tablespace_name; m_tablespace_id= org.m_tablespace_id; m_tablespace_version = org.m_tablespace_version; + DBUG_VOID_RETURN; } void NdbTableImpl::setName(const char * name) @@ -1085,14 +1116,20 @@ NdbEventImpl::NdbEventImpl() : NdbDictionary::Event(* this), NdbDictObjectImpl(NdbDictionary::Object::TypeUndefined), m_facade(this) { + DBUG_ENTER("NdbEventImpl::NdbEventImpl"); + DBUG_PRINT("info", ("this: %p", this)); init(); + DBUG_VOID_RETURN; } NdbEventImpl::NdbEventImpl(NdbDictionary::Event & f) : NdbDictionary::Event(* this), NdbDictObjectImpl(NdbDictionary::Object::TypeUndefined), m_facade(&f) { + DBUG_ENTER("NdbEventImpl::NdbEventImpl"); + DBUG_PRINT("info", ("this: %p", this)); init(); + DBUG_VOID_RETURN; } void NdbEventImpl::init() @@ -1108,10 +1145,13 @@ void NdbEventImpl::init() NdbEventImpl::~NdbEventImpl() { + DBUG_ENTER("NdbEventImpl::~NdbEventImpl"); + DBUG_PRINT("info", ("this: %p", this)); for (unsigned i = 0; i < m_columns.size(); i++) delete m_columns[i]; if (m_tableImpl) delete m_tableImpl; + DBUG_VOID_RETURN; } void NdbEventImpl::setName(const char * name) @@ -1134,11 +1174,14 @@ NdbEventImpl::setTable(const NdbDictionary::Table& table) void NdbEventImpl::setTable(NdbTableImpl *tableImpl) { + DBUG_ENTER("NdbEventImpl::setTable"); + DBUG_PRINT("info", ("this: %p tableImpl: %p", this, tableImpl)); DBUG_ASSERT(tableImpl->m_status != NdbDictionary::Object::Invalid); if (!m_tableImpl) m_tableImpl = new NdbTableImpl(); // Copy table, since event might be accessed from different threads m_tableImpl->assign(*tableImpl); + DBUG_VOID_RETURN; } const NdbDictionary::Table * @@ -1343,9 +1386,6 @@ NdbDictionaryImpl::putTable(NdbTableImpl *impl) Ndb_local_table_info::create(impl, m_local_table_data_size); m_localHash.put(impl->m_internalName.c_str(), info); - - m_ndb.theFirstTupleId[impl->getTableId()] = ~0; - m_ndb.theLastTupleId[impl->getTableId()] = ~0; } int @@ -1468,9 +1508,21 @@ NdbTableImpl * NdbDictionaryImpl::getIndexTable(NdbIndexImpl * index, NdbTableImpl * table) { + const char *current_db= m_ndb.getDatabaseName(); + NdbTableImpl *index_table; const BaseString internalName( m_ndb.internalize_index_name(table, index->getName())); - return getTable(m_ndb.externalizeTableName(internalName.c_str())); + // Get index table in system database + m_ndb.setDatabaseName(NDB_SYSTEM_DATABASE); + index_table= getTable(m_ndb.externalizeTableName(internalName.c_str())); + m_ndb.setDatabaseName(current_db); + if (!index_table) + { + // Index table not found + // Try geting index table in current database (old format) + index_table= getTable(m_ndb.externalizeTableName(internalName.c_str())); + } + return index_table; } #if 0 @@ -2205,11 +2257,11 @@ NdbDictionaryImpl::createTable(NdbTableImpl &t) } if (autoIncrement) { // XXX unlikely race condition - t.m_id may no longer be same table - if (! m_ndb.setTupleIdInNdb(t.m_id, initialValue, false)) { - if (m_ndb.theError.code) - m_error.code = m_ndb.theError.code; - else - m_error.code = 4336; + // the tuple id range is not used on input + Ndb::TupleIdRange range; + if (m_ndb.setTupleIdInNdb(&t, range, initialValue, false) == -1) { + assert(m_ndb.theError.code != 0); + m_error.code = m_ndb.theError.code; delete t2; DBUG_RETURN(-1); } @@ -2958,63 +3010,6 @@ NdbDictionaryImpl::removeCachedObject(NdbTableImpl & impl) DBUG_RETURN(0); } -/***************************************************************** - * Get index info - */ -NdbIndexImpl* -NdbDictionaryImpl::getIndexImpl(const char * externalName, - const BaseString& internalName) -{ - ASSERT_NOT_MYSQLD; - Ndb_local_table_info * info = get_local_table_info(internalName); - if(info == 0){ - m_error.code = 4243; - return 0; - } - NdbTableImpl * tab = info->m_table_impl; - - if(tab->m_indexType == NdbDictionary::Object::TypeUndefined) - { - // Not an index - m_error.code = 4243; - return 0; - } - - NdbTableImpl* prim = getTable(tab->m_primaryTable.c_str()); - if(prim == 0){ - m_error.code = 4243; - return 0; - } - - return getIndexImpl(externalName, internalName, *tab, *prim); -} - -NdbIndexImpl* -NdbDictionaryImpl::getIndexImpl(const char * externalName, - const BaseString& internalName, - NdbTableImpl &tab, - NdbTableImpl &prim) -{ - DBUG_ENTER("NdbDictionaryImpl::getIndexImpl"); - DBUG_ASSERT(tab.m_indexType != NdbDictionary::Object::TypeUndefined); - /** - * Create index impl - */ - NdbIndexImpl* idx; - if(NdbDictInterface::create_index_obj_from_table(&idx, &tab, &prim) == 0){ - idx->m_table = &tab; - idx->m_externalName.assign(externalName); - idx->m_internalName.assign(internalName); - idx->m_table_id = prim.getObjectId(); - idx->m_table_version = prim.getObjectVersion(); - // TODO Assign idx to tab->m_index - // Don't do it right now since assign can't asign a table with index - // tab->m_index = idx; - DBUG_RETURN(idx); - } - DBUG_RETURN(0); -} - int NdbDictInterface::create_index_obj_from_table(NdbIndexImpl** dst, NdbTableImpl* tab, @@ -3072,6 +3067,9 @@ NdbDictInterface::create_index_obj_from_table(NdbIndexImpl** dst, tab->m_columns[i]->m_distributionKey = 0; } + idx->m_table_id = prim->getObjectId(); + idx->m_table_version = prim->getObjectVersion(); + * dst = idx; DBUG_PRINT("exit", ("m_id: %d m_version: %d", idx->m_id, idx->m_version)); DBUG_RETURN(0); @@ -3681,9 +3679,12 @@ NdbDictionaryImpl::getEvent(const char * eventName, NdbTableImpl* tab) DBUG_RETURN(NULL); } } + ev->setTable(tab); + releaseTableGlobal(*tab, 0); } - - ev->setTable(tab); + else + ev->setTable(tab); + tab = 0; ev->setTable(m_ndb.externalizeTableName(ev->getTableName())); // get the columns from the attrListBitmask @@ -3944,6 +3945,7 @@ NdbDictionaryImpl::dropBlobEvents(const NdbEventImpl& evnt) if (blob_evnt == NULL) continue; (void)dropEvent(*blob_evnt); + delete blob_evnt; } } else { // loop over MAX_ATTRIBUTES_IN_TABLE ... @@ -4232,7 +4234,6 @@ NdbDictInterface::execWAIT_GCP_CONF(NdbApiSignal* signal, { const WaitGCPConf * const conf= CAST_CONSTPTR(WaitGCPConf, signal->getDataPtr()); - g_latest_trans_gci= conf->gcp; m_waiter.signal(NO_WAIT); } diff --git a/storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp b/storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp index 5a7a1ebb0ab..b6961edd019 100644 --- a/storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp +++ b/storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp @@ -617,6 +617,7 @@ public: get_local_table_info(const BaseString& internalTableName); NdbIndexImpl * getIndex(const char * indexName, const char * tableName); + NdbIndexImpl * getIndex(const char * indexName, const NdbTableImpl& prim); NdbEventImpl * getEvent(const char * eventName, NdbTableImpl* = NULL); NdbEventImpl * getBlobEvent(const NdbEventImpl& ev, uint col_no); NdbEventImpl * getEventImpl(const char * internalName); @@ -950,59 +951,42 @@ NdbDictionaryImpl::get_local_table_info(const BaseString& internalTableName) if (info) { m_localHash.put(internalTableName.c_str(), info); - m_ndb.theFirstTupleId[tab->getTableId()] = ~0; - m_ndb.theLastTupleId[tab->getTableId()] = ~0; } } } DBUG_RETURN(info); // autoincrement already initialized } -class InitIndexGlobal : public GlobalCacheInitObject +class InitIndex : public GlobalCacheInitObject { public: const char *m_index_name; - NdbTableImpl &m_prim; + const NdbTableImpl &m_prim; - InitIndexGlobal(NdbDictionaryImpl *dict, - const BaseString &internal_indexname, - const char *index_name, - NdbTableImpl &prim) : - GlobalCacheInitObject(dict, internal_indexname), + InitIndex(const BaseString &internal_indexname, + const char *index_name, + const NdbTableImpl &prim) : + GlobalCacheInitObject(0, internal_indexname), m_index_name(index_name), m_prim(prim) - {} - int init(NdbTableImpl &tab) const - { - tab.m_index= m_dict->getIndexImpl(m_index_name, m_name, tab, m_prim); - if (tab.m_index == 0) - return 1; - tab.m_index->m_table= &tab; - return 0; - } -}; - -class InitIndex : public GlobalCacheInitObject -{ -public: - const char *m_index_name; - - InitIndex(NdbDictionaryImpl *dict, - const BaseString &internal_indexname, - const char *index_name) : - GlobalCacheInitObject(dict, internal_indexname), - m_index_name(index_name) - {} - int init(NdbTableImpl &tab) const - { - DBUG_ASSERT(tab.m_index == 0); - tab.m_index= m_dict->getIndexImpl(m_index_name, m_name); - if (tab.m_index) + {} + + int init(NdbTableImpl &tab) const { + DBUG_ENTER("InitIndex::init"); + DBUG_ASSERT(tab.m_indexType != NdbDictionary::Object::TypeUndefined); + /** + * Create index impl + */ + NdbIndexImpl* idx; + if(NdbDictInterface::create_index_obj_from_table(&idx, &tab, &m_prim) == 0) { - tab.m_index->m_table= &tab; - return 0; + idx->m_table = &tab; + idx->m_externalName.assign(m_index_name); + idx->m_internalName.assign(m_name); + tab.m_index = idx; + DBUG_RETURN(0); } - return 1; + DBUG_RETURN(1); } }; @@ -1019,14 +1003,14 @@ NdbDictionaryImpl::getIndexGlobal(const char * index_name, while (retry) { NdbTableImpl *tab= - fetchGlobalTableImplRef(InitIndexGlobal(this, internal_indexname, - index_name, ndbtab)); + fetchGlobalTableImplRef(InitIndex(internal_indexname, + index_name, ndbtab)); if (tab) { // tab->m_index sould be set. otherwise tab == 0 NdbIndexImpl *idx= tab->m_index; - if (idx->m_table_id != ndbtab.getObjectId() || - idx->m_table_version != ndbtab.getObjectVersion()) + if (idx->m_table_id != (unsigned)ndbtab.getObjectId() || + idx->m_table_version != (unsigned)ndbtab.getObjectVersion()) { releaseIndexGlobal(*idx, 1); retry--; @@ -1036,6 +1020,33 @@ NdbDictionaryImpl::getIndexGlobal(const char * index_name, } break; } + { + // Index not found, try old format + const BaseString + old_internal_indexname(m_ndb.old_internalize_index_name(&ndbtab, + index_name)); + retry= 2; + while (retry) + { + NdbTableImpl *tab= + fetchGlobalTableImplRef(InitIndex(old_internal_indexname, + index_name, ndbtab)); + if (tab) + { + // tab->m_index sould be set. otherwise tab == 0 + NdbIndexImpl *idx= tab->m_index; + if (idx->m_table_id != (unsigned)ndbtab.getObjectId() || + idx->m_table_version != (unsigned)ndbtab.getObjectVersion()) + { + releaseIndexGlobal(*idx, 1); + retry--; + continue; + } + DBUG_RETURN(idx); + } + break; + } + } m_error.code= 4243; DBUG_RETURN(0); } @@ -1067,41 +1078,78 @@ NdbIndexImpl * NdbDictionaryImpl::getIndex(const char * index_name, const char * table_name) { - while (table_name || m_ndb.usingFullyQualifiedNames()) + if (table_name == 0) { - const BaseString internal_indexname( - (table_name) - ? - m_ndb.internalize_index_name(getTable(table_name), index_name) - : - m_ndb.internalize_table_name(index_name)); // Index is also a table - - if (internal_indexname.length()) - { - Ndb_local_table_info *info= m_localHash.get(internal_indexname.c_str()); - NdbTableImpl *tab; - if (info == 0) - { - tab= fetchGlobalTableImplRef(InitIndex(this, internal_indexname, - index_name)); - if (tab) - { - info= Ndb_local_table_info::create(tab, 0); - if (info) - m_localHash.put(internal_indexname.c_str(), info); - else - break; - } - else - break; - } - else - tab= info->m_table_impl; - return tab->m_index; - } - break; + assert(0); + m_error.code= 4243; + return 0; + } + + + NdbTableImpl* prim = getTable(table_name); + if (prim == 0) + { + m_error.code= 4243; + return 0; } + return getIndex(index_name, *prim); +} + +inline +NdbIndexImpl * +NdbDictionaryImpl::getIndex(const char* index_name, + const NdbTableImpl& prim) +{ + + const BaseString + internal_indexname(m_ndb.internalize_index_name(&prim, index_name)); + + Ndb_local_table_info *info= m_localHash.get(internal_indexname.c_str()); + NdbTableImpl *tab; + if (info == 0) + { + tab= fetchGlobalTableImplRef(InitIndex(internal_indexname, + index_name, + prim)); + if (!tab) + goto retry; + + info= Ndb_local_table_info::create(tab, 0); + if (!info) + goto retry; + m_localHash.put(internal_indexname.c_str(), info); + } + else + tab= info->m_table_impl; + + return tab->m_index; + +retry: + // Index not found, try fetching it from current database + const BaseString + old_internal_indexname(m_ndb.old_internalize_index_name(&prim, index_name)); + + info= m_localHash.get(old_internal_indexname.c_str()); + if (info == 0) + { + tab= fetchGlobalTableImplRef(InitIndex(old_internal_indexname, + index_name, + prim)); + if (!tab) + goto err; + + info= Ndb_local_table_info::create(tab, 0); + if (!info) + goto err; + m_localHash.put(old_internal_indexname.c_str(), info); + } + else + tab= info->m_table_impl; + + return tab->m_index; + +err: m_error.code= 4243; return 0; } diff --git a/storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp b/storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp index 98a8899af4a..a5fbd84e5b0 100644 --- a/storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp +++ b/storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp @@ -70,21 +70,6 @@ print_std(const SubTableData * sdata, LinearSectionPtr ptr[3]) * */ -//#define EVENT_DEBUG -#ifdef EVENT_DEBUG -#define DBUG_ENTER_EVENT(A) DBUG_ENTER(A) -#define DBUG_RETURN_EVENT(A) DBUG_RETURN(A) -#define DBUG_VOID_RETURN_EVENT DBUG_VOID_RETURN -#define DBUG_PRINT_EVENT(A,B) DBUG_PRINT(A,B) -#define DBUG_DUMP_EVENT(A,B,C) DBUG_DUMP(A,B,C) -#else -#define DBUG_ENTER_EVENT(A) -#define DBUG_RETURN_EVENT(A) return(A) -#define DBUG_VOID_RETURN_EVENT return -#define DBUG_PRINT_EVENT(A,B) -#define DBUG_DUMP_EVENT(A,B,C) -#endif - // todo handle several ndb objects // todo free allocated data when closing NdbEventBuffer @@ -168,11 +153,14 @@ NdbEventOperationImpl::init(NdbEventImpl& evnt) m_state= EO_CREATED; + m_node_bit_mask.clear(); #ifdef ndb_event_stores_merge_events_flag m_mergeEvents = m_eventImpl->m_mergeEvents; #else - m_mergeEvents = false; + m_mergeEvents = false; #endif + m_ref_count = 0; + DBUG_PRINT("info", ("m_ref_count = 0 for op: %p", this)); m_has_error= 0; @@ -189,6 +177,17 @@ NdbEventOperationImpl::~NdbEventOperationImpl() // m_bufferHandle->dropSubscribeEvent(m_bufferId); ; // ToDo? We should send stop signal here + if (theMainOp == NULL) + { + NdbEventOperationImpl* tBlobOp = theBlobOpList; + while (tBlobOp != NULL) + { + NdbEventOperationImpl *op = tBlobOp; + tBlobOp = tBlobOp->m_next; + delete op; + } + } + m_ndb->theImpl->theNdbObjectIdMap.unmap(m_oid, this); DBUG_PRINT("exit",("this: %p/%p oid: %u main: %p", this, m_facade, m_oid, theMainOp)); @@ -534,7 +533,11 @@ NdbEventOperationImpl::execute_nolock() } } if (r == 0) + { + m_ref_count++; + DBUG_PRINT("info", ("m_ref_count: %u for op: %p", m_ref_count, this)); DBUG_RETURN(0); + } } //Error m_state= EO_ERROR; @@ -661,80 +664,79 @@ NdbEventOperationImpl::execSUB_TABLE_DATA(NdbApiSignal * signal, int NdbEventOperationImpl::receive_event() { - DBUG_ENTER_EVENT("NdbEventOperationImpl::receive_event"); - Uint32 operation= (Uint32)m_data_item->sdata->operation; - DBUG_PRINT_EVENT("info",("sdata->operation %u",operation)); - - if (operation == NdbDictionary::Event::_TE_ALTER) - { - // Parse the new table definition and - // create a table object - NdbDictionary::Dictionary *myDict = m_ndb->getDictionary(); - NdbDictionaryImpl *dict = & NdbDictionaryImpl::getImpl(*myDict); - NdbError error; - NdbDictInterface dif(error); - NdbTableImpl *at; - m_change_mask = m_data_item->sdata->changeMask; - error.code = dif.parseTableInfo(&at, - (Uint32*)m_buffer.get_data(), - m_buffer.length() / 4, - true); - m_buffer.clear(); - if (at) - at->buildColumnHash(); - else - { - DBUG_PRINT_EVENT("info", ("Failed to parse DictTabInfo error %u", - error.code)); - DBUG_RETURN_EVENT(1); - } - - NdbTableImpl *tmp_table_impl= m_eventImpl->m_tableImpl; - m_eventImpl->m_tableImpl = at; - - DBUG_PRINT("info", ("switching table impl 0x%x -> 0x%x", - tmp_table_impl, at)); - - // change the rec attrs to refer to the new table object - int i; - for (i = 0; i < 2; i++) + if (unlikely(operation >= NdbDictionary::Event::_TE_FIRST_NON_DATA_EVENT)) + { + DBUG_ENTER("NdbEventOperationImpl::receive_event"); + DBUG_PRINT("info",("sdata->operation %u this: %p", operation, this)); + if (operation == NdbDictionary::Event::_TE_ALTER) { - NdbRecAttr *p = theFirstPkAttrs[i]; - while (p) + // Parse the new table definition and + // create a table object + NdbDictionary::Dictionary *myDict = m_ndb->getDictionary(); + NdbDictionaryImpl *dict = & NdbDictionaryImpl::getImpl(*myDict); + NdbError error; + NdbDictInterface dif(error); + NdbTableImpl *at; + m_change_mask = m_data_item->sdata->changeMask; + error.code = dif.parseTableInfo(&at, + (Uint32*)m_buffer.get_data(), + m_buffer.length() / 4, + true); + m_buffer.clear(); + if (unlikely(!at)) { - int no = p->getColumn()->getColumnNo(); - NdbColumnImpl *tAttrInfo = at->getColumn(no); - DBUG_PRINT("info", ("rec_attr: 0x%x " - "switching column impl 0x%x -> 0x%x", - p, p->m_column, tAttrInfo)); - p->m_column = tAttrInfo; - p = p->next(); + DBUG_PRINT("info", ("Failed to parse DictTabInfo error %u", + error.code)); + ndbout_c("Failed to parse DictTabInfo error %u", error.code); + DBUG_RETURN(1); } - } - for (i = 0; i < 2; i++) - { - NdbRecAttr *p = theFirstDataAttrs[i]; - while (p) + at->buildColumnHash(); + + NdbTableImpl *tmp_table_impl= m_eventImpl->m_tableImpl; + m_eventImpl->m_tableImpl = at; + + DBUG_PRINT("info", ("switching table impl 0x%x -> 0x%x", + tmp_table_impl, at)); + + // change the rec attrs to refer to the new table object + int i; + for (i = 0; i < 2; i++) { - int no = p->getColumn()->getColumnNo(); - NdbColumnImpl *tAttrInfo = at->getColumn(no); - DBUG_PRINT("info", ("rec_attr: 0x%x " - "switching column impl 0x%x -> 0x%x", - p, p->m_column, tAttrInfo)); - p->m_column = tAttrInfo; - p = p->next(); + NdbRecAttr *p = theFirstPkAttrs[i]; + while (p) + { + int no = p->getColumn()->getColumnNo(); + NdbColumnImpl *tAttrInfo = at->getColumn(no); + DBUG_PRINT("info", ("rec_attr: 0x%x " + "switching column impl 0x%x -> 0x%x", + p, p->m_column, tAttrInfo)); + p->m_column = tAttrInfo; + p = p->next(); + } + } + for (i = 0; i < 2; i++) + { + NdbRecAttr *p = theFirstDataAttrs[i]; + while (p) + { + int no = p->getColumn()->getColumnNo(); + NdbColumnImpl *tAttrInfo = at->getColumn(no); + DBUG_PRINT("info", ("rec_attr: 0x%x " + "switching column impl 0x%x -> 0x%x", + p, p->m_column, tAttrInfo)); + p->m_column = tAttrInfo; + p = p->next(); + } } + if (tmp_table_impl) + delete tmp_table_impl; } - if (tmp_table_impl) - delete tmp_table_impl; - } - - if (unlikely(operation >= NdbDictionary::Event::_TE_FIRST_NON_DATA_EVENT)) - { - DBUG_RETURN_EVENT(1); + DBUG_RETURN(1); } + DBUG_ENTER_EVENT("NdbEventOperationImpl::receive_event"); + DBUG_PRINT_EVENT("info",("sdata->operation %u this: %p", operation, this)); // now move the data into the RecAttrs int is_update= operation == NdbDictionary::Event::_TE_UPDATE; @@ -973,7 +975,15 @@ NdbEventBuffer::~NdbEventBuffer() delete op->m_facade; } - for (unsigned j= 0; j < m_allocated_data.size(); j++) + unsigned j; + Uint32 sz= m_active_gci.size(); + Gci_container* array = (Gci_container*)m_active_gci.getBase(); + for(j = 0; j < sz; j++) + { + array[j].~Gci_container(); + } + + for (j= 0; j < m_allocated_data.size(); j++) { unsigned sz= m_allocated_data[j]->sz; EventBufData *data= m_allocated_data[j]->data; @@ -1085,6 +1095,33 @@ NdbEventBuffer::pollEvents(int aMillisecondNumber, Uint64 *latestGCI) return ret; } +int +NdbEventBuffer::flushIncompleteEvents(Uint64 gci) +{ + /** + * Find min complete gci + */ + Uint32 i; + Uint32 sz= m_active_gci.size(); + Gci_container* array = (Gci_container*)m_active_gci.getBase(); + for(i = 0; i < sz; i++) + { + Gci_container* tmp = array + i; + if (tmp->m_gci && tmp->m_gci < gci) + { + // we have found an old not-completed gci, remove it + ndbout_c("ndb: flushing incomplete epoch %lld (<%lld)", tmp->m_gci, gci); + if(!tmp->m_data.is_empty()) + { + free_list(tmp->m_data); + } + tmp->~Gci_container(); + bzero(tmp, sizeof(Gci_container)); + } + } + return 0; +} + NdbEventOperation * NdbEventBuffer::nextEvent() { @@ -1153,7 +1190,10 @@ NdbEventBuffer::nextEvent() } EventBufData_list::Gci_ops *gci_ops = m_available_data.first_gci_ops(); while (gci_ops && op->getGCI() > gci_ops->m_gci) + { + deleteUsedEventOperations(); gci_ops = m_available_data.next_gci_ops(); + } assert(gci_ops && (op->getGCI() == gci_ops->m_gci)); DBUG_RETURN_EVENT(op->m_facade); } @@ -1173,7 +1213,10 @@ NdbEventBuffer::nextEvent() // free all "per gci unique" collected operations EventBufData_list::Gci_ops *gci_ops = m_available_data.first_gci_ops(); while (gci_ops) + { + deleteUsedEventOperations(); gci_ops = m_available_data.next_gci_ops(); + } DBUG_RETURN_EVENT(0); } @@ -1187,31 +1230,37 @@ NdbEventBuffer::getGCIEventOperations(Uint32* iter, Uint32* event_types) EventBufData_list::Gci_op g = gci_ops->m_gci_op_list[(*iter)++]; if (event_types != NULL) *event_types = g.event_types; - DBUG_PRINT("info", ("gci: %d", (unsigned)gci_ops->m_gci)); + DBUG_PRINT("info", ("gci: %d g.op: %x g.event_types: %x", + (unsigned)gci_ops->m_gci, g.op, g.event_types)); DBUG_RETURN(g.op); } DBUG_RETURN(NULL); } void -NdbEventBuffer::lock() +NdbEventBuffer::deleteUsedEventOperations() { - NdbMutex_Lock(m_mutex); -} -void -NdbEventBuffer::unlock() -{ - NdbMutex_Unlock(m_mutex); -} -void -NdbEventBuffer::add_drop_lock() -{ - NdbMutex_Lock(p_add_drop_mutex); -} -void -NdbEventBuffer::add_drop_unlock() -{ - NdbMutex_Unlock(p_add_drop_mutex); + Uint32 iter= 0; + const NdbEventOperation *op_f; + while ((op_f= getGCIEventOperations(&iter, NULL)) != NULL) + { + NdbEventOperationImpl *op = &op_f->m_impl; + DBUG_ASSERT(op->m_ref_count > 0); + op->m_ref_count--; + DBUG_PRINT("info", ("m_ref_count: %u for op: %p", op->m_ref_count, op)); + if (op->m_ref_count == 0) + { + DBUG_PRINT("info", ("deleting op: %p", op)); + DBUG_ASSERT(op->m_node_bit_mask.isclear()); + if (op->m_next) + op->m_next->m_prev = op->m_prev; + if (op->m_prev) + op->m_prev->m_next = op->m_next; + else + m_dropped_ev_op = op->m_next; + delete op->m_facade; + } + } } static @@ -1465,6 +1514,10 @@ NdbEventBuffer::complete_outof_order_gcis() void NdbEventBuffer::report_node_failure(Uint32 node_id) { + NdbEventOperation* op= m_ndb->getEventOperation(0); + if (op == 0) + return; + DBUG_ENTER("NdbEventBuffer::report_node_failure"); SubTableData data; LinearSectionPtr ptr[3]; @@ -1476,15 +1529,24 @@ NdbEventBuffer::report_node_failure(Uint32 node_id) data.req_nodeid = (Uint8)node_id; data.ndbd_nodeid = (Uint8)node_id; data.logType = SubTableData::LOG; + data.gci = m_latestGCI + 1; /** * Insert this event for each operation */ - NdbEventOperation* op= 0; - while((op = m_ndb->getEventOperation(op))) { - NdbEventOperationImpl* impl= &op->m_impl; - data.senderData = impl->m_oid; - insertDataL(impl, &data, ptr); + // no need to lock()/unlock(), receive thread calls this + NdbEventOperationImpl* impl = &op->m_impl; + do if (!impl->m_node_bit_mask.isclear()) + { + data.senderData = impl->m_oid; + insertDataL(impl, &data, ptr); + } while((impl = impl->m_next)); + for (impl = m_dropped_ev_op; impl; impl = impl->m_next) + if (!impl->m_node_bit_mask.isclear()) + { + data.senderData = impl->m_oid; + insertDataL(impl, &data, ptr); + } } DBUG_VOID_RETURN; } @@ -1492,8 +1554,11 @@ NdbEventBuffer::report_node_failure(Uint32 node_id) void NdbEventBuffer::completeClusterFailed() { - DBUG_ENTER("NdbEventBuffer::completeClusterFailed"); + NdbEventOperation* op= m_ndb->getEventOperation(0); + if (op == 0) + return; + DBUG_ENTER("NdbEventBuffer::completeClusterFailed"); SubTableData data; LinearSectionPtr ptr[3]; bzero(&data, sizeof(data)); @@ -1502,73 +1567,79 @@ NdbEventBuffer::completeClusterFailed() data.tableId = ~0; data.operation = NdbDictionary::Event::_TE_CLUSTER_FAILURE; data.logType = SubTableData::LOG; - + data.gci = m_latestGCI + 1; + /** - * Find min not completed GCI + * Insert this event for each operation */ - Uint32 sz= m_active_gci.size(); - Uint64 gci= ~0; - Gci_container* bucket = 0; - Gci_container* array = (Gci_container*)m_active_gci.getBase(); - for(Uint32 i = 0; i<sz; i++) { - if(array[i].m_gcp_complete_rep_count && array[i].m_gci < gci) + // no need to lock()/unlock(), receive thread calls this + NdbEventOperationImpl* impl = &op->m_impl; + do if (!impl->m_node_bit_mask.isclear()) { - bucket= array + i; - gci = bucket->m_gci; - } - } - - if(bucket == 0) - { - /** - * Did not find any not completed GCI's - * lets fake one... - */ - gci = m_latestGCI + 1; - bucket = array + ( gci & ACTIVE_GCI_MASK ); - bucket->m_gcp_complete_rep_count = 1; + data.senderData = impl->m_oid; + insertDataL(impl, &data, ptr); + } while((impl = impl->m_next)); + for (impl = m_dropped_ev_op; impl; impl = impl->m_next) + if (!impl->m_node_bit_mask.isclear()) + { + data.senderData = impl->m_oid; + insertDataL(impl, &data, ptr); + } } - const Uint32 cnt= bucket->m_gcp_complete_rep_count = 1; - /** - * Release all GCI's + * Release all GCI's with m_gci > gci */ - for(Uint32 i = 0; i<sz; i++) + Uint32 i; + Uint32 sz= m_active_gci.size(); + Uint64 gci= data.gci; + Gci_container* bucket = 0; + Gci_container* array = (Gci_container*)m_active_gci.getBase(); + for(i = 0; i < sz; i++) { Gci_container* tmp = array + i; - if(!tmp->m_data.is_empty()) + if (tmp->m_gci > gci) { - free_list(tmp->m_data); -#if 0 - m_free_data_count++; - EventBufData* loop= tmp->m_head; - while(loop != tmp->m_tail) + if(!tmp->m_data.is_empty()) { - m_free_data_count++; - loop = loop->m_next; + free_list(tmp->m_data); } -#endif + tmp->~Gci_container(); + bzero(tmp, sizeof(Gci_container)); + } + else if (tmp->m_gcp_complete_rep_count) + { + if (tmp->m_gci == gci) + { + bucket= tmp; + continue; + } + // we have found an old not-completed gci + // something is wrong, assert in debug, but try so salvage + // in release + ndbout_c("out of order bucket detected at cluster disconnect, " + "data.gci: %u. tmp->m_gci: %u", + (unsigned)data.gci, (unsigned)tmp->m_gci); + assert(false); + if(!tmp->m_data.is_empty()) + { + free_list(tmp->m_data); + } + tmp->~Gci_container(); + bzero(tmp, sizeof(Gci_container)); } - bzero(tmp, sizeof(Gci_container)); } - - bucket->m_gci = gci; - bucket->m_gcp_complete_rep_count = cnt; - - data.gci = gci; - - /** - * Insert this event for each operation - */ - NdbEventOperation* op= 0; - while((op = m_ndb->getEventOperation(op))) + + if (bucket == 0) { - NdbEventOperationImpl* impl= &op->m_impl; - data.senderData = impl->m_oid; - insertDataL(impl, &data, ptr); + // no bucket to complete + DBUG_VOID_RETURN; } + + const Uint32 cnt= bucket->m_gcp_complete_rep_count = 1; + bucket->m_gci = gci; + bucket->m_gcp_complete_rep_count = cnt; /** * And finally complete this GCI @@ -1594,6 +1665,40 @@ NdbEventBuffer::insertDataL(NdbEventOperationImpl *op, { DBUG_ENTER_EVENT("NdbEventBuffer::insertDataL"); Uint64 gci= sdata->gci; + const bool is_data_event = + sdata->operation < NdbDictionary::Event::_TE_FIRST_NON_DATA_EVENT; + + if (!is_data_event) + { + switch (sdata->operation) + { + case NdbDictionary::Event::_TE_NODE_FAILURE: + op->m_node_bit_mask.clear(sdata->ndbd_nodeid); + break; + case NdbDictionary::Event::_TE_ACTIVE: + op->m_node_bit_mask.set(sdata->ndbd_nodeid); + // internal event, do not relay to user + DBUG_RETURN_EVENT(0); + break; + case NdbDictionary::Event::_TE_CLUSTER_FAILURE: + op->m_node_bit_mask.clear(); + DBUG_ASSERT(op->m_ref_count > 0); + op->m_ref_count--; + DBUG_PRINT("info", ("m_ref_count: %u for op: %p", op->m_ref_count, op)); + break; + case NdbDictionary::Event::_TE_STOP: + op->m_node_bit_mask.clear(sdata->ndbd_nodeid); + if (op->m_node_bit_mask.isclear()) + { + DBUG_ASSERT(op->m_ref_count > 0); + op->m_ref_count--; + DBUG_PRINT("info", ("m_ref_count: %u for op: %p", op->m_ref_count, op)); + } + break; + default: + break; + } + } if ( likely((Uint32)op->mi_type & (1 << (Uint32)sdata->operation)) ) { @@ -1614,8 +1719,6 @@ NdbEventBuffer::insertDataL(NdbEventOperationImpl *op, } const bool is_blob_event = (op->theMainOp != NULL); - const bool is_data_event = - sdata->operation < NdbDictionary::Event::_TE_FIRST_NON_DATA_EVENT; const bool use_hash = op->m_mergeEvents && is_data_event; if (! is_data_event && is_blob_event) @@ -2243,6 +2346,8 @@ void EventBufData_list::append_list(EventBufData_list *list, Uint64 gci) void EventBufData_list::add_gci_op(Gci_op g, bool del) { + DBUG_ENTER_EVENT("EventBufData_list::add_gci_op"); + DBUG_PRINT_EVENT("info", ("p.op: %p g.event_types: %x", g.op, g.event_types)); assert(g.op != NULL); Uint32 i; for (i = 0; i < m_gci_op_count; i++) { @@ -2262,19 +2367,33 @@ EventBufData_list::add_gci_op(Gci_op g, bool del) if (m_gci_op_alloc != 0) { Uint32 bytes = m_gci_op_alloc * sizeof(Gci_op); memcpy(m_gci_op_list, old_list, bytes); + DBUG_PRINT_EVENT("info", ("this: %p delete m_gci_op_list: %p", + this, old_list)); delete [] old_list; } + DBUG_PRINT_EVENT("info", ("this: %p new m_gci_op_list: %p", + this, m_gci_op_list)); m_gci_op_alloc = n; } assert(m_gci_op_count < m_gci_op_alloc); assert(! del); +#ifndef DBUG_OFF + i = m_gci_op_count; +#endif + g.op->m_ref_count++; + DBUG_PRINT("info", ("m_ref_count: %u for op: %p", g.op->m_ref_count, g.op)); m_gci_op_list[m_gci_op_count++] = g; } + DBUG_PRINT_EVENT("exit", ("m_gci_op_list[%u].event_types: %x", i, m_gci_op_list[i].event_types)); + DBUG_VOID_RETURN_EVENT; } void EventBufData_list::move_gci_ops(EventBufData_list *list, Uint64 gci) { + DBUG_ENTER_EVENT("EventBufData_list::move_gci_ops"); + DBUG_PRINT_EVENT("info", ("this: %p list: %p gci: %llu", + this, list, gci)); assert(!m_is_not_multi_list); if (!list->m_is_not_multi_list) { @@ -2290,6 +2409,8 @@ EventBufData_list::move_gci_ops(EventBufData_list *list, Uint64 gci) } { Gci_ops *new_gci_ops = new Gci_ops; + DBUG_PRINT_EVENT("info", ("this: %p m_gci_op_list: %p", + new_gci_ops, list->m_gci_op_list)); if (m_gci_ops_list_tail) m_gci_ops_list_tail->m_next = new_gci_ops; else @@ -2308,6 +2429,7 @@ end: list->m_gci_op_list = 0; list->m_gci_ops_list_tail = 0; list->m_gci_op_alloc = 0; + DBUG_VOID_RETURN_EVENT; } NdbEventOperation* @@ -2326,6 +2448,9 @@ NdbEventBuffer::createEventOperation(const char* eventName, delete tOp; DBUG_RETURN(NULL); } + getEventOperationImpl(tOp)->m_ref_count = 1; + DBUG_PRINT("info", ("m_ref_count: %u for op: %p", + getEventOperationImpl(tOp)->m_ref_count, getEventOperationImpl(tOp))); DBUG_RETURN(tOp); } @@ -2351,16 +2476,10 @@ NdbEventBuffer::createEventOperation(NdbEventImpl& evnt, void NdbEventBuffer::dropEventOperation(NdbEventOperation* tOp) { + DBUG_ENTER("NdbEventBuffer::dropEventOperation"); NdbEventOperationImpl* op= getEventOperationImpl(tOp); op->stop(); - - op->m_next= m_dropped_ev_op; - op->m_prev= 0; - if (m_dropped_ev_op) - m_dropped_ev_op->m_prev= op; - m_dropped_ev_op= op; - // stop blob event ops if (op->theMainOp == NULL) { @@ -2380,11 +2499,24 @@ NdbEventBuffer::dropEventOperation(NdbEventOperation* tOp) } } - // ToDo, take care of these to be deleted at the - // appropriate time, after we are sure that there - // are _no_ more events coming - - // delete tOp; + DBUG_ASSERT(op->m_ref_count > 0); + op->m_ref_count--; + DBUG_PRINT("info", ("m_ref_count: %u for op: %p", op->m_ref_count, op)); + if (op->m_ref_count == 0) + { + DBUG_PRINT("info", ("deleting op: %p", op)); + DBUG_ASSERT(op->m_node_bit_mask.isclear()); + delete op->m_facade; + } + else + { + op->m_next= m_dropped_ev_op; + op->m_prev= 0; + if (m_dropped_ev_op) + m_dropped_ev_op->m_prev= op; + m_dropped_ev_op= op; + } + DBUG_VOID_RETURN; } void diff --git a/storage/ndb/src/ndbapi/NdbEventOperationImpl.hpp b/storage/ndb/src/ndbapi/NdbEventOperationImpl.hpp index 8d413cc8d14..bcae650bf44 100644 --- a/storage/ndb/src/ndbapi/NdbEventOperationImpl.hpp +++ b/storage/ndb/src/ndbapi/NdbEventOperationImpl.hpp @@ -25,6 +25,20 @@ #include <UtilBuffer.hpp> #define NDB_EVENT_OP_MAGIC_NUMBER 0xA9F301B4 +//#define EVENT_DEBUG +#ifdef EVENT_DEBUG +#define DBUG_ENTER_EVENT(A) DBUG_ENTER(A) +#define DBUG_RETURN_EVENT(A) DBUG_RETURN(A) +#define DBUG_VOID_RETURN_EVENT DBUG_VOID_RETURN +#define DBUG_PRINT_EVENT(A,B) DBUG_PRINT(A,B) +#define DBUG_DUMP_EVENT(A,B,C) DBUG_DUMP(A,B,C) +#else +#define DBUG_ENTER_EVENT(A) +#define DBUG_RETURN_EVENT(A) return(A) +#define DBUG_VOID_RETURN_EVENT return +#define DBUG_PRINT_EVENT(A,B) +#define DBUG_DUMP_EVENT(A,B,C) +#endif class NdbEventOperationImpl; @@ -149,19 +163,29 @@ EventBufData_list::EventBufData_list() m_gci_ops_list_tail(0), m_gci_op_alloc(0) { + DBUG_ENTER_EVENT("EventBufData_list::EventBufData_list"); + DBUG_PRINT_EVENT("info", ("this: %p", this)); + DBUG_VOID_RETURN_EVENT; } inline EventBufData_list::~EventBufData_list() { + DBUG_ENTER_EVENT("EventBufData_list::~EventBufData_list"); + DBUG_PRINT_EVENT("info", ("this: %p m_is_not_multi_list: %u", + this, m_is_not_multi_list)); if (m_is_not_multi_list) + { + DBUG_PRINT_EVENT("info", ("delete m_gci_op_list: %p", m_gci_op_list)); delete [] m_gci_op_list; + } else { Gci_ops *op = first_gci_ops(); while (op) op = next_gci_ops(); } + DBUG_VOID_RETURN_EVENT; } inline @@ -223,7 +247,11 @@ EventBufData_list::next_gci_ops() Gci_ops *first = m_gci_ops_list; m_gci_ops_list = first->m_next; if (first->m_gci_op_list) + { + DBUG_PRINT_EVENT("info", ("this: %p delete m_gci_op_list: %p", + this, first->m_gci_op_list)); delete [] first->m_gci_op_list; + } delete first; if (m_gci_ops_list == 0) m_gci_ops_list_tail = 0; @@ -339,6 +367,8 @@ public: Uint32 m_eventId; Uint32 m_oid; + Bitmask<(unsigned int)_NDB_NODE_BITMASK_SIZE> m_node_bit_mask; + int m_ref_count; bool m_mergeEvents; EventBufData *m_data_item; @@ -378,10 +408,10 @@ public: void dropEventOperation(NdbEventOperation *); static NdbEventOperationImpl* getEventOperationImpl(NdbEventOperation* tOp); - void add_drop_lock(); - void add_drop_unlock(); - void lock(); - void unlock(); + void add_drop_lock() { NdbMutex_Lock(p_add_drop_mutex); } + void add_drop_unlock() { NdbMutex_Unlock(p_add_drop_mutex); } + void lock() { NdbMutex_Lock(m_mutex); } + void unlock() { NdbMutex_Unlock(m_mutex); } void add_op(); void remove_op(); @@ -402,9 +432,11 @@ public: Uint32 getEventId(int bufferId); int pollEvents(int aMillisecondNumber, Uint64 *latestGCI= 0); + int flushIncompleteEvents(Uint64 gci); NdbEventOperation *nextEvent(); NdbEventOperationImpl* getGCIEventOperations(Uint32* iter, Uint32* event_types); + void deleteUsedEventOperations(); NdbEventOperationImpl *move_data(); diff --git a/storage/ndb/src/ndbapi/NdbImpl.hpp b/storage/ndb/src/ndbapi/NdbImpl.hpp index 82795550381..3b7b8cf44fb 100644 --- a/storage/ndb/src/ndbapi/NdbImpl.hpp +++ b/storage/ndb/src/ndbapi/NdbImpl.hpp @@ -93,6 +93,8 @@ public: m_schemaname.c_str(), table_name_separator); } + BaseString m_systemPrefix; // Buffer for preformatted for <sys>/<def>/ + /** * NOTE free lists must be _after_ theNdbObjectIdMap take * assure that destructors are run in correct order diff --git a/storage/ndb/src/ndbapi/NdbTransaction.cpp b/storage/ndb/src/ndbapi/NdbTransaction.cpp index 3158dca5c40..916135b12d5 100644 --- a/storage/ndb/src/ndbapi/NdbTransaction.cpp +++ b/storage/ndb/src/ndbapi/NdbTransaction.cpp @@ -32,6 +32,8 @@ #include <signaldata/TcKeyFailConf.hpp> #include <signaldata/TcHbRep.hpp> +Uint64 g_latest_trans_gci = 0; + /***************************************************************************** NdbTransaction( Ndb* aNdb ); @@ -1568,6 +1570,9 @@ NdbTransaction::receiveTC_COMMITCONF(const TcCommitConf * commitConf) theCommitStatus = Committed; theCompletionStatus = CompletedSuccess; theGlobalCheckpointId = commitConf->gci; + // theGlobalCheckpointId == 0 if NoOp transaction + if (theGlobalCheckpointId) + g_latest_trans_gci = theGlobalCheckpointId; return 0; } else { #ifdef NDB_NO_DROPPED_SIGNAL @@ -1746,6 +1751,8 @@ from other transactions. if (tCommitFlag == 1) { theCommitStatus = Committed; theGlobalCheckpointId = tGCI; + assert(tGCI); + g_latest_trans_gci = tGCI; } else if ((tNoComp >= tNoSent) && (theLastExecOpInList->theCommitIndicator == 1)){ @@ -1922,6 +1929,8 @@ NdbTransaction::receiveTCINDXCONF(const TcIndxConf * indxConf, if (tCommitFlag == 1) { theCommitStatus = Committed; theGlobalCheckpointId = tGCI; + assert(tGCI); + g_latest_trans_gci = tGCI; } else if ((tNoComp >= tNoSent) && (theLastExecOpInList->theCommitIndicator == 1)){ /**********************************************************************/ diff --git a/storage/ndb/src/ndbapi/Ndbif.cpp b/storage/ndb/src/ndbapi/Ndbif.cpp index 7799a71749e..ecaf6a3f435 100644 --- a/storage/ndb/src/ndbapi/Ndbif.cpp +++ b/storage/ndb/src/ndbapi/Ndbif.cpp @@ -46,7 +46,6 @@ #include <EventLogger.hpp> extern EventLogger g_eventLogger; -Uint64 g_latest_trans_gci= 0; /****************************************************************************** * int init( int aNrOfCon, int aNrOfOp ); @@ -367,7 +366,6 @@ Ndb::handleReceivedSignal(NdbApiSignal* aSignal, LinearSectionPtr ptr[3]) tCon = void2con(tFirstDataPtr); if ((tCon->checkMagicNumber() == 0) && (tCon->theSendStatus == NdbTransaction::sendTC_OP)) { - g_latest_trans_gci= keyConf->gci; tReturnCode = tCon->receiveTCKEYCONF(keyConf, tLen); if (tReturnCode != -1) { completedTransaction(tCon); @@ -520,7 +518,6 @@ Ndb::handleReceivedSignal(NdbApiSignal* aSignal, LinearSectionPtr ptr[3]) tCon = void2con(tFirstDataPtr); if ((tCon->checkMagicNumber() == 0) && (tCon->theSendStatus == NdbTransaction::sendTC_COMMIT)) { - g_latest_trans_gci= commitConf->gci; tReturnCode = tCon->receiveTC_COMMITCONF(commitConf); if (tReturnCode != -1) { completedTransaction(tCon); @@ -855,7 +852,6 @@ Ndb::handleReceivedSignal(NdbApiSignal* aSignal, LinearSectionPtr ptr[3]) tCon = void2con(tFirstDataPtr); if ((tCon->checkMagicNumber() == 0) && (tCon->theSendStatus == NdbTransaction::sendTC_OP)) { - g_latest_trans_gci= indxConf->gci; tReturnCode = tCon->receiveTCINDXCONF(indxConf, tLen); if (tReturnCode != -1) { completedTransaction(tCon); diff --git a/storage/ndb/src/ndbapi/Ndbinit.cpp b/storage/ndb/src/ndbapi/Ndbinit.cpp index e41380e6484..5c0fb521c36 100644 --- a/storage/ndb/src/ndbapi/Ndbinit.cpp +++ b/storage/ndb/src/ndbapi/Ndbinit.cpp @@ -100,10 +100,6 @@ void Ndb::setup(Ndb_cluster_connection *ndb_cluster_connection, theConnectionArray[i] = NULL; }//forg m_sys_tab_0 = NULL; - for (i = 0; i < 2048 ; i++) { - theFirstTupleId[i] = 0; - theLastTupleId[i] = 0; - }//for theImpl->m_dbname.assign(aDataBase); theImpl->m_schemaname.assign(aSchema); @@ -223,6 +219,9 @@ NdbImpl::NdbImpl(Ndb_cluster_connection *ndb_cluster_connection, } m_optimized_node_selection= m_ndb_cluster_connection.m_optimized_node_selection; + + m_systemPrefix.assfmt("%s%c%s%c", NDB_SYSTEM_DATABASE, table_name_separator, + NDB_SYSTEM_SCHEMA, table_name_separator); } NdbImpl::~NdbImpl() diff --git a/storage/ndb/src/ndbapi/SignalSender.cpp b/storage/ndb/src/ndbapi/SignalSender.cpp index a29fe68937b..0ecc98f5f29 100644 --- a/storage/ndb/src/ndbapi/SignalSender.cpp +++ b/storage/ndb/src/ndbapi/SignalSender.cpp @@ -75,7 +75,9 @@ SignalSender::SignalSender(TransporterFacade *facade) { m_cond = NdbCondition_Create(); theFacade = facade; + lock(); m_blockNo = theFacade->open(this, execSignal, execNodeStatus); + unlock(); assert(m_blockNo > 0); } diff --git a/storage/ndb/src/ndbapi/TransporterFacade.hpp b/storage/ndb/src/ndbapi/TransporterFacade.hpp index eb2f162da88..2d47a2febf8 100644 --- a/storage/ndb/src/ndbapi/TransporterFacade.hpp +++ b/storage/ndb/src/ndbapi/TransporterFacade.hpp @@ -319,6 +319,12 @@ TransporterFacade::unlock_mutex() #include "ClusterMgr.hpp" inline +unsigned Ndb_cluster_connection_impl::get_connect_count() const +{ + return m_transporter_facade->theClusterMgr->m_connect_count; +} + +inline bool TransporterFacade::check_send_size(Uint32 node_id, Uint32 send_size) { diff --git a/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp b/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp index 544f7424a82..a7e645f5100 100644 --- a/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp +++ b/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp @@ -253,6 +253,12 @@ Ndb_cluster_connection::wait_until_ready(int timeout, } while (1); } +unsigned Ndb_cluster_connection::get_connect_count() const +{ + return m_impl.get_connect_count(); +} + + /* diff --git a/storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp b/storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp index db6e1f9e6ed..6f0df0403d9 100644 --- a/storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp +++ b/storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp @@ -40,6 +40,7 @@ class Ndb_cluster_connection_impl : public Ndb_cluster_connection void init_get_next_node(Ndb_cluster_connection_node_iter &iter); Uint32 get_next_node(Ndb_cluster_connection_node_iter &iter); + inline unsigned get_connect_count() const; private: friend class Ndb; friend class NdbImpl; diff --git a/storage/ndb/src/ndbapi/ndberror.c b/storage/ndb/src/ndbapi/ndberror.c index 8185bf38c3e..c05924dacf8 100644 --- a/storage/ndb/src/ndbapi/ndberror.c +++ b/storage/ndb/src/ndbapi/ndberror.c @@ -600,7 +600,6 @@ ErrorBundle ErrorCodes[] = { { 4269, DMEC, IE, "No connection to ndb management server" }, { 4270, DMEC, IE, "Unknown blob error" }, { 4335, DMEC, AE, "Only one autoincrement column allowed per table. Having a table without primary key uses an autoincremented hidden key, i.e. a table without a primary key can not have an autoincremented column" }, - { 4336, DMEC, AE, "Auto-increment value set below current value" }, { 4271, DMEC, AE, "Invalid index object, not retrieved via getIndex()" }, { 4272, DMEC, AE, "Table definition has undefined column" }, { 4273, DMEC, IE, "No blob table in dict cache" }, diff --git a/storage/ndb/test/ndbapi/Makefile.am b/storage/ndb/test/ndbapi/Makefile.am index 9a1e1c5e9ea..b55acd2420d 100644 --- a/storage/ndb/test/ndbapi/Makefile.am +++ b/storage/ndb/test/ndbapi/Makefile.am @@ -24,6 +24,7 @@ testOIBasic \ testOperations \ testRestartGci \ testScan \ +testInterpreter \ testScanInterpreter \ testScanPerf \ testSystemRestart \ @@ -64,6 +65,7 @@ testOIBasic_SOURCES = testOIBasic.cpp testOperations_SOURCES = testOperations.cpp testRestartGci_SOURCES = testRestartGci.cpp testScan_SOURCES = testScan.cpp ScanFunctions.hpp +testInterpreter_SOURCES = testInterpreter.cpp testScanInterpreter_SOURCES = testScanInterpreter.cpp ScanFilter.hpp ScanInterpretTest.hpp testScanPerf_SOURCES = testScanPerf.cpp testSystemRestart_SOURCES = testSystemRestart.cpp diff --git a/storage/ndb/test/ndbapi/testDict.cpp b/storage/ndb/test/ndbapi/testDict.cpp index 7ade359342d..b015e16bae1 100644 --- a/storage/ndb/test/ndbapi/testDict.cpp +++ b/storage/ndb/test/ndbapi/testDict.cpp @@ -1139,9 +1139,13 @@ runCreateAutoincrementTable(NDBT_Context* ctx, NDBT_Step* step){ for (int i = 0; i < 16; i++) { - Uint64 value = myNdb->getAutoIncrementValue(tabname, 1); - - if (value != (startvalue+i)) { + Uint64 value; + if (myNdb->getAutoIncrementValue(tabname, value, 1) == -1) { + g_err << "getAutoIncrementValue failed on " << tabname << endl; + APIERROR(myNdb->getNdbError()); + return NDBT_FAILED; + } + else if (value != (startvalue+i)) { g_err << "value = " << value << " expected " << startvalue+i << endl;; APIERROR(myNdb->getNdbError()); // ret = NDBT_FAILED; diff --git a/storage/ndb/test/ndbapi/testInterpreter.cpp b/storage/ndb/test/ndbapi/testInterpreter.cpp index 0baba33d2b2..5d930d3d555 100644 --- a/storage/ndb/test/ndbapi/testInterpreter.cpp +++ b/storage/ndb/test/ndbapi/testInterpreter.cpp @@ -79,46 +79,46 @@ int runTestIncValue32(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); - NdbConnection* pTrans = pNdb->startTransaction(); - if (pTrans == NULL){ - ERR(pNdb->getNdbError()); - return NDBT_FAILED; - } - - NdbOperation* pOp = pTrans->getNdbOperation(pTab->getName()); - if (pOp == NULL) { - ERR(pTrans->getNdbError()); - pNdb->closeTransaction(pTrans); - return NDBT_FAILED; - } - - int check = pOp->interpretedUpdateTuple(); - if( check == -1 ) { - ERR(pTrans->getNdbError()); - pNdb->closeTransaction(pTrans); - return NDBT_FAILED; - } - - - // Primary keys - Uint32 pkVal = 1; - check = pOp->equal("KOL1", pkVal ); - if( check == -1 ) { - ERR(pTrans->getNdbError()); - pNdb->closeTransaction(pTrans); - return NDBT_FAILED; - } - - // Attributes - - // Update column - Uint32 valToIncWith = 1; - check = pOp->incValue("KOL2", valToIncWith); - if( check == -1 ) { - ERR(pTrans->getNdbError()); - pNdb->closeTransaction(pTrans); - return NDBT_FAILED; - } + NdbConnection* pTrans = pNdb->startTransaction(); + if (pTrans == NULL){ + ERR(pNdb->getNdbError()); + return NDBT_FAILED; + } + + NdbOperation* pOp = pTrans->getNdbOperation(pTab->getName()); + if (pOp == NULL) { + ERR(pTrans->getNdbError()); + pNdb->closeTransaction(pTrans); + return NDBT_FAILED; + } + + int check = pOp->interpretedUpdateTuple(); + if( check == -1 ) { + ERR(pTrans->getNdbError()); + pNdb->closeTransaction(pTrans); + return NDBT_FAILED; + } + + + // Primary keys + Uint32 pkVal = 1; + check = pOp->equal("KOL1", pkVal ); + if( check == -1 ) { + ERR(pTrans->getNdbError()); + pNdb->closeTransaction(pTrans); + return NDBT_FAILED; + } + + // Attributes + + // Update column + Uint32 valToIncWith = 1; + check = pOp->incValue("KOL2", valToIncWith); + if( check == -1 ) { + ERR(pTrans->getNdbError()); + pNdb->closeTransaction(pTrans); + return NDBT_FAILED; + } NdbRecAttr* valueRec = pOp->getValue("KOL2"); if( valueRec == NULL ) { @@ -142,6 +142,122 @@ int runTestIncValue32(NDBT_Context* ctx, NDBT_Step* step){ return NDBT_OK; } +int runTestBug19537(NDBT_Context* ctx, NDBT_Step* step){ + int result = NDBT_OK; + const NdbDictionary::Table * pTab = ctx->getTab(); + Ndb* pNdb = GETNDB(step); + + if (strcmp(pTab->getName(), "T1") != 0) { + g_err << "runTestBug19537: skip, table != T1" << endl; + return NDBT_OK; + } + + + NdbConnection* pTrans = pNdb->startTransaction(); + if (pTrans == NULL){ + ERR(pNdb->getNdbError()); + return NDBT_FAILED; + } + + NdbOperation* pOp = pTrans->getNdbOperation(pTab->getName()); + if (pOp == NULL) { + ERR(pTrans->getNdbError()); + pNdb->closeTransaction(pTrans); + return NDBT_FAILED; + } + + if (pOp->interpretedUpdateTuple() == -1) { + ERR(pOp->getNdbError()); + pNdb->closeTransaction(pTrans); + return NDBT_FAILED; + } + + + // Primary keys + const Uint32 pkVal = 1; + if (pOp->equal("KOL1", pkVal) == -1) { + ERR(pTrans->getNdbError()); + pNdb->closeTransaction(pTrans); + return NDBT_FAILED; + } + + // Load 64-bit constant into register 1 and + // write from register 1 to 32-bit column KOL2 + const Uint64 reg_val = 0x0102030405060708ULL; + + const Uint32* reg_ptr32 = (const Uint32*)®_val; + if (reg_ptr32[0] == 0x05060708 && reg_ptr32[1] == 0x01020304) { + g_err << "runTestBug19537: platform is LITTLE endian" << endl; + } else if (reg_ptr32[0] == 0x01020304 && reg_ptr32[1] == 0x05060708) { + g_err << "runTestBug19537: platform is BIG endian" << endl; + } else { + g_err << "runTestBug19537: impossible platform" + << hex << " [0]=" << reg_ptr32[0] << " [1]=" <<reg_ptr32[1] << endl; + pNdb->closeTransaction(pTrans); + return NDBT_FAILED; + } + + if (pOp->load_const_u64(1, reg_val) == -1 || + pOp->write_attr("KOL2", 1) == -1) { + ERR(pOp->getNdbError()); + pNdb->closeTransaction(pTrans); + return NDBT_FAILED; + } + + if (pTrans->execute(Commit) == -1) { + ERR(pTrans->getNdbError()); + pNdb->closeTransaction(pTrans); + return NDBT_FAILED; + } + + // Read value via a new transaction + + pTrans = pNdb->startTransaction(); + if (pTrans == NULL){ + ERR(pNdb->getNdbError()); + return NDBT_FAILED; + } + + pOp = pTrans->getNdbOperation(pTab->getName()); + if (pOp == NULL) { + ERR(pTrans->getNdbError()); + pNdb->closeTransaction(pTrans); + return NDBT_FAILED; + } + + Uint32 kol2 = 0x09090909; + if (pOp->readTuple() == -1 || + pOp->equal("KOL1", pkVal) == -1 || + pOp->getValue("KOL2", (char*)&kol2) == 0) { + ERR(pOp->getNdbError()); + pNdb->closeTransaction(pTrans); + return NDBT_FAILED; + } + + if (pTrans->execute(Commit) == -1) { + ERR(pTrans->getNdbError()); + pNdb->closeTransaction(pTrans); + return NDBT_FAILED; + } + + // Expected conversion as in C - truncate to lower (logical) word + + if (kol2 == 0x01020304) { + g_err << "runTestBug19537: the bug manifests itself !" << endl; + pNdb->closeTransaction(pTrans); + return NDBT_FAILED; + } + + if (kol2 != 0x05060708) { + g_err << "runTestBug19537: impossible KOL2 " << hex << kol2 << endl; + pNdb->closeTransaction(pTrans); + return NDBT_FAILED; + } + + pNdb->closeTransaction(pTrans); + return NDBT_OK; +} + NDBT_TESTSUITE(testInterpreter); TESTCASE("IncValue32", @@ -156,6 +272,12 @@ TESTCASE("IncValue64", INITIALIZER(runTestIncValue64); FINALIZER(runClearTable); } +TESTCASE("Bug19537", + "Test big-endian write_attr of 32 bit integer\n"){ + INITIALIZER(runLoadTable); + INITIALIZER(runTestBug19537); + FINALIZER(runClearTable); +} #if 0 TESTCASE("MaxTransactions", "Start transactions until no more can be created\n"){ diff --git a/storage/ndb/test/ndbapi/testNodeRestart.cpp b/storage/ndb/test/ndbapi/testNodeRestart.cpp index aed0b39f196..754b3edc269 100644 --- a/storage/ndb/test/ndbapi/testNodeRestart.cpp +++ b/storage/ndb/test/ndbapi/testNodeRestart.cpp @@ -868,6 +868,56 @@ runBug18612SR(NDBT_Context* ctx, NDBT_Step* step){ return NDBT_OK; } +int runBug20185(NDBT_Context* ctx, NDBT_Step* step){ + int result = NDBT_OK; + int loops = ctx->getNumLoops(); + int records = ctx->getNumRecords(); + NdbRestarter restarter; + HugoOperations hugoOps(*ctx->getTab()); + Ndb* pNdb = GETNDB(step); + + int dump[] = { 7090, 20 } ; + if (restarter.dumpStateAllNodes(dump, 2)) + return NDBT_FAILED; + + NdbSleep_MilliSleep(3000); + + if(hugoOps.startTransaction(pNdb) != 0) + return NDBT_FAILED; + + if(hugoOps.pkUpdateRecord(pNdb, 1, 1) != 0) + return NDBT_FAILED; + + if (hugoOps.execute_NoCommit(pNdb) != 0) + return NDBT_FAILED; + + int nodeId; + const int node = hugoOps.getTransaction()->getConnectedNodeId(); + do { + nodeId = restarter.getDbNodeId(rand() % restarter.getNumDbNodes()); + } while (nodeId == node); + + if (restarter.insertErrorInAllNodes(7030)) + return NDBT_FAILED; + + if (restarter.insertErrorInNode(nodeId, 7031)) + return NDBT_FAILED; + + NdbSleep_MilliSleep(500); + + if (hugoOps.execute_Commit(pNdb) == 0) + return NDBT_FAILED; + + NdbSleep_MilliSleep(3000); + + restarter.waitClusterStarted(); + + if (restarter.dumpStateAllNodes(dump, 1)) + return NDBT_FAILED; + + return NDBT_OK; +} + NDBT_TESTSUITE(testNodeRestart); TESTCASE("NoLoad", @@ -1175,6 +1225,12 @@ TESTCASE("Bug18612SR", STEP(runBug18612SR); FINALIZER(runClearTable); } +TESTCASE("Bug20185", + ""){ + INITIALIZER(runLoadTable); + STEP(runBug20185); + FINALIZER(runClearTable); +} NDBT_TESTSUITE_END(testNodeRestart); int main(int argc, const char** argv){ diff --git a/storage/ndb/test/run-test/daily-basic-tests.txt b/storage/ndb/test/run-test/daily-basic-tests.txt index 3fead45533f..5fe3506dffb 100644 --- a/storage/ndb/test/run-test/daily-basic-tests.txt +++ b/storage/ndb/test/run-test/daily-basic-tests.txt @@ -473,6 +473,10 @@ max-time: 1000 cmd: testNodeRestart args: -n Bug18612SR T1 +max-time: 1000 +cmd: testNodeRestart +args: -n Bug20185 T1 + # # DICT TESTS max-time: 1500 diff --git a/storage/ndb/tools/desc.cpp b/storage/ndb/tools/desc.cpp index 37157ef9eec..7c5ce68c950 100644 --- a/storage/ndb/tools/desc.cpp +++ b/storage/ndb/tools/desc.cpp @@ -18,6 +18,7 @@ #include <ndb_opts.h> #include <NDBT.hpp> #include <NdbApi.hpp> +#include <NdbSleep.h> void desc_AutoGrowSpecification(struct NdbDictionary::AutoGrowSpecification ags); int desc_logfilegroup(Ndb *myndb, char* name); @@ -31,6 +32,7 @@ NDB_STD_OPTS_VARS; static const char* _dbname = "TEST_DB"; static int _unqualified = 0; static int _partinfo = 0; +static int _retries = 0; static struct my_option my_long_options[] = { NDB_STD_OPTS("ndb_desc"), @@ -43,6 +45,9 @@ static struct my_option my_long_options[] = { "extra-partition-info", 'p', "Print more info per partition", (gptr*) &_partinfo, (gptr*) &_partinfo, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, + { "retries", 'r', "Retry every second for # retries", + (gptr*) &_retries, (gptr*) &_retries, 0, + GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; static void usage() @@ -231,7 +236,8 @@ int desc_datafile(Ndb_cluster_connection &con, Ndb *myndb, char* name) int desc_table(Ndb *myndb, char* name) { NdbDictionary::Dictionary * dict= myndb->getDictionary(); - NDBT_Table* pTab = (NDBT_Table*)dict->getTable(name); + NDBT_Table* pTab; + while ((pTab = (NDBT_Table*)dict->getTable(name)) == NULL && --_retries >= 0) NdbSleep_SecSleep(1); if (!pTab) return 0; diff --git a/storage/ndb/tools/restore/consumer_restore.cpp b/storage/ndb/tools/restore/consumer_restore.cpp index 3b39a1373a0..6b0d42ee0d2 100644 --- a/storage/ndb/tools/restore/consumer_restore.cpp +++ b/storage/ndb/tools/restore/consumer_restore.cpp @@ -151,9 +151,12 @@ BackupRestore::finalize_table(const TableS & table){ if (table.have_auto_inc()) { Uint64 max_val= table.get_max_auto_val(); - Uint64 auto_val= m_ndb->readAutoIncrementValue(get_table(table.m_dictTable)); - if (max_val+1 > auto_val || auto_val == ~(Uint64)0) - ret= m_ndb->setAutoIncrementValue(get_table(table.m_dictTable), max_val+1, false); + Uint64 auto_val; + int r= m_ndb->readAutoIncrementValue(get_table(table.m_dictTable), auto_val); + if (r == -1 && m_ndb->getNdbError().code != 626) + ret= false; + else if (r == -1 || max_val+1 > auto_val) + ret= m_ndb->setAutoIncrementValue(get_table(table.m_dictTable), max_val+1, false) != -1; } return ret; } diff --git a/storage/ndb/tools/waiter.cpp b/storage/ndb/tools/waiter.cpp index db90bd8bd90..cb02d5e7c36 100644 --- a/storage/ndb/tools/waiter.cpp +++ b/storage/ndb/tools/waiter.cpp @@ -124,6 +124,12 @@ getStatus(){ ndbout << "status==NULL, retries="<<retries<<endl; MGMERR(handle); retries++; + ndb_mgm_disconnect(handle); + if (ndb_mgm_connect(handle,0,0,1)) { + MGMERR(handle); + g_err << "Reconnect failed" << endl; + break; + } continue; } int count = status->no_of_nodes; diff --git a/strings/cmakelists.txt b/strings/CMakeLists.txt index ab4031f071a..ab4031f071a 100644 --- a/strings/cmakelists.txt +++ b/strings/CMakeLists.txt diff --git a/strings/Makefile.am b/strings/Makefile.am index 1183fcae01a..1cba4bab3f0 100644 --- a/strings/Makefile.am +++ b/strings/Makefile.am @@ -54,7 +54,7 @@ EXTRA_DIST = ctype-big5.c ctype-cp932.c ctype-czech.c ctype-eucjpms.c ctype-euc bmove_upp-sparc.s strappend-sparc.s strend-sparc.s \ strinstr-sparc.s strmake-sparc.s strmov-sparc.s \ strnmov-sparc.s strstr-sparc.s strxmov-sparc.s \ - t_ctype.h my_strchr.c cmakelists.txt + t_ctype.h my_strchr.c CMakeLists.txt libmystrings_a_LIBADD= conf_to_src_SOURCES = conf_to_src.c xml.c ctype.c bcmp.c diff --git a/support-files/mysql.server.sh b/support-files/mysql.server.sh index bf17375c0eb..bd16297f8e7 100644 --- a/support-files/mysql.server.sh +++ b/support-files/mysql.server.sh @@ -265,7 +265,10 @@ case "$mode" in then # Give extra arguments to mysqld with the my.cnf file. This script may # be overwritten at next upgrade. - $manager --user=$user --pid-file=$pid_file >/dev/null 2>&1 & + "$manager" \ + --mysqld-safe-compatible \ + --user="$user" \ + --pid-file="$pid_file" >/dev/null 2>&1 & wait_for_pid created # Make lock for RedHat / SuSE diff --git a/support-files/mysql.spec.sh b/support-files/mysql.spec.sh index c57496e6c55..01746d3156e 100644 --- a/support-files/mysql.spec.sh +++ b/support-files/mysql.spec.sh @@ -217,8 +217,9 @@ sh -c "PATH=\"${MYSQL_BUILD_PATH:-$PATH}\" \ --with-fast-mutexes \ --with-mysqld-user=%{mysqld_user} \ --with-unix-socket-path=/var/lib/mysql/mysql.sock \ + --with-pic \ --prefix=/ \ - --with-extra-charsets=complex \ + --with-extra-charsets=all \ %if %{YASSL_BUILD} --with-yassl \ %endif @@ -319,7 +320,7 @@ BuildMySQL "--enable-shared \ --with-example-storage-engine \ --with-blackhole-storage-engine \ --with-federated-storage-engine \ - --with-big-tables \ + --with-big-tables \ --with-comment=\"MySQL Community Server - Max (GPL)\"") # We might want to save the config log file @@ -553,7 +554,6 @@ fi %attr(755, root, root) %{_bindir}/myisampack %attr(755, root, root) %{_bindir}/mysql_convert_table_format %attr(755, root, root) %{_bindir}/mysql_create_system_tables -%attr(755, root, root) %{_bindir}/mysql_explain_log %attr(755, root, root) %{_bindir}/mysql_fix_extensions %attr(755, root, root) %{_bindir}/mysql_fix_privilege_tables %attr(755, root, root) %{_bindir}/mysql_install_db @@ -683,6 +683,16 @@ fi # itself - note that they must be ordered by date (important when # merging BK trees) %changelog +* Sat May 20 2006 Kent Boortz <kent@mysql.com> + +- Always compile for PIC, position independent code. + +* Wed May 10 2006 Kent Boortz <kent@mysql.com> + +- Use character set "all" when compiling with Cluster, to make Cluster + nodes independent on the character set directory, and the problem + that two RPM sub packages both wants to install this directory. + * Mon May 01 2006 Kent Boortz <kent@mysql.com> - Use "./libtool --mode=execute" instead of searching for the diff --git a/tests/cmakelists.txt b/tests/CMakeLists.txt index 46c42d461f3..46c42d461f3 100644 --- a/tests/cmakelists.txt +++ b/tests/CMakeLists.txt diff --git a/tests/Makefile.am b/tests/Makefile.am index 4cad3c30bdd..8ee64f8179c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -22,6 +22,13 @@ if HAVE_YASSL else yassl_dummy_link_fix= endif + +if THREAD_SAFE_CLIENT +LIBMYSQLCLIENT_LA = $(top_builddir)/libmysql_r/libmysqlclient_r.la +else +LIBMYSQLCLIENT_LA = $(top_builddir)/libmysql/libmysqlclient.la +endif + EXTRA_DIST = auto_increment.res auto_increment.tst \ function.res function.tst lock_test.pl lock_test.res \ export.pl big_record.pl \ @@ -30,7 +37,7 @@ EXTRA_DIST = auto_increment.res auto_increment.tst \ grant.pl grant.res test_delayed_insert.pl \ pmail.pl mail_to_db.pl table_types.pl \ udf_test udf_test.res myisam-big-rows.tst \ - cmakelists.txt + CMakeLists.txt bin_PROGRAMS = mysql_client_test noinst_PROGRAMS = insert_test select_test thread_test @@ -42,7 +49,7 @@ INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \ $(openssl_includes) LIBS = @CLIENT_LIBS@ LDADD = @CLIENT_EXTRA_LDFLAGS@ \ - $(top_builddir)/libmysql/libmysqlclient.la + $(LIBMYSQLCLIENT_LA) mysql_client_test_LDADD= $(LDADD) $(CXXLDFLAGS) -L../mysys -lmysys mysql_client_test_SOURCES= mysql_client_test.c $(yassl_dummy_link_fix) insert_test_SOURCES= insert_test.c $(yassl_dummy_link_fix) diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index d927b27ab37..e3159cfa5e5 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -12794,25 +12794,26 @@ from t2);"); static void test_bug8378() { #if defined(HAVE_CHARSET_gbk) && !defined(EMBEDDED_LIBRARY) - MYSQL *lmysql; + MYSQL *old_mysql=mysql; char out[9]; /* strlen(TEST_BUG8378)*2+1 */ - int len; + char buf[256]; + int len, rc; myheader("test_bug8378"); if (!opt_silent) fprintf(stdout, "\n Establishing a test connection ..."); - if (!(lmysql= mysql_init(NULL))) + if (!(mysql= mysql_init(NULL))) { myerror("mysql_init() failed"); exit(1); } - if (mysql_options(lmysql, MYSQL_SET_CHARSET_NAME, "gbk")) + if (mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "gbk")) { myerror("mysql_options() failed"); exit(1); } - if (!(mysql_real_connect(lmysql, opt_host, opt_user, + if (!(mysql_real_connect(mysql, opt_host, opt_user, opt_password, current_db, opt_port, opt_unix_socket, 0))) { @@ -12822,12 +12823,18 @@ static void test_bug8378() if (!opt_silent) fprintf(stdout, " OK"); - len= mysql_real_escape_string(lmysql, out, TEST_BUG8378_IN, 4); + len= mysql_real_escape_string(mysql, out, TEST_BUG8378_IN, 4); /* No escaping should have actually happened. */ DIE_UNLESS(memcmp(out, TEST_BUG8378_OUT, len) == 0); - mysql_close(lmysql); + sprintf(buf, "SELECT '%s'", out); + rc=mysql_real_query(mysql, buf, strlen(buf)); + myquery(rc); + + mysql_close(mysql); + + mysql=old_mysql; #endif } diff --git a/unittest/Makefile.am b/unittest/Makefile.am index fd7530ee262..ca3291efde0 100644 --- a/unittest/Makefile.am +++ b/unittest/Makefile.am @@ -1,27 +1,15 @@ SUBDIRS = mytap . mysys examples noinst_SCRIPTS = unit +EXTRA_DIST = unit.pl +CLEANFILES = unit -EXTRA_DIST = unit.pl +unittests = mytap mysys -DISTCLEANFILES = unit - -unittests = mysys examples - -.PHONY: all mytap mysys examples test - -test: unit all - @./unit run $(unittests) - -mytap: - cd mytap && $(MAKE) - -mysys: - cd mysys && $(MAKE) - -examples: - cd examples && $(MAKE) +test: unit + ./unit run $(unittests) unit: $(srcdir)/unit.pl - cp $< $@ - chmod +x $@ + cp $(srcdir)/unit.pl $@ + chmod 700 $@ + diff --git a/unittest/README.txt b/unittest/README.txt index fd9641665c7..0d8bb9025d8 100644 --- a/unittest/README.txt +++ b/unittest/README.txt @@ -7,14 +7,14 @@ will be added over time. mytap Source for the MyTAP library mysys Tests for mysys components - bitmap.t.c Unit test for MY_BITMAP - base64.t.c Unit test for base64 encoding functions + bitmap-t.c Unit test for MY_BITMAP + base64-t.c Unit test for base64 encoding functions examples Example unit tests - simple.t.c Example of a standard TAP unit test - skip.t.c Example where some test points are skipped - skip_all.t.c Example of a test where the entire test is skipped - todo.t.c Example where test contain test points that are TODO - no_plan.t.c Example of a test with no plan (avoid this) + simple-t.c Example of a standard TAP unit test + skip-t.c Example where some test points are skipped + skip_all-t.c Example of a test where the entire test is skipped + todo-t.c Example where test contain test points that are TODO + no_plan-t.c Example of a test with no plan (avoid this) Executing unit tests @@ -28,9 +28,12 @@ To make and execute all unit tests in the directory: Adding unit tests ----------------- -Add a file with a name of the format "foo.t.c" to the appropriate +Add a file with a name of the format "foo-t.c" to the appropriate directory and add the following to the Makefile.am in that directory (where ... denotes stuff already there): - noinst_PROGRAMS = ... foo.t - foo_t_c_SOURCES = foo.t.c + noinst_PROGRAMS = ... foo-t + +Note, it's important to have "-t" at the end of the filename, otherwise the +test won't be executed by 'make test' ! + diff --git a/unittest/examples/Makefile.am b/unittest/examples/Makefile.am index 94a67927d12..f3c70b654a1 100644 --- a/unittest/examples/Makefile.am +++ b/unittest/examples/Makefile.am @@ -5,14 +5,5 @@ AM_LDFLAGS = -L$(top_builddir)/unittest/mytap LDADD = -lmytap -noinst_PROGRAMS = simple.t skip.t todo.t skip_all.t no_plan.t +noinst_PROGRAMS = simple-t skip-t todo-t skip_all-t no_plan-t -simple_t_SOURCES = simple.t.c - -skip_t_SOURCES = skip.t.c - -todo_t_SOURCES = todo.t.c - -skip_all_t_SOURCES = skip_all.t.c - -no_plan_t_SOURCES = no_plan.t.c diff --git a/unittest/examples/no_plan.t.c b/unittest/examples/no_plan-t.c index 67029c7962f..98e4d06def6 100644 --- a/unittest/examples/no_plan.t.c +++ b/unittest/examples/no_plan-t.c @@ -1,4 +1,6 @@ +#include "my_config.h" + #include <stdlib.h> #include <tap.h> diff --git a/unittest/examples/simple.t.c b/unittest/examples/simple-t.c index 866af865327..866af865327 100644 --- a/unittest/examples/simple.t.c +++ b/unittest/examples/simple-t.c diff --git a/unittest/examples/skip.t.c b/unittest/examples/skip-t.c index ef717691700..ef717691700 100644 --- a/unittest/examples/skip.t.c +++ b/unittest/examples/skip-t.c diff --git a/unittest/examples/skip_all.t.c b/unittest/examples/skip_all-t.c index bbde6b63f1c..19b8c1fddaf 100644 --- a/unittest/examples/skip_all.t.c +++ b/unittest/examples/skip_all-t.c @@ -1,4 +1,6 @@ +#include "my_config.h" + #include <stdlib.h> #include <tap.h> diff --git a/unittest/examples/todo.t.c b/unittest/examples/todo-t.c index 13a0c950b54..82601bee41c 100644 --- a/unittest/examples/todo.t.c +++ b/unittest/examples/todo-t.c @@ -1,4 +1,6 @@ +#include "my_config.h" + #include <stdlib.h> #include <tap.h> diff --git a/unittest/mysys/Makefile.am b/unittest/mysys/Makefile.am index 010a7845339..b1e0356bac6 100644 --- a/unittest/mysys/Makefile.am +++ b/unittest/mysys/Makefile.am @@ -7,9 +7,5 @@ AM_LDFLAGS += -L$(top_builddir)/strings -L$(top_builddir)/dbug LDADD = -lmytap -lmysys -ldbug -lmystrings -noinst_PROGRAMS = bitmap.t base64.t - -bitmap_t_SOURCES = bitmap.t.c - -base64_t_SOURCES = base64.t.c +noinst_PROGRAMS = bitmap-t base64-t my_atomic-t diff --git a/unittest/mysys/base64.t.c b/unittest/mysys/base64-t.c index 6d85964b20d..6d85964b20d 100644 --- a/unittest/mysys/base64.t.c +++ b/unittest/mysys/base64-t.c diff --git a/unittest/mysys/bitmap.t.c b/unittest/mysys/bitmap-t.c index d5683baff66..d5683baff66 100644 --- a/unittest/mysys/bitmap.t.c +++ b/unittest/mysys/bitmap-t.c diff --git a/unittest/mysys/my_atomic-t.c b/unittest/mysys/my_atomic-t.c new file mode 100644 index 00000000000..8a3fe129b07 --- /dev/null +++ b/unittest/mysys/my_atomic-t.c @@ -0,0 +1,149 @@ +/* Copyright (C) 2006 MySQL 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 */ + +#include <tap.h> + +#include <my_global.h> +#include <my_sys.h> +#include <my_atomic.h> + +my_atomic_32_t a32,b32,c32; +my_atomic_rwlock_t rwl; + +pthread_attr_t thr_attr; +pthread_mutex_t mutex; +pthread_cond_t cond; +int N; + +/* add and sub a random number in a loop. Must get 0 at the end */ +pthread_handler_t test_atomic_add_handler(void *arg) +{ + int m=*(int *)arg; + int32 x; + for (x=((int)(&m)); m ; m--) + { + x=x*m+0x87654321; + my_atomic_add32(&a32, x, &rwl); + my_atomic_add32(&a32, -x, &rwl); + } + pthread_mutex_lock(&mutex); + N--; + if (!N) pthread_cond_signal(&cond); + pthread_mutex_unlock(&mutex); + return 0; +} + +/* + 1. generate thread number 0..N-1 from b32 + 2. add it to a32 + 3. swap thread numbers in c32 + 4. (optionally) one more swap to avoid 0 as a result + 5. subtract result from a32 + must get 0 in a32 at the end +*/ +pthread_handler_t test_atomic_swap_handler(void *arg) +{ + int m=*(int *)arg; + uint32 x=my_atomic_add32(&b32, 1, &rwl); + + my_atomic_add32(&a32, x, &rwl); + + for (; m ; m--) + x=my_atomic_swap32(&c32, x,&rwl); + + if (!x) + x=my_atomic_swap32(&c32, x,&rwl); + + my_atomic_add32(&a32, -x, &rwl); + + pthread_mutex_lock(&mutex); + N--; + if (!N) pthread_cond_signal(&cond); + pthread_mutex_unlock(&mutex); + return 0; +} + +/* + same as test_atomic_add_handler, but my_atomic_add32 is emulated with + (slower) my_atomic_cas32 +*/ +pthread_handler_t test_atomic_cas_handler(void *arg) +{ + int m=*(int *)arg; + int32 x; + for (x=((int)(&m)); m ; m--) + { + uint32 y=my_atomic_load32(&a32, &rwl); + x=x*m+0x87654321; + while (!my_atomic_cas32(&a32, &y, y+x, &rwl)) ; + while (!my_atomic_cas32(&a32, &y, y-x, &rwl)) ; + } + pthread_mutex_lock(&mutex); + N--; + if (!N) pthread_cond_signal(&cond); + pthread_mutex_unlock(&mutex); + return 0; +} + +void test_atomic(const char *test, pthread_handler handler, int n, int m) +{ + pthread_t t; + ulonglong now=my_getsystime(); + + my_atomic_store32(&a32, 0, &rwl); + my_atomic_store32(&b32, 0, &rwl); + my_atomic_store32(&c32, 0, &rwl); + + diag("Testing %s with %d threads, %d iterations... ", test, n, m); + for (N=n ; n ; n--) + pthread_create(&t, &thr_attr, handler, &m); + + pthread_mutex_lock(&mutex); + while (N) + pthread_cond_wait(&cond, &mutex); + pthread_mutex_unlock(&mutex); + now=my_getsystime()-now; + ok(my_atomic_load32(&a32, &rwl) == 0, + "tested %s in %g secs", test, ((double)now)/1e7); +} + +int main() +{ + int err; + + diag("N CPUs: %d", my_getncpus()); + err= my_atomic_initialize(); + + plan(4); + ok(err == 0, "my_atomic_initialize() returned %d", err); + + pthread_attr_init(&thr_attr); + pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED); + pthread_mutex_init(&mutex, 0); + pthread_cond_init(&cond, 0); + my_atomic_rwlock_init(&rwl); + + test_atomic("my_atomic_add32", test_atomic_add_handler, 100,1000000); + test_atomic("my_atomic_swap32", test_atomic_swap_handler, 100,1000000); + test_atomic("my_atomic_cas32", test_atomic_cas_handler, 100,1000000); + + pthread_mutex_destroy(&mutex); + pthread_cond_destroy(&cond); + pthread_attr_destroy(&thr_attr); + my_atomic_rwlock_destroy(&rwl); + return exit_status(); +} + diff --git a/unittest/mytap/t/Makefile.am b/unittest/mytap/t/Makefile.am index 88c31cfeb7f..b685ae7dc1c 100644 --- a/unittest/mytap/t/Makefile.am +++ b/unittest/mytap/t/Makefile.am @@ -5,8 +5,5 @@ AM_LDFLAGS = -L$(top_builddir)/unittest/mytap LDADD = -lmytap -noinst_PROGRAMS = basic.t +noinst_PROGRAMS = basic-t -basic_t_SOURCES = basic.t.c - -all: $(noinst_PROGRAMS) diff --git a/unittest/mytap/t/basic.t.c b/unittest/mytap/t/basic-t.c index eb820d6c651..bf4c1a9a664 100644 --- a/unittest/mytap/t/basic.t.c +++ b/unittest/mytap/t/basic-t.c @@ -1,6 +1,8 @@ +#include "my_config.h" + #include <stdlib.h> -#include <tap.h> +#include "../tap.h" int main() { plan(5); diff --git a/unittest/unit.pl b/unittest/unit.pl index cae394cf9b6..3092a874192 100644 --- a/unittest/unit.pl +++ b/unittest/unit.pl @@ -59,7 +59,7 @@ sub _find_test_files (@) { my @files; find sub { $File::Find::prune = 1 if /^SCCS$/; - push(@files, $File::Find::name) if -x _ && /\.t\z/; + push(@files, $File::Find::name) if -x _ && /-t\z/; }, @dirs; return @files; } diff --git a/vio/cmakelists.txt b/vio/CMakeLists.txt index a3cbb304289..a3cbb304289 100644 --- a/vio/cmakelists.txt +++ b/vio/CMakeLists.txt diff --git a/vio/Makefile.am b/vio/Makefile.am index b7e002a3033..e1830fdc636 100644 --- a/vio/Makefile.am +++ b/vio/Makefile.am @@ -38,7 +38,7 @@ test_sslclient_LDADD= @CLIENT_EXTRA_LDFLAGS@ ../dbug/libdbug.a libvio.a \ ../mysys/libmysys.a ../strings/libmystrings.a \ $(openssl_libs) $(yassl_libs) libvio_a_SOURCES= vio.c viosocket.c viossl.c viosslfactories.c -EXTRA_DIST= cmakelists.txt +EXTRA_DIST= CMakeLists.txt # Don't update the files from bitkeeper %::SCCS/s.% diff --git a/vio/test-ssl.c b/vio/test-ssl.c index a94eb1a21ff..f8172426e38 100644 --- a/vio/test-ssl.c +++ b/vio/test-ssl.c @@ -57,8 +57,8 @@ main(int argc, char** argv) char* cipher=0; int child_pid,sv[2]; my_bool unused; - struct st_VioSSLAcceptorFd* ssl_acceptor=0; - struct st_VioSSLConnectorFd* ssl_connector=0; + struct st_VioSSLFd* ssl_acceptor= 0; + struct st_VioSSLFd* ssl_connector= 0; Vio* client_vio=0, *server_vio=0; MY_INIT(argv[0]); DBUG_PROCESS(argv[0]); diff --git a/vio/test-sslclient.c b/vio/test-sslclient.c index 3811ba0fb6a..49d6768c884 100644 --- a/vio/test-sslclient.c +++ b/vio/test-sslclient.c @@ -46,7 +46,7 @@ main( int argc __attribute__((unused)), { char client_key[] = "../SSL/client-key.pem", client_cert[] = "../SSL/client-cert.pem"; char ca_file[] = "../SSL/cacert.pem", *ca_path = 0, *cipher=0; - struct st_VioSSLConnectorFd* ssl_connector=0; + struct st_VioSSLFd* ssl_connector= 0; struct sockaddr_in sa; Vio* client_vio=0; int err; diff --git a/vio/test-sslserver.c b/vio/test-sslserver.c index e4d32a75264..daec3a6e6f9 100644 --- a/vio/test-sslserver.c +++ b/vio/test-sslserver.c @@ -44,7 +44,7 @@ fatal_error( const char* r) typedef struct { int sd; - struct st_VioSSLAcceptorFd* ssl_acceptor; + struct st_VioSSLFd* ssl_acceptor; } TH_ARGS; static void @@ -82,7 +82,7 @@ main(int argc __attribute__((unused)), char** argv) char ca_file[] = "../SSL/cacert.pem", *ca_path = 0, *cipher = 0; - struct st_VioSSLAcceptorFd* ssl_acceptor; + struct st_VioSSLFd* ssl_acceptor; pthread_t th; TH_ARGS th_args; diff --git a/vio/vio.c b/vio/vio.c index 9ace22e3780..f20acb249ef 100644 --- a/vio/vio.c +++ b/vio/vio.c @@ -88,19 +88,19 @@ static void vio_init(Vio* vio, enum enum_vio_type type, if (type == VIO_TYPE_SSL) { vio->viodelete =vio_delete; - vio->vioerrno =vio_ssl_errno; + vio->vioerrno =vio_errno; vio->read =vio_ssl_read; vio->write =vio_ssl_write; - vio->fastsend =vio_ssl_fastsend; - vio->viokeepalive =vio_ssl_keepalive; - vio->should_retry =vio_ssl_should_retry; - vio->was_interrupted=vio_ssl_was_interrupted; + vio->fastsend =vio_fastsend; + vio->viokeepalive =vio_keepalive; + vio->should_retry =vio_should_retry; + vio->was_interrupted=vio_was_interrupted; vio->vioclose =vio_ssl_close; - vio->peer_addr =vio_ssl_peer_addr; - vio->in_addr =vio_ssl_in_addr; + vio->peer_addr =vio_peer_addr; + vio->in_addr =vio_in_addr; vio->vioblocking =vio_ssl_blocking; vio->is_blocking =vio_is_blocking; - vio->timeout =vio_ssl_timeout; + vio->timeout =vio_timeout; } else /* default is VIO_TYPE_TCPIP */ #endif /* HAVE_OPENSSL */ @@ -233,3 +233,16 @@ void vio_delete(Vio* vio) my_free((gptr) vio,MYF(0)); } } + + +/* + Cleanup memory allocated by vio or the + components below it when application finish + +*/ +void vio_end(void) +{ +#ifdef HAVE_YASSL + yaSSL_CleanUp(); +#endif +} diff --git a/vio/vio_priv.h b/vio/vio_priv.h index eb495025ddd..db331abdea8 100644 --- a/vio/vio_priv.h +++ b/vio/vio_priv.h @@ -30,28 +30,10 @@ void vio_ignore_timeout(Vio *vio, uint which, uint timeout); int vio_ssl_read(Vio *vio,gptr buf, int size); int vio_ssl_write(Vio *vio,const gptr buf,int size); -void vio_ssl_timeout(Vio *vio, uint which, uint timeout); - -/* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible. */ -int vio_ssl_fastsend(Vio *vio); -/* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible. */ -int vio_ssl_keepalive(Vio *vio, my_bool onoff); -/* Whenever we should retry the last read/write operation. */ -my_bool vio_ssl_should_retry(Vio *vio); -/* Check that operation was timed out */ -my_bool vio_ssl_was_interrupted(Vio *vio); + /* When the workday is over... */ int vio_ssl_close(Vio *vio); -/* Return last error number */ -int vio_ssl_errno(Vio *vio); -my_bool vio_ssl_peer_addr(Vio *vio, char *buf, uint16 *port); -void vio_ssl_in_addr(Vio *vio, struct in_addr *in); + int vio_ssl_blocking(Vio *vio, my_bool set_blocking_mode, my_bool *old_mode); -/* Single copy for server */ -enum vio_ssl_acceptorfd_state -{ - state_connect = 1, - state_accept = 2 -}; #endif /* HAVE_OPENSSL */ diff --git a/vio/viosocket.c b/vio/viosocket.c index 0ddceb72e91..78901fedb69 100644 --- a/vio/viosocket.c +++ b/vio/viosocket.c @@ -33,7 +33,8 @@ int vio_read(Vio * vio, gptr buf, int size) { int r; DBUG_ENTER("vio_read"); - DBUG_PRINT("enter", ("sd: %d, buf: 0x%p, size: %d", vio->sd, buf, size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, + size)); /* Ensure nobody uses vio_read_buff and vio_read simultaneously */ DBUG_ASSERT(vio->read_end == vio->read_pos); @@ -64,7 +65,8 @@ int vio_read_buff(Vio *vio, gptr buf, int size) int rc; #define VIO_UNBUFFERED_READ_MIN_SIZE 2048 DBUG_ENTER("vio_read_buff"); - DBUG_PRINT("enter", ("sd: %d, buf: 0x%p, size: %d", vio->sd, buf, size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, + size)); if (vio->read_pos < vio->read_end) { @@ -102,7 +104,8 @@ int vio_write(Vio * vio, const gptr buf, int size) { int r; DBUG_ENTER("vio_write"); - DBUG_PRINT("enter", ("sd: %d, buf: 0x%p, size: %d", vio->sd, buf, size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, + size)); #ifdef __WIN__ r = send(vio->sd, buf, size,0); #else @@ -223,7 +226,7 @@ int vio_keepalive(Vio* vio, my_bool set_keep_alive) int r=0; uint opt = 0; DBUG_ENTER("vio_keepalive"); - DBUG_PRINT("enter", ("sd: %d, set_keep_alive: %d", vio->sd, (int) + DBUG_PRINT("enter", ("sd: %d set_keep_alive: %d", vio->sd, (int) set_keep_alive)); if (vio->type != VIO_TYPE_NAMEDPIPE) { @@ -393,7 +396,8 @@ int vio_read_pipe(Vio * vio, gptr buf, int size) { DWORD length; DBUG_ENTER("vio_read_pipe"); - DBUG_PRINT("enter", ("sd: %d, buf: 0x%p, size: %d", vio->sd, buf, size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, + size)); if (!ReadFile(vio->hPipe, buf, size, &length, NULL)) DBUG_RETURN(-1); @@ -407,7 +411,8 @@ int vio_write_pipe(Vio * vio, const gptr buf, int size) { DWORD length; DBUG_ENTER("vio_write_pipe"); - DBUG_PRINT("enter", ("sd: %d, buf: 0x%p, size: %d", vio->sd, buf, size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, + size)); if (!WriteFile(vio->hPipe, (char*) buf, size, &length, NULL)) DBUG_RETURN(-1); @@ -452,7 +457,8 @@ int vio_read_shared_memory(Vio * vio, gptr buf, int size) char *current_postion; DBUG_ENTER("vio_read_shared_memory"); - DBUG_PRINT("enter", ("sd: %d, buf: 0x%p, size: %d", vio->sd, buf, size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, + size)); remain_local = size; current_postion=buf; @@ -513,7 +519,8 @@ int vio_write_shared_memory(Vio * vio, const gptr buf, int size) char *current_postion; DBUG_ENTER("vio_write_shared_memory"); - DBUG_PRINT("enter", ("sd: %d, buf: 0x%p, size: %d", vio->sd, buf, size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, + size)); remain = size; current_postion = buf; diff --git a/vio/viossl.c b/vio/viossl.c index a0262a79209..e869493c604 100644 --- a/vio/viossl.c +++ b/vio/viossl.c @@ -51,384 +51,240 @@ static int SSL_set_fd_bsd(SSL *s, int fd) static void -report_errors() +report_errors(SSL* ssl) { unsigned long l; - const char* file; - const char* data; - int line,flags; + const char *file; + const char *data; + int line, flags; +#ifndef DBUG_OFF + char buf[512]; +#endif + DBUG_ENTER("report_errors"); - while ((l=ERR_get_error_line_data(&file,&line,&data,&flags))) + while ((l= ERR_get_error_line_data(&file,&line,&data,&flags))) { - char buf[512]; DBUG_PRINT("error", ("OpenSSL: %s:%s:%d:%s\n", ERR_error_string(l,buf), file,line,(flags&ERR_TXT_STRING)?data:"")) ; } - DBUG_PRINT("info", ("errno: %d", socket_errno)); - DBUG_VOID_RETURN; -} + if (ssl) + DBUG_PRINT("error", ("error: %s", + ERR_error_string(SSL_get_error(ssl, l), buf))); -int vio_ssl_errno(Vio *vio __attribute__((unused))) -{ - return socket_errno; /* On Win32 this mapped to WSAGetLastError() */ + DBUG_PRINT("info", ("socket_errno: %d", socket_errno)); + DBUG_VOID_RETURN; } -int vio_ssl_read(Vio * vio, gptr buf, int size) +int vio_ssl_read(Vio *vio, gptr buf, int size) { int r; DBUG_ENTER("vio_ssl_read"); DBUG_PRINT("enter", ("sd: %d, buf: 0x%p, size: %d, ssl_: 0x%p", vio->sd, buf, size, vio->ssl_arg)); - if ((r= SSL_read((SSL*) vio->ssl_arg, buf, size)) < 0) - { - int err= SSL_get_error((SSL*) vio->ssl_arg, r); - DBUG_PRINT("error",("SSL_read(): %d SSL_get_error(): %d", r, err)); - report_errors(); - } + r= SSL_read((SSL*) vio->ssl_arg, buf, size); +#ifndef DBUG_OFF + if (r < 0) + report_errors((SSL*) vio->ssl_arg); +#endif DBUG_PRINT("exit", ("%d", r)); DBUG_RETURN(r); } -int vio_ssl_write(Vio * vio, const gptr buf, int size) +int vio_ssl_write(Vio *vio, const gptr buf, int size) { int r; DBUG_ENTER("vio_ssl_write"); DBUG_PRINT("enter", ("sd: %d, buf: 0x%p, size: %d", vio->sd, buf, size)); - if ((r= SSL_write((SSL*) vio->ssl_arg, buf, size)) < 0) - report_errors(); - DBUG_PRINT("exit", ("%d", r)); - DBUG_RETURN(r); -} - - -int vio_ssl_fastsend(Vio * vio __attribute__((unused))) -{ - int r=0; - DBUG_ENTER("vio_ssl_fastsend"); - -#if defined(IPTOS_THROUGHPUT) - { - int tos= IPTOS_THROUGHPUT; - r= setsockopt(vio->sd, IPPROTO_IP, IP_TOS, (void *) &tos, sizeof(tos)); - } -#endif /* IPTOS_THROUGHPUT */ - if (!r) - { -#ifdef __WIN__ - BOOL nodelay= 1; - r= setsockopt(vio->sd, IPPROTO_TCP, TCP_NODELAY, (const char*) &nodelay, - sizeof(nodelay)); -#else - int nodelay= 1; - r= setsockopt(vio->sd, IPPROTO_TCP, TCP_NODELAY, (void*) &nodelay, - sizeof(nodelay)); -#endif /* __WIN__ */ - } - if (r) - { - DBUG_PRINT("warning", ("Couldn't set socket option for fast send")); - r= -1; - } + r= SSL_write((SSL*) vio->ssl_arg, buf, size); +#ifndef DBUG_OFF + if (r < 0) + report_errors((SSL*) vio->ssl_arg); +#endif DBUG_PRINT("exit", ("%d", r)); DBUG_RETURN(r); } -int vio_ssl_keepalive(Vio* vio, my_bool set_keep_alive) +int vio_ssl_close(Vio *vio) { - int r=0; - DBUG_ENTER("vio_ssl_keepalive"); - DBUG_PRINT("enter", ("sd: %d, set_keep_alive: %d", vio->sd, (int) - set_keep_alive)); - if (vio->type != VIO_TYPE_NAMEDPIPE) - { - uint opt = (set_keep_alive) ? 1 : 0; - r= setsockopt(vio->sd, SOL_SOCKET, SO_KEEPALIVE, (char *) &opt, - sizeof(opt)); - } - DBUG_RETURN(r); -} - - -my_bool -vio_ssl_should_retry(Vio * vio __attribute__((unused))) -{ - int en = socket_errno; - return (en == SOCKET_EAGAIN || en == SOCKET_EINTR || - en == SOCKET_EWOULDBLOCK); -} - - -my_bool -vio_ssl_was_interrupted(Vio *vio __attribute__((unused))) -{ - int en= socket_errno; - return (en == SOCKET_EAGAIN || en == SOCKET_EINTR || - en == SOCKET_EWOULDBLOCK || en == SOCKET_ETIMEDOUT); -} - - -int vio_ssl_close(Vio * vio) -{ - int r; + int r= 0; + SSL *ssl= (SSL*)vio->ssl_arg; DBUG_ENTER("vio_ssl_close"); - r=0; - if ((SSL*) vio->ssl_arg) - { - r = SSL_shutdown((SSL*) vio->ssl_arg); - SSL_free((SSL*) vio->ssl_arg); - vio->ssl_arg= 0; - } - if (vio->sd >= 0) - { - if (shutdown(vio->sd, 2)) - r= -1; - if (closesocket(vio->sd)) - r= -1; - } - if (r) - { - DBUG_PRINT("error", ("close() failed, error: %d",socket_errno)); - report_errors(); - /* FIXME: error handling (not critical for MySQL) */ - } - vio->type= VIO_CLOSED; - vio->sd= -1; - DBUG_RETURN(r); -} - -const char *vio_ssl_description(Vio * vio) -{ - return vio->desc; -} - -enum enum_vio_type vio_ssl_type(Vio* vio) -{ - return vio->type; -} - -my_socket vio_ssl_fd(Vio* vio) -{ - return vio->sd; -} - - -my_bool vio_ssl_peer_addr(Vio * vio, char *buf, uint16 *port) -{ - DBUG_ENTER("vio_ssl_peer_addr"); - DBUG_PRINT("enter", ("sd: %d", vio->sd)); - if (vio->localhost) - { - strmov(buf,"127.0.0.1"); - *port=0; - } - else + if (ssl) { - size_socket addrLen = sizeof(struct sockaddr); - if (getpeername(vio->sd, (struct sockaddr *) (& (vio->remote)), - &addrLen) != 0) + switch ((r= SSL_shutdown(ssl))) { - DBUG_PRINT("exit", ("getpeername, error: %d", socket_errno)); - DBUG_RETURN(1); + case 1: /* Shutdown successful */ + break; + case 0: /* Shutdown not yet finished, call it again */ + if ((r= SSL_shutdown(ssl) >= 0)) + break; + /* Fallthrough */ + default: /* Shutdown failed */ + DBUG_PRINT("vio_error", ("SSL_shutdown() failed, error: %s", + SSL_get_error(ssl, r))); + break; } -#ifdef TO_BE_FIXED - my_inet_ntoa(vio->remote.sin_addr,buf); - *port= 0; -#else - strmov(buf, "unknown"); - *port= 0; -#endif + SSL_free(ssl); + vio->ssl_arg= 0; } - DBUG_PRINT("exit", ("addr: %s", buf)); - DBUG_RETURN(0); + DBUG_RETURN(vio_close(vio)); } -void vio_ssl_in_addr(Vio *vio, struct in_addr *in) +int sslaccept(struct st_VioSSLFd *ptr, Vio *vio, long timeout) { - DBUG_ENTER("vio_ssl_in_addr"); - if (vio->localhost) - bzero((char*) in, sizeof(*in)); - else - *in=vio->remote.sin_addr; - DBUG_VOID_RETURN; -} - - -/* - TODO: Add documentation -*/ - -int sslaccept(struct st_VioSSLAcceptorFd* ptr, Vio* vio, long timeout) -{ - char *str; - char buf[1024]; - X509* client_cert; + SSL *ssl; my_bool unused; my_bool net_blocking; enum enum_vio_type old_type; DBUG_ENTER("sslaccept"); - DBUG_PRINT("enter", ("sd: %d ptr: Ox%p, timeout: %d", + DBUG_PRINT("enter", ("sd: %d ptr: %p, timeout: %d", vio->sd, ptr, timeout)); old_type= vio->type; - net_blocking = vio_is_blocking(vio); + net_blocking= vio_is_blocking(vio); vio_blocking(vio, 1, &unused); /* Must be called before reset */ - vio_reset(vio,VIO_TYPE_SSL,vio->sd,0,FALSE); - vio->ssl_arg= 0; - if (!(vio->ssl_arg= (void*) SSL_new(ptr->ssl_context))) + vio_reset(vio, VIO_TYPE_SSL, vio->sd, 0, FALSE); + + if (!(ssl= SSL_new(ptr->ssl_context))) { DBUG_PRINT("error", ("SSL_new failure")); - report_errors(); + report_errors(ssl); vio_reset(vio, old_type,vio->sd,0,FALSE); vio_blocking(vio, net_blocking, &unused); DBUG_RETURN(1); } - DBUG_PRINT("info", ("ssl_: Ox%p timeout: %ld", - (SSL*) vio->ssl_arg, timeout)); - SSL_clear((SSL*) vio->ssl_arg); - SSL_SESSION_set_timeout(SSL_get_session((SSL*) vio->ssl_arg), timeout); - SSL_set_fd((SSL*) vio->ssl_arg,vio->sd); - SSL_set_accept_state((SSL*) vio->ssl_arg); - if (SSL_do_handshake((SSL*) vio->ssl_arg) < 1) + vio->ssl_arg= (void*)ssl; + DBUG_PRINT("info", ("ssl_: %p timeout: %ld", ssl, timeout)); + SSL_clear(ssl); + SSL_SESSION_set_timeout(SSL_get_session(ssl), timeout); + SSL_set_fd(ssl, vio->sd); + SSL_set_accept_state(ssl); + if (SSL_do_handshake(ssl) < 1) { DBUG_PRINT("error", ("SSL_do_handshake failure")); - report_errors(); - SSL_free((SSL*) vio->ssl_arg); + report_errors(ssl); + SSL_free(ssl); vio->ssl_arg= 0; vio_reset(vio, old_type,vio->sd,0,FALSE); vio_blocking(vio, net_blocking, &unused); DBUG_RETURN(1); } + #ifndef DBUG_OFF - DBUG_PRINT("info",("SSL_get_cipher_name() = '%s'" - ,SSL_get_cipher_name((SSL*) vio->ssl_arg))); - client_cert = SSL_get_peer_certificate ((SSL*) vio->ssl_arg); - if (client_cert != NULL) { - DBUG_PRINT("info",("Client certificate:")); - str = X509_NAME_oneline (X509_get_subject_name (client_cert), 0, 0); - DBUG_PRINT("info",("\t subject: %s", str)); - free (str); + char buf[1024]; + X509 *client_cert; + DBUG_PRINT("info",("cipher_name= '%s'", SSL_get_cipher_name(ssl))); - str = X509_NAME_oneline (X509_get_issuer_name (client_cert), 0, 0); - DBUG_PRINT("info",("\t issuer: %s", str)); - free (str); + if ((client_cert= SSL_get_peer_certificate (ssl))) + { + DBUG_PRINT("info",("Client certificate:")); + X509_NAME_oneline (X509_get_subject_name (client_cert), + buf, sizeof(buf)); + DBUG_PRINT("info",("\t subject: %s", buf)); - X509_free (client_cert); - } - else - DBUG_PRINT("info",("Client does not have certificate.")); + X509_NAME_oneline (X509_get_issuer_name (client_cert), + buf, sizeof(buf)); + DBUG_PRINT("info",("\t issuer: %s", buf)); - str=SSL_get_shared_ciphers((SSL*) vio->ssl_arg, buf, sizeof(buf)); - if (str) - { - DBUG_PRINT("info",("SSL_get_shared_ciphers() returned '%s'",str)); - } - else - { - DBUG_PRINT("info",("no shared ciphers!")); - } + X509_free (client_cert); + } + else + DBUG_PRINT("info",("Client does not have certificate.")); + if (SSL_get_shared_ciphers(ssl, buf, sizeof(buf))) + { + DBUG_PRINT("info",("shared_ciphers: '%s'", buf)); + } + else + DBUG_PRINT("info",("no shared ciphers!")); + } #endif + DBUG_RETURN(0); } -int sslconnect(struct st_VioSSLConnectorFd* ptr, Vio* vio, long timeout) +int sslconnect(struct st_VioSSLFd *ptr, Vio *vio, long timeout) { - char *str; - X509* server_cert; + SSL *ssl; my_bool unused; my_bool net_blocking; - enum enum_vio_type old_type; + enum enum_vio_type old_type; + DBUG_ENTER("sslconnect"); - DBUG_PRINT("enter", ("sd: %d ptr: 0x%p ctx: 0x%p", - vio->sd,ptr,ptr->ssl_context)); + DBUG_PRINT("enter", ("sd: %d, ptr: %p, ctx: %p", + vio->sd, ptr, ptr->ssl_context)); old_type= vio->type; - net_blocking = vio_is_blocking(vio); + net_blocking= vio_is_blocking(vio); vio_blocking(vio, 1, &unused); /* Must be called before reset */ - vio_reset(vio,VIO_TYPE_SSL,vio->sd,0,FALSE); - vio->ssl_arg= 0; - if (!(vio->ssl_arg = SSL_new(ptr->ssl_context))) + vio_reset(vio, VIO_TYPE_SSL, vio->sd, 0, FALSE); + if (!(ssl= SSL_new(ptr->ssl_context))) { DBUG_PRINT("error", ("SSL_new failure")); - report_errors(); - vio_reset(vio, old_type,vio->sd,0,FALSE); - vio_blocking(vio, net_blocking, &unused); + report_errors(ssl); + vio_reset(vio, old_type, vio->sd, 0, FALSE); + vio_blocking(vio, net_blocking, &unused); DBUG_RETURN(1); } - DBUG_PRINT("info", ("ssl_: 0x%p timeout: %ld", - (SSL*) vio->ssl_arg, timeout)); - SSL_clear((SSL*) vio->ssl_arg); - SSL_SESSION_set_timeout(SSL_get_session((SSL*) vio->ssl_arg), timeout); - SSL_set_fd ((SSL*) vio->ssl_arg, vio_ssl_fd(vio)); - SSL_set_connect_state((SSL*) vio->ssl_arg); - if (SSL_do_handshake((SSL*) vio->ssl_arg) < 1) + vio->ssl_arg= (void*)ssl; + DBUG_PRINT("info", ("ssl: %p, timeout: %ld", ssl, timeout)); + SSL_clear(ssl); + SSL_SESSION_set_timeout(SSL_get_session(ssl), timeout); + SSL_set_fd(ssl, vio->sd); + SSL_set_connect_state(ssl); + if (SSL_do_handshake(ssl) < 1) { DBUG_PRINT("error", ("SSL_do_handshake failure")); - report_errors(); - SSL_free((SSL*) vio->ssl_arg); + report_errors(ssl); + SSL_free(ssl); vio->ssl_arg= 0; - vio_reset(vio, old_type,vio->sd,0,FALSE); + vio_reset(vio, old_type, vio->sd, 0, FALSE); vio_blocking(vio, net_blocking, &unused); DBUG_RETURN(1); - } + } #ifndef DBUG_OFF - DBUG_PRINT("info",("SSL_get_cipher_name() = '%s'" - ,SSL_get_cipher_name((SSL*) vio->ssl_arg))); - server_cert = SSL_get_peer_certificate ((SSL*) vio->ssl_arg); - if (server_cert != NULL) { - DBUG_PRINT("info",("Server certificate:")); - str = X509_NAME_oneline (X509_get_subject_name (server_cert), 0, 0); - DBUG_PRINT("info",("\t subject: %s", str)); - free(str); - - str = X509_NAME_oneline (X509_get_issuer_name (server_cert), 0, 0); - DBUG_PRINT("info",("\t issuer: %s", str)); - free(str); - - /* - We could do all sorts of certificate verification stuff here before - deallocating the certificate. - */ - X509_free (server_cert); + X509 *server_cert; + DBUG_PRINT("info",("cipher_name: '%s'" , SSL_get_cipher_name(ssl))); + + if ((server_cert= SSL_get_peer_certificate (ssl))) + { + char buf[256]; + DBUG_PRINT("info",("Server certificate:")); + X509_NAME_oneline(X509_get_subject_name(server_cert), buf, sizeof(buf)); + DBUG_PRINT("info",("\t subject: %s", buf)); + X509_NAME_oneline (X509_get_issuer_name(server_cert), buf, sizeof(buf)); + DBUG_PRINT("info",("\t issuer: %s", buf)); + X509_free (server_cert); + } + else + DBUG_PRINT("info",("Server does not have certificate.")); } - else - DBUG_PRINT("info",("Server does not have certificate.")); #endif + DBUG_RETURN(0); } -int vio_ssl_blocking(Vio * vio __attribute__((unused)), +int vio_ssl_blocking(Vio *vio __attribute__((unused)), my_bool set_blocking_mode, my_bool *old_mode) { + /* Mode is always blocking */ + *old_mode= 1; /* Return error if we try to change to non_blocking mode */ - *old_mode=1; /* Mode is always blocking */ - return set_blocking_mode ? 0 : 1; + return (set_blocking_mode ? 0 : 1); } - -void vio_ssl_timeout(Vio *vio __attribute__((unused)), - uint which __attribute__((unused)), - uint timeout __attribute__((unused))) -{ -#ifdef __WIN__ - ulong wait_timeout= (ulong) timeout * 1000; - (void) setsockopt(vio->sd, SOL_SOCKET, - which ? SO_SNDTIMEO : SO_RCVTIMEO, (char*) &wait_timeout, - sizeof(wait_timeout)); -#endif /* __WIN__ */ -} #endif /* HAVE_OPENSSL */ diff --git a/vio/viosslfactories.c b/vio/viosslfactories.c index 002874caf58..ca7a96d5801 100644 --- a/vio/viosslfactories.c +++ b/vio/viosslfactories.c @@ -21,7 +21,6 @@ static bool ssl_algorithms_added = FALSE; static bool ssl_error_strings_loaded= FALSE; static int verify_depth = 0; -static int verify_error = X509_V_OK; static unsigned char dh512_p[]= { @@ -82,30 +81,31 @@ vio_set_cert_stuff(SSL_CTX *ctx, const char *cert_file, const char *key_file) DBUG_ENTER("vio_set_cert_stuff"); DBUG_PRINT("enter", ("ctx: %p, cert_file: %s, key_file: %s", ctx, cert_file, key_file)); - if (cert_file != NULL) + if (cert_file) { - if (SSL_CTX_use_certificate_file(ctx,cert_file,SSL_FILETYPE_PEM) <= 0) + if (SSL_CTX_use_certificate_file(ctx, cert_file, SSL_FILETYPE_PEM) <= 0) { - DBUG_PRINT("error",("unable to get certificate from '%s'\n",cert_file)); + DBUG_PRINT("error",("unable to get certificate from '%s'\n", cert_file)); /* FIX stderr */ fprintf(stderr,"Error when connection to server using SSL:"); ERR_print_errors_fp(stderr); fprintf(stderr,"Unable to get certificate from '%s'\n", cert_file); fflush(stderr); - DBUG_RETURN(0); + DBUG_RETURN(1); } - if (key_file == NULL) - key_file = cert_file; - if (SSL_CTX_use_PrivateKey_file(ctx,key_file, - SSL_FILETYPE_PEM) <= 0) + + if (!key_file) + key_file= cert_file; + + if (SSL_CTX_use_PrivateKey_file(ctx, key_file, SSL_FILETYPE_PEM) <= 0) { - DBUG_PRINT("error", ("unable to get private key from '%s'\n",key_file)); + DBUG_PRINT("error", ("unable to get private key from '%s'\n", key_file)); /* FIX stderr */ fprintf(stderr,"Error when connection to server using SSL:"); ERR_print_errors_fp(stderr); - fprintf(stderr,"Unable to get private key from '%s'\n", cert_file); - fflush(stderr); - DBUG_RETURN(0); + fprintf(stderr,"Unable to get private key from '%s'\n", key_file); + fflush(stderr); + DBUG_RETURN(1); } /* @@ -116,45 +116,45 @@ vio_set_cert_stuff(SSL_CTX *ctx, const char *cert_file, const char *key_file) { DBUG_PRINT("error", ("Private key does not match the certificate public key\n")); - DBUG_RETURN(0); + DBUG_RETURN(1); } } - DBUG_RETURN(1); + DBUG_RETURN(0); } static int vio_verify_callback(int ok, X509_STORE_CTX *ctx) { - char buf[256]; - X509* err_cert; - int err,depth; + char buf[256]; + X509 *err_cert; DBUG_ENTER("vio_verify_callback"); - DBUG_PRINT("enter", ("ok: %d, ctx: 0x%p", ok, ctx)); - err_cert=X509_STORE_CTX_get_current_cert(ctx); - err= X509_STORE_CTX_get_error(ctx); - depth= X509_STORE_CTX_get_error_depth(ctx); + DBUG_PRINT("enter", ("ok: %d, ctx: %p", ok, ctx)); - X509_NAME_oneline(X509_get_subject_name(err_cert),buf,sizeof(buf)); + err_cert= X509_STORE_CTX_get_current_cert(ctx); + X509_NAME_oneline(X509_get_subject_name(err_cert), buf, sizeof(buf)); + DBUG_PRINT("info", ("cert: %s", buf)); if (!ok) { - DBUG_PRINT("error",("verify error: num: %d : '%s'\n",err, + int err, depth; + err= X509_STORE_CTX_get_error(ctx); + depth= X509_STORE_CTX_get_error_depth(ctx); + + DBUG_PRINT("error",("verify error: %d, '%s'",err, X509_verify_cert_error_string(err))); + /* + Approve cert if depth is greater then "verify_depth", currently + verify_depth is always 0 and there is no way to increase it. + */ if (verify_depth >= depth) - { - ok=1; - verify_error=X509_V_OK; - } - else - { - verify_error=X509_V_ERR_CERT_CHAIN_TOO_LONG; - } + ok= 1; } - switch (ctx->error) { + switch (ctx->error) + { case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: - X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),buf,256); - DBUG_PRINT("info",("issuer= %s\n",buf)); + X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert), buf, 256); + DBUG_PRINT("info",("issuer= %s\n", buf)); break; case X509_V_ERR_CERT_NOT_YET_VALID: case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: @@ -198,201 +198,156 @@ static void netware_ssl_init() #endif /* __NETWARE__ */ -/************************ VioSSLConnectorFd **********************************/ -/* - TODO: - Add option --verify to mysql to be able to change verification mode -*/ - -struct st_VioSSLConnectorFd * -new_VioSSLConnectorFd(const char* key_file, - const char* cert_file, - const char* ca_file, - const char* ca_path, - const char* cipher) +static void check_ssl_init() { - int verify = SSL_VERIFY_NONE; - struct st_VioSSLConnectorFd* ptr; - int result; - DH *dh; - DBUG_ENTER("new_VioSSLConnectorFd"); - - if (!(ptr=((struct st_VioSSLConnectorFd*) - my_malloc(sizeof(struct st_VioSSLConnectorFd),MYF(0))))) - DBUG_RETURN(0); - - ptr->ssl_context= 0; - ptr->ssl_method= 0; - /* FIXME: constants! */ - if (!ssl_algorithms_added) { - DBUG_PRINT("info", ("todo: OpenSSL_add_all_algorithms()")); - ssl_algorithms_added = TRUE; + ssl_algorithms_added= TRUE; SSL_library_init(); OpenSSL_add_all_algorithms(); + } + #ifdef __NETWARE__ netware_ssl_init(); #endif if (!ssl_error_strings_loaded) { - DBUG_PRINT("info", ("todo:SSL_load_error_strings()")); - ssl_error_strings_loaded = TRUE; + ssl_error_strings_loaded= TRUE; SSL_load_error_strings(); } - ptr->ssl_method = TLSv1_client_method(); - ptr->ssl_context = SSL_CTX_new(ptr->ssl_method); - DBUG_PRINT("info", ("ssl_context: %p",ptr->ssl_context)); - if (ptr->ssl_context == 0) +} + +/************************ VioSSLFd **********************************/ +static struct st_VioSSLFd * +new_VioSSLFd(const char *key_file, const char *cert_file, + const char *ca_file, const char *ca_path, + const char *cipher, SSL_METHOD *method) +{ + DH *dh; + struct st_VioSSLFd *ssl_fd; + DBUG_ENTER("new_VioSSLFd"); + + check_ssl_init(); + + if (!(ssl_fd= ((struct st_VioSSLFd*) + my_malloc(sizeof(struct st_VioSSLFd),MYF(0))))) + DBUG_RETURN(0); + + if (!(ssl_fd->ssl_context= SSL_CTX_new(method))) { DBUG_PRINT("error", ("SSL_CTX_new failed")); report_errors(); - goto ctor_failure; - } - /* - SSL_CTX_set_options - SSL_CTX_set_info_callback - */ - if (cipher) - { - result=SSL_CTX_set_cipher_list(ptr->ssl_context, cipher); - DBUG_PRINT("info",("SSL_set_cipher_list() returned %d",result)); + my_free((void*)ssl_fd,MYF(0)); + DBUG_RETURN(0); } - SSL_CTX_set_verify(ptr->ssl_context, verify, vio_verify_callback); - if (vio_set_cert_stuff(ptr->ssl_context, cert_file, key_file) == -1) + + /* Set the ciphers that can be used */ + if (cipher && SSL_CTX_set_cipher_list(ssl_fd->ssl_context, cipher)) { - DBUG_PRINT("error", ("vio_set_cert_stuff failed")); + DBUG_PRINT("error", ("failed to set ciphers to use")); report_errors(); - goto ctor_failure; + my_free((void*)ssl_fd,MYF(0)); + DBUG_RETURN(0); } - if (SSL_CTX_load_verify_locations( ptr->ssl_context, ca_file,ca_path) == 0) + + /* Load certs from the trusted ca */ + if (SSL_CTX_load_verify_locations(ssl_fd->ssl_context, ca_file, ca_path) == 0) { DBUG_PRINT("warning", ("SSL_CTX_load_verify_locations failed")); - if (SSL_CTX_set_default_verify_paths(ptr->ssl_context) == 0) + if (SSL_CTX_set_default_verify_paths(ssl_fd->ssl_context) == 0) { DBUG_PRINT("error", ("SSL_CTX_set_default_verify_paths failed")); report_errors(); - goto ctor_failure; + my_free((void*)ssl_fd,MYF(0)); + DBUG_RETURN(0); } - } + } + + if (vio_set_cert_stuff(ssl_fd->ssl_context, cert_file, key_file)) + { + DBUG_PRINT("error", ("vio_set_cert_stuff failed")); + report_errors(); + my_free((void*)ssl_fd,MYF(0)); + DBUG_RETURN(0); + } /* DH stuff */ dh=get_dh512(); - SSL_CTX_set_tmp_dh(ptr->ssl_context,dh); + SSL_CTX_set_tmp_dh(ssl_fd->ssl_context, dh); DH_free(dh); - DBUG_RETURN(ptr); -ctor_failure: - DBUG_PRINT("exit", ("there was an error")); - my_free((gptr)ptr,MYF(0)); - DBUG_RETURN(0); + DBUG_PRINT("exit", ("OK 1")); + + DBUG_RETURN(ssl_fd); } -/************************ VioSSLAcceptorFd **********************************/ -/* - TODO: - Add option --verify to mysqld to be able to change verification mode -*/ -struct st_VioSSLAcceptorFd * -new_VioSSLAcceptorFd(const char *key_file, - const char *cert_file, - const char *ca_file, - const char *ca_path, - const char *cipher) +/************************ VioSSLConnectorFd **********************************/ +struct st_VioSSLFd * +new_VioSSLConnectorFd(const char *key_file, const char *cert_file, + const char *ca_file, const char *ca_path, + const char *cipher) { - int verify = (SSL_VERIFY_PEER | - SSL_VERIFY_CLIENT_ONCE); - struct st_VioSSLAcceptorFd* ptr; - int result; - DH *dh; - DBUG_ENTER("new_VioSSLAcceptorFd"); + struct st_VioSSLFd *ssl_fd; + int verify= SSL_VERIFY_PEER; + if (!(ssl_fd= new_VioSSLFd(key_file, cert_file, ca_file, + ca_path, cipher, TLSv1_client_method()))) + { + return 0; + } - ptr= ((struct st_VioSSLAcceptorFd*) - my_malloc(sizeof(struct st_VioSSLAcceptorFd),MYF(0))); - ptr->ssl_context=0; - ptr->ssl_method=0; - /* FIXME: constants! */ - ptr->session_id_context= ptr; + /* Init the VioSSLFd as a "connector" ie. the client side */ - if (!ssl_algorithms_added) - { - DBUG_PRINT("info", ("todo: OpenSSL_add_all_algorithms()")); - ssl_algorithms_added = TRUE; - SSL_library_init(); - OpenSSL_add_all_algorithms(); + /* + The verify_callback function is used to control the behaviour + when the SSL_VERIFY_PEER flag is set. + */ + SSL_CTX_set_verify(ssl_fd->ssl_context, verify, vio_verify_callback); - } -#ifdef __NETWARE__ - netware_ssl_init(); -#endif + return ssl_fd; +} - if (!ssl_error_strings_loaded) - { - DBUG_PRINT("info", ("todo: SSL_load_error_strings()")); - ssl_error_strings_loaded = TRUE; - SSL_load_error_strings(); - } - ptr->ssl_method= TLSv1_server_method(); - ptr->ssl_context= SSL_CTX_new(ptr->ssl_method); - if (ptr->ssl_context == 0) - { - DBUG_PRINT("error", ("SSL_CTX_new failed")); - report_errors(); - goto ctor_failure; - } - if (cipher) + +/************************ VioSSLAcceptorFd **********************************/ +struct st_VioSSLFd * +new_VioSSLAcceptorFd(const char *key_file, const char *cert_file, + const char *ca_file, const char *ca_path, + const char *cipher) +{ + struct st_VioSSLFd *ssl_fd; + int verify= SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE; + if (!(ssl_fd= new_VioSSLFd(key_file, cert_file, ca_file, + ca_path, cipher, TLSv1_server_method()))) { - result=SSL_CTX_set_cipher_list(ptr->ssl_context, cipher); - DBUG_PRINT("info",("SSL_set_cipher_list() returned %d",result)); + return 0; } - /* SSL_CTX_set_quiet_shutdown(ctx,1); */ - SSL_CTX_sess_set_cache_size(ptr->ssl_context,128); + /* Init the the VioSSLFd as a "acceptor" ie. the server side */ - /* DH? */ - SSL_CTX_set_verify(ptr->ssl_context, verify, vio_verify_callback); - SSL_CTX_set_session_id_context(ptr->ssl_context, - (const uchar*) &(ptr->session_id_context), - sizeof(ptr->session_id_context)); + /* Set max number of cached sessions, returns the previous size */ + SSL_CTX_sess_set_cache_size(ssl_fd->ssl_context, 128); /* - SSL_CTX_set_client_CA_list(ctx,SSL_load_client_CA_file(CAfile)); + The verify_callback function is used to control the behaviour + when the SSL_VERIFY_PEER flag is set. */ - if (vio_set_cert_stuff(ptr->ssl_context, cert_file, key_file) == -1) - { - DBUG_PRINT("error", ("vio_set_cert_stuff failed")); - report_errors(); - goto ctor_failure; - } - if (SSL_CTX_load_verify_locations( ptr->ssl_context, ca_file, ca_path) == 0) - { - DBUG_PRINT("warning", ("SSL_CTX_load_verify_locations failed")); - if (SSL_CTX_set_default_verify_paths(ptr->ssl_context)==0) - { - DBUG_PRINT("error", ("SSL_CTX_set_default_verify_paths failed")); - report_errors(); - goto ctor_failure; - } - } - /* DH stuff */ - dh=get_dh512(); - SSL_CTX_set_tmp_dh(ptr->ssl_context,dh); - DH_free(dh); - DBUG_RETURN(ptr); + SSL_CTX_set_verify(ssl_fd->ssl_context, verify, vio_verify_callback); -ctor_failure: - DBUG_PRINT("exit", ("there was an error")); - my_free((gptr) ptr,MYF(0)); - DBUG_RETURN(0); -} + /* + Set session_id - an identifier for this server session + Use the ssl_fd pointer + */ + SSL_CTX_set_session_id_context(ssl_fd->ssl_context, + (const unsigned char *)ssl_fd, + sizeof(ssl_fd)); + return ssl_fd; +} -void free_vio_ssl_acceptor_fd(struct st_VioSSLAcceptorFd *fd) +void free_vio_ssl_acceptor_fd(struct st_VioSSLFd *fd) { SSL_CTX_free(fd->ssl_context); my_free((gptr) fd, MYF(0)); } - #endif /* HAVE_OPENSSL */ diff --git a/zlib/cmakelists.txt b/zlib/CMakeLists.txt index 53560adf6d1..53560adf6d1 100644 --- a/zlib/cmakelists.txt +++ b/zlib/CMakeLists.txt diff --git a/zlib/Makefile.am b/zlib/Makefile.am index cc3777b1e88..40258ec589a 100644 --- a/zlib/Makefile.am +++ b/zlib/Makefile.am @@ -29,4 +29,4 @@ libz_la_SOURCES= adler32.c compress.c crc32.c deflate.c gzio.c \ infback.c inffast.c inflate.c inftrees.c trees.c \ uncompr.c zutil.c -EXTRA_DIST= README FAQ INDEX ChangeLog algorithm.txt zlib.3 cmakelists.txt +EXTRA_DIST= README FAQ INDEX ChangeLog algorithm.txt zlib.3 CMakeLists.txt |