Merge lp:~laurynas-biveinis/percona-server/bug1179978-5.5 into lp:percona-server/5.5

Proposed by Laurynas Biveinis
Status: Merged
Approved by: Alexey Kopytov
Approved revision: no longer in the source branch.
Merged at revision: 516
Proposed branch: lp:~laurynas-biveinis/percona-server/bug1179978-5.5
Merge into: lp:percona-server/5.5
Diff against target: 188 lines (+45/-16)
5 files modified
Percona-Server/include/my_base.h (+1/-0)
Percona-Server/sql/sql_select.cc (+1/-1)
Percona-Server/storage/myisam/mi_close.c (+6/-3)
Percona-Server/storage/myisam/mi_create.c (+8/-4)
Percona-Server/storage/myisam/mi_open.c (+29/-8)
To merge this branch: bzr merge lp:~laurynas-biveinis/percona-server/bug1179978-5.5
Reviewer Review Type Date Requested Status
Alexey Kopytov (community) Approve
Review via email: mp+164198@code.launchpad.net

Description of the change

Fix bug 1179978 / MySQL bug 65077 (internal temporary tables are
contended on THR_LOCK_myisam) by backporting revision 4195.3.1 from
lp:mysql-server/5.6.

5.6$ bzr log -r 4195.3.1

------------------------------------------------------------
revno: 4195.3.1
committer: Sergey Vojtovich <email address hidden>
branch nick: mysql-5.6-bug14000697
timestamp: Wed 2012-08-29 16:49:37 +0400
message:
  BUG#14000697 - 65077: INTERNAL TEMPORARY TABLES ARE CONTENDED ON
                 THR_LOCK_MYISAM

  MyISAM registers all open tables on myisam_open_list. This list is
  protected by global mutex (THR_LOCK_myisam). Under concurrent
  load it causes excessive THR_LOCK_myisam mutex contention.

  Fixed by not registering internal temporary tables on
  myisam_open_list, similarly to MEMORY engine.

http://jenkins.percona.com/job/percona-server-5.5-param/737/

To post a comment you must log in.
Revision history for this message
Alexey Kopytov (akopytov) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Percona-Server/include/my_base.h'
--- Percona-Server/include/my_base.h 2012-03-01 08:27:43 +0000
+++ Percona-Server/include/my_base.h 2013-05-16 14:29:32 +0000
@@ -319,6 +319,7 @@
319#define HA_CREATE_PAGE_CHECKSUM 32319#define HA_CREATE_PAGE_CHECKSUM 32
320#define HA_CREATE_DELAY_KEY_WRITE 64320#define HA_CREATE_DELAY_KEY_WRITE 64
321#define HA_CREATE_RELIES_ON_SQL_LAYER 128321#define HA_CREATE_RELIES_ON_SQL_LAYER 128
322#define HA_CREATE_INTERNAL_TABLE 256
322323
323/*324/*
324 The following flags (OR-ed) are passed to handler::info() method.325 The following flags (OR-ed) are passed to handler::info() method.
325326
=== modified file 'Percona-Server/sql/sql_select.cc'
--- Percona-Server/sql/sql_select.cc 2013-03-22 03:29:56 +0000
+++ Percona-Server/sql/sql_select.cc 2013-05-16 14:29:32 +0000
@@ -11222,7 +11222,7 @@
11222 param->start_recinfo,11222 param->start_recinfo,
11223 share->uniques, &uniquedef,11223 share->uniques, &uniquedef,
11224 &create_info,11224 &create_info,
11225 HA_CREATE_TMP_TABLE)))11225 HA_CREATE_TMP_TABLE | HA_CREATE_INTERNAL_TABLE)))
11226 {11226 {
11227 table->file->print_error(error,MYF(0)); /* purecov: inspected */11227 table->file->print_error(error,MYF(0)); /* purecov: inspected */
11228 table->db_stat=0;11228 table->db_stat=0;
1122911229
=== modified file 'Percona-Server/storage/myisam/mi_close.c'
--- Percona-Server/storage/myisam/mi_close.c 2012-02-16 09:48:16 +0000
+++ Percona-Server/storage/myisam/mi_close.c 2013-05-16 14:29:32 +0000
@@ -31,7 +31,8 @@
31 (long) info, (uint) share->reopen,31 (long) info, (uint) share->reopen,
32 (uint) share->tot_locks));32 (uint) share->tot_locks));
3333
34 mysql_mutex_lock(&THR_LOCK_myisam);34 if (info->open_list.data)
35 mysql_mutex_lock(&THR_LOCK_myisam);
35 if (info->lock_type == F_EXTRA_LCK)36 if (info->lock_type == F_EXTRA_LCK)
36 info->lock_type=F_UNLCK; /* HA_EXTRA_NO_USER_CHANGE */37 info->lock_type=F_UNLCK; /* HA_EXTRA_NO_USER_CHANGE */
3738
@@ -54,7 +55,8 @@
54 info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);55 info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
55 }56 }
56 flag= !--share->reopen;57 flag= !--share->reopen;
57 myisam_open_list=list_delete(myisam_open_list,&info->open_list);58 if (info->open_list.data)
59 myisam_open_list= list_delete(myisam_open_list, &info->open_list);
58 mysql_mutex_unlock(&share->intern_lock);60 mysql_mutex_unlock(&share->intern_lock);
5961
60 my_free(mi_get_rec_buff_ptr(info, info->rec_buff));62 my_free(mi_get_rec_buff_ptr(info, info->rec_buff));
@@ -108,7 +110,8 @@
108 }110 }
109 my_free(info->s);111 my_free(info->s);
110 }112 }
111 mysql_mutex_unlock(&THR_LOCK_myisam);113 if (info->open_list.data)
114 mysql_mutex_unlock(&THR_LOCK_myisam);
112 if (info->ftparser_param)115 if (info->ftparser_param)
113 {116 {
114 my_free(info->ftparser_param);117 my_free(info->ftparser_param);
115118
=== modified file 'Percona-Server/storage/myisam/mi_create.c'
--- Percona-Server/storage/myisam/mi_create.c 2011-07-03 23:48:19 +0000
+++ Percona-Server/storage/myisam/mi_create.c 2013-05-16 14:29:32 +0000
@@ -43,6 +43,7 @@
43 base_pos,long_varchar_count,varchar_length,43 base_pos,long_varchar_count,varchar_length,
44 max_key_block_length,unique_key_parts,fulltext_keys,offset;44 max_key_block_length,unique_key_parts,fulltext_keys,offset;
45 uint aligned_key_start, block_length;45 uint aligned_key_start, block_length;
46 uint internal_table= flags & HA_CREATE_INTERNAL_TABLE;
46 ulong reclength, real_reclength,min_pack_length;47 ulong reclength, real_reclength,min_pack_length;
47 char filename[FN_REFLEN],linkname[FN_REFLEN], *linkname_ptr;48 char filename[FN_REFLEN],linkname[FN_REFLEN], *linkname_ptr;
48 ulong pack_reclength;49 ulong pack_reclength;
@@ -563,7 +564,8 @@
563 if (! (flags & HA_DONT_TOUCH_DATA))564 if (! (flags & HA_DONT_TOUCH_DATA))
564 share.state.create_time= (long) time((time_t*) 0);565 share.state.create_time= (long) time((time_t*) 0);
565566
566 mysql_mutex_lock(&THR_LOCK_myisam);567 if (!internal_table)
568 mysql_mutex_lock(&THR_LOCK_myisam);
567569
568 /*570 /*
569 NOTE: For test_if_reopen() we need a real path name. Hence we need571 NOTE: For test_if_reopen() we need a real path name. Hence we need
@@ -620,7 +622,7 @@
620 NOTE: The filename is compared against unique_file_name of every622 NOTE: The filename is compared against unique_file_name of every
621 open table. Hence we need a real path here.623 open table. Hence we need a real path here.
622 */624 */
623 if (test_if_reopen(filename))625 if (!internal_table && test_if_reopen(filename))
624 {626 {
625 my_printf_error(0, "MyISAM table '%s' is in use "627 my_printf_error(0, "MyISAM table '%s' is in use "
626 "(most likely by a MERGE table). Try FLUSH TABLES.",628 "(most likely by a MERGE table). Try FLUSH TABLES.",
@@ -809,14 +811,16 @@
809 goto err;811 goto err;
810 }812 }
811 errpos=0;813 errpos=0;
812 mysql_mutex_unlock(&THR_LOCK_myisam);814 if (!internal_table)
815 mysql_mutex_unlock(&THR_LOCK_myisam);
813 if (mysql_file_close(file, MYF(0)))816 if (mysql_file_close(file, MYF(0)))
814 goto err_no_lock;817 goto err_no_lock;
815 my_free(rec_per_key_part);818 my_free(rec_per_key_part);
816 DBUG_RETURN(0);819 DBUG_RETURN(0);
817820
818err:821err:
819 mysql_mutex_unlock(&THR_LOCK_myisam);822 if (!internal_table)
823 mysql_mutex_unlock(&THR_LOCK_myisam);
820824
821err_no_lock:825err_no_lock:
822 save_errno=my_errno;826 save_errno=my_errno;
823827
=== modified file 'Percona-Server/storage/myisam/mi_open.c'
--- Percona-Server/storage/myisam/mi_open.c 2012-11-14 11:32:36 +0000
+++ Percona-Server/storage/myisam/mi_open.c 2013-05-16 14:29:32 +0000
@@ -13,7 +13,18 @@
13 along with this program; if not, write to the Free Software13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */14 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
1515
16/* open a isam-database */16/*
17 open a isam-database
18
19 Internal temporary tables
20 -------------------------
21 Since only single instance of internal temporary table is required by
22 optimizer, such tables are not registered on myisam_open_list. In effect
23 it means (a) THR_LOCK_myisam is not held while such table is being created,
24 opened or closed; (b) no iteration through myisam_open_list while opening a
25 table. This optimization gives nice scalability benefit in concurrent
26 environment. MEMORY internal temporary tables are optimized similarly.
27*/
1728
18#include "fulltext.h"29#include "fulltext.h"
19#include "sp_defs.h"30#include "sp_defs.h"
@@ -70,10 +81,11 @@
70 int lock_error,kfile,open_mode,save_errno,have_rtree=0, realpath_err;81 int lock_error,kfile,open_mode,save_errno,have_rtree=0, realpath_err;
71 uint i,j,len,errpos,head_length,base_pos,offset,info_length,keys,82 uint i,j,len,errpos,head_length,base_pos,offset,info_length,keys,
72 key_parts,unique_key_parts,fulltext_keys,uniques;83 key_parts,unique_key_parts,fulltext_keys,uniques;
84 uint internal_table= open_flags & HA_OPEN_INTERNAL_TABLE;
73 char name_buff[FN_REFLEN], org_name[FN_REFLEN], index_name[FN_REFLEN],85 char name_buff[FN_REFLEN], org_name[FN_REFLEN], index_name[FN_REFLEN],
74 data_name[FN_REFLEN];86 data_name[FN_REFLEN];
75 uchar *disk_cache, *disk_pos, *end_pos;87 uchar *disk_cache, *disk_pos, *end_pos;
76 MI_INFO info,*m_info,*old_info;88 MI_INFO info, *m_info, *old_info= NULL;
77 MYISAM_SHARE share_buff,*share;89 MYISAM_SHARE share_buff,*share;
78 ulong rec_per_key_part[HA_MAX_POSSIBLE_KEY*MI_MAX_KEY_SEG];90 ulong rec_per_key_part[HA_MAX_POSSIBLE_KEY*MI_MAX_KEY_SEG];
79 my_off_t key_root[HA_MAX_POSSIBLE_KEY],key_del[MI_MAX_KEY_BLOCK_SIZE];91 my_off_t key_root[HA_MAX_POSSIBLE_KEY],key_del[MI_MAX_KEY_BLOCK_SIZE];
@@ -96,8 +108,13 @@
96 DBUG_RETURN (NULL);108 DBUG_RETURN (NULL);
97 }109 }
98110
99 mysql_mutex_lock(&THR_LOCK_myisam);111 if (!internal_table)
100 if (!(old_info=test_if_reopen(name_buff)))112 {
113 mysql_mutex_lock(&THR_LOCK_myisam);
114 old_info= test_if_reopen(name_buff);
115 }
116
117 if (!old_info)
101 {118 {
102 share= &share_buff;119 share= &share_buff;
103 bzero((uchar*) &share_buff,sizeof(share_buff));120 bzero((uchar*) &share_buff,sizeof(share_buff));
@@ -629,10 +646,13 @@
629646
630 *m_info=info;647 *m_info=info;
631 thr_lock_data_init(&share->lock,&m_info->lock,(void*) m_info);648 thr_lock_data_init(&share->lock,&m_info->lock,(void*) m_info);
632 m_info->open_list.data=(void*) m_info;
633 myisam_open_list=list_add(myisam_open_list,&m_info->open_list);
634649
635 mysql_mutex_unlock(&THR_LOCK_myisam);650 if (!internal_table)
651 {
652 m_info->open_list.data= (void*) m_info;
653 myisam_open_list= list_add(myisam_open_list, &m_info->open_list);
654 mysql_mutex_unlock(&THR_LOCK_myisam);
655 }
636656
637 bzero(info.buff, share->base.max_key_block_length * 2);657 bzero(info.buff, share->base.max_key_block_length * 2);
638658
@@ -675,7 +695,8 @@
675 default:695 default:
676 break;696 break;
677 }697 }
678 mysql_mutex_unlock(&THR_LOCK_myisam);698 if (!internal_table)
699 mysql_mutex_unlock(&THR_LOCK_myisam);
679 my_errno=save_errno;700 my_errno=save_errno;
680 DBUG_RETURN (NULL);701 DBUG_RETURN (NULL);
681} /* mi_open */702} /* mi_open */

Subscribers

People subscribed via source and target branches