IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24541


Ignore:
Timestamp:
Jun 24, 2009, 2:17:44 PM (17 years ago)
Author:
jhoblitt
Message:

infinitely try to get a db handle if the connection fails

Location:
trunk/Nebulous-Server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/Changes

    r24540 r24541  
    2727      passwd requirement (not all dbs require a password param)
    2828    - completely rework how mountedvol is populated, drop mount table
     29    - infinitely try to get a db handle if the connection fails
    2930     
    30310.16
  • trunk/Nebulous-Server/lib/Nebulous/Server.pm

    r24521 r24541  
    3535
    3636# transaction restart/retry regex
    37 my $trans_regex = qr/Deadlock Found|Lock wait timeout exceeded|try restarting transaction/i;
     37my $trans_regex = qr/Deadlock Found|Lock wait timeout exceeded|try restarting transaction|Can't connect to MySQL server/i;
    3838
    3939sub new
     
    145145    # processes and the database might have gone away on us.  Apache::DBI will
    146146    # take care of getting a valid dbh back.
    147     eval {
    148         $dbh = DBI->connect_cached(
    149             $db_config->dsn,
    150             $db_config->dbuser,
    151             $db_config->dbpasswd,
    152             {
    153                 RaiseError => 1,
    154                 PrintError => 0,
    155                 AutoCommit => 0,
    156             },
    157         );
    158 
    159         $dbh->do( $sql->set_transaction_model );
    160         $log->debug( "connected to database: ", sub { $dbh->data_sources; } );
    161         $dbh->commit;
    162         $log->debug("commit");
    163     };
    164     if ( $@ ) {
    165         $dbh->rollback if $dbh;
    166         $log->debug("rollback");
    167         $log->logdie( "database error: $@" );
     147    TRANS: while (1) {
     148        eval {
     149            $dbh = DBI->connect_cached(
     150                $db_config->dsn,
     151                $db_config->dbuser,
     152                $db_config->dbpasswd,
     153                {
     154                    RaiseError => 1,
     155                    PrintError => 0,
     156                    AutoCommit => 0,
     157                },
     158            );
     159
     160            $dbh->do( $sql->set_transaction_model );
     161            $log->debug( "connected to database: ", sub { $dbh->data_sources; } );
     162            $dbh->commit;
     163            $log->debug("commit");
     164        };
     165        if ($@) {
     166            $dbh->rollback if $dbh;
     167            $log->debug("rollback") if $dbh;
     168            if ($@ =~ qr/Can't connect to MySQL server/) {
     169                $log->warn("database error, retrying transaction: $@");
     170                redo TRANS;
     171            }
     172            $log->logdie( "database error: $@" );
     173        }
     174        last;
    168175    }
    169176
Note: See TracChangeset for help on using the changeset viewer.