Commit e8d9458f authored by petr@mysql.com's avatar petr@mysql.com

WL#3244 "CSV engine: convert mmap to read/write calls"

parent 593daae1
......@@ -4944,10 +4944,10 @@ val
UPDATE bug13894 SET val=6 WHERE val=10;
SELECT * FROM bug13894;
val
5
11
6
6
5
11
DROP TABLE bug13894;
DROP TABLE IF EXISTS bug14672;
CREATE TABLE bug14672 (c1 integer) engine = CSV;
......
This diff is collapsed.
......@@ -19,6 +19,7 @@
#include <my_dir.h>
#define DEFAULT_CHAIN_LENGTH 512
#define DEFAULT_FILE_WINDOW_SIZE 4096
/*
Version for file format.
1 - Initial Version. That is, the version when the metafile was introduced.
......@@ -29,15 +30,12 @@
typedef struct st_tina_share {
char *table_name;
char data_file_name[FN_REFLEN];
byte *mapped_file; /* mapped region of file */
uint table_name_length, use_count;
/*
Below flag is needed to make log tables work with concurrent insert.
For more details see comment to ha_tina::update_status.
*/
my_bool is_log_table;
MY_STAT file_stat; /* Stat information for the data file */
File data_file; /* Current open data file */
/*
Here we save the length of the file for readers. This is updated by
inserts, updates and deletes. The var is initialized along with the
......@@ -46,7 +44,10 @@ typedef struct st_tina_share {
off_t saved_data_file_length;
pthread_mutex_t mutex;
THR_LOCK lock;
bool update_file_opened;
bool tina_write_opened;
File meta_file; /* Meta file we use */
File tina_write_filedes; /* File handler for readers */
bool crashed; /* Meta file is crashed */
ha_rows rows_recorded; /* Number of rows in tables */
} TINA_SHARE;
......@@ -56,6 +57,54 @@ struct tina_set {
off_t end;
};
class Transparent_file
{
File filedes;
byte *buff; /* in-memory window to the file or mmaped area */
/* current window sizes */
off_t lower_bound;
off_t upper_bound;
uint buff_size;
public:
Transparent_file(File filedes_arg) : lower_bound(0),
buff_size(DEFAULT_FILE_WINDOW_SIZE)
{
buff= (byte *) my_malloc(buff_size*sizeof(byte), MYF(MY_WME));
/* read the beginning of the file */
init_buff(filedes_arg);
}
~Transparent_file()
{ my_free(buff, MYF(MY_ALLOW_ZERO_PTR)); }
void 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)));
if (filedes && buff)
upper_bound= my_read(filedes, buff, buff_size, MYF(0));
}
byte *ptr()
{ return buff; }
off_t start()
{ return lower_bound; }
off_t end()
{ return upper_bound; }
/* get a char from the given position in the file */
char get_value (off_t offset);
/* shift a buffer windows to see the next part of the file */
off_t read_next();
};
class ha_tina: public handler
{
THR_LOCK_DATA lock; /* MySQL lock */
......@@ -64,6 +113,9 @@ class ha_tina: public handler
off_t next_position; /* Next position in the file scan */
off_t local_saved_data_file_length; /* save position for reads */
byte byte_buffer[IO_SIZE];
Transparent_file *file_buff;
File data_file; /* File handler for readers */
File update_temp_file;
String buffer;
/*
The chain contains "holes" in the file, occured because of
......@@ -77,12 +129,19 @@ class ha_tina: public handler
uint32 chain_size;
bool records_is_known;
private:
bool get_write_pos(off_t *end_pos, tina_set *closest_hole);
int open_update_temp_file_if_needed();
int init_tina_writer();
public:
ha_tina(TABLE_SHARE *table_arg);
~ha_tina()
~ha_tina()
{
if (chain_alloced)
my_free((gptr)chain,0);
my_free((gptr)chain, 0);
if (file_buff)
delete file_buff;
}
const char *table_type() const { return "CSV"; }
const char *index_type(uint inx) { return "NONE"; }
......
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