[OPEN-ILS-DEV] clarification about commits and rollbacks in action.pm

Mike Rylander mrylander at gmail.com
Thu Apr 9 20:13:41 EDT 2009


On Thu, Apr 9, 2009 at 3:19 PM, Steven Chan <schan at vcn.bc.ca> wrote:
> I'm puzzled about the sequence of commits and rollbacks in the Perl module
> Storage::Publisher::action.pm in the open-ils software.
> Most of the transactions in action.pm are structured in this way:
>
> try {
>    do_things_including_some_db_operations();
>    $self->method_lookup('open-ils.storage.transaction.commit')->run;
>    do_more_things_including_more_db_operations();
> } otherwise {
>    log_errors();
>    $self->method_lookup('open-ils.storage.transaction.rollback')->run;
> };
>


I'd be happy to comment on specific instances, but it's not most
transactional code.  In fact, the only active instance of this that I
find is in the hold targeting method.  In all cases there, the early
commit is immediately followed by a die, circumventing the rest of the
try block, or by the end of the block itself.

In other words, it works more like this:

while (next available) {
  try {
    some_stuff();
    if (done) commit() && next();

    some_more_stuff();
    if (done) commit() && next();

    still_more_stuff();
    if (done) commit() && next();

    final_stuff();
    commit();
  } otherwise {
    log();
    rollback();
  };
}

The reason we don't just use 'next;' is that it doesn't work from
inside a try block.  The block is a closure, not a syntactic structure
as in other languages like Java, so we have to die() out of it,
checking the reason for the death to decide if it was an error or
simply a short-circuit.

-- 
Mike Rylander
 | VP, Research and Design
 | Equinox Software, Inc. / The Evergreen Experts
 | phone:  1-877-OPEN-ILS (673-6457)
 | email:  miker at esilibrary.com
 | web:  http://www.esilibrary.com


More information about the Open-ils-dev mailing list