diff options
Diffstat (limited to 'storage/csv')
-rw-r--r-- | storage/csv/ha_tina.cc | 224 | ||||
-rw-r--r-- | storage/csv/ha_tina.h | 4 | ||||
-rw-r--r-- | storage/csv/transparent_file.cc | 15 |
3 files changed, 152 insertions, 91 deletions
diff --git a/storage/csv/ha_tina.cc b/storage/csv/ha_tina.cc index 5348b5b9331..65d7cd4a9c1 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; - 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"); - 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; - 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); } @@ -769,9 +815,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 +871,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 +903,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 +932,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 +959,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 +1005,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 +1040,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 +1069,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 +1234,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 +1305,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 +1329,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 +1350,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 +1388,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 +1474,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 +1493,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 +1508,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 +1517,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 +1558,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 +1608,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 3d7afae85d4..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; - 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]; - 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; |