/[webpac2]/trunk/run.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/run.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 595 by dpavlin, Mon Jul 10 10:16:11 2006 UTC revision 608 by dpavlin, Tue Aug 1 16:47:40 2006 UTC
# Line 22  use File::Slurp; Line 22  use File::Slurp;
22  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
23  use Storable qw/dclone/;  use Storable qw/dclone/;
24    
25    use Proc::Queue size => 1;
26    use POSIX ":sys_wait_h"; # imports WNOHANG
27    
28  =head1 NAME  =head1 NAME
29    
30  run.pl - start WebPAC indexing  run.pl - start WebPAC indexing
# Line 81  messages with C<--no-marc-lint>. Line 84  messages with C<--no-marc-lint>.
84    
85  Force dump or input and marc record for debugging.  Force dump or input and marc record for debugging.
86    
87    =item --parallel 4
88    
89    Run databases in parallel (aproximatly same as number of processors in
90    machine if you want to use full load)
91    
92    =item --only-links
93    
94    Create just links
95    
96    =item --merge
97    
98    Create merged index of databases which have links
99    
100  =back  =back
101    
102  =cut  =cut
# Line 97  my $validate_path; Line 113  my $validate_path;
113  my ($marc_normalize, $marc_output);  my ($marc_normalize, $marc_output);
114  my $marc_lint = 1;  my $marc_lint = 1;
115  my $marc_dump = 0;  my $marc_dump = 0;
116    my $parallel = 0;
117    my $only_links = 0;
118    my $merge = 0;
119    
120  GetOptions(  GetOptions(
121          "limit=i" => \$limit,          "limit=i" => \$limit,
# Line 112  GetOptions( Line 131  GetOptions(
131          "marc-output=s" => \$marc_output,          "marc-output=s" => \$marc_output,
132          "marc-lint!" => \$marc_lint,          "marc-lint!" => \$marc_lint,
133          "marc-dump!" => \$marc_dump,          "marc-dump!" => \$marc_dump,
134            "parallel=i" => \$parallel,
135            "only-links!" => \$only_links,
136            "merge" => \$merge,
137  );  );
138    
139  $config = LoadFile($config);  $config = LoadFile($config);
# Line 123  die "no databases in config file!\n" unl Line 145  die "no databases in config file!\n" unl
145  my $log = _new WebPAC::Common()->_get_logger();  my $log = _new WebPAC::Common()->_get_logger();
146  $log->info( "-" x 79 );  $log->info( "-" x 79 );
147    
148    
149    my $estcmd_fh;
150    my $estcmd_path = './estcmd-merge.sh';
151    if ($merge) {
152            open($estcmd_fh, '>', $estcmd_path) || $log->logdie("can't open $estcmd_path: $!");
153            print $estcmd_fh 'cd /data/estraier/_node/ || exit 1',$/;
154            print $estcmd_fh 'sudo /etc/init.d/hyperestraier stop',$/;
155            $log->info("created merge batch file $estcmd_path");
156    }
157    
158    
159  my $validate;  my $validate;
160  $validate = new WebPAC::Validate(  $validate = new WebPAC::Validate(
161          path => $validate_path,          path => $validate_path,
162  ) if ($validate_path);  ) if ($validate_path);
163    
164    
165  my $use_indexer = $config->{use_indexer} || 'hyperestraier';  my $use_indexer = $config->{use_indexer} || 'hyperestraier';
166  if ($stats) {  if ($stats) {
167          $log->debug("option --stats disables update of indexing engine...");          $log->debug("option --stats disables update of indexing engine...");
# Line 143  my $total_rows = 0; Line 177  my $total_rows = 0;
177  my $start_t = time();  my $start_t = time();
178    
179  my @links;  my @links;
180  my $indexer;  
181    if ($parallel) {
182            $log->info("Using $parallel processes for speedup");
183            Proc::Queue::size($parallel);
184    }
185    
186  while (my ($database, $db_config) = each %{ $config->{databases} }) {  while (my ($database, $db_config) = each %{ $config->{databases} }) {
187    
188          my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter);          my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter);
189          next if ($only_database && $database !~ m/$only_database/i);          next if ($only_database && $database !~ m/$only_database/i);
190    
191            if ($parallel) {
192                    my $f=fork;
193                    if(defined ($f) and $f==0) {
194                            $log->info("Created processes $$ for speedup");
195                    } else {
196                            next;
197                    }
198            }
199    
200            my $indexer;
201          if ($use_indexer) {          if ($use_indexer) {
202                  my $indexer_config = $config->{$use_indexer} || $log->logdie("can't find '$use_indexer' part in confguration");                  my $indexer_config = $config->{$use_indexer} || $log->logdie("can't find '$use_indexer' part in confguration");
203                  $indexer_config->{database} = $database;                  $indexer_config->{database} = $database;
204                  $indexer_config->{clean} = $clean;                  $indexer_config->{clean} = $clean;
205                  $indexer_config->{label} = $db_config->{name};                  $indexer_config->{label} = $db_config->{name};
206    
207                    # force clean if database has links
208                    $indexer_config->{clean} = 1 if ($db_config->{links});
209    
210                  if ($use_indexer eq 'hyperestraier') {                  if ($use_indexer eq 'hyperestraier') {
211    
212                          # open Hyper Estraier database                          # open Hyper Estraier database
# Line 178  while (my ($database, $db_config) = each Line 229  while (my ($database, $db_config) = each
229    
230    
231          #          #
232            # store Hyper Estraier links to other databases
233            #
234            if (ref($db_config->{links}) eq 'ARRAY' && $use_indexer) {
235                    foreach my $link (@{ $db_config->{links} }) {
236                            if ($use_indexer eq 'hyperestraier') {
237                                    if ($merge) {
238                                            print $estcmd_fh 'sudo -u www-data estcmd merge ' . $database . ' ' . $link->{to},$/;
239                                    } else {
240                                            $log->info("saving link $database -> $link->{to} [$link->{credit}]");
241                                            push @links, sub {
242                                                    $log->info("adding link $database -> $link->{to} [$link->{credit}]");
243                                                    $indexer->add_link(
244                                                            from => $database,
245                                                            to => $link->{to},
246                                                            credit => $link->{credit},
247                                                    );
248                                            };
249                                    }
250                            } else {
251                                    $log->warn("NOT IMPLEMENTED WITH $use_indexer: adding link $database -> $link->{to} [$link->{credit}]");
252                            }
253                    }
254            }
255            next if ($only_links);
256    
257    
258            #
259          # now WebPAC::Store          # now WebPAC::Store
260          #          #
261          my $abs_path = abs_path($0);          my $abs_path = abs_path($0);
# Line 247  while (my ($database, $db_config) = each Line 325  while (my ($database, $db_config) = each
325                          },                          },
326                          recode => $input->{recode},                          recode => $input->{recode},
327                          stats => $stats,                          stats => $stats,
328                            modify_records => $input->{modify_records},
329                  );                  );
330                  $log->logdie("can't create input using $input_module") unless ($input);                  $log->logdie("can't create input using $input_module") unless ($input);
331    
# Line 371  while (my ($database, $db_config) = each Line 450  while (my ($database, $db_config) = each
450                  )                  )
451          );          );
452    
453          #  
454          # add Hyper Estraier links to other databases          # end forked process
455          #          if ($parallel) {
456          if (ref($db_config->{links}) eq 'ARRAY' && $use_indexer) {                  $log->info("parallel process $$ finished");
457                  foreach my $link (@{ $db_config->{links} }) {                  exit(0);
                         if ($use_indexer eq 'hyperestraier') {  
                                 $log->info("saving link $database -> $link->{to} [$link->{credit}]");  
                                 push @links, {  
                                         from => $database,  
                                         to => $link->{to},  
                                         credit => $link->{credit},  
                                 };  
                         } else {  
                                 $log->warn("NOT IMPLEMENTED WITH $use_indexer: adding link $database -> $link->{to} [$link->{credit}]");  
                         }  
                 }  
458          }          }
459    
460  }  }
461    
462  foreach my $link (@links) {  if ($parallel) {
463          $log->info("adding link $link->{from} -> $link->{to} [$link->{credit}]");          # wait all children to finish
464          $indexer->add_link( %{ $link } );          sleep(1) while wait != -1;
465            $log->info("all parallel processes finished");
466    }
467    
468    #
469    # handle links or merge after indexing
470    #
471    
472    if ($merge) {
473            print $estcmd_fh 'sudo /etc/init.d/hyperestraier start',$/;
474            close($estcmd_fh);
475            chmod 0700, $estcmd_path || $log->warn("can't chmod 0700 $estcmd_path: $!");
476            system $estcmd_path;
477    } else {
478            foreach my $link (@links) {
479                    $log->logdie("coderef in link ", Dumper($link), " is ", ref($link), " and not CODE") unless (ref($link) eq 'CODE');
480                    $link->();
481            }
482  }  }

Legend:
Removed from v.595  
changed lines
  Added in v.608

  ViewVC Help
Powered by ViewVC 1.1.26