diff options
Diffstat (limited to 'storage/archive')
-rw-r--r--[-rwxr-xr-x] | storage/archive/CMakeLists.txt | 12 | ||||
-rw-r--r-- | storage/archive/Makefile.am | 70 | ||||
-rw-r--r-- | storage/archive/archive_reader.c | 9 | ||||
-rw-r--r-- | storage/archive/azio.c | 22 | ||||
-rw-r--r-- | storage/archive/azlib.h | 3 | ||||
-rw-r--r-- | storage/archive/ha_archive.cc | 228 | ||||
-rw-r--r-- | storage/archive/ha_archive.h | 11 | ||||
-rw-r--r-- | storage/archive/plug.in | 4 |
8 files changed, 191 insertions, 168 deletions
diff --git a/storage/archive/CMakeLists.txt b/storage/archive/CMakeLists.txt index 8f03cc18617..78fb95c0d26 100755..100644 --- a/storage/archive/CMakeLists.txt +++ b/storage/archive/CMakeLists.txt @@ -1,5 +1,4 @@ -# Copyright (c) 2006-2008 MySQL AB, 2009 Sun Microsystems, Inc. -# Use is subject to license terms. +# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. # # 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 @@ -12,11 +11,8 @@ # # 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX") -SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX") - -INCLUDE("${PROJECT_SOURCE_DIR}/storage/mysql_storage_engine.cmake") SET(ARCHIVE_SOURCES azio.c ha_archive.cc ha_archive.h) -MYSQL_STORAGE_ENGINE(ARCHIVE) +MYSQL_ADD_PLUGIN(archive ${ARCHIVE_SOURCES} STORAGE_ENGINE LINK_LIBRARIES ${ZLIB_LIBRARY}) + diff --git a/storage/archive/Makefile.am b/storage/archive/Makefile.am deleted file mode 100644 index b220a2c662f..00000000000 --- a/storage/archive/Makefile.am +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. -# -# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -#called from the top level Makefile - -MYSQLDATAdir = $(localstatedir) -MYSQLSHAREdir = $(pkgdatadir) -MYSQLBASEdir= $(prefix) -MYSQLLIBdir= $(pkglibdir) -pkgplugindir = $(pkglibdir)/plugin -INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include \ - -I$(top_srcdir)/regex \ - -I$(top_srcdir)/sql \ - -I$(srcdir) @ZLIB_INCLUDES@ -WRAPLIBS= - -LDADD = - -DEFS = @DEFS@ - -noinst_HEADERS = ha_archive.h azlib.h -noinst_PROGRAMS = archive_test archive_reader - -EXTRA_LTLIBRARIES = ha_archive.la -pkgplugin_LTLIBRARIES = @plugin_archive_shared_target@ -ha_archive_la_LDFLAGS = -module -rpath $(pkgplugindir) -ha_archive_la_CXXFLAGS= $(AM_CXXFLAGS) -DMYSQL_DYNAMIC_PLUGIN -ha_archive_la_CFLAGS = $(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN -ha_archive_la_SOURCES = ha_archive.cc azio.c - - -EXTRA_LIBRARIES = libarchive.a -noinst_LIBRARIES = @plugin_archive_static_target@ -libarchive_a_CXXFLAGS = $(AM_CXXFLAGS) -libarchive_a_CFLAGS = $(AM_CFLAGS) -libarchive_a_SOURCES = ha_archive.cc azio.c - - -archive_test_SOURCES = archive_test.c azio.c -archive_test_CFLAGS = $(AM_CFLAGS) -archive_test_LDADD = $(top_builddir)/mysys/libmysys.a \ - $(top_builddir)/dbug/libdbug.a \ - $(top_builddir)/strings/libmystrings.a \ - @ZLIB_LIBS@ -archive_test_LDFLAGS = @NOINST_LDFLAGS@ - -archive_reader_SOURCES = archive_reader.c azio.c -archive_reader_CFLAGS = $(AM_CFLAGS) -archive_reader_LDADD = $(top_builddir)/mysys/libmysys.a \ - $(top_builddir)/dbug/libdbug.a \ - $(top_builddir)/strings/libmystrings.a \ - @ZLIB_LIBS@ -archive_reader_LDFLAGS = @NOINST_LDFLAGS@ - - -EXTRA_DIST = CMakeLists.txt plug.in -# Don't update the files from bitkeeper -%::SCCS/s.% diff --git a/storage/archive/archive_reader.c b/storage/archive/archive_reader.c index 2a426966e73..2475418fef9 100644 --- a/storage/archive/archive_reader.c +++ b/storage/archive/archive_reader.c @@ -216,7 +216,7 @@ int main(int argc, char *argv[]) ptr= (char *)my_malloc(sizeof(char) * reader_handle.frm_length, MYF(0)); azread_frm(&reader_handle, ptr); azwrite_frm(&writer_handle, ptr, reader_handle.frm_length); - my_free(ptr, MYF(0)); + my_free(ptr); } if (reader_handle.comment_length) @@ -225,7 +225,7 @@ int main(int argc, char *argv[]) ptr= (char *)my_malloc(sizeof(char) * reader_handle.comment_length, MYF(0)); azread_comment(&reader_handle, ptr); azwrite_comment(&writer_handle, ptr, reader_handle.comment_length); - my_free(ptr, MYF(0)); + my_free(ptr); } while ((read= azread(&reader_handle, (uchar *)size_buffer, @@ -280,7 +280,7 @@ int main(int argc, char *argv[]) azread_frm(&reader_handle, ptr); my_write(frm_file, (uchar*) ptr, reader_handle.frm_length, MYF(0)); my_close(frm_file, MYF(0)); - my_free(ptr, MYF(0)); + my_free(ptr); } end: @@ -404,7 +404,8 @@ static void print_version(void) static void get_options(int *argc, char ***argv) { - load_defaults("my", load_default_groups, argc, argv); + if (load_defaults("my", load_default_groups, argc, argv)) + exit(1); default_argv= *argv; handle_options(argc, argv, my_long_options, get_one_option); diff --git a/storage/archive/azio.c b/storage/archive/azio.c index aaf8233a30c..5fc9bc875f8 100644 --- a/storage/archive/azio.c +++ b/storage/archive/azio.c @@ -31,7 +31,7 @@ int az_open(azio_stream *s, const char *path, int Flags, File fd); int do_flush(azio_stream *file, int flush); int get_byte(azio_stream *s); void check_header(azio_stream *s); -void write_header(azio_stream *s); +int write_header(azio_stream *s); int destroy(azio_stream *s); void putLong(File file, uLong x); uLong getLong(azio_stream *s); @@ -164,7 +164,7 @@ int az_open (azio_stream *s, const char *path, int Flags, File fd) } -void write_header(azio_stream *s) +int write_header(azio_stream *s) { char buffer[AZHEADER_SIZE + AZMETA_BUFFER_SIZE]; char *ptr= buffer; @@ -200,8 +200,8 @@ void write_header(azio_stream *s) *(ptr + AZ_DIRTY_POS)= (unsigned char)s->dirty; /* Start of Data Block Index Block */ /* Always begin at the begining, and end there as well */ - my_pwrite(s->file, (uchar*) buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0, - MYF(0)); + return my_pwrite(s->file, (uchar*) buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, + 0, MYF(MY_NABP)) ? 1 : 0; } /* =========================================================================== @@ -847,19 +847,19 @@ int azwrite_frm(azio_stream *s, char *blob, unsigned int length) s->frm_length= length; s->start+= length; - my_pwrite(s->file, (uchar*) blob, s->frm_length, s->frm_start_pos, MYF(0)); - - write_header(s); - my_seek(s->file, 0, MY_SEEK_END, MYF(0)); + if (my_pwrite(s->file, (uchar*) blob, s->frm_length, + s->frm_start_pos, MYF(MY_NABP)) || + write_header(s) || + (my_seek(s->file, 0, MY_SEEK_END, MYF(0)) == MY_FILEPOS_ERROR)) + return 1; return 0; } int azread_frm(azio_stream *s, char *blob) { - my_pread(s->file, (uchar*) blob, s->frm_length, s->frm_start_pos, MYF(0)); - - return 0; + return my_pread(s->file, (uchar*) blob, s->frm_length, + s->frm_start_pos, MYF(MY_NABP)) ? 1 : 0; } diff --git a/storage/archive/azlib.h b/storage/archive/azlib.h index d7abb40b2ae..29a6329fb0a 100644 --- a/storage/archive/azlib.h +++ b/storage/archive/azlib.h @@ -33,10 +33,9 @@ (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). */ -#include <zlib.h> - #include "../../mysys/mysys_priv.h" #include <my_dir.h> +#include <zlib.h> #ifdef __cplusplus extern "C" { diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc index dc88f1d652f..332afb4d437 100644 --- a/storage/archive/ha_archive.cc +++ b/storage/archive/ha_archive.cc @@ -20,7 +20,10 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" // SSV +#include "sql_table.h" #include <myisam.h> #include "ha_archive.h" @@ -97,7 +100,7 @@ */ /* Variables for archive share methods */ -pthread_mutex_t archive_mutex; +mysql_mutex_t archive_mutex; static HASH archive_open_tables; /* The file extension */ @@ -147,6 +150,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. @@ -165,6 +190,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; @@ -172,12 +201,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 (hash_init(&archive_open_tables, table_alias_charset, 32, 0, 0, - (hash_get_key) archive_get_key, 0, 0)) + 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 { @@ -200,8 +230,8 @@ error: int archive_db_done(void *p) { - hash_free(&archive_open_tables); - VOID(pthread_mutex_destroy(&archive_mutex)); + my_hash_free(&archive_open_tables); + mysql_mutex_destroy(&archive_mutex); return 0; } @@ -230,7 +260,7 @@ int archive_discover(handlerton *hton, THD* thd, const char *db, char *frm_ptr; MY_STAT file_stat; - fn_format(az_file, name, db, ARZ, MY_REPLACE_EXT | MY_UNPACK_FILENAME); + build_table_filename(az_file, sizeof(az_file) - 1, db, name, ARZ, 0); if (!(my_stat(az_file, &file_stat, MYF(0)))) goto err; @@ -315,12 +345,12 @@ 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*) hash_search(&archive_open_tables, - (uchar*) table_name, - length))) + if (!(share=(ARCHIVE_SHARE*) my_hash_search(&archive_open_tables, + (uchar*) table_name, + length))) { char *tmp_name; azio_stream archive_tmp; @@ -330,7 +360,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); } @@ -348,7 +378,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 @@ -359,8 +390,8 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc) if (!(azopen(&archive_tmp, share->data_file_name, O_RDONLY|O_BINARY))) { *rc= my_errno ? my_errno : -1; - pthread_mutex_unlock(&archive_mutex); - my_free(share, MYF(0)); + mysql_mutex_unlock(&archive_mutex); + my_free(share); DBUG_RETURN(NULL); } stats.auto_increment_value= archive_tmp.auto_increment + 1; @@ -374,7 +405,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc) *rc= HA_ERR_TABLE_NEEDS_UPGRADE; 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++; @@ -383,7 +414,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); } @@ -402,12 +433,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) { - hash_delete(&archive_open_tables, (uchar*) share); + 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 @@ -420,9 +451,9 @@ int ha_archive::free_share() if (azclose(&(share->archive_write))) rc= 1; } - my_free((uchar*) share, MYF(0)); + my_free(share); } - pthread_mutex_unlock(&archive_mutex); + mysql_mutex_unlock(&archive_mutex); DBUG_RETURN(rc); } @@ -586,6 +617,34 @@ int ha_archive::close(void) } +/** + Copy a frm blob between streams. + + @param src The source stream. + @param dst The destination stream. + + @return Zero on success, non-zero otherwise. +*/ + +int ha_archive::frm_copy(azio_stream *src, azio_stream *dst) +{ + int rc= 0; + char *frm_ptr; + + if (!(frm_ptr= (char *) my_malloc(src->frm_length, MYF(0)))) + return HA_ERR_OUT_OF_MEM; + + /* Write file offset is set to the end of the file. */ + if (azread_frm(src, frm_ptr) || + azwrite_frm(dst, frm_ptr, src->frm_length)) + rc= my_errno ? my_errno : HA_ERR_INTERNAL_ERROR; + + my_free(frm_ptr); + + return rc; +} + + /* We create our data file here. The format is pretty simple. You can read about the format of the data file above. @@ -672,14 +731,14 @@ 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) { my_read(frm_file, frm_ptr, file_stat.st_size, MYF(0)); azwrite_frm(&create_stream, (char *)frm_ptr, file_stat.st_size); - my_free((uchar*)frm_ptr, MYF(0)); + my_free(frm_ptr); } } my_close(frm_file, MYF(0)); @@ -822,7 +881,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()) @@ -905,9 +964,8 @@ int ha_archive::write_row(uchar *buf) share->rows_recorded++; rc= real_write_row(buf, &(share->archive_write)); error: - pthread_mutex_unlock(&share->mutex); - if (read_buf) - my_free((uchar*) read_buf, MYF(0)); + mysql_mutex_unlock(&share->mutex); + my_free(read_buf); DBUG_RETURN(rc); } @@ -940,7 +998,9 @@ int ha_archive::index_read(uchar *buf, const uchar *key, { int rc; DBUG_ENTER("ha_archive::index_read"); + MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str); rc= index_read_idx(buf, active_index, key, key_len, find_flag); + MYSQL_INDEX_READ_ROW_DONE(rc); DBUG_RETURN(rc); } @@ -973,7 +1033,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); @@ -983,8 +1047,10 @@ error: int ha_archive::index_next(uchar * buf) { bool found= 0; + int rc; DBUG_ENTER("ha_archive::index_next"); + MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str); while (!(get_row(&archive, buf))) { @@ -995,7 +1061,9 @@ int ha_archive::index_next(uchar * buf) } } - DBUG_RETURN(found ? 0 : HA_ERR_END_OF_FILE); + rc= found ? 0 : HA_ERR_END_OF_FILE; + MYSQL_INDEX_READ_ROW_DONE(rc); + DBUG_RETURN(rc); } /* @@ -1233,12 +1301,17 @@ int ha_archive::rnd_next(uchar *buf) { int rc; DBUG_ENTER("ha_archive::rnd_next"); + MYSQL_READ_ROW_START(table_share->db.str, + table_share->table_name.str, TRUE); if (share->crashed) DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE); if (!scan_rows) - DBUG_RETURN(HA_ERR_END_OF_FILE); + { + rc= HA_ERR_END_OF_FILE; + goto end; + } scan_rows--; ha_statistic_increment(&SSV::ha_read_rnd_next_count); @@ -1247,6 +1320,8 @@ int ha_archive::rnd_next(uchar *buf) table->status=rc ? STATUS_NOT_FOUND: 0; +end: + MYSQL_READ_ROW_DONE(rc); DBUG_RETURN(rc); } @@ -1274,12 +1349,21 @@ void ha_archive::position(const uchar *record) int ha_archive::rnd_pos(uchar * buf, uchar *pos) { + int rc; DBUG_ENTER("ha_archive::rnd_pos"); + MYSQL_READ_ROW_START(table_share->db.str, + table_share->table_name.str, FALSE); ha_statistic_increment(&SSV::ha_read_rnd_next_count); current_position= (my_off_t)my_get_ptr(pos, ref_length); if (azseek(&archive, current_position, SEEK_SET) == (my_off_t)(-1L)) - DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE); - DBUG_RETURN(get_row(&archive, buf)); + { + rc= HA_ERR_CRASHED_ON_USAGE; + goto end; + } + rc= get_row(&archive, buf); +end: + MYSQL_READ_ROW_DONE(rc); + DBUG_RETURN(rc); } /* @@ -1305,12 +1389,12 @@ int ha_archive::repair(THD* thd, HA_CHECK_OPT* check_opt) */ int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt) { - DBUG_ENTER("ha_archive::optimize"); int rc= 0; azio_stream writer; char writer_filename[FN_REFLEN]; + DBUG_ENTER("ha_archive::optimize"); - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); init_archive_reader(); // now we close both our writer and our reader for the rename @@ -1326,10 +1410,17 @@ int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt) if (!(azopen(&writer, writer_filename, O_CREAT|O_RDWR|O_BINARY))) { - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE); } + /* + Transfer the embedded FRM so that the file can be discoverable. + Write file offset is set to the end of the file. + */ + if ((rc= frm_copy(&archive, &writer))) + goto error; + /* An extended rebuild is a lot more effort. We open up each row and re-record it. Any dead rows are removed (aka rows that may have been partially recorded). @@ -1404,15 +1495,15 @@ 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)); - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); DBUG_RETURN(rc); error: DBUG_PRINT("ha_archive", ("Failed to recover, error was %d", rc)); azclose(&writer); - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); DBUG_RETURN(rc); } @@ -1490,7 +1581,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) @@ -1506,34 +1597,42 @@ 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; DBUG_PRINT("ha_archive", ("Stats rows is %d\n", (int)stats.records)); /* Costs quite a bit more to get all information */ - if (flag & HA_STATUS_TIME) + if (flag & (HA_STATUS_TIME | HA_STATUS_CONST | HA_STATUS_VARIABLE)) { 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; - stats.update_time= (ulong) file_stat.st_mtime; - stats.mean_rec_length= stats.records ? - ulong(stats.data_file_length / stats.records) : table->s->reclength; - stats.max_data_file_length= MAX_FILE_SIZE; + if (flag & HA_STATUS_TIME) + stats.update_time= (ulong) file_stat.st_mtime; + if (flag & HA_STATUS_CONST) + { + stats.max_data_file_length= share->rows_recorded * stats.mean_rec_length; + stats.max_data_file_length= MAX_FILE_SIZE; + stats.create_time= (ulong) file_stat.st_ctime; + } + if (flag & HA_STATUS_VARIABLE) + { + stats.delete_length= 0; + stats.data_file_length= file_stat.st_size; + stats.index_file_length=0; + stats.mean_rec_length= stats.records ? + ulong(stats.data_file_length / stats.records) : table->s->reclength; + } } - stats.delete_length= 0; - stats.index_file_length=0; 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; } @@ -1573,9 +1672,9 @@ int ha_archive::end_bulk_insert() This is done for security reasons. In a later version we will enable this by allowing the user to select a different row format. */ -int ha_archive::delete_all_rows() +int ha_archive::truncate() { - DBUG_ENTER("ha_archive::delete_all_rows"); + DBUG_ENTER("ha_archive::truncate"); DBUG_RETURN(HA_ERR_WRONG_COMMAND); } @@ -1600,12 +1699,12 @@ int ha_archive::check(THD* thd, HA_CHECK_OPT* check_opt) DBUG_ENTER("ha_archive::check"); old_proc_info= thd_proc_info(thd, "Checking table"); - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); count= share->rows_recorded; /* Flush any waiting data */ if (share->archive_write_open) azflush(&(share->archive_write), Z_SYNC_FLUSH); - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); if (init_archive_reader()) DBUG_RETURN(HA_ADMIN_CORRUPT); @@ -1624,13 +1723,13 @@ int ha_archive::check(THD* thd, HA_CHECK_OPT* check_opt) Acquire share->mutex so tail of the table is not modified by concurrent writers. */ - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); count= share->rows_recorded - count; if (share->archive_write_open) azflush(&(share->archive_write), Z_SYNC_FLUSH); while (!(rc= get_row(&archive, table->record[0]))) count--; - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); if ((rc && rc != HA_ERR_END_OF_FILE) || count) goto error; @@ -1672,7 +1771,7 @@ archive_record_buffer *ha_archive::create_record_buffer(unsigned int length) if (!(r->buffer= (uchar*) my_malloc(r->length, MYF(MY_WME)))) { - my_free((char*) r, MYF(MY_ALLOW_ZERO_PTR)); + my_free(r); DBUG_RETURN(NULL); /* purecov: inspected */ } @@ -1682,8 +1781,8 @@ archive_record_buffer *ha_archive::create_record_buffer(unsigned int length) void ha_archive::destroy_record_buffer(archive_record_buffer *r) { DBUG_ENTER("ha_archive::destroy_record_buffer"); - my_free((char*) r->buffer, MYF(MY_ALLOW_ZERO_PTR)); - my_free((char*) r, MYF(MY_ALLOW_ZERO_PTR)); + my_free(r->buffer); + my_free(r); DBUG_VOID_RETURN; } @@ -1703,7 +1802,8 @@ mysql_declare_plugin(archive) 0x0300 /* 3.0 */, NULL, /* status variables */ NULL, /* system variables */ - NULL /* config options */ + NULL, /* config options */ + 0, /* flags */ } mysql_declare_plugin_end; diff --git a/storage/archive/ha_archive.h b/storage/archive/ha_archive.h index ab630ed22fd..5aa68afed65 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, 2011, Oracle and/or its affiliates. All rights reserved. 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 @@ -11,7 +11,7 @@ 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 */ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifdef USE_PRAGMA_INTERFACE #pragma interface /* gcc class implementation */ @@ -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; @@ -75,6 +75,7 @@ class ha_archive: public handler archive_record_buffer *create_record_buffer(unsigned int length); void destroy_record_buffer(archive_record_buffer *r); + int frm_copy(azio_stream *src, azio_stream *dst); public: ha_archive(handlerton *hton, TABLE_SHARE *table_arg); @@ -89,7 +90,7 @@ public: return (HA_NO_TRANSACTIONS | HA_REC_NOT_IN_SEQ | HA_CAN_BIT_FIELD | HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE | HA_STATS_RECORDS_IS_EXACT | - HA_HAS_RECORDS | + HA_HAS_RECORDS | HA_CAN_REPAIR | HA_FILE_BASED | HA_CAN_INSERT_DELAYED | HA_CAN_GEOMETRY); } ulong index_flags(uint idx, uint part, bool all_parts) const @@ -114,7 +115,7 @@ public: int close(void); int write_row(uchar * buf); int real_write_row(uchar *buf, azio_stream *writer); - int delete_all_rows(); + int truncate(); int rnd_init(bool scan=1); int rnd_next(uchar *buf); int rnd_pos(uchar * buf, uchar *pos); diff --git a/storage/archive/plug.in b/storage/archive/plug.in deleted file mode 100644 index 52131b12e6b..00000000000 --- a/storage/archive/plug.in +++ /dev/null @@ -1,4 +0,0 @@ -MYSQL_STORAGE_ENGINE(archive,, [Archive Storage Engine], - [Archive Storage Engine], [max,max-no-ndb]) -MYSQL_PLUGIN_STATIC(archive, [libarchive.a]) -MYSQL_PLUGIN_DYNAMIC(archive, [ha_archive.la]) |