Changeset 18400 for trunk/Nebulous-Server/lib/Nebulous/Server.pm
- Timestamp:
- Jul 1, 2008, 5:40:10 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/Nebulous-Server/lib/Nebulous/Server.pm (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/lib/Nebulous/Server.pm
r18389 r18400 1 1 # Copyright (c) 2004-2008 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1.7 8 2008-07-01 00:28:06jhoblitt Exp $3 # $Id: Server.pm,v 1.79 2008-07-02 03:40:10 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 320 320 type => SCALAR, 321 321 callbacks => { 322 'is valid object key' => sub { $self->_is_valid_object_key($_[0]) }, 322 'is valid object key' 323 => sub { $self->_is_valid_object_key($_[0]) }, 323 324 }, 324 325 }, … … 336 337 ); 337 338 339 # if a volume name is explicity specified then we should make the 340 # replication onto that volume (even if there is alread an instance on that 341 # volume) if at all possible and throw an error if we can not. 342 # if a volume name IS NOT specified then we should make the replication 343 # onto any (hopefully the best) volume that DOES NOT already have an 344 # instance on it. If all avilable volume already have an instance on them 345 # then we should throw an error 346 338 347 my $log = $self->log; 339 348 my $sql = $self->sql; … … 353 362 } 354 363 355 my ($vol_id, $vol_host, $vol_path, $vol_xattr) = $self->_get_storage_volume($vol_name); 364 my ($vol_id, $vol_host, $vol_path, $vol_xattr); 365 if (defined $vol_name) { 366 ($vol_id, $vol_host, $vol_path, $vol_xattr) 367 = $self->_get_storage_volume($vol_name); 368 } else { 369 ($vol_id, $vol_host, $vol_path, $vol_xattr) 370 = $self->_get_replication_volume($key); 371 } 356 372 357 373 my $uri; … … 359 375 my $so_id; 360 376 { 377 # verify that at least one instance is currently available 361 378 my $query = $db->prepare_cached( $sql->get_object_instances ); 362 379 my $rows = $query->execute($key, 1); … … 382 399 ($ins_id) = $query->fetchrow_array; 383 400 # XXX finish seems to be required when using LAST_INSERT_ID() or we 384 # get a warning about the stmt handling still be active the next401 # get a warning about the stmt handling still being active the next 385 402 # time LAST_INSERT_ID() is invoked 386 403 $query->finish; … … 1197 1214 1198 1215 1216 sub _get_replication_volume 1217 { 1218 my $self = shift; 1219 1220 my $log = $self->log; 1221 my $sql = $self->sql; 1222 my $db =$self->db; 1223 1224 no warnings qw( uninitialized ); 1225 $log->debug( "entered - @_" ); 1226 use warnings; 1227 1228 my $key = shift; 1229 1230 my $volume; 1231 ($volume, $key) = parse_neb_key($key); 1232 1233 my ($vol_id, $vol_host, $vol_path, $xattr); 1234 eval { 1235 my $rows; 1236 my $query = $db->prepare_cached( $sql->get_replication_volume_for_ext_id ); 1237 # ext_id, %free, avaiable, allocate 1238 $rows = $query->execute($key, 0.95, 1, 1); 1239 # XXX destinguish between non-existant and unaviable 1240 unless ($rows > 0) { 1241 $query->finish; 1242 $log->logdie("can't find a suitable storage volume to replicate $key too"); 1243 } 1244 # when matching by name we shouldn't ever match more than once 1245 if ($rows > 1) { 1246 $query->finish; 1247 $log->logdie("affected row count is $rows instead of 1"); 1248 } 1249 1250 my $free; 1251 ($vol_id, $vol_host, $vol_path, $xattr, $free) = $query->fetchrow_array; 1252 $query->finish; 1253 }; 1254 $log->logdie("database error: $@") if $@; 1255 1256 $log->logdie("failed to find a suitable volume" ) 1257 unless defined $vol_id and defined $vol_path; 1258 1259 $log->debug( "leaving" ); 1260 1261 return ($vol_id, $vol_host, $vol_path, $xattr); 1262 } 1263 1264 1199 1265 sub _is_valid_object_key 1200 1266 {
Note:
See TracChangeset
for help on using the changeset viewer.
