IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24625


Ignore:
Timestamp:
Jun 29, 2009, 1:54:25 PM (17 years ago)
Author:
jhoblitt
Message:

change pending SQL to not use temp tables and be a hair more efficient
tab expansion

File:
1 edited

Legend:

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

    r23932 r24625  
    9191{
    9292# so_id, ext_id, instances, available_instances, need_recovery, recoverable
    93     $dbh->do("CREATE TEMPORARY TABLE mymountedvol LIKE mountedvol");
    94     $dbh->do("INSERT INTO mymountedvol SELECT * FROM mountedvol");
    95     $dbh->do("CREATE TEMPORARY TABLE myvolume LIKE volume");
    96     $dbh->do("INSERT INTO myvolume SELECT * FROM volume");
     93# XXX don't remove the temp table code -- testing w/o it
     94#    $dbh->do("CREATE TEMPORARY TABLE mymountedvol LIKE mountedvol");
     95#    $dbh->do("INSERT INTO mymountedvol SELECT * FROM mountedvol");
    9796
    9897    if (not defined $so_id_start) { $so_id_start = 0; }
     
    102101    # XXX check if so_id_start is beyond MAX(so_id): if so, exit with exit status 10
    103102    {
    104         my $query = $dbh->prepare("SELECT MAX(so_id) from storage_object");
    105         $query->execute;
     103        my $query = $dbh->prepare("SELECT MAX(so_id) from storage_object");
     104        $query->execute;
    106105        my $answer = $query->fetchrow_arrayref;
    107106        my $max_so_id = $$answer[0];
    108         $query->finish;
    109 
    110         if ($so_id_start > $max_so_id) {
    111             print STDERR "at end of so_id range, reset please\n";
    112             exit 10;
    113         }
    114     }
    115        
     107        $query->finish;
     108
     109        if ($so_id_start > $max_so_id) {
     110            print STDERR "at end of so_id range, reset please\n";
     111            exit 10;
     112        }
     113    }
     114       
    116115    my $query = $dbh->prepare(
    117     "        SELECT
    118                 storage_object.so_id,
    119                 ext_id,
    120                 count(ins_id) as instances,
    121                 myvolume.name as volume_name,
    122                 myvolume.host as volume_host,
    123                 count(mymountedvol.vol_id) as available_instances,
    124                 count(mymountedvol.vol_id) > 0 as recoverable,
    125                 storage_object_xattr.value as copies
    126             FROM storage_object
    127             JOIN instance
    128                 USING(so_id)
    129             JOIN myvolume
    130                 USING(vol_id)
    131             LEFT JOIN storage_object_xattr
    132                 ON storage_object.so_id = storage_object_xattr.so_id
    133             JOIN mymountedvol
    134                 USING(vol_id)
    135             WHERE mymountedvol.available = 1
    136             AND storage_object_xattr.name = 'user.copies'
    137             AND storage_object.so_id >= $so_id_start
    138             AND storage_object.so_id <  $so_id_end
    139             GROUP BY so_id
    140             HAVING available_instances < instances OR instances < copies
    141             LIMIT $limit"
     116    "
     117        SELECT
     118            so.so_id,
     119            so.ext_id,
     120            count(ins_id) as instances,
     121            mv.name as volume_name,
     122            mv.host as volume_host,
     123            count(mv.vol_id) as available_instances,
     124            count(mv.vol_id) > 0 as recoverable,
     125            xattr.value as copies
     126        FROM storage_object AS so
     127        JOIN storage_object_xattr AS xattr
     128            ON so.so_id = xattr.so_id
     129            AND xattr.name = 'user.copies'
     130        JOIN instance AS i
     131            ON so.so_id = i.so_id
     132        JOIN mountedvol AS mv
     133            USING(vol_id)
     134        WHERE
     135            mv.available = 1
     136            AND so.so_id >= $so_id_start
     137            AND so.so_id <  $so_id_end
     138        GROUP BY so_id
     139        ORDER BY so_id DESC
     140        HAVING available_instances < instances OR instances < copies
     141        LIMIT $limit"
    142142    );
    143143    $query->execute;
    144144
    145     $dbh->do("DROP TABLE IF EXISTS mymountedvol");
     145#    $dbh->do("DROP TABLE IF EXISTS mymountedvol");
    146146
    147147    my @rows;
     
    174174        # if the copies xattr is unset and the object has 2 or more instances, we
    175175        # will assume a target of 2 copies
    176        
    177         # XXX change this: there should be no default value or we will
    178         # have a race condition.  user.copies should never get set by
    179         # any client until AFTER a file is no longer in use.
     176       
     177        # XXX change this: there should be no default value or we will
     178        # have a race condition.  user.copies should never get set by
     179        # any client until AFTER a file is no longer in use.
    180180        my $copies = $obj->{copies} || 2;
    181181
     
    207207    # use a different exit status if we hit the limit (likely more files pending)
    208208    if ($Npending == $limit) {
    209         exit 1;
     209        exit 1;
    210210    }
    211211    exit 0;
     
    225225
    226226    $dbh->do("DROP TABLE IF EXISTS mymountedvol");
     227    $dbh->do("DROP TABLE IF EXISTS myvolume");
    227228
    228229    my @rows;
Note: See TracChangeset for help on using the changeset viewer.