[Dbix-class] forking within a single DBIx::Class transaction -- possible?

Leandro Hermida leandro.hermida at gmail.com
Tue Oct 13 16:05:13 GMT 2009


Hi everyone,

Been a long time since I've posted on this list, but been using DBIx::Class
for a couple years now and love it... great software.

Anywho, I've wrriten this code which do parallel processing (using
Parallel::Forker) within a single DBIx::Class transaction.  Something is not
working as it throws lock wait timeout errors.  I want to know, is it
possible to use for fork() in general within a single DBIx::Class
transaction?  Each of my child processes is working on different data in the
database, but I want to rollback everything if something fails in any child.

thanks for any insight,
leandro


use My::Schema;

eval {
    my $schema =3D My::Schema->connect(...);
    $schema->txn_do(sub {

        ... do some database stuff here before forking...

        my $forker =3D Parallel::Forker->new(use_sig_child =3D> 1, max_proc=
 =3D>
$num_procs);
        $SIG{CHLD} =3D sub { Parallel::Forker::sig_child($forker); };
        $SIG{TERM} =3D sub { $forker->kill_tree_all('TERM') if $forker &&
$forker->in_parent; };
        my @studies =3D $schema->resultset('Study')->all();
        for my $study (@studies) {
            $forker->schedule(run_on_start =3D> sub {

                ... here in child process code do some heavy processing and
                    then database inserts, deletes using $schema...

            })->ready();
        }
        # wait for all remaining child processes to finish
        $forker->wait_all();
    });
};
if ($@) {
    my $message =3D "Database transaction failed";
    $message .=3D " and ROLLBACK FAILED" if $@ =3D~ /rollback failed/i;
    die "\n\n$message: $@\n\n";
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20091013/0ca=
550cc/attachment.htm


More information about the DBIx-Class mailing list