#At file:///home/narayanan/Work/mysql_checkouts/shared_repository_directory/mysql-6.0-bugteam-43572-4/ based on revid:aelkin@stripped
3391 V Narayanan 2009-06-24
Bug#43572 Handle failures from hash_init
The bug needs to be tested with error injection. This
patch adds error injection tests, for, testing failure
of hash_init, caused by memory allocation failure in
the dynamic array used in the hash.
@ mysql-test/r/hash_error_injection.result
Bug#43572 Handle failures from hash_init
Result file for error injection testing in hash_init
@ mysql-test/t/hash_error_injection.test
Bug#43572 Handle failures from hash_init
sets the debug flag to simulate a dynamic array allocation
failure while initializing the hash. After setting the flag
create hash indexes on memory tables and test the queries to
ensure that, failure in the dynamic array allocation in hash_init
does not causes these queries, that exercise the hash_init
function to fail.
@ mysys/hash.c
Bug#43572 Handle failures from hash_init
Contains the changes needed to add error injection
in the hash_init function. Test a debug flag to determine
if the dynamic array needs to be reset, thus, simulating
an memory allocation failure.
added:
mysql-test/r/hash_error_injection.result
mysql-test/t/hash_error_injection.test
modified:
mysys/hash.c
=== added file 'mysql-test/r/hash_error_injection.result'
--- a/mysql-test/r/hash_error_injection.result 1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/hash_error_injection.result 2009-06-24 08:57:25 +0000
@@ -0,0 +1,75 @@
+#
+# Hash Error Injection Testing
+#
+DROP TABLE IF EXISTS t1;
+DROP TABLE IF EXISTS t2;
+#
+# Set the debug flag to enable error injection in the hash_init code
+#
+SET debug='+d,hash_init_allocation_failure_err_inj';
+#
+# Create tables necessary for testing
+#
+CREATE TABLE t1 (c1 INT, c2 VARCHAR(30), c3 VARCHAR(30), c4 VARCHAR(15)) ENGINE = MEMORY;
+CREATE TABLE t2 (c1 INT, c5 VARCHAR(30)) ENGINE = MEMORY;
+#
+# Create HASH indexes on the tables
+#
+CREATE INDEX c1_index USING HASH ON t1 (c1);
+CREATE INDEX c2_index USING HASH ON t1 (c2);
+CREATE INDEX c4_index USING HASH ON t1 (c4);
+#
+# Insert values into t1 and t2
+#
+INSERT INTO t1 VALUES(1, 'n1', 'a1', 'phone1');
+INSERT INTO t1 VALUES(2, 'n2', 'a2', 'phone2');
+INSERT INTO t1 VALUES(3, 'n3', 'a3', 'phone3');
+INSERT INTO t1 VALUES(4, 'n4', 'a4', 'phone4');
+INSERT INTO t1 VALUES(5, 'n5', 'a5', 'phone5');
+INSERT INTO t1 VALUES(6, 'n6', 'a6', 'phone6');
+INSERT INTO t2 VALUES(1, 'b1');
+INSERT INTO t2 VALUES(2, 'b2');
+INSERT INTO t2 VALUES(3, 'b3');
+INSERT INTO t2 VALUES(4, 'b4');
+INSERT INTO t2 VALUES(5, 'b5');
+INSERT INTO t2 VALUES(6, 'b6');
+#
+# Select values to determine that the error injection has not
+# impacted creation of tables and indexes.
+#
+SELECT * FROM t1 WHERE c1=3;
+c1 c2 c3 c4
+3 n3 a3 phone3
+SELECT * FROM t1 WHERE c1>3;
+c1 c2 c3 c4
+4 n4 a4 phone4
+5 n5 a5 phone5
+6 n6 a6 phone6
+SELECT t2.c5 FROM t1,t2 WHERE t1.c1=t2.c1 AND t1.c1 > 3;
+c5
+b4
+b5
+b6
+SELECT * FROM t2;
+c1 c5
+1 b1
+2 b2
+3 b3
+4 b4
+5 b5
+6 b6
+SELECT * FROM t2 WHERE c1>4;
+c1 c5
+5 b5
+6 b6
+#
+# Reset the debug flag to stop error injection
+#
+#
+# Perform error injection
+#
+DROP INDEX c1_index ON t1;
+DROP INDEX c2_index ON t1;
+DROP INDEX c4_index ON t1;
+DROP TABLE t1;
+DROP TABLE t2;
=== added file 'mysql-test/t/hash_error_injection.test'
--- a/mysql-test/t/hash_error_injection.test 1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/hash_error_injection.test 2009-06-24 08:57:25 +0000
@@ -0,0 +1,76 @@
+--echo #
+--echo # Hash Error Injection Testing
+--echo #
+
+--source include/have_debug.inc
+let $debug= `SELECT @@debug`;
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+DROP TABLE IF EXISTS t2;
+--enable_warnings
+
+--echo #
+--echo # Set the debug flag to enable error injection in the hash_init code
+--echo #
+SET debug='+d,hash_init_allocation_failure_err_inj';
+
+--echo #
+--echo # Create tables necessary for testing
+--echo #
+
+CREATE TABLE t1 (c1 INT, c2 VARCHAR(30), c3 VARCHAR(30), c4 VARCHAR(15)) ENGINE = MEMORY;
+CREATE TABLE t2 (c1 INT, c5 VARCHAR(30)) ENGINE = MEMORY;
+
+--echo #
+--echo # Create HASH indexes on the tables
+--echo #
+CREATE INDEX c1_index USING HASH ON t1 (c1);
+CREATE INDEX c2_index USING HASH ON t1 (c2);
+CREATE INDEX c4_index USING HASH ON t1 (c4);
+
+--echo #
+--echo # Insert values into t1 and t2
+--echo #
+INSERT INTO t1 VALUES(1, 'n1', 'a1', 'phone1');
+INSERT INTO t1 VALUES(2, 'n2', 'a2', 'phone2');
+INSERT INTO t1 VALUES(3, 'n3', 'a3', 'phone3');
+INSERT INTO t1 VALUES(4, 'n4', 'a4', 'phone4');
+INSERT INTO t1 VALUES(5, 'n5', 'a5', 'phone5');
+INSERT INTO t1 VALUES(6, 'n6', 'a6', 'phone6');
+
+INSERT INTO t2 VALUES(1, 'b1');
+INSERT INTO t2 VALUES(2, 'b2');
+INSERT INTO t2 VALUES(3, 'b3');
+INSERT INTO t2 VALUES(4, 'b4');
+INSERT INTO t2 VALUES(5, 'b5');
+INSERT INTO t2 VALUES(6, 'b6');
+
+--echo #
+--echo # Select values to determine that the error injection has not
+--echo # impacted creation of tables and indexes.
+--echo #
+SELECT * FROM t1 WHERE c1=3;
+SELECT * FROM t1 WHERE c1>3;
+
+SELECT t2.c5 FROM t1,t2 WHERE t1.c1=t2.c1 AND t1.c1 > 3;
+
+SELECT * FROM t2;
+SELECT * FROM t2 WHERE c1>4;
+
+--echo #
+--echo # Reset the debug flag to stop error injection
+--echo #
+--disable_query_log
+eval SET debug= '$debug';
+--enable_query_log
+
+--echo #
+--echo # Perform error injection
+--echo #
+DROP INDEX c1_index ON t1;
+DROP INDEX c2_index ON t1;
+DROP INDEX c4_index ON t1;
+
+DROP TABLE t1;
+DROP TABLE t2;
=== modified file 'mysys/hash.c'
--- a/mysys/hash.c 2009-06-22 12:38:37 +0000
+++ b/mysys/hash.c 2009-06-24 08:57:25 +0000
@@ -77,9 +77,16 @@ _my_hash_init(HASH *hash, uint growth_si
my_hash_get_key get_key,
void (*free_element)(void*), uint flags CALLER_INFO_PROTO)
{
+ /* Set to TRUE if error injection is enabled */
+ my_bool hash_init_error_injection= FALSE;
+
DBUG_ENTER("my_hash_init");
DBUG_PRINT("enter",("hash: %p size: %u", hash, (uint) size));
+ /* Error injection for coverage testing. */
+ DBUG_EXECUTE_IF("hash_init_allocation_failure_err_inj",
+ hash_init_error_injection= TRUE;);
+
hash->records=0;
hash->key_offset=key_offset;
hash->key_length=key_length;
@@ -88,6 +95,19 @@ _my_hash_init(HASH *hash, uint growth_si
hash->free=free_element;
hash->flags=flags;
hash->charset=charset;
+
+ /*
+ If error injection is enabled simulate failure to allocate
+ the dynamic array
+ */
+ if (hash_init_error_injection)
+ {
+ my_init_dynamic_array_ci(&hash->array,
+ sizeof(HASH_LINK), size, growth_size);
+ hash->array.buffer= 0;
+ hash->array.max_element= 0;
+ DBUG_RETURN(FALSE);
+ }
DBUG_RETURN(my_init_dynamic_array_ci(&hash->array,
sizeof(HASH_LINK), size, growth_size));
}
Attachment: [text/bzr-bundle] bzr/v.narayanan@sun.com-20090624085725-rzkkym431g607m3v.bundle