Subject: Developers of Sympa
List archive
Re: [sympa-developpers] [sympa-commits] sympa[10373] branches/sympa-6.2-branch/src/lib: [bug] sympa. pl and other daemons crash when database access is gone, instead of keeping retry.
- From: IKEDA Soji <address@concealed>
- To: address@concealed
- Subject: Re: [sympa-developpers] [sympa-commits] sympa[10373] branches/sympa-6.2-branch/src/lib: [bug] sympa. pl and other daemons crash when database access is gone, instead of keeping retry.
- Date: Thu, 6 Mar 2014 23:39:12 +0900
Developers,
I examine not to provide connection pooling and auto reconnect of
SDM, but I found it is very costy. So I restored that feature.
SDM module is now identical to that of sympa-6.2-branch-old.
I dump up the version to 6.2b.1. Hard tests are appreciated.
Regards,
--- Soji
On Thu, 6 Mar 2014 10:40:24 +0100 (CET)
address@concealed wrote:
> sympa[10373] branches/sympa-6.2-branch/src/lib: [bug] sympa.pl and other
> daemons crash when database access is gone, instead of keeping retry.
> Revision 10373 Author sikeda Date 2014-03-06 10:40:24 +0100 (jeu. 06 mars
> 2014)
> Log Message[bug] sympa.pl and other daemons crash when database access is
> gone, instead of keeping retry.
>
> Now SDM::check_db_connect() keeps retry unless 'just_try' option is given.
> As a result, when db connection is gone (or not available):
> - SDM::db_get_handler() returns immediately.
> - SDM::probe_db(), SDM::quote(), SDM::do_prepared_query() and
> SDM::do_query() stall while connection is restored.
>
> Note:
> - SDM::check_db_connect() should be used instead of
> SDM::connect_sympa_database() to wait for connection safely.
> - SDM::db_get_handler() is not recommented. DB handler should not be used
> directly.
> Modified Paths
> branches/sympa-6.2-branch/src/lib/Log.pm
> branches/sympa-6.2-branch/src/lib/SDM.pm
> Diff
> Modified: branches/sympa-6.2-branch/src/lib/Log.pm (10372 => 10373)
> --- branches/sympa-6.2-branch/src/lib/Log.pm 2014-03-06 09:06:46 UTC (rev
> 10372)
> +++ branches/sympa-6.2-branch/src/lib/Log.pm 2014-03-06 09:40:24 UTC (rev
> 10373)
> @@ -391,8 +391,6 @@
>
> # Scan log_table with appropriate select
> sub get_first_db_log {
> - my $dbh = &SDM::db_get_handler();
> -
> my $select = shift;
>
> my %action_type = ('message' =>
> ['reject','distribute','arc_delete','arc_download',
> Modified: branches/sympa-6.2-branch/src/lib/SDM.pm (10372 => 10373)
> --- branches/sympa-6.2-branch/src/lib/SDM.pm 2014-03-06 09:06:46 UTC (rev
> 10372)
> +++ branches/sympa-6.2-branch/src/lib/SDM.pm 2014-03-06 09:40:24 UTC (rev
> 10373)
> @@ -67,8 +67,14 @@
> my @params = @_;
> my $sth;
>
> - unless ($sth = $db_source->do_query($query,@params)) {
> - &Log::do_log('err','SQL query failed to execute in the Sympa
> database');
> + if (check_db_connect()) {
> + unless ($sth = $db_source->do_query($query, @params)) {
> + Log::do_log('err',
> + 'SQL query failed to execute in the Sympa database');
> + return undef;
> + }
> + } else {
> + Log::do_log('err', 'Unable to get a handle to Sympa database');
> return undef;
> }
>
> @@ -80,39 +86,52 @@
> my @params = @_;
> my $sth;
>
> - unless ($sth = $db_source->do_prepared_query($query,@params)) {
> - &Log::do_log('err','SQL query failed to execute in the Sympa
> database');
> + if (check_db_connect()) {
> + unless ($sth = $db_source->do_prepared_query($query, @params)) {
> + Log::do_log('err',
> + 'SQL query failed to execute in the Sympa database');
> + return undef;
> + }
> + } else {
> + Log::do_log('err', 'Unable to get a handle to Sympa database');
> return undef;
> }
> -
> +
> return $sth;
> }
>
> ## Get database handler
> +## Note: if database connection is not available, this function returns
> +## immediately.
> +##
> +## NOT RECOMMENDED. Should not access to database handler.
> sub db_get_handler {
> - &Log::do_log('debug3', 'Returning handle to sympa database');
> + Log::do_log('debug3', '()');
>
> - if(&check_db_connect()) {
> + if (check_db_connect('just_try')) {
> return $db_source->{'dbh'};
> - }else {
> - &Log::do_log('err', 'Unable to get a handle to Sympa database');
> + } else {
> + Log::do_log('err', 'Unable to get a handle to Sympa database');
> return undef;
> }
> }
>
> ## Just check if DB connection is ok
> +## Possible option is 'just_try', won't try to reconnect if database
> +## connection is not available.
> sub check_db_connect {
> + my @options = @_;
>
> - #&Log::do_log('debug2', 'Checking connection to the Sympa database');
> ## Is the Database defined
> unless (&Conf::get_robot_conf('*','db_name')) {
> - &Log::do_log('err', 'No db_name defined in configuration file');
> + Log::do_log('err', 'No db_name defined in configuration file');
> return undef;
> }
>
> - unless ($db_source->{'dbh'} && $db_source->{'dbh'}->ping()) {
> - unless (&connect_sympa_database('just_try')) {
> - &Log::do_log('err', 'Failed to connect to database');
> + unless ($db_source and $db_source->{'dbh'} and
> + $db_source->{'dbh'}->ping()) {
> + unless (connect_sympa_database(@options)) {
> + Log::do_log('err', 'Failed to connect to database');
> return undef;
> }
> }
> @@ -122,10 +141,9 @@
>
> ## Connect to Database
> sub connect_sympa_database {
> - my $option = shift;
> + Log::do_log('debug2', '(%s)', @_);
> + my $option = shift || '';
>
> - &Log::do_log('debug', 'Connecting to Sympa database');
> -
> ## We keep trying to connect if this is the first attempt
> ## Unless in a web context, because we can't afford long response time
> on the web interface
> my $db_conf = &Conf::get_parameters_group('*','Database related');
> @@ -161,10 +179,15 @@
> }
>
> sub probe_db {
> - &Log::do_log('debug3', 'Checking database structure');
> + Log::do_log('debug3', 'Checking database structure');
> my (%checked, $table);
>
> - my $dbh = &db_get_handler();
> + unless (check_db_connect()) {
> + Log::do_log('err',
> + 'Could not check the database structure. Make sure that
> database connection is available'
> + );
> + return undef;
> + }
>
> ## Database structure
> ## Report changes to listmaster
> @@ -257,7 +280,9 @@
> $List::use_db = 1;
>
> ## Notify listmaster
> - &List::send_notify_to_listmaster('db_struct_updated',
> &Conf::get_robot_conf('*','domain'), {'report' => \@report}) if ($#report
> >= 0);
> + List::send_notify_to_listmaster('db_struct_updated',
> + Conf::get_robot_conf('*','domain'), {'report' => \@report})
> + if @report;
>
> return 1;
> }
--
株式会社 コンバージョン セキュリティ&OSSソリューション部 池田荘児
〒231-0004 神奈川県横浜市中区元浜町3-21-2 ヘリオス関内ビル7F
e-mail address@concealed TEL 045-640-3550
http://www.conversion.co.jp/
-
Re: [sympa-developpers] [sympa-commits] sympa[10373] branches/sympa-6.2-branch/src/lib: [bug] sympa. pl and other daemons crash when database access is gone, instead of keeping retry.,
IKEDA Soji, 03/06/2014
-
[sympa-developpers] database connection pooling,
Guillaume Rousse, 03/10/2014
-
Re: [sympa-developpers] database connection pooling,
IKEDA Soji, 03/11/2014
-
Re: [sympa-developpers] database connection pooling,
Guillaume Rousse, 03/11/2014
- Re: [sympa-developpers] database connection pooling, IKEDA Soji, 03/11/2014
-
Re: [sympa-developpers] database connection pooling,
Guillaume Rousse, 03/11/2014
-
Re: [sympa-developpers] database connection pooling,
IKEDA Soji, 03/11/2014
-
[sympa-developpers] database connection pooling,
Guillaume Rousse, 03/10/2014
Archive powered by MHonArc 2.6.19+.