summaryrefslogtreecommitdiff
path: root/storage/archive
diff options
context:
space:
mode:
authorVladislav Vaintroub <vvaintroub@mysql.com>2009-12-10 11:47:31 +0100
committerVladislav Vaintroub <vvaintroub@mysql.com>2009-12-10 11:47:31 +0100
commit6c3bbb2800e2171c25f46858495ce5d0b2b65ade (patch)
tree05ef9e5a492c829152490fa55b8eddf54c746dda /storage/archive
parent3a72f357ee84eeeb7511c431472a7c60bef6ddcd (diff)
parentfd433cfb96adcbb013b27838cd80576dff92989d (diff)
downloadmariadb-git-6c3bbb2800e2171c25f46858495ce5d0b2b65ade.tar.gz
merge
Diffstat (limited to 'storage/archive')
-rw-r--r--storage/archive/ha_archive.cc76
-rw-r--r--storage/archive/ha_archive.h4
2 files changed, 56 insertions, 24 deletions
diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc
index a341843662f..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))
{
- 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);
- 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.
*/
- 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
@@ -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);
- 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;
@@ -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;