Below is the list of changes that have just been committed into a local
5.1 repository of cps. When cps does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet
1.1910 05/10/07 18:13:46 petr@stripped +4 -0
This patch enables concurrent insert functionality for
CSV engine. It was done while probing locking scenarios for
WL #1019 SELECT FROM logs. Recommit with post-review fixes.
sql/examples/ha_tina.h
1.5 05/10/07 18:13:26 petr@stripped +14 -0
Add concurrent insert functionality for ha_tina:
necessary methods and members added to the class
sql/examples/ha_tina.cc
1.20 05/10/07 18:13:26 petr@stripped +70 -5
Add concurrent insert functionality for ha_tina:
Following MyiSAM we store the size of the file for readers
and do not read further then this position to enable
concurrent inserts, which add new rows after the saved position.
mysql-test/t/csv.test
1.3 05/10/07 18:13:26 petr@stripped +38 -0
add test for concurrent insert
mysql-test/r/csv.result
1.2 05/10/07 18:13:25 petr@stripped +17 -0
update result file
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: petr
# Host: owlet.
# Root: /home/cps/mysql/trees/mysql-5.1
--- 1.1/mysql-test/r/csv.result 2004-08-13 07:54:29 +04:00
+++ 1.2/mysql-test/r/csv.result 2005-10-07 18:13:25 +04:00
@@ -4929,3 +4929,20 @@
Note 1051 Unknown table 't2'
Note 1051 Unknown table 't3'
Note 1051 Unknown table 't4'
+CREATE TABLE test_concurrent_insert ( val integer ) ENGINE = CSV;
+LOCK TABLES test_concurrent_insert READ LOCAL;
+INSERT INTO test_concurrent_insert VALUES (1);
+SELECT * FROM test_concurrent_insert;
+val
+1
+SELECT * FROM test_concurrent_insert;
+val
+UNLOCK TABLES;
+LOCK TABLES test_concurrent_insert WRITE;
+INSERT INTO test_concurrent_insert VALUES (2);
+SELECT * FROM test_concurrent_insert;
+val
+1
+2
+UNLOCK TABLES;
+DROP TABLE test_concurrent_insert;
--- 1.2/mysql-test/t/csv.test 2005-07-28 04:21:40 +04:00
+++ 1.3/mysql-test/t/csv.test 2005-10-07 18:13:26 +04:00
@@ -1315,3 +1315,41 @@
drop table if exists t1,t2,t3,t4;
# End of 4.1 tests
+
+#
+# Test CONCURRENT INSERT (5.1)
+#
+
+CREATE TABLE test_concurrent_insert ( val integer ) ENGINE = CSV;
+
+connect (con1,localhost,root,,);
+connect (con2,localhost,root,,);
+
+connection con1;
+# obtain TL_READ lock on the table
+LOCK TABLES test_concurrent_insert READ LOCAL;
+
+connection con2;
+# should pass despite of the lock
+INSERT INTO test_concurrent_insert VALUES (1);
+SELECT * FROM test_concurrent_insert;
+
+connection con1;
+# first connection should not notice the changes
+SELECT * FROM test_concurrent_insert;
+
+UNLOCK TABLES;
+
+# Now check that we see our own changes
+
+LOCK TABLES test_concurrent_insert WRITE;
+INSERT INTO test_concurrent_insert VALUES (2);
+SELECT * FROM test_concurrent_insert;
+UNLOCK TABLES;
+
+# cleanup
+DROP TABLE test_concurrent_insert;
+disconnect con2;
+disconnect con1;
+
+
--- 1.19/sql/examples/ha_tina.cc 2005-09-29 01:00:38 +04:00
+++ 1.20/sql/examples/ha_tina.cc 2005-10-07 18:13:26 +04:00
@@ -201,6 +201,9 @@
share->mapped_file= NULL; // We don't know the state as we just allocated it
if (get_mmap(share, 0) > 0)
goto error3;
+
+ /* init file lenght value used by readers */
+ share->saved_data_file_length= share->file_stat.st_size;
}
share->use_count++;
pthread_mutex_unlock(&tina_mutex);
@@ -264,8 +267,8 @@
These definitions are found in hanler.h
These are not probably completely right.
*/
- current_position(0), next_position(0), chain_alloced(0),
- chain_size(DEFAULT_CHAIN_LENGTH)
+ current_position(0), next_position(0), local_saved_data_file_length(0),
+ chain_alloced(0), chain_size(DEFAULT_CHAIN_LENGTH)
{
/* Set our original buffers from pre-allocated memory */
buffer.set(byte_buffer, IO_SIZE, system_charset_info);
@@ -383,9 +386,12 @@
byte *end_ptr;
DBUG_ENTER("ha_tina::find_current_row");
- /* EOF should be counted as new line */
+ /*
+ We do not read furter then local_saved_data_file_length in order
+ not to confict with undergoing concurrent insert.
+ */
if ((end_ptr= find_eoln(share->mapped_file, current_position,
- share->file_stat.st_size)) == 0)
+ local_saved_data_file_length)) == 0)
DBUG_RETURN(HA_ERR_END_OF_FILE);
for (Field **field=table->field ; *field ; field++)
@@ -443,6 +449,47 @@
return ha_tina_exts;
}
+/*
+ Three functions below are needed to enable concurrent insert functionality
+ for CSV engine. For more details see mysys/thr_lock.c
+*/
+
+void tina_get_status(void* param, int concurrent_insert)
+{
+ ha_tina *tina= (ha_tina*) param;
+ tina->get_status();
+}
+
+void tina_update_status(void* param)
+{
+ ha_tina *tina= (ha_tina*) param;
+ tina->update_status();
+}
+
+/* this should exist and and return 0 for concurrent insert to work */
+my_bool tina_check_status(void* param)
+{
+ return 0;
+}
+
+/* save the state of the table. Called during the lock phase */
+void ha_tina::get_status()
+{
+ local_saved_data_file_length= share->saved_data_file_length;
+}
+
+
+/*
+ Correct the state of the table. Called by unlock routines
+ before the write lock is released.
+*/
+
+void ha_tina::update_status()
+{
+ /* correct local_saved_data_file_length for writers */
+ share->saved_data_file_length= share->file_stat.st_size;
+}
+
/*
Open a database file. Keep in mind that tables are caches, so
@@ -455,9 +502,19 @@
if (!(share= get_share(name, table)))
DBUG_RETURN(1);
- thr_lock_data_init(&share->lock,&lock,NULL);
+
+ /*
+ Init locking. Pass handler object to the locking routines,
+ so that they could save/update local_saved_data_file_length value
+ during locking. This is needed to enable concurrent inserts.
+ */
+ thr_lock_data_init(&share->lock, &lock, (void*) this);
ref_length=sizeof(off_t);
+ share->lock.get_status= tina_get_status;
+ share->lock.update_status= tina_update_status;
+ share->lock.check_status= tina_check_status;
+
DBUG_RETURN(0);
}
@@ -501,6 +558,10 @@
*/
if (get_mmap(share, 0) > 0)
DBUG_RETURN(-1);
+
+ /* update local copy of the max position to see our own changes */
+ local_saved_data_file_length= share->file_stat.st_size;
+
DBUG_RETURN(0);
}
@@ -531,6 +592,10 @@
if (my_write(share->data_file, 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= share->file_stat.st_size;
+
DBUG_RETURN(0);
}
--- 1.4/sql/examples/ha_tina.h 2005-09-29 01:00:39 +04:00
+++ 1.5/sql/examples/ha_tina.h 2005-10-07 18:13:26 +04:00
@@ -26,6 +26,12 @@
uint table_name_length,use_count;
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
+ share initialization.
+ */
+ off_t saved_data_file_length;
pthread_mutex_t mutex;
THR_LOCK lock;
} TINA_SHARE;
@@ -41,6 +47,7 @@
TINA_SHARE *share; /* Shared lock info */
off_t current_position; /* Current position in the file during a file scan */
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];
String buffer;
/*
@@ -127,6 +134,13 @@
THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
enum thr_lock_type lock_type);
+
+ /*
+ These functions used to get/update status of the handler.
+ Needed to enable concurrent inserts.
+ */
+ void get_status();
+ void update_status();
/* The following methods were added just for TINA */
int encode_quote(byte *buf);
| Thread |
|---|
| • bk commit into 5.1 tree (petr:1.1910) | Petr Chardin | 7 Oct |