IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31889


Ignore:
Timestamp:
Jul 15, 2011, 6:01:52 PM (15 years ago)
Author:
watersc1
Message:

Updated shuffle SQL. This appears to catch instances that were ignored previously. The values are also better distributed on source hosts, so this should shuffle more efficiently.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/bin/neb-admin

    r31829 r31889  
    299299        "
    300300SELECT * FROM (
    301  -- U Randomize the list of all possible source/destination matches,then group by so_id to select one at random
    302  SELECT T.*,volume.cab_id AS source_cab_id,volume.name AS source_name,volume.host AS source_host,
    303         destination.vol_id AS destination_vol_id,destination.cab_id AS destination_cab_id,
    304         destination.name AS destination_name,destination.host AS destination_host FROM (
    305   -- V Ensure that the copy we found on the source volume is the second copy instance
    306   SELECT K.vol_id AS here,K.ins_id,K.so_id,ext_id,value AS user_copies,MAXins_id,instance.vol_id AS there FROM (
    307    -- W Determine what the second copy instance is
    308    SELECT V.*,MAX(instance.ins_id) AS MAXins_id FROM (
    309     -- X Determine which hosts have instances of an object
    310     SELECT vol_id,ins_id,so_id,ext_id,value FROM
    311     storage_object JOIN storage_object_xattr USING(so_id) JOIN instance USING(so_id)
    312     WHERE vol_id IN (
    313      -- Y Extra select for debugging purposes
    314      SELECT vol_id FROM (
    315       -- Z Ran hosts by R (need to be a source) and return top N
    316       SELECT mountedvol.vol_id,mountedvol.name,mountedvol.available,mountedvol.allocate,total,used,
    317              (used / total) AS D,total * ((used / total) - $average ) AS R,  -- average
    318              (used / total) - $average AS delta,
    319              cab_id FROM
    320       mountedvol JOIN volume USING(vol_id)
    321       WHERE mountedvol.available = 1
    322       ORDER BY delta DESC LIMIT $balance_N_sources                                            -- N
    323       ) AS ranked_sources
    324       -- Z End
    325      )
    326      -- Y End
    327     AND name = 'user.copies' AND value >= 2
    328   AND ext_id LIKE '%ota%fits'       -- This line is the emergency speedup option
    329     AND so_id >= $so_id_start                                  -- so_id_start
    330     AND so_id <  $so_id_end                                    -- so_id_end
    331    ) AS V -- volumes that host a copy
    332    -- X End
    333   LEFT OUTER JOIN instance USING(so_id) GROUP BY so_id
    334   ) AS K -- copies that are the second copy
    335   -- W End
    336  JOIN instance ON MAXins_id = instance.ins_id GROUP BY so_id
    337  ) AS T -- matched copies that I know the second copy is on my source volume
    338  -- V End
    339  JOIN volume on T.here = volume.vol_id RIGHT JOIN (
    340   -- Y2 Chose a random destination from the list
    341   SELECT vol_id,cab_id,name,host FROM (
    342    -- Z2 Reverse rank hosts by R and return top M
    343    SELECT mountedvol.vol_id,mountedvol.name,mountedvol.host,mountedvol.available,mountedvol.allocate,total,used,
    344           (used / total) AS D,total * ((used / total) - $average ) AS R,  -- average
    345           (used / total) - $average AS delta,
    346           cab_id FROM
    347    mountedvol JOIN volume USING(vol_id)
    348    WHERE mountedvol.available = 1 AND mountedvol.allocate = 1
    349    ORDER BY delta ASC LIMIT $balance_M_destinations                                               -- M
    350   ) AS ranked_destinations
    351   -- Z2 End
    352  ORDER BY RAND()
    353  ) AS destination
    354  -- Y2 End
    355  ON destination.cab_id != volume.cab_id
    356  WHERE here = there
    357  ORDER BY RAND()
     301#  -- U Randomize the list of all possible source/destination matches,then group by so_id to select one at random
     302  SELECT T.*,volume.cab_id AS source_cab_id, volume.name AS source_name, volume.host AS source_host,
     303         destination.vol_id AS destination_vol_id,destination.cab_id AS destination_cab_id,
     304         destination.name AS destination_name,destination.host AS destination_host FROM (
     305    -- V Select the volume that matches the instance with the largest ins_id
     306    SELECT S.*,vol_id FROM (
     307      -- Select objects that are in our so_id range, with two copies (and two requested copies)
     308      SELECT MAX(ins_id) AS MAXins_id,MIN(ins_id) AS MINins_id,so_id,ext_id,value AS user_copies FROM
     309       storage_object JOIN storage_object_xattr USING(so_id) RIGHT JOIN instance USING(so_id)
     310       WHERE name = 'user.copies' AND value >= 2
     311       AND ext_id LIKE '%ota%fits'                  -- This line is the emergency speedup option
     312       AND so_id >= $so_id_start                    -- so_id_start
     313       AND so_id <  $so_id_end                      -- so_id_end
     314       GROUP BY so_id
     315      ) AS S
     316      JOIN instance ON (S.MAXins_id = instance.ins_id)
     317      WHERE vol_id IN (
     318       -- Y Extra select for debugging purposes
     319       SELECT vol_id FROM (
     320        -- Z Ran hosts by R (need to be a source) and return top N
     321        SELECT mountedvol.vol_id,mountedvol.name,mountedvol.available,mountedvol.allocate,total,used,
     322               (used / total) AS D,total * ((used / total) - $average ) AS R,  -- average
     323               (used / total) - $average AS delta,
     324               cab_id FROM
     325        mountedvol JOIN volume USING(vol_id)
     326        WHERE mountedvol.available = 1
     327        ORDER BY delta DESC LIMIT $balance_N_sources                                            -- N
     328        ) AS ranked_sources
     329        -- Z End
     330       )
     331       -- Y End
     332       AND MAXins_id != MINins_id
     333     ) AS T
     334     -- V End
     335     JOIN volume on T.vol_id = volume.vol_id RIGHT JOIN (
     336       -- Y2 Chose a random destination from the list
     337       SELECT vol_id,cab_id,name,host FROM (
     338         -- Z2 Reverse rank hosts by R and return top M
     339         SELECT mountedvol.vol_id,mountedvol.name,mountedvol.host,mountedvol.available,mountedvol.allocate,total,used,
     340                (used / total) AS D,total * ((used / total) - $average ) AS R,  -- average
     341                (used / total) - $average AS delta,
     342                cab_id FROM
     343         mountedvol JOIN volume USING(vol_id)
     344         WHERE mountedvol.available = 1 AND mountedvol.allocate = 1
     345         ORDER BY delta ASC LIMIT $balance_M_destinations                                               -- M
     346       ) AS ranked_destinations
     347       -- Z2 End
     348     ORDER BY RAND()
     349     ) AS destination
     350     -- Y2 End
     351   ON destination.cab_id != volume.cab_id
     352   ORDER BY RAND()
    358353) AS results
     354WHERE so_id IS NOT NULL
    359355-- U End
    360356GROUP BY so_id
    361     LIMIT $limit                                               -- limit
    362     OFFSET $offset                                             -- offset
    363 
    364 "    );
     357  LIMIT $limit                                               -- limit
     358  OFFSET $offset                                             -- offset
     359
     360");
     361
     362#     my $query = $dbh->prepare(
     363#       "
     364# SELECT * FROM (
     365#  -- U Randomize the list of all possible source/destination matches,then group by so_id to select one at random
     366#  SELECT T.*,volume.cab_id AS source_cab_id,volume.name AS source_name,volume.host AS source_host,
     367#         destination.vol_id AS destination_vol_id,destination.cab_id AS destination_cab_id,
     368#         destination.name AS destination_name,destination.host AS destination_host FROM (
     369#   -- V Ensure that the copy we found on the source volume is the second copy instance
     370#   SELECT K.vol_id AS here,K.ins_id,K.so_id,ext_id,value AS user_copies,MAXins_id,instance.vol_id AS there FROM (
     371#    -- W Determine what the second copy instance is
     372#    SELECT V.*,MAX(instance.ins_id) AS MAXins_id FROM (
     373#     -- X Determine which hosts have instances of an object
     374#     SELECT vol_id,ins_id,so_id,ext_id,value FROM
     375#     storage_object JOIN storage_object_xattr USING(so_id) JOIN instance USING(so_id)
     376#     WHERE vol_id IN (
     377#      -- Y Extra select for debugging purposes
     378#      SELECT vol_id FROM (
     379#       -- Z Ran hosts by R (need to be a source) and return top N
     380#       SELECT mountedvol.vol_id,mountedvol.name,mountedvol.available,mountedvol.allocate,total,used,
     381#              (used / total) AS D,total * ((used / total) - $average ) AS R,  -- average
     382#              (used / total) - $average AS delta,
     383#              cab_id FROM
     384#       mountedvol JOIN volume USING(vol_id)
     385#       WHERE mountedvol.available = 1
     386#       ORDER BY delta DESC LIMIT $balance_N_sources                                            -- N
     387#       ) AS ranked_sources
     388#       -- Z End
     389#      )
     390#      -- Y End
     391#     AND name = 'user.copies' AND value >= 2
     392#   AND ext_id LIKE '%ota%fits'       -- This line is the emergency speedup option
     393#     AND so_id >= $so_id_start                                  -- so_id_start
     394#     AND so_id <  $so_id_end                                    -- so_id_end
     395#    ) AS V -- volumes that host a copy
     396#    -- X End
     397#   LEFT OUTER JOIN instance USING(so_id) GROUP BY so_id
     398#   ) AS K -- copies that are the second copy
     399#   -- W End
     400#  JOIN instance ON MAXins_id = instance.ins_id GROUP BY so_id
     401#  ) AS T -- matched copies that I know the second copy is on my source volume
     402#  -- V End
     403#  JOIN volume on T.here = volume.vol_id RIGHT JOIN (
     404#   -- Y2 Chose a random destination from the list
     405#   SELECT vol_id,cab_id,name,host FROM (
     406#    -- Z2 Reverse rank hosts by R and return top M
     407#    SELECT mountedvol.vol_id,mountedvol.name,mountedvol.host,mountedvol.available,mountedvol.allocate,total,used,
     408#           (used / total) AS D,total * ((used / total) - $average ) AS R,  -- average
     409#           (used / total) - $average AS delta,
     410#           cab_id FROM
     411#    mountedvol JOIN volume USING(vol_id)
     412#    WHERE mountedvol.available = 1 AND mountedvol.allocate = 1
     413#    ORDER BY delta ASC LIMIT $balance_M_destinations                                               -- M
     414#   ) AS ranked_destinations
     415#   -- Z2 End
     416#  ORDER BY RAND()
     417#  ) AS destination
     418#  -- Y2 End
     419#  ON destination.cab_id != volume.cab_id
     420#  WHERE here = there
     421#  ORDER BY RAND()
     422# ) AS results
     423# -- U End
     424# GROUP BY so_id
     425#     LIMIT $limit                                               -- limit
     426#     OFFSET $offset                                             -- offset
     427
     428# "    );
    365429
    366430    $query->execute();
     
    389453       
    390454
    391         my $here = $obj->{here};
    392         my $there = $obj->{there};
    393         my $ins_id = $obj->{ins_id};
     455#       my $here = $obj->{here};
     456#       my $there = $obj->{there};
     457#       my $ins_id = $obj->{ins_id};
    394458        my $max_ins_id = $obj->{MAXins_id};
    395459       
     
    398462        my $copies = $obj->{user_copies};
    399463
    400         my $source_vol_id = $obj->{here};
     464        my $source_vol_id = $obj->{vol_id};
    401465        my $source_cab_id = $obj->{source_cab_id};
    402466        my $source_name   = $obj->{source_name};
     
    408472        my $destination_host   = $obj->{destination_host};
    409473       
    410         unless ($here == $there) { $Npending-- ; next; }
    411         unless ($ins_id == $max_ins_id) { $Npending-- ; next; }
     474#       unless ($here == $there) { $Npending-- ; next; }
     475#       unless ($ins_id == $max_ins_id) { $Npending-- ; next; }
    412476        unless ($source_cab_id != $destination_cab_id) { $Npending-- ;  next; }
    413477       
Note: See TracChangeset for help on using the changeset viewer.