[Rt-commit] rt branch, 4.0/dbh-management, created. rt-4.0.0rc4-29-g2daa218

Alex Vandiver alexmv at bestpractical.com
Sun Jan 30 22:06:00 EST 2011


The branch, 4.0/dbh-management has been created
        at  2daa218b4e5d0f06cacfdb2e7a608916f9a5f27f (commit)

- Log -----------------------------------------------------------------
commit a4c97e45352f29a5785daa6b50c0d11b14479073
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sun Jan 30 20:06:10 2011 -0500

    Remove references to "Force" argument to DropDatabase, removed back in 141625a

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 33703fd..4217c7b 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -345,13 +345,13 @@ sub CreateDatabase {
     return ($status, $DBI::errstr);
 }
 
-=head3 DropDatabase $DBH [Force => 0]
+=head3 DropDatabase $DBH
 
 Drops RT's database. This method can be used as class method.
 
 Takes DBI handle as first argument. Many database systems require
-special handle to allow you to create a new database, so you have
-to use L<SystemDSN> method during connection.
+special handle to allow you to drop a database, so you have
+to use L<SystemDSN> to create this handle.
 
 Fetches type and name of the DB from the config.
 
diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index d0d465e..73337c3 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -373,7 +373,7 @@ sub bootstrap_db {
     unless ($args{nodb}) {
         unless ( $ENV{RT_TEST_PARALLEL} ) {
             # already dropped db in parallel tests, need to do so for other cases.
-            RT::Handle->DropDatabase( $dbh, Force => 1 )
+            RT::Handle->DropDatabase( $dbh )
         }
         RT::Handle->CreateDatabase( $dbh );
         $dbh->disconnect;
@@ -1380,7 +1380,7 @@ END {
         $dbh->disconnect if $dbh;
 
         $dbh = _get_dbh( RT::Handle->SystemDSN, $ENV{RT_DBA_USER}, $ENV{RT_DBA_PASSWORD} );
-        RT::Handle->DropDatabase( $dbh, Force => 1 );
+        RT::Handle->DropDatabase( $dbh );
         $dbh->disconnect;
     }
 }

commit 813a8dcef329916d44a173fec01b38c835267d79
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sun Jan 30 20:09:18 2011 -0500

    Provide a RT->DisconnectFromDatabase, to parallel RT->ConnectToDatabase

diff --git a/lib/RT.pm b/lib/RT.pm
index 865bc02..749d166 100644
--- a/lib/RT.pm
+++ b/lib/RT.pm
@@ -165,6 +165,19 @@ sub ConnectToDatabase {
     return $Handle;
 }
 
+=head2 DisconnectFromDatabase
+
+Disconnects the current L</Handle>.
+
+=cut
+
+sub DisconnectFromDatabase {
+    $RT::Handle->dbh->disconnect if $RT::Handle and $RT::Handle->dbh;
+    undef $RT::Handle;
+    # the attribute cache holds on to a stale dbh
+    delete $RT::System->{attributes};
+}
+
 =head2 InitLogging
 
 Create the Logger object and set up signal handlers.
diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 73337c3..98c0ffe 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -389,8 +389,7 @@ sub bootstrap_db {
         my $db_type = RT->Config->Get('DatabaseType');
         $RT::Handle->InsertACL( $dbh ) unless $db_type eq 'Oracle';
 
-        $RT::Handle = RT::Handle->new;
-        $RT::Handle->dbh( undef );
+        RT->DisconnectFromDatabase;
         RT->ConnectToDatabase;
         RT->InitLogging;
 
@@ -1376,10 +1375,9 @@ END {
     if ( $ENV{RT_TEST_PARALLEL} && $created_new_db ) {
 
         # Pg doesn't like if you issue a DROP DATABASE while still connected
-        my $dbh = $RT::Handle->dbh;
-        $dbh->disconnect if $dbh;
+        RT->DisconnectFromDatabase;
 
-        $dbh = _get_dbh( RT::Handle->SystemDSN, $ENV{RT_DBA_USER}, $ENV{RT_DBA_PASSWORD} );
+        my $dbh = _get_dbh( RT::Handle->SystemDSN, $ENV{RT_DBA_USER}, $ENV{RT_DBA_PASSWORD} );
         RT::Handle->DropDatabase( $dbh );
         $dbh->disconnect;
     }
diff --git a/sbin/rt-server.in b/sbin/rt-server.in
index 8b19c22..71e8813 100755
--- a/sbin/rt-server.in
+++ b/sbin/rt-server.in
@@ -129,10 +129,7 @@ EOF
 }
 
 # we must disconnect DB before fork
-if ($RT::Handle) {
-    $RT::Handle->dbh(undef);
-    undef $RT::Handle;
-}
+RT->DisconnectFromDatabase;
 
 require RT::Interface::Web::Handler;
 my $app = RT::Interface::Web::Handler->PSGIApp;

commit 8ea18312c86bc33df69f5e0515bb3913d7342c0c
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sun Jan 30 20:10:27 2011 -0500

    Remove an un-necessary disconnect and reconnect during initialdata insertion

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 98c0ffe..315d32c 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -395,13 +395,9 @@ sub bootstrap_db {
 
         unless ($args{noinitialdata}) {
             $RT::Handle->InsertInitialData;
-
             DBIx::SearchBuilder::Record::Cachable->FlushCache;
         }
 
-        $RT::Handle = RT::Handle->new;
-        $RT::Handle->dbh( undef );
-        RT->ConnectToDatabase();
         $RT::Handle->PrintError;
         $RT::Handle->dbh->{PrintError} = 1;
 

commit 337ddd072e35bccb3b79c870ffac0a12ab99da71
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sun Jan 30 20:10:45 2011 -0500

    Minor typo fix

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 315d32c..fcd64f6 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -481,7 +481,7 @@ sub bootstrap_plugins {
             Test::More::ok(1, "There is no etc dir: no data" );
         }
 
-        $RT::Handle->Connect; # XXX: strange but mysql can loose connection
+        $RT::Handle->Connect; # XXX: strange but mysql can lose connection
     }
     $dba_dbh->disconnect if $dba_dbh;
 }

commit 2daa218b4e5d0f06cacfdb2e7a608916f9a5f27f
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sun Jan 30 20:10:53 2011 -0500

    Ensure that database handles are not left open across calls to fork()
    
    This solves a problem wherein the previous live database handle was
    still connected during cleanup in the parent, causing Postgres to be
    unable to drop the database.

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index fcd64f6..1c05e50 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -1203,9 +1203,14 @@ sub start_plack_server {
              kill 'USR1' => getppid();
          });
 
+    # Ensure that we have no db connections open across the fork; we
+    # will re-open them independently in both parent and child
+    RT->DisconnectFromDatabase;
+
     my $pid = fork();
     die "failed to fork" unless defined $pid;
 
+    RT->ConnectToDatabase;
     if ($pid) {
         # We are expecting a USR1 from the child process after it's
         # ready to listen.
@@ -1218,12 +1223,6 @@ sub start_plack_server {
         my $Tester = Test::Builder->new;
         $Tester->ok(1, @_);
 
-        $RT::Handle = RT::Handle->new;
-        $RT::Handle->dbh( undef );
-        RT->ConnectToDatabase;
-        # the attribute cache holds on to a stale dbh
-        delete $RT::System->{attributes};
-
         return ("http://localhost:$port", RT::Test::Web->new);
     }
 
diff --git a/lib/RT/Test/Apache.pm b/lib/RT/Test/Apache.pm
index ae40e4c..6e88924 100644
--- a/lib/RT/Test/Apache.pm
+++ b/lib/RT/Test/Apache.pm
@@ -158,6 +158,7 @@ sub find_apache_server {
 sub fork_exec {
     my $self = shift;
 
+    RT->DisconnectFromDatabase;
     my $pid = fork;
     unless ( defined $pid ) {
         die "cannot fork: $!";
@@ -165,6 +166,7 @@ sub fork_exec {
         exec @_;
         die "can't exec `". join(' ', @_) ."` program: $!";
     } else {
+        RT->ConnectToDatabase;
         return $pid;
     }
 }

-----------------------------------------------------------------------


More information about the Rt-commit mailing list