IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 2, 2013, 5:05:35 PM (13 years ago)
Author:
watersc1
Message:

Fix possible error when there are no OTAs in a given scan range.

Add continue option that allows tiny nibbles to be used, but in an automatic fashion.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/neb_rawOTA_host_scan.pl

    r36313 r36337  
    2121    ) or die "Unable to connect to database $DBI::errstr\n";
    2222
    23 my ($host,$min_ins_id,$verbose,$limit);
     23my ($host,$min_ins_id,$verbose,$limit,$continue);
    2424$min_ins_id = 0;
    2525$verbose = 0;
    2626$limit = 10000;
     27$continue = 0;
    2728
    2829GetOptions(
     
    3132    'verbose|v'     => \$verbose,
    3233    'limit|l=s'     => \$limit,
     34    'continue|c'    => \$continue,
    3335    ) or pod2usage( 2 );
    3436pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
     
    6668
    6769# Get the files on this host
    68 
    69 my $ins_id_sth = "SELECT ins_id,so_id,uri FROM instance WHERE vol_id = ${vol_id} AND ins_id > $min_ins_id LIMIT $limit";
    70 my $r_ins      = $db->selectall_arrayref( $ins_id_sth );
    71 my $last_ins_id = 0;
    72 foreach $rr (@{ $r_ins }) {
    73     my ($ins_id,$so_id,$uri) = @{ $rr };
    74     if ($verbose) {
     70my $number = 0;
     71do {
     72    my $ins_id_sth = "SELECT ins_id,so_id,uri FROM instance WHERE vol_id = ${vol_id} AND ins_id > $min_ins_id LIMIT $limit";
     73    my $r_ins      = $db->selectall_arrayref( $ins_id_sth );
     74    my $last_ins_id = 0;
     75    $number = 0;
     76    foreach $rr (@{ $r_ins }) {
     77        my ($ins_id,$so_id,$uri) = @{ $rr };
     78        if ($verbose) {
    7579#       print ("  $ins_id $so_id $uri\n");
    76     }
    77     if ($uri !~ /ota...fits/) { next; }
    78     my $have_b_node = 0;
    79     my ($ext_id,$occ_id,$oth_id,$name,$value) = ('',0,0,'','');
    80     my $rr2;
    81 
    82     my $so_id_sth = "SELECT ext_id,so_id,vol_id,ins_id,name,value FROM storage_object JOIN instance USING(so_id) LEFT JOIN storage_object_xattr USING(so_id) WHERE so_id = ${so_id} AND ins_id != ${ins_id} AND (name IS NULL OR name = 'user.copies')";
    83 
    84     my $r_so      = $db->selectall_arrayref( $so_id_sth );
    85 
    86     foreach $rr2 (@{ $r_so }) {
    87         ($ext_id,$so_id,$occ_id,$oth_id,$name,$value) = @{ $rr2 };
     80        }
     81        $number++;
     82        $last_ins_id = $ins_id;
     83        if ($uri !~ /ota...fits/) { next; }
     84        my $have_b_node = 0;
     85        my ($ext_id,$occ_id,$oth_id,$name,$value) = ('',0,0,'','');
     86        my $rr2;
    8887       
    89         unless(defined($name)) {
    90             $name = 'UNDEF';
    91             $value = 1;
    92         }
    93 
    94         if ($name eq 'user.copies') {
    95             if ($value == 1) {
     88        my $so_id_sth = "SELECT ext_id,so_id,vol_id,ins_id,name,value FROM storage_object JOIN instance USING(so_id) LEFT JOIN storage_object_xattr USING(so_id) WHERE so_id = ${so_id} AND ins_id != ${ins_id} AND (name IS NULL OR name = 'user.copies')";
     89       
     90        my $r_so      = $db->selectall_arrayref( $so_id_sth );
     91       
     92        foreach $rr2 (@{ $r_so }) {
     93            ($ext_id,$so_id,$occ_id,$oth_id,$name,$value) = @{ $rr2 };
     94           
     95            unless(defined($name)) {
     96                $name = 'UNDEF';
     97                $value = 1;
     98            }
     99           
     100            if ($name eq 'user.copies') {
     101                if ($value == 1) {
     102                    $have_b_node = 1;
     103                }
     104            }
     105            else {
    96106                $have_b_node = 1;
    97107            }
     108           
     109            if (defined($b_nodes{$occ_id})) {
     110                $have_b_node = 1;
     111            }
     112            if ($verbose) {
     113                print("   $number $ext_id $so_id $occ_id $oth_id $have_b_node $name $value\n");
     114            }
     115           
     116            if ($have_b_node == 1) {
     117                last;
     118            }
    98119        }
    99         else {
    100             $have_b_node = 1;
     120        if ($oth_id) {
     121            if ($have_b_node != 1) {
     122                my $rep_host = int(rand() + 0.5) + 4;
     123                my $rep_part = int(rand(3));
     124                my $rep_vol  = "ippb0" . $rep_host . "." . $rep_part;
     125               
     126                print("neb-replicate --volume $rep_vol $ext_id\n");
     127                system("neb-replicate --volume $rep_vol $ext_id");
     128            }
    101129        }
    102 
    103         if (defined($b_nodes{$occ_id})) {
    104             $have_b_node = 1;
     130        $last_ins_id = $ins_id;
     131    }
     132    print "## LAST: $last_ins_id $number\n";
     133    print "## TRY:  neb_rawOTA_host_scan.pl --host $host --limit $limit --min $last_ins_id\n";
     134    if ($continue) {
     135        if ($verbose) {
     136            print("RESET $min_ins_id -> $last_ins_id $number\n");
    105137        }
    106         if ($verbose) {
    107             print("   $ext_id $so_id $occ_id $oth_id $have_b_node $name $value\n");
    108         }
    109 
    110         if ($have_b_node == 1) {
    111             last;
    112         }
     138        $min_ins_id = $last_ins_id;
    113139    }
    114     if ($oth_id) {
    115         if ($have_b_node != 1) {
    116             my $rep_host = int(rand() + 0.5) + 4;
    117             my $rep_part = int(rand(3));
    118             my $rep_vol  = "ippb0" . $rep_host . "." . $rep_part;
    119 
    120             print("neb-replicate --volume $rep_vol $ext_id\n");
    121             system("neb-replicate --volume $rep_vol $ext_id");
    122         }
    123     }
    124     $last_ins_id = $ins_id;
    125 }
    126 print "## LAST: $last_ins_id\n";
    127 print "## TRY:  neb_rawOTA_host_scan.pl --host $host --limit $limit --min $last_ins_id\n";
    128 
     140} while ($continue && $number != 0);
Note: See TracChangeset for help on using the changeset viewer.