summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/t/archive.test2
-rw-r--r--sql/examples/ha_archive.cc59
-rw-r--r--sql/examples/ha_archive.h4
-rw-r--r--sql/handler.cc14
4 files changed, 60 insertions, 19 deletions
diff --git a/mysql-test/t/archive.test b/mysql-test/t/archive.test
index f55aea6e104..ee78b53f9c8 100644
--- a/mysql-test/t/archive.test
+++ b/mysql-test/t/archive.test
@@ -1,6 +1,6 @@
#
# Simple test for archive example
-# Taken fromm the select test
+# Taken from the select test
#
-- source include/have_archive.inc
diff --git a/sql/examples/ha_archive.cc b/sql/examples/ha_archive.cc
index ef609513489..e8d07a99048 100644
--- a/sql/examples/ha_archive.cc
+++ b/sql/examples/ha_archive.cc
@@ -116,7 +116,6 @@
/* Variables for archive share methods */
pthread_mutex_t archive_mutex;
static HASH archive_open_tables;
-static int archive_init= 0;
/* The file extension */
#define ARZ ".ARZ" // The data file
@@ -142,6 +141,46 @@ static byte* archive_get_key(ARCHIVE_SHARE *share,uint *length,
return (byte*) share->table_name;
}
+
+/*
+ Initialize the archive handler.
+
+ SYNOPSIS
+ archive_db_init()
+ void
+
+ RETURN
+ FALSE OK
+ TRUE Error
+*/
+
+bool archive_db_init()
+{
+ VOID(pthread_mutex_init(&archive_mutex, MY_MUTEX_INIT_FAST));
+ return (hash_init(&archive_open_tables, system_charset_info, 32, 0, 0,
+ (hash_get_key) archive_get_key, 0, 0));
+}
+
+
+/*
+ Release the archive handler.
+
+ SYNOPSIS
+ archive_db_end()
+ void
+
+ RETURN
+ FALSE OK
+*/
+
+bool archive_db_end()
+{
+ hash_free(&archive_open_tables);
+ VOID(pthread_mutex_destroy(&archive_mutex));
+ return FALSE;
+}
+
+
/*
This method reads the header of a datafile and returns whether or not it was successful.
*/
@@ -269,23 +308,6 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, TABLE *table)
uint length;
char *tmp_name;
- if (!archive_init)
- {
- /* Hijack a mutex for init'ing the storage engine */
- pthread_mutex_lock(&LOCK_mysql_create_db);
- if (!archive_init)
- {
- VOID(pthread_mutex_init(&archive_mutex,MY_MUTEX_INIT_FAST));
- if (hash_init(&archive_open_tables,system_charset_info,32,0,0,
- (hash_get_key) archive_get_key,0,0))
- {
- pthread_mutex_unlock(&LOCK_mysql_create_db);
- return NULL;
- }
- archive_init++;
- }
- pthread_mutex_unlock(&LOCK_mysql_create_db);
- }
pthread_mutex_lock(&archive_mutex);
length=(uint) strlen(table_name);
@@ -379,6 +401,7 @@ int ha_archive::free_share(ARCHIVE_SHARE *share)
(void)write_meta_file(share->meta_file, share->rows_recorded, FALSE);
if (gzclose(share->archive_write) == Z_ERRNO)
rc= 1;
+ my_close(share->meta_file,MYF(0));
my_free((gptr) share, MYF(0));
}
pthread_mutex_unlock(&archive_mutex);
diff --git a/sql/examples/ha_archive.h b/sql/examples/ha_archive.h
index b619de5f6c1..855d756368d 100644
--- a/sql/examples/ha_archive.h
+++ b/sql/examples/ha_archive.h
@@ -125,3 +125,7 @@ public:
THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
enum thr_lock_type lock_type);
};
+
+bool archive_db_init(void);
+bool archive_db_end(void);
+
diff --git a/sql/handler.cc b/sql/handler.cc
index 3200c6932e9..70ba236a5d5 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -278,6 +278,16 @@ int ha_init()
opt_using_transactions=1;
}
#endif
+#ifdef HAVE_ARCHIVE_DB
+ if (have_archive_db == SHOW_OPTION_YES)
+ {
+ if (archive_db_init())
+ {
+ have_archive_db= SHOW_OPTION_DISABLED;
+ error= 1;
+ }
+ }
+#endif
return error;
}
@@ -309,6 +319,10 @@ int ha_panic(enum ha_panic_function flag)
if (have_ndbcluster == SHOW_OPTION_YES)
error|=ndbcluster_end();
#endif
+#ifdef HAVE_ARCHIVE_DB
+ if (have_archive_db == SHOW_OPTION_YES)
+ error|= archive_db_end();
+#endif
return error;
} /* ha_panic */