IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24500


Ignore:
Timestamp:
Jun 18, 2009, 4:48:52 PM (17 years ago)
Author:
jhoblitt
Message:

rework delete_instance() to avoid requiring an index on instance.uri

Location:
trunk/Nebulous-Server
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/Changes

    r24408 r24500  
    2323      the semantics
    2424    - add nebdiskd mountpoint test retyring
     25    - rework delete_instance() to avoid requiring an index on instance.uri
    2526     
    26270.16
  • trunk/Nebulous-Server/lib/Nebulous/Server.pm

    r24412 r24500  
    15811581TRANS: while (1) {
    15821582        eval {
     1583            my $instances;
    15831584            my $so_id;
    1584             my $instances;
    1585             # get so_id
     1585            my $ins_id;
     1586            # find so_id for key and get count of instances
    15861587            {
    1587                 my $query = $db->prepare_cached( $sql->get_object_from_uri );
    1588                 my $rows = $query->execute( $uri );
    1589 
     1588                my $query = $db->prepare_cached( $sql->get_instance_count_by_ext_id );
     1589                my $rows = $query->execute($key->path);
    15901590                unless ( $rows > 0 ) {
    15911591                    $query->finish;
     1592                    die( "$key has no associated instances - this should not happen" );
     1593                }
     1594
     1595                my $record = $query->fetchrow_hashref;
     1596                $so_id      = $record->{ 'so_id' };
     1597                $instances  = $record->{ 'count(ins_id)' };
     1598                $query->finish;
     1599            }
     1600
     1601            # find ins_id for uri
     1602            {
     1603                my $query = $db->prepare_cached( $sql->get_instance_by_uri );
     1604                my $rows = $query->execute($so_id, $uri);
     1605                unless ( $rows > 0) {
     1606                    $query->finish;
    15921607                    die( "no instance is associated with uri" );
    15931608                }
    15941609
    1595                 $so_id = $query->fetchrow_hashref->{ 'so_id' };
    1596                 $query->finish;
    1597 
    1598             }
    1599 
    1600             {
    1601                 my $query = $db->prepare_cached( $sql->get_instance_count );
    1602                 $query->execute( $so_id );
    1603 
    1604                 $instances = $query->fetchrow_hashref->{ 'count(ins_id)' };
     1610                $ins_id = $query->fetchrow_hashref->{ 'ins_id' };
    16051611                $query->finish;
    16061612            }
     
    16081614            # remove instance
    16091615            {
    1610                 my $query = $db->prepare_cached( $sql->delete_instance );
    1611                 my $rows = $query->execute( $uri );
     1616                my $query = $db->prepare_cached( $sql->delete_instance_by_ins_id );
     1617                my $rows = $query->execute( $ins_id );
    16121618                $query->finish;
    16131619               
    1614                 # if we affected something other then two rows something very bad
    1615                 # has happened
     1620                # if we affected something other then one row something very
     1621                # bad has happened
    16161622                unless ( $rows == 1 ) {
    16171623                    die( "affected row count is $rows instead of 1" );
  • trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm

    r24423 r24500  
    175175        WHERE ext_id = ?
    176176    },
    177     delete_instance    => qq{
     177    delete_instance_by_ins_id => qq{
    178178        DELETE FROM instance
    179         WHERE uri = ?
     179        WHERE ins_id = ?
    180180    },
    181181    get_object_from_uri   => qq{
     
    184184        WHERE uri = ?
    185185    },
     186    get_instance_by_uri   => qq{
     187        SELECT ins_id
     188        FROM instance
     189        WHERE
     190            so_id = ?
     191            AND uri = ?
     192    },
    186193    get_instance_count   => qq{
    187194        SELECT count(ins_id)
    188195        FROM instance
    189196        WHERE so_id = ?
     197    },
     198    get_instance_count_by_ext_id   => qq{
     199        SELECT count(ins_id), so_id
     200        FROM instance
     201        JOIN storage_object
     202            USING(so_id)
     203        WHERE
     204            ext_id = ?
     205        GROUP BY so_id
    190206    },
    191207    get_object_instances    => qq{
Note: See TracChangeset for help on using the changeset viewer.