IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13130 for trunk/Nebulous/lib


Ignore:
Timestamp:
May 2, 2007, 10:14:46 AM (19 years ago)
Author:
jhoblitt
Message:

add volume.allocate field and logic to use it

Location:
trunk/Nebulous/lib/Nebulous
Files:
2 edited

Legend:

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

    r13115 r13130  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.29 2007-05-02 01:00:10 jhoblitt Exp $
     3# $Id: Server.pm,v 1.30 2007-05-02 20:14:45 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    166166        {
    167167            # get object ID
    168             my $query = $db->prepare( $sql->last_insert_id );
     168            my $query = $db->prepare_cached( $sql->last_insert_id );
    169169            $query->execute;
    170170            ($object_id) = $query->fetchrow_array;
     171            # XXX finish seems to be required when using LAST_INSERT_ID() or we
     172            # get a warning about the stmt handling still be active the next
     173            # time LAST_INSERT_ID() is invoked
     174            $query->finish;
    171175        }
    172176
     
    185189        {
    186190            # get instance ID
    187             my $query = $db->prepare( $sql->last_insert_id );
     191            my $query = $db->prepare_cached( $sql->last_insert_id );
    188192            $query->execute;
    189193            ($ins_id) = $query->fetchrow_array;
     194            # XXX finish seems to be required when using LAST_INSERT_ID() or we
     195            # get a warning about the stmt handling still be active the next
     196            # time LAST_INSERT_ID() is invoked
     197            $query->finish;
    190198        }
    191199    };
     
    322330
    323331        {
    324             my $query = $db->prepare( $sql->last_insert_id );
     332            my $query = $db->prepare_cached( $sql->last_insert_id );
    325333            $query->execute();
    326 
    327334            ($ins_id) = $query->fetchrow_array;
     335            # XXX finish seems to be required when using LAST_INSERT_ID() or we
     336            # get a warning about the stmt handling still be active the next
     337            # time LAST_INSERT_ID() is invoked
     338            $query->finish;
    328339        }
    329340    };
     
    10411052            $query = $db->prepare_cached( $sql->get_storage_volume_byname );
    10421053            $rows = $query->execute(0.95, $name);
     1054            unless ($rows > 0) {
     1055                $query->finish;
     1056                $log->logdie("storage volume: $name is not available");
     1057            }
     1058            # when matching by name we shouldn't ever match more than once
     1059            if ($rows > 1) {
     1060                $query->finish;
     1061                $log->logdie("affected row count is $rows instead of 1");
     1062            }
    10431063        } else {
    10441064            $query = $db->prepare_cached( $sql->get_storage_volume );
    10451065            $rows = $query->execute(0.95);
    1046         }
    1047 
    1048         # there has to be atleast one storage volume
    1049         unless ($rows > 0) {
    1050             $log->logdie( "affected row count is $rows instead of > 0" );
     1066            # there has to be atleast one storage volume
     1067            unless ($rows > 0) {
     1068                $query->finish;
     1069                $log->logdie("no storage volume is available");
     1070            }
    10511071        }
    10521072
  • trunk/Nebulous/lib/Nebulous/Server/SQL.pm

    r13115 r13130  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SQL.pm,v 1.31 2007-05-02 01:00:10 jhoblitt Exp $
     3# $Id: SQL.pm,v 1.32 2007-05-02 20:14:46 jhoblitt Exp $
    44
    55package Nebulous::Server::SQL;
     
    176176    },
    177177    new_volume          => qq{
    178         INSERT INTO volume (name, path)
    179         VALUES (?, ?)
     178        INSERT INTO volume (name, path, allocate)
     179        VALUES (?, ?, TRUE)
    180180    },
    181181    get_volume_by_name => qq{
     
    303303    name VARCHAR(255) UNIQUE NOT NULL,
    304304    path VARCHAR(255) NOT NULL,
     305    allocate BOOLEAN DEFAULT FALSE,
    305306    PRIMARY KEY(vol_id),
    306     KEY(name(16))
     307    KEY(name(16)),
     308    KEY(allocate)
    307309) ENGINE=innodb;
    308310
     
    335337    DECLARE namevar VARCHAR(255);
    336338    DECLARE pathvar VARCHAR(255);
    337     DECLARE cur1 CURSOR FOR SELECT vol_id, name, path FROM volume;
     339    DECLARE cur1 CURSOR FOR SELECT vol_id, name, path FROM volume
     340        WHERE allocate = TRUE;
    338341    DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE;
    339342
Note: See TracChangeset for help on using the changeset viewer.