Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
MySQL auto-reconnect revisited
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
dubek  
View profile  
 More options Jan 22, 6:16 am
From: dubek <dov.mu...@gmail.com>
Date: Thu, 22 Jan 2009 03:16:43 -0800 (PST)
Local: Thurs, Jan 22 2009 6:16 am
Subject: MySQL auto-reconnect revisited
Hi,

In commit 9051da90e4da2ab0db16530a7f7568e24a0ccaed the following line
was added to MysqlAdapter#connect:

    @connection.reconnect = true if @connection.respond_to?
(:reconnect=)

There are couple of problems with this:

1. It doesn't stick. A look at the sources of the mysql gem tells that
the
   real_connect method sets reconnect to 0 (false). Since real_connect
is called
   after the line given about, it'll reset the value of reconnect to
0. A simple
   test for that will be:

    def test_connection_has_mysql_reconnect_property
      @connection = ActiveRecord::Base.connection
      mysql_connection = @connection.instance_variable_get
(:@connection)
      assert mysql_connection.reconnect
    end

   This test fails. And it's easy to fix, we'll just move the line
above to
   somewhere after the real_connect() call. (Unless, I'm missing
something,
   of course.)

2. Even after I fixed #1, I couldn't make reconnect work in my tests.
I did a simple
   test without AR (directly with mysql gem), and it works OK (you can
see that
   reconnection happened because the thread_id of the connection is
modified).
   However, with AR I keep getting the "MySQL server has gone away"
errors. Here's
   my test (should be in connection_test_mysql.rb):

    def test_select_auto_reconnects_after_connection_lost
      mysql_connection = @connection.instance_variable_get
(:@connection)
      assert mysql_connection.reconnect

      original_thread_id = mysql_connection.thread_id
      assert_equal ["42"], @connection.select_values('SELECT 42')

      @connection.update('set @@wait_timeout=1')
      sleep 2

      # this shouldn't raise Mysql::Error if reconnect is true
      assert_equal ["42"], @connection.select_values('SELECT 42')
      new_thread_id = mysql_connection.thread_id
      assert_not_equal original_thread_id, new_thread_id
    end

3. Do we want the reconnection at all? According to Mysql docs
   ( http://dev.mysql.com/doc/refman/5.0/en/auto-reconnect.html )
   the auto-reconnect does not save any session variables. This
includes these
   two settings that AR sets after connection is established:

     SET NAMES 'utf8'
     SET SQL_AUTO_IS_NULL=0

   Which means, if the server was gone, auto-reconnect takes place on
the next
   query, but the variables are back to the server default (use
   SHOW VARIABLES LIKE 'character_set_client' to view the variable
value before
   and after the reconnection). On my machine it's back to 'latin1'.

See previous (related) discussion at:
http://groups.google.com/group/rubyonrails-core/browse_thread/thread/...

Best,
dubek.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dubek  
View profile  
 More options Jan 22, 6:18 am
From: dubek <dov.mu...@gmail.com>
Date: Thu, 22 Jan 2009 03:18:54 -0800 (PST)
Local: Thurs, Jan 22 2009 6:18 am
Subject: Re: MySQL auto-reconnect revisited
I should also say that this ticket is related:

http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1293

(and sorry about the lousy line-wraps)

dubek.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lourens Naude  
View profile  
 More options Jan 22, 6:49 am
From: Lourens Naude <lour...@methodmissing.com>
Date: Thu, 22 Jan 2009 11:49:55 +0000
Local: Thurs, Jan 22 2009 6:49 am
Subject: Re: [Rails-core] MySQL auto-reconnect revisited

Hey,

Just a quick note that we experienced similar difficulties with  
reconnection and mysqlplus.

Found sending a mysql_ping down the wire to assert that the thread  
identifier changed works best.
libmysqld also reuses previously opened file descriptors for  
reconnection attempts.

http://github.com/oldmoe/mysqlplus/commit/8e6f300f9db75f07c03049efd00...

http://github.com/oldmoe/mysqlplus/blob/8e6f300f9db75f07c03049efd00a6...

Reconnect behavior is especially important for an async interface as  
simply setting mysql.reconnect = true essentially
invalidates an existing operation when sent down the wire, but pending  
a result.

http://github.com/oldmoe/mysqlplus/commit/85141abf097a375520ca5cf17df...

Noticed sporadic  "MySQL server has gone away" in our environment with  
2.3 / Edge ( stock mysql gem ) and am aware
of others in the same boat.

Essentially any of the following error states should warrant a  
reconnect :

* CR_SERVER_LOST

* CR_SERVER_GONE_ERROR

* ER_SERVER_SHUTDOWN

The latter being important for MySQL server restarts as well.

Thoughts ?

- Lourens

On 2009/01/22, at 11:16, dubek wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mislav Marohnić  
View profile  
 More options Jan 22, 9:50 am
From: Mislav Marohnić <mislav.maroh...@gmail.com>
Date: Thu, 22 Jan 2009 15:50:53 +0100
Local: Thurs, Jan 22 2009 9:50 am
Subject: Re: [Rails-core] MySQL auto-reconnect revisited

Hooray for investigating this. We've been getting "MySQL has gone away" for
the past month (although it magically stopped last week).

On Thu, Jan 22, 2009 at 12:16, dubek <dov.mu...@gmail.com> wrote:

>    def test_connection_has_mysql_reconnect_property
>      @connection = ActiveRecord::Base.connection
>      mysql_connection = @connection.instance_variable_get
> (:@connection)
>      assert mysql_connection.reconnect
>    end

>   This test fails.

How can the test fail if the `reconnect` property is 0? Zero is true in
Ruby.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dubek  
View profile  
 More options Jan 22, 9:56 am
From: dubek <dov.mu...@gmail.com>
Date: Thu, 22 Jan 2009 06:56:07 -0800 (PST)
Local: Thurs, Jan 22 2009 9:56 am
Subject: Re: MySQL auto-reconnect revisited
On Jan 22, 4:50 pm, Mislav Marohnić <mislav.maroh...@gmail.com> wrote:

> How can the test fail if the `reconnect` property is 0? Zero is true in
> Ruby.

The reconnect accessor method of the mysql gem returns 'true' or
'false'. In the C implementation of real_connect it sets the reconnect
flag to 0 in each connect.

dubek.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Koziarski  
View profile  
 More options Jan 25, 10:36 pm
From: Michael Koziarski <mich...@koziarski.com>
Date: Mon, 26 Jan 2009 16:36:47 +1300
Local: Sun, Jan 25 2009 10:36 pm
Subject: Re: [Rails-core] MySQL auto-reconnect revisited

Send us a patch with test for this one,  nice find!

I think we should probably push reconnect into an option in
database.yml so users can make their own decisions.  In my case the
character_set values are set in my.cnf so those queries don't actually
change anything for me.

A patch to fix this up and test that the value is actually set would
be greatly appreciated.  Failing that, a lighthouse ticket assigned to
jeremy would be a good start.

Thanks again for spending the time to look into this.

--
Cheers

Koz


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chad Woolley  
View profile  
 More options Jan 25, 11:09 pm
From: Chad Woolley <thewoolley...@gmail.com>
Date: Sun, 25 Jan 2009 21:09:33 -0700
Local: Sun, Jan 25 2009 11:09 pm
Subject: Re: [Rails-core] Re: MySQL auto-reconnect revisited
On Sun, Jan 25, 2009 at 8:36 PM, Michael Koziarski

<mich...@koziarski.com> wrote:
> Send us a patch with test for this one,  nice find!

Yeah, great catch.  This totally bit me on some daemons in the past
when the mysql connection died after several days...

-- Chad


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dov Murik  
View profile  
 More options Jan 26, 3:44 am
From: Dov Murik <dov.mu...@gmail.com>
Date: Mon, 26 Jan 2009 10:44:09 +0200
Local: Mon, Jan 26 2009 3:44 am
Subject: Re: [Rails-core] Re: MySQL auto-reconnect revisited

> Send us a patch with test for this one,  nice find!

...

> I think we should probably push reconnect into an option in
> database.yml so users can make their own decisions.  In my case the
> character_set values are set in my.cnf so those queries don't actually
> change anything for me.

> A patch to fix this up and test that the value is actually set would
> be greatly appreciated.  Failing that, a lighthouse ticket assigned to
> jeremy would be a good start.

Sounds good.
I will send a patch later today. Should I also open a lighthouse
ticket, or just post the patch here?

--
dubek.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Koziarski  
View profile  
 More options Jan 26, 3:51 am
From: Michael Koziarski <mich...@koziarski.com>
Date: Mon, 26 Jan 2009 21:51:10 +1300
Local: Mon, Jan 26 2009 3:51 am
Subject: Re: [Rails-core] Re: MySQL auto-reconnect revisited

> Sounds good.
> I will send a patch later today. Should I also open a lighthouse
> ticket, or just post the patch here?

Open a lighthouse ticket as well so we don't lose track of it.  Feel
free to assign it straight to me.

--
Cheers

Koz


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dubek  
View profile  
 More options Jan 26, 10:11 am
From: dubek <dov.mu...@gmail.com>
Date: Mon, 26 Jan 2009 07:11:00 -0800 (PST)
Subject: Re: MySQL auto-reconnect revisited

> Open a lighthouse ticket as well so we don't lose track of it.  Feel
> free to assign it straight to me.

Here's the lighthouse ticket:

http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/17...

I ran my patch tests on Mac OS X 10.5.6 and MySQL 5.0.67 . Please test
it on other combinations and report your results on the ticket.

Thanks!

--
dubek


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google