IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13115


Ignore:
Timestamp:
May 1, 2007, 3:00:10 PM (19 years ago)
Author:
jhoblitt
Message:

add instance.vol_id field
misc code cleanups

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/lib/Nebulous/Server.pm

    r13092 r13115  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.28 2007-05-01 02:52:04 jhoblitt Exp $
     3# $Id: Server.pm,v 1.29 2007-05-02 01:00:10 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    120120}
    121121
    122 sub create_object {
     122sub create_object
     123{
    123124    my $self = shift;
    124125
     
    143144    $log->debug( "entered - @_" );
    144145
    145     $volume = $self->_get_storage_volume( $volume );
    146 
    147     my $object_id;
     146    # Find the storage volume to use.  We are doing this first as there's no
     147    # point in creating a new storage object if we can't allocate a new
     148    # instance. ->_get_storage_volume() throws an exception on failure.
     149    my ($vol_id, $vol_path);
     150    eval {
     151        ($vol_id, $vol_path) = $self->_get_storage_volume($volume);
     152    };
     153    if ($@) {
     154        $log->logdie($@);
     155    }
     156
    148157    my $ins_id;
    149 
    150158    eval {
    151159        {
    152160            # create storage_object
    153             # XXX prepare_cached() was causing test failures
    154             my $query = $db->prepare( $sql->new_object );
    155             $query->execute( 'NULL', $key );
    156         }
    157 
     161            my $query = $db->prepare_cached( $sql->new_object );
     162            $query->execute('NULL', $key);
     163        }
     164
     165        my $object_id;
    158166        {
    159167            # get object ID
    160             my $query = $db->prepare_cached( $sql->last_insert_id );
     168            my $query = $db->prepare( $sql->last_insert_id );
    161169            $query->execute;
    162             ( $object_id ) = $query->fetchrow_array;
    163 
    164             $query->finish;
     170            ($object_id) = $query->fetchrow_array;
    165171        }
    166172
     
    168174            # create storage_object_attr
    169175            my $query = $db->prepare_cached( $sql->new_object_attr );
    170             $query->execute( $object_id );
     176            $query->execute($object_id);
    171177        }
    172178
     
    179185        {
    180186            # get instance ID
    181             my $query = $db->prepare_cached( $sql->last_insert_id );
     187            my $query = $db->prepare( $sql->last_insert_id );
    182188            $query->execute;
    183             ( $ins_id ) = $query->fetchrow_array;
    184 
    185             $query->finish;
    186         }
    187     };
    188     if ( $@ ) {
    189         $db->rollback;
    190         $log->logdie( "database error: $@" );
    191     }
    192 
    193     my $uri = URI::file->new("$volume/$key.$ins_id");
    194 
    195     $log->debug( "generated uri $uri");
     189            ($ins_id) = $query->fetchrow_array;
     190        }
     191    };
     192    if ($@) {
     193        $db->rollback;
     194        $log->logdie("database error: $@");
     195    }
     196
     197    # Unfortunately, since we want to use the instance row's ID as part of the
     198    # actual on disk file name we can't try to create the file until after
     199    # we've create both a new storage_storage object and instance.
     200    my $uri = URI::file->new("$vol_path/$key.$ins_id");
     201    $log->debug("generated uri $uri");
    196202
    197203    # TODO add some stuff here to retry if unsucessful
     
    199205        _create_empty_file($uri->file);
    200206    };
    201     if ( $@ ) {
    202         $db->rollback;
    203         $log->logdie( $@ );
     207    if ($@) {
     208        $db->rollback;
     209        $log->logdie($@);
    204210    }
    205211
     
    207213        {
    208214            my $query = $db->prepare_cached( $sql->update_instance_uri );
    209             $query->execute( $uri, $ins_id );
     215            # vol_id, uri, ins_id
     216            $query->execute($vol_id, $uri, $ins_id);
    210217        }
    211218
    212219        $db->commit;
    213220    };
    214     $log->logdie( "database error: $@" ) if $@;
    215 
    216     $log->debug( "leaving" );
     221    if ($@) {
     222        $db->rollback;
     223        $log->logdie("database error: $@");
     224    }
     225
     226    $log->debug("leaving");
    217227
    218228    return "$uri";
    219229}
    220230
    221 sub rename_object {
    222     my $self = shift;
    223 
    224     my ( $key, $newkey ) = validate_pos( @_,
    225         {
    226             type        => SCALAR,
    227         },
    228         {
    229             type        => SCALAR,
    230         },
    231     );
    232 
    233     my $log = $self->log;
    234     my $sql = $self->sql;
    235     my $db  =$self->db;
    236 
    237     $log->debug( "entered - @_" );
     231sub rename_object
     232{
     233    my $self = shift;
     234
     235    my ($key, $newkey) = validate_pos(@_,
     236        {
     237            type        => SCALAR,
     238        },
     239        {
     240            type        => SCALAR,
     241        },
     242    );
     243
     244    my $log = $self->log;
     245    my $sql = $self->sql;
     246    my $db  =$self->db;
     247
     248    $log->debug("entered - @_");
    238249
    239250    eval {
     
    244255
    245256        # if we affected more then one row something very bad has happened.
    246         unless ( $rows == 1 ) {
    247             $log->logdie( "affected row count is $rows instead of 1" );
    248         }
    249     };
    250     if ($@) {
    251         $db->rollback;
    252         $log->logdie( "database error: $@" );
    253     }
    254 
    255     eval {
     257        unless ($rows == 1) {
     258            $log->logdie("affected row count is $rows instead of 1");
     259        }
     260
    256261        $db->commit;
    257262    };
    258     if ( $@ ) {
    259         $db->rollback;
    260         $log->logdie( "database error: $@" );
    261     }
    262 
    263     $log->debug( "leaving" );
     263    if ($@) {
     264        $db->rollback;
     265        $log->logdie("database error: $@");
     266    }
     267
     268    $log->debug("leaving");
    264269
    265270    return $newkey;
    266271}
    267272
    268 sub replicate_object {
    269     my $self = shift;
    270 
    271     my ( $key, $volume ) = validate_pos( @_,
     273sub replicate_object
     274{
     275    my $self = shift;
     276
     277    my ($key, $volume) = validate_pos(@_,
    272278        {
    273279            type        => SCALAR,
     
    283289    my $db  =$self->db;
    284290
    285     $log->debug( "entered - @_" );
    286 
    287     # TODO
    288     $volume = $self->_get_storage_volume();
    289 
    290     my $path;
    291     my $uri;
    292 
    293     my $so_id;
     291    $log->debug("entered - @_");
     292
     293    my ($vol_id, $vol_path);
     294    eval {
     295        ($vol_id, $vol_path) = $self->_get_storage_volume($volume);
     296    };
     297    if ($@) {
     298        $log->logdie($@);
     299    }
     300
    294301    my $ins_id;
    295302    eval {
     303        my $so_id;
    296304        {
    297305            my $query = $db->prepare_cached( $sql->get_object_instances );
     
    310318        {
    311319            my $query = $db->prepare_cached( $sql->new_instance );
    312             $query->execute( $so_id );
    313         }
    314 
    315         {
    316             my $query = $db->prepare_cached( $sql->last_insert_id );
     320            $query->execute($so_id);
     321        }
     322
     323        {
     324            my $query = $db->prepare( $sql->last_insert_id );
    317325            $query->execute();
    318326
    319             ( $ins_id ) = $query->fetchrow_array;
    320 
    321             $query->finish;
    322         }
    323 
    324         {
    325             $uri = URI::file->new("$volume/$key.$ins_id");
    326             $log->debug("generated uri $uri");
    327 
     327            ($ins_id) = $query->fetchrow_array;
     328        }
     329    };
     330    if ($@) {
     331        $db->rollback;
     332        $log->logdie( "database error: $@" );
     333    }
     334
     335    my $uri = URI::file->new("$vol_path/$key.$ins_id");
     336    $log->debug("generated uri $uri");
     337
     338    # TODO add some stuff here to retry if unsucessful
     339    eval {
     340        _create_empty_file($uri->file);
     341    };
     342    if ($@) {
     343        $db->rollback;
     344        $log->logdie($@);
     345    }
     346
     347    eval {
     348        {
    328349            my $query = $db->prepare_cached( $sql->update_instance_uri );
    329             $query->execute( $uri, $ins_id );
    330         }
    331     };
    332     if ( $@ ) {
    333         $db->rollback;
    334         $log->logdie( "database error: $@" );
    335     }
    336 
    337 
    338     eval {
    339         _create_empty_file($uri->file);
    340     };
    341     if ( $@ ) {
    342         $db->rollback;
    343         $log->logdie( $@ );
    344     }
    345 
    346     $db->commit;
    347 
    348     $log->debug( "leaving" );
     350            # vol_id, uri, ins_id
     351            $query->execute($vol_id, $uri, $ins_id);
     352        }
     353
     354        $db->commit;
     355    };
     356    if ($@) {
     357        $db->rollback;
     358        $log->logdie("database error: $@");
     359    }
     360
     361    $log->debug("leaving");
    349362
    350363    return "$uri";
     
    10001013#  select *, total - used as free, (used / total) * 100 as perused from mount;
    10011014
    1002 sub _get_storage_volume {
     1015sub _get_storage_volume
     1016{
    10031017    my $self = shift;
    10041018
     
    10131027    my $name = shift;
    10141028
    1015     my $volume;
    1016     my $query;
    1017     eval {
    1018         # ask the db to generate the table of mounted Nebulous volume
    1019         $query = $db->prepare_cached("call getmountedvol()");
    1020         $query->execute();
     1029    my ($vol_id, $vol_path);
     1030    eval {
     1031        {
     1032            # ask the db to generate the table of mounted Nebulous volume
     1033            my $query = $db->prepare_cached("call getmountedvol()");
     1034            $query->execute();
     1035        }
    10211036
    10221037        # TODO cache this?
     1038        my $query;
    10231039        my $rows;
    10241040        if ( $name ) {
     
    10311047
    10321048        # there has to be atleast one storage volume
    1033         unless ( $rows > 0 ) {
    1034             $log->logdie( "affected row count is $rows instead of 1" );
    1035         }
    1036 
    1037         $volume = $query->fetchrow_hashref->{ 'volume' };
    1038 
     1049        unless ($rows > 0) {
     1050            $log->logdie( "affected row count is $rows instead of > 0" );
     1051        }
     1052
     1053        my $free;
     1054        ($vol_id, $vol_path, $free) = $query->fetchrow_array;
    10391055        $query->finish;
    1040         $db->commit;
    1041     };
    1042     if ( $@ ) {
    1043         $query->finish;
    1044         $db->rollback;
    1045         $log->logdie( "database error: $@" ) if $@;
    1046     }
    1047 
    1048     $log->logdie( "failed to find a suitable volume" ) unless defined $volume;
     1056    };
     1057    if ($@) {
     1058        $db->rollback;
     1059        $log->logdie("database error: $@");
     1060    }
     1061
     1062    $log->logdie("failed to find a suitable volume" )
     1063        unless defined $vol_id and defined $vol_path;
    10491064
    10501065    $log->debug( "leaving" );
    10511066
    1052     return $volume;
     1067    return ($vol_id, $vol_path);
    10531068}
    10541069
     
    10601075    my $db  =$self->db;
    10611076
    1062     my $volume;
     1077    my ($vol_id, $vol_path);
    10631078    eval {
    10641079        my $query = $db->prepare_cached( $sql->get_volume_by_name );
    10651080        $query->execute( $vol_name );
    1066         ( $volume ) = $query->fetchrow_array;
    1067 
     1081        my $free;
     1082        ($vol_id, $vol_path, $free) = $query->fetchrow_array;
    10681083        $query->finish;
    10691084    };
    1070     if ( $@ ) {
     1085    if ($@) {
    10711086        $db->rollback;
    10721087        $log->logdie( "database error: $@" );
    10731088    }
    10741089
    1075     return ( defined $volume ) ? 1 : undef;
     1090    if (defined $vol_id and defined $vol_path) {
     1091        return 1;
     1092    }
     1093
     1094    return;
    10761095}
    10771096
  • trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm

    r13092 r13115  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SQL.pm,v 1.30 2007-05-01 02:52:04 jhoblitt Exp $
     3# $Id: SQL.pm,v 1.31 2007-05-02 01:00:10 jhoblitt Exp $
    44
    55package Nebulous::Server::SQL;
     
    1717    },
    1818    update_instance_uri => qq{
    19         UPDATE instance SET uri = ? WHERE ins_id = ?
     19        UPDATE instance SET vol_id = ?, uri = ? WHERE ins_id = ?
    2020    },
    2121    last_insert_id      => qq{
     
    3838        WHERE storage_object.so_id = ?
    3939    },
    40     new_object_instance  => qq{
     40    new_object_instance => qq{
    4141        INSERT INTO instance
    42         VALUES (NULL, LAST_INSERT_ID(), 'error', NULL, NULL, NULL, NULL)
     42        VALUES (NULL, LAST_INSERT_ID(), 0, 'error', NULL, NULL, NULL, NULL)
    4343    },
    4444    new_instance        => qq{
    4545        INSERT INTO instance
    46         VALUES (NULL, ?, 'error', NULL,NULL, NULL, NULL)
     46        VALUES (NULL, ?, 0, 'error', NULL,NULL, NULL, NULL)
    4747    },
    4848    get_object          => qq{
     
    154154    get_storage_volume_byname   => qq{
    155155        SELECT
    156             path as volume,
     156            vol_id,
     157            path,
    157158            total - used as free
    158159        FROM mountedvol
     
    165166    get_storage_volume          => qq{
    166167        SELECT
    167             path as volume,
     168            vol_id,
     169            path,
    168170            total - used as free
    169171        FROM mountedvol
     
    210212{
    211213    my @clear = split /;/, <<END;
     214SET FOREIGN_KEY_CHECKS=0;
    212215DROP TABLE IF EXISTS storage_object;
    213216DROP TABLE IF EXISTS storage_object_attr;
     
    219222DROP TABLE IF EXISTS class;
    220223DROP TABLE IF EXISTS log;
    221 DROP PROCEDURE IF EXISTS getmountedvol
     224DROP PROCEDURE IF EXISTS getmountedvol;
     225SET FOREIGN_KEY_CHECKS=1
    222226END
    223227    $sql{get_db_clear} = \@clear;
     
    273277    ins_id BIGINT NOT NULL AUTO_INCREMENT,
    274278    so_id BIGINT NOT NULL,
     279    vol_id INT NOT NULL,
    275280    uri VARCHAR(255) NOT NULL,
    276281    sha1sum CHAR(40) ASCII,
  • trunk/Nebulous/lib/Nebulous/Server.pm

    r13092 r13115  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.28 2007-05-01 02:52:04 jhoblitt Exp $
     3# $Id: Server.pm,v 1.29 2007-05-02 01:00:10 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    120120}
    121121
    122 sub create_object {
     122sub create_object
     123{
    123124    my $self = shift;
    124125
     
    143144    $log->debug( "entered - @_" );
    144145
    145     $volume = $self->_get_storage_volume( $volume );
    146 
    147     my $object_id;
     146    # Find the storage volume to use.  We are doing this first as there's no
     147    # point in creating a new storage object if we can't allocate a new
     148    # instance. ->_get_storage_volume() throws an exception on failure.
     149    my ($vol_id, $vol_path);
     150    eval {
     151        ($vol_id, $vol_path) = $self->_get_storage_volume($volume);
     152    };
     153    if ($@) {
     154        $log->logdie($@);
     155    }
     156
    148157    my $ins_id;
    149 
    150158    eval {
    151159        {
    152160            # create storage_object
    153             # XXX prepare_cached() was causing test failures
    154             my $query = $db->prepare( $sql->new_object );
    155             $query->execute( 'NULL', $key );
    156         }
    157 
     161            my $query = $db->prepare_cached( $sql->new_object );
     162            $query->execute('NULL', $key);
     163        }
     164
     165        my $object_id;
    158166        {
    159167            # get object ID
    160             my $query = $db->prepare_cached( $sql->last_insert_id );
     168            my $query = $db->prepare( $sql->last_insert_id );
    161169            $query->execute;
    162             ( $object_id ) = $query->fetchrow_array;
    163 
    164             $query->finish;
     170            ($object_id) = $query->fetchrow_array;
    165171        }
    166172
     
    168174            # create storage_object_attr
    169175            my $query = $db->prepare_cached( $sql->new_object_attr );
    170             $query->execute( $object_id );
     176            $query->execute($object_id);
    171177        }
    172178
     
    179185        {
    180186            # get instance ID
    181             my $query = $db->prepare_cached( $sql->last_insert_id );
     187            my $query = $db->prepare( $sql->last_insert_id );
    182188            $query->execute;
    183             ( $ins_id ) = $query->fetchrow_array;
    184 
    185             $query->finish;
    186         }
    187     };
    188     if ( $@ ) {
    189         $db->rollback;
    190         $log->logdie( "database error: $@" );
    191     }
    192 
    193     my $uri = URI::file->new("$volume/$key.$ins_id");
    194 
    195     $log->debug( "generated uri $uri");
     189            ($ins_id) = $query->fetchrow_array;
     190        }
     191    };
     192    if ($@) {
     193        $db->rollback;
     194        $log->logdie("database error: $@");
     195    }
     196
     197    # Unfortunately, since we want to use the instance row's ID as part of the
     198    # actual on disk file name we can't try to create the file until after
     199    # we've create both a new storage_storage object and instance.
     200    my $uri = URI::file->new("$vol_path/$key.$ins_id");
     201    $log->debug("generated uri $uri");
    196202
    197203    # TODO add some stuff here to retry if unsucessful
     
    199205        _create_empty_file($uri->file);
    200206    };
    201     if ( $@ ) {
    202         $db->rollback;
    203         $log->logdie( $@ );
     207    if ($@) {
     208        $db->rollback;
     209        $log->logdie($@);
    204210    }
    205211
     
    207213        {
    208214            my $query = $db->prepare_cached( $sql->update_instance_uri );
    209             $query->execute( $uri, $ins_id );
     215            # vol_id, uri, ins_id
     216            $query->execute($vol_id, $uri, $ins_id);
    210217        }
    211218
    212219        $db->commit;
    213220    };
    214     $log->logdie( "database error: $@" ) if $@;
    215 
    216     $log->debug( "leaving" );
     221    if ($@) {
     222        $db->rollback;
     223        $log->logdie("database error: $@");
     224    }
     225
     226    $log->debug("leaving");
    217227
    218228    return "$uri";
    219229}
    220230
    221 sub rename_object {
    222     my $self = shift;
    223 
    224     my ( $key, $newkey ) = validate_pos( @_,
    225         {
    226             type        => SCALAR,
    227         },
    228         {
    229             type        => SCALAR,
    230         },
    231     );
    232 
    233     my $log = $self->log;
    234     my $sql = $self->sql;
    235     my $db  =$self->db;
    236 
    237     $log->debug( "entered - @_" );
     231sub rename_object
     232{
     233    my $self = shift;
     234
     235    my ($key, $newkey) = validate_pos(@_,
     236        {
     237            type        => SCALAR,
     238        },
     239        {
     240            type        => SCALAR,
     241        },
     242    );
     243
     244    my $log = $self->log;
     245    my $sql = $self->sql;
     246    my $db  =$self->db;
     247
     248    $log->debug("entered - @_");
    238249
    239250    eval {
     
    244255
    245256        # if we affected more then one row something very bad has happened.
    246         unless ( $rows == 1 ) {
    247             $log->logdie( "affected row count is $rows instead of 1" );
    248         }
    249     };
    250     if ($@) {
    251         $db->rollback;
    252         $log->logdie( "database error: $@" );
    253     }
    254 
    255     eval {
     257        unless ($rows == 1) {
     258            $log->logdie("affected row count is $rows instead of 1");
     259        }
     260
    256261        $db->commit;
    257262    };
    258     if ( $@ ) {
    259         $db->rollback;
    260         $log->logdie( "database error: $@" );
    261     }
    262 
    263     $log->debug( "leaving" );
     263    if ($@) {
     264        $db->rollback;
     265        $log->logdie("database error: $@");
     266    }
     267
     268    $log->debug("leaving");
    264269
    265270    return $newkey;
    266271}
    267272
    268 sub replicate_object {
    269     my $self = shift;
    270 
    271     my ( $key, $volume ) = validate_pos( @_,
     273sub replicate_object
     274{
     275    my $self = shift;
     276
     277    my ($key, $volume) = validate_pos(@_,
    272278        {
    273279            type        => SCALAR,
     
    283289    my $db  =$self->db;
    284290
    285     $log->debug( "entered - @_" );
    286 
    287     # TODO
    288     $volume = $self->_get_storage_volume();
    289 
    290     my $path;
    291     my $uri;
    292 
    293     my $so_id;
     291    $log->debug("entered - @_");
     292
     293    my ($vol_id, $vol_path);
     294    eval {
     295        ($vol_id, $vol_path) = $self->_get_storage_volume($volume);
     296    };
     297    if ($@) {
     298        $log->logdie($@);
     299    }
     300
    294301    my $ins_id;
    295302    eval {
     303        my $so_id;
    296304        {
    297305            my $query = $db->prepare_cached( $sql->get_object_instances );
     
    310318        {
    311319            my $query = $db->prepare_cached( $sql->new_instance );
    312             $query->execute( $so_id );
    313         }
    314 
    315         {
    316             my $query = $db->prepare_cached( $sql->last_insert_id );
     320            $query->execute($so_id);
     321        }
     322
     323        {
     324            my $query = $db->prepare( $sql->last_insert_id );
    317325            $query->execute();
    318326
    319             ( $ins_id ) = $query->fetchrow_array;
    320 
    321             $query->finish;
    322         }
    323 
    324         {
    325             $uri = URI::file->new("$volume/$key.$ins_id");
    326             $log->debug("generated uri $uri");
    327 
     327            ($ins_id) = $query->fetchrow_array;
     328        }
     329    };
     330    if ($@) {
     331        $db->rollback;
     332        $log->logdie( "database error: $@" );
     333    }
     334
     335    my $uri = URI::file->new("$vol_path/$key.$ins_id");
     336    $log->debug("generated uri $uri");
     337
     338    # TODO add some stuff here to retry if unsucessful
     339    eval {
     340        _create_empty_file($uri->file);
     341    };
     342    if ($@) {
     343        $db->rollback;
     344        $log->logdie($@);
     345    }
     346
     347    eval {
     348        {
    328349            my $query = $db->prepare_cached( $sql->update_instance_uri );
    329             $query->execute( $uri, $ins_id );
    330         }
    331     };
    332     if ( $@ ) {
    333         $db->rollback;
    334         $log->logdie( "database error: $@" );
    335     }
    336 
    337 
    338     eval {
    339         _create_empty_file($uri->file);
    340     };
    341     if ( $@ ) {
    342         $db->rollback;
    343         $log->logdie( $@ );
    344     }
    345 
    346     $db->commit;
    347 
    348     $log->debug( "leaving" );
     350            # vol_id, uri, ins_id
     351            $query->execute($vol_id, $uri, $ins_id);
     352        }
     353
     354        $db->commit;
     355    };
     356    if ($@) {
     357        $db->rollback;
     358        $log->logdie("database error: $@");
     359    }
     360
     361    $log->debug("leaving");
    349362
    350363    return "$uri";
     
    10001013#  select *, total - used as free, (used / total) * 100 as perused from mount;
    10011014
    1002 sub _get_storage_volume {
     1015sub _get_storage_volume
     1016{
    10031017    my $self = shift;
    10041018
     
    10131027    my $name = shift;
    10141028
    1015     my $volume;
    1016     my $query;
    1017     eval {
    1018         # ask the db to generate the table of mounted Nebulous volume
    1019         $query = $db->prepare_cached("call getmountedvol()");
    1020         $query->execute();
     1029    my ($vol_id, $vol_path);
     1030    eval {
     1031        {
     1032            # ask the db to generate the table of mounted Nebulous volume
     1033            my $query = $db->prepare_cached("call getmountedvol()");
     1034            $query->execute();
     1035        }
    10211036
    10221037        # TODO cache this?
     1038        my $query;
    10231039        my $rows;
    10241040        if ( $name ) {
     
    10311047
    10321048        # there has to be atleast one storage volume
    1033         unless ( $rows > 0 ) {
    1034             $log->logdie( "affected row count is $rows instead of 1" );
    1035         }
    1036 
    1037         $volume = $query->fetchrow_hashref->{ 'volume' };
    1038 
     1049        unless ($rows > 0) {
     1050            $log->logdie( "affected row count is $rows instead of > 0" );
     1051        }
     1052
     1053        my $free;
     1054        ($vol_id, $vol_path, $free) = $query->fetchrow_array;
    10391055        $query->finish;
    1040         $db->commit;
    1041     };
    1042     if ( $@ ) {
    1043         $query->finish;
    1044         $db->rollback;
    1045         $log->logdie( "database error: $@" ) if $@;
    1046     }
    1047 
    1048     $log->logdie( "failed to find a suitable volume" ) unless defined $volume;
     1056    };
     1057    if ($@) {
     1058        $db->rollback;
     1059        $log->logdie("database error: $@");
     1060    }
     1061
     1062    $log->logdie("failed to find a suitable volume" )
     1063        unless defined $vol_id and defined $vol_path;
    10491064
    10501065    $log->debug( "leaving" );
    10511066
    1052     return $volume;
     1067    return ($vol_id, $vol_path);
    10531068}
    10541069
     
    10601075    my $db  =$self->db;
    10611076
    1062     my $volume;
     1077    my ($vol_id, $vol_path);
    10631078    eval {
    10641079        my $query = $db->prepare_cached( $sql->get_volume_by_name );
    10651080        $query->execute( $vol_name );
    1066         ( $volume ) = $query->fetchrow_array;
    1067 
     1081        my $free;
     1082        ($vol_id, $vol_path, $free) = $query->fetchrow_array;
    10681083        $query->finish;
    10691084    };
    1070     if ( $@ ) {
     1085    if ($@) {
    10711086        $db->rollback;
    10721087        $log->logdie( "database error: $@" );
    10731088    }
    10741089
    1075     return ( defined $volume ) ? 1 : undef;
     1090    if (defined $vol_id and defined $vol_path) {
     1091        return 1;
     1092    }
     1093
     1094    return;
    10761095}
    10771096
  • trunk/Nebulous/lib/Nebulous/Server/SQL.pm

    r13092 r13115  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SQL.pm,v 1.30 2007-05-01 02:52:04 jhoblitt Exp $
     3# $Id: SQL.pm,v 1.31 2007-05-02 01:00:10 jhoblitt Exp $
    44
    55package Nebulous::Server::SQL;
     
    1717    },
    1818    update_instance_uri => qq{
    19         UPDATE instance SET uri = ? WHERE ins_id = ?
     19        UPDATE instance SET vol_id = ?, uri = ? WHERE ins_id = ?
    2020    },
    2121    last_insert_id      => qq{
     
    3838        WHERE storage_object.so_id = ?
    3939    },
    40     new_object_instance  => qq{
     40    new_object_instance => qq{
    4141        INSERT INTO instance
    42         VALUES (NULL, LAST_INSERT_ID(), 'error', NULL, NULL, NULL, NULL)
     42        VALUES (NULL, LAST_INSERT_ID(), 0, 'error', NULL, NULL, NULL, NULL)
    4343    },
    4444    new_instance        => qq{
    4545        INSERT INTO instance
    46         VALUES (NULL, ?, 'error', NULL,NULL, NULL, NULL)
     46        VALUES (NULL, ?, 0, 'error', NULL,NULL, NULL, NULL)
    4747    },
    4848    get_object          => qq{
     
    154154    get_storage_volume_byname   => qq{
    155155        SELECT
    156             path as volume,
     156            vol_id,
     157            path,
    157158            total - used as free
    158159        FROM mountedvol
     
    165166    get_storage_volume          => qq{
    166167        SELECT
    167             path as volume,
     168            vol_id,
     169            path,
    168170            total - used as free
    169171        FROM mountedvol
     
    210212{
    211213    my @clear = split /;/, <<END;
     214SET FOREIGN_KEY_CHECKS=0;
    212215DROP TABLE IF EXISTS storage_object;
    213216DROP TABLE IF EXISTS storage_object_attr;
     
    219222DROP TABLE IF EXISTS class;
    220223DROP TABLE IF EXISTS log;
    221 DROP PROCEDURE IF EXISTS getmountedvol
     224DROP PROCEDURE IF EXISTS getmountedvol;
     225SET FOREIGN_KEY_CHECKS=1
    222226END
    223227    $sql{get_db_clear} = \@clear;
     
    273277    ins_id BIGINT NOT NULL AUTO_INCREMENT,
    274278    so_id BIGINT NOT NULL,
     279    vol_id INT NOT NULL,
    275280    uri VARCHAR(255) NOT NULL,
    276281    sha1sum CHAR(40) ASCII,
Note: See TracChangeset for help on using the changeset viewer.