Index: /trunk/Nebulous-Server/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 13129)
+++ /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 13130)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.29 2007-05-02 01:00:10 jhoblitt Exp $
+# $Id: Server.pm,v 1.30 2007-05-02 20:14:45 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -166,7 +166,11 @@
         {
             # get object ID
-            my $query = $db->prepare( $sql->last_insert_id );
+            my $query = $db->prepare_cached( $sql->last_insert_id );
             $query->execute;
             ($object_id) = $query->fetchrow_array;
+            # XXX finish seems to be required when using LAST_INSERT_ID() or we
+            # get a warning about the stmt handling still be active the next
+            # time LAST_INSERT_ID() is invoked
+            $query->finish;
         }
 
@@ -185,7 +189,11 @@
         {
             # get instance ID
-            my $query = $db->prepare( $sql->last_insert_id );
+            my $query = $db->prepare_cached( $sql->last_insert_id );
             $query->execute;
             ($ins_id) = $query->fetchrow_array;
+            # XXX finish seems to be required when using LAST_INSERT_ID() or we
+            # get a warning about the stmt handling still be active the next
+            # time LAST_INSERT_ID() is invoked
+            $query->finish;
         }
     };
@@ -322,8 +330,11 @@
 
         {
-            my $query = $db->prepare( $sql->last_insert_id );
+            my $query = $db->prepare_cached( $sql->last_insert_id );
             $query->execute();
-
             ($ins_id) = $query->fetchrow_array;
+            # XXX finish seems to be required when using LAST_INSERT_ID() or we
+            # get a warning about the stmt handling still be active the next
+            # time LAST_INSERT_ID() is invoked
+            $query->finish;
         }
     };
@@ -1041,12 +1052,21 @@
             $query = $db->prepare_cached( $sql->get_storage_volume_byname );
             $rows = $query->execute(0.95, $name);
+            unless ($rows > 0) {
+                $query->finish;
+                $log->logdie("storage volume: $name is not available");
+            }
+            # when matching by name we shouldn't ever match more than once
+            if ($rows > 1) {
+                $query->finish;
+                $log->logdie("affected row count is $rows instead of 1");
+            }
         } else {
             $query = $db->prepare_cached( $sql->get_storage_volume );
             $rows = $query->execute(0.95);
-        }
-
-        # there has to be atleast one storage volume
-        unless ($rows > 0) {
-            $log->logdie( "affected row count is $rows instead of > 0" );
+            # there has to be atleast one storage volume
+            unless ($rows > 0) {
+                $query->finish;
+                $log->logdie("no storage volume is available");
+            }
         }
 
Index: /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 13129)
+++ /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 13130)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: SQL.pm,v 1.31 2007-05-02 01:00:10 jhoblitt Exp $
+# $Id: SQL.pm,v 1.32 2007-05-02 20:14:46 jhoblitt Exp $
 
 package Nebulous::Server::SQL;
@@ -176,6 +176,6 @@
     },
     new_volume          => qq{
-        INSERT INTO volume (name, path)
-        VALUES (?, ?)
+        INSERT INTO volume (name, path, allocate)
+        VALUES (?, ?, TRUE)
     },
     get_volume_by_name => qq{
@@ -303,6 +303,8 @@
     name VARCHAR(255) UNIQUE NOT NULL,
     path VARCHAR(255) NOT NULL,
+    allocate BOOLEAN DEFAULT FALSE,
     PRIMARY KEY(vol_id),
-    KEY(name(16))
+    KEY(name(16)),
+    KEY(allocate)
 ) ENGINE=innodb;
 
@@ -335,5 +337,6 @@
     DECLARE namevar VARCHAR(255);
     DECLARE pathvar VARCHAR(255);
-    DECLARE cur1 CURSOR FOR SELECT vol_id, name, path FROM volume;
+    DECLARE cur1 CURSOR FOR SELECT vol_id, name, path FROM volume
+        WHERE allocate = TRUE;
     DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE;
 
Index: /trunk/Nebulous-Server/t/03_server_create_object.t
===================================================================
--- /trunk/Nebulous-Server/t/03_server_create_object.t	(revision 13129)
+++ /trunk/Nebulous-Server/t/03_server_create_object.t	(revision 13130)
@@ -3,10 +3,10 @@
 # Copryight (C) 2004-2005  Joshua Hoblitt
 #
-# $Id: 03_server_create_object.t,v 1.13 2007-05-01 02:52:04 jhoblitt Exp $
+# $Id: 03_server_create_object.t,v 1.14 2007-05-02 20:14:46 jhoblitt Exp $
 
 use strict;
 use warnings FATAL => qw( all );
 
-use Test::More tests => 8;
+use Test::More tests => 10;
 
 use lib qw( ./t ./lib );
@@ -57,4 +57,18 @@
 
 eval {
+    $neb->create_object("foo", 'node03');
+};
+like($@, qr/node03 is not available/, "request volume with allocate = FALSE");
+
+Test::Nebulous->setup;
+
+eval {
+    $neb->create_object("foo", 'node04');
+};
+like($@, qr/node04 is not available/, "request volume this is full");
+
+Test::Nebulous->setup;
+
+eval {
     $neb->create_object("foo", 99);
 };
Index: /trunk/Nebulous/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous/lib/Nebulous/Server.pm	(revision 13129)
+++ /trunk/Nebulous/lib/Nebulous/Server.pm	(revision 13130)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.29 2007-05-02 01:00:10 jhoblitt Exp $
+# $Id: Server.pm,v 1.30 2007-05-02 20:14:45 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -166,7 +166,11 @@
         {
             # get object ID
-            my $query = $db->prepare( $sql->last_insert_id );
+            my $query = $db->prepare_cached( $sql->last_insert_id );
             $query->execute;
             ($object_id) = $query->fetchrow_array;
+            # XXX finish seems to be required when using LAST_INSERT_ID() or we
+            # get a warning about the stmt handling still be active the next
+            # time LAST_INSERT_ID() is invoked
+            $query->finish;
         }
 
@@ -185,7 +189,11 @@
         {
             # get instance ID
-            my $query = $db->prepare( $sql->last_insert_id );
+            my $query = $db->prepare_cached( $sql->last_insert_id );
             $query->execute;
             ($ins_id) = $query->fetchrow_array;
+            # XXX finish seems to be required when using LAST_INSERT_ID() or we
+            # get a warning about the stmt handling still be active the next
+            # time LAST_INSERT_ID() is invoked
+            $query->finish;
         }
     };
@@ -322,8 +330,11 @@
 
         {
-            my $query = $db->prepare( $sql->last_insert_id );
+            my $query = $db->prepare_cached( $sql->last_insert_id );
             $query->execute();
-
             ($ins_id) = $query->fetchrow_array;
+            # XXX finish seems to be required when using LAST_INSERT_ID() or we
+            # get a warning about the stmt handling still be active the next
+            # time LAST_INSERT_ID() is invoked
+            $query->finish;
         }
     };
@@ -1041,12 +1052,21 @@
             $query = $db->prepare_cached( $sql->get_storage_volume_byname );
             $rows = $query->execute(0.95, $name);
+            unless ($rows > 0) {
+                $query->finish;
+                $log->logdie("storage volume: $name is not available");
+            }
+            # when matching by name we shouldn't ever match more than once
+            if ($rows > 1) {
+                $query->finish;
+                $log->logdie("affected row count is $rows instead of 1");
+            }
         } else {
             $query = $db->prepare_cached( $sql->get_storage_volume );
             $rows = $query->execute(0.95);
-        }
-
-        # there has to be atleast one storage volume
-        unless ($rows > 0) {
-            $log->logdie( "affected row count is $rows instead of > 0" );
+            # there has to be atleast one storage volume
+            unless ($rows > 0) {
+                $query->finish;
+                $log->logdie("no storage volume is available");
+            }
         }
 
Index: /trunk/Nebulous/lib/Nebulous/Server/SQL.pm
===================================================================
--- /trunk/Nebulous/lib/Nebulous/Server/SQL.pm	(revision 13129)
+++ /trunk/Nebulous/lib/Nebulous/Server/SQL.pm	(revision 13130)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: SQL.pm,v 1.31 2007-05-02 01:00:10 jhoblitt Exp $
+# $Id: SQL.pm,v 1.32 2007-05-02 20:14:46 jhoblitt Exp $
 
 package Nebulous::Server::SQL;
@@ -176,6 +176,6 @@
     },
     new_volume          => qq{
-        INSERT INTO volume (name, path)
-        VALUES (?, ?)
+        INSERT INTO volume (name, path, allocate)
+        VALUES (?, ?, TRUE)
     },
     get_volume_by_name => qq{
@@ -303,6 +303,8 @@
     name VARCHAR(255) UNIQUE NOT NULL,
     path VARCHAR(255) NOT NULL,
+    allocate BOOLEAN DEFAULT FALSE,
     PRIMARY KEY(vol_id),
-    KEY(name(16))
+    KEY(name(16)),
+    KEY(allocate)
 ) ENGINE=innodb;
 
@@ -335,5 +337,6 @@
     DECLARE namevar VARCHAR(255);
     DECLARE pathvar VARCHAR(255);
-    DECLARE cur1 CURSOR FOR SELECT vol_id, name, path FROM volume;
+    DECLARE cur1 CURSOR FOR SELECT vol_id, name, path FROM volume
+        WHERE allocate = TRUE;
     DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE;
 
Index: /trunk/Nebulous/t/03_server_create_object.t
===================================================================
--- /trunk/Nebulous/t/03_server_create_object.t	(revision 13129)
+++ /trunk/Nebulous/t/03_server_create_object.t	(revision 13130)
@@ -3,10 +3,10 @@
 # Copryight (C) 2004-2005  Joshua Hoblitt
 #
-# $Id: 03_server_create_object.t,v 1.13 2007-05-01 02:52:04 jhoblitt Exp $
+# $Id: 03_server_create_object.t,v 1.14 2007-05-02 20:14:46 jhoblitt Exp $
 
 use strict;
 use warnings FATAL => qw( all );
 
-use Test::More tests => 8;
+use Test::More tests => 10;
 
 use lib qw( ./t ./lib );
@@ -57,4 +57,18 @@
 
 eval {
+    $neb->create_object("foo", 'node03');
+};
+like($@, qr/node03 is not available/, "request volume with allocate = FALSE");
+
+Test::Nebulous->setup;
+
+eval {
+    $neb->create_object("foo", 'node04');
+};
+like($@, qr/node04 is not available/, "request volume this is full");
+
+Test::Nebulous->setup;
+
+eval {
     $neb->create_object("foo", 99);
 };
Index: /trunk/Nebulous/t/Test/Nebulous.pm
===================================================================
--- /trunk/Nebulous/t/Test/Nebulous.pm	(revision 13129)
+++ /trunk/Nebulous/t/Test/Nebulous.pm	(revision 13130)
@@ -1,5 +1,5 @@
 # Copyright (C) 2004  Joshua Hoblitt
 #
-# $Id: Nebulous.pm,v 1.12 2007-05-02 00:59:33 jhoblitt Exp $
+# $Id: Nebulous.pm,v 1.13 2007-05-02 20:14:46 jhoblitt Exp $
 
 package Test::Nebulous;
@@ -22,4 +22,6 @@
 my $dir1 = "";
 my $dir2 = "";
+my $dir3 = "";
+my $dir4 = "";
 
 sub setup {
@@ -31,4 +33,6 @@
     $dir1 = tempdir( CLEANUP => 0 );
     $dir2 = tempdir( CLEANUP => 0 );
+    $dir3 = tempdir( CLEANUP => 0 );
+    $dir4 = tempdir( CLEANUP => 0 );
 
     foreach my $statement (@{ $sql->get_db_schema }) {
@@ -36,10 +40,18 @@
     }
 
-    # FIXME
-    $dbh->do(qq{ INSERT INTO volume VALUES (1, 'node01',?) }, undef, $dir1);
+    # node01/node02: allocate = TRUE
+    $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate) VALUES (1, 'node01', ?, TRUE) }, undef, $dir1);
     $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir1);
 
-    $dbh->do(qq{ INSERT INTO volume VALUES (2,'node02',?) }, undef, $dir2);
+    $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate) VALUES (2, 'node02', ?, TRUE) }, undef, $dir2);
     $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e8) }, undef, $dir2);
+
+    # node03: allocate = FALSE
+    $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate) VALUES (3, 'node03', ?, FALSE) }, undef, $dir3);
+    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e8) }, undef, $dir3);
+
+    # node04: allocate = TRUE, volume full
+    $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate) VALUES (4, 'node04', ?, TRUE) }, undef, $dir4);
+    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e10) }, undef, $dir4);
 }
 
@@ -52,4 +64,6 @@
     rmtree([$dir1], 0, 1) if -e $dir1;
     rmtree([$dir2], 0, 1) if -e $dir2;
+    rmtree([$dir3], 0, 1) if -e $dir3;
+    rmtree([$dir4], 0, 1) if -e $dir4;
 }
 
