Changeset 39956
- Timestamp:
- Jan 24, 2017, 6:09:25 PM (9 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/permcheck.pl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/permcheck.pl
r39955 r39956 344 344 foreach my $key (@keys) { 345 345 # Testing code. 346 print "$key\n";347 next;348 }349 350 ## neb-stat level handling351 #my $stat = $neb->stat($key);352 #die "nebulous key: $key not found" unless $stat;353 #my $instances;354 #my $md5sum = '';346 # print "$key\n"; 347 # next; 348 # } 349 350 # neb-stat level handling 351 my $stat = $neb->stat($key); 352 die "nebulous key: $key not found" unless $stat; 353 my $instances; 354 my $md5sum = ''; 355 355 356 356 # # This needs to be in an eval, because although we expect things to exist, they 357 357 # # may not. This is a fatal error in rawcheck, but need not be here. 358 # eval { 359 # $instances = $neb->find_instances($key, 'any'); 360 # }; 361 # unless (defined($instances)) { print "## skipping due to zero instances\n"; next; } 362 # die "no instances found" unless $instances; 363 364 # my $Ngood; 365 # my %good_instances = (); 366 # my %bad_instances = (); 367 368 # my @files = map {URI->new($_)->file if $_} @$instances; 369 # my @validation = (); 370 371 # for (my $i = 0; $i <= $#files; $i++) { 372 # my ($instance_exists,$instance_md5sum,$instance_host,$instance_volume,$instance_site, $is_good); 373 # ($instance_host,$instance_volume) = parse_volume($files[$i]); 374 # $instance_site = $volume_map{$instance_volume}; 375 # $is_good = 0; 376 377 # if (-e $files[$i]) { 378 # $instance_exists = 1; 379 # $existing_copies++; 380 # $instance_md5sum = local_md5sum($files[$i]); 381 382 # # This is bad, but I don't know what the right solution is. We don't have 383 # # the md5sum a priori. I think this is also the only major change needed 384 # # from rawcheck.pl 385 # if (($md5sum eq '')&&($instance_md5sum ne 'd41d8cd98f00b204e9800998ecf8427e')) { 386 # $md5sum = $instance_md5sum; 387 # } 388 389 # if ($instance_md5sum eq $md5sum) { 390 # push @{ $good_instance{$instance_site} }, $i; 391 # $is_good = 1; 392 # $Ngood++; 393 # } 394 # else { 395 # push @{ $bad_instances{$instance_site} }, $i; 396 # } 397 # } 398 # else { 399 # $instance_exists = 0; 400 # $instance_md5sum = 'NON-EXISTANT'; 401 # push @{ $bad_instances{$instance_site} }, $i; 402 # } 358 eval { 359 $instances = $neb->find_instances($key, 'any'); 360 }; 361 unless (defined($instances)) { print "## skipping due to zero instances\n"; next; } 362 die "no instances found" unless $instances; 363 364 my $existing_copies = 0; 365 my $Ngood = 0; 366 my $Nbad = 0; 367 my %good_instances = (); 368 my %bad_instances = (); 369 370 #unsafe 371 my $continue_checking_md5sums = 1; 372 my %good_instances_unchecked = (); 373 #end unsafe 374 375 my @files = map {URI->new($_)->file if $_} @$instances; 376 my @validation = (); 377 378 for (my $i = 0; $i <= $#files; $i++) { 379 my ($instance_exists,$instance_md5sum,$instance_host,$instance_volume,$instance_site, $is_good); 380 ($instance_host,$instance_volume) = parse_volume($files[$i]); 381 $instance_site = $volume_map{$instance_volume}; 382 $is_good = 0; 383 384 if (-e $files[$i]) { 385 $instance_exists = 1; 386 $existing_copies++; 387 if ($continue_checking_md5sums == 1) { #unsafe 388 $instance_md5sum = local_md5sum($files[$i]); 389 390 # This is bad, but I don't know what the right solution is. We don't have 391 # the md5sum a priori. I think this is also the only major change needed 392 # from rawcheck.pl 393 if (($md5sum eq '')&&($instance_md5sum ne 'd41d8cd98f00b204e9800998ecf8427e')) { 394 $md5sum = $instance_md5sum; 395 } 396 397 if ($instance_md5sum eq $md5sum) { 398 push @{ $good_instances{$instance_site} }, $i; 399 $is_good = 1; 400 $Ngood++; 401 } 402 else { 403 push @{ $bad_instances{$instance_site} }, $i; 404 $Nbad++; 405 } 406 } #unsafe 407 else { #unsafe 408 $instance_md5sum = 'CHECKING_STOPPED'; 409 push @{ $good_instances_unchecked{$instance_site} }, $i; 410 $is_good = 1; 411 $Ngood++; 412 } #end unsafe 413 } 414 else { 415 $instance_exists = 0; 416 $instance_md5sum = 'NON-EXISTANT'; 417 push @{ $bad_instances{$instance_site} }, $i; 418 } 403 419 404 # $validation[$i] = sprintf(" % 3d %d %32s %s %s %s\n", 405 # $instance_exists,$is_good,$instance_md5sum, 406 # $files[$i],$instance_host,$instance_volume); 407 # } 408 409 # $time = time() - $timer_start; 410 # # object_id ext_id epoch available existing total timer 411 # printf("%s %s %s %d %d %d %d\n",@$stat[0],@$stat[1],@$stat[4],@$stat[6],$existing_copies,@$stat[7],$timer); 412 # # instance_exists is_good instance_md5sum file instance_host instance_volume 413 # my $val_string = join('',@validation); 414 # print "$val_string"; 420 $validation[$i] = sprintf(" % 3d %d %32s %s %s %s\n", 421 $instance_exists,$is_good,$instance_md5sum, 422 $files[$i],$instance_host,$instance_volume); 423 424 #unsafe 425 # Remove this section when we decide to go back to actually checking everything 426 # to make sure we don't have any secret data corruption 427 if ($Ngood > 0) { 428 print "# Breaking from validation check, as a valid copy has been found.\n"; 429 $continue_checking_md5sums = 0; 430 } 431 #end unsafe 432 } 433 434 $timer = time() - $timer_start; 435 # object_id ext_id epoch available existing total timer 436 printf("%s %s %s %d %d %d %d\n",@$stat[0],@$stat[1],@$stat[4],@$stat[6],$existing_copies,@$stat[7],$timer); 437 # instance_exists is_good instance_md5sum file instance_host instance_volume 438 my $val_string = join('',@validation); 439 print "$val_string"; 415 440 416 441 # # Decide what to do 417 442 418 # if ($Ngood == 0) { 419 # # If we have no copies, we can't do anything. 420 # die "No valid instance of key: $key\n"; 421 # } 422 # ## We have more than zero bad copies. We may cull some of these in the future, but we should try to 423 # ## leave everything in the best state possible. 424 # printf(">> %d %d\n",$Ngood, $#files + 1); 425 # my $site_key; # Scope issues? 426 427 # if ($Ngood != $#files + 1) { 428 # my $good_copy; 429 # my $good_copy_index; 430 # foreach $site_key (keys %good_instances) { 431 # if ($#{ $good_instances{$site_key} } != -1) { 432 # $good_copy_index = $good_instances{$site_key}[0]; 433 # $good_copy = $files[$good_copy_index]; 434 # last; 435 # } 436 # } 437 # printf(">> GOOD: $good_copy\n"); 438 # foreach $site_key (keys %bad_instances) { 439 # foreach my $bad_copy_index (@{ $bad_instances{$site_key} }) { 440 # print "cp $good_copy $files[$bad_copy_index]\n"; 441 # if ($do_ops) { 442 # system("cp $good_copy $files[$bad_copy_index]"); 443 # } 444 # my $tmpmd5 = local_md5sum($files[$bad_copy_index]); 445 # if ($tmpmd5 ne $md5sum) { 446 # ## This isn't super critical, so we don't need to die here. 447 # warn "Post-repair md5sum does not match! $tmpmd5 != $md5sum: $files[$bad_copy_index]"; 448 # } 449 # else { 450 # ## success 451 # push @{ $good_instances{$site_key} }, $bad_copy_index; 452 # } 453 # } 454 # } 455 # ## We've done work here, so we can't do a cull this iteration. 456 # if ($do_cull == 1) { $do_cull = -1; } 457 # } 458 459 # ## We can now attempt to make replicated copies to the sites that require additional copies. 460 # foreach $site_key (keys %requirement_map) { 461 # my $have_instances = $#{ $good_instances{$site_key} } + 1; 462 # print "## $site_key $have_instances $requirement_map{$site_key}\n"; 463 # if ($#{ $good_instances{$site_key} } + 1 < $requirement_map{$site_key}) { 464 # my $rep_vol = get_random_site_volume($site_key); 465 # print "neb-replicate --volume $rep_vol $key\n"; 466 # if ($do_ops) { 467 # $neb->replicate($key,$rep_vol) or die "failed to replicate the single valid copy to the backup node"; 468 # if ($@) { die $@; } 469 470 # # Begin my best validation thought 471 # system("sync") == 0 or die "Couldn't sync?"; 472 # my $uris = $neb->find_instances($key,$rep_vol); 473 # @$uris = map {URI->new($_)->file if $_} @$uris; 474 # my $tmpmd5 = local_md5sum(${ $uris }[0]); 475 476 # my $validation_str = sprintf("% 3d %d %32s %s %s %s", 477 # -1,-1,$tmpmd5, 478 # ${ $uris }[0],"repl",$rep_vol); 479 # print 480 # join("\n" . " " x 4, $validation_str), "\n"; 481 482 # if ($tmpmd5 ne $md5sum) { 483 # die "Post-replication md5sum does not match! $tmpmd5 != $md5sum"; 484 # } 485 # # End my best validation thought. 486 # } 487 # ## We've done work here, so we can't do a cull this iteration. 488 # if ($do_cull == 1) { $do_cull = -1; } 489 # } 490 # } 443 if ($Ngood == 0) { 444 # If we have no copies, we can't do anything. 445 die "No valid instance of key: $key\n"; 446 } 447 ## We have more than zero bad copies. We may cull some of these in the future, but we should try to 448 ## leave everything in the best state possible. 449 printf(">> %d %d\n",$Ngood, $#files + 1); 450 if ($Nbad > 0) { 451 my $good_copy; 452 my $good_copy_index; 453 foreach my $site_key (keys %good_instances) { 454 if ($#{ $good_instances{$site_key} } != -1) { 455 $good_copy_index = $good_instances{$site_key}[0]; 456 $good_copy = $files[$good_copy_index]; 457 last; 458 } 459 } 460 printf(">> GOOD: $good_copy\n"); 461 foreach my $site_key (keys %bad_instances) { 462 foreach my $bad_copy_index (@{ $bad_instances{$site_key} }) { 463 print "cp $good_copy $files[$bad_copy_index]\n"; 464 if ($do_ops) { 465 system("cp $good_copy $files[$bad_copy_index]"); 466 } 467 my $tmpmd5 = local_md5sum($files[$bad_copy_index]); 468 if ($tmpmd5 ne $md5sum) { 469 ## This isn't super critical, so we don't need to die here. 470 warn "Post-repair md5sum does not match! $tmpmd5 != $md5sum: $files[$bad_copy_index]"; 471 } 472 else { 473 ## success 474 push @{ $good_instances{$site_key} }, $bad_copy_index; 475 } 476 } 477 } 478 ## We've done work here, so we can't do a cull this iteration. 479 if ($do_cull == 1) { $do_cull = -1; } 480 } 481 482 #unsafe 483 foreach my $site_key (keys %good_instances_unchecked) { 484 push @{ $good_instances{$site_key} }, @{ $good_instances_unchecked{$site_key} }; 485 } 486 #end unsafe 487 488 ## We can now attempt to make replicated copies to the sites that require additional copies. 489 foreach my $site_key (keys %requirement_map) { 490 my $have_instances = $#{ $good_instances{$site_key} } + 1; 491 print "## $site_key $have_instances $requirement_map{$site_key}\n"; 492 if ($#{ $good_instances{$site_key} } + 1 < $requirement_map{$site_key}) { 493 my $rep_vol = get_random_site_volume($site_key); 494 print "neb-replicate --volume $rep_vol $key\n"; 495 if ($do_ops) { 496 $neb->replicate($key,$rep_vol) or die "failed to replicate the single valid copy to the backup node"; 497 if ($@) { die $@; } 498 499 # Begin my best validation thought 500 system("sync") == 0 or die "Couldn't sync?"; 501 my $uris = $neb->find_instances($key,$rep_vol); 502 @$uris = map {URI->new($_)->file if $_} @$uris; 503 my $tmpmd5 = local_md5sum(${ $uris }[0]); 504 505 my $validation_str = sprintf("% 3d %d %32s %s %s %s", 506 -1,-1,$tmpmd5, 507 ${ $uris }[0],"repl",$rep_vol); 508 print 509 join("\n" . " " x 4, $validation_str), "\n"; 510 511 if ($tmpmd5 ne $md5sum) { 512 die "Post-replication md5sum does not match! $tmpmd5 != $md5sum"; 513 } 514 # End my best validation thought. 515 } 516 ## We've done work here, so we can't do a cull this iteration. 517 if ($do_cull == 1) { $do_cull = -1; } 518 } 519 } 520 521 ## Do culls if that's what we were going to do. 522 if ($do_cull == -1) { 523 die "Cull option passed, but files were modified in the scan/repair/replicate phase. Not running cull!\n"; 524 } 525 elsif ($do_cull == 1) { 526 ## At this point, we should have no files in the bad_instances lists, because we've repaired them. 527 foreach my $site_key (keys %good_instances) { 528 if ($#{ $good_instances{$site_key} } + 1 > $requirement_map{$site_key}) { 529 for ($i = $requirement_map{$site_key}; $i <= $#{ $good_instances{$site_key} }; $i++) { 530 my $cull_index = ${ $good_instances{$site_key} }[$i]; 531 my ($instance_host,$instance_volume) = parse_volume($files[$cull_index]); 532 print "neb-cull --volume $instance_volume $key\n"; 533 if ($do_ops) { 534 # The tilde here is to force hard volumes. Don't touch it. 535 # Also: the 2 is a "minimum number of copies" restriction. Let's not be crazy here. 536 $neb->cull($key,"~${instance_volume}",2) or die "failed to cull a superfluous instance"; 537 if ($@) { die "$@"; } 538 } 539 } # End loop over extra instances 540 } # End check for sites with extra instances 541 } # End loop over sites. 542 } # End cull 543 544 } ## End loop over keys. 545 } ## Endd loop over stage components. 491 546 492 # ## Do culls if that's what we were going to do.493 # if ($do_cull == -1) {494 # die "Cull option passed, but files were modified in the scan/repair/replicate phase. Not running cull!\n";495 # }496 # elsif ($do_cull == 1) {497 # ## At this point, we should have no files in the bad_instances lists, because we've repaired them.498 # foreach my $site_key (keys %good_instances) {499 # if ($#{ $good_instances{$site_key} } + 1 > $requirement_map{$site_key}) {500 # for ($i = $requirement_map{$site_key}; $i <= $#{ $good_instances{$site_key} }; $i++) {501 # my $cull_index = ${ $good_instances{$site_key} }[$i];502 # my ($instance_host,$instance_volume) = parse_volume($files[$cull_index]);503 # print "neb-cull --volume $instance_volume $key\n";504 # if ($do_ops) {505 # # The tilde here is to force hard volumes. Don't touch it.506 # # Also: the 2 is a "minimum number of copies" restriction. Let's not be crazy here.507 # $neb->cull($key,"~${instance_volume}",2) or die "failed to cull a superfluous instance";508 # if ($@) { die "$@"; }509 # }510 # } # End loop over extra instances511 # } # End check for sites with extra instances512 # } # End loop over sites.513 # } # End cull514 515 } ## End loop over imfiles.516 517 547 518 548 sub local_md5sum { … … 522 552 $host =~ s/\.\d//; 523 553 # print "$filename $host $volume\n"; 524 my $response = `ssh $host md5sum$filename`;554 my $response = `ssh $host remote_md5sum.pl $filename`; 525 555 chomp($response); 526 556 my ($sum, undef) = split /\s+/, $response;
Note:
See TracChangeset
for help on using the changeset viewer.
