summaryrefslogtreecommitdiff
path: root/storage
diff options
context:
space:
mode:
Diffstat (limited to 'storage')
-rw-r--r--storage/archive/ha_archive.cc80
-rw-r--r--storage/archive/ha_archive.h4
-rw-r--r--storage/blackhole/ha_blackhole.cc45
-rw-r--r--storage/csv/ha_tina.cc297
-rw-r--r--storage/csv/ha_tina.h4
-rw-r--r--storage/csv/transparent_file.cc15
-rw-r--r--storage/example/ha_example.cc49
-rw-r--r--storage/example/ha_example.h4
-rw-r--r--storage/federated/ha_federated.cc53
-rw-r--r--storage/federated/ha_federated.h4
-rw-r--r--storage/heap/ha_heap.cc10
-rw-r--r--storage/heap/heapdef.h15
-rw-r--r--storage/heap/hp_clear.c6
-rw-r--r--storage/heap/hp_close.c6
-rw-r--r--storage/heap/hp_create.c21
-rw-r--r--storage/heap/hp_open.c12
-rw-r--r--storage/heap/hp_panic.c6
-rw-r--r--storage/heap/hp_rename.c8
-rw-r--r--storage/heap/hp_static.c33
-rw-r--r--storage/heap/hp_test1.c2
-rw-r--r--storage/heap/hp_test2.c2
-rw-r--r--storage/innobase/handler/ha_innodb.cc11
-rw-r--r--storage/innobase/include/srv0srv.h3
-rw-r--r--storage/innobase/os/os0thread.c14
-rw-r--r--storage/innobase/srv/srv0srv.c3
-rwxr-xr-xstorage/myisam/CMakeLists.txt3
-rw-r--r--storage/myisam/Makefile.am2
-rw-r--r--storage/myisam/ft_eval.c4
-rw-r--r--storage/myisam/ha_myisam.cc261
-rw-r--r--storage/myisam/ha_myisam.h6
-rw-r--r--storage/myisam/mi_cache.c9
-rw-r--r--storage/myisam/mi_changed.c2
-rw-r--r--storage/myisam/mi_check.c240
-rw-r--r--storage/myisam/mi_close.c20
-rw-r--r--storage/myisam/mi_create.c55
-rw-r--r--storage/myisam/mi_dbug.c36
-rw-r--r--storage/myisam/mi_delete.c4
-rw-r--r--storage/myisam/mi_delete_all.c10
-rw-r--r--storage/myisam/mi_delete_table.c7
-rw-r--r--storage/myisam/mi_dynrec.c49
-rw-r--r--storage/myisam/mi_extra.c36
-rw-r--r--storage/myisam/mi_extrafunc.h21
-rw-r--r--storage/myisam/mi_info.c10
-rw-r--r--storage/myisam/mi_keycache.c10
-rw-r--r--storage/myisam/mi_locking.c52
-rw-r--r--storage/myisam/mi_log.c41
-rw-r--r--storage/myisam/mi_open.c79
-rw-r--r--storage/myisam/mi_packrec.c32
-rw-r--r--storage/myisam/mi_panic.c32
-rw-r--r--storage/myisam/mi_preload.c5
-rw-r--r--storage/myisam/mi_range.c6
-rw-r--r--storage/myisam/mi_rename.c8
-rw-r--r--storage/myisam/mi_rkey.c6
-rw-r--r--storage/myisam/mi_rnext.c6
-rw-r--r--storage/myisam/mi_rnext_same.c6
-rw-r--r--storage/myisam/mi_rprev.c6
-rw-r--r--storage/myisam/mi_rsame.c10
-rw-r--r--storage/myisam/mi_static.c73
-rw-r--r--storage/myisam/mi_statrec.c2
-rw-r--r--storage/myisam/mi_test1.c8
-rw-r--r--storage/myisam/mi_test2.c4
-rw-r--r--storage/myisam/mi_test3.c4
-rw-r--r--storage/myisam/mi_update.c4
-rw-r--r--storage/myisam/mi_write.c26
-rw-r--r--storage/myisam/myisam_ftdump.c2
-rw-r--r--storage/myisam/myisamchk.c88
-rw-r--r--storage/myisam/myisamdef.h42
-rw-r--r--storage/myisam/myisamlog.c52
-rw-r--r--storage/myisam/myisampack.c270
-rw-r--r--storage/myisam/rt_test.c2
-rw-r--r--storage/myisam/sort.c23
-rw-r--r--storage/myisam/sp_test.c1
-rw-r--r--storage/myisammrg/ha_myisammrg.cc793
-rw-r--r--storage/myisammrg/ha_myisammrg.h54
-rw-r--r--storage/myisammrg/myrg_close.c8
-rw-r--r--storage/myisammrg/myrg_create.c20
-rw-r--r--storage/myisammrg/myrg_def.h15
-rw-r--r--storage/myisammrg/myrg_extra.c11
-rw-r--r--storage/myisammrg/myrg_open.c61
-rw-r--r--storage/myisammrg/myrg_static.c34
-rw-r--r--storage/ndb/include/kernel/signaldata/DictTabInfo.hpp4
81 files changed, 2019 insertions, 1363 deletions
diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc
index 1cb9b8bba80..2ff4a5daff5 100644
--- a/storage/archive/ha_archive.cc
+++ b/storage/archive/ha_archive.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003 MySQL AB
+/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -95,7 +95,7 @@
*/
/* Variables for archive share methods */
-pthread_mutex_t archive_mutex;
+mysql_mutex_t archive_mutex;
static HASH archive_open_tables;
/* The file extension */
@@ -145,6 +145,28 @@ static uchar* archive_get_key(ARCHIVE_SHARE *share, size_t *length,
return (uchar*) share->table_name;
}
+#ifdef HAVE_PSI_INTERFACE
+PSI_mutex_key az_key_mutex_archive_mutex, az_key_mutex_ARCHIVE_SHARE_mutex;
+
+static PSI_mutex_info all_archive_mutexes[]=
+{
+ { &az_key_mutex_archive_mutex, "archive_mutex", PSI_FLAG_GLOBAL},
+ { &az_key_mutex_ARCHIVE_SHARE_mutex, "ARCHIVE_SHARE::mutex", 0}
+};
+
+static void init_archive_psi_keys(void)
+{
+ const char* category= "archive";
+ int count;
+
+ if (PSI_server == NULL)
+ return;
+
+ count= array_elements(all_archive_mutexes);
+ PSI_server->register_mutex(category, all_archive_mutexes, count);
+}
+
+#endif /* HAVE_PSI_INTERFACE */
/*
Initialize the archive handler.
@@ -163,6 +185,10 @@ int archive_db_init(void *p)
DBUG_ENTER("archive_db_init");
handlerton *archive_hton;
+#ifdef HAVE_PSI_INTERFACE
+ init_archive_psi_keys();
+#endif
+
archive_hton= (handlerton *)p;
archive_hton->state= SHOW_OPTION_YES;
archive_hton->db_type= DB_TYPE_ARCHIVE_DB;
@@ -170,12 +196,13 @@ int archive_db_init(void *p)
archive_hton->flags= HTON_NO_FLAGS;
archive_hton->discover= archive_discover;
- if (pthread_mutex_init(&archive_mutex, MY_MUTEX_INIT_FAST))
+ if (mysql_mutex_init(az_key_mutex_archive_mutex,
+ &archive_mutex, MY_MUTEX_INIT_FAST))
goto error;
if (my_hash_init(&archive_open_tables, table_alias_charset, 32, 0, 0,
(my_hash_get_key) archive_get_key, 0, 0))
{
- VOID(pthread_mutex_destroy(&archive_mutex));
+ mysql_mutex_destroy(&archive_mutex);
}
else
{
@@ -199,7 +226,7 @@ error:
int archive_db_done(void *p)
{
my_hash_free(&archive_open_tables);
- VOID(pthread_mutex_destroy(&archive_mutex));
+ mysql_mutex_destroy(&archive_mutex);
return 0;
}
@@ -313,7 +340,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc)
uint length;
DBUG_ENTER("ha_archive::get_share");
- pthread_mutex_lock(&archive_mutex);
+ mysql_mutex_lock(&archive_mutex);
length=(uint) strlen(table_name);
if (!(share=(ARCHIVE_SHARE*) my_hash_search(&archive_open_tables,
@@ -328,7 +355,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc)
&tmp_name, length+1,
NullS))
{
- pthread_mutex_unlock(&archive_mutex);
+ mysql_mutex_unlock(&archive_mutex);
*rc= HA_ERR_OUT_OF_MEM;
DBUG_RETURN(NULL);
}
@@ -346,7 +373,8 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc)
/*
We will use this lock for rows.
*/
- VOID(pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST));
+ mysql_mutex_init(az_key_mutex_ARCHIVE_SHARE_mutex,
+ &share->mutex, MY_MUTEX_INIT_FAST);
/*
We read the meta file, but do not mark it dirty. Since we are not
@@ -363,7 +391,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc)
share->crashed= archive_tmp.dirty;
azclose(&archive_tmp);
- VOID(my_hash_insert(&archive_open_tables, (uchar*) share));
+ (void) my_hash_insert(&archive_open_tables, (uchar*) share);
thr_lock_init(&share->lock);
}
share->use_count++;
@@ -372,7 +400,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc)
share->use_count));
if (share->crashed)
*rc= HA_ERR_CRASHED_ON_USAGE;
- pthread_mutex_unlock(&archive_mutex);
+ mysql_mutex_unlock(&archive_mutex);
DBUG_RETURN(share);
}
@@ -391,12 +419,12 @@ int ha_archive::free_share()
share->table_name_length, share->table_name,
share->use_count));
- pthread_mutex_lock(&archive_mutex);
+ mysql_mutex_lock(&archive_mutex);
if (!--share->use_count)
{
my_hash_delete(&archive_open_tables, (uchar*) share);
thr_lock_delete(&share->lock);
- VOID(pthread_mutex_destroy(&share->mutex));
+ mysql_mutex_destroy(&share->mutex);
/*
We need to make sure we don't reset the crashed state.
If we open a crashed file, wee need to close it as crashed unless
@@ -411,7 +439,7 @@ int ha_archive::free_share()
}
my_free((uchar*) share, MYF(0));
}
- pthread_mutex_unlock(&archive_mutex);
+ mysql_mutex_unlock(&archive_mutex);
DBUG_RETURN(rc);
}
@@ -651,7 +679,7 @@ int ha_archive::create(const char *name, TABLE *table_arg,
*/
if ((frm_file= my_open(name_buff, O_RDONLY, MYF(0))) > 0)
{
- if (!my_fstat(frm_file, &file_stat, MYF(MY_WME)))
+ if (!mysql_file_fstat(frm_file, &file_stat, MYF(MY_WME)))
{
frm_ptr= (uchar *)my_malloc(sizeof(uchar) * file_stat.st_size, MYF(0));
if (frm_ptr)
@@ -800,7 +828,7 @@ int ha_archive::write_row(uchar *buf)
ha_statistic_increment(&SSV::ha_write_count);
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
table->timestamp_field->set_time();
- pthread_mutex_lock(&share->mutex);
+ mysql_mutex_lock(&share->mutex);
if (!share->archive_write_open)
if (init_archive_writer())
@@ -883,7 +911,7 @@ int ha_archive::write_row(uchar *buf)
share->rows_recorded++;
rc= real_write_row(buf, &(share->archive_write));
error:
- pthread_mutex_unlock(&share->mutex);
+ mysql_mutex_unlock(&share->mutex);
if (read_buf)
my_free((uchar*) read_buf, MYF(0));
@@ -953,7 +981,11 @@ int ha_archive::index_read_idx(uchar *buf, uint index, const uchar *key,
}
if (found)
+ {
+ /* notify handler that a record has been found */
+ table->status= 0;
DBUG_RETURN(0);
+ }
error:
DBUG_RETURN(rc ? rc : HA_ERR_END_OF_FILE);
@@ -1383,7 +1415,7 @@ int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt)
azclose(&archive);
// make the file we just wrote be our data file
- rc = my_rename(writer_filename,share->data_file_name,MYF(0));
+ rc= my_rename(writer_filename, share->data_file_name, MYF(0));
DBUG_RETURN(rc);
@@ -1467,7 +1499,7 @@ int ha_archive::info(uint flag)
If dirty, we lock, and then reset/flush the data.
I found that just calling azflush() doesn't always work.
*/
- pthread_mutex_lock(&share->mutex);
+ mysql_mutex_lock(&share->mutex);
if (share->dirty == TRUE)
{
if (share->dirty == TRUE)
@@ -1483,7 +1515,7 @@ int ha_archive::info(uint flag)
cause the number to be inaccurate.
*/
stats.records= share->rows_recorded;
- pthread_mutex_unlock(&share->mutex);
+ mysql_mutex_unlock(&share->mutex);
stats.deleted= 0;
@@ -1493,7 +1525,7 @@ int ha_archive::info(uint flag)
{
MY_STAT file_stat; // Stat information for the data file
- VOID(my_stat(share->data_file_name, &file_stat, MYF(MY_WME)));
+ (void) my_stat(share->data_file_name, &file_stat, MYF(MY_WME));
stats.data_file_length= file_stat.st_size;
stats.create_time= (ulong) file_stat.st_ctime;
@@ -1508,9 +1540,9 @@ int ha_archive::info(uint flag)
if (flag & HA_STATUS_AUTO)
{
init_archive_reader();
- pthread_mutex_lock(&share->mutex);
+ mysql_mutex_lock(&share->mutex);
azflush(&archive, Z_SYNC_FLUSH);
- pthread_mutex_unlock(&share->mutex);
+ mysql_mutex_unlock(&share->mutex);
stats.auto_increment_value= archive.auto_increment + 1;
}
@@ -1578,9 +1610,9 @@ int ha_archive::check(THD* thd, HA_CHECK_OPT* check_opt)
old_proc_info= thd_proc_info(thd, "Checking table");
/* Flush any waiting data */
- pthread_mutex_lock(&share->mutex);
+ mysql_mutex_lock(&share->mutex);
azflush(&(share->archive_write), Z_SYNC_FLUSH);
- pthread_mutex_unlock(&share->mutex);
+ mysql_mutex_unlock(&share->mutex);
/*
Now we will rewind the archive file so that we are positioned at the
diff --git a/storage/archive/ha_archive.h b/storage/archive/ha_archive.h
index ab630ed22fd..94842203f16 100644
--- a/storage/archive/ha_archive.h
+++ b/storage/archive/ha_archive.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003 MySQL AB
+/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -36,7 +36,7 @@ typedef struct st_archive_share {
char *table_name;
char data_file_name[FN_REFLEN];
uint table_name_length,use_count;
- pthread_mutex_t mutex;
+ mysql_mutex_t mutex;
THR_LOCK lock;
azio_stream archive_write; /* Archive file we are working with */
bool archive_write_open;
diff --git a/storage/blackhole/ha_blackhole.cc b/storage/blackhole/ha_blackhole.cc
index 27e4c919911..e10054a79f2 100644
--- a/storage/blackhole/ha_blackhole.cc
+++ b/storage/blackhole/ha_blackhole.cc
@@ -1,4 +1,4 @@
-/* Copyright 2005-2008 MySQL AB, 2008 Sun Microsystems, Inc.
+/* Copyright 2005-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
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
@@ -35,7 +35,7 @@ static handler *blackhole_create_handler(handlerton *hton,
/* Static declarations for shared structures */
-static pthread_mutex_t blackhole_mutex;
+static mysql_mutex_t blackhole_mutex;
static HASH blackhole_open_tables;
static st_blackhole_share *get_share(const char *table_name);
@@ -317,7 +317,7 @@ static st_blackhole_share *get_share(const char *table_name)
uint length;
length= (uint) strlen(table_name);
- pthread_mutex_lock(&blackhole_mutex);
+ mysql_mutex_lock(&blackhole_mutex);
if (!(share= (st_blackhole_share*)
my_hash_search(&blackhole_open_tables,
@@ -343,16 +343,16 @@ static st_blackhole_share *get_share(const char *table_name)
share->use_count++;
error:
- pthread_mutex_unlock(&blackhole_mutex);
+ mysql_mutex_unlock(&blackhole_mutex);
return share;
}
static void free_share(st_blackhole_share *share)
{
- pthread_mutex_lock(&blackhole_mutex);
+ mysql_mutex_lock(&blackhole_mutex);
if (!--share->use_count)
my_hash_delete(&blackhole_open_tables, (uchar*) share);
- pthread_mutex_unlock(&blackhole_mutex);
+ mysql_mutex_unlock(&blackhole_mutex);
}
static void blackhole_free_key(st_blackhole_share *share)
@@ -368,16 +368,43 @@ static uchar* blackhole_get_key(st_blackhole_share *share, size_t *length,
return (uchar*) share->table_name;
}
+#ifdef HAVE_PSI_INTERFACE
+static PSI_mutex_key bh_key_mutex_blackhole;
+
+static PSI_mutex_info all_blackhole_mutexes[]=
+{
+ { &bh_key_mutex_blackhole, "blackhole", PSI_FLAG_GLOBAL}
+};
+
+void init_blackhole_psi_keys()
+{
+ const char* category= "blackhole";
+ int count;
+
+ if (PSI_server == NULL)
+ return;
+
+ count= array_elements(all_blackhole_mutexes);
+ PSI_server->register_mutex(category, all_blackhole_mutexes, count);
+}
+#endif
+
static int blackhole_init(void *p)
{
handlerton *blackhole_hton;
+
+#ifdef HAVE_PSI_INTERFACE
+ init_blackhole_psi_keys();
+#endif
+
blackhole_hton= (handlerton *)p;
blackhole_hton->state= SHOW_OPTION_YES;
blackhole_hton->db_type= DB_TYPE_BLACKHOLE_DB;
blackhole_hton->create= blackhole_create_handler;
blackhole_hton->flags= HTON_CAN_RECREATE;
-
- VOID(pthread_mutex_init(&blackhole_mutex, MY_MUTEX_INIT_FAST));
+
+ mysql_mutex_init(bh_key_mutex_blackhole,
+ &blackhole_mutex, MY_MUTEX_INIT_FAST);
(void) my_hash_init(&blackhole_open_tables, system_charset_info,32,0,0,
(my_hash_get_key) blackhole_get_key,
(my_hash_free_key) blackhole_free_key, 0);
@@ -388,7 +415,7 @@ static int blackhole_init(void *p)
static int blackhole_fini(void *p)
{
my_hash_free(&blackhole_open_tables);
- pthread_mutex_destroy(&blackhole_mutex);
+ mysql_mutex_destroy(&blackhole_mutex);
return 0;
}
diff --git a/storage/csv/ha_tina.cc b/storage/csv/ha_tina.cc
index 9cc0f1e607b..52462ca9c90 100644
--- a/storage/csv/ha_tina.cc
+++ b/storage/csv/ha_tina.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003 MySQL AB
+/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -75,7 +75,7 @@ extern "C" void tina_update_status(void* param);
extern "C" my_bool tina_check_status(void* param);
/* Stuff for shares */
-pthread_mutex_t tina_mutex;
+mysql_mutex_t tina_mutex;
static HASH tina_open_tables;
static handler *tina_create_handler(handlerton *hton,
TABLE_SHARE *table,
@@ -105,12 +105,52 @@ static uchar* tina_get_key(TINA_SHARE *share, size_t *length,
return (uchar*) share->table_name;
}
+#ifdef HAVE_PSI_INTERFACE
+
+static PSI_mutex_key csv_key_mutex_tina, csv_key_mutex_TINA_SHARE_mutex;
+
+static PSI_mutex_info all_tina_mutexes[]=
+{
+ { &csv_key_mutex_tina, "tina", PSI_FLAG_GLOBAL},
+ { &csv_key_mutex_TINA_SHARE_mutex, "TINA_SHARE::mutex", 0}
+};
+
+static PSI_file_key csv_key_file_metadata, csv_key_file_data,
+ csv_key_file_update;
+
+static PSI_file_info all_tina_files[]=
+{
+ { &csv_key_file_metadata, "metadata", 0},
+ { &csv_key_file_data, "data", 0},
+ { &csv_key_file_update, "update", 0}
+};
+
+static void init_tina_psi_keys(void)
+{
+ const char* category= "csv";
+ int count;
+
+ if (PSI_server == NULL)
+ return;
+
+ count= array_elements(all_tina_mutexes);
+ PSI_server->register_mutex(category, all_tina_mutexes, count);
+
+ count= array_elements(all_tina_files);
+ PSI_server->register_file(category, all_tina_files, count);
+}
+#endif /* HAVE_PSI_INTERFACE */
+
static int tina_init_func(void *p)
{
handlerton *tina_hton;
+#ifdef HAVE_PSI_INTERFACE
+ init_tina_psi_keys();
+#endif
+
tina_hton= (handlerton *)p;
- VOID(pthread_mutex_init(&tina_mutex,MY_MUTEX_INIT_FAST));
+ mysql_mutex_init(csv_key_mutex_tina, &tina_mutex, MY_MUTEX_INIT_FAST);
(void) my_hash_init(&tina_open_tables,system_charset_info,32,0,0,
(my_hash_get_key) tina_get_key,0,0);
tina_hton->state= SHOW_OPTION_YES;
@@ -124,7 +164,7 @@ static int tina_init_func(void *p)
static int tina_done_func(void *p)
{
my_hash_free(&tina_open_tables);
- pthread_mutex_destroy(&tina_mutex);
+ mysql_mutex_destroy(&tina_mutex);
return 0;
}
@@ -141,7 +181,7 @@ static TINA_SHARE *get_share(const char *table_name, TABLE *table)
char *tmp_name;
uint length;
- pthread_mutex_lock(&tina_mutex);
+ mysql_mutex_lock(&tina_mutex);
length=(uint) strlen(table_name);
/*
@@ -157,7 +197,7 @@ static TINA_SHARE *get_share(const char *table_name, TABLE *table)
&tmp_name, length+1,
NullS))
{
- pthread_mutex_unlock(&tina_mutex);
+ mysql_mutex_unlock(&tina_mutex);
return NULL;
}
@@ -176,14 +216,16 @@ static TINA_SHARE *get_share(const char *table_name, TABLE *table)
fn_format(meta_file_name, table_name, "", CSM_EXT,
MY_REPLACE_EXT|MY_UNPACK_FILENAME);
- if (my_stat(share->data_file_name, &file_stat, MYF(MY_WME)) == NULL)
+ if (mysql_file_stat(csv_key_file_data,
+ share->data_file_name, &file_stat, MYF(MY_WME)) == NULL)
goto error;
share->saved_data_file_length= file_stat.st_size;
if (my_hash_insert(&tina_open_tables, (uchar*) share))
goto error;
thr_lock_init(&share->lock);
- pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(csv_key_mutex_TINA_SHARE_mutex,
+ &share->mutex, MY_MUTEX_INIT_FAST);
/*
Open or create the meta file. In the latter case, we'll get
@@ -191,19 +233,21 @@ static TINA_SHARE *get_share(const char *table_name, TABLE *table)
Usually this will result in auto-repair, and we will get a good
meta-file in the end.
*/
- if (((share->meta_file= my_open(meta_file_name,
- O_RDWR|O_CREAT, MYF(MY_WME))) == -1) ||
+ if (((share->meta_file= mysql_file_open(csv_key_file_metadata,
+ meta_file_name,
+ O_RDWR|O_CREAT,
+ MYF(MY_WME))) == -1) ||
read_meta_file(share->meta_file, &share->rows_recorded))
share->crashed= TRUE;
}
share->use_count++;
- pthread_mutex_unlock(&tina_mutex);
+ mysql_mutex_unlock(&tina_mutex);
return share;
error:
- pthread_mutex_unlock(&tina_mutex);
+ mysql_mutex_unlock(&tina_mutex);
my_free((uchar*) share, MYF(0));
return NULL;
@@ -236,8 +280,8 @@ static int read_meta_file(File meta_file, ha_rows *rows)
DBUG_ENTER("ha_tina::read_meta_file");
- VOID(my_seek(meta_file, 0, MY_SEEK_SET, MYF(0)));
- if (my_read(meta_file, (uchar*)meta_buffer, META_BUFFER_SIZE, 0)
+ mysql_file_seek(meta_file, 0, MY_SEEK_SET, MYF(0));
+ if (mysql_file_read(meta_file, (uchar*)meta_buffer, META_BUFFER_SIZE, 0)
!= META_BUFFER_SIZE)
DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
@@ -259,7 +303,7 @@ static int read_meta_file(File meta_file, ha_rows *rows)
((bool)(*ptr)== TRUE))
DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
- my_sync(meta_file, MYF(MY_WME));
+ mysql_file_sync(meta_file, MYF(MY_WME));
DBUG_RETURN(0);
}
@@ -305,12 +349,12 @@ static int write_meta_file(File meta_file, ha_rows rows, bool dirty)
ptr+= 3*sizeof(ulonglong);
*ptr= (uchar)dirty;
- VOID(my_seek(meta_file, 0, MY_SEEK_SET, MYF(0)));
- if (my_write(meta_file, (uchar *)meta_buffer, META_BUFFER_SIZE, 0)
+ mysql_file_seek(meta_file, 0, MY_SEEK_SET, MYF(0));
+ if (mysql_file_write(meta_file, (uchar *)meta_buffer, META_BUFFER_SIZE, 0)
!= META_BUFFER_SIZE)
DBUG_RETURN(-1);
- my_sync(meta_file, MYF(MY_WME));
+ mysql_file_sync(meta_file, MYF(MY_WME));
DBUG_RETURN(0);
}
@@ -338,7 +382,9 @@ int ha_tina::init_tina_writer()
(void)write_meta_file(share->meta_file, share->rows_recorded, TRUE);
if ((share->tina_write_filedes=
- my_open(share->data_file_name, O_RDWR|O_APPEND, MYF(MY_WME))) == -1)
+ mysql_file_open(csv_key_file_data,
+ share->data_file_name, O_RDWR|O_APPEND,
+ MYF(MY_WME))) == -1)
{
DBUG_PRINT("info", ("Could not open tina file writes"));
share->crashed= TRUE;
@@ -362,27 +408,27 @@ bool ha_tina::is_crashed() const
static int free_share(TINA_SHARE *share)
{
DBUG_ENTER("ha_tina::free_share");
- pthread_mutex_lock(&tina_mutex);
+ mysql_mutex_lock(&tina_mutex);
int result_code= 0;
if (!--share->use_count){
/* Write the meta file. Mark it as crashed if needed. */
(void)write_meta_file(share->meta_file, share->rows_recorded,
share->crashed ? TRUE :FALSE);
- if (my_close(share->meta_file, MYF(0)))
+ if (mysql_file_close(share->meta_file, MYF(0)))
result_code= 1;
if (share->tina_write_opened)
{
- if (my_close(share->tina_write_filedes, MYF(0)))
+ if (mysql_file_close(share->tina_write_filedes, MYF(0)))
result_code= 1;
share->tina_write_opened= FALSE;
}
my_hash_delete(&tina_open_tables, (uchar*) share);
thr_lock_delete(&share->lock);
- pthread_mutex_destroy(&share->mutex);
+ mysql_mutex_destroy(&share->mutex);
my_free((uchar*) share, MYF(0));
}
- pthread_mutex_unlock(&tina_mutex);
+ mysql_mutex_unlock(&tina_mutex);
DBUG_RETURN(result_code);
}
@@ -614,6 +660,33 @@ int ha_tina::find_current_row(uchar *buf)
memset(buf, 0, table->s->null_bytes);
+ /*
+ Parse the line obtained using the following algorithm
+
+ BEGIN
+ 1) Store the EOL (end of line) for the current row
+ 2) Until all the fields in the current query have not been
+ filled
+ 2.1) If the current character is a quote
+ 2.1.1) Until EOL has not been reached
+ a) If end of current field is reached, move
+ to next field and jump to step 2.3
+ b) If current character is a \\ handle
+ \\n, \\r, \\, \\"
+ c) else append the current character into the buffer
+ before checking that EOL has not been reached.
+ 2.2) If the current character does not begin with a quote
+ 2.2.1) Until EOL has not been reached
+ a) If the end of field has been reached move to the
+ next field and jump to step 2.3
+ b) If current character begins with \\ handle
+ \\n, \\r, \\, \\"
+ c) else append the current character into the buffer
+ before checking that EOL has not been reached.
+ 2.3) Store the current field value and jump to 2)
+ TERMINATE
+ */
+
for (Field **field=table->field ; *field ; field++)
{
char curr_char;
@@ -622,19 +695,23 @@ int ha_tina::find_current_row(uchar *buf)
if (curr_offset >= end_offset)
goto err;
curr_char= file_buff->get_value(curr_offset);
+ /* Handle the case where the first character is a quote */
if (curr_char == '"')
{
- curr_offset++; // Incrementpast the first quote
+ /* Increment past the first quote */
+ curr_offset++;
- for(; curr_offset < end_offset; curr_offset++)
+ /* Loop through the row to extract the values for the current field */
+ for ( ; curr_offset < end_offset; curr_offset++)
{
curr_char= file_buff->get_value(curr_offset);
- // Need to convert line feeds!
+ /* check for end of the current field */
if (curr_char == '"' &&
(curr_offset == end_offset - 1 ||
file_buff->get_value(curr_offset + 1) == ','))
{
- curr_offset+= 2; // Move past the , and the "
+ /* Move past the , and the " */
+ curr_offset+= 2;
break;
}
if (curr_char == '\\' && curr_offset != (end_offset - 1))
@@ -656,7 +733,7 @@ int ha_tina::find_current_row(uchar *buf)
else // ordinary symbol
{
/*
- We are at final symbol and no last quote was found =>
+ If we are at final symbol and no last quote was found =>
we are working with a damaged file.
*/
if (curr_offset == end_offset - 1)
@@ -667,15 +744,41 @@ int ha_tina::find_current_row(uchar *buf)
}
else
{
- for(; curr_offset < end_offset; curr_offset++)
+ for ( ; curr_offset < end_offset; curr_offset++)
{
curr_char= file_buff->get_value(curr_offset);
+ /* Move past the ,*/
if (curr_char == ',')
{
- curr_offset++; // Skip the ,
+ curr_offset++;
break;
}
- buffer.append(curr_char);
+ if (curr_char == '\\' && curr_offset != (end_offset - 1))
+ {
+ curr_offset++;
+ curr_char= file_buff->get_value(curr_offset);
+ if (curr_char == 'r')
+ buffer.append('\r');
+ else if (curr_char == 'n' )
+ buffer.append('\n');
+ else if (curr_char == '\\' || curr_char == '"')
+ buffer.append(curr_char);
+ else /* This could only happed with an externally created file */
+ {
+ buffer.append('\\');
+ buffer.append(curr_char);
+ }
+ }
+ else
+ {
+ /*
+ We are at the final symbol and a quote was found for the
+ unquoted field => We are working with a damaged field.
+ */
+ if (curr_offset == end_offset - 1 && curr_char == '"')
+ goto err;
+ buffer.append(curr_char);
+ }
}
}
@@ -769,9 +872,9 @@ void ha_tina::get_status()
We have to use mutex to follow pthreads memory visibility
rules for share->saved_data_file_length
*/
- pthread_mutex_lock(&share->mutex);
+ mysql_mutex_lock(&share->mutex);
local_saved_data_file_length= share->saved_data_file_length;
- pthread_mutex_unlock(&share->mutex);
+ mysql_mutex_unlock(&share->mutex);
return;
}
local_saved_data_file_length= share->saved_data_file_length;
@@ -825,8 +928,9 @@ int ha_tina::open(const char *name, int mode, uint open_options)
}
local_data_file_version= share->data_file_version;
- if ((data_file= my_open(share->data_file_name,
- O_RDONLY, MYF(MY_WME))) == -1)
+ if ((data_file= mysql_file_open(csv_key_file_data,
+ share->data_file_name,
+ O_RDONLY, MYF(MY_WME))) == -1)
{
free_share(share);
DBUG_RETURN(my_errno ? my_errno : -1);
@@ -856,7 +960,7 @@ int ha_tina::close(void)
{
int rc= 0;
DBUG_ENTER("ha_tina::close");
- rc= my_close(data_file, MYF(0));
+ rc= mysql_file_close(data_file, MYF(0));
DBUG_RETURN(free_share(share) || rc);
}
@@ -885,20 +989,20 @@ int ha_tina::write_row(uchar * buf)
DBUG_RETURN(-1);
/* use pwrite, as concurrent reader could have changed the position */
- if (my_write(share->tina_write_filedes, (uchar*)buffer.ptr(), size,
- MYF(MY_WME | MY_NABP)))
+ if (mysql_file_write(share->tina_write_filedes, (uchar*)buffer.ptr(), size,
+ MYF(MY_WME | MY_NABP)))
DBUG_RETURN(-1);
/* update local copy of the max position to see our own changes */
local_saved_data_file_length+= size;
/* update shared info */
- pthread_mutex_lock(&share->mutex);
+ mysql_mutex_lock(&share->mutex);
share->rows_recorded++;
/* update status for the log tables */
if (share->is_log_table)
update_status();
- pthread_mutex_unlock(&share->mutex);
+ mysql_mutex_unlock(&share->mutex);
stats.records++;
DBUG_RETURN(0);
@@ -912,10 +1016,11 @@ int ha_tina::open_update_temp_file_if_needed()
if (!share->update_file_opened)
{
if ((update_temp_file=
- my_create(fn_format(updated_fname, share->table_name,
- "", CSN_EXT,
- MY_REPLACE_EXT | MY_UNPACK_FILENAME),
- 0, O_RDWR | O_TRUNC, MYF(MY_WME))) < 0)
+ mysql_file_create(csv_key_file_update,
+ fn_format(updated_fname, share->table_name,
+ "", CSN_EXT,
+ MY_REPLACE_EXT | MY_UNPACK_FILENAME),
+ 0, O_RDWR | O_TRUNC, MYF(MY_WME))) < 0)
return 1;
share->update_file_opened= TRUE;
temp_file_length= 0;
@@ -957,8 +1062,8 @@ int ha_tina::update_row(const uchar * old_data, uchar * new_data)
if (open_update_temp_file_if_needed())
goto err;
- if (my_write(update_temp_file, (uchar*)buffer.ptr(), size,
- MYF(MY_WME | MY_NABP)))
+ if (mysql_file_write(update_temp_file, (uchar*)buffer.ptr(), size,
+ MYF(MY_WME | MY_NABP)))
goto err;
temp_file_length+= size;
rc= 0;
@@ -992,9 +1097,9 @@ int ha_tina::delete_row(const uchar * buf)
stats.records--;
/* Update shared info */
DBUG_ASSERT(share->rows_recorded);
- pthread_mutex_lock(&share->mutex);
+ mysql_mutex_lock(&share->mutex);
share->rows_recorded--;
- pthread_mutex_unlock(&share->mutex);
+ mysql_mutex_unlock(&share->mutex);
/* DELETE should never happen on the log table */
DBUG_ASSERT(!share->is_log_table);
@@ -1021,8 +1126,10 @@ int ha_tina::init_data_file()
if (local_data_file_version != share->data_file_version)
{
local_data_file_version= share->data_file_version;
- if (my_close(data_file, MYF(0)) ||
- (data_file= my_open(share->data_file_name, O_RDONLY, MYF(MY_WME))) == -1)
+ if (mysql_file_close(data_file, MYF(0)) ||
+ (data_file= mysql_file_open(csv_key_file_data,
+ share->data_file_name, O_RDONLY,
+ MYF(MY_WME))) == -1)
return my_errno ? my_errno : -1;
}
file_buff->init_buff(data_file);
@@ -1184,9 +1291,9 @@ int ha_tina::extra(enum ha_extra_function operation)
DBUG_ENTER("ha_tina::extra");
if (operation == HA_EXTRA_MARK_AS_LOG_TABLE)
{
- pthread_mutex_lock(&share->mutex);
+ mysql_mutex_lock(&share->mutex);
share->is_log_table= TRUE;
- pthread_mutex_unlock(&share->mutex);
+ mysql_mutex_unlock(&share->mutex);
}
DBUG_RETURN(0);
}
@@ -1255,10 +1362,10 @@ int ha_tina::rnd_end()
/* if there is something to write, write it */
if (write_length)
{
- if (my_write(update_temp_file,
- (uchar*) (file_buff->ptr() +
- (write_begin - file_buff->start())),
- (size_t)write_length, MYF_RW))
+ if (mysql_file_write(update_temp_file,
+ (uchar*) (file_buff->ptr() +
+ (write_begin - file_buff->start())),
+ (size_t)write_length, MYF_RW))
goto error;
temp_file_length+= write_length;
}
@@ -1279,15 +1386,15 @@ int ha_tina::rnd_end()
}
- if (my_sync(update_temp_file, MYF(MY_WME)) ||
- my_close(update_temp_file, MYF(0)))
+ if (mysql_file_sync(update_temp_file, MYF(MY_WME)) ||
+ mysql_file_close(update_temp_file, MYF(0)))
DBUG_RETURN(-1);
share->update_file_opened= FALSE;
if (share->tina_write_opened)
{
- if (my_close(share->tina_write_filedes, MYF(0)))
+ if (mysql_file_close(share->tina_write_filedes, MYF(0)))
DBUG_RETURN(-1);
/*
Mark that the writer fd is closed, so that init_tina_writer()
@@ -1300,15 +1407,18 @@ int ha_tina::rnd_end()
Close opened fildes's. Then move updated file in place
of the old datafile.
*/
- if (my_close(data_file, MYF(0)) ||
- my_rename(fn_format(updated_fname, share->table_name, "", CSN_EXT,
- MY_REPLACE_EXT | MY_UNPACK_FILENAME),
- share->data_file_name, MYF(0)))
+ if (mysql_file_close(data_file, MYF(0)) ||
+ mysql_file_rename(csv_key_file_data,
+ fn_format(updated_fname, share->table_name,
+ "", CSN_EXT,
+ MY_REPLACE_EXT | MY_UNPACK_FILENAME),
+ share->data_file_name, MYF(0)))
DBUG_RETURN(-1);
/* Open the file again */
- if (((data_file= my_open(share->data_file_name,
- O_RDONLY, MYF(MY_WME))) == -1))
+ if (((data_file= mysql_file_open(csv_key_file_data,
+ share->data_file_name,
+ O_RDONLY, MYF(MY_WME))) == -1))
DBUG_RETURN(my_errno ? my_errno : -1);
/*
As we reopened the data file, increase share->data_file_version
@@ -1335,7 +1445,7 @@ int ha_tina::rnd_end()
DBUG_RETURN(0);
error:
- my_close(update_temp_file, MYF(0));
+ mysql_file_close(update_temp_file, MYF(0));
share->update_file_opened= FALSE;
DBUG_RETURN(-1);
}
@@ -1421,10 +1531,12 @@ int ha_tina::repair(THD* thd, HA_CHECK_OPT* check_opt)
Otherwise we've encountered a bad row => repair is needed.
Let us create a temporary file.
*/
- if ((repair_file= my_create(fn_format(repaired_fname, share->table_name,
- "", CSN_EXT,
- MY_REPLACE_EXT|MY_UNPACK_FILENAME),
- 0, O_RDWR | O_TRUNC,MYF(MY_WME))) < 0)
+ if ((repair_file= mysql_file_create(csv_key_file_update,
+ fn_format(repaired_fname,
+ share->table_name,
+ "", CSN_EXT,
+ MY_REPLACE_EXT|MY_UNPACK_FILENAME),
+ 0, O_RDWR | O_TRUNC, MYF(MY_WME))) < 0)
DBUG_RETURN(HA_ERR_CRASHED_ON_REPAIR);
file_buff->init_buff(data_file);
@@ -1438,8 +1550,8 @@ int ha_tina::repair(THD* thd, HA_CHECK_OPT* check_opt)
{
write_end= min(file_buff->end(), current_position);
if ((write_end - write_begin) &&
- (my_write(repair_file, (uchar*)file_buff->ptr(),
- (size_t) (write_end - write_begin), MYF_RW)))
+ (mysql_file_write(repair_file, (uchar*)file_buff->ptr(),
+ (size_t) (write_end - write_begin), MYF_RW)))
DBUG_RETURN(-1);
write_begin= write_end;
@@ -1453,7 +1565,7 @@ int ha_tina::repair(THD* thd, HA_CHECK_OPT* check_opt)
Close the files and rename repaired file to the datafile.
We have to close the files, as on Windows one cannot rename
a file, which descriptor is still open. EACCES will be returned
- when trying to delete the "to"-file in my_rename().
+ when trying to delete the "to"-file in mysql_file_rename().
*/
if (share->tina_write_opened)
{
@@ -1462,17 +1574,20 @@ int ha_tina::repair(THD* thd, HA_CHECK_OPT* check_opt)
during write_row execution. We need to close both instances
to satisfy Win.
*/
- if (my_close(share->tina_write_filedes, MYF(0)))
+ if (mysql_file_close(share->tina_write_filedes, MYF(0)))
DBUG_RETURN(my_errno ? my_errno : -1);
share->tina_write_opened= FALSE;
}
- if (my_close(data_file,MYF(0)) || my_close(repair_file, MYF(0)) ||
- my_rename(repaired_fname, share->data_file_name, MYF(0)))
+ if (mysql_file_close(data_file, MYF(0)) ||
+ mysql_file_close(repair_file, MYF(0)) ||
+ mysql_file_rename(csv_key_file_data,
+ repaired_fname, share->data_file_name, MYF(0)))
DBUG_RETURN(-1);
/* Open the file again, it should now be repaired */
- if ((data_file= my_open(share->data_file_name, O_RDWR|O_APPEND,
- MYF(MY_WME))) == -1)
+ if ((data_file= mysql_file_open(csv_key_file_data,
+ share->data_file_name, O_RDWR|O_APPEND,
+ MYF(MY_WME))) == -1)
DBUG_RETURN(my_errno ? my_errno : -1);
/* Set new file size. The file size will be updated by ::update_status() */
@@ -1500,13 +1615,13 @@ int ha_tina::delete_all_rows()
DBUG_RETURN(-1);
/* Truncate the file to zero size */
- rc= my_chsize(share->tina_write_filedes, 0, 0, MYF(MY_WME));
+ rc= mysql_file_chsize(share->tina_write_filedes, 0, 0, MYF(MY_WME));
stats.records=0;
/* Update shared info */
- pthread_mutex_lock(&share->mutex);
+ mysql_mutex_lock(&share->mutex);
share->rows_recorded= 0;
- pthread_mutex_unlock(&share->mutex);
+ mysql_mutex_unlock(&share->mutex);
local_saved_data_file_length= 0;
DBUG_RETURN(rc);
}
@@ -1550,20 +1665,22 @@ int ha_tina::create(const char *name, TABLE *table_arg,
}
- if ((create_file= my_create(fn_format(name_buff, name, "", CSM_EXT,
- MY_REPLACE_EXT|MY_UNPACK_FILENAME), 0,
- O_RDWR | O_TRUNC,MYF(MY_WME))) < 0)
+ if ((create_file= mysql_file_create(csv_key_file_metadata,
+ fn_format(name_buff, name, "", CSM_EXT,
+ MY_REPLACE_EXT|MY_UNPACK_FILENAME),
+ 0, O_RDWR | O_TRUNC, MYF(MY_WME))) < 0)
DBUG_RETURN(-1);
write_meta_file(create_file, 0, FALSE);
- my_close(create_file, MYF(0));
+ mysql_file_close(create_file, MYF(0));
- if ((create_file= my_create(fn_format(name_buff, name, "", CSV_EXT,
- MY_REPLACE_EXT|MY_UNPACK_FILENAME),0,
- O_RDWR | O_TRUNC,MYF(MY_WME))) < 0)
+ if ((create_file= mysql_file_create(csv_key_file_data,
+ fn_format(name_buff, name, "", CSV_EXT,
+ MY_REPLACE_EXT|MY_UNPACK_FILENAME),
+ 0, O_RDWR | O_TRUNC, MYF(MY_WME))) < 0)
DBUG_RETURN(-1);
- my_close(create_file, MYF(0));
+ mysql_file_close(create_file, MYF(0));
DBUG_RETURN(0);
}
diff --git a/storage/csv/ha_tina.h b/storage/csv/ha_tina.h
index a246d1858e5..7bb80170e87 100644
--- a/storage/csv/ha_tina.h
+++ b/storage/csv/ha_tina.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003 MySQL AB
+/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -41,7 +41,7 @@ typedef struct st_tina_share {
share initialization.
*/
my_off_t saved_data_file_length;
- pthread_mutex_t mutex;
+ mysql_mutex_t mutex;
THR_LOCK lock;
bool update_file_opened;
bool tina_write_opened;
diff --git a/storage/csv/transparent_file.cc b/storage/csv/transparent_file.cc
index 841c3efc476..937f1fb292a 100644
--- a/storage/csv/transparent_file.cc
+++ b/storage/csv/transparent_file.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003 MySQL AB
+/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -35,9 +35,9 @@ void Transparent_file::init_buff(File filedes_arg)
filedes= filedes_arg;
/* read the beginning of the file */
lower_bound= 0;
- VOID(my_seek(filedes, 0, MY_SEEK_SET, MYF(0)));
+ mysql_file_seek(filedes, 0, MY_SEEK_SET, MYF(0));
if (filedes && buff)
- upper_bound= my_read(filedes, buff, buff_size, MYF(0));
+ upper_bound= mysql_file_read(filedes, buff, buff_size, MYF(0));
}
uchar *Transparent_file::ptr()
@@ -63,7 +63,8 @@ my_off_t Transparent_file::read_next()
No need to seek here, as the file managed by Transparent_file class
always points to upper_bound byte
*/
- if ((bytes_read= my_read(filedes, buff, buff_size, MYF(0))) == MY_FILE_ERROR)
+ if ((bytes_read= mysql_file_read(filedes, buff, buff_size, MYF(0)))
+ == MY_FILE_ERROR)
return (my_off_t) -1;
/* end of file */
@@ -85,10 +86,10 @@ char Transparent_file::get_value(my_off_t offset)
if ((lower_bound <= offset) && (((my_off_t) offset) < upper_bound))
return buff[offset - lower_bound];
- VOID(my_seek(filedes, offset, MY_SEEK_SET, MYF(0)));
+ mysql_file_seek(filedes, offset, MY_SEEK_SET, MYF(0));
/* read appropriate portion of the file */
- if ((bytes_read= my_read(filedes, buff, buff_size,
- MYF(0))) == MY_FILE_ERROR)
+ if ((bytes_read= mysql_file_read(filedes, buff, buff_size,
+ MYF(0))) == MY_FILE_ERROR)
return 0;
lower_bound= offset;
diff --git a/storage/example/ha_example.cc b/storage/example/ha_example.cc
index 9bc666663c3..8d2eb914a97 100644
--- a/storage/example/ha_example.cc
+++ b/storage/example/ha_example.cc
@@ -112,7 +112,7 @@ handlerton *example_hton;
static HASH example_open_tables;
/* The mutex used to init the hash; variable for example share methods */
-pthread_mutex_t example_mutex;
+mysql_mutex_t example_mutex;
/**
@brief
@@ -126,13 +126,39 @@ static uchar* example_get_key(EXAMPLE_SHARE *share, size_t *length,
return (uchar*) share->table_name;
}
+#ifdef HAVE_PSI_INTERFACE
+static PSI_mutex_key ex_key_mutex_example, ex_key_mutex_EXAMPLE_SHARE_mutex;
+
+static PSI_mutex_info all_example_mutexes[]=
+{
+ { &ex_key_mutex_example, "example", PSI_FLAG_GLOBAL},
+ { &ex_key_mutex_EXAMPLE_SHARE_mutex, "EXAMPLE_SHARE::mutex", 0}
+};
+
+static void init_example_psi_keys()
+{
+ const char* category= "example";
+ int count;
+
+ if (PSI_server == NULL)
+ return;
+
+ count= array_elements(all_example_mutexes);
+ PSI_server->register_mutex(category, all_example_mutexes, count);
+}
+#endif
+
static int example_init_func(void *p)
{
DBUG_ENTER("example_init_func");
+#ifdef HAVE_PSI_INTERFACE
+ init_example_psi_keys();
+#endif
+
example_hton= (handlerton *)p;
- VOID(pthread_mutex_init(&example_mutex,MY_MUTEX_INIT_FAST));
+ mysql_mutex_init(ex_key_mutex_example, &example_mutex, MY_MUTEX_INIT_FAST);
(void) my_hash_init(&example_open_tables,system_charset_info,32,0,0,
(my_hash_get_key) example_get_key,0,0);
@@ -152,7 +178,7 @@ static int example_done_func(void *p)
if (example_open_tables.records)
error= 1;
my_hash_free(&example_open_tables);
- pthread_mutex_destroy(&example_mutex);
+ mysql_mutex_destroy(&example_mutex);
DBUG_RETURN(0);
}
@@ -172,7 +198,7 @@ static EXAMPLE_SHARE *get_share(const char *table_name, TABLE *table)
uint length;
char *tmp_name;
- pthread_mutex_lock(&example_mutex);
+ mysql_mutex_lock(&example_mutex);
length=(uint) strlen(table_name);
if (!(share=(EXAMPLE_SHARE*) my_hash_search(&example_open_tables,
@@ -185,7 +211,7 @@ static EXAMPLE_SHARE *get_share(const char *table_name, TABLE *table)
&tmp_name, length+1,
NullS)))
{
- pthread_mutex_unlock(&example_mutex);
+ mysql_mutex_unlock(&example_mutex);
return NULL;
}
@@ -196,15 +222,16 @@ static EXAMPLE_SHARE *get_share(const char *table_name, TABLE *table)
if (my_hash_insert(&example_open_tables, (uchar*) share))
goto error;
thr_lock_init(&share->lock);
- pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(ex_key_mutex_EXAMPLE_SHARE_mutex,
+ &share->mutex, MY_MUTEX_INIT_FAST);
}
share->use_count++;
- pthread_mutex_unlock(&example_mutex);
+ mysql_mutex_unlock(&example_mutex);
return share;
error:
- pthread_mutex_destroy(&share->mutex);
+ mysql_mutex_destroy(&share->mutex);
my_free(share, MYF(0));
return NULL;
@@ -219,15 +246,15 @@ error:
static int free_share(EXAMPLE_SHARE *share)
{
- pthread_mutex_lock(&example_mutex);
+ mysql_mutex_lock(&example_mutex);
if (!--share->use_count)
{
my_hash_delete(&example_open_tables, (uchar*) share);
thr_lock_delete(&share->lock);
- pthread_mutex_destroy(&share->mutex);
+ mysql_mutex_destroy(&share->mutex);
my_free(share, MYF(0));
}
- pthread_mutex_unlock(&example_mutex);
+ mysql_mutex_unlock(&example_mutex);
return 0;
}
diff --git a/storage/example/ha_example.h b/storage/example/ha_example.h
index ec3987ced5d..4f88d6ced8e 100644
--- a/storage/example/ha_example.h
+++ b/storage/example/ha_example.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003 MySQL AB
+/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -42,7 +42,7 @@
typedef struct st_example_share {
char *table_name;
uint table_name_length,use_count;
- pthread_mutex_t mutex;
+ mysql_mutex_t mutex;
THR_LOCK lock;
} EXAMPLE_SHARE;
diff --git a/storage/federated/ha_federated.cc b/storage/federated/ha_federated.cc
index 05be8b27a8b..a73a39440d7 100644
--- a/storage/federated/ha_federated.cc
+++ b/storage/federated/ha_federated.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2004 MySQL AB
+/* Copyright (C) 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -388,7 +388,7 @@
/* Variables for federated share methods */
static HASH federated_open_tables; // To track open tables
-pthread_mutex_t federated_mutex; // To init the hash
+mysql_mutex_t federated_mutex; // To init the hash
static char ident_quote_char= '`'; // Character for quoting
// identifiers
static char value_quote_char= '\''; // Character for quoting
@@ -427,6 +427,28 @@ static uchar *federated_get_key(FEDERATED_SHARE *share, size_t *length,
return (uchar*) share->share_key;
}
+#ifdef HAVE_PSI_INTERFACE
+static PSI_mutex_key fe_key_mutex_federated, fe_key_mutex_FEDERATED_SHARE_mutex;
+
+static PSI_mutex_info all_federated_mutexes[]=
+{
+ { &fe_key_mutex_federated, "federated", PSI_FLAG_GLOBAL},
+ { &fe_key_mutex_FEDERATED_SHARE_mutex, "FEDERATED_SHARE::mutex", 0}
+};
+
+static void init_federated_psi_keys(void)
+{
+ const char* category= "federated";
+ int count;
+
+ if (PSI_server == NULL)
+ return;
+
+ count= array_elements(all_federated_mutexes);
+ PSI_server->register_mutex(category, all_federated_mutexes, count);
+}
+#endif /* HAVE_PSI_INTERFACE */
+
/*
Initialize the federated handler.
@@ -442,6 +464,11 @@ static uchar *federated_get_key(FEDERATED_SHARE *share, size_t *length,
int federated_db_init(void *p)
{
DBUG_ENTER("federated_db_init");
+
+#ifdef HAVE_PSI_INTERFACE
+ init_federated_psi_keys();
+#endif /* HAVE_PSI_INTERFACE */
+
handlerton *federated_hton= (handlerton *)p;
federated_hton->state= SHOW_OPTION_YES;
federated_hton->db_type= DB_TYPE_FEDERATED_DB;
@@ -457,7 +484,8 @@ int federated_db_init(void *p)
federated_hton->commit= 0;
federated_hton->rollback= 0;
- if (pthread_mutex_init(&federated_mutex, MY_MUTEX_INIT_FAST))
+ if (mysql_mutex_init(fe_key_mutex_federated,
+ &federated_mutex, MY_MUTEX_INIT_FAST))
goto error;
if (!my_hash_init(&federated_open_tables, &my_charset_bin, 32, 0, 0,
(my_hash_get_key) federated_get_key, 0, 0))
@@ -465,7 +493,7 @@ int federated_db_init(void *p)
DBUG_RETURN(FALSE);
}
- VOID(pthread_mutex_destroy(&federated_mutex));
+ mysql_mutex_destroy(&federated_mutex);
error:
DBUG_RETURN(TRUE);
}
@@ -484,7 +512,7 @@ error:
int federated_done(void *p)
{
my_hash_free(&federated_open_tables);
- VOID(pthread_mutex_destroy(&federated_mutex));
+ mysql_mutex_destroy(&federated_mutex);
return 0;
}
@@ -1487,7 +1515,7 @@ static FEDERATED_SHARE *get_share(const char *table_name, TABLE *table)
init_alloc_root(&mem_root, 256, 0);
- pthread_mutex_lock(&federated_mutex);
+ mysql_mutex_lock(&federated_mutex);
tmp_share.share_key= table_name;
tmp_share.share_key_length= (uint) strlen(table_name);
@@ -1529,18 +1557,19 @@ static FEDERATED_SHARE *get_share(const char *table_name, TABLE *table)
if (my_hash_insert(&federated_open_tables, (uchar*) share))
goto error;
thr_lock_init(&share->lock);
- pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(fe_key_mutex_FEDERATED_SHARE_mutex,
+ &share->mutex, MY_MUTEX_INIT_FAST);
}
else
free_root(&mem_root, MYF(0)); /* prevents memory leak */
share->use_count++;
- pthread_mutex_unlock(&federated_mutex);
+ mysql_mutex_unlock(&federated_mutex);
DBUG_RETURN(share);
error:
- pthread_mutex_unlock(&federated_mutex);
+ mysql_mutex_unlock(&federated_mutex);
free_root(&mem_root, MYF(0));
DBUG_RETURN(NULL);
}
@@ -1557,15 +1586,15 @@ static int free_share(FEDERATED_SHARE *share)
MEM_ROOT mem_root= share->mem_root;
DBUG_ENTER("free_share");
- pthread_mutex_lock(&federated_mutex);
+ mysql_mutex_lock(&federated_mutex);
if (!--share->use_count)
{
my_hash_delete(&federated_open_tables, (uchar*) share);
thr_lock_delete(&share->lock);
- VOID(pthread_mutex_destroy(&share->mutex));
+ mysql_mutex_destroy(&share->mutex);
free_root(&mem_root, MYF(0));
}
- pthread_mutex_unlock(&federated_mutex);
+ mysql_mutex_unlock(&federated_mutex);
DBUG_RETURN(0);
}
diff --git a/storage/federated/ha_federated.h b/storage/federated/ha_federated.h
index ea0a3d2f591..8efb8ed744a 100644
--- a/storage/federated/ha_federated.h
+++ b/storage/federated/ha_federated.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003 MySQL AB
+/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -71,7 +71,7 @@ typedef struct st_federated_share {
ushort port;
size_t table_name_length, server_name_length, connect_string_length, use_count;
- pthread_mutex_t mutex;
+ mysql_mutex_t mutex;
THR_LOCK lock;
} FEDERATED_SHARE;
diff --git a/storage/heap/ha_heap.cc b/storage/heap/ha_heap.cc
index 99c1ca5d2e9..8d07d21c6ae 100644
--- a/storage/heap/ha_heap.cc
+++ b/storage/heap/ha_heap.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -39,6 +39,10 @@ int heap_init(void *p)
{
handlerton *heap_hton;
+#ifdef HAVE_PSI_INTERFACE
+ init_heap_psi_keys();
+#endif
+
heap_hton= (handlerton *)p;
heap_hton->state= SHOW_OPTION_YES;
heap_hton->db_type= DB_TYPE_HEAP;
@@ -106,9 +110,9 @@ int ha_heap::open(const char *name, int mode, uint test_if_locked)
if (!file)
{
/* Couldn't open table; Remove the newly created table */
- pthread_mutex_lock(&THR_LOCK_heap);
+ mysql_mutex_lock(&THR_LOCK_heap);
hp_free(internal_share);
- pthread_mutex_unlock(&THR_LOCK_heap);
+ mysql_mutex_unlock(&THR_LOCK_heap);
}
implicit_emptied= 1;
}
diff --git a/storage/heap/heapdef.h b/storage/heap/heapdef.h
index 3fc94062303..bc3c6bf7239 100644
--- a/storage/heap/heapdef.h
+++ b/storage/heap/heapdef.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2002, 2004 MySQL AB
+/* Copyright (C) 2000-2002, 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -103,9 +103,14 @@ extern void hp_clear_keys(HP_SHARE *info);
extern uint hp_rb_pack_key(HP_KEYDEF *keydef, uchar *key, const uchar *old,
key_part_map keypart_map);
#ifdef THREAD
-extern pthread_mutex_t THR_LOCK_heap;
-#else
-#define pthread_mutex_lock(A)
-#define pthread_mutex_unlock(A)
+extern mysql_mutex_t THR_LOCK_heap;
#endif
+
+#ifdef HAVE_PSI_INTERFACE
+#ifdef THREAD
+extern PSI_mutex_key hp_key_mutex_HP_SHARE_intern_lock;
+#endif /* THREAD */
+void init_heap_psi_keys();
+#endif /* HAVE_PSI_INTERFACE */
+
C_MODE_END
diff --git a/storage/heap/hp_clear.c b/storage/heap/hp_clear.c
index babfcbd6f41..9c04684e269 100644
--- a/storage/heap/hp_clear.c
+++ b/storage/heap/hp_clear.c
@@ -31,8 +31,8 @@ void hp_clear(HP_SHARE *info)
DBUG_ENTER("hp_clear");
if (info->block.levels)
- VOID(hp_free_level(&info->block,info->block.levels,info->block.root,
- (uchar*) 0));
+ (void) hp_free_level(&info->block,info->block.levels,info->block.root,
+ (uchar*) 0);
info->block.levels=0;
hp_clear_keys(info);
info->records= info->deleted= 0;
@@ -94,7 +94,7 @@ void hp_clear_keys(HP_SHARE *info)
{
HP_BLOCK *block= &keyinfo->block;
if (block->levels)
- VOID(hp_free_level(block,block->levels,block->root,(uchar*) 0));
+ (void) hp_free_level(block,block->levels,block->root,(uchar*) 0);
block->levels=0;
block->last_allocated=0;
keyinfo->hash_buckets= 0;
diff --git a/storage/heap/hp_close.c b/storage/heap/hp_close.c
index d571815980c..49d8ec376bb 100644
--- a/storage/heap/hp_close.c
+++ b/storage/heap/hp_close.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2002 MySQL AB
+/* Copyright (C) 2000-2002 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -24,9 +24,9 @@ int heap_close(HP_INFO *info)
{
int tmp;
DBUG_ENTER("heap_close");
- pthread_mutex_lock(&THR_LOCK_heap);
+ mysql_mutex_lock(&THR_LOCK_heap);
tmp= hp_close(info);
- pthread_mutex_unlock(&THR_LOCK_heap);
+ mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_RETURN(tmp);
}
diff --git a/storage/heap/hp_create.c b/storage/heap/hp_create.c
index b6814fc1614..3f651d1573c 100644
--- a/storage/heap/hp_create.c
+++ b/storage/heap/hp_create.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -32,7 +32,7 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef,
if (!create_info->internal_table)
{
- pthread_mutex_lock(&THR_LOCK_heap);
+ mysql_mutex_lock(&THR_LOCK_heap);
if ((share= hp_find_named_heap(name)) && share->open_count == 0)
{
hp_free(share);
@@ -194,7 +194,8 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef,
}
#ifdef THREAD
thr_lock_init(&share->lock);
- VOID(pthread_mutex_init(&share->intern_lock,MY_MUTEX_INIT_FAST));
+ mysql_mutex_init(hp_key_mutex_HP_SHARE_intern_lock,
+ &share->intern_lock, MY_MUTEX_INIT_FAST);
#endif
if (!create_info->internal_table)
{
@@ -205,14 +206,14 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef,
share->delete_on_close= 1;
}
if (!create_info->internal_table)
- pthread_mutex_unlock(&THR_LOCK_heap);
+ mysql_mutex_unlock(&THR_LOCK_heap);
*res= share;
DBUG_RETURN(0);
err:
if (!create_info->internal_table)
- pthread_mutex_unlock(&THR_LOCK_heap);
+ mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_RETURN(1);
} /* heap_create */
@@ -266,7 +267,7 @@ int heap_delete_table(const char *name)
reg1 HP_SHARE *share;
DBUG_ENTER("heap_delete_table");
- pthread_mutex_lock(&THR_LOCK_heap);
+ mysql_mutex_lock(&THR_LOCK_heap);
if ((share= hp_find_named_heap(name)))
{
heap_try_free(share);
@@ -276,7 +277,7 @@ int heap_delete_table(const char *name)
{
result= my_errno=ENOENT;
}
- pthread_mutex_unlock(&THR_LOCK_heap);
+ mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_RETURN(result);
}
@@ -284,9 +285,9 @@ int heap_delete_table(const char *name)
void heap_drop_table(HP_INFO *info)
{
DBUG_ENTER("heap_drop_table");
- pthread_mutex_lock(&THR_LOCK_heap);
+ mysql_mutex_lock(&THR_LOCK_heap);
heap_try_free(info->s);
- pthread_mutex_unlock(&THR_LOCK_heap);
+ mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_VOID_RETURN;
}
@@ -298,7 +299,7 @@ void hp_free(HP_SHARE *share)
hp_clear(share); /* Remove blocks from memory */
#ifdef THREAD
thr_lock_delete(&share->lock);
- VOID(pthread_mutex_destroy(&share->intern_lock));
+ mysql_mutex_destroy(&share->intern_lock);
#endif
my_free((uchar*) share->name, MYF(0));
my_free((uchar*) share, MYF(0));
diff --git a/storage/heap/hp_open.c b/storage/heap/hp_open.c
index 4d5ec6e27ac..feafa5d5cf1 100644
--- a/storage/heap/hp_open.c
+++ b/storage/heap/hp_open.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2004, 2006 MySQL AB
+/* Copyright (C) 2000-2004, 2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -69,13 +69,13 @@ HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode)
HP_INFO *info;
DBUG_ENTER("heap_open_from_share_and_register");
- pthread_mutex_lock(&THR_LOCK_heap);
+ mysql_mutex_lock(&THR_LOCK_heap);
if ((info= heap_open_from_share(share, mode)))
{
info->open_list.data= (void*) info;
heap_open_list= list_add(heap_open_list,&info->open_list);
}
- pthread_mutex_unlock(&THR_LOCK_heap);
+ mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_RETURN(info);
}
@@ -94,11 +94,11 @@ HP_INFO *heap_open(const char *name, int mode)
HP_SHARE *share;
DBUG_ENTER("heap_open");
- pthread_mutex_lock(&THR_LOCK_heap);
+ mysql_mutex_lock(&THR_LOCK_heap);
if (!(share= hp_find_named_heap(name)))
{
my_errno= ENOENT;
- pthread_mutex_unlock(&THR_LOCK_heap);
+ mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_RETURN(0);
}
if ((info= heap_open_from_share(share, mode)))
@@ -106,7 +106,7 @@ HP_INFO *heap_open(const char *name, int mode)
info->open_list.data= (void*) info;
heap_open_list= list_add(heap_open_list,&info->open_list);
}
- pthread_mutex_unlock(&THR_LOCK_heap);
+ mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_RETURN(info);
}
diff --git a/storage/heap/hp_panic.c b/storage/heap/hp_panic.c
index 9a2bd2c574e..87d982dff2a 100644
--- a/storage/heap/hp_panic.c
+++ b/storage/heap/hp_panic.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2002 MySQL AB
+/* Copyright (C) 2000-2002 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -23,7 +23,7 @@ int hp_panic(enum ha_panic_function flag)
LIST *element,*next_open;
DBUG_ENTER("hp_panic");
- pthread_mutex_lock(&THR_LOCK_heap);
+ mysql_mutex_lock(&THR_LOCK_heap);
for (element=heap_open_list ; element ; element=next_open)
{
HP_INFO *info=(HP_INFO*) element->data;
@@ -51,6 +51,6 @@ int hp_panic(enum ha_panic_function flag)
break;
}
}
- pthread_mutex_unlock(&THR_LOCK_heap);
+ mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_RETURN(0);
} /* hp_panic */
diff --git a/storage/heap/hp_rename.c b/storage/heap/hp_rename.c
index c2350450e2b..c4e8390cc43 100644
--- a/storage/heap/hp_rename.c
+++ b/storage/heap/hp_rename.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2002 MySQL AB
+/* Copyright (C) 2000-2002 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -25,17 +25,17 @@ int heap_rename(const char *old_name, const char *new_name)
char *name_buff;
DBUG_ENTER("heap_rename");
- pthread_mutex_lock(&THR_LOCK_heap);
+ mysql_mutex_lock(&THR_LOCK_heap);
if ((info = hp_find_named_heap(old_name)))
{
if (!(name_buff=(char*) my_strdup(new_name,MYF(MY_WME))))
{
- pthread_mutex_unlock(&THR_LOCK_heap);
+ mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_RETURN(my_errno);
}
my_free(info->name,MYF(0));
info->name=name_buff;
}
- pthread_mutex_unlock(&THR_LOCK_heap);
+ mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_RETURN(0);
}
diff --git a/storage/heap/hp_static.c b/storage/heap/hp_static.c
index a501ba7e359..e1ca7d1f445 100644
--- a/storage/heap/hp_static.c
+++ b/storage/heap/hp_static.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2001 MySQL AB
+/* Copyright (C) 2000-2001 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -23,3 +23,34 @@
#endif
LIST *heap_open_list=0,*heap_share_list=0;
+
+#ifdef HAVE_PSI_INTERFACE
+#ifdef THREAD
+PSI_mutex_key hp_key_mutex_HP_SHARE_intern_lock;
+
+static PSI_mutex_info all_heap_mutexes[]=
+{
+ { & hp_key_mutex_HP_SHARE_intern_lock, "HP_SHARE::intern_lock", 0}
+ /*
+ Note:
+ THR_LOCK_heap is part of mysys, not storage/heap.
+ */
+};
+#endif /* THREAD */
+
+void init_heap_psi_keys()
+{
+#ifdef THREAD
+ const char* category= "memory";
+ int count;
+
+ if (PSI_server == NULL)
+ return;
+
+ count= array_elements(all_heap_mutexes);
+ PSI_server->register_mutex(category, all_heap_mutexes, count);
+#endif /* THREAD */
+}
+#endif /* HAVE_PSI_INTERFACE */
+
+
diff --git a/storage/heap/hp_test1.c b/storage/heap/hp_test1.c
index b1b55098a78..911e3a285a2 100644
--- a/storage/heap/hp_test1.c
+++ b/storage/heap/hp_test1.c
@@ -91,7 +91,7 @@ int main(int argc, char **argv)
printf("- Removing records\n");
for (i=1 ; i<=10 ; i++)
{
- if (i == remove_ant) { VOID(heap_close(file)) ; return (0) ; }
+ if (i == remove_ant) { (void) heap_close(file); return (0) ; }
sprintf((char*) key,"%6d",(j=(int) ((rand() & 32767)/32767.*25)));
if ((error = heap_rkey(file,record,0,key,6,HA_READ_KEY_EXACT)))
{
diff --git a/storage/heap/hp_test2.c b/storage/heap/hp_test2.c
index 5c548b6be74..8216c7360b4 100644
--- a/storage/heap/hp_test2.c
+++ b/storage/heap/hp_test2.c
@@ -609,7 +609,7 @@ end:
return(0);
err:
printf("Got error: %d when using heap-database\n",my_errno);
- VOID(heap_close(file));
+ (void) heap_close(file);
return(1);
} /* main */
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index 851957e53a5..a36fc3b981e 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -902,7 +902,7 @@ innobase_mysql_prepare_print_arbitrary_thd(void)
/*============================================*/
{
ut_ad(!mutex_own(&kernel_mutex));
- VOID(pthread_mutex_lock(&LOCK_thread_count));
+ pthread_mutex_lock(&LOCK_thread_count);
}
/*************************************************************//**
@@ -916,7 +916,7 @@ innobase_mysql_end_print_arbitrary_thd(void)
/*========================================*/
{
ut_ad(!mutex_own(&kernel_mutex));
- VOID(pthread_mutex_unlock(&LOCK_thread_count));
+ pthread_mutex_unlock(&LOCK_thread_count);
}
/*************************************************************//**
@@ -2046,13 +2046,6 @@ innobase_init(
ut_a(default_path);
- if (specialflag & SPECIAL_NO_PRIOR) {
- srv_set_thread_priorities = FALSE;
- } else {
- srv_set_thread_priorities = TRUE;
- srv_query_thread_priority = QUERY_PRIOR;
- }
-
/* Set InnoDB initialization parameters according to the values
read from MySQL .cnf file */
diff --git a/storage/innobase/include/srv0srv.h b/storage/innobase/include/srv0srv.h
index 23472bd100e..9804a3e7a85 100644
--- a/storage/innobase/include/srv0srv.h
+++ b/storage/innobase/include/srv0srv.h
@@ -207,9 +207,6 @@ extern unsigned long long srv_stats_sample_pages;
extern ibool srv_use_doublewrite_buf;
extern ibool srv_use_checksums;
-extern ibool srv_set_thread_priorities;
-extern int srv_query_thread_priority;
-
extern ulong srv_max_buf_pool_modified_pct;
extern ulong srv_max_purge_lag;
diff --git a/storage/innobase/os/os0thread.c b/storage/innobase/os/os0thread.c
index 9a2d95cb166..2cac26fa128 100644
--- a/storage/innobase/os/os0thread.c
+++ b/storage/innobase/os/os0thread.c
@@ -133,15 +133,6 @@ os_thread_create(
0, /* thread runs immediately */
&win_thread_id);
- if (srv_set_thread_priorities) {
-
- /* Set created thread priority the same as a normal query
- in MYSQL: we try to prevent starvation of threads by
- assigning same priority QUERY_PRIOR to all */
-
- ut_a(SetThreadPriority(thread, srv_query_thread_priority));
- }
-
if (thread_id) {
*thread_id = win_thread_id;
}
@@ -200,11 +191,6 @@ os_thread_create(
#ifndef UNIV_HPUX10
pthread_attr_destroy(&attr);
#endif
- if (srv_set_thread_priorities) {
-
- my_pthread_setprio(pthread, srv_query_thread_priority);
- }
-
if (thread_id) {
*thread_id = pthread;
}
diff --git a/storage/innobase/srv/srv0srv.c b/storage/innobase/srv/srv0srv.c
index d638b23692e..4722640af3f 100644
--- a/storage/innobase/srv/srv0srv.c
+++ b/storage/innobase/srv/srv0srv.c
@@ -369,9 +369,6 @@ UNIV_INTERN unsigned long long srv_stats_sample_pages = 8;
UNIV_INTERN ibool srv_use_doublewrite_buf = TRUE;
UNIV_INTERN ibool srv_use_checksums = TRUE;
-UNIV_INTERN ibool srv_set_thread_priorities = TRUE;
-UNIV_INTERN int srv_query_thread_priority = 0;
-
UNIV_INTERN ulong srv_replication_delay = 0;
/*-------------------------------------------*/
diff --git a/storage/myisam/CMakeLists.txt b/storage/myisam/CMakeLists.txt
index 829d89a798a..9a0aa06e861 100755
--- a/storage/myisam/CMakeLists.txt
+++ b/storage/myisam/CMakeLists.txt
@@ -26,7 +26,8 @@ SET(MYISAM_SOURCES ft_boolean_search.c ft_nlq_search.c ft_parser.c ft_static.c
mi_rfirst.c mi_rlast.c mi_rnext.c mi_rnext_same.c mi_rprev.c mi_rrnd.c
mi_rsame.c mi_rsamepos.c mi_scan.c mi_search.c mi_static.c mi_statrec.c
mi_unique.c mi_update.c mi_write.c rt_index.c rt_key.c rt_mbr.c
- rt_split.c sort.c sp_key.c ft_eval.h myisamdef.h rt_index.h mi_rkey.c)
+ rt_split.c sort.c sp_key.c ft_eval.h mi_extrafunc.h myisamdef.h
+ rt_index.h mi_rkey.c)
MYSQL_STORAGE_ENGINE(MYISAM)
diff --git a/storage/myisam/Makefile.am b/storage/myisam/Makefile.am
index 6dd0d2bcbdb..c659d05be40 100644
--- a/storage/myisam/Makefile.am
+++ b/storage/myisam/Makefile.am
@@ -50,7 +50,7 @@ myisampack_LDADD= @CLIENT_EXTRA_LDFLAGS@ libmyisam.a \
noinst_PROGRAMS = mi_test1 mi_test2 mi_test3 rt_test sp_test #ft_test1 ft_eval
noinst_HEADERS = myisamdef.h rt_index.h rt_key.h rt_mbr.h sp_defs.h \
fulltext.h ftdefs.h ft_test1.h ft_eval.h \
- ha_myisam.h
+ ha_myisam.h mi_extrafunc.h
mi_test1_DEPENDENCIES= $(LIBRARIES)
mi_test1_LDADD= @CLIENT_EXTRA_LDFLAGS@ libmyisam.a \
$(top_builddir)/mysys/libmysys.a \
diff --git a/storage/myisam/ft_eval.c b/storage/myisam/ft_eval.c
index de01510fdd7..f4faabe7919 100644
--- a/storage/myisam/ft_eval.c
+++ b/storage/myisam/ft_eval.c
@@ -236,8 +236,8 @@ static void print_error(int exit_code, const char *fmt,...)
va_start(args,fmt);
fprintf(stderr,"%s: error: ",my_progname);
- VOID(vfprintf(stderr, fmt, args));
- VOID(fputc('\n',stderr));
+ (void) vfprintf(stderr, fmt, args);
+ (void) fputc('\n',stderr);
fflush(stderr);
va_end(args);
exit(exit_code);
diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc
index 612d02bbcd3..c88fe737e0b 100644
--- a/storage/myisam/ha_myisam.cc
+++ b/storage/myisam/ha_myisam.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -118,7 +118,7 @@ static void mi_check_print_msg(MI_CHECK *param, const char* msg_type,
*/
#ifdef THREAD
if (param->need_print_msg_lock)
- pthread_mutex_lock(&param->print_msg_mutex);
+ mysql_mutex_lock(&param->print_msg_mutex);
#endif
protocol->prepare_for_resend();
protocol->store(name, length, system_charset_info);
@@ -130,7 +130,7 @@ static void mi_check_print_msg(MI_CHECK *param, const char* msg_type,
msgbuf);
#ifdef THREAD
if (param->need_print_msg_lock)
- pthread_mutex_unlock(&param->print_msg_mutex);
+ mysql_mutex_unlock(&param->print_msg_mutex);
#endif
return;
}
@@ -539,6 +539,45 @@ void mi_check_print_warning(MI_CHECK *param, const char *fmt,...)
va_end(args);
}
+
+/**
+ Report list of threads (and queries) accessing a table, thread_id of a
+ thread that detected corruption, ource file name and line number where
+ this corruption was detected, optional extra information (string).
+
+ This function is intended to be used when table corruption is detected.
+
+ @param[in] file MI_INFO object.
+ @param[in] message Optional error message.
+ @param[in] sfile Name of source file.
+ @param[in] sline Line number in source file.
+
+ @return void
+*/
+
+void _mi_report_crashed(MI_INFO *file, const char *message,
+ const char *sfile, uint sline)
+{
+ THD *cur_thd;
+ LIST *element;
+ char buf[1024];
+ mysql_mutex_lock(&file->s->intern_lock);
+ if ((cur_thd= (THD*) file->in_use.data))
+ sql_print_error("Got an error from thread_id=%lu, %s:%d", cur_thd->thread_id,
+ sfile, sline);
+ else
+ sql_print_error("Got an error from unknown thread, %s:%d", sfile, sline);
+ if (message)
+ sql_print_error("%s", message);
+ for (element= file->s->in_use; element; element= list_rest(element))
+ {
+ THD *thd= (THD*) element->data;
+ sql_print_error("%s", thd ? thd_security_context(thd, buf, sizeof(buf), 0)
+ : "Unknown thread accessing table");
+ }
+ mysql_mutex_unlock(&file->s->intern_lock);
+}
+
}
@@ -585,90 +624,6 @@ const char *ha_myisam::index_type(uint key_number)
"BTREE");
}
-#ifdef HAVE_REPLICATION
-int ha_myisam::net_read_dump(NET* net)
-{
- int data_fd = file->dfile;
- int error = 0;
-
- my_seek(data_fd, 0L, MY_SEEK_SET, MYF(MY_WME));
- for (;;)
- {
- ulong packet_len = my_net_read(net);
- if (!packet_len)
- break ; // end of file
- if (packet_len == packet_error)
- {
- sql_print_error("ha_myisam::net_read_dump - read error ");
- error= -1;
- goto err;
- }
- if (my_write(data_fd, (uchar*)net->read_pos, (uint) packet_len,
- MYF(MY_WME|MY_FNABP)))
- {
- error = errno;
- goto err;
- }
- }
-err:
- return error;
-}
-
-
-int ha_myisam::dump(THD* thd, int fd)
-{
- MYISAM_SHARE* share = file->s;
- NET* net = &thd->net;
- uint blocksize = share->blocksize;
- my_off_t bytes_to_read = share->state.state.data_file_length;
- int data_fd = file->dfile;
- uchar *buf = (uchar*) my_malloc(blocksize, MYF(MY_WME));
- if (!buf)
- return ENOMEM;
-
- int error = 0;
- my_seek(data_fd, 0L, MY_SEEK_SET, MYF(MY_WME));
- for (; bytes_to_read > 0;)
- {
- size_t bytes = my_read(data_fd, buf, blocksize, MYF(MY_WME));
- if (bytes == MY_FILE_ERROR)
- {
- error = errno;
- goto err;
- }
-
- if (fd >= 0)
- {
- if (my_write(fd, buf, bytes, MYF(MY_WME | MY_FNABP)))
- {
- error = errno ? errno : EPIPE;
- goto err;
- }
- }
- else
- {
- if (my_net_write(net, buf, bytes))
- {
- error = errno ? errno : EPIPE;
- goto err;
- }
- }
- bytes_to_read -= bytes;
- }
-
- if (fd < 0)
- {
- if (my_net_write(net, (uchar*) "", 0))
- error = errno ? errno : EPIPE;
- net_flush(net);
- }
-
-err:
- my_free((uchar*) buf, MYF(0));
- return error;
-}
-#endif /* HAVE_REPLICATION */
-
/* Name is here without an extension */
int ha_myisam::open(const char *name, int mode, uint test_if_locked)
@@ -721,11 +676,11 @@ int ha_myisam::open(const char *name, int mode, uint test_if_locked)
}
if (test_if_locked & (HA_OPEN_IGNORE_IF_LOCKED | HA_OPEN_TMP_TABLE))
- VOID(mi_extra(file, HA_EXTRA_NO_WAIT_LOCK, 0));
+ (void) mi_extra(file, HA_EXTRA_NO_WAIT_LOCK, 0);
info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
if (!(test_if_locked & HA_OPEN_WAIT_IF_LOCKED))
- VOID(mi_extra(file, HA_EXTRA_WAIT_LOCK, 0));
+ (void) mi_extra(file, HA_EXTRA_WAIT_LOCK, 0);
if (!table->s->db_record_offset)
int_table_flags|=HA_REC_NOT_IN_SEQ;
if (file->s->options & (HA_OPTION_CHECKSUM | HA_OPTION_COMPRESS_RECORD))
@@ -846,13 +801,13 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt)
mi_is_crashed(file))
{
file->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED;
- pthread_mutex_lock(&share->intern_lock);
+ mysql_mutex_lock(&share->intern_lock);
share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED |
STATE_CRASHED_ON_REPAIR);
if (!(table->db_stat & HA_READ_ONLY))
error=update_state_info(&param,file,UPDATE_TIME | UPDATE_OPEN_COUNT |
UPDATE_STAT);
- pthread_mutex_unlock(&share->intern_lock);
+ mysql_mutex_unlock(&share->intern_lock);
info(HA_STATUS_NO_LOCK | HA_STATUS_TIME | HA_STATUS_VARIABLE |
HA_STATUS_CONST);
}
@@ -896,9 +851,9 @@ int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt)
error = chk_key(&param, file);
if (!error)
{
- pthread_mutex_lock(&share->intern_lock);
+ mysql_mutex_lock(&share->intern_lock);
error=update_state_info(&param,file,UPDATE_STAT);
- pthread_mutex_unlock(&share->intern_lock);
+ mysql_mutex_unlock(&share->intern_lock);
}
else if (!mi_is_crashed(file) && !thd->killed)
mi_mark_crashed(file);
@@ -906,113 +861,6 @@ int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt)
}
-int ha_myisam::restore(THD* thd, HA_CHECK_OPT *check_opt)
-{
- HA_CHECK_OPT tmp_check_opt;
- char *backup_dir= thd->lex->backup_dir;
- char src_path[FN_REFLEN], dst_path[FN_REFLEN];
- char table_name[FN_REFLEN];
- int error;
- const char* errmsg;
- DBUG_ENTER("restore");
-
- VOID(tablename_to_filename(table->s->table_name.str, table_name,
- sizeof(table_name)));
-
- if (fn_format_relative_to_data_home(src_path, table_name, backup_dir,
- MI_NAME_DEXT))
- DBUG_RETURN(HA_ADMIN_INVALID);
-
- strxmov(dst_path, table->s->normalized_path.str, MI_NAME_DEXT, NullS);
- if (my_copy(src_path, dst_path, MYF(MY_WME)))
- {
- error= HA_ADMIN_FAILED;
- errmsg= "Failed in my_copy (Error %d)";
- goto err;
- }
-
- tmp_check_opt.init();
- tmp_check_opt.flags |= T_VERY_SILENT | T_CALC_CHECKSUM | T_QUICK;
- DBUG_RETURN(repair(thd, &tmp_check_opt));
-
- err:
- {
- MI_CHECK param;
- myisamchk_init(&param);
- param.thd= thd;
- param.op_name= "restore";
- param.db_name= table->s->db.str;
- param.table_name= table->s->table_name.str;
- param.testflag= 0;
- mi_check_print_error(&param, errmsg, my_errno);
- DBUG_RETURN(error);
- }
-}
-
-
-int ha_myisam::backup(THD* thd, HA_CHECK_OPT *check_opt)
-{
- char *backup_dir= thd->lex->backup_dir;
- char src_path[FN_REFLEN], dst_path[FN_REFLEN];
- char table_name[FN_REFLEN];
- int error;
- const char *errmsg;
- DBUG_ENTER("ha_myisam::backup");
-
- VOID(tablename_to_filename(table->s->table_name.str, table_name,
- sizeof(table_name)));
-
- if (fn_format_relative_to_data_home(dst_path, table_name, backup_dir,
- reg_ext))
- {
- errmsg= "Failed in fn_format() for .frm file (errno: %d)";
- error= HA_ADMIN_INVALID;
- goto err;
- }
-
- strxmov(src_path, table->s->normalized_path.str, reg_ext, NullS);
- if (my_copy(src_path, dst_path,
- MYF(MY_WME | MY_HOLD_ORIGINAL_MODES | MY_DONT_OVERWRITE_FILE)))
- {
- error = HA_ADMIN_FAILED;
- errmsg = "Failed copying .frm file (errno: %d)";
- goto err;
- }
-
- /* Change extension */
- if (fn_format_relative_to_data_home(dst_path, table_name, backup_dir,
- MI_NAME_DEXT))
- {
- errmsg = "Failed in fn_format() for .MYD file (errno: %d)";
- error = HA_ADMIN_INVALID;
- goto err;
- }
-
- strxmov(src_path, table->s->normalized_path.str, MI_NAME_DEXT, NullS);
- if (my_copy(src_path, dst_path,
- MYF(MY_WME | MY_HOLD_ORIGINAL_MODES | MY_DONT_OVERWRITE_FILE)))
- {
- errmsg = "Failed copying .MYD file (errno: %d)";
- error= HA_ADMIN_FAILED;
- goto err;
- }
- DBUG_RETURN(HA_ADMIN_OK);
-
- err:
- {
- MI_CHECK param;
- myisamchk_init(&param);
- param.thd= thd;
- param.op_name= "backup";
- param.db_name= table->s->db.str;
- param.table_name= table->s->table_name.str;
- param.testflag = 0;
- mi_check_print_error(&param,errmsg, my_errno);
- DBUG_RETURN(error);
- }
-}
-
-
int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt)
{
int error;
@@ -1109,7 +957,7 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param, bool do_optimize)
ha_release_temporary_latches(thd);
// Don't lock tables if we have used LOCK TABLE
- if (!thd->locked_tables &&
+ if (! thd->locked_tables_mode &&
mi_lock_database(file, table->s->tmp_table ? F_EXTRA_LCK : F_WRLCK))
{
mi_check_print_error(&param,ER(ER_CANT_LOCK),my_errno);
@@ -1219,7 +1067,7 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param, bool do_optimize)
update_state_info(&param, file, 0);
}
thd_proc_info(thd, old_proc_info);
- if (!thd->locked_tables)
+ if (! thd->locked_tables_mode)
mi_lock_database(file,F_UNLCK);
DBUG_RETURN(error ? HA_ADMIN_FAILED :
!optimize_done ? HA_ADMIN_ALREADY_DONE : HA_ADMIN_OK);
@@ -1812,7 +1660,7 @@ int ha_myisam::info(uint flag)
/* Update share */
if (share->tmp_table == NO_TMP_TABLE)
- pthread_mutex_lock(&share->mutex);
+ pthread_mutex_lock(&share->LOCK_ha_data);
share->keys_in_use.set_prefix(share->keys);
share->keys_in_use.intersect_extended(misam_info.key_map);
share->keys_for_keyread.intersect(share->keys_in_use);
@@ -1822,7 +1670,7 @@ int ha_myisam::info(uint flag)
(char*) misam_info.rec_per_key,
sizeof(table->key_info[0].rec_per_key[0])*share->key_parts);
if (share->tmp_table == NO_TMP_TABLE)
- pthread_mutex_unlock(&share->mutex);
+ pthread_mutex_unlock(&share->LOCK_ha_data);
/*
Set data_file_name and index_file_name to point at the symlink value
@@ -1894,6 +1742,7 @@ int ha_myisam::delete_table(const char *name)
int ha_myisam::external_lock(THD *thd, int lock_type)
{
+ file->in_use.data= thd;
return mi_lock_database(file, !table->s->tmp_table ?
lock_type : ((lock_type == F_UNLCK) ?
F_UNLCK : F_EXTRA_LCK));
@@ -2117,6 +1966,10 @@ static int myisam_init(void *p)
{
handlerton *myisam_hton;
+#ifdef HAVE_PSI_INTERFACE
+ init_myisam_psi_keys();
+#endif
+
myisam_hton= (handlerton *)p;
myisam_hton->state= SHOW_OPTION_YES;
myisam_hton->db_type= DB_TYPE_MYISAM;
diff --git a/storage/myisam/ha_myisam.h b/storage/myisam/ha_myisam.h
index 55a5eac92de..5bb46b03650 100644
--- a/storage/myisam/ha_myisam.h
+++ b/storage/myisam/ha_myisam.h
@@ -125,15 +125,9 @@ class ha_myisam: public handler
bool is_crashed() const;
bool auto_repair() const { return myisam_recover_options != 0; }
int optimize(THD* thd, HA_CHECK_OPT* check_opt);
- int restore(THD* thd, HA_CHECK_OPT* check_opt);
- int backup(THD* thd, HA_CHECK_OPT* check_opt);
int assign_to_keycache(THD* thd, HA_CHECK_OPT* check_opt);
int preload_keys(THD* thd, HA_CHECK_OPT* check_opt);
bool check_if_incompatible_data(HA_CREATE_INFO *info, uint table_changes);
-#ifdef HAVE_REPLICATION
- int dump(THD* thd, int fd);
- int net_read_dump(NET* net);
-#endif
#ifdef HAVE_QUERY_CACHE
my_bool register_query_cache_table(THD *thd, char *table_key,
uint key_length,
diff --git a/storage/myisam/mi_cache.c b/storage/myisam/mi_cache.c
index d6dcc431a8d..139a50a7c0d 100644
--- a/storage/myisam/mi_cache.c
+++ b/storage/myisam/mi_cache.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -29,7 +29,7 @@
is set) - unread part is bzero'ed
Note: out-of-cache reads are enabled for shared IO_CACHE's too,
- as these reads will be cached by OS cache (and my_pread is always atomic)
+ as these reads will be cached by OS cache (and mysql_file_pread is always atomic)
*/
@@ -49,7 +49,7 @@ int _mi_read_cache(IO_CACHE *info, uchar *buff, my_off_t pos, uint length,
if ((my_off_t) read_length > (my_off_t) (info->pos_in_file-pos))
read_length=(uint) (info->pos_in_file-pos);
info->seek_not_done=1;
- if (my_pread(info->file,buff,read_length,pos,MYF(MY_NABP)))
+ if (mysql_file_pread(info->file, buff, read_length, pos, MYF(MY_NABP)))
DBUG_RETURN(1);
if (!(length-=read_length))
DBUG_RETURN(0);
@@ -88,7 +88,8 @@ int _mi_read_cache(IO_CACHE *info, uchar *buff, my_off_t pos, uint length,
else
{
info->seek_not_done=1;
- if ((read_length=my_pread(info->file,buff,length,pos,MYF(0))) == length)
+ if ((read_length= mysql_file_pread(info->file, buff, length, pos,
+ MYF(0))) == length)
DBUG_RETURN(0);
}
if (!(flag & READING_HEADER) || (int) read_length == -1 ||
diff --git a/storage/myisam/mi_changed.c b/storage/myisam/mi_changed.c
index 7422f995dd0..049974e4a65 100644
--- a/storage/myisam/mi_changed.c
+++ b/storage/myisam/mi_changed.c
@@ -25,7 +25,7 @@ int mi_is_changed(MI_INFO *info)
DBUG_ENTER("mi_is_changed");
if (fast_mi_readinfo(info))
DBUG_RETURN(-1);
- VOID(_mi_writeinfo(info,0));
+ (void) _mi_writeinfo(info,0);
result=(int) info->data_changed;
info->data_changed=0;
DBUG_PRINT("exit",("result: %d",result));
diff --git a/storage/myisam/mi_check.c b/storage/myisam/mi_check.c
index c10cfdd0c9b..8e55a7bc50e 100644
--- a/storage/myisam/mi_check.c
+++ b/storage/myisam/mi_check.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -53,8 +53,8 @@
#include "rt_index.h"
#ifndef USE_RAID
-#define my_raid_create(A,B,C,D,E,F,G) my_create(A,B,C,G)
-#define my_raid_delete(A,B,C) my_delete(A,B)
+#define my_raid_create(K, A, B, C, D, E, F, G) mysql_file_create(K, A, B, C, G)
+#define my_raid_delete(K, A, B, C) mysql_file_delete(K, A, B)
#endif
/* Functions defined in this file */
@@ -175,8 +175,8 @@ int chk_del(MI_CHECK *param, register MI_INFO *info, uint test_flag)
printf(" %9s",llstr(next_link,buff));
if (next_link >= info->state->data_file_length)
goto wrong;
- if (my_pread(info->dfile, (uchar*) buff,delete_link_length,
- next_link,MYF(MY_NABP)))
+ if (mysql_file_pread(info->dfile, (uchar*) buff, delete_link_length,
+ next_link, MYF(MY_NABP)))
{
if (test_flag & T_VERBOSE) puts("");
mi_check_print_error(param,"Can't read delete-link at filepos: %s",
@@ -338,7 +338,7 @@ int chk_size(MI_CHECK *param, register MI_INFO *info)
flush_key_blocks(info->s->key_cache,
info->s->kfile, FLUSH_FORCE_WRITE);
- size= my_seek(info->s->kfile, 0L, MY_SEEK_END, MYF(MY_THREADSAFE));
+ size= mysql_file_seek(info->s->kfile, 0L, MY_SEEK_END, MYF(MY_THREADSAFE));
if ((skr=(my_off_t) info->state->key_file_length) != size)
{
/* Don't give error if file generated by myisampack */
@@ -362,7 +362,7 @@ int chk_size(MI_CHECK *param, register MI_INFO *info)
llstr(info->state->key_file_length,buff),
llstr(info->s->base.max_key_file_length-1,buff));
- size=my_seek(info->dfile,0L,MY_SEEK_END,MYF(0));
+ size= mysql_file_seek(info->dfile, 0L, MY_SEEK_END, MYF(0));
skr=(my_off_t) info->state->data_file_length;
if (info->s->options & HA_OPTION_COMPRESS_RECORD)
skr+= MEMMAP_EXTRA_MARGIN;
@@ -598,8 +598,8 @@ static int chk_index_down(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo,
{
/* purecov: begin tested */
/* Give it a chance to fit in the real file size. */
- my_off_t max_length= my_seek(info->s->kfile, 0L, MY_SEEK_END,
- MYF(MY_THREADSAFE));
+ my_off_t max_length= mysql_file_seek(info->s->kfile, 0L, MY_SEEK_END,
+ MYF(MY_THREADSAFE));
mi_check_print_error(param, "Invalid key block position: %s "
"key block size: %u file_length: %s",
llstr(page, llbuff), keyinfo->block_length,
@@ -1184,8 +1184,8 @@ int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend)
goto err;
start_recpos=pos;
splits++;
- VOID(_mi_pack_get_block_info(info, &info->bit_buff, &block_info,
- &info->rec_buff, -1, start_recpos));
+ (void) _mi_pack_get_block_info(info, &info->bit_buff, &block_info,
+ &info->rec_buff, -1, start_recpos);
pos=block_info.filepos+block_info.rec_len;
if (block_info.rec_len < (uint) info->s->min_pack_length ||
block_info.rec_len > (uint) info->s->max_pack_length)
@@ -1222,7 +1222,7 @@ int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend)
records++;
if (param->testflag & T_WRITE_LOOP && records % WRITE_COUNT == 0)
{
- printf("%s\r", llstr(records,llbuff)); VOID(fflush(stdout));
+ printf("%s\r", llstr(records,llbuff)); (void) fflush(stdout);
}
/* Check if keys match the record */
@@ -1275,7 +1275,7 @@ int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend)
}
if (param->testflag & T_WRITE_LOOP)
{
- VOID(fputs(" \r",stdout)); VOID(fflush(stdout));
+ (void) fputs(" \r",stdout); (void) fflush(stdout);
}
if (records != info->state->records)
{
@@ -1551,8 +1551,8 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info,
DBUG_ASSERT(param->use_buffers < SIZE_T_MAX);
if (!param->using_global_keycache)
- VOID(init_key_cache(dflt_key_cache, param->key_cache_block_size,
- (size_t) param->use_buffers, 0, 0));
+ (void) init_key_cache(dflt_key_cache, param->key_cache_block_size,
+ param->use_buffers, 0, 0);
if (init_io_cache(&param->read_cache,info->dfile,
(uint) param->read_buffer_length,
@@ -1577,14 +1577,15 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info,
if (!rep_quick)
{
/* Get real path for data file */
- if ((new_file=my_raid_create(fn_format(param->temp_filename,
- share->data_file_name, "",
- DATA_TMP_EXT, 2+4),
- 0,param->tmpfile_createflag,
- share->base.raid_type,
- share->base.raid_chunks,
- share->base.raid_chunksize,
- MYF(0))) < 0)
+ if ((new_file= my_raid_create(mi_key_file_datatmp,
+ fn_format(param->temp_filename,
+ share->data_file_name, "",
+ DATA_TMP_EXT, 2+4),
+ 0, param->tmpfile_createflag,
+ share->base.raid_type,
+ share->base.raid_chunks,
+ share->base.raid_chunksize,
+ MYF(0))) < 0)
{
mi_check_print_error(param,"Can't create new tempfile: '%s'",
param->temp_filename);
@@ -1608,7 +1609,7 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info,
sort_param.pos=sort_param.max_pos=share->pack.header_length;
sort_param.filepos=new_header_length;
param->read_cache.end_of_file=sort_info.filelength=
- my_seek(info->dfile,0L,MY_SEEK_END,MYF(0));
+ mysql_file_seek(info->dfile, 0L, MY_SEEK_END, MYF(0));
sort_info.dupp=0;
sort_param.fix_datafile= (my_bool) (! rep_quick);
sort_param.master=1;
@@ -1645,8 +1646,8 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info,
llstr(info->dupp_key_pos,llbuff2));
if (param->testflag & T_VERBOSE)
{
- VOID(_mi_make_key(info,(uint) info->errkey,info->lastkey,
- sort_param.record,0L));
+ (void) _mi_make_key(info,(uint) info->errkey,info->lastkey,
+ sort_param.record,0L);
_mi_print_key(stdout,share->keyinfo[info->errkey].seg,info->lastkey,
USE_WHOLE_KEY);
}
@@ -1668,9 +1669,9 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info,
if (param->testflag & T_WRITE_LOOP)
{
- VOID(fputs(" \r",stdout)); VOID(fflush(stdout));
+ (void) fputs(" \r",stdout); (void) fflush(stdout);
}
- if (my_chsize(share->kfile,info->state->key_file_length,0,MYF(0)))
+ if (mysql_file_chsize(share->kfile, info->state->key_file_length, 0, MYF(0)))
{
mi_check_print_warning(param,
"Can't change size of indexfile, error: %d",
@@ -1700,7 +1701,7 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info,
if (!rep_quick)
{
- my_close(info->dfile,MYF(0));
+ mysql_file_close(info->dfile, MYF(0));
info->dfile=new_file;
info->state->data_file_length=sort_param.filepos;
share->state.version=(ulong) time((time_t*) 0); /* Force reopen */
@@ -1733,7 +1734,7 @@ err:
/* Replace the actual file with the temporary file */
if (new_file >= 0)
{
- my_close(new_file,MYF(0));
+ mysql_file_close(new_file, MYF(0));
info->dfile=new_file= -1;
if (change_to_newfile(share->data_file_name,MI_NAME_DEXT,
DATA_TMP_EXT, share->base.raid_chunks,
@@ -1750,9 +1751,10 @@ err:
llstr(sort_param.start_recpos,llbuff));
if (new_file >= 0)
{
- VOID(my_close(new_file,MYF(0)));
- VOID(my_raid_delete(param->temp_filename,info->s->base.raid_chunks,
- MYF(MY_WME)));
+ (void) mysql_file_close(new_file, MYF(0));
+ (void) my_raid_delete(mi_key_file_datatmp,
+ param->temp_filename, info->s->base.raid_chunks,
+ MYF(MY_WME));
info->rec_cache.file=-1; /* don't flush data to new_file, it's closed */
}
mi_mark_crashed_on_repair(info);
@@ -1762,9 +1764,9 @@ err:
my_free(mi_get_rec_buff_ptr(info, sort_param.record),
MYF(MY_ALLOW_ZERO_PTR));
my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR));
- VOID(end_io_cache(&param->read_cache));
+ (void) end_io_cache(&param->read_cache);
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
- VOID(end_io_cache(&info->rec_cache));
+ (void) end_io_cache(&info->rec_cache);
got_error|=flush_blocks(param, share->key_cache, share->kfile);
if (!got_error && param->testflag & T_UNPACK)
{
@@ -1949,9 +1951,11 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name)
/* Get real path for index file */
fn_format(param->temp_filename,name,"", MI_NAME_IEXT,2+4+32);
- if ((new_file=my_create(fn_format(param->temp_filename,param->temp_filename,
- "", INDEX_TMP_EXT,2+4),
- 0,param->tmpfile_createflag,MYF(0))) <= 0)
+ if ((new_file= mysql_file_create(mi_key_file_datatmp,
+ fn_format(param->temp_filename,
+ param->temp_filename,
+ "", INDEX_TMP_EXT, 2+4),
+ 0, param->tmpfile_createflag, MYF(0))) <= 0)
{
mi_check_print_error(param,"Can't create new tempfile: '%s'",
param->temp_filename);
@@ -1991,9 +1995,9 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name)
/* Put same locks as old file */
share->r_locks= share->w_locks= share->tot_locks= 0;
(void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
- VOID(my_close(share->kfile,MYF(MY_WME)));
+ (void) mysql_file_close(share->kfile, MYF(MY_WME));
share->kfile = -1;
- VOID(my_close(new_file,MYF(MY_WME)));
+ (void) mysql_file_close(new_file, MYF(MY_WME));
if (change_to_newfile(share->index_file_name,MI_NAME_IEXT,INDEX_TMP_EXT,0,
MYF(0)) ||
mi_open_keyfile(share))
@@ -2017,9 +2021,10 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name)
DBUG_RETURN(0);
err:
- VOID(my_close(new_file,MYF(MY_WME)));
+ (void) mysql_file_close(new_file, MYF(MY_WME));
err2:
- VOID(my_delete(param->temp_filename,MYF(MY_WME)));
+ (void) mysql_file_delete(mi_key_file_datatmp,
+ param->temp_filename, MYF(MY_WME));
DBUG_RETURN(-1);
} /* mi_sort_index */
@@ -2099,8 +2104,8 @@ static int sort_one_index(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo,
/* Fill block with zero and write it to the new index file */
length=mi_getint(buff);
bzero((uchar*) buff+length,keyinfo->block_length-length);
- if (my_pwrite(new_file,(uchar*) buff,(uint) keyinfo->block_length,
- new_page_pos,MYF(MY_NABP | MY_WAIT_IF_FULL)))
+ if (mysql_file_pwrite(new_file, (uchar*) buff, (uint) keyinfo->block_length,
+ new_page_pos, MYF(MY_NABP | MY_WAIT_IF_FULL)))
{
mi_check_print_error(param,"Can't write indexblock, error: %d",my_errno);
goto err;
@@ -2176,16 +2181,16 @@ int filecopy(MI_CHECK *param, File to,File from,my_off_t start,
buff=tmp_buff; buff_length=IO_SIZE;
}
- VOID(my_seek(from,start,MY_SEEK_SET,MYF(0)));
+ mysql_file_seek(from, start, MY_SEEK_SET, MYF(0));
while (length > buff_length)
{
- if (my_read(from,(uchar*) buff,buff_length,MYF(MY_NABP)) ||
- my_write(to,(uchar*) buff,buff_length,param->myf_rw))
+ if (mysql_file_read(from, (uchar*) buff, buff_length, MYF(MY_NABP)) ||
+ mysql_file_write(to, (uchar*) buff, buff_length, param->myf_rw))
goto err;
length-= buff_length;
}
- if (my_read(from,(uchar*) buff,(uint) length,MYF(MY_NABP)) ||
- my_write(to,(uchar*) buff,(uint) length,param->myf_rw))
+ if (mysql_file_read(from, (uchar*) buff, (uint) length, MYF(MY_NABP)) ||
+ mysql_file_write(to, (uchar*) buff, (uint) length, param->myf_rw))
goto err;
if (buff != tmp_buff)
my_free(buff,MYF(0));
@@ -2275,14 +2280,15 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
if (!rep_quick)
{
/* Get real path for data file */
- if ((new_file=my_raid_create(fn_format(param->temp_filename,
- share->data_file_name, "",
- DATA_TMP_EXT, 2+4),
- 0,param->tmpfile_createflag,
- share->base.raid_type,
- share->base.raid_chunks,
- share->base.raid_chunksize,
- MYF(0))) < 0)
+ if ((new_file= my_raid_create(mi_key_file_datatmp,
+ fn_format(param->temp_filename,
+ share->data_file_name, "",
+ DATA_TMP_EXT, 2+4),
+ 0, param->tmpfile_createflag,
+ share->base.raid_type,
+ share->base.raid_chunks,
+ share->base.raid_chunksize,
+ MYF(0))) < 0)
{
mi_check_print_error(param,"Can't create new tempfile: '%s'",
param->temp_filename);
@@ -2320,7 +2326,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
sort_info.dupp=0;
sort_info.buff=0;
param->read_cache.end_of_file=sort_info.filelength=
- my_seek(param->read_cache.file,0L,MY_SEEK_END,MYF(0));
+ mysql_file_seek(param->read_cache.file, 0L, MY_SEEK_END, MYF(0));
sort_param.wordlist=NULL;
init_alloc_root(&sort_param.wordroot, FTPARSER_MEMROOT_ALLOC_SIZE, 0);
@@ -2470,7 +2476,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
sort_param.filepos;
/* Only whole records */
share->state.version=(ulong) time((time_t*) 0);
- my_close(info->dfile,MYF(0));
+ mysql_file_close(info->dfile, MYF(0));
info->dfile=new_file;
share->data_file_type=sort_info.new_data_file_type;
share->pack.header_length=(ulong) new_header_length;
@@ -2486,7 +2492,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
if (param->testflag & T_WRITE_LOOP)
{
- VOID(fputs(" \r",stdout)); VOID(fflush(stdout));
+ (void) fputs(" \r",stdout); (void) fflush(stdout);
}
if (rep_quick && del+sort_info.dupp != info->state->del)
@@ -2510,7 +2516,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
skr=share->base.reloc*share->base.min_pack_length;
#endif
if (skr != sort_info.filelength && !info->s->base.raid_type)
- if (my_chsize(info->dfile,skr,0,MYF(0)))
+ if (mysql_file_chsize(info->dfile, skr, 0, MYF(0)))
mi_check_print_warning(param,
"Can't change size of datafile, error: %d",
my_errno);
@@ -2518,7 +2524,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
if (param->testflag & T_CALC_CHECKSUM)
info->state->checksum=param->glob_crc;
- if (my_chsize(share->kfile,info->state->key_file_length,0,MYF(0)))
+ if (mysql_file_chsize(share->kfile, info->state->key_file_length, 0, MYF(0)))
mi_check_print_warning(param,
"Can't change size of indexfile, error: %d",
my_errno);
@@ -2539,13 +2545,13 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
err:
got_error|= flush_blocks(param, share->key_cache, share->kfile);
- VOID(end_io_cache(&info->rec_cache));
+ (void) end_io_cache(&info->rec_cache);
if (!got_error)
{
/* Replace the actual file with the temporary file */
if (new_file >= 0)
{
- my_close(new_file,MYF(0));
+ mysql_file_close(new_file, MYF(0));
info->dfile=new_file= -1;
if (change_to_newfile(share->data_file_name,MI_NAME_DEXT,
DATA_TMP_EXT, share->base.raid_chunks,
@@ -2561,9 +2567,10 @@ err:
mi_check_print_error(param,"%d when fixing table",my_errno);
if (new_file >= 0)
{
- VOID(my_close(new_file,MYF(0)));
- VOID(my_raid_delete(param->temp_filename,share->base.raid_chunks,
- MYF(MY_WME)));
+ (void) mysql_file_close(new_file, MYF(0));
+ (void) my_raid_delete(mi_key_file_datatmp,
+ param->temp_filename, share->base.raid_chunks,
+ MYF(MY_WME));
if (info->dfile == new_file) /* Retry with key cache */
if (unlikely(mi_open_datafile(info, share, name, -1)))
param->retry_repair= 0; /* Safety */
@@ -2581,7 +2588,7 @@ err:
my_free((uchar*) sort_info.key_block,MYF(MY_ALLOW_ZERO_PTR));
my_free((uchar*) sort_info.ft_buf, MYF(MY_ALLOW_ZERO_PTR));
my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR));
- VOID(end_io_cache(&param->read_cache));
+ (void) end_io_cache(&param->read_cache);
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
if (!got_error && (param->testflag & T_UNPACK))
{
@@ -2704,9 +2711,11 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
DBUG_PRINT("info", ("is quick repair: %d", rep_quick));
bzero((char*)&sort_info,sizeof(sort_info));
/* Initialize pthread structures before goto err. */
- pthread_mutex_init(&sort_info.mutex, MY_MUTEX_INIT_FAST);
- pthread_cond_init(&sort_info.cond, 0);
- pthread_mutex_init(&param->print_msg_mutex, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(mi_key_mutex_MI_SORT_INFO_mutex,
+ &sort_info.mutex, MY_MUTEX_INIT_FAST);
+ mysql_cond_init(mi_key_cond_MI_SORT_INFO_cond, &sort_info.cond, 0);
+ mysql_mutex_init(mi_key_mutex_MI_CHECK_print_msg,
+ &param->print_msg_mutex, MY_MUTEX_INIT_FAST);
param->need_print_msg_lock= 1;
if (!(sort_info.key_block=
@@ -2732,15 +2741,16 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
if (!rep_quick)
{
/* Get real path for data file */
- if ((new_file=my_raid_create(fn_format(param->temp_filename,
- share->data_file_name, "",
- DATA_TMP_EXT,
- 2+4),
- 0,param->tmpfile_createflag,
- share->base.raid_type,
- share->base.raid_chunks,
- share->base.raid_chunksize,
- MYF(0))) < 0)
+ if ((new_file= my_raid_create(mi_key_file_datatmp,
+ fn_format(param->temp_filename,
+ share->data_file_name, "",
+ DATA_TMP_EXT,
+ 2+4),
+ 0, param->tmpfile_createflag,
+ share->base.raid_type,
+ share->base.raid_chunks,
+ share->base.raid_chunksize,
+ MYF(0))) < 0)
{
mi_check_print_error(param,"Can't create new tempfile: '%s'",
param->temp_filename);
@@ -2777,7 +2787,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
sort_info.dupp=0;
sort_info.buff=0;
param->read_cache.end_of_file=sort_info.filelength=
- my_seek(param->read_cache.file,0L,MY_SEEK_END,MYF(0));
+ mysql_file_seek(param->read_cache.file, 0L, MY_SEEK_END, MYF(0));
if (share->data_file_type == DYNAMIC_RECORD)
rec_length=max(share->base.min_pack_length+1,share->base.min_block_length);
@@ -2903,7 +2913,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
goto err;
sort_info.got_error=0;
- pthread_mutex_lock(&sort_info.mutex);
+ mysql_mutex_lock(&sort_info.mutex);
/*
Initialize the I/O cache share for use with the read caches and, in
@@ -2951,9 +2961,10 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
#else
param->sort_buffer_length*sort_param[i].key_length/total_key_length;
#endif
- if (pthread_create(&sort_param[i].thr, &thr_attr,
- thr_find_all_keys,
- (void *) (sort_param+i)))
+ if (mysql_thread_create(mi_key_thread_find_all_keys,
+ &sort_param[i].thr, &thr_attr,
+ thr_find_all_keys,
+ (void *) (sort_param+i)))
{
mi_check_print_error(param,"Cannot start a repair thread");
/* Cleanup: Detach from the share. Avoid others to be blocked. */
@@ -2969,8 +2980,8 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
/* waiting for all threads to finish */
while (sort_info.threads_running)
- pthread_cond_wait(&sort_info.cond, &sort_info.mutex);
- pthread_mutex_unlock(&sort_info.mutex);
+ mysql_cond_wait(&sort_info.cond, &sort_info.mutex);
+ mysql_mutex_unlock(&sort_info.mutex);
if ((got_error= thr_write_keys(sort_param)))
{
@@ -3006,7 +3017,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
Exchange the data file descriptor of the table, so that we use the
new file from now on.
*/
- my_close(info->dfile,MYF(0));
+ mysql_file_close(info->dfile, MYF(0));
info->dfile=new_file;
share->data_file_type=sort_info.new_data_file_type;
@@ -3035,7 +3046,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
skr=share->base.reloc*share->base.min_pack_length;
#endif
if (skr != sort_info.filelength && !info->s->base.raid_type)
- if (my_chsize(info->dfile,skr,0,MYF(0)))
+ if (mysql_file_chsize(info->dfile, skr, 0, MYF(0)))
mi_check_print_warning(param,
"Can't change size of datafile, error: %d",
my_errno);
@@ -3043,7 +3054,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
if (param->testflag & T_CALC_CHECKSUM)
info->state->checksum=param->glob_crc;
- if (my_chsize(share->kfile,info->state->key_file_length,0,MYF(0)))
+ if (mysql_file_chsize(share->kfile, info->state->key_file_length, 0, MYF(0)))
mi_check_print_warning(param,
"Can't change size of indexfile, error: %d", my_errno);
@@ -3068,7 +3079,7 @@ err:
the share by remove_io_thread() or it was not yet started (if the
error happend before creating the thread).
*/
- VOID(end_io_cache(&info->rec_cache));
+ (void) end_io_cache(&info->rec_cache);
/*
Destroy the new data cache in case of non-quick repair. All slave
threads did either detach from the share by remove_io_thread()
@@ -3076,13 +3087,13 @@ err:
creating the threads).
*/
if (!rep_quick)
- VOID(end_io_cache(&new_data_cache));
+ (void) end_io_cache(&new_data_cache);
if (!got_error)
{
/* Replace the actual file with the temporary file */
if (new_file >= 0)
{
- my_close(new_file,MYF(0));
+ mysql_file_close(new_file, MYF(0));
info->dfile=new_file= -1;
if (change_to_newfile(share->data_file_name,MI_NAME_DEXT,
DATA_TMP_EXT, share->base.raid_chunks,
@@ -3098,9 +3109,10 @@ err:
mi_check_print_error(param,"%d when fixing table",my_errno);
if (new_file >= 0)
{
- VOID(my_close(new_file,MYF(0)));
- VOID(my_raid_delete(param->temp_filename,share->base.raid_chunks,
- MYF(MY_WME)));
+ (void) mysql_file_close(new_file, MYF(0));
+ (void) my_raid_delete(mi_key_file_datatmp,
+ param->temp_filename, share->base.raid_chunks,
+ MYF(MY_WME));
if (info->dfile == new_file) /* Retry with key cache */
if (unlikely(mi_open_datafile(info, share, name, -1)))
param->retry_repair= 0; /* Safety */
@@ -3111,16 +3123,16 @@ err:
share->state.changed&= ~STATE_NOT_OPTIMIZED_KEYS;
share->state.changed|=STATE_NOT_SORTED_PAGES;
- pthread_cond_destroy (&sort_info.cond);
- pthread_mutex_destroy(&sort_info.mutex);
- pthread_mutex_destroy(&param->print_msg_mutex);
+ mysql_cond_destroy(&sort_info.cond);
+ mysql_mutex_destroy(&sort_info.mutex);
+ mysql_mutex_destroy(&param->print_msg_mutex);
param->need_print_msg_lock= 0;
my_free((uchar*) sort_info.ft_buf, MYF(MY_ALLOW_ZERO_PTR));
my_free((uchar*) sort_info.key_block,MYF(MY_ALLOW_ZERO_PTR));
my_free((uchar*) sort_param,MYF(MY_ALLOW_ZERO_PTR));
my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR));
- VOID(end_io_cache(&param->read_cache));
+ (void) end_io_cache(&param->read_cache);
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
if (!got_error && (param->testflag & T_UNPACK))
{
@@ -3774,7 +3786,7 @@ int sort_write_record(MI_SORT_PARAM *sort_param)
{
char llbuff[22];
printf("%s\r", llstr(info->state->records,llbuff));
- VOID(fflush(stdout));
+ (void) fflush(stdout);
}
}
DBUG_RETURN(0);
@@ -4048,7 +4060,7 @@ static int sort_insert_key(MI_SORT_PARAM *sort_param,
key_block->end_pos+=t_length;
if (a_length <= keyinfo->block_length)
{
- VOID(_mi_move_key(keyinfo,key_block->lastkey,key));
+ (void) _mi_move_key(keyinfo,key_block->lastkey,key);
key_block->last_length=a_length-t_length;
DBUG_RETURN(0);
}
@@ -4067,8 +4079,9 @@ static int sort_insert_key(MI_SORT_PARAM *sort_param,
if (_mi_write_keypage(info, keyinfo, filepos, DFLT_INIT_HITS, anc_buff))
DBUG_RETURN(1);
}
- else if (my_pwrite(info->s->kfile,(uchar*) anc_buff,
- (uint) keyinfo->block_length,filepos, param->myf_rw))
+ else if (mysql_file_pwrite(info->s->kfile, (uchar*) anc_buff,
+ (uint) keyinfo->block_length, filepos,
+ param->myf_rw))
DBUG_RETURN(1);
DBUG_DUMP("buff",(uchar*) anc_buff,mi_getint(anc_buff));
@@ -4172,8 +4185,8 @@ int flush_pending_blocks(MI_SORT_PARAM *sort_param)
DFLT_INIT_HITS, key_block->buff))
DBUG_RETURN(1);
}
- else if (my_pwrite(info->s->kfile,(uchar*) key_block->buff,
- (uint) keyinfo->block_length,filepos, myf_rw))
+ else if (mysql_file_pwrite(info->s->kfile, (uchar*) key_block->buff,
+ (uint) keyinfo->block_length, filepos, myf_rw))
DBUG_RETURN(1);
DBUG_DUMP("buff",(uchar*) key_block->buff,length);
nod_flag=1;
@@ -4213,9 +4226,11 @@ int test_if_almost_full(MI_INFO *info)
{
if (info->s->options & HA_OPTION_COMPRESS_RECORD)
return 0;
- return my_seek(info->s->kfile, 0L, MY_SEEK_END, MYF(MY_THREADSAFE)) / 10 * 9 >
+ return mysql_file_seek(info->s->kfile, 0L, MY_SEEK_END,
+ MYF(MY_THREADSAFE)) / 10 * 9 >
(my_off_t) info->s->base.max_key_file_length ||
- my_seek(info->dfile, 0L, MY_SEEK_END, MYF(0)) / 10 * 9 >
+ mysql_file_seek(info->dfile, 0L, MY_SEEK_END,
+ MYF(0)) / 10 * 9 >
(my_off_t) info->s->base.max_data_file_length;
}
@@ -4313,7 +4328,8 @@ int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename)
if (share.options & HA_OPTION_COMPRESS_RECORD)
share.base.records=max_records=info.state->records;
else if (share.base.min_pack_length)
- max_records=(ha_rows) (my_seek(info.dfile,0L,MY_SEEK_END,MYF(0)) /
+ max_records=(ha_rows) (mysql_file_seek(info.dfile, 0L, MY_SEEK_END,
+ MYF(0)) /
(ulong) share.base.min_pack_length);
else
max_records=0;
@@ -4321,13 +4337,13 @@ int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename)
(param->testflag & T_UNPACK);
share.options&= ~HA_OPTION_TEMP_COMPRESS_RECORD;
- file_length=(ulonglong) my_seek(info.dfile,0L,MY_SEEK_END,MYF(0));
+ file_length=(ulonglong) mysql_file_seek(info.dfile, 0L, MY_SEEK_END, MYF(0));
tmp_length= file_length+file_length/10;
set_if_bigger(file_length,param->max_data_file_length);
set_if_bigger(file_length,tmp_length);
set_if_bigger(file_length,(ulonglong) share.base.max_data_file_length);
- VOID(mi_close(*org_info));
+ (void) mi_close(*org_info);
bzero((char*) &create_info,sizeof(create_info));
create_info.max_rows=max(max_records,share.base.records);
create_info.reloc_rows=share.base.reloc;
@@ -4368,7 +4384,7 @@ int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename)
}
/* We are modifing */
(*org_info)->s->options&= ~HA_OPTION_READ_ONLY_DATA;
- VOID(_mi_readinfo(*org_info,F_WRLCK,0));
+ (void) _mi_readinfo(*org_info,F_WRLCK,0);
(*org_info)->state->records=info.state->records;
if (share.state.create_time)
(*org_info)->s->state.create_time=share.state.create_time;
diff --git a/storage/myisam/mi_close.c b/storage/myisam/mi_close.c
index 2066d092e1f..8ec0bf14e0a 100644
--- a/storage/myisam/mi_close.c
+++ b/storage/myisam/mi_close.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2004 MySQL AB
+/* Copyright (C) 2000-2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -31,7 +31,7 @@ int mi_close(register MI_INFO *info)
(long) info, (uint) share->reopen,
(uint) share->tot_locks));
- pthread_mutex_lock(&THR_LOCK_myisam);
+ mysql_mutex_lock(&THR_LOCK_myisam);
if (info->lock_type == F_EXTRA_LCK)
info->lock_type=F_UNLCK; /* HA_EXTRA_NO_USER_CHANGE */
@@ -40,7 +40,7 @@ int mi_close(register MI_INFO *info)
if (mi_lock_database(info,F_UNLCK))
error=my_errno;
}
- pthread_mutex_lock(&share->intern_lock);
+ mysql_mutex_lock(&share->intern_lock);
if (share->options & HA_OPTION_READ_ONLY_DATA)
{
@@ -55,7 +55,7 @@ int mi_close(register MI_INFO *info)
}
flag= !--share->reopen;
myisam_open_list=list_delete(myisam_open_list,&info->open_list);
- pthread_mutex_unlock(&share->intern_lock);
+ mysql_mutex_unlock(&share->intern_lock);
my_free(mi_get_rec_buff_ptr(info, info->rec_buff), MYF(MY_ALLOW_ZERO_PTR));
if (flag)
@@ -79,7 +79,7 @@ int mi_close(register MI_INFO *info)
mi_state_info_write(share->kfile, &share->state, 1);
/* Decrement open count must be last I/O on this file. */
_mi_decrement_open_count(info);
- if (my_close(share->kfile,MYF(0)))
+ if (mysql_file_close(share->kfile, MYF(0)))
error = my_errno;
}
#ifdef HAVE_MMAP
@@ -93,25 +93,25 @@ int mi_close(register MI_INFO *info)
}
#ifdef THREAD
thr_lock_delete(&share->lock);
- VOID(pthread_mutex_destroy(&share->intern_lock));
+ mysql_mutex_destroy(&share->intern_lock);
{
int i,keys;
keys = share->state.header.keys;
- VOID(rwlock_destroy(&share->mmap_lock));
+ mysql_rwlock_destroy(&share->mmap_lock);
for(i=0; i<keys; i++) {
- VOID(rwlock_destroy(&share->key_root_lock[i]));
+ mysql_rwlock_destroy(&share->key_root_lock[i]);
}
}
#endif
my_free((uchar*) info->s,MYF(0));
}
- pthread_mutex_unlock(&THR_LOCK_myisam);
+ mysql_mutex_unlock(&THR_LOCK_myisam);
if (info->ftparser_param)
{
my_free((uchar*)info->ftparser_param, MYF(0));
info->ftparser_param= 0;
}
- if (info->dfile >= 0 && my_close(info->dfile,MYF(0)))
+ if (info->dfile >= 0 && mysql_file_close(info->dfile, MYF(0)))
error = my_errno;
myisam_log_command(MI_LOG_CLOSE,info,NULL,0,error);
diff --git a/storage/myisam/mi_create.c b/storage/myisam/mi_create.c
index 0b4d781379c..66d5d4fa3cd 100644
--- a/storage/myisam/mi_create.c
+++ b/storage/myisam/mi_create.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -572,7 +572,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
if (! (flags & HA_DONT_TOUCH_DATA))
share.state.create_time= (long) time((time_t*) 0);
- pthread_mutex_lock(&THR_LOCK_myisam);
+ mysql_mutex_lock(&THR_LOCK_myisam);
/*
NOTE: For test_if_reopen() we need a real path name. Hence we need
@@ -638,8 +638,10 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
goto err;
}
- if ((file= my_create_with_symlink(linkname_ptr, filename, 0, create_mode,
- MYF(MY_WME | create_flag))) < 0)
+ if ((file= mysql_file_create_with_symlink(mi_key_file_kfile,
+ linkname_ptr, filename, 0,
+ create_mode,
+ MYF(MY_WME | create_flag))) < 0)
goto err;
errpos=1;
@@ -694,8 +696,10 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
create_flag=(flags & HA_CREATE_KEEP_FILES) ? 0 : MY_DELETE_OLD;
}
if ((dfile=
- my_create_with_symlink(linkname_ptr, filename, 0, create_mode,
- MYF(MY_WME | create_flag))) < 0)
+ mysql_file_create_with_symlink(mi_key_file_dfile,
+ linkname_ptr, filename, 0,
+ create_mode,
+ MYF(MY_WME | create_flag))) < 0)
goto err;
}
errpos=3;
@@ -706,9 +710,9 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
mi_base_info_write(file, &share.base))
goto err;
#ifndef DBUG_OFF
- if ((uint) my_tell(file,MYF(0)) != base_pos+ MI_BASE_INFO_SIZE)
+ if ((uint) mysql_file_tell(file, MYF(0)) != base_pos + MI_BASE_INFO_SIZE)
{
- uint pos=(uint) my_tell(file,MYF(0));
+ uint pos=(uint) mysql_file_tell(file, MYF(0));
DBUG_PRINT("warning",("base_length: %d != used_length: %d",
base_pos+ MI_BASE_INFO_SIZE, pos));
}
@@ -803,9 +807,9 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
goto err;
#ifndef DBUG_OFF
- if ((uint) my_tell(file,MYF(0)) != info_length)
+ if ((uint) mysql_file_tell(file, MYF(0)) != info_length)
{
- uint pos= (uint) my_tell(file,MYF(0));
+ uint pos= (uint) mysql_file_tell(file, MYF(0));
DBUG_PRINT("warning",("info_length: %d != used_length: %d",
info_length, pos));
}
@@ -813,46 +817,49 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
/* Enlarge files */
DBUG_PRINT("info", ("enlarge to keystart: %lu", (ulong) share.base.keystart));
- if (my_chsize(file,(ulong) share.base.keystart,0,MYF(0)))
+ if (mysql_file_chsize(file, (ulong) share.base.keystart, 0, MYF(0)))
goto err;
if (! (flags & HA_DONT_TOUCH_DATA))
{
#ifdef USE_RELOC
- if (my_chsize(dfile,share.base.min_pack_length*ci->reloc_rows,0,MYF(0)))
+ if (mysql_file_chsize(dfile, share.base.min_pack_length*ci->reloc_rows,
+ 0, MYF(0)))
goto err;
#endif
errpos=2;
- if (my_close(dfile,MYF(0)))
+ if (mysql_file_close(dfile, MYF(0)))
goto err;
}
errpos=0;
- pthread_mutex_unlock(&THR_LOCK_myisam);
- if (my_close(file,MYF(0)))
+ mysql_mutex_unlock(&THR_LOCK_myisam);
+ if (mysql_file_close(file, MYF(0)))
goto err;
my_free((char*) rec_per_key_part,MYF(0));
DBUG_RETURN(0);
err:
- pthread_mutex_unlock(&THR_LOCK_myisam);
+ mysql_mutex_unlock(&THR_LOCK_myisam);
save_errno=my_errno;
switch (errpos) {
case 3:
- VOID(my_close(dfile,MYF(0)));
+ (void) mysql_file_close(dfile, MYF(0));
/* fall through */
case 2:
/* QQ: Tõnu should add a call to my_raid_delete() here */
if (! (flags & HA_DONT_TOUCH_DATA))
- my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_DEXT,
- MY_UNPACK_FILENAME | MY_APPEND_EXT),
- MYF(0));
+ mysql_file_delete_with_symlink(mi_key_file_dfile,
+ fn_format(filename, name, "", MI_NAME_DEXT,
+ MY_UNPACK_FILENAME | MY_APPEND_EXT),
+ MYF(0));
/* fall through */
case 1:
- VOID(my_close(file,MYF(0)));
+ (void) mysql_file_close(file, MYF(0));
if (! (flags & HA_DONT_TOUCH_DATA))
- my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_IEXT,
- MY_UNPACK_FILENAME | MY_APPEND_EXT),
- MYF(0));
+ mysql_file_delete_with_symlink(mi_key_file_kfile,
+ fn_format(filename, name, "", MI_NAME_IEXT,
+ MY_UNPACK_FILENAME | MY_APPEND_EXT),
+ MYF(0));
}
my_free((char*) rec_per_key_part, MYF(0));
DBUG_RETURN(my_errno=save_errno); /* return the fatal errno */
diff --git a/storage/myisam/mi_dbug.c b/storage/myisam/mi_dbug.c
index 07c314c43e6..45882eda6af 100644
--- a/storage/myisam/mi_dbug.c
+++ b/storage/myisam/mi_dbug.c
@@ -30,12 +30,12 @@ void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg,
const uchar *end;
const uchar *key_end=key+length;
- VOID(fputs("Key: \"",stream));
+ (void) fputs("Key: \"",stream);
flag=0;
for (; keyseg->type && key < key_end ;keyseg++)
{
if (flag++)
- VOID(putc('-',stream));
+ (void) putc('-',stream);
end= key+ keyseg->length;
if (keyseg->flag & HA_NULL_PART)
{
@@ -51,7 +51,7 @@ void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg,
case HA_KEYTYPE_BINARY:
if (!(keyseg->flag & HA_SPACE_PACK) && keyseg->length == 1)
{ /* packed binary digit */
- VOID(fprintf(stream,"%d",(uint) *key++));
+ (void) fprintf(stream,"%d",(uint) *key++);
break;
}
/* fall through */
@@ -59,58 +59,58 @@ void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg,
case HA_KEYTYPE_NUM:
if (keyseg->flag & HA_SPACE_PACK)
{
- VOID(fprintf(stream,"%.*s",(int) *key,key+1));
+ (void) fprintf(stream,"%.*s",(int) *key,key+1);
key+= (int) *key+1;
}
else
{
- VOID(fprintf(stream,"%.*s",(int) keyseg->length,key));
+ (void) fprintf(stream,"%.*s",(int) keyseg->length,key);
key=end;
}
break;
case HA_KEYTYPE_INT8:
- VOID(fprintf(stream,"%d",(int) *((signed char*) key)));
+ (void) fprintf(stream,"%d",(int) *((signed char*) key));
key=end;
break;
case HA_KEYTYPE_SHORT_INT:
s_1= mi_sint2korr(key);
- VOID(fprintf(stream,"%d",(int) s_1));
+ (void) fprintf(stream,"%d",(int) s_1);
key=end;
break;
case HA_KEYTYPE_USHORT_INT:
{
ushort u_1;
u_1= mi_uint2korr(key);
- VOID(fprintf(stream,"%u",(uint) u_1));
+ (void) fprintf(stream,"%u",(uint) u_1);
key=end;
break;
}
case HA_KEYTYPE_LONG_INT:
l_1=mi_sint4korr(key);
- VOID(fprintf(stream,"%ld",l_1));
+ (void) fprintf(stream,"%ld",l_1);
key=end;
break;
case HA_KEYTYPE_ULONG_INT:
l_1=mi_sint4korr(key);
- VOID(fprintf(stream,"%lu",(ulong) l_1));
+ (void) fprintf(stream,"%lu",(ulong) l_1);
key=end;
break;
case HA_KEYTYPE_INT24:
- VOID(fprintf(stream,"%ld",(long) mi_sint3korr(key)));
+ (void) fprintf(stream,"%ld",(long) mi_sint3korr(key));
key=end;
break;
case HA_KEYTYPE_UINT24:
- VOID(fprintf(stream,"%lu",(ulong) mi_uint3korr(key)));
+ (void) fprintf(stream,"%lu",(ulong) mi_uint3korr(key));
key=end;
break;
case HA_KEYTYPE_FLOAT:
mi_float4get(f_1,key);
- VOID(fprintf(stream,"%g",(double) f_1));
+ (void) fprintf(stream,"%g",(double) f_1);
key=end;
break;
case HA_KEYTYPE_DOUBLE:
mi_float8get(d_1,key);
- VOID(fprintf(stream,"%g",d_1));
+ (void) fprintf(stream,"%g",d_1);
key=end;
break;
#ifdef HAVE_LONG_LONG
@@ -118,7 +118,7 @@ void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg,
{
char buff[21];
longlong2str(mi_sint8korr(key),buff,-10);
- VOID(fprintf(stream,"%s",buff));
+ (void) fprintf(stream,"%s",buff);
key=end;
break;
}
@@ -126,7 +126,7 @@ void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg,
{
char buff[21];
longlong2str(mi_sint8korr(key),buff,10);
- VOID(fprintf(stream,"%s",buff));
+ (void) fprintf(stream,"%s",buff);
key=end;
break;
}
@@ -152,14 +152,14 @@ void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg,
The following command sometimes gives a warning from valgrind.
Not yet sure if the bug is in valgrind, glibc or mysqld
*/
- VOID(fprintf(stream,"%.*s",(int) tmp_length,key));
+ (void) fprintf(stream,"%.*s",(int) tmp_length,key);
key+=tmp_length;
break;
}
default: break; /* This never happens */
}
}
- VOID(fputs("\"\n",stream));
+ (void) fputs("\"\n",stream);
return;
} /* print_key */
diff --git a/storage/myisam/mi_delete.c b/storage/myisam/mi_delete.c
index 904ce4b2247..9314148cd8c 100644
--- a/storage/myisam/mi_delete.c
+++ b/storage/myisam/mi_delete.c
@@ -101,7 +101,7 @@ int mi_delete(MI_INFO *info,const uchar *record)
mi_sizestore(lastpos,info->lastpos);
myisam_log_command(MI_LOG_DELETE,info,(uchar*) lastpos,sizeof(lastpos),0);
- VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
+ (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
allow_break(); /* Allow SIGHUP & SIGINT */
if (info->invalidator != 0)
{
@@ -120,7 +120,7 @@ err:
mi_print_error(info->s, HA_ERR_CRASHED);
mi_mark_crashed(info); /* mark table crashed */
}
- VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
+ (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
info->update|=HA_STATE_WRITTEN; /* Buffer changed */
allow_break(); /* Allow SIGHUP & SIGINT */
my_errno=save_errno;
diff --git a/storage/myisam/mi_delete_all.c b/storage/myisam/mi_delete_all.c
index e2bbb04ab3c..b8706069ced 100644
--- a/storage/myisam/mi_delete_all.c
+++ b/storage/myisam/mi_delete_all.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003, 2005 MySQL AB
+/* Copyright (C) 2000-2003, 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -57,10 +57,10 @@ int mi_delete_all_rows(MI_INFO *info)
if (share->file_map)
_mi_unmap_file(info);
#endif
- if (my_chsize(info->dfile, 0, 0, MYF(MY_WME)) ||
- my_chsize(share->kfile, share->base.keystart, 0, MYF(MY_WME)) )
+ if (mysql_file_chsize(info->dfile, 0, 0, MYF(MY_WME)) ||
+ mysql_file_chsize(share->kfile, share->base.keystart, 0, MYF(MY_WME)))
goto err;
- VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
+ (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
#ifdef HAVE_MMAP
/* Map again */
if (share->file_map)
@@ -72,7 +72,7 @@ int mi_delete_all_rows(MI_INFO *info)
err:
{
int save_errno=my_errno;
- VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
+ (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
info->update|=HA_STATE_WRITTEN; /* Buffer changed */
allow_break(); /* Allow SIGHUP & SIGINT */
DBUG_RETURN(my_errno=save_errno);
diff --git a/storage/myisam/mi_delete_table.c b/storage/myisam/mi_delete_table.c
index a3c0dede581..28aee848665 100644
--- a/storage/myisam/mi_delete_table.c
+++ b/storage/myisam/mi_delete_table.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2001, 2004, 2006 MySQL AB
+/* Copyright (C) 2000-2001, 2004, 2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -58,12 +58,13 @@ int mi_delete_table(const char *name)
#endif /* USE_RAID */
fn_format(from,name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
- if (my_delete_with_symlink(from, MYF(MY_WME)))
+ if (mysql_file_delete_with_symlink(mi_key_file_kfile, from, MYF(MY_WME)))
DBUG_RETURN(my_errno);
fn_format(from,name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
#ifdef USE_RAID
if (raid_type)
DBUG_RETURN(my_raid_delete(from, raid_chunks, MYF(MY_WME)) ? my_errno : 0);
#endif
- DBUG_RETURN(my_delete_with_symlink(from, MYF(MY_WME)) ? my_errno : 0);
+ DBUG_RETURN(mysql_file_delete_with_symlink(mi_key_file_dfile,
+ from, MYF(MY_WME)) ? my_errno : 0);
}
diff --git a/storage/myisam/mi_dynrec.c b/storage/myisam/mi_dynrec.c
index 79f1ea0e4e5..4c681eeff5f 100644
--- a/storage/myisam/mi_dynrec.c
+++ b/storage/myisam/mi_dynrec.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -115,7 +115,7 @@ void mi_remap_file(MI_INFO *info, my_off_t size)
{
if (info->s->file_map)
{
- VOID(my_munmap((char*) info->s->file_map,
+ (void) (my_munmap((char*) info->s->file_map,
(size_t) info->s->mmaped_length));
mi_dynmap_file(info, size);
}
@@ -143,7 +143,7 @@ size_t mi_mmap_pread(MI_INFO *info, uchar *Buffer,
{
DBUG_PRINT("info", ("mi_read with mmap %d\n", info->dfile));
if (info->s->concurrent_insert)
- rw_rdlock(&info->s->mmap_lock);
+ mysql_rwlock_rdlock(&info->s->mmap_lock);
/*
The following test may fail in the following cases:
@@ -156,24 +156,24 @@ size_t mi_mmap_pread(MI_INFO *info, uchar *Buffer,
{
memcpy(Buffer, info->s->file_map + offset, Count);
if (info->s->concurrent_insert)
- rw_unlock(&info->s->mmap_lock);
+ mysql_rwlock_unlock(&info->s->mmap_lock);
return 0;
}
else
{
if (info->s->concurrent_insert)
- rw_unlock(&info->s->mmap_lock);
- return my_pread(info->dfile, Buffer, Count, offset, MyFlags);
+ mysql_rwlock_unlock(&info->s->mmap_lock);
+ return mysql_file_pread(info->dfile, Buffer, Count, offset, MyFlags);
}
}
- /* wrapper for my_pread in case if mmap isn't used */
+ /* wrapper for mysql_file_pread in case if mmap isn't used */
size_t mi_nommap_pread(MI_INFO *info, uchar *Buffer,
size_t Count, my_off_t offset, myf MyFlags)
{
- return my_pread(info->dfile, Buffer, Count, offset, MyFlags);
+ return mysql_file_pread(info->dfile, Buffer, Count, offset, MyFlags);
}
@@ -198,7 +198,7 @@ size_t mi_mmap_pwrite(MI_INFO *info, const uchar *Buffer,
{
DBUG_PRINT("info", ("mi_write with mmap %d\n", info->dfile));
if (info->s->concurrent_insert)
- rw_rdlock(&info->s->mmap_lock);
+ mysql_rwlock_rdlock(&info->s->mmap_lock);
/*
The following test may fail in the following cases:
@@ -211,26 +211,26 @@ size_t mi_mmap_pwrite(MI_INFO *info, const uchar *Buffer,
{
memcpy(info->s->file_map + offset, Buffer, Count);
if (info->s->concurrent_insert)
- rw_unlock(&info->s->mmap_lock);
+ mysql_rwlock_unlock(&info->s->mmap_lock);
return 0;
}
else
{
info->s->nonmmaped_inserts++;
if (info->s->concurrent_insert)
- rw_unlock(&info->s->mmap_lock);
- return my_pwrite(info->dfile, Buffer, Count, offset, MyFlags);
+ mysql_rwlock_unlock(&info->s->mmap_lock);
+ return mysql_file_pwrite(info->dfile, Buffer, Count, offset, MyFlags);
}
}
- /* wrapper for my_pwrite in case if mmap isn't used */
+ /* wrapper for mysql_file_pwrite in case if mmap isn't used */
size_t mi_nommap_pwrite(MI_INFO *info, const uchar *Buffer,
size_t Count, my_off_t offset, myf MyFlags)
{
- return my_pwrite(info->dfile, Buffer, Count, offset, MyFlags);
+ return mysql_file_pwrite(info->dfile, Buffer, Count, offset, MyFlags);
}
@@ -1515,7 +1515,7 @@ int _mi_read_dynamic_record(MI_INFO *info, my_off_t filepos, uchar *buf)
panic:
my_errno=HA_ERR_WRONG_IN_RECORD;
err:
- VOID(_mi_writeinfo(info,0));
+ (void) _mi_writeinfo(info,0);
DBUG_RETURN(-1);
}
@@ -1642,7 +1642,7 @@ static int _mi_cmp_buffer(File file, const uchar *buff, my_off_t filepos,
while (length > IO_SIZE*2)
{
- if (my_pread(file,temp_buff,next_length,filepos, MYF(MY_NABP)) ||
+ if (mysql_file_pread(file, temp_buff, next_length, filepos, MYF(MY_NABP)) ||
memcmp(buff, temp_buff, next_length))
goto err;
filepos+=next_length;
@@ -1650,7 +1650,7 @@ static int _mi_cmp_buffer(File file, const uchar *buff, my_off_t filepos,
length-= next_length;
next_length=IO_SIZE*2;
}
- if (my_pread(file,temp_buff,length,filepos,MYF(MY_NABP)))
+ if (mysql_file_pread(file, temp_buff, length, filepos, MYF(MY_NABP)))
goto err;
DBUG_RETURN(memcmp(buff,temp_buff,length));
err:
@@ -1831,8 +1831,9 @@ int _mi_read_rnd_dynamic_record(MI_INFO *info, uchar *buf,
block_info.filepos + block_info.data_len &&
flush_io_cache(&info->rec_cache))
goto err;
- /* VOID(my_seek(info->dfile,filepos,MY_SEEK_SET,MYF(0))); */
- if (my_read(info->dfile,(uchar*) to,block_info.data_len,MYF(MY_NABP)))
+ /* mysql_file_seek(info->dfile, filepos, MY_SEEK_SET, MYF(0)); */
+ if (mysql_file_read(info->dfile, (uchar*) to, block_info.data_len,
+ MYF(MY_NABP)))
{
if (my_errno == -1)
my_errno= HA_ERR_WRONG_IN_RECORD; /* Unexpected end of file */
@@ -1865,7 +1866,7 @@ panic:
my_errno=HA_ERR_WRONG_IN_RECORD; /* Something is fatal wrong */
err:
save_errno=my_errno;
- VOID(_mi_writeinfo(info,0));
+ (void) _mi_writeinfo(info,0);
DBUG_RETURN(my_errno=save_errno);
}
@@ -1880,12 +1881,12 @@ uint _mi_get_block_info(MI_BLOCK_INFO *info, File file, my_off_t filepos)
if (file >= 0)
{
/*
- We do not use my_pread() here because we want to have the file
+ We do not use mysql_file_pread() here because we want to have the file
pointer set to the end of the header after this function.
- my_pread() may leave the file pointer untouched.
+ mysql_file_pread() may leave the file pointer untouched.
*/
- VOID(my_seek(file,filepos,MY_SEEK_SET,MYF(0)));
- if (my_read(file, header, sizeof(info->header),MYF(0)) !=
+ mysql_file_seek(file, filepos, MY_SEEK_SET, MYF(0));
+ if (mysql_file_read(file, header, sizeof(info->header), MYF(0)) !=
sizeof(info->header))
goto err;
}
diff --git a/storage/myisam/mi_extra.c b/storage/myisam/mi_extra.c
index f0ddc15b325..d8f4fc99c8e 100644
--- a/storage/myisam/mi_extra.c
+++ b/storage/myisam/mi_extra.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2005 MySQL AB
+/* Copyright (C) 2000-2005 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -74,17 +74,17 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE)
if ((share->options & HA_OPTION_COMPRESS_RECORD))
{
- pthread_mutex_lock(&share->intern_lock);
+ mysql_mutex_lock(&share->intern_lock);
if (_mi_memmap_file(info))
{
/* We don't nead MADV_SEQUENTIAL if small file */
madvise((char*) share->file_map, share->state.state.data_file_length,
share->state.state.data_file_length <= RECORD_CACHE_SIZE*16 ?
MADV_RANDOM : MADV_SEQUENTIAL);
- pthread_mutex_unlock(&share->intern_lock);
+ mysql_mutex_unlock(&share->intern_lock);
break;
}
- pthread_mutex_unlock(&share->intern_lock);
+ mysql_mutex_unlock(&share->intern_lock);
}
#endif
if (info->opt_flag & WRITE_CACHE_USED)
@@ -252,16 +252,16 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
}
break;
case HA_EXTRA_FORCE_REOPEN:
- pthread_mutex_lock(&THR_LOCK_myisam);
+ mysql_mutex_lock(&THR_LOCK_myisam);
share->last_version= 0L; /* Impossible version */
- pthread_mutex_unlock(&THR_LOCK_myisam);
+ mysql_mutex_unlock(&THR_LOCK_myisam);
break;
case HA_EXTRA_PREPARE_FOR_DROP:
- pthread_mutex_lock(&THR_LOCK_myisam);
+ mysql_mutex_lock(&THR_LOCK_myisam);
share->last_version= 0L; /* Impossible version */
#ifdef __WIN__REMOVE_OBSOLETE_WORKAROUND
/* Close the isam and data files as Win32 can't drop an open table */
- pthread_mutex_lock(&share->intern_lock);
+ mysql_mutex_lock(&share->intern_lock);
if (flush_key_blocks(share->key_cache, share->kfile,
(function == HA_EXTRA_FORCE_REOPEN ?
FLUSH_RELEASE : FLUSH_IGNORE_CHANGED)))
@@ -285,7 +285,7 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
}
if (share->kfile >= 0)
_mi_decrement_open_count(info);
- if (share->kfile >= 0 && my_close(share->kfile,MYF(0)))
+ if (share->kfile >= 0 && mysql_file_close(share->kfile, MYF(0)))
error=my_errno;
{
LIST *list_element ;
@@ -296,16 +296,16 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
MI_INFO *tmpinfo=(MI_INFO*) list_element->data;
if (tmpinfo->s == info->s)
{
- if (tmpinfo->dfile >= 0 && my_close(tmpinfo->dfile,MYF(0)))
+ if (tmpinfo->dfile >= 0 && mysql_file_close(tmpinfo->dfile, MYF(0)))
error = my_errno;
tmpinfo->dfile= -1;
}
}
}
share->kfile= -1; /* Files aren't open anymore */
- pthread_mutex_unlock(&share->intern_lock);
+ mysql_mutex_unlock(&share->intern_lock);
#endif
- pthread_mutex_unlock(&THR_LOCK_myisam);
+ mysql_mutex_unlock(&THR_LOCK_myisam);
break;
case HA_EXTRA_FLUSH:
if (!share->temporary)
@@ -316,9 +316,9 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
if (share->not_flushed)
{
share->not_flushed=0;
- if (my_sync(share->kfile, MYF(0)))
+ if (mysql_file_sync(share->kfile, MYF(0)))
error= my_errno;
- if (my_sync(info->dfile, MYF(0)))
+ if (mysql_file_sync(info->dfile, MYF(0)))
error= my_errno;
if (error)
{
@@ -349,7 +349,7 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
break;
case HA_EXTRA_MMAP:
#ifdef HAVE_MMAP
- pthread_mutex_lock(&share->intern_lock);
+ mysql_mutex_lock(&share->intern_lock);
/*
Memory map the data file if it is not already mapped. It is safe
to memory map a file while other threads are using file I/O on it.
@@ -370,13 +370,13 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
share->file_write= mi_mmap_pwrite;
}
}
- pthread_mutex_unlock(&share->intern_lock);
+ mysql_mutex_unlock(&share->intern_lock);
#endif
break;
case HA_EXTRA_MARK_AS_LOG_TABLE:
- pthread_mutex_lock(&share->intern_lock);
+ mysql_mutex_lock(&share->intern_lock);
share->is_log_table= TRUE;
- pthread_mutex_unlock(&share->intern_lock);
+ mysql_mutex_unlock(&share->intern_lock);
break;
case HA_EXTRA_KEY_CACHE:
case HA_EXTRA_NO_KEY_CACHE:
diff --git a/storage/myisam/mi_extrafunc.h b/storage/myisam/mi_extrafunc.h
new file mode 100644
index 00000000000..4aa28832c6d
--- /dev/null
+++ b/storage/myisam/mi_extrafunc.h
@@ -0,0 +1,21 @@
+/* Copyright (C) 2000-2006 MySQL 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
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+void _mi_report_crashed(MI_INFO *file __attribute__((unused)),
+ const char *message __attribute__((unused)),
+ const char *sfile __attribute__((unused)),
+ uint sline __attribute__((unused)))
+{
+}
diff --git a/storage/myisam/mi_info.c b/storage/myisam/mi_info.c
index 91e7ca659e4..36d7073a4dc 100644
--- a/storage/myisam/mi_info.c
+++ b/storage/myisam/mi_info.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2001, 2003-2004 MySQL AB
+/* Copyright (C) 2000-2001, 2003-2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -42,10 +42,10 @@ int mi_status(MI_INFO *info, register MI_ISAMINFO *x, uint flag)
DBUG_RETURN(0); /* Compatible with ISAM */
if (!(flag & HA_STATUS_NO_LOCK))
{
- pthread_mutex_lock(&share->intern_lock);
- VOID(_mi_readinfo(info,F_RDLCK,0));
+ mysql_mutex_lock(&share->intern_lock);
+ (void) _mi_readinfo(info,F_RDLCK,0);
fast_mi_writeinfo(info);
- pthread_mutex_unlock(&share->intern_lock);
+ mysql_mutex_unlock(&share->intern_lock);
}
if (flag & HA_STATUS_VARIABLE)
{
@@ -85,7 +85,7 @@ int mi_status(MI_INFO *info, register MI_ISAMINFO *x, uint flag)
x->data_file_name = share->data_file_name;
x->index_file_name = share->index_file_name;
}
- if ((flag & HA_STATUS_TIME) && !my_fstat(info->dfile,&state,MYF(0)))
+ if ((flag & HA_STATUS_TIME) && !mysql_file_fstat(info->dfile, &state, MYF(0)))
x->update_time=state.st_mtime;
else
x->update_time=0;
diff --git a/storage/myisam/mi_keycache.c b/storage/myisam/mi_keycache.c
index 5cf3fede1ae..cbd9c7d76ab 100644
--- a/storage/myisam/mi_keycache.c
+++ b/storage/myisam/mi_keycache.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003 MySQL AB
+/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -96,7 +96,7 @@ int mi_assign_to_key_cache(MI_INFO *info,
ensure that setting the key cache and changing the multi_key_cache
is done atomicly
*/
- pthread_mutex_lock(&share->intern_lock);
+ mysql_mutex_lock(&share->intern_lock);
/*
Tell all threads to use the new key cache
This should be seen at the lastes for the next call to an myisam function.
@@ -108,7 +108,7 @@ int mi_assign_to_key_cache(MI_INFO *info,
share->unique_name_length,
share->key_cache))
error= my_errno;
- pthread_mutex_unlock(&share->intern_lock);
+ mysql_mutex_unlock(&share->intern_lock);
DBUG_RETURN(error);
}
@@ -143,7 +143,7 @@ void mi_change_key_cache(KEY_CACHE *old_key_cache,
/*
Lock list to ensure that no one can close the table while we manipulate it
*/
- pthread_mutex_lock(&THR_LOCK_myisam);
+ mysql_mutex_lock(&THR_LOCK_myisam);
for (pos=myisam_open_list ; pos ; pos=pos->next)
{
MI_INFO *info= (MI_INFO*) pos->data;
@@ -158,6 +158,6 @@ void mi_change_key_cache(KEY_CACHE *old_key_cache,
open a new table that will be associted with the old key cache
*/
multi_key_cache_change(old_key_cache, new_key_cache);
- pthread_mutex_unlock(&THR_LOCK_myisam);
+ mysql_mutex_unlock(&THR_LOCK_myisam);
DBUG_VOID_RETURN;
}
diff --git a/storage/myisam/mi_locking.c b/storage/myisam/mi_locking.c
index 8a5866ae763..bfe79f51e4e 100644
--- a/storage/myisam/mi_locking.c
+++ b/storage/myisam/mi_locking.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -45,11 +45,12 @@ int mi_lock_database(MI_INFO *info, int lock_type)
++share->w_locks;
++share->tot_locks;
info->lock_type= lock_type;
+ info->s->in_use= list_add(info->s->in_use, &info->in_use);
DBUG_RETURN(0);
}
flag=error=0;
- pthread_mutex_lock(&share->intern_lock);
+ mysql_mutex_lock(&share->intern_lock);
if (share->kfile >= 0) /* May only be false on windows */
{
switch (lock_type) {
@@ -88,11 +89,11 @@ int mi_lock_database(MI_INFO *info, int lock_type)
(info->s->nonmmaped_inserts > MAX_NONMAPPED_INSERTS))
{
if (info->s->concurrent_insert)
- rw_wrlock(&info->s->mmap_lock);
+ mysql_rwlock_wrlock(&info->s->mmap_lock);
mi_remap_file(info, info->s->state.state.data_file_length);
info->s->nonmmaped_inserts= 0;
if (info->s->concurrent_insert)
- rw_unlock(&info->s->mmap_lock);
+ mysql_rwlock_unlock(&info->s->mmap_lock);
}
#endif
share->state.process= share->last_process=share->this_process;
@@ -103,9 +104,9 @@ int mi_lock_database(MI_INFO *info, int lock_type)
share->changed=0;
if (myisam_flush)
{
- if (my_sync(share->kfile, MYF(0)))
+ if (mysql_file_sync(share->kfile, MYF(0)))
error= my_errno;
- if (my_sync(info->dfile, MYF(0)))
+ if (mysql_file_sync(info->dfile, MYF(0)))
error= my_errno;
}
else
@@ -136,6 +137,7 @@ int mi_lock_database(MI_INFO *info, int lock_type)
}
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
info->lock_type= F_UNLCK;
+ info->s->in_use= list_delete(info->s->in_use, &info->in_use);
break;
case F_RDLCK:
if (info->lock_type == F_WRLCK)
@@ -173,15 +175,16 @@ int mi_lock_database(MI_INFO *info, int lock_type)
if (mi_state_info_read_dsk(share->kfile, &share->state, 1))
{
error=my_errno;
- VOID(my_lock(share->kfile,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)));
+ (void) my_lock(share->kfile,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
my_errno=error;
break;
}
}
- VOID(_mi_test_if_changed(info));
+ (void) _mi_test_if_changed(info);
share->r_locks++;
share->tot_locks++;
info->lock_type=lock_type;
+ info->s->in_use= list_add(info->s->in_use, &info->in_use);
break;
case F_WRLCK:
if (info->lock_type == F_RDLCK)
@@ -217,20 +220,21 @@ int mi_lock_database(MI_INFO *info, int lock_type)
if (mi_state_info_read_dsk(share->kfile, &share->state, 1))
{
error=my_errno;
- VOID(my_lock(share->kfile,F_UNLCK,0L,F_TO_EOF,
- info->lock_wait | MY_SEEK_NOT_DONE));
+ (void) my_lock(share->kfile,F_UNLCK,0L,F_TO_EOF,
+ info->lock_wait | MY_SEEK_NOT_DONE);
my_errno=error;
break;
}
}
}
}
- VOID(_mi_test_if_changed(info));
+ (void) _mi_test_if_changed(info);
info->lock_type=lock_type;
info->invalidator=info->s->invalidator;
share->w_locks++;
share->tot_locks++;
+ info->s->in_use= list_add(info->s->in_use, &info->in_use);
break;
default:
break; /* Impossible */
@@ -251,7 +255,7 @@ int mi_lock_database(MI_INFO *info, int lock_type)
}
}
#endif
- pthread_mutex_unlock(&share->intern_lock);
+ mysql_mutex_unlock(&share->intern_lock);
#if defined(FULL_LOG) || defined(_lint)
lock_type|=(int) (flag << 8); /* Set bit to set if real lock */
myisam_log_command(MI_LOG_LOCK,info,(uchar*) &lock_type,sizeof(lock_type),
@@ -412,14 +416,14 @@ int _mi_readinfo(register MI_INFO *info, int lock_type, int check_keybuffer)
if (mi_state_info_read_dsk(share->kfile, &share->state, 1))
{
int error=my_errno ? my_errno : -1;
- VOID(my_lock(share->kfile,F_UNLCK,0L,F_TO_EOF,
- MYF(MY_SEEK_NOT_DONE)));
+ (void) my_lock(share->kfile,F_UNLCK,0L,F_TO_EOF,
+ MYF(MY_SEEK_NOT_DONE));
my_errno=error;
DBUG_RETURN(1);
}
}
if (check_keybuffer)
- VOID(_mi_test_if_changed(info));
+ (void) _mi_test_if_changed(info);
info->invalidator=info->s->invalidator;
}
else if (lock_type == F_WRLCK && info->lock_type == F_RDLCK)
@@ -458,8 +462,8 @@ int _mi_writeinfo(register MI_INFO *info, uint operation)
#ifdef _WIN32
if (myisam_flush)
{
- my_sync(share->kfile,0);
- my_sync(info->dfile,0);
+ mysql_file_sync(share->kfile, 0);
+ mysql_file_sync(info->dfile, 0);
}
#endif
}
@@ -487,7 +491,7 @@ int _mi_test_if_changed(register MI_INFO *info)
{ /* Keyfile has changed */
DBUG_PRINT("info",("index file changed"));
if (share->state.process != share->this_process)
- VOID(flush_key_blocks(share->key_cache, share->kfile, FLUSH_RELEASE));
+ (void) flush_key_blocks(share->key_cache, share->kfile, FLUSH_RELEASE);
share->last_process=share->state.process;
info->last_unique= share->state.unique;
info->last_loop= share->state.update_count;
@@ -539,9 +543,9 @@ int _mi_mark_file_changed(MI_INFO *info)
{
mi_int2store(buff,share->state.open_count);
buff[2]=1; /* Mark that it's changed */
- DBUG_RETURN(my_pwrite(share->kfile,buff,sizeof(buff),
- sizeof(share->state.header),
- MYF(MY_NABP)));
+ DBUG_RETURN(mysql_file_pwrite(share->kfile, buff, sizeof(buff),
+ sizeof(share->state.header),
+ MYF(MY_NABP)));
}
}
DBUG_RETURN(0);
@@ -568,9 +572,9 @@ int _mi_decrement_open_count(MI_INFO *info)
{
share->state.open_count--;
mi_int2store(buff,share->state.open_count);
- write_error=my_pwrite(share->kfile,buff,sizeof(buff),
- sizeof(share->state.header),
- MYF(MY_NABP));
+ write_error= mysql_file_pwrite(share->kfile, buff, sizeof(buff),
+ sizeof(share->state.header),
+ MYF(MY_NABP));
}
if (!lock_error)
lock_error=mi_lock_database(info,old_lock);
diff --git a/storage/myisam/mi_log.c b/storage/myisam/mi_log.c
index 8b9ca038fec..54498393f15 100644
--- a/storage/myisam/mi_log.c
+++ b/storage/myisam/mi_log.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2001, 2004 MySQL AB
+/* Copyright (C) 2000-2001, 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -54,16 +54,19 @@ int mi_log(int activate_log)
myisam_pid=(ulong) getpid();
if (myisam_log_file < 0)
{
- if ((myisam_log_file = my_create(fn_format(buff,myisam_log_filename,
- "",".log",4),
- 0,(O_RDWR | O_BINARY | O_APPEND),MYF(0)))
- < 0)
+ if ((myisam_log_file= mysql_file_create(mi_key_file_log,
+ fn_format(buff,
+ myisam_log_filename,
+ "", ".log", 4),
+ 0,
+ (O_RDWR | O_BINARY | O_APPEND),
+ MYF(0))) < 0)
DBUG_RETURN(my_errno);
}
}
else if (myisam_log_file >= 0)
{
- error=my_close(myisam_log_file,MYF(0)) ? my_errno : 0 ;
+ error= mysql_file_close(myisam_log_file, MYF(0)) ? my_errno : 0 ;
myisam_log_file= -1;
}
DBUG_RETURN(error);
@@ -86,13 +89,13 @@ void _myisam_log(enum myisam_log_commands command, MI_INFO *info,
mi_int4store(buff+3,pid);
mi_int2store(buff+9,length);
- pthread_mutex_lock(&THR_LOCK_myisam);
+ mysql_mutex_lock(&THR_LOCK_myisam);
error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
- VOID(my_write(myisam_log_file,buff,sizeof(buff),MYF(0)));
- VOID(my_write(myisam_log_file,buffert,length,MYF(0)));
+ (void) mysql_file_write(myisam_log_file, buff, sizeof(buff), MYF(0));
+ (void) mysql_file_write(myisam_log_file, buffert, length, MYF(0));
if (!error)
error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
- pthread_mutex_unlock(&THR_LOCK_myisam);
+ mysql_mutex_unlock(&THR_LOCK_myisam);
my_errno=old_errno;
}
@@ -109,14 +112,14 @@ void _myisam_log_command(enum myisam_log_commands command, MI_INFO *info,
mi_int2store(buff+1,info->dfile);
mi_int4store(buff+3,pid);
mi_int2store(buff+7,result);
- pthread_mutex_lock(&THR_LOCK_myisam);
+ mysql_mutex_lock(&THR_LOCK_myisam);
error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
- VOID(my_write(myisam_log_file,buff,sizeof(buff),MYF(0)));
+ (void) mysql_file_write(myisam_log_file, buff, sizeof(buff), MYF(0));
if (buffert)
- VOID(my_write(myisam_log_file,buffert,length,MYF(0)));
+ (void) mysql_file_write(myisam_log_file, buffert, length, MYF(0));
if (!error)
error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
- pthread_mutex_unlock(&THR_LOCK_myisam);
+ mysql_mutex_unlock(&THR_LOCK_myisam);
my_errno=old_errno;
}
@@ -140,10 +143,10 @@ void _myisam_log_record(enum myisam_log_commands command, MI_INFO *info,
mi_int2store(buff+7,result);
mi_sizestore(buff+9,filepos);
mi_int4store(buff+17,length);
- pthread_mutex_lock(&THR_LOCK_myisam);
+ mysql_mutex_lock(&THR_LOCK_myisam);
error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
- VOID(my_write(myisam_log_file, buff,sizeof(buff),MYF(0)));
- VOID(my_write(myisam_log_file, record,info->s->base.reclength,MYF(0)));
+ (void) mysql_file_write(myisam_log_file, buff, sizeof(buff), MYF(0));
+ (void) mysql_file_write(myisam_log_file, record, info->s->base.reclength, MYF(0));
if (info->s->base.blobs)
{
MI_BLOB *blob,*end;
@@ -154,11 +157,11 @@ void _myisam_log_record(enum myisam_log_commands command, MI_INFO *info,
{
memcpy_fixed((uchar*) &pos, record+blob->offset+blob->pack_length,
sizeof(char*));
- VOID(my_write(myisam_log_file,pos,blob->length,MYF(0)));
+ (void) mysql_file_write(myisam_log_file, pos, blob->length, MYF(0));
}
}
if (!error)
error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
- pthread_mutex_unlock(&THR_LOCK_myisam);
+ mysql_mutex_unlock(&THR_LOCK_myisam);
my_errno=old_errno;
}
diff --git a/storage/myisam/mi_open.c b/storage/myisam/mi_open.c
index 9117d76de24..f7137ac554d 100644
--- a/storage/myisam/mi_open.c
+++ b/storage/myisam/mi_open.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -103,7 +103,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
DBUG_RETURN (NULL);
}
- pthread_mutex_lock(&THR_LOCK_myisam);
+ mysql_mutex_lock(&THR_LOCK_myisam);
if (!(old_info=test_if_reopen(name_buff)))
{
share= &share_buff;
@@ -120,17 +120,21 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
my_errno= HA_ERR_CRASHED;
goto err;
});
- if ((kfile=my_open(name_buff,(open_mode=O_RDWR) | O_SHARE,MYF(0))) < 0)
+ if ((kfile= mysql_file_open(mi_key_file_kfile,
+ name_buff,
+ (open_mode= O_RDWR) | O_SHARE, MYF(0))) < 0)
{
if ((errno != EROFS && errno != EACCES) ||
mode != O_RDONLY ||
- (kfile=my_open(name_buff,(open_mode=O_RDONLY) | O_SHARE,MYF(0))) < 0)
+ (kfile= mysql_file_open(mi_key_file_kfile,
+ name_buff,
+ (open_mode= O_RDONLY) | O_SHARE, MYF(0))) < 0)
goto err;
}
share->mode=open_mode;
errpos=1;
- if (my_read(kfile, share->state.header.file_version, head_length,
- MYF(MY_NABP)))
+ if (mysql_file_read(kfile, share->state.header.file_version, head_length,
+ MYF(MY_NABP)))
{
my_errno= HA_ERR_NOT_A_TABLE;
goto err;
@@ -181,7 +185,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
end_pos=disk_cache+info_length;
errpos=2;
- VOID(my_seek(kfile,0L,MY_SEEK_SET,MYF(0)));
+ mysql_file_seek(kfile, 0L, MY_SEEK_SET, MYF(0));
if (!(open_flags & HA_OPEN_TMP_TABLE))
{
if ((lock_error=my_lock(kfile,F_RDLCK,0L,F_TO_EOF,
@@ -191,7 +195,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
goto err;
}
errpos=3;
- if (my_read(kfile,disk_cache,info_length,MYF(MY_NABP)))
+ if (mysql_file_read(kfile, disk_cache, info_length, MYF(MY_NABP)))
{
my_errno=HA_ERR_CRASHED;
goto err;
@@ -309,9 +313,9 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
&share->state.key_del,
(share->state.header.max_block_size_index*sizeof(my_off_t)),
#ifdef THREAD
- &share->key_root_lock,sizeof(rw_lock_t)*keys,
+ &share->key_root_lock, sizeof(mysql_rwlock_t)*keys,
#endif
- &share->mmap_lock,sizeof(rw_lock_t),
+ &share->mmap_lock, sizeof(mysql_rwlock_t),
NullS))
goto err;
errpos=4;
@@ -482,7 +486,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
if (! lock_error)
{
- VOID(my_lock(kfile,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)));
+ (void) my_lock(kfile,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
lock_error=1; /* Database unlocked */
}
@@ -522,10 +526,12 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
share->is_log_table= FALSE;
#ifdef THREAD
thr_lock_init(&share->lock);
- VOID(pthread_mutex_init(&share->intern_lock,MY_MUTEX_INIT_FAST));
+ mysql_mutex_init(mi_key_mutex_MYISAM_SHARE_intern_lock,
+ &share->intern_lock, MY_MUTEX_INIT_FAST);
for (i=0; i<keys; i++)
- VOID(my_rwlock_init(&share->key_root_lock[i], NULL));
- VOID(my_rwlock_init(&share->mmap_lock, NULL));
+ mysql_rwlock_init(mi_key_rwlock_MYISAM_SHARE_key_root_lock,
+ &share->key_root_lock[i]);
+ mysql_rwlock_init(mi_key_rwlock_MYISAM_SHARE_mmap_lock, &share->mmap_lock);
if (!thr_lock_inited)
{
/* Probably a single threaded program; Don't use concurrent inserts */
@@ -611,7 +617,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
info.ft1_to_ft2=0;
info.errkey= -1;
info.page_changed=1;
- pthread_mutex_lock(&share->intern_lock);
+ mysql_mutex_lock(&share->intern_lock);
info.read_record=share->read_record;
share->reopen++;
share->write_flag=MYF(MY_NABP | MY_WAIT_IF_FULL);
@@ -635,7 +641,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
myisam_delay_key_write)
share->delay_key_write=1;
info.state= &share->state.state; /* Change global values by default */
- pthread_mutex_unlock(&share->intern_lock);
+ mysql_mutex_unlock(&share->intern_lock);
/* Allocate buffer for one record */
@@ -651,7 +657,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
m_info->open_list.data=(void*) m_info;
myisam_open_list=list_add(myisam_open_list,&m_info->open_list);
- pthread_mutex_unlock(&THR_LOCK_myisam);
+ mysql_mutex_unlock(&THR_LOCK_myisam);
if (myisam_log_file >= 0)
{
intern_filename(name_buff,share->index_file_name);
@@ -670,7 +676,7 @@ err:
my_free((uchar*) m_info,MYF(0));
/* fall through */
case 5:
- VOID(my_close(info.dfile,MYF(0)));
+ (void) mysql_file_close(info.dfile, MYF(0));
if (old_info)
break; /* Don't remove open table */
/* fall through */
@@ -679,19 +685,19 @@ err:
/* fall through */
case 3:
if (! lock_error)
- VOID(my_lock(kfile, F_UNLCK, 0L, F_TO_EOF, MYF(MY_SEEK_NOT_DONE)));
+ (void) my_lock(kfile, F_UNLCK, 0L, F_TO_EOF, MYF(MY_SEEK_NOT_DONE));
/* fall through */
case 2:
my_afree(disk_cache);
/* fall through */
case 1:
- VOID(my_close(kfile,MYF(0)));
+ (void) mysql_file_close(kfile, MYF(0));
/* fall through */
case 0:
default:
break;
}
- pthread_mutex_unlock(&THR_LOCK_myisam);
+ mysql_mutex_unlock(&THR_LOCK_myisam);
my_errno=save_errno;
DBUG_RETURN (NULL);
} /* mi_open */
@@ -924,10 +930,10 @@ uint mi_state_info_write(File file, MI_STATE_INFO *state, uint pWrite)
}
if (pWrite & 1)
- DBUG_RETURN(my_pwrite(file, buff, (size_t) (ptr-buff), 0L,
- MYF(MY_NABP | MY_THREADSAFE)) != 0);
- DBUG_RETURN(my_write(file, buff, (size_t) (ptr-buff),
- MYF(MY_NABP)) != 0);
+ DBUG_RETURN(mysql_file_pwrite(file, buff, (size_t) (ptr-buff), 0L,
+ MYF(MY_NABP | MY_THREADSAFE)) != 0);
+ DBUG_RETURN(mysql_file_write(file, buff, (size_t) (ptr-buff),
+ MYF(MY_NABP)) != 0);
}
@@ -992,10 +998,10 @@ uint mi_state_info_read_dsk(File file, MI_STATE_INFO *state, my_bool pRead)
{
if (pRead)
{
- if (my_pread(file, buff, state->state_length,0L, MYF(MY_NABP)))
+ if (mysql_file_pread(file, buff, state->state_length, 0L, MYF(MY_NABP)))
return 1;
}
- else if (my_read(file, buff, state->state_length,MYF(MY_NABP)))
+ else if (mysql_file_read(file, buff, state->state_length, MYF(MY_NABP)))
return 1;
mi_state_info_read(buff, state);
}
@@ -1038,7 +1044,7 @@ uint mi_base_info_write(File file, MI_BASE_INFO *base)
mi_int2store(ptr,base->raid_chunks); ptr +=2;
mi_int4store(ptr,base->raid_chunksize); ptr +=4;
bzero(ptr,6); ptr +=6; /* extra */
- return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0;
+ return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0;
}
@@ -1098,7 +1104,7 @@ uint mi_keydef_write(File file, MI_KEYDEF *keydef)
mi_int2store(ptr,keydef->keylength); ptr +=2;
mi_int2store(ptr,keydef->minlength); ptr +=2;
mi_int2store(ptr,keydef->maxlength); ptr +=2;
- return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0;
+ return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0;
}
uchar *mi_keydef_read(uchar *ptr, MI_KEYDEF *keydef)
@@ -1142,7 +1148,7 @@ int mi_keyseg_write(File file, const HA_KEYSEG *keyseg)
mi_int4store(ptr, pos);
ptr+=4;
- return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0;
+ return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0;
}
@@ -1184,7 +1190,7 @@ uint mi_uniquedef_write(File file, MI_UNIQUEDEF *def)
*ptr++= (uchar) def->key;
*ptr++ = (uchar) def->null_are_equal;
- return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0;
+ return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0;
}
uchar *mi_uniquedef_read(uchar *ptr, MI_UNIQUEDEF *def)
@@ -1208,7 +1214,7 @@ uint mi_recinfo_write(File file, MI_COLUMNDEF *recinfo)
mi_int2store(ptr,recinfo->length); ptr +=2;
*ptr++ = recinfo->null_bit;
mi_int2store(ptr,recinfo->null_pos); ptr+= 2;
- return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0;
+ return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0;
}
uchar *mi_recinfo_read(uchar *ptr, MI_COLUMNDEF *recinfo)
@@ -1261,15 +1267,18 @@ int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, const char *org_name,
}
else
#endif
- info->dfile=my_open(data_name, share->mode | O_SHARE, MYF(MY_WME));
+ info->dfile= mysql_file_open(mi_key_file_dfile,
+ data_name, share->mode | O_SHARE, MYF(MY_WME));
return info->dfile >= 0 ? 0 : 1;
}
int mi_open_keyfile(MYISAM_SHARE *share)
{
- if ((share->kfile=my_open(share->unique_file_name, share->mode | O_SHARE,
- MYF(MY_WME))) < 0)
+ if ((share->kfile= mysql_file_open(mi_key_file_kfile,
+ share->unique_file_name,
+ share->mode | O_SHARE,
+ MYF(MY_WME))) < 0)
return 1;
return 0;
}
diff --git a/storage/myisam/mi_packrec.c b/storage/myisam/mi_packrec.c
index 5ef9aa7f88f..ee56d86f5ba 100644
--- a/storage/myisam/mi_packrec.c
+++ b/storage/myisam/mi_packrec.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -150,7 +150,7 @@ my_bool _mi_read_pack_info(MI_INFO *info, pbool fix_keys)
file=info->dfile;
my_errno=0;
- if (my_read(file,(uchar*) header,sizeof(header),MYF(MY_NABP)))
+ if (mysql_file_read(file, (uchar*) header, sizeof(header), MYF(MY_NABP)))
{
if (!my_errno)
my_errno=HA_ERR_END_OF_FILE;
@@ -224,9 +224,9 @@ my_bool _mi_read_pack_info(MI_INFO *info, pbool fix_keys)
tmp_buff=share->decode_tables+length;
disk_cache= (uchar*) (tmp_buff+OFFSET_TABLE_SIZE);
- if (my_read(file,disk_cache,
- (uint) (share->pack.header_length-sizeof(header)),
- MYF(MY_NABP)))
+ if (mysql_file_read(file, disk_cache,
+ (uint) (share->pack.header_length-sizeof(header)),
+ MYF(MY_NABP)))
goto err2;
huff_tree_bits=max_bit(trees ? trees-1 : 0);
@@ -717,8 +717,8 @@ int _mi_read_pack_record(MI_INFO *info, my_off_t filepos, uchar *buf)
if (_mi_pack_get_block_info(info, &info->bit_buff, &block_info,
&info->rec_buff, file, filepos))
goto err;
- if (my_read(file,(uchar*) info->rec_buff + block_info.offset ,
- block_info.rec_len - block_info.offset, MYF(MY_NABP)))
+ if (mysql_file_read(file, (uchar*) info->rec_buff + block_info.offset,
+ block_info.rec_len - block_info.offset, MYF(MY_NABP)))
goto panic;
info->update|= HA_STATE_AKTIV;
DBUG_RETURN(_mi_pack_rec_unpack(info, &info->bit_buff, buf,
@@ -1339,9 +1339,9 @@ int _mi_read_rnd_pack_record(MI_INFO *info, uchar *buf,
}
else
{
- if (my_read(info->dfile,(uchar*) info->rec_buff + block_info.offset,
- block_info.rec_len-block_info.offset,
- MYF(MY_NABP)))
+ if (mysql_file_read(info->dfile,
+ (uchar*) info->rec_buff + block_info.offset,
+ block_info.rec_len-block_info.offset, MYF(MY_NABP)))
goto err;
}
info->packed_length=block_info.rec_len;
@@ -1370,11 +1370,11 @@ uint _mi_pack_get_block_info(MI_INFO *myisam, MI_BIT_BUFF *bit_buff,
{
ref_length=myisam->s->pack.ref_length;
/*
- We can't use my_pread() here because mi_read_rnd_pack_record assumes
+ We can't use mysql_file_pread() here because mi_read_rnd_pack_record assumes
position is ok
*/
- VOID(my_seek(file,filepos,MY_SEEK_SET,MYF(0)));
- if (my_read(file, header,ref_length,MYF(MY_NABP)))
+ mysql_file_seek(file, filepos, MY_SEEK_SET, MYF(0));
+ if (mysql_file_read(file, header, ref_length, MYF(MY_NABP)))
return BLOCK_FATAL_ERROR;
DBUG_DUMP("header",(uchar*) header,ref_length);
}
@@ -1496,7 +1496,7 @@ my_bool _mi_memmap_file(MI_INFO *info)
if (!info->s->file_map)
{
- if (my_seek(info->dfile,0L,MY_SEEK_END,MYF(0)) <
+ if (mysql_file_seek(info->dfile, 0L, MY_SEEK_END, MYF(0)) <
share->state.state.data_file_length+MEMMAP_EXTRA_MARGIN)
{
DBUG_PRINT("warning",("File isn't extended for memmap"));
@@ -1516,8 +1516,8 @@ my_bool _mi_memmap_file(MI_INFO *info)
void _mi_unmap_file(MI_INFO *info)
{
- VOID(my_munmap((char*) info->s->file_map,
- (size_t) info->s->mmaped_length + MEMMAP_EXTRA_MARGIN));
+ (void) my_munmap((char*) info->s->file_map,
+ (size_t) info->s->mmaped_length + MEMMAP_EXTRA_MARGIN);
}
diff --git a/storage/myisam/mi_panic.c b/storage/myisam/mi_panic.c
index 74c93761b61..69865cfc0bb 100644
--- a/storage/myisam/mi_panic.c
+++ b/storage/myisam/mi_panic.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2001, 2003 MySQL AB
+/* Copyright (C) 2000-2001, 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -30,17 +30,17 @@ int mi_panic(enum ha_panic_function flag)
MI_INFO *info;
DBUG_ENTER("mi_panic");
- pthread_mutex_lock(&THR_LOCK_myisam);
+ mysql_mutex_lock(&THR_LOCK_myisam);
for (list_element=myisam_open_list ; list_element ; list_element=next_open)
{
next_open=list_element->next; /* Save if close */
info=(MI_INFO*) list_element->data;
switch (flag) {
case HA_PANIC_CLOSE:
- pthread_mutex_unlock(&THR_LOCK_myisam); /* Not exactly right... */
+ mysql_mutex_unlock(&THR_LOCK_myisam); /* Not exactly right... */
if (mi_close(info))
error=my_errno;
- pthread_mutex_lock(&THR_LOCK_myisam);
+ mysql_mutex_lock(&THR_LOCK_myisam);
break;
case HA_PANIC_WRITE: /* Do this to free databases */
#ifdef CANT_OPEN_FILES_TWICE
@@ -66,9 +66,9 @@ int mi_panic(enum ha_panic_function flag)
error=my_errno;
}
#ifdef CANT_OPEN_FILES_TWICE
- if (info->s->kfile >= 0 && my_close(info->s->kfile,MYF(0)))
+ if (info->s->kfile >= 0 && mysql_file_close(info->s->kfile, MYF(0)))
error = my_errno;
- if (info->dfile >= 0 && my_close(info->dfile,MYF(0)))
+ if (info->dfile >= 0 && mysql_file_close(info->dfile, MYF(0)))
error = my_errno;
info->s->kfile=info->dfile= -1; /* Files aren't open anymore */
break;
@@ -78,15 +78,19 @@ int mi_panic(enum ha_panic_function flag)
{ /* Open closed files */
char name_buff[FN_REFLEN];
if (info->s->kfile < 0)
- if ((info->s->kfile= my_open(fn_format(name_buff,info->filename,"",
- N_NAME_IEXT,4),info->mode,
- MYF(MY_WME))) < 0)
+ if ((info->s->kfile= mysql_file_open(mi_key_file_kfile,
+ fn_format(name_buff,
+ info->filename, "",
+ N_NAME_IEXT, 4),
+ info->mode, MYF(MY_WME))) < 0)
error = my_errno;
if (info->dfile < 0)
{
- if ((info->dfile= my_open(fn_format(name_buff,info->filename,"",
- N_NAME_DEXT,4),info->mode,
- MYF(MY_WME))) < 0)
+ if ((info->dfile= mysql_file_open(mi_key_file_dfile,
+ fn_format(name_buff,
+ info->filename, "",
+ N_NAME_DEXT, 4),
+ info->mode, MYF(MY_WME))) < 0)
error = my_errno;
info->rec_cache.file=info->dfile;
}
@@ -103,10 +107,10 @@ int mi_panic(enum ha_panic_function flag)
}
if (flag == HA_PANIC_CLOSE)
{
- VOID(mi_log(0)); /* Close log if neaded */
+ (void) mi_log(0); /* Close log if neaded */
ft_free_stopwords();
}
- pthread_mutex_unlock(&THR_LOCK_myisam);
+ mysql_mutex_unlock(&THR_LOCK_myisam);
if (!error)
DBUG_RETURN(0);
DBUG_RETURN(my_errno=error);
diff --git a/storage/myisam/mi_preload.c b/storage/myisam/mi_preload.c
index 60ab55106cb..ae45014eab5 100644
--- a/storage/myisam/mi_preload.c
+++ b/storage/myisam/mi_preload.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003, 2005 MySQL AB
+/* Copyright (C) 2003, 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -81,7 +81,8 @@ int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves)
/* Read the next block of index file into the preload buffer */
if ((my_off_t) length > (key_file_length-pos))
length= (ulong) (key_file_length-pos);
- if (my_pread(share->kfile, (uchar*) buff, length, pos, MYF(MY_FAE|MY_FNABP)))
+ if (mysql_file_pread(share->kfile, (uchar*) buff, length, pos,
+ MYF(MY_FAE|MY_FNABP)))
goto err;
if (ignore_leaves)
diff --git a/storage/myisam/mi_range.c b/storage/myisam/mi_range.c
index dc6dc9d62b7..927c511eec1 100644
--- a/storage/myisam/mi_range.c
+++ b/storage/myisam/mi_range.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2004, 2006 MySQL AB
+/* Copyright (C) 2000-2004, 2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -57,7 +57,7 @@ ha_rows mi_records_in_range(MI_INFO *info, int inx,
DBUG_RETURN(HA_POS_ERROR);
info->update&= (HA_STATE_CHANGED+HA_STATE_ROW_CHANGED);
if (info->s->concurrent_insert)
- rw_rdlock(&info->s->key_root_lock[inx]);
+ mysql_rwlock_rdlock(&info->s->key_root_lock[inx]);
switch(info->s->keyinfo[inx].key_alg){
#ifdef HAVE_RTREE_KEYS
@@ -106,7 +106,7 @@ ha_rows mi_records_in_range(MI_INFO *info, int inx,
}
if (info->s->concurrent_insert)
- rw_unlock(&info->s->key_root_lock[inx]);
+ mysql_rwlock_unlock(&info->s->key_root_lock[inx]);
fast_mi_writeinfo(info);
DBUG_PRINT("info",("records: %ld",(ulong) (res)));
diff --git a/storage/myisam/mi_rename.c b/storage/myisam/mi_rename.c
index 51669b0caa6..56ccb333d03 100644
--- a/storage/myisam/mi_rename.c
+++ b/storage/myisam/mi_rename.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2001, 2004 MySQL AB
+/* Copyright (C) 2000-2001, 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -47,7 +47,7 @@ int mi_rename(const char *old_name, const char *new_name)
fn_format(from,old_name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
fn_format(to,new_name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
- if (my_rename_with_symlink(from, to, MYF(MY_WME)))
+ if (mysql_file_rename_with_symlink(mi_key_file_kfile, from, to, MYF(MY_WME)))
DBUG_RETURN(my_errno);
fn_format(from,old_name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
fn_format(to,new_name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
@@ -56,5 +56,7 @@ int mi_rename(const char *old_name, const char *new_name)
DBUG_RETURN(my_raid_rename(from, to, raid_chunks, MYF(MY_WME)) ? my_errno :
0);
#endif
- DBUG_RETURN(my_rename_with_symlink(from, to,MYF(MY_WME)) ? my_errno : 0);
+ DBUG_RETURN(mysql_file_rename_with_symlink(mi_key_file_dfile,
+ from, to,
+ MYF(MY_WME)) ? my_errno : 0);
}
diff --git a/storage/myisam/mi_rkey.c b/storage/myisam/mi_rkey.c
index f1d35810d36..d3744c9a053 100644
--- a/storage/myisam/mi_rkey.c
+++ b/storage/myisam/mi_rkey.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -71,7 +71,7 @@ int mi_rkey(MI_INFO *info, uchar *buf, int inx, const uchar *key,
goto err;
if (share->concurrent_insert)
- rw_rdlock(&share->key_root_lock[inx]);
+ mysql_rwlock_rdlock(&share->key_root_lock[inx]);
nextflag=myisam_read_vec[search_flag];
use_key_length=pack_key_length;
@@ -156,7 +156,7 @@ int mi_rkey(MI_INFO *info, uchar *buf, int inx, const uchar *key,
}
}
if (share->concurrent_insert)
- rw_unlock(&share->key_root_lock[inx]);
+ mysql_rwlock_unlock(&share->key_root_lock[inx]);
/* Calculate length of the found key; Used by mi_rnext_same */
if ((keyinfo->flag & HA_VAR_LENGTH_KEY) && last_used_keyseg &&
diff --git a/storage/myisam/mi_rnext.c b/storage/myisam/mi_rnext.c
index 7ce66d41e0f..6def5749043 100644
--- a/storage/myisam/mi_rnext.c
+++ b/storage/myisam/mi_rnext.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2004 MySQL AB
+/* Copyright (C) 2000-2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -39,7 +39,7 @@ int mi_rnext(MI_INFO *info, uchar *buf, int inx)
if (fast_mi_readinfo(info))
DBUG_RETURN(my_errno);
if (info->s->concurrent_insert)
- rw_rdlock(&info->s->key_root_lock[inx]);
+ mysql_rwlock_rdlock(&info->s->key_root_lock[inx]);
changed=_mi_test_if_changed(info);
if (!flag)
{
@@ -96,7 +96,7 @@ int mi_rnext(MI_INFO *info, uchar *buf, int inx)
break;
}
}
- rw_unlock(&info->s->key_root_lock[inx]);
+ mysql_rwlock_unlock(&info->s->key_root_lock[inx]);
}
/* Don't clear if database-changed */
info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
diff --git a/storage/myisam/mi_rnext_same.c b/storage/myisam/mi_rnext_same.c
index 1892fe3e1e0..6779709fc80 100644
--- a/storage/myisam/mi_rnext_same.c
+++ b/storage/myisam/mi_rnext_same.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -38,7 +38,7 @@ int mi_rnext_same(MI_INFO *info, uchar *buf)
DBUG_RETURN(my_errno);
if (info->s->concurrent_insert)
- rw_rdlock(&info->s->key_root_lock[inx]);
+ mysql_rwlock_rdlock(&info->s->key_root_lock[inx]);
switch (keyinfo->key_alg)
{
@@ -81,7 +81,7 @@ int mi_rnext_same(MI_INFO *info, uchar *buf)
}
}
if (info->s->concurrent_insert)
- rw_unlock(&info->s->key_root_lock[inx]);
+ mysql_rwlock_unlock(&info->s->key_root_lock[inx]);
/* Don't clear if database-changed */
info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
info->update|= HA_STATE_NEXT_FOUND | HA_STATE_RNEXT_SAME;
diff --git a/storage/myisam/mi_rprev.c b/storage/myisam/mi_rprev.c
index d1407012590..f7dddefb647 100644
--- a/storage/myisam/mi_rprev.c
+++ b/storage/myisam/mi_rprev.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2001, 2004 MySQL AB
+/* Copyright (C) 2000-2001, 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -39,7 +39,7 @@ int mi_rprev(MI_INFO *info, uchar *buf, int inx)
DBUG_RETURN(my_errno);
changed=_mi_test_if_changed(info);
if (share->concurrent_insert)
- rw_rdlock(&share->key_root_lock[inx]);
+ mysql_rwlock_rdlock(&share->key_root_lock[inx]);
if (!flag)
error=_mi_search_last(info, share->keyinfo+inx,
share->state.key_root[inx]);
@@ -65,7 +65,7 @@ int mi_rprev(MI_INFO *info, uchar *buf, int inx)
break;
}
}
- rw_unlock(&share->key_root_lock[inx]);
+ mysql_rwlock_unlock(&share->key_root_lock[inx]);
}
info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
info->update|= HA_STATE_PREV_FOUND;
diff --git a/storage/myisam/mi_rsame.c b/storage/myisam/mi_rsame.c
index 8093498483f..ea41dc73c92 100644
--- a/storage/myisam/mi_rsame.c
+++ b/storage/myisam/mi_rsame.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2001, 2005 MySQL AB
+/* Copyright (C) 2000-2001, 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -49,12 +49,12 @@ int mi_rsame(MI_INFO *info, uchar *record, int inx)
info->lastkey_length=_mi_make_key(info,(uint) inx,info->lastkey,record,
info->lastpos);
if (info->s->concurrent_insert)
- rw_rdlock(&info->s->key_root_lock[inx]);
- VOID(_mi_search(info,info->s->keyinfo+inx,info->lastkey, USE_WHOLE_KEY,
+ mysql_rwlock_rdlock(&info->s->key_root_lock[inx]);
+ (void) _mi_search(info,info->s->keyinfo+inx,info->lastkey, USE_WHOLE_KEY,
SEARCH_SAME,
- info->s->state.key_root[inx]));
+ info->s->state.key_root[inx]);
if (info->s->concurrent_insert)
- rw_unlock(&info->s->key_root_lock[inx]);
+ mysql_rwlock_unlock(&info->s->key_root_lock[inx]);
}
if (!(*info->read_record)(info,info->lastpos,record))
diff --git a/storage/myisam/mi_static.c b/storage/myisam/mi_static.c
index a3ba785a94f..aaa7405bbb5 100644
--- a/storage/myisam/mi_static.c
+++ b/storage/myisam/mi_static.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2002, 2004-2005 MySQL AB
+/* Copyright (C) 2000-2002, 2004-2005 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -68,3 +68,74 @@ uint NEAR myisam_readnext_vec[]=
SEARCH_BIGGER, SEARCH_BIGGER, SEARCH_SMALLER, SEARCH_BIGGER, SEARCH_SMALLER,
SEARCH_BIGGER, SEARCH_SMALLER, SEARCH_SMALLER
};
+
+#ifdef HAVE_PSI_INTERFACE
+PSI_mutex_key mi_key_mutex_MYISAM_SHARE_intern_lock,
+ mi_key_mutex_MI_SORT_INFO_mutex, mi_key_mutex_MI_CHECK_print_msg;
+
+static PSI_mutex_info all_myisam_mutexes[]=
+{
+ { &mi_key_mutex_MI_SORT_INFO_mutex, "MI_SORT_INFO::mutex", 0},
+ { &mi_key_mutex_MYISAM_SHARE_intern_lock, "MYISAM_SHARE::intern_lock", 0},
+ { &mi_key_mutex_MI_CHECK_print_msg, "MI_CHECK::print_msg", 0}
+};
+
+PSI_rwlock_key mi_key_rwlock_MYISAM_SHARE_key_root_lock,
+ mi_key_rwlock_MYISAM_SHARE_mmap_lock;
+
+static PSI_rwlock_info all_myisam_rwlocks[]=
+{
+ { &mi_key_rwlock_MYISAM_SHARE_key_root_lock, "MYISAM_SHARE::key_root_lock", 0},
+ { &mi_key_rwlock_MYISAM_SHARE_mmap_lock, "MYISAM_SHARE::mmap_lock", 0}
+};
+
+PSI_cond_key mi_key_cond_MI_SORT_INFO_cond;
+
+static PSI_cond_info all_myisam_conds[]=
+{
+ { &mi_key_cond_MI_SORT_INFO_cond, "MI_SORT_INFO::cond", 0}
+};
+
+PSI_file_key mi_key_file_datatmp, mi_key_file_dfile, mi_key_file_kfile,
+ mi_key_file_log;
+
+static PSI_file_info all_myisam_files[]=
+{
+ { & mi_key_file_datatmp, "data_tmp", 0},
+ { & mi_key_file_dfile, "dfile", 0},
+ { & mi_key_file_kfile, "kfile", 0},
+ { & mi_key_file_log, "log", 0}
+};
+
+PSI_thread_key mi_key_thread_find_all_keys;
+
+static PSI_thread_info all_myisam_threads[]=
+{
+ { &mi_key_thread_find_all_keys, "find_all_keys", 0},
+};
+
+void init_myisam_psi_keys()
+{
+ const char* category= "myisam";
+ int count;
+
+ if (PSI_server == NULL)
+ return;
+
+ count= array_elements(all_myisam_mutexes);
+ PSI_server->register_mutex(category, all_myisam_mutexes, count);
+
+ count= array_elements(all_myisam_rwlocks);
+ PSI_server->register_rwlock(category, all_myisam_rwlocks, count);
+
+ count= array_elements(all_myisam_conds);
+ PSI_server->register_cond(category, all_myisam_conds, count);
+
+ count= array_elements(all_myisam_files);
+ PSI_server->register_file(category, all_myisam_files, count);
+
+ count= array_elements(all_myisam_threads);
+ PSI_server->register_thread(category, all_myisam_threads, count);
+}
+#endif /* HAVE_PSI_INTERFACE */
+
diff --git a/storage/myisam/mi_statrec.c b/storage/myisam/mi_statrec.c
index e3771560c01..74fca5902f5 100644
--- a/storage/myisam/mi_statrec.c
+++ b/storage/myisam/mi_statrec.c
@@ -282,7 +282,7 @@ int _mi_read_rnd_static_record(MI_INFO *info, uchar *buf,
info->s->base.pack_reclength - info->s->base.reclength);
}
if (locked)
- VOID(_mi_writeinfo(info,0)); /* Unlock keyfile */
+ (void) _mi_writeinfo(info,0); /* Unlock keyfile */
if (!error)
{
if (!buf[0])
diff --git a/storage/myisam/mi_test1.c b/storage/myisam/mi_test1.c
index f218bf4e77f..728ac9514fd 100644
--- a/storage/myisam/mi_test1.c
+++ b/storage/myisam/mi_test1.c
@@ -161,7 +161,7 @@ static int run_test(const char *filename)
row_count=deleted=0;
for (i=49 ; i>=1 ; i-=2 )
{
- if (insert_count-- == 0) { VOID(mi_close(file)) ; exit(0) ; }
+ if (insert_count-- == 0) { (void) mi_close(file); exit(0) ; }
j=i%25 +1;
create_record(record,j);
error=mi_write(file,record);
@@ -225,7 +225,7 @@ static int run_test(const char *filename)
found=0;
while ((error=mi_rrnd(file,read_record,pos)) == 0)
{
- if (update_count-- == 0) { VOID(mi_close(file)) ; exit(0) ; }
+ if (update_count-- == 0) { (void) mi_close(file); exit(0) ; }
memcpy(record,read_record,rec_length);
update_record(record);
if (mi_update(file,read_record,record))
@@ -252,7 +252,7 @@ static int run_test(const char *filename)
for (i=0 ; i <= 10 ; i++)
{
/* testing */
- if (remove_count-- == 0) { VOID(mi_close(file)) ; exit(0) ; }
+ if (remove_count-- == 0) { (void) mi_close(file); exit(0) ; }
j=i*2;
if (!flags[j])
continue;
@@ -679,3 +679,5 @@ static void usage()
my_print_help(my_long_options);
my_print_variables(my_long_options);
}
+
+#include "mi_extrafunc.h"
diff --git a/storage/myisam/mi_test2.c b/storage/myisam/mi_test2.c
index 23c58638166..63525b08820 100644
--- a/storage/myisam/mi_test2.c
+++ b/storage/myisam/mi_test2.c
@@ -862,7 +862,7 @@ reads: %10lu\n",
err:
printf("got error: %d when using MyISAM-database\n",my_errno);
if (file)
- VOID(mi_close(file));
+ (void) mi_close(file);
return(1);
} /* main */
@@ -1055,3 +1055,5 @@ static void copy_key(MI_INFO *info,uint inx,uchar *rec,uchar *key_buff)
}
return;
}
+
+#include "mi_extrafunc.h"
diff --git a/storage/myisam/mi_test3.c b/storage/myisam/mi_test3.c
index 5bdc33b8518..7b16d6c05d6 100644
--- a/storage/myisam/mi_test3.c
+++ b/storage/myisam/mi_test3.c
@@ -109,7 +109,7 @@ int main(int argc,char **argv)
sleep(1);
return 0;
}
- VOID(rnd(1));
+ (void) rnd(1);
}
for (i=0 ; i < forks ; i++)
@@ -488,6 +488,8 @@ int test_update(MI_INFO *file,int id,int lock_type)
return 0;
}
+#include "mi_extrafunc.h"
+
#else /* __NETWARE__ */
#include <stdio.h>
diff --git a/storage/myisam/mi_update.c b/storage/myisam/mi_update.c
index a18bb5f1443..b538bcd0bb1 100644
--- a/storage/myisam/mi_update.c
+++ b/storage/myisam/mi_update.c
@@ -178,7 +178,7 @@ int mi_update(register MI_INFO *info, const uchar *oldrec, uchar *newrec)
mi_update() must always pass !0 value as operation, since even if
there is no index change there could be data change.
*/
- VOID(_mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE));
+ (void) _mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE);
allow_break(); /* Allow SIGHUP & SIGINT */
if (info->invalidator != 0)
{
@@ -229,7 +229,7 @@ err:
err_end:
myisam_log_record(MI_LOG_UPDATE,info,newrec,info->lastpos,my_errno);
- VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
+ (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
allow_break(); /* Allow SIGHUP & SIGINT */
if (save_errno == HA_ERR_KEY_NOT_FOUND)
{
diff --git a/storage/myisam/mi_write.c b/storage/myisam/mi_write.c
index 624c31e57ff..4293d9b5269 100644
--- a/storage/myisam/mi_write.c
+++ b/storage/myisam/mi_write.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -107,7 +107,7 @@ int mi_write(MI_INFO *info, uchar *record)
is_tree_inited(&info->bulk_insert[i])));
if (local_lock_tree)
{
- rw_wrlock(&share->key_root_lock[i]);
+ mysql_rwlock_wrlock(&share->key_root_lock[i]);
share->keyinfo[i].version++;
}
if (share->keyinfo[i].flag & HA_FULLTEXT )
@@ -115,7 +115,7 @@ int mi_write(MI_INFO *info, uchar *record)
if (_mi_ft_add(info,i, buff, record, filepos))
{
if (local_lock_tree)
- rw_unlock(&share->key_root_lock[i]);
+ mysql_rwlock_unlock(&share->key_root_lock[i]);
DBUG_PRINT("error",("Got error: %d on write",my_errno));
goto err;
}
@@ -126,7 +126,7 @@ int mi_write(MI_INFO *info, uchar *record)
_mi_make_key(info,i,buff,record,filepos)))
{
if (local_lock_tree)
- rw_unlock(&share->key_root_lock[i]);
+ mysql_rwlock_unlock(&share->key_root_lock[i]);
DBUG_PRINT("error",("Got error: %d on write",my_errno));
goto err;
}
@@ -136,7 +136,7 @@ int mi_write(MI_INFO *info, uchar *record)
info->update&= ~HA_STATE_RNEXT_SAME;
if (local_lock_tree)
- rw_unlock(&share->key_root_lock[i]);
+ mysql_rwlock_unlock(&share->key_root_lock[i]);
}
}
if (share->calc_checksum)
@@ -155,7 +155,7 @@ int mi_write(MI_INFO *info, uchar *record)
info->state->records++;
info->lastpos=filepos;
myisam_log_record(MI_LOG_WRITE,info,record,filepos,0);
- VOID(_mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE));
+ (void) _mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE);
if (info->invalidator != 0)
{
DBUG_PRINT("info", ("invalidator... '%s' (update)", info->filename));
@@ -197,13 +197,13 @@ err:
!(info->bulk_insert &&
is_tree_inited(&info->bulk_insert[i])));
if (local_lock_tree)
- rw_wrlock(&share->key_root_lock[i]);
+ mysql_rwlock_wrlock(&share->key_root_lock[i]);
if (share->keyinfo[i].flag & HA_FULLTEXT)
{
if (_mi_ft_del(info,i, buff,record,filepos))
{
if (local_lock_tree)
- rw_unlock(&share->key_root_lock[i]);
+ mysql_rwlock_unlock(&share->key_root_lock[i]);
break;
}
}
@@ -213,12 +213,12 @@ err:
if (_mi_ck_delete(info,i,buff,key_length))
{
if (local_lock_tree)
- rw_unlock(&share->key_root_lock[i]);
+ mysql_rwlock_unlock(&share->key_root_lock[i]);
break;
}
}
if (local_lock_tree)
- rw_unlock(&share->key_root_lock[i]);
+ mysql_rwlock_unlock(&share->key_root_lock[i]);
}
}
}
@@ -232,7 +232,7 @@ err:
err2:
save_errno=my_errno;
myisam_log_record(MI_LOG_WRITE,info,record,filepos,my_errno);
- VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
+ (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
allow_break(); /* Allow SIGHUP & SIGINT */
DBUG_RETURN(my_errno=save_errno);
} /* mi_write */
@@ -943,7 +943,7 @@ static int keys_free(uchar *key, TREE_FREE mode, bulk_insert_param *param)
case free_init:
if (param->info->s->concurrent_insert)
{
- rw_wrlock(&param->info->s->key_root_lock[param->keynr]);
+ mysql_rwlock_wrlock(&param->info->s->key_root_lock[param->keynr]);
param->info->s->keyinfo[param->keynr].version++;
}
return 0;
@@ -955,7 +955,7 @@ static int keys_free(uchar *key, TREE_FREE mode, bulk_insert_param *param)
keylen - param->info->s->rec_reflength);
case free_end:
if (param->info->s->concurrent_insert)
- rw_unlock(&param->info->s->key_root_lock[param->keynr]);
+ mysql_rwlock_unlock(&param->info->s->key_root_lock[param->keynr]);
return 0;
}
return -1;
diff --git a/storage/myisam/myisam_ftdump.c b/storage/myisam/myisam_ftdump.c
index 63d954242a0..7c14ae37de2 100644
--- a/storage/myisam/myisam_ftdump.c
+++ b/storage/myisam/myisam_ftdump.c
@@ -274,3 +274,5 @@ static void complain(int val) /* Kinda assert :-) */
exit(1);
}
}
+
+#include "mi_extrafunc.h"
diff --git a/storage/myisam/myisamchk.c b/storage/myisam/myisamchk.c
index de0e53e6a36..e4eccdc1dc6 100644
--- a/storage/myisam/myisamchk.c
+++ b/storage/myisam/myisamchk.c
@@ -99,8 +99,8 @@ int main(int argc, char **argv)
int new_error=myisamchk(&check_param, *(argv++));
if ((check_param.testflag & T_REP_ANY) != T_REP)
check_param.testflag&= ~T_REP;
- VOID(fflush(stdout));
- VOID(fflush(stderr));
+ (void) fflush(stdout);
+ (void) fflush(stderr);
if ((check_param.error_printed | check_param.warning_printed) &&
(check_param.testflag & T_FORCE_CREATE) &&
(!(check_param.testflag & (T_REP | T_REP_BY_SORT | T_SORT_RECORDS |
@@ -112,15 +112,15 @@ int main(int argc, char **argv)
check_param.testflag&= ~T_EXTEND; /* Don't needed */
error|=myisamchk(&check_param, argv[-1]);
check_param.testflag= old_testflag;
- VOID(fflush(stdout));
- VOID(fflush(stderr));
+ (void) fflush(stdout);
+ (void) fflush(stderr);
}
else
error|=new_error;
if (argc && (!(check_param.testflag & T_SILENT) || check_param.testflag & T_INFO))
{
puts("\n---------\n");
- VOID(fflush(stdout));
+ (void) fflush(stdout);
}
}
if (check_param.total_files > 1)
@@ -764,9 +764,9 @@ static void get_options(register int *argc,register char ***argv)
if ((check_param.testflag & T_UNPACK) &&
(check_param.testflag & (T_QUICK | T_SORT_RECORDS)))
{
- VOID(fprintf(stderr,
+ (void) fprintf(stderr,
"%s: --unpack can't be used with --quick or --sort-records\n",
- my_progname_short));
+ my_progname_short);
exit(1);
}
if ((check_param.testflag & T_READONLY) &&
@@ -774,9 +774,9 @@ static void get_options(register int *argc,register char ***argv)
(T_REP_ANY | T_STATISTICS | T_AUTO_INC |
T_SORT_RECORDS | T_SORT_INDEX | T_FORCE_CREATE)))
{
- VOID(fprintf(stderr,
+ (void) fprintf(stderr,
"%s: Can't use --readonly when repairing or sorting\n",
- my_progname_short));
+ my_progname_short);
exit(1);
}
@@ -930,9 +930,9 @@ static int myisamchk(MI_CHECK *param, char * filename)
param->language= set_collation->number;
if (recreate_table(param, &info,filename))
{
- VOID(fprintf(stderr,
+ (void) fprintf(stderr,
"MyISAM-table '%s' is not fixed because of errors\n",
- filename));
+ filename);
return(-1);
}
recreate=1;
@@ -1032,7 +1032,7 @@ static int myisamchk(MI_CHECK *param, char * filename)
#ifndef TO_BE_REMOVED
if (param->out_flag & O_NEW_DATA)
{ /* Change temp file to org file */
- VOID(my_close(info->dfile,MYF(MY_WME))); /* Close new file */
+ (void) my_close(info->dfile,MYF(MY_WME)); /* Close new file */
error|=change_to_newfile(filename,MI_NAME_DEXT,DATA_TMP_EXT,
raid_chunks,
MYF(0));
@@ -1103,23 +1103,23 @@ static int myisamchk(MI_CHECK *param, char * filename)
!(param->testflag & (T_FAST | T_FORCE_CREATE)))
{
if (param->testflag & (T_EXTEND | T_MEDIUM))
- VOID(init_key_cache(dflt_key_cache,opt_key_cache_block_size,
- (size_t) param->use_buffers, 0, 0));
- VOID(init_io_cache(&param->read_cache,datafile,
+ (void) init_key_cache(dflt_key_cache,opt_key_cache_block_size,
+ param->use_buffers, 0, 0);
+ (void) init_io_cache(&param->read_cache,datafile,
(uint) param->read_buffer_length,
READ_CACHE,
(param->start_check_pos ?
param->start_check_pos :
share->pack.header_length),
1,
- MYF(MY_WME)));
+ MYF(MY_WME));
lock_memory(param);
if ((info->s->options & (HA_OPTION_PACK_RECORD |
HA_OPTION_COMPRESS_RECORD)) ||
(param->testflag & (T_EXTEND | T_MEDIUM)))
error|=chk_data_link(param, info, param->testflag & T_EXTEND);
error|=flush_blocks(param, share->key_cache, share->kfile);
- VOID(end_io_cache(&param->read_cache));
+ (void) end_io_cache(&param->read_cache);
}
if (!error)
{
@@ -1152,7 +1152,7 @@ static int myisamchk(MI_CHECK *param, char * filename)
(state_updated ? UPDATE_STAT : 0) |
((param->testflag & T_SORT_RECORDS) ?
UPDATE_SORT : 0)));
- VOID(lock_file(param, share->kfile,0L,F_UNLCK,"indexfile",filename));
+ (void) lock_file(param, share->kfile,0L,F_UNLCK,"indexfile",filename);
info->update&= ~HA_STATE_CHANGED;
}
mi_lock_database(info, F_UNLCK);
@@ -1173,30 +1173,30 @@ end2:
error|=change_to_newfile(filename,MI_NAME_IEXT,INDEX_TMP_EXT,0,
MYF(0));
}
- VOID(fflush(stdout)); VOID(fflush(stderr));
+ (void) fflush(stdout); (void) fflush(stderr);
if (param->error_printed)
{
if (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX))
{
- VOID(fprintf(stderr,
+ (void) fprintf(stderr,
"MyISAM-table '%s' is not fixed because of errors\n",
- filename));
+ filename);
if (param->testflag & T_REP_ANY)
- VOID(fprintf(stderr,
- "Try fixing it by using the --safe-recover (-o), the --force (-f) option or by not using the --quick (-q) flag\n"));
+ (void) fprintf(stderr,
+ "Try fixing it by using the --safe-recover (-o), the --force (-f) option or by not using the --quick (-q) flag\n");
}
else if (!(param->error_printed & 2) &&
!(param->testflag & T_FORCE_CREATE))
- VOID(fprintf(stderr,
+ (void) fprintf(stderr,
"MyISAM-table '%s' is corrupted\nFix it using switch \"-r\" or \"-o\"\n",
- filename));
+ filename);
}
else if (param->warning_printed &&
! (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX |
T_FORCE_CREATE)))
- VOID(fprintf(stderr, "MyISAM-table '%s' is usable but should be fixed\n",
- filename));
- VOID(fflush(stderr));
+ (void) fprintf(stderr, "MyISAM-table '%s' is usable but should be fixed\n",
+ filename);
+ (void) fflush(stderr);
DBUG_RETURN(error);
} /* myisamchk */
@@ -1323,7 +1323,7 @@ static void descript(MI_CHECK *param, register MI_INFO *info, char * name)
printf("Key Start Len Index Type");
if (param->testflag & T_VERBOSE)
printf(" Rec/key Root Blocksize");
- VOID(putchar('\n'));
+ (void) putchar('\n');
for (key=keyseg_nr=0, keyinfo= &share->keyinfo[0] ;
key < share->base.keys;
@@ -1362,7 +1362,7 @@ static void descript(MI_CHECK *param, register MI_INFO *info, char * name)
printf("%11lu %12s %10d",
share->state.rec_per_key_part[keyseg_nr++],
buff,keyinfo->block_length);
- VOID(putchar('\n'));
+ (void) putchar('\n');
while ((++keyseg)->type != HA_KEYTYPE_END)
{
pos=buff;
@@ -1381,7 +1381,7 @@ static void descript(MI_CHECK *param, register MI_INFO *info, char * name)
(long) keyseg->start+1,keyseg->length,buff);
if (param->testflag & T_VERBOSE)
printf("%11lu", share->state.rec_per_key_part[keyseg_nr++]);
- VOID(putchar('\n'));
+ (void) putchar('\n');
}
keyseg++;
}
@@ -1419,7 +1419,7 @@ static void descript(MI_CHECK *param, register MI_INFO *info, char * name)
printf("\nField Start Length Nullpos Nullbit Type");
if (share->options & HA_OPTION_COMPRESS_RECORD)
printf(" Huff tree Bits");
- VOID(putchar('\n'));
+ (void) putchar('\n');
start=1;
for (field=0 ; field < share->base.fields ; field++)
{
@@ -1458,7 +1458,7 @@ static void descript(MI_CHECK *param, register MI_INFO *info, char * name)
(uint) (share->rec[field].huff_tree-share->decode_trees)+1,
share->rec[field].huff_tree->quick_table_bits);
}
- VOID(putchar('\n'));
+ (void) putchar('\n');
start+=share->rec[field].length;
}
}
@@ -1606,7 +1606,7 @@ static int mi_sort_records(MI_CHECK *param,
goto err;
}
- VOID(my_close(info->dfile,MYF(MY_WME)));
+ (void) my_close(info->dfile,MYF(MY_WME));
param->out_flag|=O_NEW_DATA; /* Data in new file */
info->dfile=new_file; /* Use new datafile */
info->state->del=0;
@@ -1620,14 +1620,14 @@ static int mi_sort_records(MI_CHECK *param,
if (param->testflag & T_WRITE_LOOP)
{
- VOID(fputs(" \r",stdout)); VOID(fflush(stdout));
+ (void) fputs(" \r",stdout); (void) fflush(stdout);
}
got_error=0;
err:
if (got_error && new_file >= 0)
{
- VOID(end_io_cache(&info->rec_cache));
+ (void) end_io_cache(&info->rec_cache);
(void) my_close(new_file,MYF(MY_WME));
(void) my_raid_delete(param->temp_filename, share->base.raid_chunks,
MYF(MY_WME));
@@ -1639,7 +1639,7 @@ err:
my_free(mi_get_rec_buff_ptr(info, sort_param.record),
MYF(MY_ALLOW_ZERO_PTR));
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
- VOID(end_io_cache(&info->rec_cache));
+ (void) end_io_cache(&info->rec_cache);
my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR));
sort_info.buff=0;
share->state.sortkey=sort_key;
@@ -1763,8 +1763,8 @@ void mi_check_print_info(MI_CHECK *param __attribute__((unused)),
va_list args;
va_start(args,fmt);
- VOID(vfprintf(stdout, fmt, args));
- VOID(fputc('\n',stdout));
+ (void) vfprintf(stdout, fmt, args);
+ (void) fputc('\n',stdout);
va_end(args);
}
@@ -1786,8 +1786,8 @@ void mi_check_print_warning(MI_CHECK *param, const char *fmt,...)
param->warning_printed=1;
va_start(args,fmt);
fprintf(stderr,"%s: warning: ",my_progname_short);
- VOID(vfprintf(stderr, fmt, args));
- VOID(fputc('\n',stderr));
+ (void) vfprintf(stderr, fmt, args);
+ (void) fputc('\n',stderr);
fflush(stderr);
va_end(args);
DBUG_VOID_RETURN;
@@ -1811,9 +1811,11 @@ void mi_check_print_error(MI_CHECK *param, const char *fmt,...)
param->error_printed|=1;
va_start(args,fmt);
fprintf(stderr,"%s: error: ",my_progname_short);
- VOID(vfprintf(stderr, fmt, args));
- VOID(fputc('\n',stderr));
+ (void) vfprintf(stderr, fmt, args);
+ (void) fputc('\n',stderr);
fflush(stderr);
va_end(args);
DBUG_VOID_RETURN;
}
+
+#include "mi_extrafunc.h"
diff --git a/storage/myisam/myisamdef.h b/storage/myisam/myisamdef.h
index b64c7f6bd7f..43746975232 100644
--- a/storage/myisam/myisamdef.h
+++ b/storage/myisam/myisamdef.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -24,6 +24,7 @@
#else
#include <my_no_pthread.h>
#endif
+#include <mysql/psi/mysql_file.h>
#if defined(my_write) && !defined(MAP_TO_USE_RAID)
#undef my_write /* undef map from my_nosys; We need test-if-disk full */
@@ -165,6 +166,7 @@ typedef struct st_mi_isam_share { /* Shared between opens */
MI_COLUMNDEF *rec; /* Pointer to field information */
MI_PACK pack; /* Data about packed records */
MI_BLOB *blobs; /* Pointer to blobs */
+ LIST *in_use; /* List of threads using this table */
char *unique_file_name; /* realpath() of index file */
char *data_file_name, /* Resolved path names from symlinks */
*index_file_name;
@@ -213,13 +215,13 @@ typedef struct st_mi_isam_share { /* Shared between opens */
concurrent_insert;
#ifdef THREAD
THR_LOCK lock;
- pthread_mutex_t intern_lock; /* Locking for use with _locking */
- rw_lock_t *key_root_lock;
+ mysql_mutex_t intern_lock; /* Locking for use with _locking */
+ mysql_rwlock_t *key_root_lock;
#endif
my_off_t mmaped_length;
uint nonmmaped_inserts; /* counter of writing in non-mmaped
area */
- rw_lock_t mmap_lock;
+ mysql_rwlock_t mmap_lock;
} MYISAM_SHARE;
@@ -242,6 +244,7 @@ struct st_myisam_info {
DYNAMIC_ARRAY *ft1_to_ft2; /* used only in ft1->ft2 conversion */
MEM_ROOT ft_memroot; /* used by the parser */
MYSQL_FTPARSER_PARAM *ftparser_param; /* share info between init/deinit */
+ LIST in_use; /* Thread using this table */
char *filename; /* parameter to open filename */
uchar *buff, /* Temp area for key */
*lastkey,*lastkey2; /* Last used search key */
@@ -385,8 +388,10 @@ typedef struct st_mi_sort_param
#define mi_putint(x,y,nod) { uint16 boh=(nod ? (uint16) 32768 : 0) + (uint16) (y);\
mi_int2store(x,boh); }
#define mi_test_if_nod(x) (x[0] & 128 ? info->s->base.key_reflength : 0)
+#define mi_report_crashed(A, B) _mi_report_crashed((A), (B), __FILE__, __LINE__)
#define mi_mark_crashed(x) do{(x)->s->state.changed|= STATE_CRASHED; \
DBUG_PRINT("error", ("Marked table crashed")); \
+ mi_report_crashed((x), 0); \
}while(0)
#define mi_mark_crashed_on_repair(x) do{(x)->s->state.changed|= \
STATE_CRASHED|STATE_CRASHED_ON_REPAIR; \
@@ -460,12 +465,12 @@ typedef struct st_mi_sort_param
#define mi_unique_store(A,B) mi_int4store((A),(B))
#ifdef THREAD
-extern pthread_mutex_t THR_LOCK_myisam;
+extern mysql_mutex_t THR_LOCK_myisam;
#endif
#if !defined(THREAD) || defined(DONT_USE_RW_LOCKS)
-#define rw_wrlock(A) {}
-#define rw_rdlock(A) {}
-#define rw_unlock(A) {}
+#define mysql_rwlock_wrlock(A) {}
+#define mysql_rwlock_rdlock(A) {}
+#define mysql_rwlock_unlock(A) {}
#endif
/* Some extern variables */
@@ -764,6 +769,8 @@ int mi_open_keyfile(MYISAM_SHARE *share);
void mi_setup_functions(register MYISAM_SHARE *share);
my_bool mi_dynmap_file(MI_INFO *info, my_off_t size);
void mi_remap_file(MI_INFO *info, my_off_t size);
+void _mi_report_crashed(MI_INFO *file, const char *message,
+ const char *sfile, uint sline);
/* Functions needed by mi_check */
volatile int *killed_ptr(MI_CHECK *param);
@@ -785,3 +792,22 @@ int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, ulong);
}
#endif
+#ifdef HAVE_PSI_INTERFACE
+C_MODE_START
+extern PSI_mutex_key mi_key_mutex_MYISAM_SHARE_intern_lock,
+ mi_key_mutex_MI_SORT_INFO_mutex, mi_key_mutex_MI_CHECK_print_msg;
+
+extern PSI_rwlock_key mi_key_rwlock_MYISAM_SHARE_key_root_lock,
+ mi_key_rwlock_MYISAM_SHARE_mmap_lock;
+
+extern PSI_cond_key mi_key_cond_MI_SORT_INFO_cond;
+
+extern PSI_file_key mi_key_file_datatmp, mi_key_file_dfile, mi_key_file_kfile,
+ mi_key_file_log;
+
+extern PSI_thread_key mi_key_thread_find_all_keys;
+
+void init_myisam_psi_keys();
+C_MODE_END
+#endif /* HAVE_PSI_INTERFACE */
+
diff --git a/storage/myisam/myisamlog.c b/storage/myisam/myisamlog.c
index fafb5140a5e..b2699d66f84 100644
--- a/storage/myisam/myisamlog.c
+++ b/storage/myisam/myisamlog.c
@@ -121,7 +121,7 @@ int main(int argc, char **argv)
if (re_open_count)
printf("Had to do %d re-open because of too few possibly open files\n",
re_open_count);
- VOID(mi_panic(HA_PANIC_CLOSE));
+ (void) mi_panic(HA_PANIC_CLOSE);
my_free_open_file_info();
my_end(test_info ? MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR);
exit(error);
@@ -292,8 +292,8 @@ static void get_options(register int *argc, register char ***argv)
}
return;
err:
- VOID(fprintf(stderr,"option \"%c\" used without or with wrong argument\n",
- option));
+ (void) fprintf(stderr,"option \"%c\" used without or with wrong argument\n",
+ option);
exit(1);
}
@@ -332,8 +332,8 @@ static int examine_log(char * file_name, char **table_names)
bzero((uchar*) com_count,sizeof(com_count));
init_tree(&tree,0,0,sizeof(file_info),(qsort_cmp2) file_info_compare,1,
(tree_element_free) file_info_free, NULL);
- VOID(init_key_cache(dflt_key_cache,KEY_CACHE_BLOCK_SIZE,KEY_CACHE_SIZE,
- 0, 0));
+ (void) init_key_cache(dflt_key_cache,KEY_CACHE_BLOCK_SIZE,KEY_CACHE_SIZE,
+ 0, 0);
files_open=0; access_time=0;
while (access_time++ != number_of_commands &&
@@ -412,8 +412,8 @@ static int examine_log(char * file_name, char **table_names)
}
open_param.name=file_info.name;
open_param.max_id=0;
- VOID(tree_walk(&tree,(tree_walk_action) test_if_open,(void*) &open_param,
- left_root_right));
+ (void) tree_walk(&tree,(tree_walk_action) test_if_open,(void*) &open_param,
+ left_root_right);
file_info.id=open_param.max_id+1;
/*
* In the line below +10 is added to accomodate '<' and '>' chars
@@ -458,7 +458,7 @@ static int examine_log(char * file_name, char **table_names)
files_open++;
file_info.closed=0;
}
- VOID(tree_insert(&tree, (uchar*) &file_info, 0, tree.custom_arg));
+ (void) tree_insert(&tree, (uchar*) &file_info, 0, tree.custom_arg);
if (file_info.used)
{
if (verbose && !record_pos_file)
@@ -477,7 +477,7 @@ static int examine_log(char * file_name, char **table_names)
{
if (!curr_file_info->closed)
files_open--;
- VOID(tree_delete(&tree, (uchar*) curr_file_info, 0, tree.custom_arg));
+ (void) tree_delete(&tree, (uchar*) curr_file_info, 0, tree.custom_arg);
}
break;
case MI_LOG_EXTRA:
@@ -493,10 +493,10 @@ static int examine_log(char * file_name, char **table_names)
if (mi_extra(curr_file_info->isam, extra_command, 0) != (int) result)
{
fflush(stdout);
- VOID(fprintf(stderr,
+ (void) fprintf(stderr,
"Warning: error %d, expected %d on command %s at %s\n",
my_errno,result,command_name[command],
- llstr(isamlog_filepos,llbuff)));
+ llstr(isamlog_filepos,llbuff));
fflush(stderr);
}
}
@@ -641,39 +641,39 @@ static int examine_log(char * file_name, char **table_names)
break;
default:
fflush(stdout);
- VOID(fprintf(stderr,
+ (void) fprintf(stderr,
"Error: found unknown command %d in logfile, aborted\n",
- command));
+ command);
fflush(stderr);
goto end;
}
}
end_key_cache(dflt_key_cache,1);
delete_tree(&tree);
- VOID(end_io_cache(&cache));
- VOID(my_close(file,MYF(0)));
+ (void) end_io_cache(&cache);
+ (void) my_close(file,MYF(0));
if (write_file && my_fclose(write_file,MYF(MY_WME)))
DBUG_RETURN(1);
DBUG_RETURN(0);
err:
fflush(stdout);
- VOID(fprintf(stderr,"Got error %d when reading from logfile\n",my_errno));
+ (void) fprintf(stderr,"Got error %d when reading from logfile\n",my_errno);
fflush(stderr);
goto end;
com_err:
fflush(stdout);
- VOID(fprintf(stderr,"Got error %d, expected %d on command %s at %s\n",
+ (void) fprintf(stderr,"Got error %d, expected %d on command %s at %s\n",
my_errno,result,command_name[command],
- llstr(isamlog_filepos,llbuff)));
+ llstr(isamlog_filepos,llbuff));
fflush(stderr);
end:
end_key_cache(dflt_key_cache, 1);
delete_tree(&tree);
- VOID(end_io_cache(&cache));
- VOID(my_close(file,MYF(0)));
+ (void) end_io_cache(&cache);
+ (void) my_close(file,MYF(0));
if (write_file)
- VOID(my_fclose(write_file,MYF(MY_WME)));
+ (void) my_fclose(write_file,MYF(MY_WME));
DBUG_RETURN(1);
}
@@ -757,7 +757,7 @@ static void file_info_free(struct file_info *fileinfo)
if (update)
{
if (!fileinfo->closed)
- VOID(mi_close(fileinfo->isam));
+ (void) mi_close(fileinfo->isam);
if (fileinfo->record)
my_free(fileinfo->record,MYF(0));
}
@@ -775,8 +775,8 @@ static int close_some_file(TREE *tree)
access_param.min_accessed=LONG_MAX;
access_param.found=0;
- VOID(tree_walk(tree,(tree_walk_action) test_when_accessed,
- (void*) &access_param,left_root_right));
+ (void) tree_walk(tree,(tree_walk_action) test_when_accessed,
+ (void*) &access_param,left_root_right);
if (!access_param.found)
return 1; /* No open file that is possibly to close */
if (mi_close(access_param.found->isam))
@@ -815,7 +815,7 @@ static int find_record_with_key(struct file_info *file_info, uchar *record)
if (mi_is_key_active(info->s->state.key_map, key) &&
info->s->keyinfo[key].flag & HA_NOSAME)
{
- VOID(_mi_make_key(info,key,tmp_key,record,0L));
+ (void) _mi_make_key(info,key,tmp_key,record,0L);
return mi_rkey(info,file_info->record,(int) key,tmp_key,0,
HA_READ_KEY_EXACT);
}
@@ -845,3 +845,5 @@ static my_bool cmp_filename(struct file_info *file_info, char * name)
return 1;
return strcmp(file_info->name,name) ? 1 : 0;
}
+
+#include "mi_extrafunc.h"
diff --git a/storage/myisam/myisampack.c b/storage/myisam/myisampack.c
index 9ebd11b2516..1d8d2e2fcfe 100644
--- a/storage/myisam/myisampack.c
+++ b/storage/myisam/myisampack.c
@@ -44,6 +44,7 @@
#define DATA_TMP_EXT ".TMD"
#define OLD_EXT ".OLD"
+#define FRM_EXT ".frm"
#define WRITE_COUNT MY_HOW_OFTEN_TO_WRITE
struct st_file_buffer {
@@ -125,6 +126,7 @@ static void get_options(int *argc,char ***argv);
static MI_INFO *open_isam_file(char *name,int mode);
static my_bool open_isam_files(PACK_MRG_INFO *mrg,char **names,uint count);
static int compress(PACK_MRG_INFO *file,char *join_name);
+static int create_dest_frm(char *source_table, char *dest_table);
static HUFF_COUNTS *init_huff_count(MI_INFO *info,my_off_t records);
static void free_counts_and_tree_and_queue(HUFF_TREE *huff_trees,
uint trees,
@@ -216,9 +218,13 @@ int main(int argc, char **argv)
error=ok=isamchk_neaded=0;
if (join_table)
- { /* Join files into one */
+ {
+ /*
+ Join files into one and create FRM file for the compressed table only if
+ the compression succeeds
+ */
if (open_isam_files(&merge,argv,(uint) argc) ||
- compress(&merge,join_table))
+ compress(&merge, join_table) || create_dest_frm(argv[0], join_table))
error=1;
}
else while (argc--)
@@ -240,8 +246,8 @@ int main(int argc, char **argv)
}
if (ok && isamchk_neaded && !silent)
puts("Remember to run myisamchk -rq on compressed tables");
- VOID(fflush(stdout));
- VOID(fflush(stderr));
+ (void) fflush(stdout);
+ (void) fflush(stderr);
free_defaults(default_argv);
my_end(verbose ? MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR);
exit(error ? 2 : 0);
@@ -293,8 +299,8 @@ static struct my_option my_long_options[] =
static void print_version(void)
{
- VOID(printf("%s Ver 1.23 for %s on %s\n",
- my_progname, SYSTEM_TYPE, MACHINE_TYPE));
+ printf("%s Ver 1.23 for %s on %s\n",
+ my_progname, SYSTEM_TYPE, MACHINE_TYPE);
NETWARE_SET_SCREEN_MODE(1);
}
@@ -311,7 +317,7 @@ static void usage(void)
puts("afterwards to update the keys.");
puts("You should give the .MYI file as the filename argument.");
- VOID(printf("\nUsage: %s [OPTIONS] filename...\n", my_progname));
+ printf("\nUsage: %s [OPTIONS] filename...\n", my_progname);
my_print_help(my_long_options);
print_defaults("my", load_default_groups);
my_print_variables(my_long_options);
@@ -409,7 +415,7 @@ static MI_INFO *open_isam_file(char *name,int mode)
(opt_wait ? HA_OPEN_WAIT_IF_LOCKED :
HA_OPEN_ABORT_IF_LOCKED))))
{
- VOID(fprintf(stderr, "%s gave error %d on open\n", name, my_errno));
+ (void) fprintf(stderr, "%s gave error %d on open\n", name, my_errno);
DBUG_RETURN(0);
}
share=isam_file->s;
@@ -417,8 +423,8 @@ static MI_INFO *open_isam_file(char *name,int mode)
{
if (!force_pack)
{
- VOID(fprintf(stderr, "%s is already compressed\n", name));
- VOID(mi_close(isam_file));
+ (void) fprintf(stderr, "%s is already compressed\n", name);
+ (void) mi_close(isam_file);
DBUG_RETURN(0);
}
if (verbose)
@@ -429,11 +435,11 @@ static MI_INFO *open_isam_file(char *name,int mode)
(share->state.state.records <= 1 ||
share->state.state.data_file_length < 1024))
{
- VOID(fprintf(stderr, "%s is too small to compress\n", name));
- VOID(mi_close(isam_file));
+ (void) fprintf(stderr, "%s is too small to compress\n", name);
+ (void) mi_close(isam_file);
DBUG_RETURN(0);
}
- VOID(mi_lock_database(isam_file,F_WRLCK));
+ (void) mi_lock_database(isam_file,F_WRLCK);
DBUG_RETURN(isam_file);
}
@@ -475,8 +481,8 @@ static my_bool open_isam_files(PACK_MRG_INFO *mrg, char **names, uint count)
return 0;
diff_file:
- VOID(fprintf(stderr, "%s: Tables '%s' and '%s' are not identical\n",
- my_progname, names[j], names[j+1]));
+ (void) fprintf(stderr, "%s: Tables '%s' and '%s' are not identical\n",
+ my_progname, names[j], names[j+1]);
error:
while (i--)
mi_close(mrg->file[i]);
@@ -508,16 +514,16 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table)
/* Create temporary or join file */
if (backup)
- VOID(fn_format(org_name,isam_file->filename,"",MI_NAME_DEXT,2));
+ (void) fn_format(org_name,isam_file->filename,"",MI_NAME_DEXT,2);
else
- VOID(fn_format(org_name,isam_file->filename,"",MI_NAME_DEXT,2+4+16));
+ (void) fn_format(org_name,isam_file->filename,"",MI_NAME_DEXT,2+4+16);
if (!test_only && result_table)
{
/* Make a new indexfile based on first file in list */
uint length;
uchar *buff;
strmov(org_name,result_table); /* Fix error messages */
- VOID(fn_format(new_name,result_table,"",MI_NAME_IEXT,2));
+ (void) fn_format(new_name,result_table,"",MI_NAME_IEXT,2);
if ((join_isam_file=my_create(new_name,0,tmpfile_createflag,MYF(MY_WME)))
< 0)
goto err;
@@ -532,12 +538,12 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table)
goto err;
}
my_free(buff,MYF(0));
- VOID(fn_format(new_name,result_table,"",MI_NAME_DEXT,2));
+ (void) fn_format(new_name,result_table,"",MI_NAME_DEXT,2);
}
else if (!tmp_dir[0])
- VOID(make_new_name(new_name,org_name));
+ (void) make_new_name(new_name,org_name);
else
- VOID(fn_format(new_name,org_name,tmp_dir,DATA_TMP_EXT,1+2+4));
+ (void) fn_format(new_name,org_name,tmp_dir,DATA_TMP_EXT,1+2+4);
if (!test_only &&
(new_file=my_create(new_name,0,tmpfile_createflag,MYF(MY_WME))) < 0)
goto err;
@@ -553,8 +559,8 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table)
(ulong) mrg->records));
if (write_loop || verbose)
{
- VOID(printf("Compressing %s: (%lu records)\n",
- result_table ? new_name : org_name, (ulong) mrg->records));
+ printf("Compressing %s: (%lu records)\n",
+ result_table ? new_name : org_name, (ulong) mrg->records);
}
trees=fields=share->base.fields;
huff_counts=init_huff_count(isam_file,mrg->records);
@@ -565,7 +571,7 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table)
*/
DBUG_PRINT("info", ("- Calculating statistics"));
if (write_loop || verbose)
- VOID(printf("- Calculating statistics\n"));
+ printf("- Calculating statistics\n");
if (get_statistic(mrg,huff_counts))
goto err;
NORMAL_SAFEMALLOC;
@@ -615,7 +621,7 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table)
*/
file_buffer.pos_in_file=HEAD_LENGTH;
if (! test_only)
- VOID(my_seek(new_file,file_buffer.pos_in_file,MY_SEEK_SET,MYF(0)));
+ my_seek(new_file,file_buffer.pos_in_file,MY_SEEK_SET,MYF(0));
/*
Write field infos: field type, pack type, length bits, tree number.
@@ -641,7 +647,7 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table)
*/
DBUG_PRINT("info", ("- Compressing file"));
if (write_loop || verbose)
- VOID(printf("- Compressing file\n"));
+ printf("- Compressing file\n");
error=compress_isam_file(mrg,huff_counts);
new_length=file_buffer.pos_in_file;
if (!error && !test_only)
@@ -668,9 +674,9 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table)
mrg->min_pack_length, mrg->max_pack_length,
(ulong) (mrg->records ? (new_length/mrg->records) : 0)));
if (verbose && mrg->records)
- VOID(printf("Min record length: %6d Max length: %6d "
+ printf("Min record length: %6d Max length: %6d "
"Mean total length: %6ld\n", mrg->min_pack_length,
- mrg->max_pack_length, (ulong) (new_length/mrg->records)));
+ mrg->max_pack_length, (ulong) (new_length/mrg->records));
/* Close source and target file. */
if (!test_only)
@@ -706,9 +712,9 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table)
error=my_rename(new_name,org_name,MYF(MY_WME));
if (!error)
{
- VOID(my_copystat(temp_name,org_name,MYF(MY_COPYTIME)));
+ (void) my_copystat(temp_name,org_name,MYF(MY_COPYTIME));
if (tmp_dir[0])
- VOID(my_delete(new_name,MYF(MY_WME)));
+ (void) my_delete(new_name,MYF(MY_WME));
}
}
}
@@ -719,7 +725,7 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table)
error=my_copy(new_name,org_name,
MYF(MY_WME | MY_HOLD_ORIGINAL_MODES | MY_COPYTIME));
if (!error)
- VOID(my_delete(new_name,MYF(MY_WME)));
+ (void) my_delete(new_name,MYF(MY_WME));
}
else
error=my_redel(org_name,new_name,MYF(MY_WME | MY_COPYTIME));
@@ -733,16 +739,16 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table)
error|=my_close(join_isam_file,MYF(MY_WME));
if (error)
{
- VOID(fprintf(stderr, "Aborting: %s is not compressed\n", org_name));
- VOID(my_delete(new_name,MYF(MY_WME)));
+ (void) fprintf(stderr, "Aborting: %s is not compressed\n", org_name);
+ (void) my_delete(new_name,MYF(MY_WME));
DBUG_RETURN(-1);
}
if (write_loop || verbose)
{
if (old_length)
- VOID(printf("%.4g%% \n",
+ printf("%.4g%% \n",
(((longlong) (old_length - new_length)) * 100.0 /
- (longlong) old_length)));
+ (longlong) old_length));
else
puts("Empty file saved in compressed format");
}
@@ -751,14 +757,52 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table)
err:
free_counts_and_tree_and_queue(huff_trees,trees,huff_counts,fields);
if (new_file >= 0)
- VOID(my_close(new_file,MYF(0)));
+ (void) my_close(new_file,MYF(0));
if (join_isam_file >= 0)
- VOID(my_close(join_isam_file,MYF(0)));
+ (void) my_close(join_isam_file,MYF(0));
mrg_close(mrg);
- VOID(fprintf(stderr, "Aborted: %s is not compressed\n", org_name));
+ (void) fprintf(stderr, "Aborted: %s is not compressed\n", org_name);
DBUG_RETURN(-1);
}
+
+/**
+ Create FRM for the destination table for --join operation
+ Copy the first table FRM as the destination table FRM file. Doing so
+ will help the mysql server to recognize the newly created table.
+ See Bug#36573.
+
+ @param source_table Name of the source table
+ @param dest_table Name of the destination table
+ @retval 0 Successful copy operation
+
+ @note We always return 0 because we don't want myisampack to report error
+ even if the copy operation fails.
+*/
+
+static int create_dest_frm(char *source_table, char *dest_table)
+{
+ char source_name[FN_REFLEN], dest_name[FN_REFLEN];
+
+ DBUG_ENTER("create_dest_frm");
+
+ (void) fn_format(source_name, source_table,
+ "", FRM_EXT, MY_UNPACK_FILENAME | MY_RESOLVE_SYMLINKS);
+ (void) fn_format(dest_name, dest_table,
+ "", FRM_EXT, MY_UNPACK_FILENAME | MY_RESOLVE_SYMLINKS);
+ /*
+ Error messages produced by my_copy() are suppressed as this
+ is not vital for --join operation. User shouldn't see any error messages
+ like "source file frm not found" and "unable to create destination frm
+ file. So we don't pass the flag MY_WME -Write Message on Error to
+ my_copy()
+ */
+ (void) my_copy(source_name, dest_name, MYF(MY_DONT_OVERWRITE_FILE));
+
+ return 0;
+}
+
+
/* Init a huff_count-struct for each field and init it */
static HUFF_COUNTS *init_huff_count(MI_INFO *info,my_off_t records)
@@ -1071,13 +1115,13 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts)
record_count++;
if (write_loop && record_count % WRITE_COUNT == 0)
{
- VOID(printf("%lu\r", (ulong) record_count));
- VOID(fflush(stdout));
+ printf("%lu\r", (ulong) record_count);
+ (void) fflush(stdout);
}
}
else if (error != HA_ERR_RECORD_DELETED)
{
- VOID(fprintf(stderr, "Got error %d while reading rows", error));
+ (void) fprintf(stderr, "Got error %d while reading rows", error);
break;
}
@@ -1085,8 +1129,8 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts)
}
if (write_loop)
{
- VOID(printf(" \r"));
- VOID(fflush(stdout));
+ printf(" \r");
+ (void) fflush(stdout);
}
/*
@@ -1098,8 +1142,8 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts)
DBUG_PRINT("info", ("Found the following number of incidents "
"of the byte codes:"));
if (verbose >= 2)
- VOID(printf("Found the following number of incidents "
- "of the byte codes:\n"));
+ printf("Found the following number of incidents "
+ "of the byte codes:\n");
for (count= huff_counts ; count < end_count; count++)
{
uint idx;
@@ -1108,16 +1152,16 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts)
DBUG_PRINT("info", ("column: %3u", (uint) (count - huff_counts + 1)));
if (verbose >= 2)
- VOID(printf("column: %3u\n", (uint) (count - huff_counts + 1)));
+ printf("column: %3u\n", (uint) (count - huff_counts + 1));
if (count->tree_buff)
{
DBUG_PRINT("info", ("number of distinct values: %u",
(uint) ((count->tree_pos - count->tree_buff) /
count->field_length)));
if (verbose >= 2)
- VOID(printf("number of distinct values: %u\n",
+ printf("number of distinct values: %u\n",
(uint) ((count->tree_pos - count->tree_buff) /
- count->field_length)));
+ count->field_length));
}
total_count= 0;
for (idx= 0; idx < 256; idx++)
@@ -1128,16 +1172,16 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts)
DBUG_PRINT("info", ("counts[0x%02x]: %12s", idx,
llstr((longlong) count->counts[idx], llbuf)));
if (verbose >= 2)
- VOID(printf("counts[0x%02x]: %12s\n", idx,
- llstr((longlong) count->counts[idx], llbuf)));
+ printf("counts[0x%02x]: %12s\n", idx,
+ llstr((longlong) count->counts[idx], llbuf));
}
}
DBUG_PRINT("info", ("total: %12s", llstr((longlong) total_count,
llbuf)));
if ((verbose >= 2) && total_count)
{
- VOID(printf("total: %12s\n",
- llstr((longlong) total_count, llbuf)));
+ printf("total: %12s\n",
+ llstr((longlong) total_count, llbuf));
}
}
@@ -1354,7 +1398,7 @@ static void check_counts(HUFF_COUNTS *huff_counts, uint trees,
field_count[FIELD_INTERVALL],
field_count[FIELD_ZERO]));
if (verbose)
- VOID(printf("\nnormal: %3d empty-space: %3d "
+ printf("\nnormal: %3d empty-space: %3d "
"empty-zero: %3d empty-fill: %3d\n"
"pre-space: %3d end-space: %3d "
"intervall-fields: %3d zero: %3d\n",
@@ -1363,7 +1407,7 @@ static void check_counts(HUFF_COUNTS *huff_counts, uint trees,
field_count[FIELD_SKIP_PRESPACE],
field_count[FIELD_SKIP_ENDSPACE],
field_count[FIELD_INTERVALL],
- field_count[FIELD_ZERO]));
+ field_count[FIELD_ZERO]);
DBUG_VOID_RETURN;
}
@@ -1878,7 +1922,7 @@ static uint join_same_trees(HUFF_COUNTS *huff_counts, uint trees)
DBUG_PRINT("info", ("Original trees: %d After join: %d",
trees, tree_number));
if (verbose)
- VOID(printf("Original trees: %d After join: %d\n", trees, tree_number));
+ printf("Original trees: %d After join: %d\n", trees, tree_number);
return tree_number; /* Return trees left */
}
@@ -2024,7 +2068,7 @@ static int write_header(PACK_MRG_INFO *mrg,uint head_length,uint trees,
buff[27]= (uchar) mi_get_pointer_length((ulonglong) filelength,2);
if (test_only)
return 0;
- VOID(my_seek(file_buffer.file,0L,MY_SEEK_SET,MYF(0)));
+ my_seek(file_buffer.file,0L,MY_SEEK_SET,MYF(0));
return my_write(file_buffer.file,(const uchar *) file_buffer.pos,HEAD_LENGTH,
MYF(MY_WME | MY_NABP | MY_WAIT_IF_FULL)) != 0;
}
@@ -2057,24 +2101,24 @@ static void write_field_info(HUFF_COUNTS *counts, uint fields, uint trees)
DBUG_PRINT("info", (" "));
if (verbose >= 2)
{
- VOID(printf("\n"));
- VOID(printf("column types:\n"));
- VOID(printf("FIELD_NORMAL 0\n"));
- VOID(printf("FIELD_SKIP_ENDSPACE 1\n"));
- VOID(printf("FIELD_SKIP_PRESPACE 2\n"));
- VOID(printf("FIELD_SKIP_ZERO 3\n"));
- VOID(printf("FIELD_BLOB 4\n"));
- VOID(printf("FIELD_CONSTANT 5\n"));
- VOID(printf("FIELD_INTERVALL 6\n"));
- VOID(printf("FIELD_ZERO 7\n"));
- VOID(printf("FIELD_VARCHAR 8\n"));
- VOID(printf("FIELD_CHECK 9\n"));
- VOID(printf("\n"));
- VOID(printf("pack type as a set of flags:\n"));
- VOID(printf("PACK_TYPE_SELECTED 1\n"));
- VOID(printf("PACK_TYPE_SPACE_FIELDS 2\n"));
- VOID(printf("PACK_TYPE_ZERO_FILL 4\n"));
- VOID(printf("\n"));
+ printf("\n");
+ printf("column types:\n");
+ printf("FIELD_NORMAL 0\n");
+ printf("FIELD_SKIP_ENDSPACE 1\n");
+ printf("FIELD_SKIP_PRESPACE 2\n");
+ printf("FIELD_SKIP_ZERO 3\n");
+ printf("FIELD_BLOB 4\n");
+ printf("FIELD_CONSTANT 5\n");
+ printf("FIELD_INTERVALL 6\n");
+ printf("FIELD_ZERO 7\n");
+ printf("FIELD_VARCHAR 8\n");
+ printf("FIELD_CHECK 9\n");
+ printf("\n");
+ printf("pack type as a set of flags:\n");
+ printf("PACK_TYPE_SELECTED 1\n");
+ printf("PACK_TYPE_SPACE_FIELDS 2\n");
+ printf("PACK_TYPE_ZERO_FILL 4\n");
+ printf("\n");
}
for (i=0 ; i++ < fields ; counts++)
{
@@ -2091,10 +2135,10 @@ static void write_field_info(HUFF_COUNTS *counts, uint fields, uint trees)
counts->max_zero_fill, counts->length_bits,
counts->tree->tree_number, counts->field_length));
if (verbose >= 2)
- VOID(printf("column: %3u type: %2u pack: %2u zero: %4u lbits: %2u "
+ printf("column: %3u type: %2u pack: %2u zero: %4u lbits: %2u "
"tree: %2u length: %4u\n", i , counts->field_type,
counts->pack_type, counts->max_zero_fill, counts->length_bits,
- counts->tree->tree_number, counts->field_length));
+ counts->tree->tree_number, counts->field_length);
}
flush_bits();
return;
@@ -2129,7 +2173,7 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees)
DBUG_PRINT("info", (" "));
if (verbose >= 2)
- VOID(printf("\n"));
+ printf("\n");
tree_no= 0;
intervall_length=0;
for (elements=0; trees-- ; huff_tree++)
@@ -2140,7 +2184,7 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees)
tree_no++;
DBUG_PRINT("info", (" "));
if (verbose >= 3)
- VOID(printf("\n"));
+ printf("\n");
/* Count the total number of elements (byte codes or column values). */
elements+=huff_tree->elements;
huff_tree->max_offset=2;
@@ -2159,8 +2203,8 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees)
*/
if (huff_tree->max_offset >= IS_OFFSET)
{ /* This should be impossible */
- VOID(fprintf(stderr, "Tree offset got too big: %d, aborted\n",
- huff_tree->max_offset));
+ (void) fprintf(stderr, "Tree offset got too big: %d, aborted\n",
+ huff_tree->max_offset);
my_afree((uchar*) packed_tree);
return 0;
}
@@ -2199,19 +2243,19 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees)
"bufflen" : "min_chr", huff_tree->counts->tree_buff ?
int_length : huff_tree->min_chr, huff_tree->height));
if (verbose >= 2)
- VOID(printf("tree: %2u elements: %4u char_bits: %2u offset_bits: %2u "
+ printf("tree: %2u elements: %4u char_bits: %2u offset_bits: %2u "
"%s: %5u codelen: %2u\n", tree_no, huff_tree->elements,
huff_tree->char_bits, huff_tree->offset_bits,
huff_tree->counts->tree_buff ? "bufflen" : "min_chr",
huff_tree->counts->tree_buff ? int_length :
- huff_tree->min_chr, huff_tree->height));
+ huff_tree->min_chr, huff_tree->height);
/* Check that the code tree length matches the element count. */
length=(uint) (offset-packed_tree);
if (length != huff_tree->elements*2-2)
{
- VOID(fprintf(stderr, "error: Huff-tree-length: %d != calc_length: %d\n",
- length, huff_tree->elements * 2 - 2));
+ (void) fprintf(stderr, "error: Huff-tree-length: %d != calc_length: %d\n",
+ length, huff_tree->elements * 2 - 2);
errors++;
break;
}
@@ -2228,10 +2272,10 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees)
" -> " : "", (packed_tree[i] & IS_OFFSET) ?
packed_tree[i] - IS_OFFSET + i : packed_tree[i]));
if (verbose >= 3)
- VOID(printf("tree[0x%04x]: %s0x%04x\n",
+ printf("tree[0x%04x]: %s0x%04x\n",
i, (packed_tree[i] & IS_OFFSET) ? " -> " : "",
(packed_tree[i] & IS_OFFSET) ?
- packed_tree[i] - IS_OFFSET + i : packed_tree[i]));
+ packed_tree[i] - IS_OFFSET + i : packed_tree[i]);
}
flush_bits();
@@ -2253,9 +2297,9 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees)
bindigits(huff_tree->code[i],
huff_tree->code_len[i])));
if (verbose >= 3)
- VOID(printf("code[0x%04x]: 0x%s bits: %2u bin: %s\n", i,
+ printf("code[0x%04x]: 0x%s bits: %2u bin: %s\n", i,
hexdigits(huff_tree->code[i]), huff_tree->code_len[i],
- bindigits(huff_tree->code[i], huff_tree->code_len[i])));
+ bindigits(huff_tree->code[i], huff_tree->code_len[i]));
/* Check that the encode table decodes correctly. */
code= 0;
@@ -2268,9 +2312,9 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees)
{
if (! len)
{
- VOID(fflush(stdout));
- VOID(fprintf(stderr, "error: code 0x%s with %u bits not found\n",
- hexdigits(huff_tree->code[i]), huff_tree->code_len[i]));
+ (void) fflush(stdout);
+ (void) fprintf(stderr, "error: code 0x%s with %u bits not found\n",
+ hexdigits(huff_tree->code[i]), huff_tree->code_len[i]);
errors++;
break;
}
@@ -2279,18 +2323,18 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees)
bits++;
if (bits > 8 * sizeof(code))
{
- VOID(fflush(stdout));
- VOID(fprintf(stderr, "error: Huffman code too long: %u/%u\n",
- bits, (uint) (8 * sizeof(code))));
+ (void) fflush(stdout);
+ (void) fprintf(stderr, "error: Huffman code too long: %u/%u\n",
+ bits, (uint) (8 * sizeof(code)));
errors++;
break;
}
idx+= (uint) code & 1;
if (idx >= length)
{
- VOID(fflush(stdout));
- VOID(fprintf(stderr, "error: illegal tree offset: %u/%u\n",
- idx, length));
+ (void) fflush(stdout);
+ (void) fprintf(stderr, "error: illegal tree offset: %u/%u\n",
+ idx, length);
errors++;
break;
}
@@ -2305,9 +2349,9 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees)
DBUG_EXECUTE_IF("forcechkerr4", packed_tree[idx]++;);
if (packed_tree[idx] != i)
{
- VOID(fflush(stdout));
- VOID(fprintf(stderr, "error: decoded value 0x%04x should be: 0x%04x\n",
- packed_tree[idx], i));
+ (void) fflush(stdout);
+ (void) fprintf(stderr, "error: decoded value 0x%04x should be: 0x%04x\n",
+ packed_tree[idx], i);
errors++;
break;
}
@@ -2324,19 +2368,19 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees)
DBUG_PRINT("info", ("column_values[0x%04x]: 0x%02x",
i, (uchar) huff_tree->counts->tree_buff[i]));
if (verbose >= 3)
- VOID(printf("column_values[0x%04x]: 0x%02x\n",
- i, (uchar) huff_tree->counts->tree_buff[i]));
+ printf("column_values[0x%04x]: 0x%02x\n",
+ i, (uchar) huff_tree->counts->tree_buff[i]);
}
}
flush_bits();
}
DBUG_PRINT("info", (" "));
if (verbose >= 2)
- VOID(printf("\n"));
+ printf("\n");
my_afree((uchar*) packed_tree);
if (errors)
{
- VOID(fprintf(stderr, "Error: Generated decode trees are corrupt. Stop.\n"));
+ (void) fprintf(stderr, "Error: Generated decode trees are corrupt. Stop.\n");
return 0;
}
return elements;
@@ -2758,8 +2802,8 @@ static int compress_isam_file(PACK_MRG_INFO *mrg, HUFF_COUNTS *huff_counts)
record_count++;
if (write_loop && record_count % WRITE_COUNT == 0)
{
- VOID(printf("%lu\r", (ulong) record_count));
- VOID(fflush(stdout));
+ printf("%lu\r", (ulong) record_count);
+ (void) fflush(stdout);
}
}
else if (error != HA_ERR_RECORD_DELETED)
@@ -2769,11 +2813,11 @@ static int compress_isam_file(PACK_MRG_INFO *mrg, HUFF_COUNTS *huff_counts)
error=0;
else
{
- VOID(fprintf(stderr, "%s: Got error %d reading records\n",
- my_progname, error));
+ (void) fprintf(stderr, "%s: Got error %d reading records\n",
+ my_progname, error);
}
if (verbose >= 2)
- VOID(printf("wrote %s records.\n", llstr((longlong) record_count, llbuf)));
+ printf("wrote %s records.\n", llstr((longlong) record_count, llbuf));
my_afree((uchar*) record);
mrg->ref_length=max_pack_length;
@@ -2903,7 +2947,7 @@ static void write_bits(register ulonglong value, register uint bits)
if (bits != 8 * sizeof(value))
value&= (((ulonglong) 1) << bits) - 1;
if (file_buffer.pos >= file_buffer.end)
- VOID(flush_buffer(~ (ulong) 0));
+ (void) flush_buffer(~ (ulong) 0);
file_buffer.bits=(int) (BITS_SAVED - bits);
file_buffer.bitbucket= value << (BITS_SAVED - bits);
}
@@ -2926,7 +2970,7 @@ static void flush_bits(void)
*file_buffer.pos++= (uchar) (bit_buffer >> bits);
}
if (file_buffer.pos >= file_buffer.end)
- VOID(flush_buffer(~ (ulong) 0));
+ (void) flush_buffer(~ (ulong) 0);
file_buffer.bits= BITS_SAVED;
file_buffer.bitbucket= 0;
}
@@ -2976,7 +3020,7 @@ static int save_state(MI_INFO *isam_file,PACK_MRG_INFO *mrg,my_off_t new_length,
share->changed=1; /* Force write of header */
share->state.open_count=0;
share->global_changed=0;
- VOID(my_chsize(share->kfile, share->base.keystart, 0, MYF(0)));
+ (void) my_chsize(share->kfile, share->base.keystart, 0, MYF(0));
if (share->base.keys)
isamchk_neaded=1;
DBUG_RETURN(mi_state_info_write(share->kfile,&share->state,1+2));
@@ -3203,4 +3247,4 @@ static int fakecmp(my_off_t **count1, my_off_t **count2)
}
#endif
-
+#include "mi_extrafunc.h"
diff --git a/storage/myisam/rt_test.c b/storage/myisam/rt_test.c
index 7d15afd12ef..4a9b61605d9 100644
--- a/storage/myisam/rt_test.c
+++ b/storage/myisam/rt_test.c
@@ -468,3 +468,5 @@ int main(int argc __attribute__((unused)),char *argv[] __attribute__((unused)))
exit(0);
}
#endif /*HAVE_RTREE_KEYS*/
+
+#include "mi_extrafunc.h"
diff --git a/storage/myisam/sort.c b/storage/myisam/sort.c
index b450d27de66..441d6bfa05b 100644
--- a/storage/myisam/sort.c
+++ b/storage/myisam/sort.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -478,10 +478,10 @@ ok:
if (sort_param->read_cache.share)
remove_io_thread(&sort_param->read_cache);
- pthread_mutex_lock(&sort_param->sort_info->mutex);
+ mysql_mutex_lock(&sort_param->sort_info->mutex);
if (!--sort_param->sort_info->threads_running)
- pthread_cond_signal(&sort_param->sort_info->cond);
- pthread_mutex_unlock(&sort_param->sort_info->mutex);
+ mysql_cond_signal(&sort_param->sort_info->cond);
+ mysql_mutex_unlock(&sort_param->sort_info->mutex);
DBUG_PRINT("exit", ("======== ending thread ========"));
}
my_thread_end();
@@ -824,8 +824,9 @@ static uint NEAR_F read_to_buffer(IO_CACHE *fromfile, BUFFPEK *buffpek,
if ((count=(uint) min((ha_rows) buffpek->max_keys,buffpek->count)))
{
- if (my_pread(fromfile->file,(uchar*) buffpek->base,
- (length= sort_length*count),buffpek->file_pos,MYF_RW))
+ if (mysql_file_pread(fromfile->file, (uchar*) buffpek->base,
+ (length= sort_length*count),
+ buffpek->file_pos, MYF_RW))
return((uint) -1); /* purecov: inspected */
buffpek->key=buffpek->base;
buffpek->file_pos+= length; /* New filepos */
@@ -849,12 +850,12 @@ static uint NEAR_F read_to_buffer_varlen(IO_CACHE *fromfile, BUFFPEK *buffpek,
for (idx=1;idx<=count;idx++)
{
- if (my_pread(fromfile->file,(uchar*)&length_of_key,sizeof(length_of_key),
- buffpek->file_pos,MYF_RW))
+ if (mysql_file_pread(fromfile->file, (uchar*)&length_of_key,
+ sizeof(length_of_key), buffpek->file_pos, MYF_RW))
return((uint) -1);
buffpek->file_pos+=sizeof(length_of_key);
- if (my_pread(fromfile->file,(uchar*) buffp,length_of_key,
- buffpek->file_pos,MYF_RW))
+ if (mysql_file_pread(fromfile->file, (uchar*) buffp,
+ length_of_key, buffpek->file_pos, MYF_RW))
return((uint) -1);
buffpek->file_pos+=length_of_key;
buffp = buffp + sort_length;
@@ -970,7 +971,7 @@ merge_buffers(MI_SORT_PARAM *info, uint keys, IO_CACHE *from_file,
uchar *base=buffpek->base;
uint max_keys=buffpek->max_keys;
- VOID(queue_remove(&queue,0));
+ (void) queue_remove(&queue,0);
/* Put room used by buffer to use in other buffer */
for (refpek= (BUFFPEK**) &queue_top(&queue);
diff --git a/storage/myisam/sp_test.c b/storage/myisam/sp_test.c
index f572c7ab19b..069f43c320d 100644
--- a/storage/myisam/sp_test.c
+++ b/storage/myisam/sp_test.c
@@ -562,3 +562,4 @@ int main(int argc __attribute__((unused)),char *argv[] __attribute__((unused)))
}
#endif /*HAVE_SPATIAL*/
+#include "mi_extrafunc.h"
diff --git a/storage/myisammrg/ha_myisammrg.cc b/storage/myisammrg/ha_myisammrg.cc
index 471e2243aac..a34a52d8f9c 100644
--- a/storage/myisammrg/ha_myisammrg.cc
+++ b/storage/myisammrg/ha_myisammrg.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -33,40 +33,29 @@
and hence through open_tables(). When the parent appears in the list
of tables to open, the initial open of the handler does nothing but
read the meta file and collect a list of TABLE_LIST objects for the
- children. This list is attached to the parent TABLE object as
- TABLE::child_l. The end of the children list is saved in
- TABLE::child_last_l.
-
- Back in open_tables(), add_merge_table_list() is called. It updates
- each list member with the lock type and a back pointer to the parent
- TABLE_LIST object TABLE_LIST::parent_l. The list is then inserted in
- the list of tables to open, right behind the parent. Consequently,
- open_tables() opens the children, one after the other. The TABLE
- references of the TABLE_LIST objects are implicitly set to the open
- tables. The children are opened as independent MyISAM tables, right as
- if they are used by the SQL statement.
-
- TABLE_LIST::parent_l is required to find the parent 1. when the last
- child has been opened and children are to be attached, and 2. when an
- error happens during child open and the child list must be removed
- from the queuery list. In these cases the current child does not have
- TABLE::parent set or does not have a TABLE at all respectively.
-
- When the last child is open, attach_merge_children() is called. It
- removes the list of children from the open list. Then the children are
- "attached" to the parent. All required references between parent and
+ children. This list is attached to the handler object as
+ ha_myisammrg::children_l. The end of the children list is saved in
+ ha_myisammrg::children_last_l.
+
+ Back in open_tables(), handler::extra(HA_EXTRA_ADD_CHILDREN_LIST) is
+ called. It updates each list member with the lock type and a back
+ pointer to the parent TABLE_LIST object TABLE_LIST::parent_l. The list
+ is then inserted in the list of tables to open, right behind the
+ parent. Consequently, open_tables() opens the children, one after the
+ other. The TABLE references of the TABLE_LIST objects are implicitly
+ set to the open tables by open_table(). The children are opened as
+ independent MyISAM tables, right as if they are used by the SQL
+ statement.
+
+ When all tables from the statement query list are open,
+ handler::extra(HA_EXTRA_ATTACH_CHILDREN) is called. It "attaches" the
+ children to the parent. All required references between parent and
children are set up.
The MERGE storage engine sets up an array with references to the
low-level MyISAM table objects (MI_INFO). It remembers the state of
the table in MYRG_INFO::children_attached.
- Every child TABLE::parent references the parent TABLE object. That way
- TABLE objects belonging to a MERGE table can be identified.
- TABLE::parent is required because the parent and child TABLE objects
- can live longer than the parent TABLE_LIST object. So the path
- child->pos_in_table_list->parent_l->table can be broken.
-
If necessary, the compatibility of parent and children is checked.
This check is necessary when any of the objects are reopend. This is
detected by comparing the current table def version against the
@@ -80,14 +69,20 @@
myisammrg_attach_children_callback() sets it ot TRUE if a table
def version mismatches the remembered child def version.
- Finally the parent TABLE::children_attached is set.
+ The children chain remains in the statement query list until the table
+ is closed or the children are detached. This is done so that the
+ children are locked by lock_tables().
+
+ At statement end the children are detached. At the next statement
+ begin the open-add-attach sequence repeats. There is no exception for
+ LOCK TABLES. The fresh establishment of the parent-child relationship
+ before every statement catches numerous cases of ALTER/FLUSH/DROP/etc
+ of parent or children during LOCK TABLES.
---
On parent open the storage engine structures are allocated and initialized.
They stay with the open table until its final close.
-
-
*/
#ifdef USE_PRAGMA_IMPLEMENTATION
@@ -118,7 +113,10 @@ static handler *myisammrg_create_handler(handlerton *hton,
ha_myisammrg::ha_myisammrg(handlerton *hton, TABLE_SHARE *table_arg)
:handler(hton, table_arg), file(0), is_cloned(0)
-{}
+{
+ init_sql_alloc(&children_mem_root,
+ FN_REFLEN + ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
+}
/**
@@ -126,7 +124,9 @@ ha_myisammrg::ha_myisammrg(handlerton *hton, TABLE_SHARE *table_arg)
*/
ha_myisammrg::~ha_myisammrg(void)
-{}
+{
+ free_root(&children_mem_root, MYF(0));
+}
static const char *ha_myisammrg_exts[] = {
@@ -178,49 +178,53 @@ const char *ha_myisammrg::index_type(uint key_number)
/**
- @brief Callback function for open of a MERGE parent table.
-
- @detail This function adds a TABLE_LIST object for a MERGE child table
- to a list of tables of the parent TABLE object. It is called for
- each child table.
-
- The list of child TABLE_LIST objects is kept in the TABLE object of
- the parent for the whole life time of the MERGE table. It is
- inserted in the statement list behind the MERGE parent TABLE_LIST
- object when the MERGE table is opened. It is removed from the
- statement list after the last child is opened.
-
- All memeory used for the child TABLE_LIST objects and the strings
- referred by it are taken from the parent TABLE::mem_root. Thus they
- are all freed implicitly at the final close of the table.
-
- TABLE::child_l -> TABLE_LIST::next_global -> TABLE_LIST::next_global
- # # ^ # ^
- # # | # |
- # # +--------- TABLE_LIST::prev_global
- # # |
- # |<--- TABLE_LIST::prev_global |
- # |
- TABLE::child_last_l -----------------------------------------+
+ Callback function for open of a MERGE parent table.
@param[in] callback_param data pointer as given to myrg_parent_open()
+ this is used to pass the handler handle
@param[in] filename file name of MyISAM table
without extension.
@return status
@retval 0 OK
@retval != 0 Error
+
+ @detail
+
+ This function adds a TABLE_LIST object for a MERGE child table to a
+ list of tables in the parent handler object. It is called for each
+ child table.
+
+ The list of child TABLE_LIST objects is kept in the handler object
+ of the parent for the whole life time of the MERGE table. It is
+ inserted in the statement query list behind the MERGE parent
+ TABLE_LIST object when the MERGE table is opened. It is removed from
+ the statement query list at end of statement or at children detach.
+
+ All memory used for the child TABLE_LIST objects and the strings
+ referred by it are taken from the parent
+ ha_myisammrg::children_mem_root. Thus they are all freed implicitly at
+ the final close of the table.
+
+ children_l -> TABLE_LIST::next_global -> TABLE_LIST::next_global
+ # # ^ # ^
+ # # | # |
+ # # +--------- TABLE_LIST::prev_global
+ # # |
+ # |<--- TABLE_LIST::prev_global |
+ # |
+ children_last_l -----------------------------------------+
*/
static int myisammrg_parent_open_callback(void *callback_param,
const char *filename)
{
- ha_myisammrg *ha_myrg;
- TABLE *parent;
- TABLE_LIST *child_l;
- const char *db;
- const char *table_name;
- size_t dirlen;
+ ha_myisammrg *ha_myrg= (ha_myisammrg*) callback_param;
+ Mrg_child_def *mrg_child_def;
+ char *db;
+ char *table_name;
+ uint dirlen;
+ uint table_name_length;
char dir_path[FN_REFLEN];
DBUG_ENTER("myisammrg_parent_open_callback");
@@ -234,7 +238,7 @@ static int myisammrg_parent_open_callback(void *callback_param,
DBUG_RETURN(1);
/* purecov: end */
}
- table_name= filename + dirlen;
+ table_name= (char*) filename + dirlen;
dirlen--; /* Strip off trailing '/'. */
memcpy(dir_path, filename, dirlen);
dir_path[dirlen]= '\0';
@@ -242,117 +246,313 @@ static int myisammrg_parent_open_callback(void *callback_param,
dirlen-= db - dir_path; /* This is now the length of 'db'. */
DBUG_PRINT("myrg", ("open: '%s'.'%s'", db, table_name));
- ha_myrg= (ha_myisammrg*) callback_param;
- parent= ha_myrg->table_ptr();
+ /* Set database (schema) name. */
+ db= strmake_root(&ha_myrg->children_mem_root, db, dirlen);
+ /* Set table name. */
+ table_name_length= strlen(table_name);
+ table_name= strmake_root(&ha_myrg->children_mem_root, table_name,
+ table_name_length);
+
+ if (! db || ! table_name)
+ DBUG_RETURN(1);
- /* Get a TABLE_LIST object. */
- if (!(child_l= (TABLE_LIST*) alloc_root(&parent->mem_root,
- sizeof(TABLE_LIST))))
+ /* Convert to lowercase if required. */
+ if (lower_case_table_names && table_name_length)
+ {
+ /* purecov: begin tested */
+ table_name_length= my_casedn_str(files_charset_info, table_name);
+ /* purecov: end */
+ }
+
+ mrg_child_def= new (&ha_myrg->children_mem_root)
+ Mrg_child_def(db, dirlen, table_name, table_name_length);
+
+ if (! mrg_child_def ||
+ ha_myrg->child_def_list.push_back(mrg_child_def,
+ &ha_myrg->children_mem_root))
{
- /* purecov: begin inspected */
- DBUG_PRINT("error", ("my_malloc error: %d", my_errno));
DBUG_RETURN(1);
+ }
+ DBUG_RETURN(0);
+}
+
+
+/**
+ Open a MERGE parent table, but not its children.
+
+ @param[in] name MERGE table path name
+ @param[in] mode read/write mode, unused
+ @param[in] test_if_locked_arg open flags
+
+ @return status
+ @retval 0 OK
+ @retval -1 Error, my_errno gives reason
+
+ @detail
+ This function initializes the MERGE storage engine structures
+ and adds a child list of TABLE_LIST to the parent handler.
+*/
+
+int ha_myisammrg::open(const char *name, int mode __attribute__((unused)),
+ uint test_if_locked_arg)
+{
+ DBUG_ENTER("ha_myisammrg::open");
+ DBUG_PRINT("myrg", ("name: '%s' table: 0x%lx", name, (long) table));
+ DBUG_PRINT("myrg", ("test_if_locked: %u", test_if_locked_arg));
+
+ /* Must not be used when table is open. */
+ DBUG_ASSERT(!this->file);
+
+ /* Save for later use. */
+ test_if_locked= test_if_locked_arg;
+
+ /* In case this handler was open and closed before, free old data. */
+ free_root(&this->children_mem_root, MYF(MY_MARK_BLOCKS_FREE));
+
+ /*
+ Initialize variables that are used, modified, and/or set by
+ myisammrg_parent_open_callback().
+ 'children_l' is the head of the children chain.
+ 'children_last_l' points to the end of the children chain.
+ 'my_errno' is set by myisammrg_parent_open_callback() in
+ case of an error.
+ */
+ children_l= NULL;
+ children_last_l= NULL;
+ child_def_list.empty();
+ my_errno= 0;
+
+ /* retrieve children table list. */
+ if (is_cloned)
+ {
+ /*
+ Open and attaches the MyISAM tables,that are under the MERGE table
+ parent, on the MyISAM storage engine interface directly within the
+ MERGE engine. The new MyISAM table instances, as well as the MERGE
+ clone itself, are not visible in the table cache. This is not a
+ problem because all locking is handled by the original MERGE table
+ from which this is cloned of.
+ */
+ if (!(file= myrg_open(name, table->db_stat, HA_OPEN_IGNORE_IF_LOCKED)))
+ {
+ DBUG_PRINT("error", ("my_errno %d", my_errno));
+ DBUG_RETURN(my_errno ? my_errno : -1);
+ }
+
+ file->children_attached= TRUE;
+
+ info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
+ }
+ else if (!(file= myrg_parent_open(name, myisammrg_parent_open_callback, this)))
+ {
+ /* purecov: begin inspected */
+ DBUG_PRINT("error", ("my_errno %d", my_errno));
+ DBUG_RETURN(my_errno ? my_errno : -1);
/* purecov: end */
}
- bzero((char*) child_l, sizeof(TABLE_LIST));
+ DBUG_PRINT("myrg", ("MYRG_INFO: 0x%lx child tables: %u",
+ (long) file, file->tables));
+ DBUG_RETURN(0);
+}
- /* Set database (schema) name. */
- child_l->db_length= dirlen;
- child_l->db= strmake_root(&parent->mem_root, db, dirlen);
- /* Set table name. */
- child_l->table_name_length= strlen(table_name);
- child_l->table_name= strmake_root(&parent->mem_root, table_name,
- child_l->table_name_length);
- /* Convert to lowercase if required. */
- if (lower_case_table_names && child_l->table_name_length)
- child_l->table_name_length= my_casedn_str(files_charset_info,
- child_l->table_name);
- /* Set alias. */
- child_l->alias= child_l->table_name;
- /* Initialize table map to 'undefined'. */
- child_l->init_child_def_version();
+/**
+ Add list of MERGE children to a TABLE_LIST chain.
+
+ @return status
+ @retval 0 OK
+ @retval != 0 Error
+
+ @detail
+ When a MERGE parent table has just been opened, insert the
+ TABLE_LIST chain from the MERGE handler into the table list used for
+ opening tables for this statement. This lets the children be opened
+ too.
+*/
- /* Link TABLE_LIST object into the parent list. */
- if (!parent->child_last_l)
+int ha_myisammrg::add_children_list(void)
+{
+ TABLE_LIST *parent_l= this->table->pos_in_table_list;
+ THD *thd= table->in_use;
+ List_iterator_fast<Mrg_child_def> it(child_def_list);
+ Mrg_child_def *mrg_child_def;
+ DBUG_ENTER("ha_myisammrg::add_children_list");
+ DBUG_PRINT("myrg", ("table: '%s'.'%s' 0x%lx", this->table->s->db.str,
+ this->table->s->table_name.str, (long) this->table));
+
+ /* Must call this with open table. */
+ DBUG_ASSERT(this->file);
+
+ /* Ignore this for empty MERGE tables (UNION=()). */
+ if (!this->file->tables)
{
- /* Initialize parent->child_last_l when handling first child. */
- parent->child_last_l= &parent->child_l;
+ DBUG_PRINT("myrg", ("empty merge table union"));
+ goto end;
}
- *parent->child_last_l= child_l;
- child_l->prev_global= parent->child_last_l;
- parent->child_last_l= &child_l->next_global;
+ /* Must not call this with attached children. */
+ DBUG_ASSERT(!this->file->children_attached);
+
+ /* Must not call this with children list in place. */
+ DBUG_ASSERT(this->children_l == NULL);
+
+ /*
+ Prevent inclusion of another MERGE table, which could make infinite
+ recursion.
+ */
+ if (parent_l->parent_l)
+ {
+ my_error(ER_ADMIN_WRONG_MRG_TABLE, MYF(0), parent_l->alias);
+ DBUG_RETURN(1);
+ }
+
+ while ((mrg_child_def= it++))
+ {
+ TABLE_LIST *child_l;
+ char *db;
+ char *table_name;
+
+ child_l= (TABLE_LIST*) thd->alloc(sizeof(TABLE_LIST));
+ db= (char*) thd->memdup(mrg_child_def->db.str, mrg_child_def->db.length+1);
+ table_name= (char*) thd->memdup(mrg_child_def->name.str,
+ mrg_child_def->name.length+1);
+
+ if (child_l == NULL || db == NULL || table_name == NULL)
+ DBUG_RETURN(1);
+
+ child_l->init_one_table(db, mrg_child_def->db.length,
+ table_name, mrg_child_def->name.length,
+ table_name, parent_l->lock_type);
+ /* Set parent reference. Used to detect MERGE in children list. */
+ child_l->parent_l= parent_l;
+ /* Copy select_lex. Used in unique_table() at least. */
+ child_l->select_lex= parent_l->select_lex;
+ /*
+ Set the expected table version, to not cause spurious re-prepare.
+ @todo: revise after the fix for Bug#36171
+ */
+ child_l->set_table_ref_id(mrg_child_def->get_child_table_ref_type(),
+ mrg_child_def->get_child_def_version());
+ /* Link TABLE_LIST object into the children list. */
+ if (this->children_last_l)
+ child_l->prev_global= this->children_last_l;
+ else
+ {
+ /* Initialize children_last_l when handling first child. */
+ this->children_last_l= &this->children_l;
+ }
+ *this->children_last_l= child_l;
+ this->children_last_l= &child_l->next_global;
+ }
+
+ /* Insert children into the table list. */
+ if (parent_l->next_global)
+ parent_l->next_global->prev_global= this->children_last_l;
+ *this->children_last_l= parent_l->next_global;
+ parent_l->next_global= this->children_l;
+ this->children_l->prev_global= &parent_l->next_global;
+ /*
+ We have to update LEX::query_tables_last if children are added to
+ the tail of the table list in order to be able correctly add more
+ elements to it (e.g. as part of prelocking process).
+ */
+ if (thd->lex->query_tables_last == &parent_l->next_global)
+ thd->lex->query_tables_last= this->children_last_l;
+
+end:
DBUG_RETURN(0);
}
/**
- @brief Callback function for attaching a MERGE child table.
+ A context of myrg_attach_children() callback.
+*/
- @detail This function retrieves the MyISAM table handle from the
- next child table. It is called for each child table.
+class Mrg_attach_children_callback_param
+{
+public:
+ /**
+ 'need_compat_check' is set by myisammrg_attach_children_callback()
+ if a child fails the table def version check.
+ */
+ bool need_compat_check;
+ /** TABLE_LIST identifying this merge parent. */
+ TABLE_LIST *parent_l;
+ /** Iterator position, the current child to attach. */
+ TABLE_LIST *next_child_attach;
+ List_iterator_fast<Mrg_child_def> def_it;
+ Mrg_child_def *mrg_child_def;
+public:
+ Mrg_attach_children_callback_param(TABLE_LIST *parent_l_arg,
+ TABLE_LIST *first_child,
+ List<Mrg_child_def> &child_def_list)
+ :need_compat_check(FALSE),
+ parent_l(parent_l_arg),
+ next_child_attach(first_child),
+ def_it(child_def_list),
+ mrg_child_def(def_it++)
+ {}
+ void next()
+ {
+ next_child_attach= next_child_attach->next_global;
+ if (next_child_attach && next_child_attach->parent_l != parent_l)
+ next_child_attach= NULL;
+ if (mrg_child_def)
+ mrg_child_def= def_it++;
+ }
+};
+
+
+/**
+ Callback function for attaching a MERGE child table.
- @param[in] callback_param data pointer as given to
- myrg_attach_children()
+ @param[in] callback_param data pointer as given to myrg_attach_children()
+ this is used to pass the handler handle
@return pointer to open MyISAM table structure
@retval !=NULL OK, returning pointer
@retval NULL, my_errno == 0 Ok, no more child tables
@retval NULL, my_errno != 0 error
+
+ @detail
+ This function retrieves the MyISAM table handle from the
+ next child table. It is called for each child table.
*/
static MI_INFO *myisammrg_attach_children_callback(void *callback_param)
{
- ha_myisammrg *ha_myrg;
- TABLE *parent;
+ Mrg_attach_children_callback_param *param=
+ (Mrg_attach_children_callback_param*) callback_param;
+ TABLE *parent= param->parent_l->table;
TABLE *child;
- TABLE_LIST *child_l;
- MI_INFO *myisam;
+ TABLE_LIST *child_l= param->next_child_attach;
+ Mrg_child_def *mrg_child_def= param->mrg_child_def;
+ MI_INFO *myisam= NULL;
DBUG_ENTER("myisammrg_attach_children_callback");
- my_errno= 0;
- ha_myrg= (ha_myisammrg*) callback_param;
- parent= ha_myrg->table_ptr();
-
- /* Get child list item. */
- child_l= ha_myrg->next_child_attach;
if (!child_l)
{
DBUG_PRINT("myrg", ("No more children to attach"));
- DBUG_RETURN(NULL);
+ my_errno= 0; /* Ok, no more child tables. */
+ goto end;
}
child= child_l->table;
- DBUG_PRINT("myrg", ("child table: '%s'.'%s' 0x%lx", child->s->db.str,
- child->s->table_name.str, (long) child));
- /*
- Prepare for next child. Used as child_l in next call to this function.
- We cannot rely on a NULL-terminated chain.
- */
- if (&child_l->next_global == parent->child_last_l)
- {
- DBUG_PRINT("myrg", ("attaching last child"));
- ha_myrg->next_child_attach= NULL;
- }
- else
- ha_myrg->next_child_attach= child_l->next_global;
-
- /* Set parent reference. */
- child->parent= parent;
+ /* Prepare for next child. */
+ param->next();
/*
Do a quick compatibility check. The table def version is set when
the table share is created. The child def version is copied
- from the table def version after a sucessful compatibility check.
+ from the table def version after a successful compatibility check.
We need to repeat the compatibility check only if a child is opened
from a different share than last time it was used with this MERGE
table.
*/
DBUG_PRINT("myrg", ("table_def_version last: %lu current: %lu",
- (ulong) child_l->get_child_def_version(),
+ (ulong) mrg_child_def->get_child_def_version(),
(ulong) child->s->get_table_def_version()));
- if (child_l->get_child_def_version() != child->s->get_table_def_version())
- ha_myrg->need_compat_check= TRUE;
+ if (mrg_child_def->get_child_def_version() != child->s->get_table_def_version())
+ param->need_compat_check= TRUE;
/*
If parent is temporary, children must be temporary too and vice
@@ -368,7 +568,7 @@ static MI_INFO *myisammrg_attach_children_callback(void *callback_param)
DBUG_PRINT("error", ("temporary table mismatch parent: %d child: %d",
parent->s->tmp_table, child->s->tmp_table));
my_errno= HA_ERR_WRONG_MRG_TABLE_DEF;
- goto err;
+ goto end;
}
/* Extract the MyISAM table structure pointer from the handler object. */
@@ -383,69 +583,12 @@ static MI_INFO *myisammrg_attach_children_callback(void *callback_param)
DBUG_PRINT("myrg", ("MyISAM handle: 0x%lx my_errno: %d",
(long) myisam, my_errno));
- err:
- DBUG_RETURN(my_errno ? NULL : myisam);
+ end:
+ DBUG_RETURN(myisam);
}
/**
- @brief Open a MERGE parent table, not its children.
-
- @detail This function initializes the MERGE storage engine structures
- and adds a child list of TABLE_LIST to the parent TABLE.
-
- @param[in] name MERGE table path name
- @param[in] mode read/write mode, unused
- @param[in] test_if_locked open flags
-
- @return status
- @retval 0 OK
- @retval -1 Error, my_errno gives reason
-*/
-
-int ha_myisammrg::open(const char *name, int mode __attribute__((unused)),
- uint test_if_locked)
-{
- DBUG_ENTER("ha_myisammrg::open");
- DBUG_PRINT("myrg", ("name: '%s' table: 0x%lx", name, (long) table));
- DBUG_PRINT("myrg", ("test_if_locked: %u", test_if_locked));
-
- /* Save for later use. */
- this->test_if_locked= test_if_locked;
-
- /* retrieve children table list. */
- my_errno= 0;
- if (is_cloned)
- {
- /*
- Open and attaches the MyISAM tables,that are under the MERGE table
- parent, on the MyISAM storage engine interface directly within the
- MERGE engine. The new MyISAM table instances, as well as the MERGE
- clone itself, are not visible in the table cache. This is not a
- problem because all locking is handled by the original MERGE table
- from which this is cloned of.
- */
- if (!(file= myrg_open(table->s->normalized_path.str, table->db_stat,
- HA_OPEN_IGNORE_IF_LOCKED)))
- {
- DBUG_PRINT("error", ("my_errno %d", my_errno));
- DBUG_RETURN(my_errno ? my_errno : -1);
- }
-
- file->children_attached= TRUE;
-
- info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
- }
- else if (!(file= myrg_parent_open(name, myisammrg_parent_open_callback, this)))
- {
- DBUG_PRINT("error", ("my_errno %d", my_errno));
- DBUG_RETURN(my_errno ? my_errno : -1);
- }
- DBUG_PRINT("myrg", ("MYRG_INFO: 0x%lx", (long) file));
- DBUG_RETURN(0);
-}
-
-/**
Returns a cloned instance of the current handler.
@return A cloned handler instance.
@@ -496,22 +639,24 @@ handler *ha_myisammrg::clone(MEM_ROOT *mem_root)
/**
- @brief Attach children to a MERGE table.
+ Attach children to a MERGE table.
- @detail Let the storage engine attach its children through a callback
+ @return status
+ @retval 0 OK
+ @retval != 0 Error, my_errno gives reason
+
+ @detail
+ Let the storage engine attach its children through a callback
function. Check table definitions for consistency.
- @note Special thd->open_options may be in effect. We can make use of
+ @note
+ Special thd->open_options may be in effect. We can make use of
them in attach. I.e. we use HA_OPEN_FOR_REPAIR to report the names
of mismatching child tables. We cannot transport these options in
ha_myisammrg::test_if_locked because they may change after the
parent is opened. The parent is kept open in the table cache over
multiple statements and can be used by other threads. Open options
can change over time.
-
- @return status
- @retval 0 OK
- @retval != 0 Error, my_errno gives reason
*/
int ha_myisammrg::attach_children(void)
@@ -521,36 +666,47 @@ int ha_myisammrg::attach_children(void)
MI_KEYDEF *keyinfo;
uint recs;
uint keys= table->s->keys;
+ TABLE_LIST *parent_l= table->pos_in_table_list;
int error;
+ Mrg_attach_children_callback_param param(parent_l, this->children_l, child_def_list);
DBUG_ENTER("ha_myisammrg::attach_children");
DBUG_PRINT("myrg", ("table: '%s'.'%s' 0x%lx", table->s->db.str,
table->s->table_name.str, (long) table));
DBUG_PRINT("myrg", ("test_if_locked: %u", this->test_if_locked));
+
+ /* Must call this with open table. */
+ DBUG_ASSERT(this->file);
+
+ /*
+ A MERGE table with no children (empty union) is always seen as
+ attached internally.
+ */
+ if (!this->file->tables)
+ {
+ DBUG_PRINT("myrg", ("empty merge table union"));
+ goto end;
+ }
+ DBUG_PRINT("myrg", ("child tables: %u", this->file->tables));
+
+ /* Must not call this with attached children. */
DBUG_ASSERT(!this->file->children_attached);
+ /* Must call this with children list in place. */
+ DBUG_ASSERT(this->table->pos_in_table_list->next_global == this->children_l);
+
/*
- Initialize variables that are used, modified, and/or set by
- myisammrg_attach_children_callback().
- 'next_child_attach' traverses the chain of TABLE_LIST objects
- that has been compiled during myrg_parent_open(). Every call
- to myisammrg_attach_children_callback() moves the pointer to
- the next object.
- 'need_compat_check' is set by myisammrg_attach_children_callback()
- if a child fails the table def version check.
'my_errno' is set by myisammrg_attach_children_callback() in
case of an error.
*/
- next_child_attach= table->child_l;
- need_compat_check= FALSE;
my_errno= 0;
if (myrg_attach_children(this->file, this->test_if_locked |
current_thd->open_options,
- myisammrg_attach_children_callback, this,
- (my_bool *) &need_compat_check))
+ myisammrg_attach_children_callback, &param,
+ (my_bool *) &param.need_compat_check))
{
- DBUG_PRINT("error", ("my_errno %d", my_errno));
- DBUG_RETURN(my_errno ? my_errno : -1);
+ error= my_errno;
+ goto err;
}
DBUG_PRINT("myrg", ("calling myrg_extrafunc"));
myrg_extrafunc(file, query_cache_invalidate_by_MyISAM_filename_ref);
@@ -567,8 +723,8 @@ int ha_myisammrg::attach_children(void)
always happen at the first attach because the reference child def
version is initialized to 'undefined' at open.
*/
- DBUG_PRINT("myrg", ("need_compat_check: %d", need_compat_check));
- if (need_compat_check)
+ DBUG_PRINT("myrg", ("need_compat_check: %d", param.need_compat_check));
+ if (param.need_compat_check)
{
TABLE_LIST *child_l;
@@ -577,7 +733,11 @@ int ha_myisammrg::attach_children(void)
DBUG_PRINT("error",("reclength: %lu mean_rec_length: %lu",
table->s->reclength, stats.mean_rec_length));
if (test_if_locked & HA_OPEN_FOR_REPAIR)
+ {
+ /* purecov: begin inspected */
myrg_print_wrong_table(file->open_tables->table->filename);
+ /* purecov: end */
+ }
error= HA_ERR_WRONG_MRG_TABLE_DEF;
goto err;
}
@@ -608,20 +768,25 @@ int ha_myisammrg::attach_children(void)
my_free((uchar*) recinfo, MYF(0));
goto err;
}
+ /* purecov: begin inspected */
myrg_print_wrong_table(u_table->table->filename);
+ /* purecov: end */
}
}
my_free((uchar*) recinfo, MYF(0));
if (error == HA_ERR_WRONG_MRG_TABLE_DEF)
- goto err;
+ goto err; /* purecov: inspected */
- /* All checks passed so far. Now update child def version. */
- for (child_l= table->child_l; ; child_l= child_l->next_global)
+ List_iterator_fast<Mrg_child_def> def_it(child_def_list);
+ DBUG_ASSERT(this->children_l);
+ for (child_l= this->children_l; ; child_l= child_l->next_global)
{
- child_l->set_child_def_version(
+ Mrg_child_def *mrg_child_def= def_it++;
+ mrg_child_def->set_child_def_version(
+ child_l->table->s->get_table_ref_type(),
child_l->table->s->get_table_def_version());
- if (&child_l->next_global == table->child_last_l)
+ if (&child_l->next_global == this->children_last_l)
break;
}
}
@@ -634,50 +799,132 @@ int ha_myisammrg::attach_children(void)
goto err;
}
#endif
+
+ end:
DBUG_RETURN(0);
err:
- myrg_detach_children(file);
+ DBUG_PRINT("error", ("attaching MERGE children failed: %d", error));
+ print_error(error, MYF(0));
+ detach_children();
DBUG_RETURN(my_errno= error);
}
/**
- @brief Detach all children from a MERGE table.
-
- @note Detach must not touch the children in any way.
- They may have been closed at ths point already.
- All references to the children should be removed.
+ Detach all children from a MERGE table and from the query list of tables.
@return status
@retval 0 OK
@retval != 0 Error, my_errno gives reason
+
+ @note
+ Detach must not touch the child TABLE objects in any way.
+ They may have been closed at ths point already.
+ All references to the children should be removed.
*/
int ha_myisammrg::detach_children(void)
{
+ TABLE_LIST *child_l;
DBUG_ENTER("ha_myisammrg::detach_children");
- DBUG_ASSERT(this->file && this->file->children_attached);
+
+ /* Must call this with open table. */
+ DBUG_ASSERT(this->file);
+
+ /* A MERGE table with no children (empty union) cannot be detached. */
+ if (!this->file->tables)
+ {
+ DBUG_PRINT("myrg", ("empty merge table union"));
+ goto end;
+ }
+
+ if (this->children_l)
+ {
+ THD *thd= table->in_use;
+
+ /* Clear TABLE references. */
+ for (child_l= this->children_l; ; child_l= child_l->next_global)
+ {
+ /*
+ Do not DBUG_ASSERT(child_l->table); open_tables might be
+ incomplete.
+
+ Clear the table reference.
+ */
+ child_l->table= NULL;
+ /* Similarly, clear the ticket reference. */
+ child_l->mdl_request.ticket= NULL;
+
+ /* Break when this was the last child. */
+ if (&child_l->next_global == this->children_last_l)
+ break;
+ }
+ /*
+ Remove children from the table list. This won't fail if called
+ twice. The list is terminated after removal.
+
+ If the parent is LEX::query_tables_own_last and pre-locked tables
+ follow (tables used by stored functions or triggers), the children
+ are inserted behind the parent and before the pre-locked tables. But
+ we do not adjust LEX::query_tables_own_last. The pre-locked tables
+ could have chopped off the list by clearing
+ *LEX::query_tables_own_last. This did also chop off the children. If
+ we would copy the reference from *this->children_last_l in this
+ case, we would put the chopped off pre-locked tables back to the
+ list. So we refrain from copying it back, if the destination has
+ been set to NULL meanwhile.
+ */
+ if (this->children_l->prev_global && *this->children_l->prev_global)
+ *this->children_l->prev_global= *this->children_last_l;
+ if (*this->children_last_l)
+ (*this->children_last_l)->prev_global= this->children_l->prev_global;
+
+ /*
+ If table elements being removed are at the end of table list we
+ need to adjust LEX::query_tables_last member to point to the
+ new last element of the list.
+ */
+ if (thd->lex->query_tables_last == this->children_last_l)
+ thd->lex->query_tables_last= this->children_l->prev_global;
+
+ /* Terminate child list. So it cannot be tried to remove again. */
+ *this->children_last_l= NULL;
+ this->children_l->prev_global= NULL;
+
+ /* Forget about the children, we don't own their memory. */
+ this->children_l= NULL;
+ this->children_last_l= NULL;
+ }
+
+ if (!this->file->children_attached)
+ {
+ DBUG_PRINT("myrg", ("merge children are already detached"));
+ goto end;
+ }
if (myrg_detach_children(this->file))
{
/* purecov: begin inspected */
- DBUG_PRINT("error", ("my_errno %d", my_errno));
+ print_error(my_errno, MYF(0));
DBUG_RETURN(my_errno ? my_errno : -1);
/* purecov: end */
}
+
+ end:
DBUG_RETURN(0);
}
/**
- @brief Close a MERGE parent table, not its children.
-
- @note The children are expected to be closed separately by the caller.
+ Close a MERGE parent table, but not its children.
@return status
@retval 0 OK
@retval != 0 Error, my_errno gives reason
+
+ @note
+ The children are expected to be closed separately by the caller.
*/
int ha_myisammrg::close(void)
@@ -685,11 +932,12 @@ int ha_myisammrg::close(void)
int rc;
DBUG_ENTER("ha_myisammrg::close");
/*
- Children must not be attached here. Unless the MERGE table has no
- children or the handler instance has been cloned. In these cases
- children_attached is always true.
+ There are cases where children are not explicitly detached before
+ close. detach_children() protects itself against double detach.
*/
- DBUG_ASSERT(!this->file->children_attached || !this->file->tables || this->is_cloned);
+ if (!is_cloned)
+ detach_children();
+
rc= myrg_close(file);
file= 0;
DBUG_RETURN(rc);
@@ -967,13 +1215,23 @@ int ha_myisammrg::info(uint flag)
int ha_myisammrg::extra(enum ha_extra_function operation)
{
- if (operation == HA_EXTRA_ATTACH_CHILDREN)
+ if (operation == HA_EXTRA_ADD_CHILDREN_LIST)
+ {
+ int rc= add_children_list();
+ return(rc);
+ }
+ else if (operation == HA_EXTRA_ATTACH_CHILDREN)
{
int rc= attach_children();
if (!rc)
(void) extra(HA_EXTRA_NO_READCHECK); // Not needed in SQL
return(rc);
}
+ else if (operation == HA_EXTRA_IS_ATTACHED_CHILDREN)
+ {
+ /* For the upper layer pretend empty MERGE union is never attached. */
+ return(file && file->tables && file->children_attached);
+ }
else if (operation == HA_EXTRA_DETACH_CHILDREN)
{
/*
@@ -994,6 +1252,7 @@ int ha_myisammrg::extra(enum ha_extra_function operation)
int ha_myisammrg::reset(void)
{
+ /* This is normally called with detached children. */
return myrg_reset(file);
}
@@ -1009,21 +1268,24 @@ int ha_myisammrg::extra_opt(enum ha_extra_function operation, ulong cache_size)
int ha_myisammrg::external_lock(THD *thd, int lock_type)
{
- DBUG_ASSERT(this->file->children_attached);
- return myrg_lock_database(file,lock_type);
+ /*
+ This can be called with no children attached. E.g. FLUSH TABLES
+ unlocks and re-locks tables under LOCK TABLES, but it does not open
+ them first. So they are detached all the time. But locking of the
+ children should work anyway because thd->open_tables is not changed
+ during FLUSH TABLES.
+
+ If this handler instance has been cloned, we still must call
+ myrg_lock_database().
+ */
+ if (is_cloned)
+ return myrg_lock_database(file, lock_type);
+ return 0;
}
uint ha_myisammrg::lock_count(void) const
{
- /*
- Return the real lock count even if the children are not attached.
- This method is used for allocating memory. If we would return 0
- to another thread (e.g. doing FLUSH TABLE), and attach the children
- before the other thread calls store_lock(), then we would return
- more locks in store_lock() than we claimed by lock_count(). The
- other tread would overrun its memory.
- */
- return file->tables;
+ return 0;
}
@@ -1031,37 +1293,6 @@ THR_LOCK_DATA **ha_myisammrg::store_lock(THD *thd,
THR_LOCK_DATA **to,
enum thr_lock_type lock_type)
{
- MYRG_TABLE *open_table;
-
- /*
- This method can be called while another thread is attaching the
- children. If the processor reorders instructions or write to memory,
- 'children_attached' could be set before 'open_tables' has all the
- pointers to the children. Use of a mutex here and in
- myrg_attach_children() forces consistent data.
- */
- pthread_mutex_lock(&this->file->mutex);
-
- /*
- When MERGE table is open, but not yet attached, other threads
- could flush it, which means call mysql_lock_abort_for_thread()
- on this threads TABLE. 'children_attached' is FALSE in this
- situaton. Since the table is not locked, return no lock data.
- */
- if (!this->file->children_attached)
- goto end; /* purecov: tested */
-
- for (open_table=file->open_tables ;
- open_table != file->end_table ;
- open_table++)
- {
- *(to++)= &open_table->table->lock;
- if (lock_type != TL_IGNORE && open_table->table->lock.type == TL_UNLOCK)
- open_table->table->lock.type=lock_type;
- }
-
- end:
- pthread_mutex_unlock(&this->file->mutex);
return to;
}
@@ -1150,7 +1381,7 @@ int ha_myisammrg::create(const char *name, register TABLE *form,
/* Allocate a table_names array in thread mem_root. */
if (!(table_names= (const char**)
thd->alloc((create_info->merge_list.elements+1) * sizeof(char*))))
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM); /* purecov: inspected */
/* Create child path names. */
for (pos= table_names; tables; tables= tables->next_local)
@@ -1260,7 +1491,7 @@ bool ha_myisammrg::check_if_incompatible_data(HA_CREATE_INFO *info,
int ha_myisammrg::check(THD* thd, HA_CHECK_OPT* check_opt)
{
- return HA_ADMIN_OK;
+ return this->file->children_attached ? HA_ADMIN_OK : HA_ADMIN_CORRUPT;
}
@@ -1282,6 +1513,10 @@ static int myisammrg_init(void *p)
myisammrg_hton= (handlerton *)p;
+#ifdef HAVE_PSI_INTERFACE
+ init_myisammrg_psi_keys();
+#endif
+
myisammrg_hton->db_type= DB_TYPE_MRG_MYISAM;
myisammrg_hton->create= myisammrg_create_handler;
myisammrg_hton->panic= myisammrg_panic;
diff --git a/storage/myisammrg/ha_myisammrg.h b/storage/myisammrg/ha_myisammrg.h
index 790aa15e90a..4ff24c69071 100644
--- a/storage/myisammrg/ha_myisammrg.h
+++ b/storage/myisammrg/ha_myisammrg.h
@@ -22,15 +22,62 @@
#include <myisammrg.h>
+/**
+ Represents one name of a MERGE child.
+
+ @todo: Add MYRG_SHARE and store chlidren names in the
+ share.
+*/
+
+class Mrg_child_def: public Sql_alloc
+{
+ /* Remembered MERGE child def version. See top comment in ha_myisammrg.cc */
+ enum_table_ref_type m_child_table_ref_type;
+ ulong m_child_def_version;
+public:
+ LEX_STRING db;
+ LEX_STRING name;
+
+ /* Access MERGE child def version. See top comment in ha_myisammrg.cc */
+ inline enum_table_ref_type get_child_table_ref_type()
+ {
+ return m_child_table_ref_type;
+ }
+ inline ulong get_child_def_version()
+ {
+ return m_child_def_version;
+ }
+ inline void set_child_def_version(enum_table_ref_type child_table_ref_type,
+ ulong version)
+ {
+ m_child_table_ref_type= child_table_ref_type;
+ m_child_def_version= version;
+ }
+
+ Mrg_child_def(char *db_arg, size_t db_len_arg,
+ char *table_name_arg, size_t table_name_len_arg)
+ {
+ db.str= db_arg;
+ db.length= db_len_arg;
+ name.str= table_name_arg;
+ name.length= table_name_len_arg;
+ m_child_def_version= ~0UL;
+ m_child_table_ref_type= TABLE_REF_NULL;
+ }
+};
+
+
class ha_myisammrg: public handler
{
MYRG_INFO *file;
my_bool is_cloned; /* This instance has been cloned */
- public:
- TABLE_LIST *next_child_attach; /* next child to attach */
+public:
+ MEM_ROOT children_mem_root; /* mem root for children list */
+ List<Mrg_child_def> child_def_list;
+ TABLE_LIST *children_l; /* children list */
+ TABLE_LIST **children_last_l; /* children list end */
uint test_if_locked; /* flags from ::open() */
- bool need_compat_check; /* if need compatibility check */
ha_myisammrg(handlerton *hton, TABLE_SHARE *table_arg);
~ha_myisammrg();
@@ -60,6 +107,7 @@ class ha_myisammrg: public handler
{ return ulonglong2double(stats.data_file_length) / IO_SIZE + file->tables; }
int open(const char *name, int mode, uint test_if_locked);
+ int add_children_list(void);
int attach_children(void);
int detach_children(void);
virtual handler *clone(MEM_ROOT *mem_root);
diff --git a/storage/myisammrg/myrg_close.c b/storage/myisammrg/myrg_close.c
index 97216ed47fe..45e0a82913a 100644
--- a/storage/myisammrg/myrg_close.c
+++ b/storage/myisammrg/myrg_close.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2001 MySQL AB
+/* Copyright (C) 2000-2001 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -55,10 +55,10 @@ int myrg_close(MYRG_INFO *info)
else
my_free((uchar*) info->rec_per_key_part, MYF(MY_ALLOW_ZERO_PTR));
delete_queue(&info->by_key);
- pthread_mutex_lock(&THR_LOCK_open);
+ mysql_mutex_lock(&THR_LOCK_open);
myrg_open_list=list_delete(myrg_open_list,&info->open_list);
- pthread_mutex_unlock(&THR_LOCK_open);
- VOID(pthread_mutex_destroy(&info->mutex));
+ mysql_mutex_unlock(&THR_LOCK_open);
+ mysql_mutex_destroy(&info->mutex);
my_free((uchar*) info,MYF(0));
if (error)
{
diff --git a/storage/myisammrg/myrg_create.c b/storage/myisammrg/myrg_create.c
index eaed470daec..5fbf8a44b8d 100644
--- a/storage/myisammrg/myrg_create.c
+++ b/storage/myisammrg/myrg_create.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2001, 2005 MySQL AB
+/* Copyright (C) 2000-2001, 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -32,9 +32,10 @@ int myrg_create(const char *name, const char **table_names,
DBUG_ENTER("myrg_create");
errpos=0;
- if ((file = my_create(fn_format(buff,name,"",MYRG_NAME_EXT,
- MY_UNPACK_FILENAME|MY_APPEND_EXT),0,
- O_RDWR | O_EXCL | O_NOFOLLOW,MYF(MY_WME))) < 0)
+ if ((file= mysql_file_create(rg_key_file_MRG,
+ fn_format(buff, name, "", MYRG_NAME_EXT,
+ MY_UNPACK_FILENAME|MY_APPEND_EXT), 0,
+ O_RDWR | O_EXCL | O_NOFOLLOW, MYF(MY_WME))) < 0)
goto err;
errpos=1;
if (table_names)
@@ -46,8 +47,8 @@ int myrg_create(const char *name, const char **table_names,
fn_same(buff,name,4);
*(end=strend(buff))='\n';
end[1]=0;
- if (my_write(file,(uchar*) buff,(uint) (end-buff+1),
- MYF(MY_WME | MY_NABP)))
+ if (mysql_file_write(file, (uchar*) buff, (uint) (end-buff+1),
+ MYF(MY_WME | MY_NABP)))
goto err;
}
}
@@ -55,10 +56,11 @@ int myrg_create(const char *name, const char **table_names,
{
end=strxmov(buff,"#INSERT_METHOD=",
get_type(&merge_insert_method,insert_method-1),"\n",NullS);
- if (my_write(file, (uchar*) buff,(uint) (end-buff),MYF(MY_WME | MY_NABP)))
+ if (mysql_file_write(file, (uchar*) buff, (uint) (end-buff),
+ MYF(MY_WME | MY_NABP)))
goto err;
}
- if (my_close(file,MYF(0)))
+ if (mysql_file_close(file, MYF(0)))
goto err;
DBUG_RETURN(0);
@@ -66,7 +68,7 @@ err:
save_errno=my_errno ? my_errno : -1;
switch (errpos) {
case 1:
- VOID(my_close(file,MYF(0)));
+ (void) mysql_file_close(file, MYF(0));
}
DBUG_RETURN(my_errno=save_errno);
} /* myrg_create */
diff --git a/storage/myisammrg/myrg_def.h b/storage/myisammrg/myrg_def.h
index 9c69da1424d..b916243be21 100644
--- a/storage/myisammrg/myrg_def.h
+++ b/storage/myisammrg/myrg_def.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2001, 2003 MySQL AB
+/* Copyright (C) 2000-2001, 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -24,7 +24,7 @@
extern LIST *myrg_open_list;
#ifdef THREAD
-extern pthread_mutex_t THR_LOCK_open;
+extern mysql_mutex_t THR_LOCK_open;
#endif
int _myrg_init_queue(MYRG_INFO *info,int inx,enum ha_rkey_function search_flag);
@@ -33,3 +33,14 @@ int _myrg_mi_read_record(MI_INFO *info, uchar *buf);
extern "C"
#endif
void myrg_print_wrong_table(const char *table_name);
+
+#ifdef HAVE_PSI_INTERFACE
+extern PSI_mutex_key rg_key_mutex_MYRG_INFO_mutex;
+
+extern PSI_file_key rg_key_file_MRG;
+
+C_MODE_START
+void init_myisammrg_psi_keys();
+C_MODE_END
+#endif /* HAVE_PSI_INTERFACE */
+
diff --git a/storage/myisammrg/myrg_extra.c b/storage/myisammrg/myrg_extra.c
index 3d14f6a56e6..0b9c138a188 100644
--- a/storage/myisammrg/myrg_extra.c
+++ b/storage/myisammrg/myrg_extra.c
@@ -75,12 +75,17 @@ int myrg_reset(MYRG_INFO *info)
MYRG_TABLE *file;
DBUG_ENTER("myrg_reset");
- if (!info->children_attached)
- DBUG_RETURN(1);
info->cache_in_use=0;
info->current_table=0;
info->last_used_table= info->open_tables;
-
+
+ /*
+ This is normally called with detached children.
+ Return OK as this is the normal case.
+ */
+ if (!info->children_attached)
+ DBUG_RETURN(0);
+
for (file=info->open_tables ; file != info->end_table ; file++)
{
int error;
diff --git a/storage/myisammrg/myrg_open.c b/storage/myisammrg/myrg_open.c
index 7b310dc2eed..d782224a680 100644
--- a/storage/myisammrg/myrg_open.c
+++ b/storage/myisammrg/myrg_open.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -50,9 +50,10 @@ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking)
DBUG_ENTER("myrg_open");
bzero((char*) &file,sizeof(file));
- if ((fd=my_open(fn_format(name_buff,name,"",MYRG_NAME_EXT,
- MY_UNPACK_FILENAME|MY_APPEND_EXT),
- O_RDONLY | O_SHARE,MYF(0))) < 0)
+ if ((fd= mysql_file_open(rg_key_file_MRG,
+ fn_format(name_buff, name, "", MYRG_NAME_EXT,
+ MY_UNPACK_FILENAME|MY_APPEND_EXT),
+ O_RDONLY | O_SHARE, MYF(0))) < 0)
goto err;
errpos=1;
if (init_io_cache(&file, fd, 4*IO_SIZE, READ_CACHE, 0, 0,
@@ -87,9 +88,9 @@ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking)
if (!has_path(buff))
{
- VOID(strmake(name_buff+dir_length,buff,
- sizeof(name_buff)-1-dir_length));
- VOID(cleanup_dirname(buff,name_buff));
+ (void) strmake(name_buff+dir_length,buff,
+ sizeof(name_buff)-1-dir_length);
+ (void) cleanup_dirname(buff,name_buff);
}
else
fn_format(buff, buff, "", "", 0);
@@ -167,13 +168,14 @@ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking)
m_info->last_used_table=m_info->open_tables;
m_info->children_attached= TRUE;
- VOID(my_close(fd,MYF(0)));
+ (void) mysql_file_close(fd, MYF(0));
end_io_cache(&file);
- VOID(pthread_mutex_init(&m_info->mutex, MY_MUTEX_INIT_FAST));
+ mysql_mutex_init(rg_key_mutex_MYRG_INFO_mutex,
+ &m_info->mutex, MY_MUTEX_INIT_FAST);
m_info->open_list.data=(void*) m_info;
- pthread_mutex_lock(&THR_LOCK_open);
+ mysql_mutex_lock(&THR_LOCK_open);
myrg_open_list=list_add(myrg_open_list,&m_info->open_list);
- pthread_mutex_unlock(&THR_LOCK_open);
+ mysql_mutex_unlock(&THR_LOCK_open);
DBUG_RETURN(m_info);
bad_children:
@@ -190,7 +192,7 @@ err:
end_io_cache(&file);
/* Fall through */
case 1:
- VOID(my_close(fd,MYF(0)));
+ (void) mysql_file_close(fd, MYF(0));
}
my_errno=save_errno;
DBUG_RETURN (NULL);
@@ -241,9 +243,11 @@ MYRG_INFO *myrg_parent_open(const char *parent_name,
bzero((char*) &file_cache, sizeof(file_cache));
/* Open MERGE meta file. */
- if ((fd= my_open(fn_format(parent_name_buff, parent_name, "", MYRG_NAME_EXT,
- MY_UNPACK_FILENAME|MY_APPEND_EXT),
- O_RDONLY | O_SHARE, MYF(0))) < 0)
+ if ((fd= mysql_file_open(rg_key_file_MRG,
+ fn_format(parent_name_buff, parent_name,
+ "", MYRG_NAME_EXT,
+ MY_UNPACK_FILENAME|MY_APPEND_EXT),
+ O_RDONLY | O_SHARE, MYF(0))) < 0)
goto err; /* purecov: inspected */
errpos= 1;
@@ -313,9 +317,9 @@ MYRG_INFO *myrg_parent_open(const char *parent_name,
if (!has_path(child_name_buff))
{
- VOID(strmake(parent_name_buff + dir_length, child_name_buff,
- sizeof(parent_name_buff) - 1 - dir_length));
- VOID(cleanup_dirname(child_name_buff, parent_name_buff));
+ (void) strmake(parent_name_buff + dir_length, child_name_buff,
+ sizeof(parent_name_buff) - 1 - dir_length);
+ (void) cleanup_dirname(child_name_buff, parent_name_buff);
}
else
fn_format(child_name_buff, child_name_buff, "", "", 0);
@@ -327,13 +331,14 @@ MYRG_INFO *myrg_parent_open(const char *parent_name,
}
end_io_cache(&file_cache);
- VOID(my_close(fd, MYF(0)));
- VOID(pthread_mutex_init(&m_info->mutex, MY_MUTEX_INIT_FAST));
+ (void) mysql_file_close(fd, MYF(0));
+ mysql_mutex_init(rg_key_mutex_MYRG_INFO_mutex,
+ &m_info->mutex, MY_MUTEX_INIT_FAST);
m_info->open_list.data= (void*) m_info;
- pthread_mutex_lock(&THR_LOCK_open);
+ mysql_mutex_lock(&THR_LOCK_open);
myrg_open_list= list_add(myrg_open_list, &m_info->open_list);
- pthread_mutex_unlock(&THR_LOCK_open);
+ mysql_mutex_unlock(&THR_LOCK_open);
DBUG_RETURN(m_info);
@@ -348,7 +353,7 @@ MYRG_INFO *myrg_parent_open(const char *parent_name,
end_io_cache(&file_cache);
/* Fall through */
case 1:
- VOID(my_close(fd, MYF(0)));
+ (void) mysql_file_close(fd, MYF(0));
}
my_errno= save_errno;
DBUG_RETURN (NULL);
@@ -405,7 +410,7 @@ int myrg_attach_children(MYRG_INFO *m_info, int handle_locking,
'open_tables' has all the pointers to the children. Use of a mutex
here and in ha_myisammrg::store_lock() forces consistent data.
*/
- pthread_mutex_lock(&m_info->mutex);
+ mysql_mutex_lock(&m_info->mutex);
rc= 1;
errpos= 0;
file_offset= 0;
@@ -485,7 +490,7 @@ int myrg_attach_children(MYRG_INFO *m_info, int handle_locking,
m_info->keys= min_keys;
m_info->last_used_table= m_info->open_tables;
m_info->children_attached= TRUE;
- pthread_mutex_unlock(&m_info->mutex);
+ mysql_mutex_unlock(&m_info->mutex);
DBUG_RETURN(0);
bad_children:
@@ -497,7 +502,7 @@ err:
my_free((char*) m_info->rec_per_key_part, MYF(0));
m_info->rec_per_key_part= NULL;
}
- pthread_mutex_unlock(&m_info->mutex);
+ mysql_mutex_unlock(&m_info->mutex);
my_errno= save_errno;
DBUG_RETURN(1);
}
@@ -520,7 +525,7 @@ int myrg_detach_children(MYRG_INFO *m_info)
{
DBUG_ENTER("myrg_detach_children");
/* For symmetry with myrg_attach_children() we use the mutex here. */
- pthread_mutex_lock(&m_info->mutex);
+ mysql_mutex_lock(&m_info->mutex);
if (m_info->tables)
{
/* Do not attach/detach an empty child list. */
@@ -531,7 +536,7 @@ int myrg_detach_children(MYRG_INFO *m_info)
m_info->del= 0;
m_info->data_file_length= 0;
m_info->options= 0;
- pthread_mutex_unlock(&m_info->mutex);
+ mysql_mutex_unlock(&m_info->mutex);
DBUG_RETURN(0);
}
diff --git a/storage/myisammrg/myrg_static.c b/storage/myisammrg/myrg_static.c
index c20d2be4396..b518a3d84c8 100644
--- a/storage/myisammrg/myrg_static.c
+++ b/storage/myisammrg/myrg_static.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2001, 2004 MySQL AB
+/* Copyright (C) 2000-2001, 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -27,3 +27,35 @@ static const char *merge_insert_methods[] =
{ "FIRST", "LAST", NullS };
TYPELIB merge_insert_method= { array_elements(merge_insert_methods)-1,"",
merge_insert_methods, 0};
+
+#ifdef HAVE_PSI_INTERFACE
+PSI_mutex_key rg_key_mutex_MYRG_INFO_mutex;
+
+static PSI_mutex_info all_myisammrg_mutexes[]=
+{
+ { &rg_key_mutex_MYRG_INFO_mutex, "MYRG_INFO::mutex", 0}
+};
+
+PSI_file_key rg_key_file_MRG;
+
+static PSI_file_info all_myisammrg_files[]=
+{
+ { &rg_key_file_MRG, "MRG", 0}
+};
+
+void init_myisammrg_psi_keys()
+{
+ const char* category= "myisammrg";
+ int count;
+
+ if (PSI_server == NULL)
+ return;
+
+ count= array_elements(all_myisammrg_mutexes);
+ PSI_server->register_mutex(category, all_myisammrg_mutexes, count);
+
+ count= array_elements(all_myisammrg_files);
+ PSI_server->register_file(category, all_myisammrg_files, count);
+}
+#endif /* HAVE_PSI_INTERFACE */
+
diff --git a/storage/ndb/include/kernel/signaldata/DictTabInfo.hpp b/storage/ndb/include/kernel/signaldata/DictTabInfo.hpp
index 3923d8e6fbf..43de91b7c22 100644
--- a/storage/ndb/include/kernel/signaldata/DictTabInfo.hpp
+++ b/storage/ndb/include/kernel/signaldata/DictTabInfo.hpp
@@ -30,10 +30,6 @@
#define DECIMAL_MAX_LENGTH ((8 * 9) - 8)
-#ifndef NOT_FIXED_DEC
-#define NOT_FIXED_DEC 31
-#endif
-
C_MODE_START
extern int decimal_bin_size(int, int);
C_MODE_END