Loading ...
Sorry, an error occurred while loading the content.

Re: some children not returning newly-inserted data

Expand Messages
  • Aaron Ross
    Hi Dave, It looks like you are using Class::DBI. The behavior you describe is exactly what you would see if you had uncommitted changes. The changes would be
    Message 1 of 7 , May 2, 2004
    • 0 Attachment
      Hi Dave,

      It looks like you are using Class::DBI. The behavior you describe is
      exactly what you would see if you had uncommitted changes. The changes
      would be visible to the connections that made the changes, but not to
      the other processes or connections.

      If the problem is easy to reproduce, you could enable AutoCommit and see
      if it goes away.

      You've got all that nice logging in there, can you give us more details
      about the behavior your are seeing?

      HTH, Aaron

      On Sat, 2004-05-01 at 20:22, Dave Boodman wrote:
      > OK, here's some code:
      >
      > # systems
      > my @statuses;
      > my (@systems) = Lib::Systems->search( cid => $cid );
      > unless (@systems) { $self->model->log('debug',"systems for '$cid'
      > not found"); $self->context->throw('systems.not_found','Systems not
      > found' ); };
      > my $systems_profile = Lib::Profiles->system;
      > foreach my $sys (@systems) {
      > # reassign params from form names
      > my %tmp = map { $_ => $params{$_.'_'.$sys->sysid} }
      > Lib::Systems->columns;
      > my ($data, $errors) = $self->model->validate($systems_profile,
      > \%tmp);
      > if (@$errors) {
      > $self->context->throw('required', { fields => [@$errors] }
      > );
      > } else {
      > my (@relen_ips, @add_ips);
      > # establish status
      > my $status = 1;
      > if ($sys->cancel_date) { $status = 3; }
      > if ($sys->stop_date) { $status = 9; }
      >
      > # process a change in status
      > my $newstatus;
      > if ($sys->cancel_date < 1 && $tmp{'cancel_date'}) {
      > $self->model->log('info','cancelling system
      > '.$sys->sysid);
      > $newstatus = 3;
      > $status = 3;
      > }
      > if ($sys->stop_date < 1 && $tmp{'stop_date'}) {
      > $self->model->log('info','stopping system
      > '.$sys->sysid);
      > $newstatus = 9;
      > $status = 9;
      > }
      >
      > # store status so we can look at all and determine a cust
      > status
      > push @statuses, $status;
      >
      > # if status 9, add existing system's IPs to relen list
      > if ($newstatus == 9) {
      > my @ipobj = Lib::Ipmap->search( sysid => $sys->sysid,
      > status => 1 );
      > foreach (@ipobj) { push @relen_ips, $_->ip; }
      > }
      >
      > $self->model->log('info',"updating values for system
      > ".$sys->sysid);
      > while (my($key, $value) = each %$data) {
      > # we add this next line in case the client sends extra
      > # fields which we don't want to update. like the web
      > # client does
      > next unless ( Lib::Systems->find_column( $key ) );
      > $self->model->log('info',"setting $key to $value");
      >
      > eval { $sys->$key( $value ) };
      > if ($@) { $self->context->throw('set value', $@ ); }
      > }# end while
      > push @toupdate, $sys;
      >
      > # IPs
      > # add new
      > if ($params{'ip_'.$sys->sysid.'_new'}) {
      > my $assign_date = $self->model->{'time'}->ymd;
      > my $relen_date = 0;
      > # REMOVE WHEN WE GO LIVE AND ALL 2nd SYSTEMS ARE ADDED TO RECORDS
      > #
      > $assign_date = $sys->start_date;
      > # END REMOVE #
      > # if stopping server at same time assigning new ips
      > # we assume they were supposed to be there all the
      > time so we set
      > # assign date to sys start date. also, set relen_date
      > if ($newstatus == 9) { $assign_date =
      > $sys->start_date; $relen_date = $self->model->{'time'}->ymd; }
      > push @toupdate, update_ip($self, $sys->sysid, $cid,
      > $assign_date, $relen_date, split /[\s\,]/,
      > $params{'ip_'.$sys->sysid.'_new'});
      > $self->model->set('ip_'.$sys->sysid.'_new','');
      > } # end new ip if
      >
      > # get rid of ips
      > my $relen_date = $self->model->{'time'}->ymd;
      > push @relen_ips, $self->model->input('ip_'.$sys->sysid);
      > push @toupdate, update_ip($self, $sys->sysid, $cid, undef,
      > $relen_date, @relen_ips);
      > } # end update sys else
      > } # end sys foreach
      >
      > ---SNIP---
      >
      > # process updates
      > foreach my $obj (@toupdate) {
      > $self->model->log('info', "updating obj:");
      > $self->model->log_dumper('info', $obj);
      > eval { $obj->update };
      > if ($@) {
      > $self->model->log('info', 'update failed, rolling back');
      > foreach my $o (@created) { $o->dbi_rollback; }
      > $self->context->throw( 'update', $@ );
      > } else {
      > push @created, $obj;
      > }
      > }
      >
      > # if we made it this far, commit everything
      > foreach my $obj (@toupdate) { $obj->dbi_commit; }
      >
      > $self->model->set('addsystem','');
      > $self->model->set('addcontact','');
      > $self->model->set('do_update','');
      > return;
      >
      > Thanks!
      > At 03:40 PM 5/1/2004, Perrin Harkins wrote:
      > > Dave Boodman wrote:
      > > > I'm seeing an issue where I do an insert and upon subsequent
      > > > requests, certain children are not returning the newly-inserted
      > > > data (row), while others are. Restarting apache fixes this as does
      > > > waiting for some length of time.
      > >
      > > Sounds like you have a scoping problem. You are probably
      > > accidentally creating a closure somewhere that is holding onto old
      > > values. If you can reduce your code down to an example small enough
      > > to post here, we can try to spot it for you.
      > >
      > > - Perrin
      --
      Aaron Ross <aross@...>
      Plus Three


      --
      Report problems: http://perl.apache.org/bugs/
      Mail list info: http://perl.apache.org/maillist/modperl.html
      List etiquette: http://perl.apache.org/maillist/email-etiquette.html
    • Dave Boodman
      OK, here s some code: # systems my @statuses; my (@systems) = Lib::Systems- search( cid = $cid ); unless (@systems) { $self- model- log( debug , systems for
      Message 2 of 7 , May 3, 2004
      • 0 Attachment
        OK, here's some code:

        # systems
        my @statuses;
        my (@systems) = Lib::Systems->search( cid => $cid );
        unless (@systems) { $self->model->log('debug', "systems for '$cid' not
        found"); $self->context->throw( 'systems.not_found', 'Systems not found' ); };
        my $systems_profile = Lib::Profiles->system;
        foreach my $sys (@systems) {
        # reassign params from form names
        my %tmp = map { $_ => $params{$_.'_'.$sys->sysid} }
        Lib::Systems->columns;
        my ($data, $errors) = $self->model->validate($systems_profile, \%tmp);
        if (@$errors) {
        $self->context->throw( 'required', { fields => [@$errors] } );
        } else {
        my (@relen_ips, @add_ips);
        # establish status
        my $status = 1;
        if ($sys->cancel_date) { $status = 3; }
        if ($sys->stop_date) { $status = 9; }

        # process a change in status
        my $newstatus;
        if ($sys->cancel_date < 1 && $tmp{'cancel_date'}) {
        $self->model->log('info', 'cancelling system '.$sys->sysid);
        $newstatus = 3;
        $status = 3;
        }
        if ($sys->stop_date < 1 && $tmp{'stop_date'}) {
        $self->model->log('info', 'stopping system '.$sys->sysid);
        $newstatus = 9;
        $status = 9;
        }

        # store status so we can look at all and determine a cust status
        push @statuses, $status;

        # if status 9, add existing system's IPs to relen list
        if ($newstatus == 9) {
        my @ipobj = Lib::Ipmap->search( sysid => $sys->sysid,
        status => 1 );
        foreach (@ipobj) { push @relen_ips, $_->ip; }
        }

        $self->model->log('info', "updating values for system
        ".$sys->sysid);
        while (my($key, $value) = each %$data) {
        # we add this next line in case the client sends extra
        # fields which we don't want to update. like the web
        # client does
        next unless ( Lib::Systems->find_column( $key ) );
        $self->model->log('info', "setting $key to $value" );

        eval { $sys->$key( $value ) };
        if ($@) { $self->context->throw( 'set value', $@ ); }
        } # end while
        push @toupdate, $sys;

        # IPs
        # add new
        if ($params{'ip_'.$sys->sysid.'_new'}) {
        my $assign_date = $self->model->{'time'}->ymd;
        my $relen_date = 0;
        # REMOVE WHEN WE GO LIVE AND ALL 2nd SYSTEMS ARE ADDED TO RECORDS #
        $assign_date = $sys->start_date;
        # END REMOVE #
        # if stopping server at same time assigning new ips
        # we assume they were supposed to be there all the time so
        we set
        # assign date to sys start date. also, set relen_date
        if ($newstatus == 9) { $assign_date = $sys->start_date;
        $relen_date = $self->model->{'time'}->ymd; }
        push @toupdate, update_ip($self, $sys->sysid, $cid,
        $assign_date, $relen_date, split /[\s\,]/, $params{'ip_'.$sys->sysid.'_new'});
        $self->model->set('ip_'.$sys->sysid.'_new','');
        } # end new ip if

        # get rid of ips
        my $relen_date = $self->model->{'time'}->ymd;
        push @relen_ips, $self->model->input('ip_'.$sys->sysid);
        push @toupdate, update_ip($self, $sys->sysid, $cid, undef,
        $relen_date, @relen_ips);
        } # end update sys else
        } # end sys foreach

        ---SNIP---

        # process updates
        foreach my $obj (@toupdate) {
        $self->model->log('info', "updating obj:");
        $self->model->log_dumper('info', $obj);
        eval { $obj->update };
        if ($@) {
        $self->model->log('info', 'update failed, rolling back');
        foreach my $o (@created) { $o->dbi_rollback; }
        $self->context->throw( 'update', $@ );
        } else {
        push @created, $obj;
        }
        }

        # if we made it this far, commit everything
        foreach my $obj (@toupdate) { $obj->dbi_commit; }

        $self->model->set('addsystem','');
        $self->model->set('addcontact','');
        $self->model->set('do_update','');
        return;

        Thanks!
        At 03:40 PM 5/1/2004, Perrin Harkins wrote:
        >Dave Boodman wrote:
        >>I'm seeing an issue where I do an insert and upon subsequent requests,
        >>certain children are not returning the newly-inserted data (row), while
        >>others are. Restarting apache fixes this as does waiting for some length
        >>of time.
        >
        >Sounds like you have a scoping problem. You are probably accidentally
        >creating a closure somewhere that is holding onto old values. If you can
        >reduce your code down to an example small enough to post here, we can try
        >to spot it for you.
        >
        >- Perrin


        --
        Report problems: http://perl.apache.org/bugs/
        Mail list info: http://perl.apache.org/maillist/modperl.html
        List etiquette: http://perl.apache.org/maillist/email-etiquette.html
      • Perrin Harkins
        ... This is a little too much code to look at without any direction. The best thing to do would be to remove as much code as possible to get things down to
        Message 3 of 7 , May 3, 2004
        • 0 Attachment
          On Mon, 2004-05-03 at 13:15, Dave Boodman wrote:
          > OK, here's some code:

          This is a little too much code to look at without any direction. The
          best thing to do would be to remove as much code as possible to get
          things down to the smallest example that demonstrates the problem. You
          should also tell us which variables seem to be having the updating
          problem.

          I don't see any obvious scoping problems (closures) here, and you do
          seem to be updating your Class::DBI objects. I did notice that you are
          creating a new Template Toolkit object on every request, which is a bad
          idea because it breaks the built-in template cache and slows things down
          a lot, but that's not related to the problem you're having.

          - Perrin


          --
          Report problems: http://perl.apache.org/bugs/
          Mail list info: http://perl.apache.org/maillist/modperl.html
          List etiquette: http://perl.apache.org/maillist/email-etiquette.html
        Your message has been successfully submitted and would be delivered to recipients shortly.