[freeside-commits] branch master updated. fb03e9179814686b5c3665ce35b90cfeadb16fb9

Ivan ivan at 420.am
Wed May 14 13:20:51 PDT 2014


The branch, master has been updated
       via  fb03e9179814686b5c3665ce35b90cfeadb16fb9 (commit)
      from  9acc16fbf3b990f4d98d2dc31b46a0e486e73f4a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit fb03e9179814686b5c3665ce35b90cfeadb16fb9
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Wed May 14 13:20:50 2014 -0700

    added -a flag to freeside-upgrade to run schema changes in parallel, RT#29163

diff --git a/FS/bin/freeside-upgrade b/FS/bin/freeside-upgrade
index 3755a81..8c87ab2 100755
--- a/FS/bin/freeside-upgrade
+++ b/FS/bin/freeside-upgrade
@@ -1,9 +1,10 @@
 #!/usr/bin/perl -w
 
 use strict;
-use vars qw( $opt_d $opt_s $opt_q $opt_v $opt_r $opt_c $opt_j );
+use vars qw( $opt_d $opt_s $opt_q $opt_v $opt_r $opt_c $opt_j $opt_a );
 use vars qw( $DEBUG $DRY_RUN );
 use Getopt::Std;
+use DBD::Pg qw(:async); #for -a
 use DBIx::DBSchema 0.31; #0.39
 use FS::UID qw(adminsuidsetup checkeuid datasrc driver_name);
 use FS::CurrentUser;
@@ -17,7 +18,7 @@ my $start = time;
 
 die "Not running uid freeside!" unless checkeuid();
 
-getopts("dqrcsj");
+getopts("dqrcsja");
 
 $DEBUG = !$opt_q;
 #$DEBUG = $opt_v;
@@ -186,10 +187,43 @@ if ( $DRY_RUN ) {
     join(";\n", @statements ). ";\n";
   exit;
 } else {
+
+  my @clones = ();
   foreach my $statement ( @statements ) {
-    warn "$statement\n";
-    $dbh->do( $statement )
-      or die "Error: ". $dbh->errstr. "\n executing: $statement";
+
+    if ( $opt_a ) {
+
+      my $clone = '';
+      until ( $clone = $dbh->clone ) {
+        sleep 60; #too many database connections?  wait and retry
+      }
+      until ( $clone->do( $statement, {pg_async=>PG_ASYNC} ) ) {
+        sleep 60; #too many ... running queries?  wait and retry
+      }
+      warn "$statement\n";
+      push @clones, $clone;
+
+    } else {
+      warn "$statement\n";
+      $dbh->do( $statement )
+        or die "Error: ". $dbh->errstr. "\n executing: $statement";
+    }
+
+  }
+
+  warn "Waiting for all schema changes to complete\n" if @clones; # && $DEBUG;
+  while ( @clones ) {
+    my @newclones = ();
+    foreach my $clone ( @clones ) {
+      if ( $clone->pg_ready ) {
+        $clone->pg_result or die $clone->errstr;
+        $clone->commit    or die $clone->errstr;
+      } else {
+        push @newclones, $clone;
+      }
+    }
+    @clones = @newclones;
+    sleep 30 if @clones;
   }
 
 #  warn "Pre-schema change upgrades completed in ". (time-$start). " seconds\n"; # if $DEBUG;
@@ -330,7 +364,7 @@ sub dbdef_create { # reverse engineer the schema from the DB and save to file
 }
 
 sub usage {
-  die "Usage:\n  freeside-upgrade [ -d ] [ -r ] [ -s ] [ -q | -v ] user\n"; 
+  die "Usage:\n  freeside-upgrade [ -d ] [ -q | -v ] [ -r ] [ -c ] [ -s ] [ -j ] [ -a ] user\n"; 
 }
 
 =head1 NAME
@@ -339,7 +373,7 @@ freeside-upgrade - Upgrades database schema for new freeside verisons.
 
 =head1 SYNOPSIS
 
-  freeside-upgrade [ -d ] [ -r ] [ -c ] [ -s ] [ -q | -v ]
+  freeside-upgrade [ -d ] [ -q | -v ] [ -r ] [ -c ] [ -s ] [ -j ] [ -a ]
 
 =head1 DESCRIPTION
 
@@ -361,21 +395,27 @@ Also performs other upgrade functions:
 
   [ -q ]: Run quietly.  This may become the default at some point.
 
+  [ -v ]: Run verbosely, sending debugging information to STDERR.  This is the
+          current default.
+
+  [ -s ]: Schema changes only.  Useful for Pg/slony slaves where the data
+
   [ -r ]: Skip sqlradius updates.  Useful for occassions where the sqlradius
           databases may be inaccessible.
 
   [ -c ]: Skip cdr and h_cdr updates.
 
-  [ -v ]: Run verbosely, sending debugging information to STDERR.  This is the
-          current default.
-
-  [ -s ]: Schema changes only.  Useful for Pg/slony slaves where the data
           changes will be replicated from the Pg/slony master.
 
   [ -j ]: Run certain upgrades asychronously from the job queue.  Currently 
-          used only for the 2.x -> 3.x cust_location upgrade.  This may cause
-          odd behavior before the upgrade is complete, so it's recommended 
-          only for very large cust_main tables that take too long to upgrade.
+          used only for the 2.x -> 3.x cust_location, cust_pay and part_pkg
+          upgrades.  This may cause odd behavior before the upgrade is
+          complete, so it's recommended only for very large cust_main, cust_pay
+          and/or part_pkg tables that take too long to upgrade.
+
+  [ -a ]: Run schema changes in parallel (Pg only).  DBIx::DBSchema minimum 
+          version 0.41 recommended.  Recommended only for large databases and
+          powerful database servers, to reduce upgrade time.
 
 =head1 SEE ALSO
 

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

Summary of changes:
 FS/bin/freeside-upgrade |   68 +++++++++++++++++++++++++++++++++++++---------
 1 files changed, 54 insertions(+), 14 deletions(-)




More information about the freeside-commits mailing list