mirror of
https://github.com/MariaDB/server.git
synced 2025-07-16 00:42:55 +03:00
MDEV-17845 Extreme high open file limit used
SHOW STATUS LIKE 'Open_files' was showing 18446744073709551615 my_file_opened used statistic_increment/statistic_decrement, so one-off errors were normal and expected. But they confused monitoring tools, so let's move my_file_opened to use atomics.
This commit is contained in:
@ -23,6 +23,8 @@
|
|||||||
#define ETIME ETIMEDOUT /* For FreeBSD */
|
#define ETIME ETIMEDOUT /* For FreeBSD */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <my_atomic.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#define EXTERNC extern "C"
|
#define EXTERNC extern "C"
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -803,6 +805,26 @@ extern uint thd_lib_detected;
|
|||||||
#define statistic_sub(V,C,L) (V)-=(C)
|
#define statistic_sub(V,C,L) (V)-=(C)
|
||||||
#endif /* SAFE_STATISTICS */
|
#endif /* SAFE_STATISTICS */
|
||||||
|
|
||||||
|
static inline void thread_safe_increment32(int32 *value)
|
||||||
|
{
|
||||||
|
(void) my_atomic_add32_explicit(value, 1, MY_MEMORY_ORDER_RELAXED);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void thread_safe_decrement32(int32 *value)
|
||||||
|
{
|
||||||
|
(void) my_atomic_add32_explicit(value, -1, MY_MEMORY_ORDER_RELAXED);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void thread_safe_increment64(int64 *value)
|
||||||
|
{
|
||||||
|
(void) my_atomic_add64_explicit(value, 1, MY_MEMORY_ORDER_RELAXED);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void thread_safe_decrement64(int64 *value)
|
||||||
|
{
|
||||||
|
(void) my_atomic_add64_explicit(value, -1, MY_MEMORY_ORDER_RELAXED);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
No locking needed, the counter is owned by the thread
|
No locking needed, the counter is owned by the thread
|
||||||
*/
|
*/
|
||||||
|
@ -261,10 +261,11 @@ extern ulonglong my_collation_statistics_get_use_count(uint id);
|
|||||||
extern const char *my_collation_get_tailoring(uint id);
|
extern const char *my_collation_get_tailoring(uint id);
|
||||||
|
|
||||||
/* statistics */
|
/* statistics */
|
||||||
extern ulong my_file_opened,my_stream_opened, my_tmp_file_created;
|
extern ulong my_stream_opened, my_tmp_file_created;
|
||||||
extern ulong my_file_total_opened;
|
extern ulong my_file_total_opened;
|
||||||
extern ulong my_sync_count;
|
extern ulong my_sync_count;
|
||||||
extern uint mysys_usage_id;
|
extern uint mysys_usage_id;
|
||||||
|
extern int32 my_file_opened;
|
||||||
extern my_bool my_init_done, my_thr_key_mysys_exists;
|
extern my_bool my_init_done, my_thr_key_mysys_exists;
|
||||||
extern my_bool my_assert_on_error;
|
extern my_bool my_assert_on_error;
|
||||||
extern myf my_global_flags; /* Set to MY_WME for more error messages */
|
extern myf my_global_flags; /* Set to MY_WME for more error messages */
|
||||||
|
@ -223,7 +223,7 @@ FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags)
|
|||||||
{
|
{
|
||||||
if (my_file_info[Filedes].type != UNOPEN)
|
if (my_file_info[Filedes].type != UNOPEN)
|
||||||
{
|
{
|
||||||
statistic_decrement(my_file_opened, &THR_LOCK_open); /* File is opened with my_open ! */
|
thread_safe_decrement32(&my_file_opened); /* File is opened with my_open ! */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -105,7 +105,7 @@ int my_close(File fd, myf MyFlags)
|
|||||||
{
|
{
|
||||||
my_free(name);
|
my_free(name);
|
||||||
}
|
}
|
||||||
statistic_decrement(my_file_opened, &THR_LOCK_open);
|
thread_safe_decrement32(&my_file_opened);
|
||||||
DBUG_RETURN(err);
|
DBUG_RETURN(err);
|
||||||
} /* my_close */
|
} /* my_close */
|
||||||
|
|
||||||
@ -133,13 +133,10 @@ File my_register_filename(File fd, const char *FileName, enum file_type
|
|||||||
DBUG_ENTER("my_register_filename");
|
DBUG_ENTER("my_register_filename");
|
||||||
if ((int) fd >= MY_FILE_MIN)
|
if ((int) fd >= MY_FILE_MIN)
|
||||||
{
|
{
|
||||||
|
thread_safe_increment32(&my_file_opened);
|
||||||
if ((uint) fd >= my_file_limit)
|
if ((uint) fd >= my_file_limit)
|
||||||
{
|
DBUG_RETURN(fd);
|
||||||
statistic_increment(my_file_opened,&THR_LOCK_open);
|
|
||||||
DBUG_RETURN(fd); /* safeguard */
|
|
||||||
}
|
|
||||||
my_file_info[fd].name = (char*) my_strdup(FileName, MyFlags);
|
my_file_info[fd].name = (char*) my_strdup(FileName, MyFlags);
|
||||||
statistic_increment(my_file_opened,&THR_LOCK_open);
|
|
||||||
statistic_increment(my_file_total_opened,&THR_LOCK_open);
|
statistic_increment(my_file_total_opened,&THR_LOCK_open);
|
||||||
my_file_info[fd].type = type_of_file;
|
my_file_info[fd].type = type_of_file;
|
||||||
DBUG_PRINT("exit",("fd: %d",fd));
|
DBUG_PRINT("exit",("fd: %d",fd));
|
||||||
|
@ -31,7 +31,7 @@ char *mysql_data_home= (char*) ".";
|
|||||||
const char *my_progname= NULL, *my_progname_short= NULL;
|
const char *my_progname= NULL, *my_progname_short= NULL;
|
||||||
char curr_dir[FN_REFLEN]= {0},
|
char curr_dir[FN_REFLEN]= {0},
|
||||||
home_dir_buff[FN_REFLEN]= {0};
|
home_dir_buff[FN_REFLEN]= {0};
|
||||||
ulong my_stream_opened=0,my_file_opened=0, my_tmp_file_created=0;
|
ulong my_stream_opened=0,my_tmp_file_created=0;
|
||||||
ulong my_file_total_opened= 0;
|
ulong my_file_total_opened= 0;
|
||||||
int my_umask=0664, my_umask_dir=0777;
|
int my_umask=0664, my_umask_dir=0777;
|
||||||
|
|
||||||
@ -39,6 +39,7 @@ myf my_global_flags= 0;
|
|||||||
my_bool my_assert_on_error= 0;
|
my_bool my_assert_on_error= 0;
|
||||||
struct st_my_file_info my_file_info_default[MY_NFILE];
|
struct st_my_file_info my_file_info_default[MY_NFILE];
|
||||||
uint my_file_limit= MY_NFILE;
|
uint my_file_limit= MY_NFILE;
|
||||||
|
int32 my_file_opened=0;
|
||||||
struct st_my_file_info *my_file_info= my_file_info_default;
|
struct st_my_file_info *my_file_info= my_file_info_default;
|
||||||
|
|
||||||
/* From mf_brkhant */
|
/* From mf_brkhant */
|
||||||
|
@ -8630,7 +8630,7 @@ SHOW_VAR status_vars[]= {
|
|||||||
{"Memory_used", (char*) &show_memory_used, SHOW_SIMPLE_FUNC},
|
{"Memory_used", (char*) &show_memory_used, SHOW_SIMPLE_FUNC},
|
||||||
{"Memory_used_initial", (char*) &start_memory_used, SHOW_LONGLONG},
|
{"Memory_used_initial", (char*) &start_memory_used, SHOW_LONGLONG},
|
||||||
{"Not_flushed_delayed_rows", (char*) &delayed_rows_in_use, SHOW_LONG_NOFLUSH},
|
{"Not_flushed_delayed_rows", (char*) &delayed_rows_in_use, SHOW_LONG_NOFLUSH},
|
||||||
{"Open_files", (char*) &my_file_opened, SHOW_LONG_NOFLUSH},
|
{"Open_files", (char*) &my_file_opened, SHOW_SINT},
|
||||||
{"Open_streams", (char*) &my_stream_opened, SHOW_LONG_NOFLUSH},
|
{"Open_streams", (char*) &my_stream_opened, SHOW_LONG_NOFLUSH},
|
||||||
{"Open_table_definitions", (char*) &show_table_definitions, SHOW_SIMPLE_FUNC},
|
{"Open_table_definitions", (char*) &show_table_definitions, SHOW_SIMPLE_FUNC},
|
||||||
{"Open_tables", (char*) &show_open_tables, SHOW_SIMPLE_FUNC},
|
{"Open_tables", (char*) &show_open_tables, SHOW_SIMPLE_FUNC},
|
||||||
|
20
sql/mysqld.h
20
sql/mysqld.h
@ -790,26 +790,6 @@ inline void table_case_convert(char * name, uint length)
|
|||||||
name, length, name, length);
|
name, length, name, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void thread_safe_increment32(int32 *value)
|
|
||||||
{
|
|
||||||
(void) my_atomic_add32_explicit(value, 1, MY_MEMORY_ORDER_RELAXED);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void thread_safe_decrement32(int32 *value)
|
|
||||||
{
|
|
||||||
(void) my_atomic_add32_explicit(value, -1, MY_MEMORY_ORDER_RELAXED);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void thread_safe_increment64(int64 *value)
|
|
||||||
{
|
|
||||||
(void) my_atomic_add64_explicit(value, 1, MY_MEMORY_ORDER_RELAXED);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void thread_safe_decrement64(int64 *value)
|
|
||||||
{
|
|
||||||
(void) my_atomic_add64_explicit(value, -1, MY_MEMORY_ORDER_RELAXED);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern void set_server_version(char *buf, size_t size);
|
extern void set_server_version(char *buf, size_t size);
|
||||||
|
|
||||||
#define current_thd _current_thd()
|
#define current_thd _current_thd()
|
||||||
|
@ -596,13 +596,13 @@ update: %10lu\n",
|
|||||||
tmp.ha_update_count);
|
tmp.ha_update_count);
|
||||||
printf("\nTable status:\n\
|
printf("\nTable status:\n\
|
||||||
Opened tables: %10lu\n\
|
Opened tables: %10lu\n\
|
||||||
Open tables: %10lu\n\
|
Open tables: %10u\n\
|
||||||
Open files: %10lu\n\
|
Open files: %10u\n\
|
||||||
Open streams: %10lu\n",
|
Open streams: %10lu\n",
|
||||||
tmp.opened_tables,
|
tmp.opened_tables,
|
||||||
(ulong) tc_records(),
|
tc_records(),
|
||||||
(ulong) my_file_opened,
|
my_file_opened,
|
||||||
(ulong) my_stream_opened);
|
my_stream_opened);
|
||||||
|
|
||||||
#ifndef DONT_USE_THR_ALARM
|
#ifndef DONT_USE_THR_ALARM
|
||||||
ALARM_INFO alarm_info;
|
ALARM_INFO alarm_info;
|
||||||
|
Reference in New Issue
Block a user