List:MySQL++« Previous MessageNext Message »
From:Dino Korah Date:November 26 2009 12:30am
Subject:Re: set_option ( ReconnectOption )
View as plain text  
Yes, I have tested that.

My test results seem to tally up with what I could read here 
http://dev.mysql.com/doc/refman/5.0/en/auto-reconnect.html

Code below was used. I restarted the server at every 30s sleep() I have 
in the below code.
If you follow the same but with the "SET @@session..." lines other than 
the first set commented out; the sequence generated in the table is 1 2 
3, where as the expected sequence is 1 3 5

Here MySQL version is 5.0.75

--------------------------8<----------------------------
#include <mysql++.h>
#include <string>
#include <iostream>

int main() {
	mysqlpp::Connection conn(true);
	conn.set_option(new mysqlpp::ReconnectOption(true));

	if(!conn.connect("test_purge", "localhost", "root")) {
		std::cerr << "db connection failed - " << conn.error() << std::endl;
		return 1;
	}
	
	conn.query("SET @@session.AUTO_INCREMENT_INCREMENT = 2").execute();
	conn.query("SET @@session.AUTO_INCREMENT_OFFSET = 1").execute();
	conn.query("INSERT INTO auto_inc () VALUES ()").execute();


	std::cout << "========================" << std::endl;
	sleep(30);

	conn.query("SET @@session.AUTO_INCREMENT_INCREMENT = 2").execute();
	conn.query("SET @@session.AUTO_INCREMENT_OFFSET = 1").execute();
	conn.query("INSERT INTO auto_inc () VALUES ()").execute();

	std::cout << "========================" << std::endl;
	sleep(30);
	
	conn.query("SET @@session.AUTO_INCREMENT_INCREMENT = 2").execute();
	conn.query("SET @@session.AUTO_INCREMENT_OFFSET = 1").execute();
	conn.query("INSERT INTO auto_inc () VALUES ()").execute();

	
}


-------------------8<-------------------

CREATE TABLE `auto_inc` (
   `id` int(11) NOT NULL auto_increment,
   PRIMARY KEY  (`id`)
) ENGINE=MyISAM


Warren Young wrote:
> Dino Korah wrote:
>> reconnect -> re-initialise-connection -> do-processing.
> 
> Are you certain you need to re-send the connection setup SQL commands 
> after reconnection?  The whole point of automatic reconnection is that 
> the connection should be put back in the same state it was in before it 
> was dropped.  I don't know one way or the other; have you tested it?
> 
> If that doesn't happen, then I would suggest using periodic 
> Connection::ping() calls instead of ReconnectOption.  When ping() fails, 
> reconnect and reinit.  You also have to check query failure if you go 
> down this path, however, because the DB server could go away in between 
> a ping() success and the Query::execute()/store()/use() call.
Thread
set_option ( ReconnectOption )Dino Korah25 Nov
  • Re: set_option ( ReconnectOption )Warren Young25 Nov
    • Re: set_option ( ReconnectOption )Dino Korah25 Nov
      • Re: set_option ( ReconnectOption )Warren Young25 Nov
        • Re: set_option ( ReconnectOption )Dino Korah25 Nov
          • Re: set_option ( ReconnectOption )Warren Young25 Nov
            • Re: set_option ( ReconnectOption )Dino Korah26 Nov
              • Re: set_option ( ReconnectOption )Warren Young26 Nov
                • Re: set_option ( ReconnectOption )Dino Korah26 Nov
                  • Re: set_option ( ReconnectOption )Warren Young26 Nov
                • Re: set_option ( ReconnectOption )Dino Korah26 Nov
                  • Re: set_option ( ReconnectOption )Warren Young26 Nov
            • Re: set_option ( ReconnectOption )Dino Korah26 Nov
              • RE: set_option ( ReconnectOption )F.N. Bruggeman26 Nov