Changeset 16265
- Timestamp:
- Jan 30, 2008, 4:26:33 PM (18 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
-
Nebulous-Server/lib/Nebulous/Server.pm (modified) (11 diffs)
-
Nebulous-Server/lib/Nebulous/Server/SQL.pm (modified) (3 diffs)
-
Nebulous-Server/t/03_server_create_object.t (modified) (3 diffs)
-
Nebulous/lib/Nebulous/Server.pm (modified) (11 diffs)
-
Nebulous/lib/Nebulous/Server/SQL.pm (modified) (3 diffs)
-
Nebulous/t/03_server_create_object.t (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/lib/Nebulous/Server.pm
r16244 r16265 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1.5 0 2008-01-26 02:04:46jhoblitt Exp $3 # $Id: Server.pm,v 1.51 2008-01-31 02:26:33 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 161 161 my $volume; 162 162 ($volume, $key) = parse_neb_key($key); 163 if (defined $volume) { 164 die "$volume is not a valid volume name" 165 unless $self->_is_valid_volume_name($volume); 166 } 163 # vol_name overrides the key implied volume 167 164 $vol_name ||= $volume; 168 169 } 170 171 my ($uri, $vol_id); 165 } 166 167 if (defined $vol_name and !$self->_is_valid_volume_name($vol_name)) { 168 die "$vol_name is not a valid volume name" 169 } 170 171 my ($vol_id, $vol_path, $vol_xattr) = $self->_get_storage_volume($vol_name); 172 173 my $uri; 172 174 eval { 173 175 { … … 177 179 } 178 180 179 my $ object_id;181 my $so_id; 180 182 { 181 183 # get object ID 182 184 my $query = $db->prepare_cached( $sql->last_insert_id ); 183 185 $query->execute; 184 ($ object_id) = $query->fetchrow_array;186 ($so_id) = $query->fetchrow_array; 185 187 # XXX finish seems to be required when using LAST_INSERT_ID() or we 186 188 # get a warning about the stmt handling still be active the next … … 192 194 # create storage_object_attr 193 195 my $query = $db->prepare_cached( $sql->new_object_attr ); 194 $query->execute($ object_id);196 $query->execute($so_id); 195 197 } 196 198 … … 198 200 # create instance with no URI 199 201 my $query = $db->prepare_cached( $sql->new_object_instance ); 200 $query->execute ;202 $query->execute($vol_id); 201 203 } 202 204 … … 218 220 219 221 # TODO add some stuff here to retry if unsucessful 220 ($uri, $vol_id) = $self->_create_empty_instance_file($key, $ins_id, $vol_name);222 $uri = $self->_create_empty_instance_file($key, $so_id, $ins_id, $vol_path, $vol_xattr); 221 223 $log->debug("created $uri on volume ID: $vol_id"); 222 224 … … 328 330 my $volume; 329 331 ($volume, $key) = parse_neb_key($key); 330 if (defined $volume) { 331 die "$volume is not a valid volume name" 332 unless $self->_is_valid_volume_name($volume); 333 } 332 # vol_name overrides the key implied volume 334 333 $vol_name ||= $volume; 335 334 } 336 335 337 my ($uri, $vol_id); 336 if (defined $vol_name and !$self->_is_valid_volume_name($vol_name)) { 337 die "$vol_name is not a valid volume name" 338 } 339 340 my ($vol_id, $vol_path, $vol_xattr) = $self->_get_storage_volume($vol_name); 341 342 my $uri; 338 343 eval { 339 344 my $so_id; … … 355 360 { 356 361 my $query = $db->prepare_cached( $sql->new_instance ); 357 $query->execute($so_id );362 $query->execute($so_id, $vol_id); 358 363 } 359 364 … … 374 379 375 380 # TODO add some stuff here to retry if unsucessful 376 ($uri, $vol_id) = $self->_create_empty_instance_file($key, $ins_id, $vol_name);381 $uri = $self->_create_empty_instance_file($key, $so_id, $ins_id, $vol_path, $vol_xattr); 377 382 378 383 { … … 1211 1216 my $self = shift; 1212 1217 1213 my ($key, $ins_id, $volume) = @_; 1214 1215 my $log = $self->log; 1216 my $sql = $self->sql; 1217 my $db =$self->db; 1218 1219 # Find the storage volume to use. 1220 # ->_get_storage_volume() throws an exception on failure. 1221 my ($vol_id, $vol_path, $xattr); 1218 my ($key, $so_id, $ins_id, $vol_path, $xattr) = @_; 1219 1220 my $log = $self->log; 1221 my $sql = $self->sql; 1222 my $db =$self->db; 1223 1222 1224 my ($storage_filename); 1223 1225 my ($uri); 1224 1226 eval { 1225 ($vol_id, $vol_path, $xattr) = $self->_get_storage_volume($volume);1226 1227 $storage_filename = $self->_generate_storage_filename($key, $ins_id); 1227 1228 # XXX put a hook for directory hashing here … … 1240 1241 } 1241 1242 1242 return ($uri, $vol_id);1243 return $uri; 1243 1244 } 1244 1245 -
trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
r16264 r16265 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1.4 6 2008-01-30 00:19:06jhoblitt Exp $3 # $Id: SQL.pm,v 1.47 2008-01-31 02:26:33 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 40 40 new_object_instance => qq{ 41 41 INSERT INTO instance 42 VALUES (NULL, LAST_INSERT_ID(), 0, 'error', NULL, NULL, NULL, NULL)42 VALUES (NULL, LAST_INSERT_ID(), ?, 'error', NULL, NULL, NULL, NULL) 43 43 }, 44 44 new_instance => qq{ 45 45 INSERT INTO instance 46 VALUES (NULL, ?, 0, 'error', NULL,NULL, NULL, NULL)46 VALUES (NULL, ?, ?, 'error', NULL, NULL, NULL, NULL) 47 47 }, 48 48 get_object => qq{ … … 253 253 count(mountedvol.vol_id) > 0 as recoverable 254 254 FROM storage_object 255 JOIN storage_object_attr 256 USING(so_id) 257 JOIN storage_object_xattr 258 ON storage_object.so_id = storage_object_xattr.so_id 259 AND storage_object_xattr.name = 'copies' 255 260 JOIN instance 256 261 USING(so_id) -
trunk/Nebulous-Server/t/03_server_create_object.t
r16223 r16265 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 03_server_create_object.t,v 1.2 2 2008-01-25 02:06:08jhoblitt Exp $5 # $Id: 03_server_create_object.t,v 1.23 2008-01-31 02:26:33 jhoblitt Exp $ 6 6 7 7 use strict; 8 8 use warnings FATAL => qw( all ); 9 9 10 use Test::More tests => 6 5;10 use Test::More tests => 67; 11 11 12 12 use lib qw( ./t ./lib ); … … 239 239 Test::Nebulous->setup; 240 240 241 { 242 # volume name override 243 # OK because the volume arg overrides the key's implied volume 244 my $uri = $neb->create_object("neb://99/foo", "node01"); 245 246 my ($scheme, $auth, $path, $query, $frag) = uri_split($uri); 247 ok(-e $path, "file exists"); 248 ok($neb->find_instances("foo"), 'object key exists'); 249 uri_scheme_ok($uri, 'file'); 250 } 251 252 Test::Nebulous->setup; 253 241 254 eval { 242 255 $neb->create_object("foo"); … … 326 339 327 340 eval { 328 # volume name override329 $neb->create_object("neb://99/foo", "node01");330 };331 like($@, qr/is not a valid volume name/, "volume name doesn't exist");332 333 Test::Nebulous->setup;334 335 eval {336 341 $neb->create_object(); 337 342 }; -
trunk/Nebulous/lib/Nebulous/Server.pm
r16244 r16265 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1.5 0 2008-01-26 02:04:46jhoblitt Exp $3 # $Id: Server.pm,v 1.51 2008-01-31 02:26:33 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 161 161 my $volume; 162 162 ($volume, $key) = parse_neb_key($key); 163 if (defined $volume) { 164 die "$volume is not a valid volume name" 165 unless $self->_is_valid_volume_name($volume); 166 } 163 # vol_name overrides the key implied volume 167 164 $vol_name ||= $volume; 168 169 } 170 171 my ($uri, $vol_id); 165 } 166 167 if (defined $vol_name and !$self->_is_valid_volume_name($vol_name)) { 168 die "$vol_name is not a valid volume name" 169 } 170 171 my ($vol_id, $vol_path, $vol_xattr) = $self->_get_storage_volume($vol_name); 172 173 my $uri; 172 174 eval { 173 175 { … … 177 179 } 178 180 179 my $ object_id;181 my $so_id; 180 182 { 181 183 # get object ID 182 184 my $query = $db->prepare_cached( $sql->last_insert_id ); 183 185 $query->execute; 184 ($ object_id) = $query->fetchrow_array;186 ($so_id) = $query->fetchrow_array; 185 187 # XXX finish seems to be required when using LAST_INSERT_ID() or we 186 188 # get a warning about the stmt handling still be active the next … … 192 194 # create storage_object_attr 193 195 my $query = $db->prepare_cached( $sql->new_object_attr ); 194 $query->execute($ object_id);196 $query->execute($so_id); 195 197 } 196 198 … … 198 200 # create instance with no URI 199 201 my $query = $db->prepare_cached( $sql->new_object_instance ); 200 $query->execute ;202 $query->execute($vol_id); 201 203 } 202 204 … … 218 220 219 221 # TODO add some stuff here to retry if unsucessful 220 ($uri, $vol_id) = $self->_create_empty_instance_file($key, $ins_id, $vol_name);222 $uri = $self->_create_empty_instance_file($key, $so_id, $ins_id, $vol_path, $vol_xattr); 221 223 $log->debug("created $uri on volume ID: $vol_id"); 222 224 … … 328 330 my $volume; 329 331 ($volume, $key) = parse_neb_key($key); 330 if (defined $volume) { 331 die "$volume is not a valid volume name" 332 unless $self->_is_valid_volume_name($volume); 333 } 332 # vol_name overrides the key implied volume 334 333 $vol_name ||= $volume; 335 334 } 336 335 337 my ($uri, $vol_id); 336 if (defined $vol_name and !$self->_is_valid_volume_name($vol_name)) { 337 die "$vol_name is not a valid volume name" 338 } 339 340 my ($vol_id, $vol_path, $vol_xattr) = $self->_get_storage_volume($vol_name); 341 342 my $uri; 338 343 eval { 339 344 my $so_id; … … 355 360 { 356 361 my $query = $db->prepare_cached( $sql->new_instance ); 357 $query->execute($so_id );362 $query->execute($so_id, $vol_id); 358 363 } 359 364 … … 374 379 375 380 # TODO add some stuff here to retry if unsucessful 376 ($uri, $vol_id) = $self->_create_empty_instance_file($key, $ins_id, $vol_name);381 $uri = $self->_create_empty_instance_file($key, $so_id, $ins_id, $vol_path, $vol_xattr); 377 382 378 383 { … … 1211 1216 my $self = shift; 1212 1217 1213 my ($key, $ins_id, $volume) = @_; 1214 1215 my $log = $self->log; 1216 my $sql = $self->sql; 1217 my $db =$self->db; 1218 1219 # Find the storage volume to use. 1220 # ->_get_storage_volume() throws an exception on failure. 1221 my ($vol_id, $vol_path, $xattr); 1218 my ($key, $so_id, $ins_id, $vol_path, $xattr) = @_; 1219 1220 my $log = $self->log; 1221 my $sql = $self->sql; 1222 my $db =$self->db; 1223 1222 1224 my ($storage_filename); 1223 1225 my ($uri); 1224 1226 eval { 1225 ($vol_id, $vol_path, $xattr) = $self->_get_storage_volume($volume);1226 1227 $storage_filename = $self->_generate_storage_filename($key, $ins_id); 1227 1228 # XXX put a hook for directory hashing here … … 1240 1241 } 1241 1242 1242 return ($uri, $vol_id);1243 return $uri; 1243 1244 } 1244 1245 -
trunk/Nebulous/lib/Nebulous/Server/SQL.pm
r16264 r16265 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1.4 6 2008-01-30 00:19:06jhoblitt Exp $3 # $Id: SQL.pm,v 1.47 2008-01-31 02:26:33 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 40 40 new_object_instance => qq{ 41 41 INSERT INTO instance 42 VALUES (NULL, LAST_INSERT_ID(), 0, 'error', NULL, NULL, NULL, NULL)42 VALUES (NULL, LAST_INSERT_ID(), ?, 'error', NULL, NULL, NULL, NULL) 43 43 }, 44 44 new_instance => qq{ 45 45 INSERT INTO instance 46 VALUES (NULL, ?, 0, 'error', NULL,NULL, NULL, NULL)46 VALUES (NULL, ?, ?, 'error', NULL, NULL, NULL, NULL) 47 47 }, 48 48 get_object => qq{ … … 253 253 count(mountedvol.vol_id) > 0 as recoverable 254 254 FROM storage_object 255 JOIN storage_object_attr 256 USING(so_id) 257 JOIN storage_object_xattr 258 ON storage_object.so_id = storage_object_xattr.so_id 259 AND storage_object_xattr.name = 'copies' 255 260 JOIN instance 256 261 USING(so_id) -
trunk/Nebulous/t/03_server_create_object.t
r16223 r16265 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 03_server_create_object.t,v 1.2 2 2008-01-25 02:06:08jhoblitt Exp $5 # $Id: 03_server_create_object.t,v 1.23 2008-01-31 02:26:33 jhoblitt Exp $ 6 6 7 7 use strict; 8 8 use warnings FATAL => qw( all ); 9 9 10 use Test::More tests => 6 5;10 use Test::More tests => 67; 11 11 12 12 use lib qw( ./t ./lib ); … … 239 239 Test::Nebulous->setup; 240 240 241 { 242 # volume name override 243 # OK because the volume arg overrides the key's implied volume 244 my $uri = $neb->create_object("neb://99/foo", "node01"); 245 246 my ($scheme, $auth, $path, $query, $frag) = uri_split($uri); 247 ok(-e $path, "file exists"); 248 ok($neb->find_instances("foo"), 'object key exists'); 249 uri_scheme_ok($uri, 'file'); 250 } 251 252 Test::Nebulous->setup; 253 241 254 eval { 242 255 $neb->create_object("foo"); … … 326 339 327 340 eval { 328 # volume name override329 $neb->create_object("neb://99/foo", "node01");330 };331 like($@, qr/is not a valid volume name/, "volume name doesn't exist");332 333 Test::Nebulous->setup;334 335 eval {336 341 $neb->create_object(); 337 342 };
Note:
See TracChangeset
for help on using the changeset viewer.
