]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 480001: MySQL 5.1.31 throws an error when you try to SET SESSION max_allowed_pack...
authormkanat%bugzilla.org <>
Mon, 2 Mar 2009 01:23:09 +0000 (01:23 +0000)
committermkanat%bugzilla.org <>
Mon, 2 Mar 2009 01:23:09 +0000 (01:23 +0000)
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=LpSolit

Bugzilla/Config/Attachment.pm
Bugzilla/Config/Common.pm
Bugzilla/DB/Mysql.pm
Bugzilla/Install/DB.pm
docs/en/xml/installation.xml
template/en/default/setup/strings.txt.pl

index 15ba2672aef26185d1b098079d9b4ce7729042ac..999c4797e7a57bb3c8888bcc1810704e5f66a7e3 100644 (file)
@@ -74,7 +74,7 @@ sub get_param_list {
    name => 'maxattachmentsize',
    type => 't',
    default => '1000',
-   checker => \&check_numeric
+   checker => \&check_maxattachmentsize
   },
 
   # The maximum size (in bytes) for patches and non-patch attachments.
index e6f0398e311014d0f75d40e12ba5adddee871fe3..5b2cabb93514c91dddef9e5e4defea9db14f94ad 100644 (file)
@@ -50,7 +50,8 @@ use base qw(Exporter);
        check_opsys check_shadowdb check_urlbase check_webdotbase
        check_netmask check_user_verify_class check_image_converter
        check_mail_delivery_method check_notification check_timezone check_utf8
-       check_bug_status check_smtp_auth
+       check_bug_status check_smtp_auth 
+       check_maxattachmentsize
 );
 
 # Checking functions for the various values
@@ -320,6 +321,24 @@ sub check_mail_delivery_method {
     return "";
 }
 
+sub check_maxattachmentsize {
+    my $check = check_numeric(@_);
+    return $check if $check;
+    my $size = shift;
+    my $dbh = Bugzilla->dbh;
+    if ($dbh->isa('Bugzilla::DB::Mysql')) {
+        my (undef, $max_packet) = $dbh->selectrow_array(
+            q{SHOW VARIABLES LIKE 'max\_allowed\_packet'});
+        my $byte_size = $size * 1024;
+        if ($max_packet < $byte_size) {
+            return "You asked for a maxattachmentsize of $byte_size bytes,"
+                   . " but the max_allowed_packet setting in MySQL currently"
+                   . " only allows packets up to $max_packet bytes";
+        }
+    }
+    return "";
+}
+
 sub check_notification {
     my $option = shift;
     my @current_version =
index f8198621cf22355dd722bb53b96e59bf39262306..92d1df1a01a1f6adaf7249f5b5176b1f412a593b 100644 (file)
@@ -44,6 +44,7 @@ package Bugzilla::DB::Mysql;
 use strict;
 
 use Bugzilla::Constants;
+use Bugzilla::Install::Util qw(install_string);
 use Bugzilla::Util;
 use Bugzilla::Error;
 use Bugzilla::DB::Schema::Mysql;
@@ -97,20 +98,9 @@ sub new {
         }
     }
 
-    # The "comments" field of the bugs_fulltext table could easily exceed
-    # MySQL's default max_allowed_packet. Also, MySQL should never have
-    # a max_allowed_packet smaller than our max_attachment_size. However,
-    # if we've already set a max_allowed_packet in MySQL bigger than all
-    # of those, we should keep it.
-    my (undef, $current_max_allowed) = $self->selectrow_array(
-        q{SHOW VARIABLES LIKE 'max\_allowed\_packet'});
-    my $min_max_allowed_packet = MAX_COMMENTS * MAX_COMMENT_LENGTH;
-    my $max_allowed_packet = max($min_max_allowed_packet,
-                                 $current_max_allowed,
-                                 # This parameter is not yet defined when the DB
-                                 # is being built for the very first time.
-                                 Bugzilla->params->{'maxattachmentsize'} || 0);
-    $self->do("SET SESSION max_allowed_packet = $max_allowed_packet");
+    # Allow large GROUP_CONCATs (largely for inserting comments 
+    # into bugs_fulltext).
+    $self->do('SET SESSION group_concat_max_len = 128000000');
 
     return $self;
 }
@@ -244,6 +234,24 @@ sub _bz_get_initial_schema {
 sub bz_setup_database {
     my ($self) = @_;
 
+    # The "comments" field of the bugs_fulltext table could easily exceed
+    # MySQL's default max_allowed_packet. Also, MySQL should never have
+    # a max_allowed_packet smaller than our max_attachment_size. So, we
+    # warn the user here if max_allowed_packet is too small.
+    my $min_max_allowed = MAX_COMMENTS * MAX_COMMENT_LENGTH;
+    my (undef, $current_max_allowed) = $self->selectrow_array(
+        q{SHOW VARIABLES LIKE 'max\_allowed\_packet'});
+    # This parameter is not yet defined when the DB is being built for
+    # the very first time. The code below still works properly, however,
+    # because the default maxattachmentsize is smaller than $min_max_allowed.
+    my $max_attachment = (Bugzilla->params->{'maxattachmentsize'} || 0) * 1024;
+    my $needed_max_allowed = max($min_max_allowed, $max_attachment);
+    if ($current_max_allowed < $needed_max_allowed) {
+        warn install_string('max_allowed_packet',
+                            { current => $current_max_allowed,
+                              needed  => $needed_max_allowed }) . "\n";
+    }
+
     # Make sure the installation has InnoDB turned on, or we're going to be
     # doing silly things like making foreign keys on MyISAM tables, which is
     # hard to fix later. We do this up here because none of the code below
index 270b0e8041a35fb4bdcc2489dbafe105fe14d497..1bda135f25598a1428e85df39647440526b86413 100644 (file)
@@ -3009,11 +3009,6 @@ sub _populate_bugs_fulltext {
         if (UNIVERSAL::can($dbh, 'sql_group_concat')) {
             print "Populating bugs_fulltext...";
             print " (this can take a long time.)\n";
-            # XXX This hack should probably be moved elsewhere.
-            if ($dbh->isa('Bugzilla::DB::Mysql')) {
-                $dbh->do('SET SESSION group_concat_max_len = 128000000');
-                $dbh->do('SET SESSION max_allowed_packet =   128000000');
-            }
             $dbh->do(
                 q{INSERT INTO bugs_fulltext (bug_id, short_desc, comments, 
                                              comments_noprivate)
index 54ec6c1c67d01e8f6723179ad86590cd38aac3d9..9a3b08865fb06bb1dd6d0aedbe5564f54ca17c91 100644 (file)
@@ -1,5 +1,5 @@
 <!-- <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"> -->
-<!-- $Id: installation.xml,v 1.157.2.6 2009/01/08 23:44:22 lpsolit%gmail.com Exp $ -->
+<!-- $Id: installation.xml,v 1.157.2.7 2009/03/02 01:23:16 mkanat%bugzilla.org Exp $ -->
 <chapter id="installing-bugzilla">
   <title>Installing Bugzilla</title>
 
             improving your installation's security.
           </para>
         </caution>
+        <section id="mysql-max-allowed-packet">
+          <title>Allow large attachments and many comments</title>
+          
+          <para>By default, MySQL will only allow you to insert things
+          into the database that are smaller than 64KB. Attachments
+          may be larger than this. Also, Bugzilla combines all comments
+          on a single bug into one field for full-text searching, and the
+          combination of all comments on a single bug are very likely to
+          be larger than 64KB.</para>
+          
+          <para>To change MySQL's default, you need to edit your MySQL
+          configuration file, which is usually <filename>/etc/my.cnf</filename>
+          on Linux. We recommend that you allow at least 4MB packets by
+          adding the "max_allowed_packet" parameter to your MySQL 
+          configuration in the "[mysqld]" section, like this:</para>
+
+          <screen>[mysqld]
+# Allow packets up to 4MB
+max_allowed_packet=4M
+          </screen>
+        </section>
         
         <section>
           <title>Allow small words in full-text indexes</title>
index 51e1ac0597b1249957305e3ffd942ee92ecdc6be..f1b5008925d51591006dbccf5e3ff4eb23e69fd1 100644 (file)
@@ -52,6 +52,12 @@ then the value of the ##column## column that needs to be fixed:
 
 EOT
     install_module => 'Installing ##module## version ##version##...',
+    max_allowed_packet => <<EOT,
+WARNING: You need to set the max_allowed_packet parameter in your MySQL
+configuration to at least ##needed##. Currently it is set to ##current##.
+You can set this parameter in the [mysqld] section of your MySQL
+configuration file.
+EOT
     module_found => "found v##ver##",
     module_not_found => "not found",
     module_ok => 'ok',