cvsuser     03/06/20 21:52:28

  Modified:    P5EEx/Blue/P5EEx/Blue Repository.pm
               P5EEx/Blue/P5EEx/Blue/Repository DBI.pm
  Log:
  changed locking from hard (db) table locking to advisory
  
  Revision  Changes    Path
  1.24      +41 -1     p5ee/P5EEx/Blue/P5EEx/Blue/Repository.pm
  
  Index: Repository.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/P5EEx/Blue/P5EEx/Blue/Repository.pm,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -w -r1.23 -r1.24
  --- Repository.pm     30 Aug 2002 17:50:25 -0000      1.23
  +++ Repository.pm     21 Jun 2003 04:52:28 -0000      1.24
  @@ -1,6 +1,6 @@
   
   #############################################################################
  -## $Id: Repository.pm,v 1.23 2002/08/30 17:50:25 spadkins Exp $
  +## $Id: Repository.pm,v 1.24 2003/06/21 04:52:28 spadkins Exp $
   #############################################################################
   
   package P5EEx::Blue::Repository;
  @@ -2406,6 +2406,46 @@
       };
       bless $object, $class;
       return $object;
  +}
  +
  +#############################################################################
  +# METHODS
  +#############################################################################
  +
  +=head1 Methods: Locking (Concurrency Management)
  +
  +=cut
  +
  +# this is a write lock for the table
  +sub _lock_table {
  +    &App::sub_entry if ($App::trace_subs);
  +    my ($self, $table) = @_;
  +    if (! $self->{locked}) {   # I have locked it myself, so I don't need to again
  +        my ($srs, $dbname, $context, $rlock);
  +        $srs = $self->{shared_resource_set} || "default";
  +        $dbname = $self->{dbname};
  +        $context = $self->{context};
  +        $rlock = $context->shared_resource_set($srs);  # get the one that 
corresponds to this repository
  +        $rlock->lock("db.$dbname.$table");
  +        $self->{locked} = 1;
  +    }
  +    &App::sub_exit() if ($App::trace_subs);
  +}
  +
  +# unlocks the write lock for the table
  +sub _unlock_table {
  +    &App::sub_entry if ($App::trace_subs);
  +    my ($self, $table) = @_;
  +    if ($self->{locked}) {
  +        my ($srs, $dbname, $context, $rlock);
  +        $srs = $self->{shared_resource_set} || "default";
  +        $dbname = $self->{dbname};
  +        $context = $self->{context};
  +        $rlock = $context->shared_resource_set($srs);  # get the one that 
corresponds to this repository
  +        $rlock->unlock("db.$dbname.$table");
  +        delete $self->{locked};
  +    }
  +    &App::sub_exit() if ($App::trace_subs);
   }
   
   #############################################################################
  
  
  
  1.23      +373 -355  p5ee/P5EEx/Blue/P5EEx/Blue/Repository/DBI.pm
  
  Index: DBI.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/P5EEx/Blue/P5EEx/Blue/Repository/DBI.pm,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -w -r1.22 -r1.23
  --- DBI.pm    14 Mar 2003 16:51:38 -0000      1.22
  +++ DBI.pm    21 Jun 2003 04:52:28 -0000      1.23
  @@ -1,13 +1,13 @@
   
   ######################################################################
  -## File: $Id: DBI.pm,v 1.22 2003/03/14 16:51:38 spadkins Exp $
  +## File: $Id: DBI.pm,v 1.23 2003/06/21 04:52:28 spadkins Exp $
   ######################################################################
   
   use P5EEx::Blue::P5EE;
   use P5EEx::Blue::Repository;
   
   package P5EEx::Blue::Repository::DBI;
  -$VERSION = do { my @r=(q$Revision: 1.22 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
  +$VERSION = do { my @r=(q$Revision: 1.23 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
   
   @ISA = ( "P5EEx::Blue::Repository" );
   
  @@ -1344,7 +1344,9 @@
       $self->{sql} = $sql;
       my $dbh = $self->{dbh};
       return 0 if (!defined $dbh);
  -    return $dbh->do($sql);
  +    my $rval = $dbh->do($sql);
  +    #print "sql=\n$sql\n >> rows=$rval err=", $dbh->errstr(), "\n";
  +    return($rval);
   }
   
   # $ok = $rep->update_rows($table, [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL 
PROTECTED], \%paramvalues);
  @@ -1431,7 +1433,9 @@
           $context->dbgprint("   keycolidx=[", join(",",@$keycolidx),  "]") if 
($keycolidx);
       }
   
  -    $self->store_begin($table);
  +    #$self->store_begin($table);
  +    $self->_lock_table($table);
  +    eval {
       $tabledef = $self->{table}{$table};
       $table_ih = $tabledef->{table_ih} || "";
       $column_change_dttm = $tabledef->{column_change_dttm} || "";
  @@ -1577,8 +1581,13 @@
       }
   
       $nrows = $ok ? 1 : 0;
  -
  -    $self->store_end($table);
  +    };
  +    if ($@) {
  +        $self->_unlock_table($table);
  +        die "Exception in store_rows(): $@";
  +    }
  +    $self->_unlock_table($table);
  +    #$self->store_end($table);
       $self->{numrows} = $nrows;
       $nrows;
   }
  @@ -1634,7 +1643,9 @@
           $context->dbgprint("   rowcrit=[",   join("|",%$row_crit),"]") if 
($row_crit);
       }
   
  -    $self->store_begin($table);
  +    #$self->store_begin($table);
  +    $self->_lock_table($table);
  +    eval {
       $tabledef = $self->{table}{$table};
       $table_ih = $tabledef->{table_ih} || "";
       $column_change_dttm = $tabledef->{column_change_dttm} || "";
  @@ -1857,25 +1868,32 @@
               last if (!$ok);
           }
       }
  -
  -    $self->store_end($table);
  +    };
  +    if ($@) {
  +        $self->_unlock_table($table);
  +        die "Exception in store_rows(): $@";
  +    }
  +    $self->_unlock_table($table);
  +    #$self->store_end($table);
       $self->{numrows} = $nrows;
       $nrows;
   }
   
  -sub store_begin {
  -    my ($self, $table) = @_;
  -    if (! $self->{locked}) {
  -        my ($lock_stmt, $alias, $table_ih);
  -        $lock_stmt = "lock tables $table write";
  -        $alias = $self->{table}{$table}{alias};
  -        $lock_stmt .= ", $table $alias write" if ($alias);
  -        $table_ih = $self->{table}{$table}{table_ih};
  -        $lock_stmt .= ", $table_ih write" if ($table_ih);
  -        $self->{dbh}->do($lock_stmt);
  -        $self->{locked} = 1;
  -    }
  -}
  +#sub store_begin {
  +#    my ($self, $table) = @_;
  +#    if (! $self->{locked}) {
  +#        my ($lock_stmt, $alias, $table_ih);
  +#        $lock_stmt = "lock tables $table write";
  +#        $alias = $self->{table}{$table}{alias};
  +#        $lock_stmt .= ", $table $alias write" if ($alias);
  +#        $table_ih = $self->{table}{$table}{table_ih};
  +#        $lock_stmt .= ", $table_ih write" if ($table_ih);
  +#        $self->{context}->dbgprint("store_begin(): $lock_stmt\n")
  +#            if ($P5EEx::Blue::DEBUG && $self->{context}->dbg(1));
  +#        $self->{dbh}->do($lock_stmt);
  +#        $self->{locked} = 1;
  +#    }
  +#}
   
   sub next_id {
       my ($self, $table, $last_id) = @_;
  @@ -1894,13 +1912,13 @@
       return $id;
   }
   
  -sub store_end {
  -    my ($self, $table) = @_;
  -    if ($self->{locked}) {
  -        delete $self->{locked};
  -        $self->{dbh}->do("unlock tables");
  -    }
  -}
  +#sub store_end {
  +#    my ($self, $table) = @_;
  +#    if ($self->{locked}) {
  +#        delete $self->{locked};
  +#        $self->{dbh}->do("unlock tables");
  +#    }
  +#}
   
   ######################################################################
   # METADATA REPOSITORY METHODS (implements methods from P5EEx::Blue::Repository)
  
  
  

Reply via email to