Commit 05f32a3d authored by holyfoot@mysql.com's avatar holyfoot@mysql.com

Merge bk@192.168.21.1:mysql-5.1-new

into mysql.com:/home/hf/work/mysql-5.1.18518
parents ff3e5f40 8ab2897e
......@@ -457,8 +457,8 @@ static struct my_option my_long_options[] =
(gptr*) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0,
0},
{"preserve-schema", OPT_MYSQL_PRESERVE_SCHEMA,
"Preserve the schema from the mysqlslap run, this happens unless \
--auto-generate-sql or --create are used.",
"Preserve the schema from the mysqlslap run, this happens unless "
"--auto-generate-sql or --create are used.",
(gptr*) &opt_preserve, (gptr*) &opt_preserve, 0, GET_BOOL,
NO_ARG, TRUE, 0, 0, 0, 0, 0},
{"protocol", OPT_MYSQL_PROTOCOL,
......
......@@ -459,12 +459,11 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name,
share->table_name_length= length;
share->table_name= tmp_name;
share->crashed= FALSE;
share->archive_write_open= FALSE;
fn_format(share->data_file_name, table_name, "",
ARZ,MY_REPLACE_EXT|MY_UNPACK_FILENAME);
fn_format(meta_file_name, table_name, "", ARM,
MY_REPLACE_EXT|MY_UNPACK_FILENAME);
DBUG_PRINT("info", ("archive opening (1) up write at %s",
share->data_file_name));
strmov(share->table_name,table_name);
/*
We will use this lock for rows.
......@@ -476,38 +475,20 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name,
share->data_file_name));
/*
After we read, we set the file to dirty. When we close, we will do the
opposite. If the meta file will not open we assume it is crashed and
leave it up to the user to fix.
We read the meta file, but do not mark it dirty unless we actually do
a write.
*/
if (read_meta_file(share->meta_file, &share->rows_recorded,
&share->auto_increment_value,
&share->forced_flushes,
share->real_path))
share->crashed= TRUE;
else
(void)write_meta_file(share->meta_file, share->rows_recorded,
share->auto_increment_value,
share->forced_flushes,
share->real_path,
TRUE);
/*
Since we now possibly no real_path, we will use it instead if it exists.
*/
if (*share->real_path)
fn_format(share->data_file_name, share->real_path, "", ARZ,
MY_REPLACE_EXT|MY_UNPACK_FILENAME);
/*
It is expensive to open and close the data files and since you can't have
a gzip file that can be both read and written we keep a writer open
that is shared amoung all open tables.
*/
if (!(azopen(&(share->archive_write), share->data_file_name,
O_WRONLY|O_APPEND|O_BINARY)))
{
DBUG_PRINT("info", ("Could not open archive write file"));
share->crashed= TRUE;
}
VOID(my_hash_insert(&archive_open_tables, (byte*) share));
thr_lock_init(&share->lock);
}
......@@ -554,6 +535,7 @@ int ha_archive::free_share(ARCHIVE_SHARE *share)
share->forced_flushes,
share->real_path,
share->crashed ? TRUE :FALSE);
if (share->archive_write_open)
if (azclose(&(share->archive_write)))
rc= 1;
if (my_close(share->meta_file, MYF(0)))
......@@ -565,6 +547,32 @@ int ha_archive::free_share(ARCHIVE_SHARE *share)
DBUG_RETURN(rc);
}
int ha_archive::init_archive_writer()
{
DBUG_ENTER("ha_archive::init_archive_writer");
(void)write_meta_file(share->meta_file, share->rows_recorded,
share->auto_increment_value,
share->forced_flushes,
share->real_path,
TRUE);
/*
It is expensive to open and close the data files and since you can't have
a gzip file that can be both read and written we keep a writer open
that is shared amoung all open tables.
*/
if (!(azopen(&(share->archive_write), share->data_file_name,
O_WRONLY|O_APPEND|O_BINARY)))
{
DBUG_PRINT("info", ("Could not open archive write file"));
share->crashed= TRUE;
DBUG_RETURN(1);
}
share->archive_write_open= TRUE;
DBUG_RETURN(0);
}
/*
We just implement one additional file extension.
......@@ -910,6 +918,9 @@ int ha_archive::write_row(byte *buf)
Notice that the global auto_increment has been increased.
In case of a failed row write, we will never try to reuse the value.
*/
if (!share->archive_write_open)
if (init_archive_writer())
DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
share->rows_recorded++;
rc= real_write_row(buf, &(share->archive_write));
......@@ -1221,6 +1232,10 @@ int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt)
azio_stream writer;
char writer_filename[FN_REFLEN];
/* Open up the writer if we haven't yet */
if (!share->archive_write_open)
init_archive_writer();
/* Flush any waiting data */
azflush(&(share->archive_write), Z_SYNC_FLUSH);
share->forced_flushes++;
......
......@@ -35,6 +35,7 @@ typedef struct st_archive_share {
THR_LOCK lock;
File meta_file; /* Meta file we use */
azio_stream archive_write; /* Archive file we are working with */
bool archive_write_open;
bool dirty; /* Flag for if a flush should occur */
bool crashed; /* Meta file is crashed */
ha_rows rows_recorded; /* Number of rows in tables */
......@@ -112,6 +113,7 @@ class ha_archive: public handler
bool dirty);
ARCHIVE_SHARE *get_share(const char *table_name, TABLE *table, int *rc);
int free_share(ARCHIVE_SHARE *share);
int init_archive_writer();
bool auto_repair() const { return 1; } // For the moment we just do this
int read_data_header(azio_stream *file_to_read);
int write_data_header(azio_stream *file_to_write);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment