summaryrefslogtreecommitdiff
path: root/storage/csv
diff options
context:
space:
mode:
Diffstat (limited to 'storage/csv')
-rw-r--r--storage/csv/CMakeLists.txt8
-rw-r--r--storage/csv/Makefile.am42
-rw-r--r--storage/csv/ha_tina.cc375
-rw-r--r--storage/csv/ha_tina.h15
-rw-r--r--storage/csv/plug.in4
-rw-r--r--storage/csv/transparent_file.cc26
-rw-r--r--storage/csv/transparent_file.h6
7 files changed, 279 insertions, 197 deletions
diff --git a/storage/csv/CMakeLists.txt b/storage/csv/CMakeLists.txt
index 5fab7eef0c4..31e41b6d3f8 100644
--- a/storage/csv/CMakeLists.txt
+++ b/storage/csv/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,8 +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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-INCLUDE("${PROJECT_SOURCE_DIR}/storage/mysql_storage_engine.cmake")
SET(CSV_SOURCES ha_tina.cc ha_tina.h transparent_file.cc transparent_file.h)
-MYSQL_STORAGE_ENGINE(CSV) \ No newline at end of file
+MYSQL_ADD_PLUGIN(csv ${CSV_SOURCES} STORAGE_ENGINE MANDATORY)
diff --git a/storage/csv/Makefile.am b/storage/csv/Makefile.am
deleted file mode 100644
index e21dc9c5ede..00000000000
--- a/storage/csv/Makefile.am
+++ /dev/null
@@ -1,42 +0,0 @@
-# Copyright (c) 2005, 2010, Oracle and/or its affiliates
-#
-# 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)
-INCLUDES = -I$(top_builddir)/include \
- -I$(top_srcdir)/include \
- -I$(top_srcdir)/regex \
- -I$(top_srcdir)/sql \
- -I$(srcdir)
-LDADD =
-
-DEFS = @DEFS@
-noinst_HEADERS = ha_tina.h transparent_file.h
-
-EXTRA_LTLIBRARIES = libcsv.la ha_csv.la
-pkglib_LTLIBRARIES = @plugin_csv_shared_target@
-ha_csv_la_LDFLAGS = -module -rpath $(MYSQLLIBdir)
-ha_csv_la_CXXFLAGS = -shared $(AM_CXXFLAGS) -DMYSQL_PLUGIN
-ha_csv_la_SOURCES = transparent_file.cc ha_tina.cc
-
-noinst_LTLIBRARIES = @plugin_csv_static_target@
-libcsv_la_CXXFLAGS = $(AM_CXXFLAGS)
-libcsv_la_SOURCES = transparent_file.cc ha_tina.cc
-
-EXTRA_DIST = CMakeLists.txt plug.in
diff --git a/storage/csv/ha_tina.cc b/storage/csv/ha_tina.cc
index 26d6e16b9d4..d31e5ee8d89 100644
--- a/storage/csv/ha_tina.cc
+++ b/storage/csv/ha_tina.cc
@@ -1,5 +1,4 @@
-/*
- Copyright (c) 2004, 2010, Oracle and/or its affiliates
+/* Copyright (c) 2004, 2011, Oracle and/or its affiliates.
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,8 +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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
/*
Make sure to look at ha_tina.h for more details.
@@ -47,9 +45,13 @@ TODO:
#pragma implementation // gcc: Class implementation
#endif
-#include "mysql_priv.h"
+#include "my_global.h"
+#include "sql_priv.h"
+#include "sql_class.h" // SSV
#include <mysql/plugin.h>
+#include <mysql/psi/mysql_file.h>
#include "ha_tina.h"
+#include "probes_mysql.h"
/*
@@ -76,7 +78,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,
@@ -106,14 +108,54 @@ 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));
- (void) hash_init(&tina_open_tables,system_charset_info,32,0,0,
- (hash_get_key) tina_get_key,0,0);
+ 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;
tina_hton->db_type= DB_TYPE_CSV_DB;
tina_hton->create= tina_create_handler;
@@ -124,8 +166,8 @@ static int tina_init_func(void *p)
static int tina_done_func(void *p)
{
- hash_free(&tina_open_tables);
- pthread_mutex_destroy(&tina_mutex);
+ my_hash_free(&tina_open_tables);
+ mysql_mutex_destroy(&tina_mutex);
return 0;
}
@@ -142,23 +184,23 @@ 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);
/*
If share is not present in the hash, create a new share and
initialize its members.
*/
- if (!(share=(TINA_SHARE*) hash_search(&tina_open_tables,
- (uchar*) table_name,
- length)))
+ if (!(share=(TINA_SHARE*) my_hash_search(&tina_open_tables,
+ (uchar*) table_name,
+ length)))
{
if (!my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
&share, sizeof(*share),
&tmp_name, length+1,
NullS))
{
- pthread_mutex_unlock(&tina_mutex);
+ mysql_mutex_unlock(&tina_mutex);
return NULL;
}
@@ -177,14 +219,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
@@ -192,20 +236,22 @@ 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);
- my_free((uchar*) share, MYF(0));
+ mysql_mutex_unlock(&tina_mutex);
+ my_free(share);
return NULL;
}
@@ -237,8 +283,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);
@@ -260,7 +306,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);
}
@@ -306,12 +352,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);
}
@@ -339,7 +385,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;
@@ -363,27 +411,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;
}
- hash_delete(&tina_open_tables, (uchar*) share);
+ my_hash_delete(&tina_open_tables, (uchar*) share);
thr_lock_delete(&share->lock);
- pthread_mutex_destroy(&share->mutex);
- my_free((uchar*) share, MYF(0));
+ mysql_mutex_destroy(&share->mutex);
+ my_free(share);
}
- pthread_mutex_unlock(&tina_mutex);
+ mysql_mutex_unlock(&tina_mutex);
DBUG_RETURN(result_code);
}
@@ -449,6 +497,7 @@ ha_tina::ha_tina(handlerton *hton, TABLE_SHARE *table_arg)
buffer.set((char*)byte_buffer, IO_SIZE, &my_charset_bin);
chain= chain_buffer;
file_buff= new Transparent_file();
+ init_alloc_root(&blobroot, BLOB_MEMROOT_ALLOC_SIZE, 0);;
}
@@ -598,7 +647,7 @@ int ha_tina::find_current_row(uchar *buf)
bool read_all;
DBUG_ENTER("ha_tina::find_current_row");
- free_root(&blobroot, MYF(MY_MARK_BLOCKS_FREE));
+ free_root(&blobroot, MYF(0));
/*
We do not read further then local_saved_data_file_length in order
@@ -617,6 +666,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;
@@ -625,19 +701,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))
@@ -659,7 +739,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)
@@ -670,15 +750,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);
+ }
}
}
@@ -704,15 +810,15 @@ int ha_tina::find_current_row(uchar *buf)
Field_blob *blob= *(Field_blob**) field;
uchar *src, *tgt;
uint length, packlength;
-
+
packlength= blob->pack_length_no_ptr();
length= blob->get_length(blob->ptr);
- memcpy_fixed(&src, blob->ptr + packlength, sizeof(char*));
+ memcpy(&src, blob->ptr + packlength, sizeof(char*));
if (src)
{
tgt= (uchar*) alloc_root(&blobroot, length);
bmove(tgt, src, length);
- memcpy_fixed(blob->ptr + packlength, &tgt, sizeof(char*));
+ memcpy(blob->ptr + packlength, &tgt, sizeof(char*));
}
}
}
@@ -784,9 +890,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;
@@ -840,8 +946,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);
@@ -873,7 +980,7 @@ int ha_tina::close(void)
int rc= 0;
DBUG_ENTER("ha_tina::close");
free_root(&blobroot, MYF(0));
- rc= my_close(data_file, MYF(0));
+ rc= mysql_file_close(data_file, MYF(0));
DBUG_RETURN(free_share(share) || rc);
}
@@ -902,20 +1009,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);
@@ -929,10 +1036,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;
@@ -974,8 +1082,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;
@@ -1009,9 +1117,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);
@@ -1038,8 +1146,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);
@@ -1112,9 +1222,14 @@ int ha_tina::rnd_next(uchar *buf)
{
int rc;
DBUG_ENTER("ha_tina::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);
+ {
+ rc= HA_ERR_CRASHED_ON_USAGE;
+ goto end;
+ }
ha_statistic_increment(&SSV::ha_read_rnd_next_count);
@@ -1123,18 +1238,19 @@ int ha_tina::rnd_next(uchar *buf)
/* don't scan an empty file */
if (!local_saved_data_file_length)
{
- found_end_of_file= 1;
- DBUG_RETURN(HA_ERR_END_OF_FILE);
+ rc= HA_ERR_END_OF_FILE;
+ goto end;
}
+
if ((rc= find_current_row(buf)))
- {
- DBUG_PRINT("warning", ("got error %d while reading file", rc));
- found_end_of_file= (rc == HA_ERR_END_OF_FILE);
- DBUG_RETURN(rc);
- }
+ goto end;
stats.records++;
- DBUG_RETURN(0);
+ rc= 0;
+end:
+ found_end_of_file= (rc == HA_ERR_END_OF_FILE);
+ MYSQL_READ_ROW_DONE(rc);
+ DBUG_RETURN(rc);
}
/*
@@ -1161,10 +1277,15 @@ void ha_tina::position(const uchar *record)
int ha_tina::rnd_pos(uchar * buf, uchar *pos)
{
+ int rc;
DBUG_ENTER("ha_tina::rnd_pos");
+ MYSQL_READ_ROW_START(table_share->db.str, table_share->table_name.str,
+ FALSE);
ha_statistic_increment(&SSV::ha_read_rnd_count);
current_position= my_get_ptr(pos,ref_length);
- DBUG_RETURN(find_current_row(buf));
+ rc= find_current_row(buf);
+ MYSQL_READ_ROW_DONE(rc);
+ DBUG_RETURN(rc);
}
/*
@@ -1191,13 +1312,14 @@ 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);
}
+
/*
Set end_pos to the last valid byte of continuous area, closest
to the given "hole", stored in the buffer. "Valid" here means,
@@ -1260,10 +1382,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;
}
@@ -1284,15 +1406,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()
@@ -1305,15 +1427,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
@@ -1340,7 +1465,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);
}
@@ -1409,7 +1534,7 @@ int ha_tina::repair(THD* thd, HA_CHECK_OPT* check_opt)
free_root(&blobroot, MYF(0));
- my_free((char*)buf, MYF(0));
+ my_free(buf);
if (rc == HA_ERR_END_OF_FILE)
{
@@ -1426,10 +1551,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);
@@ -1443,8 +1570,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;
@@ -1458,7 +1585,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)
{
@@ -1467,17 +1594,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() */
@@ -1505,13 +1635,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);
}
@@ -1563,20 +1693,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);
}
@@ -1613,10 +1745,10 @@ int ha_tina::check(THD* thd, HA_CHECK_OPT* check_opt)
count--;
current_position= next_position;
}
-
+
free_root(&blobroot, MYF(0));
- my_free((char*)buf, MYF(0));
+ my_free(buf);
thd_proc_info(thd, old_proc_info);
if ((rc != HA_ERR_END_OF_FILE) || count)
@@ -1658,7 +1790,8 @@ mysql_declare_plugin(csv)
0x0100 /* 1.0 */,
NULL, /* status variables */
NULL, /* system variables */
- NULL /* config options */
+ NULL, /* config options */
+ 0, /* flags */
}
mysql_declare_plugin_end;
maria_declare_plugin(csv)
diff --git a/storage/csv/ha_tina.h b/storage/csv/ha_tina.h
index a124ea77f3c..88af2c9652c 100644
--- a/storage/csv/ha_tina.h
+++ b/storage/csv/ha_tina.h
@@ -1,6 +1,4 @@
-/*
- Copyright (c) 2004-2008 MySQL AB, 2009 Sun Microsystems, Inc.
- Use is subject to license terms.
+/* 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
@@ -13,8 +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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#include <sys/types.h>
#include <sys/stat.h>
@@ -44,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;
@@ -100,9 +97,10 @@ public:
~ha_tina()
{
if (chain_alloced)
- my_free(chain, 0);
+ my_free(chain);
if (file_buff)
delete file_buff;
+ free_root(&blobroot, MYF(0));
}
const char *table_type() const { return "CSV"; }
const char *index_type(uint inx) { return "NONE"; }
@@ -110,7 +108,8 @@ public:
ulonglong table_flags() const
{
return (HA_NO_TRANSACTIONS | HA_REC_NOT_IN_SEQ | HA_NO_AUTO_INCREMENT |
- HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE);
+ HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE |
+ HA_CAN_REPAIR);
}
ulong index_flags(uint idx, uint part, bool all_parts) const
{
diff --git a/storage/csv/plug.in b/storage/csv/plug.in
deleted file mode 100644
index eb4bd4d9883..00000000000
--- a/storage/csv/plug.in
+++ /dev/null
@@ -1,4 +0,0 @@
-MYSQL_STORAGE_ENGINE(csv,, [CSV Storage Engine],
- [Stores tables in text CSV format])
-MYSQL_PLUGIN_STATIC(csv, [libcsv.la])
-MYSQL_PLUGIN_MANDATORY(csv) dnl Used for logging
diff --git a/storage/csv/transparent_file.cc b/storage/csv/transparent_file.cc
index 3a7ebe55df6..a307f9885c0 100644
--- a/storage/csv/transparent_file.cc
+++ b/storage/csv/transparent_file.cc
@@ -1,6 +1,4 @@
-/*
- Copyright (c) 2007 MySQL AB, 2009 Sun Microsystems, Inc.
- Use is subject to license terms.
+/* Copyright (c) 2003, 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
@@ -13,15 +11,16 @@
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 */
#ifdef USE_PRAGMA_IMPLEMENTATION
#pragma implementation // gcc: Class implementation
#endif
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include <mysql/psi/mysql_file.h>
#include "transparent_file.h"
+#include "my_sys.h" // MY_WME, MY_ALLOW_ZERO_PTR, MY_SEEK_SET
Transparent_file::Transparent_file() : lower_bound(0), buff_size(IO_SIZE)
{
@@ -30,7 +29,7 @@ Transparent_file::Transparent_file() : lower_bound(0), buff_size(IO_SIZE)
Transparent_file::~Transparent_file()
{
- my_free((uchar*)buff, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(buff);
}
void Transparent_file::init_buff(File filedes_arg)
@@ -38,9 +37,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()
@@ -66,7 +65,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 */
@@ -88,10 +88,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/csv/transparent_file.h b/storage/csv/transparent_file.h
index 575ae0b6f6b..2536ad16a0f 100644
--- a/storage/csv/transparent_file.h
+++ b/storage/csv/transparent_file.h
@@ -1,5 +1,4 @@
-/*
- Copyright (c) 2007 MySQL AB, 2009 Sun Microsystems, Inc.
+/* Copyright (c) 2003, 2007 MySQL AB, 2009 Sun Microsystems, Inc.
Use is subject to license terms.
This program is free software; you can redistribute it and/or modify
@@ -13,8 +12,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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#include <sys/types.h>
#include <sys/stat.h>