--- Percona-Server-5.1.59/sql/set_var.cc 2011-10-16 22:16:06.000000000 +0800 +++ Percona-Server-5.1.59-debug/sql/set_var.cc 2011-12-23 14:47:13.000000000 +0800 @@ -754,7 +754,14 @@ SYSTEM_TYPE); static sys_var_thd_ulong sys_net_wait_timeout(&vars, "wait_timeout", &SV::net_wait_timeout); - +/* Add For Kill Idle Transaction By P.Linux*/ +static sys_var_thd_ulong sys_trx_idle_timeout(&vars, "trx_idle_timeout", + &SV::trx_idle_timeout); +static sys_var_thd_ulong sys_trx_readonly_idle_timeout(&vars, "trx_readonly_idle_timeout", + &SV::trx_readonly_idle_timeout); +static sys_var_thd_ulong sys_trx_changes_idle_timeout(&vars, "trx_changes_idle_timeout", + &SV::trx_changes_idle_timeout); +/* End */ /* Condition pushdown to storage engine */ static sys_var_thd_bool sys_engine_condition_pushdown(&vars, "engine_condition_pushdown", --- Percona-Server-5.1.59/sql/sql_class.h 2011-10-16 22:16:06.000000000 +0800 +++ Percona-Server-5.1.59-debug/sql/sql_class.h 2011-12-23 19:14:48.000000000 +0800 @@ -325,6 +325,11 @@ ulong net_read_timeout; ulong net_retry_count; ulong net_wait_timeout; + /* Add For Kill Idle Transaction By P.Linux */ + ulong trx_idle_timeout; + ulong trx_readonly_idle_timeout; + ulong trx_changes_idle_timeout; + /* End */ ulong net_write_timeout; ulong optimizer_prune_level; ulong optimizer_search_depth; @@ -1488,6 +1493,9 @@ uint last_errno; + /* Add For Kill Idle Transaction By P.Linux */ + bool is_readonly_trx; // This Thread is in a readonly Transaction? + /* End */ /* <> 0 if we are inside of trigger or stored function. */ uint in_sub_stmt; /* TRUE when the current top has SQL_LOG_BIN ON */ --- Percona-Server-5.1.59/sql/sql_class.cc 2011-10-16 22:16:05.000000000 +0800 +++ Percona-Server-5.1.59-debug/sql/sql_class.cc 2011-12-23 19:05:54.000000000 +0800 @@ -707,6 +707,9 @@ #ifdef ERROR_INJECT_SUPPORT error_inject_value= 0UL; #endif + /* Add For Kill Idle Transaction By P.Linux */ + is_readonly_trx = TRUE; + /* End */ // Must be reset to handle error with THD's created for init of mysqld lex->current_select= 0; start_time=(time_t) 0; --- Percona-Server-5.1.59/sql/sql_parse.cc 2011-10-16 22:16:06.000000000 +0800 +++ Percona-Server-5.1.59-debug/sql/sql_parse.cc 2011-12-23 20:17:42.000000000 +0800 @@ -143,6 +143,7 @@ thd->options&= ~(ulong) OPTION_BEGIN; thd->transaction.all.modified_non_trans_table= FALSE; thd->server_status&= ~SERVER_STATUS_IN_TRANS; + thd->is_readonly_trx = TRUE; xid_cache_delete(&thd->transaction.xid_state); thd->transaction.xid_state.xa_state= XA_NOTR; @@ -183,6 +184,7 @@ if (!thd->locked_tables) thd->options&= ~OPTION_TABLE_LOCK; thd->server_status&= ~SERVER_STATUS_IN_TRANS; + thd->is_readonly_trx = TRUE; if (ha_commit(thd)) error=1; } @@ -212,6 +214,7 @@ { thd->options|= OPTION_BEGIN; thd->server_status|= SERVER_STATUS_IN_TRANS; + thd->is_readonly_trx = TRUE; } return error; } @@ -754,6 +757,7 @@ (Which of course should never happen...) */ thd->server_status&= ~SERVER_STATUS_IN_TRANS; + thd->is_readonly_trx = TRUE; res= ha_commit(thd); thd->options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG); thd->transaction.all.modified_non_trans_table= FALSE; @@ -771,6 +775,7 @@ case ROLLBACK_AND_CHAIN: { thd->server_status&= ~SERVER_STATUS_IN_TRANS; + thd->is_readonly_trx = TRUE; if (ha_rollback(thd)) res= -1; thd->options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG); @@ -828,8 +833,25 @@ the client, the connection is closed or "net_wait_timeout" number of seconds has passed */ - my_net_set_read_timeout(net, thd->variables.net_wait_timeout); - + /* Add For Kill Idle Transaction By P.Linux */ + if (thd->active_transaction()) + { + if (thd->variables.trx_idle_timeout > 0) + { + my_net_set_read_timeout(net, thd->variables.trx_idle_timeout); + } else if (thd->variables.trx_readonly_idle_timeout > 0 && thd->is_readonly_trx) + { + my_net_set_read_timeout(net, thd->variables.trx_readonly_idle_timeout); + } else if (thd->variables.trx_changes_idle_timeout > 0 && !thd->is_readonly_trx) + { + my_net_set_read_timeout(net, thd->variables.trx_changes_idle_timeout); + } else { + my_net_set_read_timeout(net, thd->variables.net_wait_timeout); + } + } else { + my_net_set_read_timeout(net, thd->variables.net_wait_timeout); + } + /* End */ /* XXX: this code is here only to clear possible errors of init_connect. Consider moving to init_connect() instead. @@ -2350,7 +2372,21 @@ status_var_increment(thd->status_var.com_stat[lex->sql_command]); DBUG_ASSERT(thd->transaction.stmt.modified_non_trans_table == FALSE); - + + /* Add For Kill Idle Transaction By P.Linux */ + switch (lex->sql_command) { + case SQLCOM_DELETE_MULTI: + case SQLCOM_UPDATE_MULTI: + case SQLCOM_UPDATE: + case SQLCOM_INSERT: + case SQLCOM_INSERT_SELECT: + case SQLCOM_DELETE: + case SQLCOM_REPLACE: + case SQLCOM_REPLACE_SELECT: + thd->is_readonly_trx = FALSE; + break; + } + /* End */ switch (lex->sql_command) { case SQLCOM_SHOW_EVENTS: @@ -4965,6 +5001,7 @@ thd->transaction.all.modified_non_trans_table= FALSE; thd->options= ((thd->options & ~(OPTION_KEEP_LOG)) | OPTION_BEGIN); thd->server_status|= SERVER_STATUS_IN_TRANS; + thd->is_readonly_trx = TRUE; my_ok(thd); break; case SQLCOM_XA_END: @@ -5082,6 +5119,7 @@ thd->options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG); thd->transaction.all.modified_non_trans_table= FALSE; thd->server_status&= ~SERVER_STATUS_IN_TRANS; + thd->is_readonly_trx = TRUE; xid_cache_delete(&thd->transaction.xid_state); thd->transaction.xid_state.xa_state=XA_NOTR; break;