IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40178


Ignore:
Timestamp:
Oct 20, 2017, 4:14:55 PM (9 years ago)
Author:
watersc1
Message:

Updated shuffle code that fixes more cases including orphaned disk files (with no neb entry) and bad copies (exists but has wrong md5sum).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/rawcheck_mddb.pl

    r40166 r40178  
    208208        my $class_id   = $imfile->{class_id};
    209209
     210        unless(defined($key))        { die "No database uri: $exp_id"; }
     211        unless(defined($data_state)) { $data_state = 'no_data_state'; }
     212        unless(defined($md5sum))     { die "No database md5sum: $exp_id"; }
     213        unless(defined($hostname))   { $hostname = 'ipp004'; }
     214        unless(defined($class_id))   { die "No database class_id: $class_id"; }
     215
    210216        # This hash contains all the information about the instances, indexed by the full filename of the instance.
    211217        my %unified_list = ();
     218        my %orphans      = ();
    212219
    213220        $timer = time();
     
    223230        for (my $i = 0; $i <= $#files; $i++) {
    224231            my $f = $files[$i];
     232            $f =~ s%//%/%g;
    225233            my ($instance_exists,$instance_host,$instance_volume,$instance_site);
    226234            ($instance_host,$instance_volume) = parse_volume($files[$i]);   
     
    239247
    240248        # Get md database results for this exp_id/class_id
    241 
    242249        my $md_query = "select file_id,ins_id,mvol_name,site_name,file,disk_sum,(STRCMP(md5sum,disk_sum) = 0) AS is_valid FROM obj JOIN ins USING(file_id) JOIN vol USING(mvol_id) WHERE exp_id = $exp_id AND class_id = '${class_id}'";
    243250        my $md_instances = $mddb->selectall_arrayref( $md_query );
     
    248255        foreach my $r (@{ $md_instances }) {
    249256            my ($file_id,$ins_id,$vol_name,$site_name,$f,$disk_sum,$is_valid) = @{ $r };
    250 
     257            $f =~ s%//%/%g;
    251258            unless (exists($unified_list{$f})) {
    252259                if (-e $f) {
     
    304311        # Check that evrything is consistent.
    305312        my $good_copies = 0;
    306         my $all_copies = length(keys(%unified_list));
     313        my $all_copies = scalar(keys(%unified_list));
    307314        my $a_good_copy = '';
    308315
     
    315322            $unified_list{$f}{good_instance} = 0;
    316323            print "$f  ";
    317 
     324           
     325            # Identify orphans, and push their handling until later.
    318326            unless (exists($unified_list{$f}{neb_host})) {
    319                 die "No neb entry for $unified_list{$f}{md_ins_id} $exp_id $class_id $f \n";
    320 #               mddb_delete_instance($mddb,$unified_list{$f}{md_ins_id});
     327                # Handle this.
     328                $orphans{$f} = $unified_list{$f};
     329                delete($unified_list{$f});
     330                warn "No neb entry for $orphans{$f}{md_ins_id} $exp_id $class_id $f \n";
     331                next;
    321332            }
    322333            print "$unified_list{$f}{neb_host} $unified_list{$f}{neb_vol} $unified_list{$f}{neb_site} $unified_list{$f}{exists}  ";
     334
     335
     336            # Create an entry in the mddb database if that doesn't already exist.
    323337            unless (exists($unified_list{$f}{md_vol})) {
    324338                # Insert a new row in the mddb ins table for this instance. 
     339                if ($unified_list{$f}{exists} != 1) {
     340                    # Ensure that the file exists, so an md5sum can be performed.
     341                    system("touch $f");
     342                }
    325343                my $tmpmd5 = local_md5sum($f);
    326344                my ($ins_id, $site_name) = mddb_insert_instance($mddb,$md_file_id,$f, $unified_list{$f}{neb_vol}, $tmpmd5);
     345
     346                $unified_list{$f}{md_vol}     = $unified_list{$f}{neb_vol};
     347                $unified_list{$f}{md_site}    = $site_name;
     348                $unified_list{$f}{disk_sum}   = $tmpmd5;
     349                $unified_list{$f}{md_file_id} = $md_file_id;
     350                $unified_list{$f}{md_ins_id}  = $ins_id;
    327351
    328352                if ($tmpmd5 ne $md5sum) {
    329353                    # Insert even if we fail so we can try fixing next time.
    330354                    # This may cause a problem if the first instance we checked has a bad md5sum.
    331                     die "Post-replication md5sum does not match! $tmpmd5 != $md5sum";
    332                 }
    333 
    334                 $unified_list{$f}{md_vol}     = $unified_list{$f}{neb_vol};
    335                 $unified_list{$f}{md_site}    = $site_name;
    336                 $unified_list{$f}{disk_sum}   = $tmpmd5;
    337                 $unified_list{$f}{is_valid}   = 1;
    338                 $unified_list{$f}{md_file_id} = $md_file_id;
    339                 $unified_list{$f}{md_ins_id}  = $ins_id;
     355                    warn "Post-replication md5sum does not match! $tmpmd5 != $md5sum";
     356                    $unified_list{$f}{is_valid}   = 0;
     357                }
     358                else {
     359                    $unified_list{$f}{is_valid}   = 1;
     360                }
    340361            }
    341362
     
    349370                }
    350371                if ($tmpmd5 ne $md5sum) {
    351                     die "Revalidated md5sum does not match!";
     372                    warn "Revalidated md5sum does not match!";
    352373                }
    353374            }
    354375
    355376            print "$unified_list{$f}{md_file_id} $unified_list{$f}{md_ins_id} $unified_list{$f}{md_vol} $unified_list{$f}{md_site} $unified_list{$f}{disk_sum} $unified_list{$f}{is_valid}  ";
    356             if ($unified_list{$f}{neb_vol} ne $unified_list{$f}{md_vol}) {
    357                 die "Inconsistent volumes for $exp_id $class_id $f $unified_list{$f}{neb_vol} $unified_list{$f}{md_vol}\n";
    358             }
     377
     378
    359379            if ($unified_list{$f}{exists} != 1) {
    360380                warn "Instance does not exist $exp_id $class_id $f\n";
    361381                next;
    362382            }
     383            if ($unified_list{$f}{neb_vol} ne $unified_list{$f}{md_vol}) {
     384                die "Inconsistent volumes for $exp_id $class_id $f $unified_list{$f}{neb_vol} $unified_list{$f}{md_vol}\n";
     385            }
    363386            if ($unified_list{$f}{is_valid} != 1) {
    364387                warn "Instance is not valid $exp_id $class_id $f\n";
     
    369392                die "Inconsistent md5sum values $exp_id $class_id $f $md5sum $unified_list{$f}{disk_sum}\n";
    370393            }
    371 
    372394           
    373395            # If none of that stopped us, then this instance is probably fine.
     
    383405
    384406        if ($good_copies == 0) {
    385             die "No good copies available for $exp_id $class_id\n";
     407            my $orphan_copy = '';
     408            foreach my $orph (keys (%orphans)) {
     409                if ($orphans{$orph}{is_valid} == 1) {
     410                    $orphan_copy = $orph;
     411                }
     412            }
     413
     414            if ($orphan_copy eq '') {
     415                die "No good copies available for $exp_id $class_id\n";
     416            }
     417            else {
     418                die "No good copies available for $exp_id $class_id (but $orphan_copy may exist)\n";
     419            }
    386420        }
    387421
     
    390424
    391425        # Attempt to repair any bad instance.
     426        print "COUNT CHECK $good_copies $all_copies\n";
    392427        if ($good_copies != $all_copies) {
    393428            foreach my $f (keys(%unified_list)) {
     
    497532                }
    498533            }
     534
     535            # If we're here, then we've sucessfully sorted out this instance.
     536            foreach my $f (keys %orphans) {
     537                print "ORPHAN $f $orphans{$f}{md_ins_id}\n";
     538                mddb_delete_instance($mddb,$orphans{$f}{md_ins_id});
     539#               unlink($f) or warn "Could not unlink $f: $!";
     540            }
     541           
    499542        } # End culling
    500543
Note: See TracChangeset for help on using the changeset viewer.