Processing long transactions with perl dbi

I have a big transaction consisting of getting a lot of data from database A, do some manipulation of this data, and then paste the managed data into database B. I only have permission to choose in database A, but I can create tables and insert / update etc. to database B.

Part of the manipulation and insertion is written in perl and is already used to load data into database B from other data sources, so all that is needed is to get the necessary data from database A and use it to initialize the perl classes.

How can I do this so that I can easily track and get from where the error occurred if during manipulation or insertion procedures (shutting down the database, problems initializing the class due to invalid values, hard disk failure, etc. ..)? Running a transaction at a time does not seem like a good option, because the sum of the data from database A means that it takes at least a day or 2 to process the data and insert it into database B.

Data from database A can be grouped into approximately 1000 groups using unique keys, each of which contains 1000 rows. One of the ways that I thought I could do is to write a script that makes transactions for each group, that is, I have to keep track of which group has already been inserted into database B. The only way that I can I can track the progress of the group whether they were processed or not, either in the log file or in the table in database B. The second way, which I thought could work, was to reset all the necessary fields needed to load the classes for manipulation and insert into a flatfile, read the file for Initialization and class inserts into a database B. This also means that I have to do some logging,but should narrow it down to the exact line in the flatfile if any error occurs. The script will look something like this:

use strict;
use warnings;
use DBI;

#connect to database A
my $dbh = DBI->connect('dbi:oracle:my_db', $user, $password, { RaiseError => 1, AutoCommit => 0 });

#statement to get data based on group unique key
my $sth = $dbh->prepare($my_sql);

my @groups; #I have a list of this already

open my $fh, '>>', 'my_logfile' or die "can't open logfile $!";

eval {
    foreach my $g (@groups){
        #subroutine to check if group has already been processed, either from log file or from database table
        next if is_processed($g);

        $sth->execute($g);
        my $data = $sth->fetchall_arrayref;

        #manipulate $data, then use it to load perl classes for insertion into database B
        #.
        #.
        #.
    }
    print $fh "$g\n";
};
if ($@){
   $dbh->rollback;
   die "something wrong...rollback";
}

, - , script, , .

, , ( ), , B .

, , . , ​​? Perl, perl .

+5
1

, , , , . , :

  • / temp ( "perldoc -f tie" sqlite)
  • TryCatch.pm, eval ,
  • , .. ,
  • script,

, , , , , , , "" .

+2

All Articles