I can confirm having to resend the connection setup SQL commands after a reconnect as
well. At first we were using auto reconnect, until we found out the character set (sent
after a connect) reset after a reconnect.
We also tried finding out if there was an onConnect() callback to use, but there was none.
This resulted in us having to build a manager doing the ping and query queuing Warren
suggested, which was a headache since we also had to make sure the query queue was backed
up in case the software crashes while in queue mode.
Quite odd behavior, the feature is unusable if you need to know when it reconnects and/or
need to setup the connection.
Freddy
-----Oorspronkelijk bericht-----
Van: Dino Korah [mailto:dckorah@stripped]
Verzonden: donderdag 26 november 2009 1:31
Aan: plusplus@stripped; plusplus@stripped
Onderwerp: Re: set_option ( ReconnectOption )
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.
--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsub=1