From d47f320c192c72a144ca961d7ae4bb5693be0c62 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 28 Jul 2007 10:25:50 +0200 Subject: [PATCH 1/3] Backported mi_test_all.sh from 5.1. --- myisam/mi_test_all.sh | 256 +++++++++++++++++++++--------------------- 1 file changed, 128 insertions(+), 128 deletions(-) diff --git a/myisam/mi_test_all.sh b/myisam/mi_test_all.sh index c1fb12d7c3b..5989d9cfaf0 100755 --- a/myisam/mi_test_all.sh +++ b/myisam/mi_test_all.sh @@ -6,143 +6,143 @@ valgrind="valgrind --alignment=8 --leak-check=yes" silent="-s" -if test -f mi_test1$MACH ; then suffix=$MACH else suffix=""; fi -mi_test1$suffix $silent -myisamchk$suffix -se test1 -mi_test1$suffix $silent -N -S -myisamchk$suffix -se test1 -mi_test1$suffix $silent -P --checksum -myisamchk$suffix -se test1 -mi_test1$suffix $silent -P -N -S -myisamchk$suffix -se test1 -mi_test1$suffix $silent -B -N -R2 -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -a -k 480 --unique -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -a -N -S -R1 -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -p -S -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -p -S -N --unique -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -p -S -N --key_length=127 --checksum -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -p -S -N --key_length=128 -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -p -S --key_length=480 -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -a -B -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -a -B --key_length=64 --unique -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -a -B -k 480 --checksum -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -a -B -k 480 -N --unique --checksum -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -a -m -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -a -m -P --unique --checksum -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -a -m -P --key_length=480 --key_cache -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -m -p -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -w -S --unique -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -a -w --key_length=64 --checksum -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -a -w -N --key_length=480 -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -a -w -S --key_length=480 --checksum -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -a -b -N -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -a -b --key_length=480 -myisamchk$suffix -sm test1 -mi_test1$suffix $silent -p -B --key_length=480 -myisamchk$suffix -sm test1 +if test -f mi_test1$MACH ; then suffix=$MACH ; else suffix=""; fi +./mi_test1$suffix $silent +./myisamchk$suffix -se test1 +./mi_test1$suffix $silent -N -S +./myisamchk$suffix -se test1 +./mi_test1$suffix $silent -P --checksum +./myisamchk$suffix -se test1 +./mi_test1$suffix $silent -P -N -S +./myisamchk$suffix -se test1 +./mi_test1$suffix $silent -B -N -R2 +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -a -k 480 --unique +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -a -N -S -R1 +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -p -S +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -p -S -N --unique +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -p -S -N --key_length=127 --checksum +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -p -S -N --key_length=128 +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -p -S --key_length=480 +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -a -B +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -a -B --key_length=64 --unique +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -a -B -k 480 --checksum +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -a -B -k 480 -N --unique --checksum +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -a -m +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -a -m -P --unique --checksum +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -a -m -P --key_length=480 --key_cache +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -m -p +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -w -S --unique +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -a -w --key_length=64 --checksum +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -a -w -N --key_length=480 +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -a -w -S --key_length=480 --checksum +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -a -b -N +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -a -b --key_length=480 +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent -p -B --key_length=480 +./myisamchk$suffix -sm test1 -mi_test1$suffix $silent --checksum -myisamchk$suffix -se test1 -myisamchk$suffix -rs test1 -myisamchk$suffix -se test1 -myisamchk$suffix -rqs test1 -myisamchk$suffix -se test1 -myisamchk$suffix -rs --correct-checksum test1 -myisamchk$suffix -se test1 -myisamchk$suffix -rqs --correct-checksum test1 -myisamchk$suffix -se test1 -myisamchk$suffix -ros --correct-checksum test1 -myisamchk$suffix -se test1 -myisamchk$suffix -rqos --correct-checksum test1 -myisamchk$suffix -se test1 +./mi_test1$suffix $silent --checksum +./myisamchk$suffix -se test1 +./myisamchk$suffix -rs test1 +./myisamchk$suffix -se test1 +./myisamchk$suffix -rqs test1 +./myisamchk$suffix -se test1 +./myisamchk$suffix -rs --correct-checksum test1 +./myisamchk$suffix -se test1 +./myisamchk$suffix -rqs --correct-checksum test1 +./myisamchk$suffix -se test1 +./myisamchk$suffix -ros --correct-checksum test1 +./myisamchk$suffix -se test1 +./myisamchk$suffix -rqos --correct-checksum test1 +./myisamchk$suffix -se test1 # check of myisampack / myisamchk -myisampack$suffix --force -s test1 +./myisampack$suffix --force -s test1 # Ignore error for index file -myisamchk$suffix -es test1 2>&1 >& /dev/null -myisamchk$suffix -rqs test1 -myisamchk$suffix -es test1 -myisamchk$suffix -rs test1 -myisamchk$suffix -es test1 -myisamchk$suffix -rus test1 -myisamchk$suffix -es test1 +./myisamchk$suffix -es test1 2>&1 >& /dev/null +./myisamchk$suffix -rqs test1 +./myisamchk$suffix -es test1 +./myisamchk$suffix -rs test1 +./myisamchk$suffix -es test1 +./myisamchk$suffix -rus test1 +./myisamchk$suffix -es test1 -mi_test1$suffix $silent --checksum -S -myisamchk$suffix -se test1 -myisamchk$suffix -ros test1 -myisamchk$suffix -rqs test1 -myisamchk$suffix -se test1 +./mi_test1$suffix $silent --checksum -S +./myisamchk$suffix -se test1 +./myisamchk$suffix -ros test1 +./myisamchk$suffix -rqs test1 +./myisamchk$suffix -se test1 -myisampack$suffix --force -s test1 -myisamchk$suffix -rqs test1 -myisamchk$suffix -es test1 -myisamchk$suffix -rus test1 -myisamchk$suffix -es test1 +./myisampack$suffix --force -s test1 +./myisamchk$suffix -rqs test1 +./myisamchk$suffix -es test1 +./myisamchk$suffix -rus test1 +./myisamchk$suffix -es test1 -mi_test1$suffix $silent --checksum --unique -myisamchk$suffix -se test1 -mi_test1$suffix $silent --unique -S -myisamchk$suffix -se test1 +./mi_test1$suffix $silent --checksum --unique +./myisamchk$suffix -se test1 +./mi_test1$suffix $silent --unique -S +./myisamchk$suffix -se test1 -mi_test1$suffix $silent --key_multiple -N -S -myisamchk$suffix -sm test1 -mi_test1$suffix $silent --key_multiple -a -p --key_length=480 -myisamchk$suffix -sm test1 -mi_test1$suffix $silent --key_multiple -a -B --key_length=480 -myisamchk$suffix -sm test1 -mi_test1$suffix $silent --key_multiple -P -S -myisamchk$suffix -sm test1 +./mi_test1$suffix $silent --key_multiple -N -S +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent --key_multiple -a -p --key_length=480 +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent --key_multiple -a -B --key_length=480 +./myisamchk$suffix -sm test1 +./mi_test1$suffix $silent --key_multiple -P -S +./myisamchk$suffix -sm test1 -mi_test2$suffix $silent -L -K -W -P -myisamchk$suffix -sm test2 -mi_test2$suffix $silent -L -K -W -P -A -myisamchk$suffix -sm test2 -mi_test2$suffix $silent -L -K -W -P -S -R1 -m500 +./mi_test2$suffix $silent -L -K -W -P +./myisamchk$suffix -sm test2 +./mi_test2$suffix $silent -L -K -W -P -A +./myisamchk$suffix -sm test2 +./mi_test2$suffix $silent -L -K -W -P -S -R1 -m500 echo "mi_test2$suffix $silent -L -K -R1 -m2000 ; Should give error 135" -myisamchk$suffix -sm test2 -mi_test2$suffix $silent -L -K -R1 -m2000 -myisamchk$suffix -sm test2 -mi_test2$suffix $silent -L -K -P -S -R3 -m50 -b1000000 -myisamchk$suffix -sm test2 -mi_test2$suffix $silent -L -B -myisamchk$suffix -sm test2 -mi_test2$suffix $silent -D -B -c -myisamchk$suffix -sm test2 -mi_test2$suffix $silent -m10000 -e8192 -K -myisamchk$suffix -sm test2 -mi_test2$suffix $silent -m10000 -e16384 -E16384 -K -L -myisamchk$suffix -sm test2 +./myisamchk$suffix -sm test2 +./mi_test2$suffix $silent -L -K -R1 -m2000 +./myisamchk$suffix -sm test2 +./mi_test2$suffix $silent -L -K -P -S -R3 -m50 -b1000000 +./myisamchk$suffix -sm test2 +./mi_test2$suffix $silent -L -B +./myisamchk$suffix -sm test2 +./mi_test2$suffix $silent -D -B -c +./myisamchk$suffix -sm test2 +./mi_test2$suffix $silent -m10000 -e8192 -K +./myisamchk$suffix -sm test2 +./mi_test2$suffix $silent -m10000 -e16384 -E16384 -K -L +./myisamchk$suffix -sm test2 -mi_test2$suffix $silent -L -K -W -P -m50 -l -myisamlog$suffix -mi_test2$suffix $silent -L -K -W -P -m50 -l -b100 -myisamlog$suffix -time mi_test2$suffix $silent -time mi_test2$suffix $silent -K -B -time mi_test2$suffix $silent -L -B -time mi_test2$suffix $silent -L -K -B -time mi_test2$suffix $silent -L -K -W -B -time mi_test2$suffix $silent -L -K -W -S -B -time mi_test2$suffix $silent -D -K -W -S -B +./mi_test2$suffix $silent -L -K -W -P -m50 -l +./myisamlog$suffix +./mi_test2$suffix $silent -L -K -W -P -m50 -l -b100 +./myisamlog$suffix +time ./mi_test2$suffix $silent +time ./mi_test2$suffix $silent -K -B +time ./mi_test2$suffix $silent -L -B +time ./mi_test2$suffix $silent -L -K -B +time ./mi_test2$suffix $silent -L -K -W -B +time ./mi_test2$suffix $silent -L -K -W -S -B +time ./mi_test2$suffix $silent -D -K -W -S -B From 8018d6ac94a9859358600c646ec55bc2a244c4a5 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 31 Jul 2007 19:40:36 +0500 Subject: [PATCH 2/3] BUG#29152 - INSERT DELAYED does not use concurrent_insert on slave INSERT DELAYED on a replication slave was converted to regular INSERT, whereas it should try concurrent INSERT first. With this patch we try to convert delayed insert to concurrent insert on a replication slave. If it is impossible for some reason, we fall back to regular insert. No test case for this fix. I do not see anything indicating this is regression - we behave this way since Nov 2000. sql/sql_insert.cc: If we're executing INSERT DELAYED on a replication slave, we're upgrading lock type to TL_WRITE as we need to ensure serial execution of queries on the slave. OTOH if we're executing regular INSERT on a replication slave, we're trying TL_WRITE_CONCURRENT_INSERT first, and if we may not use it, we fall back to TL_WRITE. Fixed INSERT DELAYED on a replication slave to behave the same way as regular INSERT, that is to try TL_WRITE_CONCURRENT_INSERT first. --- sql/sql_insert.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 19c9360b0ed..d2d03a1a119 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -446,7 +446,6 @@ void upgrade_lock_type(THD *thd, thr_lock_type *lock_type, client connection and the delayed thread. */ if (specialflag & (SPECIAL_NO_NEW_FUNC | SPECIAL_SAFE_MODE) || - thd->slave_thread || thd->variables.max_insert_delayed_threads == 0 || thd->prelocked_mode || thd->lex->uses_stored_routines()) @@ -454,6 +453,14 @@ void upgrade_lock_type(THD *thd, thr_lock_type *lock_type, *lock_type= TL_WRITE; return; } + if (thd->slave_thread) + { + /* Try concurrent insert */ + *lock_type= (duplic == DUP_UPDATE || duplic == DUP_REPLACE) ? + TL_WRITE : TL_WRITE_CONCURRENT_INSERT; + return; + } + bool log_on= (thd->options & OPTION_BIN_LOG || ! (thd->security_ctx->master_access & SUPER_ACL)); if (log_on && mysql_bin_log.is_open() && is_multi_insert) From 4158e75ded1e6ac0adcca94b83dd4db62d09f3eb Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 1 Aug 2007 11:54:24 +0200 Subject: [PATCH 3/3] Bug#29838 - myisam corruption using concurrent select ... and update When using concurrent insert with parallel index reads, it could happen that reading sessions found keys that pointed to records yet to be written to the data file. The result was a report of a corrupted table. But it was false alert. When inserting a record in a table with indexes, the keys are inserted into the indexes before the record is written to the data file. When the insert happens concurrently to selects, an index read can find a key that references the record that is not yet written to the data file. To avoid any access to such record, the select saves the current end of file position when it starts. Since concurrent inserts are always appended at end of the data file, the select can easily ignore any concurrently inserted record. The problem was that the ignore was only done for non-exact key searches (partial key or using >, >=, < or <=). The fix is to ignore concurrently inserted records also for exact key searches. No test case. Concurrent inserts cannot be tested with the test suite. Test cases are attached to the bug report. myisam/mi_rkey.c: Bug#29838 - myisam corruption using concurrent select ... and update Fixed mi_rkey() to always ignore records beyond saved eof. --- myisam/mi_rkey.c | 81 ++++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 30 deletions(-) diff --git a/myisam/mi_rkey.c b/myisam/mi_rkey.c index e34799da6ed..ea60b9a6f43 100644 --- a/myisam/mi_rkey.c +++ b/myisam/mi_rkey.c @@ -95,42 +95,63 @@ int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, uint key_len, myisam_read_vec[search_flag], info->s->state.key_root[inx])) { /* - If we searching for a partial key (or using >, >=, < or <=) and - the data is outside of the data file, we need to continue searching - for the first key inside the data file + Found a key, but it might not be usable. We cannot use rows that + are inserted by other threads after we got our table lock + ("concurrent inserts"). The record may not even be present yet. + Keys are inserted into the index(es) before the record is + inserted into the data file. When we got our table lock, we + saved the current data_file_length. Concurrent inserts always go + to the end of the file. So we can test if the found key + references a new record. */ - if (info->lastpos >= info->state->data_file_length && - (search_flag != HA_READ_KEY_EXACT || - last_used_keyseg != keyinfo->seg + keyinfo->keysegs)) + if (info->lastpos >= info->state->data_file_length) { - do + /* The key references a concurrently inserted record. */ + if (search_flag == HA_READ_KEY_EXACT && + last_used_keyseg == keyinfo->seg + keyinfo->keysegs) + { + /* Simply ignore the key if it matches exactly. (Bug #29838) */ + my_errno= HA_ERR_KEY_NOT_FOUND; + info->lastpos= HA_OFFSET_ERROR; + } + else { - uint not_used[2]; /* - Skip rows that are inserted by other threads since we got a lock - Note that this can only happen if we are not searching after an - full length exact key, because the keys are sorted - according to position + If searching for a partial key (or using >, >=, < or <=) and + the data is outside of the data file, we need to continue + searching for the first key inside the data file. */ - if (_mi_search_next(info, keyinfo, info->lastkey, - info->lastkey_length, - myisam_readnext_vec[search_flag], - info->s->state.key_root[inx])) - break; - /* - Check that the found key does still match the search. - _mi_search_next() delivers the next key regardless of its - value. - */ - if (search_flag == HA_READ_KEY_EXACT && - ha_key_cmp(keyinfo->seg, key_buff, info->lastkey, use_key_length, - SEARCH_FIND, not_used)) + do { - my_errno= HA_ERR_KEY_NOT_FOUND; - info->lastpos= HA_OFFSET_ERROR; - break; - } - } while (info->lastpos >= info->state->data_file_length); + uint not_used[2]; + /* + Skip rows that are inserted by other threads since we got + a lock. Note that this can only happen if we are not + searching after a full length exact key, because the keys + are sorted according to position. + */ + if (_mi_search_next(info, keyinfo, info->lastkey, + info->lastkey_length, + myisam_readnext_vec[search_flag], + info->s->state.key_root[inx])) + break; /* purecov: inspected */ + /* + Check that the found key does still match the search. + _mi_search_next() delivers the next key regardless of its + value. + */ + if (search_flag == HA_READ_KEY_EXACT && + ha_key_cmp(keyinfo->seg, key_buff, info->lastkey, + use_key_length, SEARCH_FIND, not_used)) + { + /* purecov: begin inspected */ + my_errno= HA_ERR_KEY_NOT_FOUND; + info->lastpos= HA_OFFSET_ERROR; + break; + /* purecov: end */ + } + } while (info->lastpos >= info->state->data_file_length); + } } } }