IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 32382


Ignore:
Timestamp:
Sep 9, 2011, 1:20:04 PM (15 years ago)
Author:
watersc1
Message:

Code to shift first copies to newly targetted hosts.

Location:
tags/ipp-20110622
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • tags/ipp-20110622/Nebulous-Server/bin/neb-admin

    r31944 r32382  
    2929    $pending,
    3030    $balance,
     31    $retarget,
    3132    $balance_N_sources,
    3233    $balance_M_destinations,
     
    4950    'pendingreplicate|r'    => \$pending,
    5051    'pendingbalance|b'      => \$balance,
     52    'pendingtarget|t'       => \$retarget,
    5153    'balancesources|N=s'      => \$balance_N_sources,
    5254    'balancedestinations|M=s' => \$balance_M_destinations,
     
    6466pod2usage( -msg => "--limit is meaningless without --pendingreplicate",
    6567        -exitval => 2 )
    66     if defined $limit and not (defined $pending or defined $balance);
     68    if defined $limit and not (defined $pending or defined $balance or defined $retarget);
    6769pod2usage( -msg => "no operation specified", -exitval => 2 )
    68     unless defined $pending or defined $balance;
     70    unless defined $pending or defined $balance or defined $retarget;
    6971pod2usage( -msg => "--pendingbalance needs --balancesources and --balancedestinations options",
    7072           -exitval => 2)
     
    8183elsif (defined $balance) {
    8284    $pidfile = '/var/tmp/neb-admin.balance';
     85}
     86elsif (defined $retarget) {
     87    $pidfile = '/var/tmp/neb-admin.retarget';
    8388}
    8489else {
     
    107112} elsif ($balance) {
    108113    balance();
     114} elsif ($retarget) {
     115    retarget();
    109116} else {
    110117    die "THIS SHOULD NOT HAPPEN";
     
    524531}
    525532
     533sub retarget
     534{
     535    my %destination;
     536    %{ $destination{VOL} }  = ('ota01' => 7,       'ota02' => 8,       'ota03' => 3,       'ota04' => 3,       'ota05' => 4,       'ota06' => 4,
     537                               'ota10' => 50,      'ota11' => 50,      'ota12' => 6,       'ota13' => 6,       'ota14' => 7,       'ota15' => 8,       'ota16' => 15,      'ota17' => 15,
     538                               'ota20' => 16,      'ota21' => 18,      'ota22' => 18,      'ota23' => 17,      'ota24' => 9,       'ota25' => 9,       'ota26' => 10,      'ota27' => 11,
     539                               'ota30' => 12,      'ota31' => 52,      'ota32' => 14,      'ota33' => 14,      'ota34' => 19,      'ota35' => 16,      'ota36' => 20,      'ota37' => 12,
     540                               'ota40' => 32,      'ota41' => 11,      'ota42' => 10,      'ota43' => 17,      'ota44' => 49,      'ota45' => 23,      'ota46' => 24,      'ota47' => 25,
     541                               'ota50' => 26,      'ota51' => 27,      'ota52' => 28,      'ota53' => 29,      'ota54' => 30,      'ota55' => 31,      'ota56' => 51,      'ota57' => 33,
     542                               'ota60' => 34,      'ota61' => 35,      'ota62' => 36,      'ota63' => 37,      'ota64' => 38,      'ota65' => 39,      'ota66' => 41,      'ota67' => 42,
     543                               'ota71' => 43,      'ota72' => 44,      'ota73' => 45,      'ota74' => 46,      'ota75' => 47,      'ota76' => 53);
     544    %{ $destination{HOST} } = ('ota01' => 'ipp010','ota02' => 'ipp011','ota03' => 'ipp006','ota04' => 'ipp006','ota05' => 'ipp007','ota06' => 'ipp007',
     545                               'ota10' => 'ipp008','ota11' => 'ipp008','ota12' => 'ipp009','ota13' => 'ipp009','ota14' => 'ipp010','ota15' => 'ipp011','ota16' => 'ipp012','ota17' => 'ipp012',
     546                               'ota20' => 'ipp013','ota21' => 'ipp014','ota22' => 'ipp014','ota23' => 'ipp015','ota24' => 'ipp016','ota25' => 'ipp016','ota26' => 'ipp017','ota27' => 'ipp018',
     547                               'ota30' => 'ipp019','ota31' => 'ipp020','ota32' => 'ipp021','ota33' => 'ipp021','ota34' => 'ipp023','ota35' => 'ipp013','ota36' => 'ipp024','ota37' => 'ipp019',
     548                               'ota40' => 'ipp025','ota41' => 'ipp018','ota42' => 'ipp017','ota43' => 'ipp015','ota44' => 'ipp027','ota45' => 'ipp028','ota46' => 'ipp029','ota47' => 'ipp030',
     549                               'ota50' => 'ipp031','ota51' => 'ipp032','ota52' => 'ipp033','ota53' => 'ipp034','ota54' => 'ipp035','ota55' => 'ipp036','ota56' => 'ipp037','ota57' => 'ipp038',
     550                               'ota60' => 'ipp039','ota61' => 'ipp040','ota62' => 'ipp041','ota63' => 'ipp042','ota64' => 'ipp043','ota65' => 'ipp044','ota66' => 'ipp046','ota67' => 'ipp047',
     551                               'ota71' => 'ipp048','ota72' => 'ipp049','ota73' => 'ipp050','ota74' => 'ipp051','ota75' => 'ipp052','ota76' => 'ipp053');
     552    %{ $destination{NAME} } = ('ota01' => 'ipp010.0','ota02' => 'ipp011.0','ota03' => 'ipp006.0','ota04' => 'ipp006.0','ota05' => 'ipp007.0','ota06' => 'ipp007.0',
     553                               'ota10' => 'ipp008.0','ota11' => 'ipp008.0','ota12' => 'ipp009.0','ota13' => 'ipp009.0','ota14' => 'ipp010.0','ota15' => 'ipp011.0','ota16' => 'ipp012.0','ota17' => 'ipp012.0',
     554                               'ota20' => 'ipp013.0','ota21' => 'ipp014.0','ota22' => 'ipp014.0','ota23' => 'ipp015.0','ota24' => 'ipp016.0','ota25' => 'ipp016.0','ota26' => 'ipp017.0','ota27' => 'ipp018.0',
     555                               'ota30' => 'ipp019.0','ota31' => 'ipp020.0','ota32' => 'ipp021.0','ota33' => 'ipp021.0','ota34' => 'ipp023.0','ota35' => 'ipp013.0','ota36' => 'ipp024.0','ota37' => 'ipp019.0',
     556                               'ota40' => 'ipp025.0','ota41' => 'ipp018.0','ota42' => 'ipp017.0','ota43' => 'ipp015.0','ota44' => 'ipp027.0','ota45' => 'ipp028.0','ota46' => 'ipp029.0','ota47' => 'ipp030.0',
     557                               'ota50' => 'ipp031.0','ota51' => 'ipp032.0','ota52' => 'ipp033.0','ota53' => 'ipp034.0','ota54' => 'ipp035.0','ota55' => 'ipp036.0','ota56' => 'ipp037.0','ota57' => 'ipp038.0',
     558                               'ota60' => 'ipp039.0','ota61' => 'ipp040.0','ota62' => 'ipp041.0','ota63' => 'ipp042.0','ota64' => 'ipp043.0','ota65' => 'ipp044.0','ota66' => 'ipp046.0','ota67' => 'ipp047.0',
     559                               'ota71' => 'ipp048.0','ota72' => 'ipp049.0','ota73' => 'ipp050.0','ota74' => 'ipp051.0','ota75' => 'ipp052.0','ota76' => 'ipp053.0');
     560
     561    if (not defined $so_id_start) { $so_id_start = 0; }
     562    if (not defined $so_id_range) { $so_id_range = 100000; }
     563    my $so_id_end = $so_id_start + $so_id_range;
     564
     565    # XXX check if so_id_start is beyond MAX(so_id): if so, exit with exit status 10
     566    {
     567        my $query = $dbh->prepare("SELECT MAX(so_id) from storage_object");
     568        $query->execute;
     569        my $answer = $query->fetchrow_arrayref;
     570        my $max_so_id = $$answer[0];
     571        $query->finish;
     572
     573        if ($so_id_start > $max_so_id) {
     574            print STDERR "at end of so_id range, reset please\n";
     575            exit 10;
     576        }
     577    }
     578
     579    # Determine a list of first instances
     580    my $query = $dbh->prepare(
     581        "
     582SELECT S.so_id,ext_id,ins_id,uri,substr(uri,-10,5) AS class_id,vol_id,name AS vol_name,host AS vol_host FROM (
     583  select * FROM (
     584  select MAX(ins_id) AS MAXins_id, MIN(ins_id) AS MINins_id, so_id,ext_id,value AS user_copies FROM storage_object
     585    JOIN storage_object_xattr USING(so_id)
     586    RIGHT JOIN instance USING(so_id)
     587     WHERE name = 'user.copies'
     588     AND value >= 2
     589     AND ext_id LIKE '%ota%fits'
     590     AND so_id >= $so_id_start
     591     AND so_id <  $so_id_end
     592     GROUP BY so_id
     593  ) AS V
     594  WHERE MAXins_id != MINins_id
     595  ) AS S
     596  JOIN instance ON (S.MINins_id = instance.ins_id AND S.so_id = instance.so_id) JOIN volume USING(vol_id) WHERE volume.available = 1
     597  LIMIT $limit
     598  OFFSET $offset
     599");
     600    $query->execute();
     601
     602    my @rows;
     603    while (my $row = $query->fetchrow_hashref) {
     604        push @rows, $row;       
     605    }
     606    $query->finish;
     607
     608    print STDERR "No rows found\n" unless scalar @rows;
     609    exit unless scalar @rows;
     610   
     611    # compare number of responses to limit below
     612    my $Npending = @rows;
     613
     614    print "targetPending MULTI\n\n";
     615
     616    foreach my $obj (@rows) {
     617        if (defined $verbose) {
     618            require Data::Dumper;
     619            print Data::Dumper::Dumper($obj);
     620        }
     621       
     622        my $so_id = $obj->{so_id};
     623        my $key   = $obj->{ext_id};
     624
     625        my $ins_id = $obj->{ins_id};
     626        my $uri   = $obj->{uri};
     627        my $class_id = $obj->{class_id};
     628
     629        my $source_vol_id = $obj->{vol_id};
     630        my $source_name   = $obj->{vol_name};
     631        my $source_host   = $obj->{vol_host};
     632
     633
     634        my $destination_vol_id = $destination{VOL}{$class_id};
     635        my $destination_name   = $destination{NAME}{$class_id};
     636        my $destination_host   = $destination{HOST}{$class_id};
     637        my $destination_uri    = $uri;
     638        $destination_uri =~ s/$source_name/$destination_name/;
     639       
     640        my %md = (
     641            so_id         => $so_id,
     642            key           => $key,
     643            ins_id        => $ins_id,
     644            uri           => $uri,
     645            class_id      => $class_id,
     646           
     647            source_vol_id => $source_vol_id,
     648            source_name   => $source_name,
     649            source_host   => $source_host,
     650
     651            destination_vol_id => $destination_vol_id,
     652            destination_name   => $destination_name,
     653            destination_host   => $destination_host,
     654            destination_uri    => $destination_uri,
     655        );
     656        if ($source_vol_id != $destination_vol_id) {
     657            print_metadata("targetPending", \%md);
     658            print "\n";
     659        }
     660    }
     661
     662    # use a different exit status if we hit the limit (likely more files pending)
     663    print STDERR "Which exit: $Npending $limit\n";
     664    # This is a better way to do this. This should be even better-er.
     665    if ($Npending < $limit) {
     666        exit 0;
     667    }
     668    else {
     669        exit 1;
     670    }
     671}
     672
    526673sub removal
    527674{
  • tags/ipp-20110622/ippTasks/diskbalance.pro

    r31883 r32382  
    1515book init balanceControl
    1616
     17
     18book init targetPending
     19book init targetControl
     20
    1721macro balance.reset
    1822  book init balancePending
     
    4145end
    4246
     47macro target.reset
     48  book init targetPending
     49end
     50
     51macro target.status
     52  book listbook targetPending
     53end
     54
     55macro target.on
     56  task target.load
     57    active true
     58  end
     59  task target.run
     60    active true
     61  end
     62end
     63
     64macro target.off
     65  task target.load
     66    active false
     67  end
     68  task target.run
     69    active false
     70  end
     71end
     72 
    4373macro set.host.for.balance
    4474  if ($0 != 2)
     
    92122end
    93123
     124macro show.target.numbers
     125  book listpage targetControl control
     126  echo "target so_ids: $TARGET_SO_ID_START $TARGET_SO_ID_RANGE"
     127end
     128
     129macro show.targetPending
     130  book npages targetPending -var N
     131  echo "$N pages in book"
     132  book listbook targetPending
     133end
     134
    94135# the balance process interacts with only the single Nebulous server
    95136
     
    104145$BALANCE_LIMIT       = 500
    105146$BALANCE_OFFSET      = 0
    106 $BALANCE_TARGET      = "SOURCE"
     147$BALANCE_TARGET      = SOURCE
    107148# Select Nebulous objects which should be shuffled
    108149task           balance.load
     
    250291
    251292
    252 
    253    
    254 
     293# This value will need to be incremented periodically.  It looks like we grow by about 5e7 so_ids per month.
     294$TARGET_BIG_SO_ID   = 6e8
     295$TARGET_SO_ID_START = int($TARGET_BIG_SO_ID * rnd(0))
     296$TARGET_SO_ID_RANGE = 500000
     297$TARGET_LIMIT       = 500
     298$TARGET_OFFSET      = 0
     299$TARGET_TARGET      = "SOURCE"
     300# Select Nebulous objects which should be shuffled
     301task           target.load
     302  host         local
     303
     304  periods      -poll 60
     305  periods      -exec 60
     306  periods      -timeout 1500
     307  npending     1
     308
     309  # logs
     310  stdout NULL
     311  stderr $LOGSUBDIR/target.log
     312   
     313  task.exec
     314    book npages targetPending -var N
     315    if ($N > 2000)
     316      process_cleanup targetPending
     317      break
     318    end
     319
     320    command neb-admin --host $NEB_HOST --db $NEB_DB --user $NEB_USER --pass $NEB_PASS --pendingtarget --limit $TARGET_LIMIT --offset $TARGET_OFFSET --so_id_start $TARGET_SO_ID_START --so_id_range $TARGET_SO_ID_RANGE 
     321  end
     322
     323   # success : 0 -- we did not hit the limit, advance so_id counter
     324  task.exit 0
     325    # advance the so_id counter
     326    $TARGET_SO_ID_START = $TARGET_SO_ID_START + $TARGET_SO_ID_RANGE
     327    $TARGET_OFFSET = 0
     328    # convert 'stdout' to book format
     329    ipptool2book stdout targetPending -key key -uniq -setword pantaskState INIT
     330
     331    if ($VERBOSE > 2)
     332      book listbook targetPending
     333    end
     334
     335    # delete existing entries in the appropriate pantaskStates
     336    process_cleanup targetPending
     337  end
     338
     339  # success : 1 -- we DID hit the limit, do NOT advance so_id counter
     340  task.exit 1
     341    # convert 'stdout' to book format
     342    ipptool2book stdout targetPending -key key -uniq -setword pantaskState INIT
     343    $TARGET_OFFSET = $TARGET_OFFSET + $TARGET_LIMIT
     344    if ($VERBOSE > 2)
     345      book listbook targetPending
     346    end
     347
     348    # delete existing entries in the appropriate pantaskStates
     349    process_cleanup targetPending
     350  end
     351
     352  # out of so_id range, reset
     353  task.exit 10
     354    # advance the so_id counter
     355    $TARGET_SO_ID_START = 0
     356  end
     357
     358  # locked list
     359  task.exit    default
     360    showcommand failure
     361  end
     362
     363  task.exit    crash
     364    showcommand crash
     365  end
     366
     367  # operation times out?
     368  task.exit    timeout
     369    showcommand timeout
     370  end
     371end
     372
     373# task to execute shuffles
     374task            target.run
     375  periods       -poll 0.5
     376  periods       -exec 5
     377  periods       -timeout 5
     378  npending      200
     379
     380  task.exec
     381    # if we are unable to run the 'exec', use a long retry time
     382    periods -exec 5
     383
     384    book npages targetPending -var N
     385    if ($NETWORK == 0) break
     386    if ($N == 0) break
     387
     388    # look for new objects in targetPending
     389    book getpage targetPending 0 -var pageName -key pantaskState INIT
     390    if ("$pageName" == "NULL") break
     391
     392    book setword targetPending $pageName pantaskState RUN
     393
     394    book getword targetPending $pageName key              -var KEY
     395    book getword targetPending $pageName source_name      -var SOURCE
     396    book getword targetPending $pageName source_host      -var SOURCE_HOST
     397    book getword targetPending $pageName destination_name -var DESTINATION
     398    book getword targetPending $pageName destination_host -var DEST_HOST
     399    book getword targetPending $pageName destination_uri  -var DEST_URI
     400    book getword targetPending $pageName ins_id           -var INS_ID
     401
     402    # Fix this with multihost restriction when possible.
     403    if ("$TARGET_TARGET" == "DESTINATION")
     404       set.host.for.target $DEST_HOST
     405    else
     406       set.host.for.target $SOURCE_HOST
     407    end
     408   
     409
     410    stdout NULL
     411    stderr $LOGSUBDIR/target.log
     412
     413    $run = neb-insedit --key $KEY --ins_id $INS_ID --uri $DEST_URI --volume $DESTINATION
     414    $run = $run --db $NEB_DB --host $NEB_HOST --user $NEB_USER --pass $NEB_PASS
     415    $run = $run --neb_host http://ippc04/nebulous
     416   
     417    # save the pageName for future reference below
     418    options $pageName
     419
     420    # create the command line
     421    if ($VERBOSE > 1)
     422        echo command $run
     423    end
     424    periods -exec 0.05
     425    command $run
     426  end
     427
     428  # default exit status
     429  task.exit     default
     430    process_exit targetPending $options:0 $JOB_STATUS
     431  end
     432
     433  task.exit    crash
     434    showcommand crash
     435    book setword targetPending $options:0 pantaskState CRASH
     436  end
     437
     438  # operation timed out?
     439  task.exit    timeout
     440    showcommand timeout
     441    book setword targetPending $options:0 pantaskState TIMEOUT
     442  end
     443end
     444
     445
     446
     447   
     448
Note: See TracChangeset for help on using the changeset viewer.