Changeset 13130
- Timestamp:
- May 2, 2007, 10:14:46 AM (19 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
-
Nebulous-Server/lib/Nebulous/Server.pm (modified) (5 diffs)
-
Nebulous-Server/lib/Nebulous/Server/SQL.pm (modified) (4 diffs)
-
Nebulous-Server/t/03_server_create_object.t (modified) (2 diffs)
-
Nebulous/lib/Nebulous/Server.pm (modified) (5 diffs)
-
Nebulous/lib/Nebulous/Server/SQL.pm (modified) (4 diffs)
-
Nebulous/t/03_server_create_object.t (modified) (2 diffs)
-
Nebulous/t/Test/Nebulous.pm (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/lib/Nebulous/Server.pm
r13115 r13130 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1. 29 2007-05-02 01:00:10jhoblitt Exp $3 # $Id: Server.pm,v 1.30 2007-05-02 20:14:45 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 166 166 { 167 167 # get object ID 168 my $query = $db->prepare ( $sql->last_insert_id );168 my $query = $db->prepare_cached( $sql->last_insert_id ); 169 169 $query->execute; 170 170 ($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; 171 175 } 172 176 … … 185 189 { 186 190 # get instance ID 187 my $query = $db->prepare ( $sql->last_insert_id );191 my $query = $db->prepare_cached( $sql->last_insert_id ); 188 192 $query->execute; 189 193 ($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; 190 198 } 191 199 }; … … 322 330 323 331 { 324 my $query = $db->prepare ( $sql->last_insert_id );332 my $query = $db->prepare_cached( $sql->last_insert_id ); 325 333 $query->execute(); 326 327 334 ($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; 328 339 } 329 340 }; … … 1041 1052 $query = $db->prepare_cached( $sql->get_storage_volume_byname ); 1042 1053 $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 } 1043 1063 } else { 1044 1064 $query = $db->prepare_cached( $sql->get_storage_volume ); 1045 1065 $rows = $query->execute(0.95); 1046 }1047 1048 # there has to be atleast one storage volume1049 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 } 1051 1071 } 1052 1072 -
trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
r13115 r13130 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1.3 1 2007-05-02 01:00:10jhoblitt Exp $3 # $Id: SQL.pm,v 1.32 2007-05-02 20:14:46 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 176 176 }, 177 177 new_volume => qq{ 178 INSERT INTO volume (name, path )179 VALUES (?, ? )178 INSERT INTO volume (name, path, allocate) 179 VALUES (?, ?, TRUE) 180 180 }, 181 181 get_volume_by_name => qq{ … … 303 303 name VARCHAR(255) UNIQUE NOT NULL, 304 304 path VARCHAR(255) NOT NULL, 305 allocate BOOLEAN DEFAULT FALSE, 305 306 PRIMARY KEY(vol_id), 306 KEY(name(16)) 307 KEY(name(16)), 308 KEY(allocate) 307 309 ) ENGINE=innodb; 308 310 … … 335 337 DECLARE namevar VARCHAR(255); 336 338 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; 338 341 DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE; 339 342 -
trunk/Nebulous-Server/t/03_server_create_object.t
r13092 r13130 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 03_server_create_object.t,v 1.1 3 2007-05-01 02:52:04jhoblitt Exp $5 # $Id: 03_server_create_object.t,v 1.14 2007-05-02 20:14:46 jhoblitt Exp $ 6 6 7 7 use strict; 8 8 use warnings FATAL => qw( all ); 9 9 10 use Test::More tests => 8;10 use Test::More tests => 10; 11 11 12 12 use lib qw( ./t ./lib ); … … 57 57 58 58 eval { 59 $neb->create_object("foo", 'node03'); 60 }; 61 like($@, qr/node03 is not available/, "request volume with allocate = FALSE"); 62 63 Test::Nebulous->setup; 64 65 eval { 66 $neb->create_object("foo", 'node04'); 67 }; 68 like($@, qr/node04 is not available/, "request volume this is full"); 69 70 Test::Nebulous->setup; 71 72 eval { 59 73 $neb->create_object("foo", 99); 60 74 }; -
trunk/Nebulous/lib/Nebulous/Server.pm
r13115 r13130 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1. 29 2007-05-02 01:00:10jhoblitt Exp $3 # $Id: Server.pm,v 1.30 2007-05-02 20:14:45 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 166 166 { 167 167 # get object ID 168 my $query = $db->prepare ( $sql->last_insert_id );168 my $query = $db->prepare_cached( $sql->last_insert_id ); 169 169 $query->execute; 170 170 ($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; 171 175 } 172 176 … … 185 189 { 186 190 # get instance ID 187 my $query = $db->prepare ( $sql->last_insert_id );191 my $query = $db->prepare_cached( $sql->last_insert_id ); 188 192 $query->execute; 189 193 ($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; 190 198 } 191 199 }; … … 322 330 323 331 { 324 my $query = $db->prepare ( $sql->last_insert_id );332 my $query = $db->prepare_cached( $sql->last_insert_id ); 325 333 $query->execute(); 326 327 334 ($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; 328 339 } 329 340 }; … … 1041 1052 $query = $db->prepare_cached( $sql->get_storage_volume_byname ); 1042 1053 $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 } 1043 1063 } else { 1044 1064 $query = $db->prepare_cached( $sql->get_storage_volume ); 1045 1065 $rows = $query->execute(0.95); 1046 }1047 1048 # there has to be atleast one storage volume1049 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 } 1051 1071 } 1052 1072 -
trunk/Nebulous/lib/Nebulous/Server/SQL.pm
r13115 r13130 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1.3 1 2007-05-02 01:00:10jhoblitt Exp $3 # $Id: SQL.pm,v 1.32 2007-05-02 20:14:46 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 176 176 }, 177 177 new_volume => qq{ 178 INSERT INTO volume (name, path )179 VALUES (?, ? )178 INSERT INTO volume (name, path, allocate) 179 VALUES (?, ?, TRUE) 180 180 }, 181 181 get_volume_by_name => qq{ … … 303 303 name VARCHAR(255) UNIQUE NOT NULL, 304 304 path VARCHAR(255) NOT NULL, 305 allocate BOOLEAN DEFAULT FALSE, 305 306 PRIMARY KEY(vol_id), 306 KEY(name(16)) 307 KEY(name(16)), 308 KEY(allocate) 307 309 ) ENGINE=innodb; 308 310 … … 335 337 DECLARE namevar VARCHAR(255); 336 338 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; 338 341 DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE; 339 342 -
trunk/Nebulous/t/03_server_create_object.t
r13092 r13130 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 03_server_create_object.t,v 1.1 3 2007-05-01 02:52:04jhoblitt Exp $5 # $Id: 03_server_create_object.t,v 1.14 2007-05-02 20:14:46 jhoblitt Exp $ 6 6 7 7 use strict; 8 8 use warnings FATAL => qw( all ); 9 9 10 use Test::More tests => 8;10 use Test::More tests => 10; 11 11 12 12 use lib qw( ./t ./lib ); … … 57 57 58 58 eval { 59 $neb->create_object("foo", 'node03'); 60 }; 61 like($@, qr/node03 is not available/, "request volume with allocate = FALSE"); 62 63 Test::Nebulous->setup; 64 65 eval { 66 $neb->create_object("foo", 'node04'); 67 }; 68 like($@, qr/node04 is not available/, "request volume this is full"); 69 70 Test::Nebulous->setup; 71 72 eval { 59 73 $neb->create_object("foo", 99); 60 74 }; -
trunk/Nebulous/t/Test/Nebulous.pm
r13114 r13130 1 1 # Copyright (C) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Nebulous.pm,v 1.1 2 2007-05-02 00:59:33jhoblitt Exp $3 # $Id: Nebulous.pm,v 1.13 2007-05-02 20:14:46 jhoblitt Exp $ 4 4 5 5 package Test::Nebulous; … … 22 22 my $dir1 = ""; 23 23 my $dir2 = ""; 24 my $dir3 = ""; 25 my $dir4 = ""; 24 26 25 27 sub setup { … … 31 33 $dir1 = tempdir( CLEANUP => 0 ); 32 34 $dir2 = tempdir( CLEANUP => 0 ); 35 $dir3 = tempdir( CLEANUP => 0 ); 36 $dir4 = tempdir( CLEANUP => 0 ); 33 37 34 38 foreach my $statement (@{ $sql->get_db_schema }) { … … 36 40 } 37 41 38 # FIXME39 $dbh->do(qq{ INSERT INTO volume VALUES (1, 'node01',?) }, undef, $dir1);42 # node01/node02: allocate = TRUE 43 $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate) VALUES (1, 'node01', ?, TRUE) }, undef, $dir1); 40 44 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir1); 41 45 42 $dbh->do(qq{ INSERT INTO volume VALUES (2,'node02',?) }, undef, $dir2);46 $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate) VALUES (2, 'node02', ?, TRUE) }, undef, $dir2); 43 47 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e8) }, undef, $dir2); 48 49 # node03: allocate = FALSE 50 $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate) VALUES (3, 'node03', ?, FALSE) }, undef, $dir3); 51 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e8) }, undef, $dir3); 52 53 # node04: allocate = TRUE, volume full 54 $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate) VALUES (4, 'node04', ?, TRUE) }, undef, $dir4); 55 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e10) }, undef, $dir4); 44 56 } 45 57 … … 52 64 rmtree([$dir1], 0, 1) if -e $dir1; 53 65 rmtree([$dir2], 0, 1) if -e $dir2; 66 rmtree([$dir3], 0, 1) if -e $dir3; 67 rmtree([$dir4], 0, 1) if -e $dir4; 54 68 } 55 69
Note:
See TracChangeset
for help on using the changeset viewer.
