Changeset 40178
- Timestamp:
- Oct 20, 2017, 4:14:55 PM (9 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/rawcheck_mddb.pl (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/rawcheck_mddb.pl
r40166 r40178 208 208 my $class_id = $imfile->{class_id}; 209 209 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 210 216 # This hash contains all the information about the instances, indexed by the full filename of the instance. 211 217 my %unified_list = (); 218 my %orphans = (); 212 219 213 220 $timer = time(); … … 223 230 for (my $i = 0; $i <= $#files; $i++) { 224 231 my $f = $files[$i]; 232 $f =~ s%//%/%g; 225 233 my ($instance_exists,$instance_host,$instance_volume,$instance_site); 226 234 ($instance_host,$instance_volume) = parse_volume($files[$i]); … … 239 247 240 248 # Get md database results for this exp_id/class_id 241 242 249 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}'"; 243 250 my $md_instances = $mddb->selectall_arrayref( $md_query ); … … 248 255 foreach my $r (@{ $md_instances }) { 249 256 my ($file_id,$ins_id,$vol_name,$site_name,$f,$disk_sum,$is_valid) = @{ $r }; 250 257 $f =~ s%//%/%g; 251 258 unless (exists($unified_list{$f})) { 252 259 if (-e $f) { … … 304 311 # Check that evrything is consistent. 305 312 my $good_copies = 0; 306 my $all_copies = length(keys(%unified_list));313 my $all_copies = scalar(keys(%unified_list)); 307 314 my $a_good_copy = ''; 308 315 … … 315 322 $unified_list{$f}{good_instance} = 0; 316 323 print "$f "; 317 324 325 # Identify orphans, and push their handling until later. 318 326 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; 321 332 } 322 333 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. 323 337 unless (exists($unified_list{$f}{md_vol})) { 324 338 # 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 } 325 343 my $tmpmd5 = local_md5sum($f); 326 344 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; 327 351 328 352 if ($tmpmd5 ne $md5sum) { 329 353 # Insert even if we fail so we can try fixing next time. 330 354 # 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 } 340 361 } 341 362 … … 349 370 } 350 371 if ($tmpmd5 ne $md5sum) { 351 die"Revalidated md5sum does not match!";372 warn "Revalidated md5sum does not match!"; 352 373 } 353 374 } 354 375 355 376 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 359 379 if ($unified_list{$f}{exists} != 1) { 360 380 warn "Instance does not exist $exp_id $class_id $f\n"; 361 381 next; 362 382 } 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 } 363 386 if ($unified_list{$f}{is_valid} != 1) { 364 387 warn "Instance is not valid $exp_id $class_id $f\n"; … … 369 392 die "Inconsistent md5sum values $exp_id $class_id $f $md5sum $unified_list{$f}{disk_sum}\n"; 370 393 } 371 372 394 373 395 # If none of that stopped us, then this instance is probably fine. … … 383 405 384 406 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 } 386 420 } 387 421 … … 390 424 391 425 # Attempt to repair any bad instance. 426 print "COUNT CHECK $good_copies $all_copies\n"; 392 427 if ($good_copies != $all_copies) { 393 428 foreach my $f (keys(%unified_list)) { … … 497 532 } 498 533 } 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 499 542 } # End culling 500 543
Note:
See TracChangeset
for help on using the changeset viewer.
