Bug #70303 main.partition sporadically fails when using the embedded server
Submitted: 11 Sep 2013 19:24 Modified: 11 Sep 2013 20:44
Reporter: Davi Arnaut (OCA) Email Updates:
Status: Analyzing Impact on me:
None 
Category:MySQL Server: Partitions Severity:S2 (Serious)
Version:5.5.32 OS:Mac OS X
Assigned to: CPU Architecture:Any
Tags: crash, embedded, libmysqld

[11 Sep 2013 19:24] Davi Arnaut
Description:
The test case main.partition crashes when run with embedded server and
the data directory (MTR's --vardir) contains uppercase letters:

main.partition                           w2 [ fail ]
        Test ended at 2013-09-09 19:04:51

CURRENT_TEST: main.partition
130910  5:04:22 InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!
130910  5:04:22 InnoDB: The InnoDB memory heap is disabled
130910  5:04:22 InnoDB: Mutexes and rw_locks use GCC atomic builtins
130910  5:04:22 InnoDB: Compressed tables use zlib 1.2.5
130910  5:04:22 InnoDB: Initializing buffer pool, size = 8.0M
130910  5:04:22 InnoDB: Completed initialization of buffer pool
130910  5:04:22 InnoDB: highest supported file format is Barracuda.
130910  5:04:23  InnoDB: Waiting for the background threads to start
mysqltest got signal 11
read_command_buf (0x103c34740): SELECT * FROM t1 WHERE c1 = 4
conn->name (0x7f9f034067e0): is an invalid pointer
conn->cur_query (0x7f9f04207d20): is an invalid pointer
Attempting backtrace...
stack_bottom = 0 thread_stack 0x40000
0   mysqltest_embedded                  0x00000001030fd102 my_print_stacktrace + 66�
1   mysqltest_embedded                  0x000000010307aa2b _ZL14dump_backtracev + 267�
2   mysqltest_embedded                  0x000000010307a8de signal_handler + 46�
3   libsystem_c.dylib                   0x00007fff931d094a _sigtramp + 26�
4   ???                                 0x00007f9f0430ca48 0x0 + 140320946833992�
5   mysqltest_embedded                  0x000000010311dafc hp_rb_records_in_range + 220�
6   mysqltest_embedded                  0x000000010311c777 _ZN7ha_heap16records_in_rangeEjP12st_key_rangeS1_ + 103�
7   mysqltest_embedded                  0x000000010333ec20 _ZN12ha_partition16records_in_rangeEjP12st_key_rangeS1_ + 208�
8   mysqltest_embedded                  0x00000001034cef85 _ZL16check_quick_keysP5PARAMjP7SEL_ARGPhjiS3_ji + 2341�
9   mysqltest_embedded                  0x00000001034cd906 _ZL18check_quick_selectP5PARAMjP7SEL_ARGb + 550�
10  mysqltest_embedded                  0x00000001034bfc48 _ZL20get_key_scans_paramsP5PARAMP8SEL_TREEbbd + 568�
11  mysqltest_embedded                  0x00000001034bc794 _ZN10SQL_SELECT17test_quick_selectEP3THD6BitmapILj64EEyyb + 2756�
12  mysqltest_embedded                  0x00000001036015bd _ZL22get_quick_record_countP3THDP10SQL_SELECTP5TABLEPK6BitmapILj64EEy + 237�
13  mysqltest_embedded                  0x00000001035d985b _ZL20make_join_statisticsP4JOINP10TABLE_LISTP4ItemP16st_dynamic_array + 6043�
14  mysqltest_embedded                  0x00000001035d412c _ZN4JOIN8optimizeEv + 2972�
15  mysqltest_embedded                  0x00000001035d0cd6 _Z12mysql_selectP3THDPPP4ItemP10TABLE_LISTjR4ListIS1_ES2_jP8st_orderSB_S2_SB_yP13select_resultP18st_select_lex_unitP13st_select_lex + 1206�
16  mysqltest_embedded                  0x00000001035d0737 _Z13handle_selectP3THDP3LEXP13select_resultm + 519�
17  mysqltest_embedded                  0x000000010359af28 _ZL21execute_sqlcom_selectP3THDP10TABLE_LIST + 1256�
18  mysqltest_embedded                  0x0000000103594262 _Z21mysql_execute_commandP3THD + 1634�
19  mysqltest_embedded                  0x0000000103593240 _Z11mysql_parseP3THDPcjP12Parser_state + 624�
20  mysqltest_embedded                  0x0000000103591055 _Z16dispatch_command19enum_server_commandP3THDPcj + 2037�
21  mysqltest_embedded                  0x0000000103347328 emb_advanced_command + 488�
22  mysqltest_embedded                  0x0000000103362260 mysql_send_query + 160�
23  mysqltest_embedded                  0x00000001030645a4 connection_thread + 292�
24  libsystem_c.dylib                   0x00007fff931e27a2 _pthread_start + 327�
25  libsystem_c.dylib                   0x00007fff931cf1e1 thread_start + 13�

The problem is that the mysql_real_data_home_len variable is not updated
when the data directory is set as an option in the command-line. In the
embedded server initialization, after command-line argument parsing,
mysql_real_data_home_len is assigned to mysql_data_home_len, which is
later used as the (incorrect) length of the data directory string. This
ends up affecting the case sensitivity of table filenames in the table
creation path (e.g. see get_canonical_filename), but not for a regular
table open code path. Later this leads to a crash in the heap storage
engine as it uses case-sensitive comparison when looking up the internal
table share.

How to repeat:
./mtr --vardir=/tmp/UPPERCASE/ --embedded partition

Suggested fix:
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index c97a8c5..55eacdf 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -6963,6 +6963,7 @@ mysqld_get_one_option(int optid,
     break;
   case 'h':
     strmake(mysql_real_data_home,argument, sizeof(mysql_real_data_home)-1);
+    mysql_real_data_home_len= strlen(mysql_real_data_home);
     /* Correct pointer set by my_getopt (for embedded library) */
     mysql_real_data_home_ptr= mysql_real_data_home;
     break;
[11 Sep 2013 20:44] Miguel Solorzano
[17:17:55][pochita:]mysql-5.5 miguel$ cd mysql-test/
[17:41:53][pochita:]mysql-test miguel$ ./mtr --vardir=/tmp/UPPERCASE/ --embedded partition
Logging: ./mtr  --vardir=/tmp/UPPERCASE/ --embedded partition
130911 17:42:01 [Warning] Setting lower_case_table_names=2 because file system for /var/folders/_q/gbljyvnj1g97b03433vcb2hr0000gn/T/nR4JhEuazT/ is case insensitive
130911 17:42:01 [Note] Plugin 'FEDERATED' is disabled.
MySQL Version 5.5.33
Checking supported features...
 - skipping SSL
 - binaries are debug compiled
Collecting tests...
Removing old var directory...
Creating var directory '/tmp/UPPERCASE/'...
Installing system database...
Using server port 49649

==============================================================================

TEST                                      RESULT   TIME (ms) or COMMENT
--------------------------------------------------------------------------

worker[1] Using MTR_BUILD_THREAD 300, with reserved ports 13000..13009
main.partition                           [ fail ]
        Test ended at 2013-09-11 17:42:34

CURRENT_TEST: main.partition
130911 23:42:14 InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!
130911 23:42:14 InnoDB: The InnoDB memory heap is disabled
130911 23:42:14 InnoDB: Mutexes and rw_locks use GCC atomic builtins
130911 23:42:14 InnoDB: Compressed tables use zlib 1.2.5
130911 23:42:14 InnoDB: Initializing buffer pool, size = 8.0M
130911 23:42:14 InnoDB: Completed initialization of buffer pool
130911 23:42:14 InnoDB: highest supported file format is Barracuda.
130911 23:42:14  InnoDB: Waiting for the background threads to start
mysqltest got signal 11
read_command_buf (0x10b02a2d0): SELECT * FROM t1 WHERE c1 = 4
conn->name (0x7fafaad13b00): is an invalid pointer
conn->cur_query (0x7fafaad45a20): is an invalid pointer
Attempting backtrace...
stack_bottom = 0 thread_stack 0x40000
0   mysqltest_embedded                  0x000000010a4998f2 my_print_stacktrace + 66
1   mysqltest_embedded                  0x000000010a413e7b _ZL14dump_backtracev + 267
2   mysqltest_embedded                  0x000000010a413d2e signal_handler + 46
3   libsystem_c.dylib                   0x00007fff8c37a94a _sigtramp + 26
4   ???                                 0x00007fafaac68200 0x0 + 140392461140480
5   mysqltest_embedded                  0x000000010a4cb9bc hp_rb_records_in_range + 220
6   mysqltest_embedded                  0x000000010a4ca637 _ZN7ha_heap16records_in_rangeEjP12st_key_rangeS1_ + 103
7   mysqltest_embedded                  0x000000010a70f1c0 _ZN12ha_partition16records_in_rangeEjP12st_key_rangeS1_ + 208
8   mysqltest_embedded                  0x000000010a8a4f25 _ZL16check_quick_keysP5PARAMjP7SEL_ARGPhjiS3_ji + 2341
9   mysqltest_embedded                  0x000000010a8a38a6 _ZL18check_quick_selectP5PARAMjP7SEL_ARGb + 550
10  mysqltest_embedded                  0x000000010a895be8 _ZL20get_key_scans_paramsP5PARAMP8SEL_TREEbbd + 568
11  mysqltest_embedded                  0x000000010a892734 _ZN10SQL_SELECT17test_quick_selectEP3THD6BitmapILj64EEyyb + 2756
12  mysqltest_embedded                  0x000000010a9deb9d _ZL22get_quick_record_countP3THDP10SQL_SELECTP5TABLEPK6BitmapILj64EEy + 237
13  mysqltest_embedded                  0x000000010a9b695b _ZL20make_join_statisticsP4JOINP10TABLE_LISTP4ItemP16st_dynamic_array + 6043
14  mysqltest_embedded                  0x000000010a9b122c _ZN4JOIN8optimizeEv + 2972
15  mysqltest_embedded                  0x000000010a9addd6 _Z12mysql_selectP3THDPPP4ItemP10TABLE_LISTjR4ListIS1_ES2_jP8st_orderSB_S2_SB_yP13select_resultP18st_select_lex_unitP13st_select_lex + 1206
16  mysqltest_embedded                  0x000000010a9ad837 _Z13handle_selectP3THDP3LEXP13select_resultm + 519
17  mysqltest_embedded                  0x000000010a976008 _ZL21execute_sqlcom_selectP3THDP10TABLE_LIST + 1256
18  mysqltest_embedded                  0x000000010a96f33a _Z21mysql_execute_commandP3THD + 1658
19  mysqltest_embedded                  0x000000010a96e300 _Z11mysql_parseP3THDPcjP12Parser_state + 624
20  mysqltest_embedded                  0x000000010a96c065 _Z16dispatch_command19enum_server_commandP3THDPcj + 2037
21  mysqltest_embedded                  0x000000010a718228 emb_advanced_command + 488
22  mysqltest_embedded                  0x000000010a734260 mysql_send_query + 160
23  mysqltest_embedded                  0x000000010a3fd99a connection_thread + 330
24  libsystem_c.dylib                   0x00007fff8c38c7a2 _pthread_start + 327
25  libsystem_c.dylib                   0x00007fff8c3791e1 thread_start + 13
Writing a core file...

 - saving '/tmp/UPPERCASE//log/main.partition/' to '/tmp/UPPERCASE//log/main.partition/'

Only  1  of 2 completed.
mysql-test-run: *** ERROR: Not all tests completed
[17:42:34][pochita:]mysql-test miguel$