2011-10-01 21:23:01 +02:00
|
|
|
/* Copyright (C) 2010 Sergei Golubchik and Monty Program 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; version 2 of the License.
|
|
|
|
|
|
|
|
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
|
Update FSF address
This commit is based on the work of Michal Schorm, rebased on the
earliest MariaDB version.
Th command line used to generate this diff was:
find ./ -type f \
-exec sed -i -e 's/Foundation, Inc., 59 Temple Place, Suite 330, Boston, /Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, /g' {} \; \
-exec sed -i -e 's/Foundation, Inc. 59 Temple Place.* Suite 330, Boston, /Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, /g' {} \; \
-exec sed -i -e 's/MA.*.....-1307.*USA/MA 02110-1335 USA/g' {} \; \
-exec sed -i -e 's/Foundation, Inc., 59 Temple/Foundation, Inc., 51 Franklin/g' {} \; \
-exec sed -i -e 's/Place, Suite 330, Boston, MA.*02111-1307.*USA/Street, Fifth Floor, Boston, MA 02110-1335 USA/g' {} \; \
-exec sed -i -e 's/MA.*.....-1307/MA 02110-1335/g' {} \;
2019-05-10 20:49:46 +03:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
|
2011-10-01 21:23:01 +02:00
|
|
|
|
|
|
|
#include "feedback.h"
|
2011-11-22 18:04:38 +01:00
|
|
|
#include <sql_acl.h>
|
|
|
|
#include <sql_parse.h>
|
2014-08-25 19:08:01 +02:00
|
|
|
#include <sql_show.h>
|
2011-10-01 21:23:01 +02:00
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
namespace feedback {
|
|
|
|
|
|
|
|
static THD *thd= 0; ///< background thread thd
|
|
|
|
static my_thread_id thd_thread_id; ///< its thread_id
|
|
|
|
|
|
|
|
static size_t needed_size= 20480;
|
|
|
|
|
2015-12-06 11:51:57 +01:00
|
|
|
ulong startup_interval= 60*5; ///< in seconds (5 minutes)
|
|
|
|
ulong first_interval= 60*60*24; ///< in seconds (one day)
|
|
|
|
ulong interval= 60*60*24*7; ///< in seconds (one week)
|
2011-10-01 21:23:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
reads the rows from a table and puts them, concatenated, in a String
|
|
|
|
|
|
|
|
@note
|
|
|
|
1. only supports two column tables - no less, no more.
|
|
|
|
2. it emulates mysql -e "select * from..." and thus it separates
|
|
|
|
columns with \t and starts the output with column names.
|
|
|
|
*/
|
|
|
|
static int table_to_string(TABLE *table, String *result)
|
|
|
|
{
|
2018-02-06 17:14:05 +00:00
|
|
|
int res;
|
2011-10-01 21:23:01 +02:00
|
|
|
char buff1[MAX_FIELD_WIDTH], buff2[MAX_FIELD_WIDTH];
|
|
|
|
String str1(buff1, sizeof(buff1), system_charset_info);
|
|
|
|
String str2(buff2, sizeof(buff2), system_charset_info);
|
|
|
|
|
|
|
|
res= table->file->ha_rnd_init(1);
|
|
|
|
|
MDEV-17556 Assertion `bitmap_is_set_all(&table->s->all_set)' failed
The assertion failed in handler::ha_reset upon SELECT under
READ UNCOMMITTED from table with index on virtual column.
This was the debug-only failure, though the problem is mush wider:
* MY_BITMAP is a structure containing my_bitmap_map, the latter is a raw
bitmap.
* read_set, write_set and vcol_set of TABLE are the pointers to MY_BITMAP
* The rest of MY_BITMAPs are stored in TABLE and TABLE_SHARE
* The pointers to the stored MY_BITMAPs, like orig_read_set etc, and
sometimes all_set and tmp_set, are assigned to the pointers.
* Sometimes tmp_use_all_columns is used to substitute the raw bitmap
directly with all_set.bitmap
* Sometimes even bitmaps are directly modified, like in
TABLE::update_virtual_field(): bitmap_clear_all(&tmp_set) is called.
The last three bullets in the list, when used together (which is mostly
always) make the program flow cumbersome and impossible to follow,
notwithstanding the errors they cause, like this MDEV-17556, where tmp_set
pointer was assigned to read_set, write_set and vcol_set, then its bitmap
was substituted with all_set.bitmap by dbug_tmp_use_all_columns() call,
and then bitmap_clear_all(&tmp_set) was applied to all this.
To untangle this knot, the rule should be applied:
* Never substitute bitmaps! This patch is about this.
orig_*, all_set bitmaps are never substituted already.
This patch changes the following function prototypes:
* tmp_use_all_columns, dbug_tmp_use_all_columns
to accept MY_BITMAP** and to return MY_BITMAP * instead of my_bitmap_map*
* tmp_restore_column_map, dbug_tmp_restore_column_maps to accept
MY_BITMAP* instead of my_bitmap_map*
These functions now will substitute read_set/write_set/vcol_set directly,
and won't touch underlying bitmaps.
2020-12-29 13:38:16 +10:00
|
|
|
dbug_tmp_use_all_columns(table, &table->read_set);
|
2011-10-01 21:23:01 +02:00
|
|
|
|
2011-10-07 00:18:30 +02:00
|
|
|
while(!res && !table->file->ha_rnd_next(table->record[0]))
|
2011-10-01 21:23:01 +02:00
|
|
|
{
|
|
|
|
table->field[0]->val_str(&str1);
|
|
|
|
table->field[1]->val_str(&str2);
|
|
|
|
if (result->reserve(str1.length() + str2.length() + 3))
|
|
|
|
res= 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result->qs_append(str1.ptr(), str1.length());
|
|
|
|
result->qs_append('\t');
|
|
|
|
result->qs_append(str2.ptr(), str2.length());
|
|
|
|
result->qs_append('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-06 17:14:05 +00:00
|
|
|
res = res || (int)result->append('\n');
|
2011-10-01 21:23:01 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Note, "|=" and not "||" - because we want to call ha_rnd_end()
|
|
|
|
even if res is already 1.
|
|
|
|
*/
|
|
|
|
res |= table->file->ha_rnd_end();
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initialize the THD and TABLE_LIST
|
|
|
|
|
|
|
|
The structures must be sufficiently initialized for create_tmp_table()
|
|
|
|
and fill_feedback() to work.
|
|
|
|
*/
|
|
|
|
static int prepare_for_fill(TABLE_LIST *tables)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Add our thd to the list, for it to be visible in SHOW PROCESSLIST.
|
|
|
|
But don't generate thread_id every time - use the saved value
|
|
|
|
(every increment of global thread_id counts as a new connection
|
|
|
|
in SHOW STATUS and we want to avoid skewing the statistics)
|
|
|
|
*/
|
2016-04-07 19:51:40 +03:00
|
|
|
thd->variables.pseudo_thread_id= thd->thread_id;
|
2019-01-20 02:32:35 +04:00
|
|
|
server_threads.insert(thd);
|
2011-10-01 21:23:01 +02:00
|
|
|
thd->thread_stack= (char*) &tables;
|
2020-04-30 20:06:26 +03:00
|
|
|
thd->store_globals();
|
2011-10-01 21:23:01 +02:00
|
|
|
|
|
|
|
thd->mysys_var->current_cond= &sleep_condition;
|
|
|
|
thd->mysys_var->current_mutex= &sleep_mutex;
|
2023-11-06 17:37:11 +02:00
|
|
|
thd->mark_connection_idle();
|
2011-10-01 21:23:01 +02:00
|
|
|
thd->proc_info="feedback";
|
|
|
|
thd->system_thread= SYSTEM_THREAD_EVENT_WORKER; // whatever
|
|
|
|
thd->set_time();
|
|
|
|
thd->init_for_queries();
|
|
|
|
thd->real_id= pthread_self();
|
2018-01-07 18:03:44 +02:00
|
|
|
thd->db= null_clex_str;
|
2011-10-01 21:23:01 +02:00
|
|
|
thd->security_ctx->host_or_ip= "";
|
|
|
|
thd->security_ctx->db_access= DB_ACLS;
|
2020-02-09 21:53:11 +04:00
|
|
|
thd->security_ctx->master_access= ALL_KNOWN_ACL;
|
2011-10-01 21:23:01 +02:00
|
|
|
bzero((char*) &thd->net, sizeof(thd->net));
|
|
|
|
lex_start(thd);
|
2022-10-21 17:16:05 +02:00
|
|
|
thd->lex->init_select();
|
2011-10-01 21:23:01 +02:00
|
|
|
|
2023-04-26 15:27:01 +04:00
|
|
|
const LEX_CSTRING tbl_name= i_s_feedback->table_name;
|
2018-01-07 18:03:44 +02:00
|
|
|
|
|
|
|
tables->init_one_table(&INFORMATION_SCHEMA_NAME, &tbl_name, 0, TL_READ);
|
2011-10-01 21:23:01 +02:00
|
|
|
tables->schema_table= i_s_feedback;
|
2020-12-11 20:35:25 +01:00
|
|
|
tables->schema_table_reformed= 1;
|
2018-07-06 16:26:19 +02:00
|
|
|
tables->select_lex= thd->lex->first_select_lex();
|
|
|
|
DBUG_ASSERT(tables->select_lex);
|
2014-08-25 19:08:01 +02:00
|
|
|
tables->table= create_schema_table(thd, tables);
|
2011-10-01 21:23:01 +02:00
|
|
|
if (!tables->table)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
tables->table->pos_in_table_list= tables;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Try to detect if this thread is going down
|
|
|
|
|
|
|
|
which can happen for different reasons:
|
|
|
|
* plugin is being unloaded
|
|
|
|
* mysqld server is being shut down
|
|
|
|
* the thread is being killed
|
|
|
|
|
|
|
|
*/
|
|
|
|
static bool going_down()
|
|
|
|
{
|
2019-01-25 14:24:35 +04:00
|
|
|
return shutdown_plugin || abort_loop || (thd && thd->killed);
|
2011-10-01 21:23:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
just like sleep, but waits on a condition and checks "plugin shutdown" status
|
|
|
|
*/
|
2011-10-04 15:48:39 +02:00
|
|
|
static int slept_ok(time_t sec)
|
2011-10-01 21:23:01 +02:00
|
|
|
{
|
|
|
|
struct timespec abstime;
|
|
|
|
int ret= 0;
|
|
|
|
|
|
|
|
set_timespec(abstime, sec);
|
|
|
|
|
2011-11-22 18:04:38 +01:00
|
|
|
mysql_mutex_lock(&sleep_mutex);
|
2011-10-01 21:23:01 +02:00
|
|
|
while (!going_down() && ret != ETIMEDOUT)
|
2011-11-22 18:04:38 +01:00
|
|
|
ret= mysql_cond_timedwait(&sleep_condition, &sleep_mutex, &abstime);
|
|
|
|
mysql_mutex_unlock(&sleep_mutex);
|
2011-10-01 21:23:01 +02:00
|
|
|
|
2011-10-04 15:48:39 +02:00
|
|
|
return !going_down();
|
2011-10-01 21:23:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
create a feedback report and send it to all specified urls
|
|
|
|
|
|
|
|
If "when" argument is not null, only it and the server uid are sent.
|
|
|
|
Otherwise a full report is generated.
|
|
|
|
*/
|
|
|
|
static void send_report(const char *when)
|
|
|
|
{
|
|
|
|
TABLE_LIST tables;
|
|
|
|
String str;
|
|
|
|
int i, last_todo;
|
|
|
|
Url **todo= (Url**)alloca(url_count*sizeof(Url*));
|
|
|
|
|
|
|
|
str.alloc(needed_size); // preallocate it to avoid many small mallocs
|
|
|
|
|
|
|
|
/*
|
|
|
|
on startup and shutdown the server may not be completely
|
|
|
|
initialized, and full report won't work.
|
|
|
|
We send a short status notice only.
|
|
|
|
*/
|
|
|
|
if (when)
|
|
|
|
{
|
|
|
|
str.length(0);
|
|
|
|
str.append(STRING_WITH_LEN("FEEDBACK_SERVER_UID"));
|
|
|
|
str.append('\t');
|
2024-07-03 13:27:23 +02:00
|
|
|
str.append(server_uid, sizeof(server_uid)-1);
|
2011-10-01 21:23:01 +02:00
|
|
|
str.append('\n');
|
|
|
|
str.append(STRING_WITH_LEN("FEEDBACK_WHEN"));
|
|
|
|
str.append('\t');
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 20:29:55 +03:00
|
|
|
str.append(when, strlen(when));
|
2011-10-01 21:23:01 +02:00
|
|
|
str.append('\n');
|
|
|
|
str.append(STRING_WITH_LEN("FEEDBACK_USER_INFO"));
|
|
|
|
str.append('\t');
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 20:29:55 +03:00
|
|
|
str.append(user_info, strlen(user_info));
|
2011-10-01 21:23:01 +02:00
|
|
|
str.append('\n');
|
|
|
|
str.append('\n');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
otherwise, prepare the THD and TABLE_LIST,
|
|
|
|
create and fill the temporary table with data just like
|
2017-05-17 15:16:24 +02:00
|
|
|
SELECT * FROM INFORMATION_SCHEMA.FEEDBACK is doing,
|
2011-10-01 21:23:01 +02:00
|
|
|
read and concatenate table data into a String.
|
|
|
|
*/
|
2016-04-07 19:51:40 +03:00
|
|
|
if (!(thd= new THD(thd_thread_id)))
|
2011-10-01 21:23:01 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (prepare_for_fill(&tables))
|
|
|
|
goto ret;
|
|
|
|
|
|
|
|
if (fill_feedback(thd, &tables, NULL))
|
|
|
|
goto ret;
|
|
|
|
|
|
|
|
if (table_to_string(tables.table, &str))
|
|
|
|
goto ret;
|
|
|
|
|
|
|
|
needed_size= (size_t)(str.length() * 1.1);
|
|
|
|
|
|
|
|
free_tmp_table(thd, tables.table);
|
|
|
|
tables.table= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Try to send the report on every url from the list, remove url on success,
|
|
|
|
keep failed in the list. Repeat until the list is empty.
|
|
|
|
*/
|
|
|
|
memcpy(todo, urls, url_count*sizeof(Url*));
|
|
|
|
last_todo= url_count - 1;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
for (i= 0; i <= last_todo;)
|
|
|
|
{
|
|
|
|
Url *url= todo[i];
|
|
|
|
|
|
|
|
if (thd) // for nicer SHOW PROCESSLIST
|
2017-09-28 10:38:02 +00:00
|
|
|
thd->set_query(const_cast<char*>(url->url()), (uint) url->url_length());
|
2011-10-01 21:23:01 +02:00
|
|
|
|
|
|
|
if (url->send(str.ptr(), str.length()))
|
|
|
|
i++;
|
|
|
|
else
|
|
|
|
todo[i]= todo[last_todo--];
|
|
|
|
}
|
|
|
|
if (last_todo < 0)
|
|
|
|
break;
|
2011-10-04 15:48:39 +02:00
|
|
|
} while (slept_ok(send_retry_wait)); // wait a little bit before retrying
|
2011-10-01 21:23:01 +02:00
|
|
|
|
|
|
|
ret:
|
|
|
|
if (thd)
|
|
|
|
{
|
|
|
|
if (tables.table)
|
|
|
|
free_tmp_table(thd, tables.table);
|
2015-12-07 14:07:36 +01:00
|
|
|
thd->cleanup_after_query();
|
2011-10-01 21:23:01 +02:00
|
|
|
/*
|
|
|
|
clean up, free the thd.
|
|
|
|
reset all thread local status variables to minimize
|
|
|
|
the effect of the background thread on SHOW STATUS.
|
|
|
|
*/
|
2019-01-20 02:32:35 +04:00
|
|
|
server_threads.erase(thd);
|
MDEV-9101 Limit size of created disk temporary files and tables
Two new variables added:
- max_tmp_space_usage : Limits the the temporary space allowance per user
- max_total_tmp_space_usage: Limits the temporary space allowance for
all users.
New status variables: tmp_space_used & max_tmp_space_used
New field in information_schema.process_list: TMP_SPACE_USED
The temporary space is counted for:
- All SQL level temporary files. This includes files for filesort,
transaction temporary space, analyze, binlog_stmt_cache etc.
It does not include engine internal temporary files used for repair,
alter table, index pre sorting etc.
- All internal on disk temporary tables created as part of resolving a
SELECT, multi-source update etc.
Special cases:
- When doing a commit, the last flush of the binlog_stmt_cache
will not cause an error even if the temporary space limit is exceeded.
This is to avoid giving errors on commit. This means that a user
can temporary go over the limit with up to binlog_stmt_cache_size.
Noteworthy issue:
- One has to be careful when using small values for max_tmp_space_limit
together with binary logging and with non transactional tables.
If a the binary log entry for the query is bigger than
binlog_stmt_cache_size and one hits the limit of max_tmp_space_limit
when flushing the entry to disk, the query will abort and the
binary log will not contain the last changes to the table.
This will also stop the slave!
This is also true for all Aria tables as Aria cannot do rollback
(except in case of crashes)!
One way to avoid it is to use @@binlog_format=statement for
queries that updates a lot of rows.
Implementation:
- All writes to temporary files or internal temporary tables, that
increases the file size, are routed through temp_file_size_cb_func()
which updates and checks the temp space usage.
- Most of the temporary file monitoring is done inside IO_CACHE.
Temporary file monitoring is done inside the Aria engine.
- MY_TRACK and MY_TRACK_WITH_LIMIT are new flags for ini_io_cache().
MY_TRACK means that we track the file usage. TRACK_WITH_LIMIT means
that we track the file usage and we give an error if the limit is
breached. This is used to not give an error on commit when
binlog_stmp_cache is flushed.
- global_tmp_space_used contains the total tmp space used so far.
This is needed quickly check against max_total_tmp_space_usage.
- Temporary space errors are using EE_LOCAL_TMP_SPACE_FULL and
handler errors are using HA_ERR_LOCAL_TMP_SPACE_FULL.
This is needed until we move general errors to it's own error space
so that they cannot conflict with system error numbers.
- Return value of my_chsize() and mysql_file_chsize() has changed
so that -1 is returned in the case my_chsize() could not decrease
the file size (very unlikely and will not happen on modern systems).
All calls to _chsize() are updated to check for > 0 as the error
condition.
- At the destruction of THD we check that THD::tmp_file_space == 0
- At server end we check that global_tmp_space_used == 0
- As a precaution against errors in the tmp_space_used code, one can set
max_tmp_space_usage and max_total_tmp_space_usage to 0 to disable
the tmp space quota errors.
- truncate_io_cache() function added.
- Aria tables using static or dynamic row length are registered in 8K
increments to avoid some calls to update_tmp_file_size().
Other things:
- Ensure that all handler errors are registered. Before, some engine
errors could be printed as "Unknown error".
- Fixed bug in filesort() that causes a assert if there was an error
when writing to the temporay file.
- Fixed that compute_window_func() now takes into account write errors.
- In case of parallel replication, rpl_group_info::cleanup_context()
could call trans_rollback() with thd->error set, which would cause
an assert. Fixed by resetting the error before calling trans_rollback().
- Fixed bug in subselect3.inc which caused following test to use
heap tables with low value for max_heap_table_size
- Fixed bug in sql_expression_cache where it did not overflow
heap table to Aria table.
- Added Max_tmp_disk_space_used to slow query log.
- Fixed some bugs in log_slow_innodb.test
2024-03-14 17:59:00 +01:00
|
|
|
DBUG_ASSERT(thd->status_var.tmp_space_used == 0);
|
|
|
|
thd->set_status_var_init(clear_for_new_connection);
|
2011-10-11 12:55:42 +02:00
|
|
|
thd->killed= KILL_CONNECTION;
|
2011-10-01 21:23:01 +02:00
|
|
|
delete thd;
|
|
|
|
thd= 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
background sending thread
|
|
|
|
*/
|
|
|
|
pthread_handler_t background_thread(void *arg __attribute__((unused)))
|
|
|
|
{
|
|
|
|
if (my_thread_init())
|
|
|
|
return 0;
|
|
|
|
|
2016-02-01 12:45:39 +02:00
|
|
|
thd_thread_id= next_thread_id();
|
2011-10-01 21:23:01 +02:00
|
|
|
|
2011-10-04 15:48:39 +02:00
|
|
|
if (slept_ok(startup_interval))
|
|
|
|
{
|
|
|
|
send_report("startup");
|
|
|
|
|
|
|
|
if (slept_ok(first_interval))
|
|
|
|
{
|
|
|
|
send_report(NULL);
|
2011-10-01 21:23:01 +02:00
|
|
|
|
2011-10-04 15:48:39 +02:00
|
|
|
while(slept_ok(interval))
|
|
|
|
send_report(NULL);
|
|
|
|
}
|
2011-10-01 21:23:01 +02:00
|
|
|
|
2011-10-04 15:48:39 +02:00
|
|
|
send_report("shutdown");
|
|
|
|
}
|
2011-10-01 21:23:01 +02:00
|
|
|
|
|
|
|
my_thread_end();
|
|
|
|
pthread_exit(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace feedback
|
|
|
|
|