diff options
author | unknown <guilhem@mysql.com> | 2003-10-31 23:20:23 +0100 |
---|---|---|
committer | unknown <guilhem@mysql.com> | 2003-10-31 23:20:23 +0100 |
commit | b920ab261e7aea61a7b8a5b950faafa1ce719d4c (patch) | |
tree | 498d4bfea3f5514d76aac06dd4120c7aa8b1a02c | |
parent | 40ed42e14a7911a879c11e0b23b0730d763f6651 (diff) | |
download | mariadb-git-b920ab261e7aea61a7b8a5b950faafa1ce719d4c.tar.gz |
4 small items in this:
- when we don't have in_addr_t, use uint32.
- a forgotten initialization of slave_proxy_id in sql/log_event.cc (was not really "forgot", was
"we needn't init it there", but there was one case where we needed...).
- made slave_proxy_id always meaningful in THD and Log_event, so we can
rely more on it (no need to test if it's meaningful). THD::slave_proxy_id
is equal to THD::thread_id except for the slave SQL thread.
- clean up the slave's temporary table (i.e. free their memory) when slave
server shuts down.
extra/resolveip.c:
removed #define as it is simpler to put it in my_net.h
(because we need the #define elsewhere)
include/my_net.h:
When in_addr_t is not defined, use uint32.
libmysql/libmysql.c:
using in_addr_t is more generic.
libmysql/manager.c:
using in_addr_t is more generic.
mysql-test/t/rpl_chain_temp_table.test:
comments
sql/log_event.cc:
* Had forgot to initialize slave_proxy_id in the event constructor (char* buf...).
Initializing is in fact only needed for Create_file_log_event, because
it uses slave_proxy_id even if it does not write an event to the binlog
(it uses slave_proxy_id to write it to SQL-LOAD.info).
* When we write events we now always write slave_proxy_id, which is now always
meaningful (as thd->slave_proxy_id is now always meaningful, see change in
sql_class.cc).
sql/mini_client.cc:
in_addr_t is more generic.
sql/slave.cc:
A RELAY_LOG_INFO method to free the slave's temporary tables from memory
at slave's server shutdown.
It is called by end_slave(), which is called by close_connections(),
which is called when the server terminates
(close_connections() is just before clean_up(); putting the call in
clean_up() was buggy, as active_mi is already deleted by close_connections().
sql/slave.h:
new method
sql/sql_class.cc:
By default we set THD::slave_proxy_id to THD::thread_id,
so THD::slave_proxy_id is always meaningful (not 0).
It's always the same as the thread id except for the slave
SQL thread.
-rw-r--r-- | extra/resolveip.c | 4 | ||||
-rw-r--r-- | include/my_net.h | 9 | ||||
-rw-r--r-- | libmysql/libmysql.c | 2 | ||||
-rw-r--r-- | libmysql/manager.c | 2 | ||||
-rw-r--r-- | mysql-test/t/rpl_chain_temp_table.test | 10 | ||||
-rw-r--r-- | sql/log_event.cc | 10 | ||||
-rw-r--r-- | sql/mini_client.cc | 2 | ||||
-rw-r--r-- | sql/slave.cc | 21 | ||||
-rw-r--r-- | sql/slave.h | 1 | ||||
-rw-r--r-- | sql/sql_class.cc | 5 |
10 files changed, 53 insertions, 13 deletions
diff --git a/extra/resolveip.c b/extra/resolveip.c index 6d05152e20b..d3caa9e1d45 100644 --- a/extra/resolveip.c +++ b/extra/resolveip.c @@ -36,10 +36,6 @@ extern int h_errno; #endif -#ifndef HAVE_IN_ADDR_T -#define in_addr_t ulong -#endif - static my_bool silent; static struct my_option my_long_options[] = diff --git a/include/my_net.h b/include/my_net.h index 28d862d8528..7b42afa1f3a 100644 --- a/include/my_net.h +++ b/include/my_net.h @@ -63,6 +63,15 @@ C_MODE_START #define O_NONBLOCK 1 /* For emulation of fcntl() */ #endif +/* + On OSes which don't have the in_addr_t, we guess that using uint32 is the best + possible choice. We guess this from the fact that on HP-UX64bit & FreeBSD64bit + & Solaris64bit, in_addr_t is equivalent to uint32. And on Linux32bit too. +*/ +#ifndef HAVE_IN_ADDR_T +#define in_addr_t uint32 +#endif + /* Thread safe or portable version of some functions */ void my_inet_ntoa(struct in_addr in, char *buf); diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index d8966b30fb9..5d809adf36a 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -1623,7 +1623,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, char buff[NAME_LEN+USERNAME_LENGTH+100],charset_name_buff[16]; char *end,*host_info,*charset_name; my_socket sock; - uint32 ip_addr; + in_addr_t ip_addr; struct sockaddr_in sock_addr; ulong pkt_length; NET *net= &mysql->net; diff --git a/libmysql/manager.c b/libmysql/manager.c index d4bd8d5520b..1a4ac718ef9 100644 --- a/libmysql/manager.c +++ b/libmysql/manager.c @@ -90,7 +90,7 @@ MYSQL_MANAGER* STDCALL mysql_manager_connect(MYSQL_MANAGER* con, { my_socket sock; struct sockaddr_in sock_addr; - uint32 ip_addr; + in_addr_t ip_addr; char msg_buf[MAX_MYSQL_MANAGER_MSG]; int msg_len; Vio* vio; diff --git a/mysql-test/t/rpl_chain_temp_table.test b/mysql-test/t/rpl_chain_temp_table.test index 65701d8a078..007b018e9d8 100644 --- a/mysql-test/t/rpl_chain_temp_table.test +++ b/mysql-test/t/rpl_chain_temp_table.test @@ -3,6 +3,7 @@ # stop/restart servers. Note that if assumptions are wrong, the test will not # fail; it will just fail to test the error-prone scenario. # Using the manager is the only way to have more than one slave server. +# So you must run this test with --manager. require_manager; server_stop master; @@ -87,3 +88,12 @@ drop table t2; save_master_pos; connection slave_sec; sync_with_master; + +# On purpose, we don't delete the temporary tables explicitely. +# So temp tables remain on slave (remember they are not deleted when the slave +# SQL thread terminates). If you run this test with +# --valgrind --valgrind-options=--show-reachable=yes +# you will see if they get cleaned up at slave's shutdown (that is, if the +# memory they use is freed (it should) by mysqld before it terminates). +# If they wouldn't be cleaned up, you would see some "still reachable" blocks in +# Valgrind. diff --git a/sql/log_event.cc b/sql/log_event.cc index 4f241c6b992..d17c94a2b44 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -874,7 +874,7 @@ Query_log_event::Query_log_event(const char* buf, int event_len, return; memcpy(data_buf, buf + Q_DATA_OFFSET, data_len); - thread_id = uint4korr(buf + Q_THREAD_ID_OFFSET); + slave_proxy_id= thread_id= uint4korr(buf + Q_THREAD_ID_OFFSET); db = data_buf; db_len = (uint)buf[Q_DB_LEN_OFFSET]; query=data_buf + db_len + 1; @@ -955,8 +955,7 @@ int Query_log_event::write_data(IO_CACHE* file) SET PSEUDO_THREAD_ID= for each query using temp tables. */ - int4store(buf + Q_THREAD_ID_OFFSET, (slave_proxy_id ? slave_proxy_id : - thread_id)); + int4store(buf + Q_THREAD_ID_OFFSET, slave_proxy_id); int4store(buf + Q_EXEC_TIME_OFFSET, exec_time); buf[Q_DB_LEN_OFFSET] = (char) db_len; int2store(buf + Q_ERR_CODE_OFFSET, error_code); @@ -1057,8 +1056,7 @@ void Rand_log_event::print(FILE* file, bool short_form, char* last_db) int Load_log_event::write_data_header(IO_CACHE* file) { char buf[LOAD_HEADER_LEN]; - int4store(buf + L_THREAD_ID_OFFSET, (slave_proxy_id ? slave_proxy_id : - thread_id)); + int4store(buf + L_THREAD_ID_OFFSET, slave_proxy_id); int4store(buf + L_EXEC_TIME_OFFSET, exec_time); int4store(buf + L_SKIP_LINES_OFFSET, skip_lines); buf[L_TBL_LEN_OFFSET] = (char)table_name_len; @@ -1276,7 +1274,7 @@ int Load_log_event::copy_log_event(const char *buf, ulong event_len, char* buf_end = (char*)buf + event_len; uint header_len= old_format ? OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN; const char* data_head = buf + header_len; - thread_id = uint4korr(data_head + L_THREAD_ID_OFFSET); + slave_proxy_id= thread_id= uint4korr(data_head + L_THREAD_ID_OFFSET); exec_time = uint4korr(data_head + L_EXEC_TIME_OFFSET); skip_lines = uint4korr(data_head + L_SKIP_LINES_OFFSET); table_name_len = (uint)data_head[L_TBL_LEN_OFFSET]; diff --git a/sql/mini_client.cc b/sql/mini_client.cc index f204c38c18c..2de5227a953 100644 --- a/sql/mini_client.cc +++ b/sql/mini_client.cc @@ -547,7 +547,7 @@ mc_mysql_connect(MYSQL *mysql,const char *host, const char *user, { char buff[NAME_LEN+USERNAME_LENGTH+100],*end,*host_info; my_socket sock; - uint32 ip_addr; + in_addr_t ip_addr; struct sockaddr_in sock_addr; ulong pkt_length; NET *net= &mysql->net; diff --git a/sql/slave.cc b/sql/slave.cc index 90b0cc74fd8..da63ca71951 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -324,6 +324,20 @@ void init_slave_skip_errors(const char* arg) } } +void st_relay_log_info::close_temporary_tables() +{ + TABLE *table,*next; + + for (table=save_temporary_tables ; table ; table=next) + { + next=table->next; + /* + 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. + */ + close_temporary(table, 0); + } +} /* We assume we have a run lock on rli and that both slave thread @@ -790,6 +804,7 @@ static int end_slave_on_walk(MASTER_INFO* mi, gptr /*unused*/) void end_slave() { + /* This is called when the server terminates, in close_connections(). */ if (active_mi) { /* @@ -3092,6 +3107,12 @@ void end_relay_log_info(RELAY_LOG_INFO* rli) } rli->inited = 0; rli->relay_log.close(LOG_CLOSE_INDEX | LOG_CLOSE_STOP_EVENT); + /* + Delete the slave's temporary tables from memory. + In the future there will be other actions than this, to ensure persistance + of slave's temp tables after shutdown. + */ + rli->close_temporary_tables(); DBUG_VOID_RETURN; } diff --git a/sql/slave.h b/sql/slave.h index 778ddf2ec72..8f7d96b23dd 100644 --- a/sql/slave.h +++ b/sql/slave.h @@ -239,6 +239,7 @@ typedef struct st_relay_log_info int wait_for_pos(THD* thd, String* log_name, longlong log_pos, longlong timeout); + void st_relay_log_info::close_temporary_tables(); } RELAY_LOG_INFO; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 132e0d7745f..3ea61da28fc 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -323,6 +323,11 @@ bool THD::store_globals() return 1; mysys_var=my_thread_var; dbug_thread_id=my_thread_id(); + /* + By default 'slave_proxy_id' is 'thread_id'. They may later become different + if this is the slave SQL thread. + */ + slave_proxy_id= thread_id; return 0; } |