Added --temp-pool option to mysqld. This will cause temporary files

created to use a small set of filenames, to try and avoid problems
in the Linux kernel.
parent 89b5dab2
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA */
#ifndef _my_bitmap_h_
#define _my_bitmap_h_
#define MY_BIT_NONE ~(uint)0
#ifdef __cplusplus
extern "C" {
#endif
extern void bitmap_set_bit(uchar *bitmap, uint bitmap_size, uint bitmap_bit);
extern uint bitmap_set_next(uchar *bitmap, uint bitmap_size);
extern void bitmap_clear_bit(uchar *bitmap,uint bitmap_size,uint bitmap_bit);
#ifdef __cplusplus
}
#endif
#endif
......@@ -44,7 +44,7 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c\
my_quick.c my_lockmem.c my_static.c \
getopt.c getopt1.c getvar.c my_mkdir.c \
default.c my_compress.c checksum.c raid.cc my_net.c \
my_vsnprintf.c charset.c
my_vsnprintf.c charset.c my_bitmap.c
EXTRA_DIST = thr_alarm.c thr_lock.c my_pthread.c my_thr_init.c \
thr_mutex.c thr_rwlock.c
libmysys_a_LIBADD = @THREAD_LOBJECTS@
......
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA */
/*
Handling of uchar arrays as large bitmaps.
*/
#include "mysys_priv.h"
#include <my_bitmap.h>
pthread_mutex_t LOCK_bitmap;
void bitmap_set_bit(uchar *bitmap, uint bitmap_size, uint bitmap_bit) {
if((bitmap_bit != MY_BIT_NONE) && (bitmap_bit < bitmap_size*8)) {
pthread_mutex_lock(&LOCK_bitmap);
bitmap[bitmap_bit / 8] |= (1 << bitmap_bit % 8);
pthread_mutex_unlock(&LOCK_bitmap);
};
};
uint bitmap_set_next(uchar *bitmap, uint bitmap_size) {
uint bit_found = MY_BIT_NONE;
int i, b;
pthread_mutex_lock(&LOCK_bitmap);
for(i=0; (i<bitmap_size) && (bit_found==MY_BIT_NONE); i++) {
if(bitmap[i] == 0xff) continue;
for(b=0; (b<8) && (bit_found==MY_BIT_NONE); b++)
if((bitmap[i] & 1<<b) == 0) {
bit_found = (i*8)+b;
bitmap[i] |= 1<<b;
};
};
pthread_mutex_unlock(&LOCK_bitmap);
return bit_found;
};
void bitmap_clear_bit(uchar *bitmap, uint bitmap_size, uint bitmap_bit) {
if((bitmap_bit != MY_BIT_NONE) && (bitmap_bit < bitmap_size*8)) {
pthread_mutex_lock(&LOCK_bitmap);
bitmap[bitmap_bit / 8] &= ~(1 << bitmap_bit % 8);
pthread_mutex_unlock(&LOCK_bitmap);
};
};
......@@ -48,6 +48,7 @@ static my_bool win32_init_tcp_ip();
static my_bool my_init_done=0;
static ulong atoi_octal(const char *str)
{
long int tmp;
......@@ -76,6 +77,7 @@ void my_init(void)
#ifndef __WIN__
sigfillset(&my_signals); /* signals blocked by mf_brkhant */
#endif
pthread_mutex_init(&LOCK_bitmap, NULL);
#endif
{
DBUG_ENTER("my_init");
......@@ -127,7 +129,12 @@ void my_end(int infoflag)
#ifdef HAVE_GETRUSAGE
struct rusage rus;
if (!getrusage(RUSAGE_SELF, &rus))
fprintf(info_file,"\nUser time %.2f, System time %.2f\nMaximum resident set size %ld, Integral resident set size %ld\nNon physical pagefaults %ld, Physical pagefaults %ld, Swaps %ld\nBlocks in %ld out %ld, Messages in %ld out %ld, Signals %ld\nVouluntary context switches %ld, Invouluntary context switches %ld\n",
fprintf(info_file,"\n\
User time %.2f, System time %.2f\n\
Maximum resident set size %ld, Integral resident set size %ld\n\
Non-physical pagefaults %ld, Physical pagefaults %ld, Swaps %ld\n\
Blocks in %ld out %ld, Messages in %ld out %ld, Signals %ld\n\
Voluntary context switches %ld, Involuntary context switches %ld\n",
(rus.ru_utime.tv_sec * SCALE_SEC +
rus.ru_utime.tv_usec / SCALE_USEC) / 100.0,
(rus.ru_stime.tv_sec * SCALE_SEC +
......@@ -159,6 +166,7 @@ void my_end(int infoflag)
pthread_mutex_destroy(&THR_LOCK_keycache);
pthread_mutex_destroy(&THR_LOCK_malloc);
pthread_mutex_destroy(&THR_LOCK_open);
pthread_mutex_destroy(&LOCK_bitmap);
DBUG_POP(); /* Must be done before my_thread_end */
my_thread_end();
my_thread_global_end();
......
......@@ -25,6 +25,7 @@
#ifdef THREAD
extern pthread_mutex_t THR_LOCK_malloc,THR_LOCK_open,THR_LOCK_keycache,
THR_LOCK_lock,THR_LOCK_isam,THR_LOCK_net,THR_LOCK_charset;
extern pthread_mutex_t LOCK_bitmap;
#else /* THREAD */
#define pthread_mutex_lock(A)
#define pthread_mutex_unlock(A)
......
......@@ -73,6 +73,7 @@ void kill_one_thread(THD *thd, ulong id);
#ifndef MYSQLD_NET_RETRY_COUNT
#define MYSQLD_NET_RETRY_COUNT 10 // Abort read after this many int.
#endif
#define TEMP_POOL_SIZE 128
/* The following parameters is to decide when to use an extra cache to
optimise seeks when reading a big table in sorted order */
#define MIN_FILE_LENGTH_TO_USE_ROW_CACHE (16L*1024*1024)
......@@ -507,7 +508,8 @@ extern ulong ha_read_count, ha_write_count, ha_delete_count, ha_update_count,
ha_read_key_count, ha_read_next_count, ha_read_prev_count,
ha_read_first_count, ha_read_last_count,
ha_read_rnd_count, ha_read_rnd_next_count;
extern uchar temp_pool[TEMP_POOL_SIZE];
extern bool use_temp_pool;
extern char f_fyllchar;
extern uchar *days_in_month;
extern DATE_FORMAT dayord;
......
......@@ -287,6 +287,9 @@ I_List<THD> threads,thread_cache;
time_t start_time;
uchar temp_pool[TEMP_POOL_SIZE];
bool use_temp_pool;
pthread_key(MEM_ROOT*,THR_MALLOC);
pthread_key(THD*, THR_THD);
pthread_key(NET*, THR_NET);
......@@ -1498,6 +1501,9 @@ int main(int argc, char **argv)
if (!mysql_tmpdir || !mysql_tmpdir[0])
mysql_tmpdir=(char*) P_tmpdir; /* purecov: inspected */
bzero(temp_pool, TEMP_POOL_SIZE);
use_temp_pool = 0;
set_options();
#ifdef __WIN__
/* service parameters can be overwritten by options */
......@@ -2370,7 +2376,8 @@ enum options {
OPT_INNOBASE_LOG_GROUP_HOME_DIR,
OPT_INNOBASE_LOG_ARCH_DIR, OPT_INNOBASE_LOG_ARCHIVE,
OPT_INNOBASE_FLUSH_LOG_AT_TRX_COMMIT, OPT_SAFE_SHOW_DB,
OPT_GEMINI_SKIP
OPT_GEMINI_SKIP,
OPT_TEMP_POOL
};
static struct option long_options[] = {
......@@ -2501,6 +2508,7 @@ static struct option long_options[] = {
#ifdef __WIN__
{"standalone", no_argument, 0, (int) OPT_STANDALONE},
#endif
{"temp-pool", no_argument, 0, (int) OPT_TEMP_POOL},
{"tmpdir", required_argument, 0, 't'},
{"use-locking", no_argument, 0, (int) OPT_USE_LOCKING},
#ifdef USE_SYMDIR
......@@ -2874,6 +2882,7 @@ static void usage(void)
Don't give threads different priorities.\n\
--socket=... Socket file to use for connection\n\
-t, --tmpdir=path Path for temporary files\n\
--temp-pool Use a pool of temporary files\n\
-u, --user=user_name Run mysqld daemon as user\n\
-V, --version output version information and exit");
#ifdef __WIN__
......@@ -3049,6 +3058,9 @@ static void get_options(int argc,char **argv)
case 't':
mysql_tmpdir=optarg;
break;
case OPT_TEMP_POOL:
use_temp_pool=1;
break;
case 'u':
mysqld_user=optarg;
break;
......
......@@ -30,6 +30,7 @@
#include <hash.h>
#include <ft_global.h>
#include <assert.h>
#include <my_bitmap.h>
const char *join_type_str[]={ "UNKNOWN","system","const","eq_ref","ref",
"MAYBE_REF","ALL","range","index","fulltext" };
......@@ -3276,14 +3277,28 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
KEY_PART_INFO *key_part_info;
Item_result_field **copy_func;
MI_COLUMNDEF *recinfo;
uint temp_pool_slot;
DBUG_ENTER("create_tmp_table");
DBUG_PRINT("enter",("distinct: %d save_sum_fields: %d allow_distinct_limit: %d group: %d",
(int) distinct, (int) save_sum_fields,
(int) allow_distinct_limit,test(group)));
statistic_increment(created_tmp_tables, &LOCK_status);
sprintf(path,"%s%s%lx_%lx_%x",mysql_tmpdir,tmp_file_prefix,current_pid,
thd->thread_id, thd->tmp_table++);
if(use_temp_pool) {
temp_pool_slot = bitmap_set_next(temp_pool, TEMP_POOL_SIZE);
if(temp_pool_slot != MY_BIT_NONE) // we got a slot
sprintf(path, "%s%s_%lx_%i", mysql_tmpdir, tmp_file_prefix,
current_pid, temp_pool_slot);
else // if we run out of slots in the pool, fall back to old behavior
sprintf(path,"%s%s%lx_%lx_%x",mysql_tmpdir,tmp_file_prefix,current_pid,
thd->thread_id, thd->tmp_table++);
} else {
sprintf(path,"%s%s%lx_%lx_%x",mysql_tmpdir,tmp_file_prefix,current_pid,
thd->thread_id, thd->tmp_table++);
};
if (group)
{
if (!param->quick_group)
......@@ -3310,10 +3325,12 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
param->group_length : 0,
NullS))
{
bitmap_clear_bit(temp_pool, TEMP_POOL_SIZE, temp_pool_slot);
DBUG_RETURN(NULL); /* purecov: inspected */
}
if (!(param->copy_field=copy=new Copy_field[field_count]))
{
bitmap_clear_bit(temp_pool, TEMP_POOL_SIZE, temp_pool_slot);
my_free((gptr) table,MYF(0)); /* purecov: inspected */
DBUG_RETURN(NULL); /* purecov: inspected */
}
......@@ -3333,6 +3350,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
table->map=1;
table->tmp_table=1;
table->db_low_byte_first=1; // True for HEAP and MyISAM
table->temp_pool_slot = temp_pool_slot;
/* Calculate with type of fields we will need in heap table */
......@@ -3626,7 +3645,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
DBUG_RETURN(table);
err:
free_tmp_table(thd,table); /* purecov: inspected */
free_tmp_table(thd,table); /* purecov: inspected */
bitmap_clear_bit(temp_pool, TEMP_POOL_SIZE, temp_pool_slot);
DBUG_RETURN(NULL); /* purecov: inspected */
}
......@@ -3773,6 +3793,9 @@ free_tmp_table(THD *thd, TABLE *entry)
delete *ptr;
my_free((gptr) entry->record[0],MYF(0));
free_io_cache(entry);
bitmap_clear_bit(temp_pool, TEMP_POOL_SIZE, entry->temp_pool_slot);
my_free((gptr) entry,MYF(0));
thd->proc_info=save_proc_info;
......
......@@ -119,6 +119,8 @@ struct st_table {
key_part_map const_key_parts[MAX_KEY];
ulong query_id;
uint temp_pool_slot;
THD *in_use; /* Which thread uses this */
struct st_table *next,*prev;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment