From aba49a6c0bf31b7b9c481058be660661797c8e77 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 15 Jun 2004 11:35:23 +0200 Subject: [PATCH 1/3] API change: mysql_shutdown() now needs a 2nd parameter, the shutdown level. Server will however still accept shutdown without specified level; so that old mysqladmin can still shut server down. I would like your comments on the names of shutdown level which I chose. You are welcome to propose better names. Please however check WL#709 before. Reason for the names I propose is to be accurate, thus leaving possibility for other levels which we may imagine in the future; that's why I have rejected names like "fast", "smart", "graceful" so far. My position is that WAIT_ALL_BUFFERS or WAIT_CRITICAL_BUFFERS say what the shutdown does, whereas for "smart", "fast" you need to remember what it does. This should be pushed in 4.1.3 but only after your comments. client/mysqladmin.c: 2nd parameter for mysql_shutdown() include/mysql.h: 2nd paramater for mysql_shutdown() include/mysql_com.h: 4 types of shutdown libmysql/libmysql.c: passing the requested shutdown level sql/sql_parse.cc: check for the shutdown level in dispatch_command(). Though its value is ignored for now. tools/mysqlmanager.c: 2nd parameter to mysql_shutdown --- client/mysqladmin.c | 2 +- include/mysql.h | 4 +++- include/mysql_com.h | 20 ++++++++++++++++++++ libmysql/libmysql.c | 7 +++++-- sql/sql_parse.cc | 20 +++++++++++++++++++- tools/mysqlmanager.c | 2 +- 6 files changed, 49 insertions(+), 6 deletions(-) diff --git a/client/mysqladmin.c b/client/mysqladmin.c index fcbcc0d7151..aaed101a83e 100644 --- a/client/mysqladmin.c +++ b/client/mysqladmin.c @@ -509,7 +509,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv) !stat(pidfile, &pidfile_status)) last_modified= pidfile_status.st_mtime; - if (mysql_shutdown(mysql)) + if (mysql_shutdown(mysql, SHUTDOWN_DEFAULT)) { my_printf_error(0,"shutdown failed; error: '%s'",MYF(ME_BELL), mysql_error(mysql)); diff --git a/include/mysql.h b/include/mysql.h index 71bff833d59..57c04f32dc8 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -453,7 +453,9 @@ int STDCALL mysql_add_slave(MYSQL* mysql, const char* host, const char* user, const char* passwd); -int STDCALL mysql_shutdown(MYSQL *mysql); +int STDCALL mysql_shutdown(MYSQL *mysql, + enum enum_shutdown_level + shutdown_level); int STDCALL mysql_dump_debug_info(MYSQL *mysql); int STDCALL mysql_refresh(MYSQL *mysql, unsigned int refresh_options); diff --git a/include/mysql_com.h b/include/mysql_com.h index d354a979cd1..bfd38f4f0fc 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -223,6 +223,26 @@ enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY, #define FIELD_TYPE_INTERVAL MYSQL_TYPE_ENUM #define FIELD_TYPE_GEOMETRY MYSQL_TYPE_GEOMETRY +enum enum_shutdown_level { + /* + We want levels to be in growing order of gracefulness. So we leave room + for future intermediate levels. For now, escalating one level is += 10; + later if we insert new levels in between we will need a function + next_shutdown_level(level). Note that DEFAULT does not respect the + growing property. + */ + SHUTDOWN_DEFAULT= 255, /* mapped to WAIT_ALL_BUFFERS for now */ + /* + Here is the list in growing order (the next does the previous plus + something). WAIT_ALL_BUFFERS is what we have now. Others are "this MySQL + server does not support this shutdown level yet". + */ + SHUTDOWN_WAIT_CRITICAL_BUFFERS= 10, /* flush MyISAM buffs (no corruption) */ + SHUTDOWN_WAIT_ALL_BUFFERS= 20, /* flush InnoDB buffers */ + SHUTDOWN_WAIT_TRANSACTIONS= 30, /* wait for existing trans to finish */ + SHUTDOWN_WAIT_CONNECTIONS= 40 /* wait for existing connections to finish */ +}; + /* options for mysql_set_option */ enum enum_mysql_set_option { diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index eb8368977e9..1e8244e670b 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -1285,10 +1285,13 @@ mysql_drop_db(MYSQL *mysql, const char *db) int STDCALL -mysql_shutdown(MYSQL *mysql) +mysql_shutdown(MYSQL *mysql, enum enum_shutdown_level shutdown_level) { + uchar level[1]; + level[0]= (uchar) shutdown_level; DBUG_ENTER("mysql_shutdown"); - DBUG_RETURN(simple_command(mysql,COM_SHUTDOWN,0,0,0)); + DBUG_RETURN(simple_command(mysql, COM_SHUTDOWN, + &level, 1, 0)); } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 28e833b8421..b0d476c695f 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1308,6 +1308,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (command != COM_STATISTICS && command != COM_PING) query_id++; thread_running++; + /* TODO: set thd->lex->sql_command to SQLCOM_PARSE here */ VOID(pthread_mutex_unlock(&LOCK_thread_count)); thd->server_status&= @@ -1478,6 +1479,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->query_length= length; thd->query= packet; thd->query_id= query_id++; + /* TODO: set thd->lex->sql_command to SQLCOM_PARSE here */ VOID(pthread_mutex_unlock(&LOCK_thread_count)); #ifndef EMBEDDED_LIBRARY mysql_parse(thd, packet, length); @@ -1631,10 +1633,25 @@ bool dispatch_command(enum enum_server_command command, THD *thd, } #ifndef EMBEDDED_LIBRARY case COM_SHUTDOWN: + { statistic_increment(com_other,&LOCK_status); if (check_global_access(thd,SHUTDOWN_ACL)) break; /* purecov: inspected */ - DBUG_PRINT("quit",("Got shutdown command")); + enum enum_shutdown_level level= (packet_length >= 2) ? + (enum enum_shutdown_level) (uchar) packet[0] : SHUTDOWN_DEFAULT; + DBUG_PRINT("quit",("Got shutdown command for level %u", level)); + /* + Accept old mysql_shutdown (with no argument). For now we do nothing of + the argument. + */ + if (level == SHUTDOWN_DEFAULT) + level= SHUTDOWN_WAIT_ALL_BUFFERS; // soon default will be configurable + else if (level != SHUTDOWN_WAIT_ALL_BUFFERS) + { + my_error(ER_NOT_SUPPORTED_YET, MYF(0), "this shutdown level"); + send_error(thd); + break; + } mysql_log.write(thd,command,NullS); send_eof(thd); #ifdef __WIN__ @@ -1650,6 +1667,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, kill_mysql(); error=TRUE; break; + } #endif case COM_STATISTICS: { diff --git a/tools/mysqlmanager.c b/tools/mysqlmanager.c index 45865e97ab7..bb0a76d6c49 100644 --- a/tools/mysqlmanager.c +++ b/tools/mysqlmanager.c @@ -687,7 +687,7 @@ HANDLE_DECL(handle_stop_exec) error="Process not running"; goto err; } - if (mysql_shutdown(&e->mysql)) + if (mysql_shutdown(&e->mysql, SHUTDOWN_DEFAULT)) { /* e->th=0; */ /* th may be a struct */ pthread_mutex_unlock(&e->lock); From 408dad07a949a570c59e5f660d648c4df727625c Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 15 Jun 2004 14:28:00 +0200 Subject: [PATCH 2/3] Adding SHUTDOWN_WAIT_STATEMENTS to the possible arguments of mysql_shutdown(). Comments on names still welcome. include/mysql_com.h: one more possible shutdown level --- include/mysql_com.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/mysql_com.h b/include/mysql_com.h index bfd38f4f0fc..ef84ad4dea2 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -239,8 +239,9 @@ enum enum_shutdown_level { */ SHUTDOWN_WAIT_CRITICAL_BUFFERS= 10, /* flush MyISAM buffs (no corruption) */ SHUTDOWN_WAIT_ALL_BUFFERS= 20, /* flush InnoDB buffers */ - SHUTDOWN_WAIT_TRANSACTIONS= 30, /* wait for existing trans to finish */ - SHUTDOWN_WAIT_CONNECTIONS= 40 /* wait for existing connections to finish */ + SHUTDOWN_WAIT_STATEMENTS= 30, + SHUTDOWN_WAIT_TRANSACTIONS= 40, /* wait for existing trans to finish */ + SHUTDOWN_WAIT_CONNECTIONS= 50 /* wait for existing connections to finish */ }; /* options for mysql_set_option */ From 83f485968f643cc87573d57be6944ff32b18d79a Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 18 Jun 2004 23:50:04 +0200 Subject: [PATCH 3/3] API change: mysql_shutdown() now requires a 2nd argument, the shutdown level. mysqld >=4.1.3 will however understand shutdown requests sent by clients <4.1.3. And mysqld <4.1.3 will understand shutdown requests sent by clients >=4.1.3 (it will ignore the level). Those shutdown level are just PLACEHOLDERS now. So this change is just to make the 4.1 API suitable before it is frozen. Later we will actually implement the shutdown levels. VC++Files/winmysqladmin/main.cpp: 2nd argument to mysql_shutdown() VC++Files/winmysqladmin/mysql.h: 2nd argument to mysql_shutdown() VC++Files/winmysqladmin/mysql_com.h: Several types of shutdown now. include/mysql_com.h: SHUTDOWN_DEFAULT is now 0 instead of 255, this saves one test in sql_parse.cc libmysql/libmysql.c: correcting mistake (how come that my tests still all worked with this? - should recheck, for curiosity). sql/sql_parse.cc: with SHUTDOWN_DEFAULT==0, no need for testing packet_length. --- VC++Files/winmysqladmin/main.cpp | 2 +- VC++Files/winmysqladmin/mysql.h | 4 +++- VC++Files/winmysqladmin/mysql_com.h | 21 +++++++++++++++++++++ include/mysql_com.h | 4 ++-- libmysql/libmysql.c | 3 +-- sql/sql_parse.cc | 17 ++++++++++------- 6 files changed, 38 insertions(+), 13 deletions(-) diff --git a/VC++Files/winmysqladmin/main.cpp b/VC++Files/winmysqladmin/main.cpp index 6ca29659255..dfb2004a780 100644 --- a/VC++Files/winmysqladmin/main.cpp +++ b/VC++Files/winmysqladmin/main.cpp @@ -1196,7 +1196,7 @@ bool __fastcall TForm1::Shutd() if (IsConnect) { mysql_kill(MySQL,mysql_thread_id(MySQL)); - mysql_shutdown(MySQL); + mysql_shutdown(MySQL, SHUTDOWN_DEFAULT); StatusLine->SimpleText = ""; } diff --git a/VC++Files/winmysqladmin/mysql.h b/VC++Files/winmysqladmin/mysql.h index e83babb8fa8..f01b55f5d3f 100644 --- a/VC++Files/winmysqladmin/mysql.h +++ b/VC++Files/winmysqladmin/mysql.h @@ -229,7 +229,9 @@ int STDCALL mysql_real_query(MYSQL *mysql, const char *q, unsigned int length); int STDCALL mysql_create_db(MYSQL *mysql, const char *DB); int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB); -int STDCALL mysql_shutdown(MYSQL *mysql); +int STDCALL mysql_shutdown(MYSQL *mysql, + enum enum_shutdown_level + shutdown_level); int STDCALL mysql_dump_debug_info(MYSQL *mysql); int STDCALL mysql_refresh(MYSQL *mysql, unsigned int refresh_options); diff --git a/VC++Files/winmysqladmin/mysql_com.h b/VC++Files/winmysqladmin/mysql_com.h index 2a1471f735d..7d7d77898c3 100644 --- a/VC++Files/winmysqladmin/mysql_com.h +++ b/VC++Files/winmysqladmin/mysql_com.h @@ -155,6 +155,27 @@ enum enum_field_types { FIELD_TYPE_DECIMAL, FIELD_TYPE_TINY, #define FIELD_TYPE_CHAR FIELD_TYPE_TINY /* For compability */ #define FIELD_TYPE_INTERVAL FIELD_TYPE_ENUM /* For compability */ +enum enum_shutdown_level { + /* + We want levels to be in growing order of gracefulness. So we leave room + for future intermediate levels. For now, escalating one level is += 10; + later if we insert new levels in between we will need a function + next_shutdown_level(level). Note that DEFAULT does not respect the + growing property. + */ + SHUTDOWN_DEFAULT= 0, /* mapped to WAIT_ALL_BUFFERS for now */ + /* + Here is the list in growing order (the next does the previous plus + something). WAIT_ALL_BUFFERS is what we have now. Others are "this MySQL + server does not support this shutdown level yet". + */ + SHUTDOWN_WAIT_CRITICAL_BUFFERS= 10, /* flush MyISAM buffs (no corruption) */ + SHUTDOWN_WAIT_ALL_BUFFERS= 20, /* flush InnoDB buffers */ + SHUTDOWN_WAIT_STATEMENTS= 30, /* wait for existing updating stmts to finish */ + SHUTDOWN_WAIT_TRANSACTIONS= 40, /* wait for existing trans to finish */ + SHUTDOWN_WAIT_CONNECTIONS= 50 /* wait for existing connections to finish */ +}; + extern unsigned long max_allowed_packet; extern unsigned long net_buffer_length; diff --git a/include/mysql_com.h b/include/mysql_com.h index ef84ad4dea2..90859b467c6 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -231,7 +231,7 @@ enum enum_shutdown_level { next_shutdown_level(level). Note that DEFAULT does not respect the growing property. */ - SHUTDOWN_DEFAULT= 255, /* mapped to WAIT_ALL_BUFFERS for now */ + SHUTDOWN_DEFAULT= 0, /* mapped to WAIT_ALL_BUFFERS for now */ /* Here is the list in growing order (the next does the previous plus something). WAIT_ALL_BUFFERS is what we have now. Others are "this MySQL @@ -239,7 +239,7 @@ enum enum_shutdown_level { */ SHUTDOWN_WAIT_CRITICAL_BUFFERS= 10, /* flush MyISAM buffs (no corruption) */ SHUTDOWN_WAIT_ALL_BUFFERS= 20, /* flush InnoDB buffers */ - SHUTDOWN_WAIT_STATEMENTS= 30, + SHUTDOWN_WAIT_STATEMENTS= 30, /* wait for existing updating stmts to finish */ SHUTDOWN_WAIT_TRANSACTIONS= 40, /* wait for existing trans to finish */ SHUTDOWN_WAIT_CONNECTIONS= 50 /* wait for existing connections to finish */ }; diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 1e8244e670b..7135488aade 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -1290,8 +1290,7 @@ mysql_shutdown(MYSQL *mysql, enum enum_shutdown_level shutdown_level) uchar level[1]; level[0]= (uchar) shutdown_level; DBUG_ENTER("mysql_shutdown"); - DBUG_RETURN(simple_command(mysql, COM_SHUTDOWN, - &level, 1, 0)); + DBUG_RETURN(simple_command(mysql, COM_SHUTDOWN, (char *)level, 1, 0)); } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index b0d476c695f..cfb04c96d8d 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1308,7 +1308,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (command != COM_STATISTICS && command != COM_PING) query_id++; thread_running++; - /* TODO: set thd->lex->sql_command to SQLCOM_PARSE here */ + /* TODO: set thd->lex->sql_command to SQLCOM_END here */ VOID(pthread_mutex_unlock(&LOCK_thread_count)); thd->server_status&= @@ -1479,7 +1479,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->query_length= length; thd->query= packet; thd->query_id= query_id++; - /* TODO: set thd->lex->sql_command to SQLCOM_PARSE here */ + /* TODO: set thd->lex->sql_command to SQLCOM_END here */ VOID(pthread_mutex_unlock(&LOCK_thread_count)); #ifndef EMBEDDED_LIBRARY mysql_parse(thd, packet, length); @@ -1637,13 +1637,15 @@ bool dispatch_command(enum enum_server_command command, THD *thd, statistic_increment(com_other,&LOCK_status); if (check_global_access(thd,SHUTDOWN_ACL)) break; /* purecov: inspected */ - enum enum_shutdown_level level= (packet_length >= 2) ? - (enum enum_shutdown_level) (uchar) packet[0] : SHUTDOWN_DEFAULT; - DBUG_PRINT("quit",("Got shutdown command for level %u", level)); /* - Accept old mysql_shutdown (with no argument). For now we do nothing of - the argument. + If the client is < 4.1.3, it is going to send us no argument; then + packet_length is 1, packet[0] is the end 0 of the packet. Note that + SHUTDOWN_DEFAULT is 0. If client is >= 4.1.3, the shutdown level is in + packet[0]. */ + enum enum_shutdown_level level= + (enum enum_shutdown_level) (uchar) packet[0]; + DBUG_PRINT("quit",("Got shutdown command for level %u", level)); if (level == SHUTDOWN_DEFAULT) level= SHUTDOWN_WAIT_ALL_BUFFERS; // soon default will be configurable else if (level != SHUTDOWN_WAIT_ALL_BUFFERS) @@ -1652,6 +1654,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, send_error(thd); break; } + DBUG_PRINT("quit",("Got shutdown command for level %u", level)); mysql_log.write(thd,command,NullS); send_eof(thd); #ifdef __WIN__