Changeset 333 for server/trunk/web/bin


Ignore:
Timestamp:
01/23/11 23:34:43 (13 years ago)
Author:
nanardon
Message:
  • massive rework of the base updater
File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/trunk/web/bin/sophie_scan

    r332 r333  
    66use POSIX ":sys_wait_h"; 
    77use Getopt::Long; 
     8use Sophie::Scan; 
    89 
    910$ENV{LC_ALL} = 'C'; 
    10 require Sophie::Base; 
    11 require Sophie::Base::RpmsPath; 
     11require Sophie::Scan::RpmsPath; 
    1212 
    1313GetOptions( 
     
    2828} 
    2929 
     30my $update = 1; 
    3031alarm($updated_inotify); 
    3132while (1) { 
    3233    local $SIG{ALRM} = sub { 
    3334        alarm($updated_inotify); 
     35        $update = 1; 
    3436    }; 
    35     if (update_base(keys %modified_paths)) { 
    36         %modified_paths = (); 
     37    if ($update) { 
     38        if (update_base(keys %modified_paths)) { 
     39            %modified_paths = (); 
     40            $update = 0; 
     41        } 
    3742    } 
    3843    warn "$$ Inotify"; 
    3944    $inotify = inotify_path(); 
    40     $inotify->poll; 
     45    if ($inotify) { 
     46        $inotify->poll and $update = 1; 
     47    } else { 
     48        sleep(300); 
     49    } 
    4150} 
    4251 
     
    4453 
    4554    my $i = Linux::Inotify2->new; 
    46     my $sophie = Sophie::Base->connect; 
    4755     
    48     foreach ($sophie->resultset('Paths')->get_column('path')->all) { 
     56    my @paths = Sophie::Scan->new->list_paths; 
     57    if (!@paths) { 
     58        return; 
     59    } 
     60    foreach (@paths) { 
     61        -d $_ or next; 
    4962        $i->watch( 
    5063            $_, 
     
    7285    if (my $pid = fork()) { 
    7386    } else { 
    74  
    7587        alarm 0; 
     88        my $scan = Sophie::Scan->new; 
     89        $scan->update_meta_paths; 
    7690        my @pkey; 
    7791        { 
    78             my $sophie = Sophie::Base->connect or do { 
    79                 die "cannot read config file\n"; 
    80             }; 
    81             @pkey = $sophie->resultset('Paths')->search( 
    82                 path => [ @path ], 
    83             )->get_column('d_path_key')->all; 
    84             push(@pkey, $sophie->resultset('Paths')->search({ 
    85                 updated => [ undef,  
    86                     \[ " < now() - '24 hours'::interval"], 
    87                 ], 
    88             })->get_column('d_path_key')->all); 
    89             my %uniq = map { $_ => 1 } @pkey; 
    90             @pkey = keys %uniq; 
     92            @pkey = $scan->paths_to_keys(@path); 
     93             
     94            push(@pkey, $scan->list_unscanned_paths); 
    9195        } 
    9296 
    9397        exit(0) if (!@pkey); 
    9498 
     99        foreach my $pathkey (@pkey) { 
     100            my $time = time; 
     101            my @delta = Sophie::Scan::RpmsPath 
     102                ->new($pathkey, Sophie::Scan->new) 
     103                ->find_delta; 
     104            while (my @d = splice(@delta, 0, 25)) { 
     105                my $scan = Sophie::Scan->new; 
     106                my $path = Sophie::Scan::RpmsPath->new($pathkey, $scan); 
     107                $path->update_content(@d); 
     108                last if (time > $time + 15 * 60); 
     109            } 
    95110 
    96  
    97         my $NB_PAR = 1; 
    98         my @split; 
    99         my $div = @pkey / $NB_PAR; 
    100  
    101         for (my $i = 0; $i < $NB_PAR - 1; $i++) { 
    102             $split[$i] = [ splice(@pkey, 0, $div) ]; 
     111            Sophie::Scan::RpmsPath->new($pathkey, Sophie::Scan->new)->set_updated 
     112                if (!@delta); # update only if we finished 
    103113        } 
    104         $split[$NB_PAR -1] = [ @pkey ]; 
    105         foreach my $job (@split) { 
    106             @{$job || []} or next; 
    107  
    108             if (fork()) { 
    109             } else { 
    110  
    111                 foreach my $pathkey (@{ $job }) { 
    112                     my $time = time; 
    113                     my @delta = Sophie::Base::RpmsPath->new($pathkey, Sophie::Base->connect) 
    114                         ->find_delta; 
    115                     while (my @d = splice(@delta, 0, 25)) { 
    116                         my $path = Sophie::Base::RpmsPath->new($pathkey, Sophie::Base->connect); 
    117                         $path->update_content(@d); 
    118                         #$path->db->disconnect; 
    119                         # If it take too long time, next path 
    120                         last if (time > $time + 15 * 60); 
    121                     } 
    122                     Sophie::Base::RpmsPath->new($pathkey, Sophie::Base->connect)->set_updated 
    123                         if (!@delta); # update only if we finished 
    124                 } 
    125                 exit(0); 
    126             } 
    127         } 
    128         1 while(waitpid(-1, 0) <= 0); 
    129114        exit(0); 
    130115    } 
Note: See TracChangeset for help on using the changeset viewer.