Changeset 13180 for trunk/Nebulous/lib
- Timestamp:
- May 2, 2007, 5:21:28 PM (19 years ago)
- Location:
- trunk/Nebulous/lib/Nebulous
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous/lib/Nebulous/Client.pm
r13092 r13180 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Client.pm,v 1. 29 2007-05-01 02:52:04jhoblitt Exp $3 # $Id: Client.pm,v 1.30 2007-05-03 03:21:28 jhoblitt Exp $ 4 4 5 5 package Nebulous::Client; … … 227 227 my $self = shift; 228 228 229 my ( $key, @params ) = validate_pos(@_,229 my ($key, $vol_name) = validate_pos(@_, 230 230 { 231 231 type => SCALAR, … … 240 240 $log->debug( "entered - @_" ); 241 241 242 # need some way to determine which is the best instance to remove 243 my $locations = $self->find_instances( $key, @params ); 244 unless ( $locations ) { 242 my $locations; 243 # if vol_name is specified we need to stat the file to find out how many 244 # instances there are on all volumes. Otherwise we wouldn't know if it's 245 # safe to remove the last instance on the specified volume. 246 # XXX We need some way to determine which is the best instance to remove 247 if (defined $vol_name) { 248 my @stats = $self->stat($key); 249 my $instances = $stats[6]; 250 if (defined $instances and $instances < 2) { 251 $log->debug("can not cull - not enough instances"); 252 $log->debug("leaving"); 253 254 return; 255 } 256 257 $locations = $self->find_instances($key, $vol_name); 258 unless (scalar @{ $locations }) { 245 259 $log->debug( "no instances" ); 246 260 $log->debug( "leaving" ); 247 261 248 return undef; 249 } 250 251 if ( scalar @{ $locations } < 2 ) { 252 $log->debug( "can not cull - not enough instances" ); 253 $log->debug( "leaving" ); 254 255 return undef; 256 } 257 258 my $uri = $self->delete_instance( $locations->[0] ); 259 260 $log->debug( "leaving" ); 262 return; 263 } 264 } else { 265 $locations = $self->find_instances($key); 266 unless ($locations) { 267 $log->debug("no instances"); 268 $log->debug("leaving"); 269 270 return; 271 } 272 273 if (scalar @{ $locations } < 2) { 274 $log->debug("can not cull - not enough instances"); 275 $log->debug("leaving"); 276 277 return; 278 } 279 } 280 281 my $uri = $self->delete_instance( @$locations[0] ); 282 283 $log->debug("leaving"); 261 284 262 285 return $uri; … … 638 661 my $self = shift; 639 662 640 my ( $uri ) = validate_pos(@_,663 my ($uri) = validate_pos(@_, 641 664 { 642 665 type => SCALAR, -
trunk/Nebulous/lib/Nebulous/Server.pm
r13173 r13180 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1.3 2 2007-05-03 01:44:23jhoblitt Exp $3 # $Id: Server.pm,v 1.33 2007-05-03 03:21:28 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 1021 1021 my ( $key ) = validate_pos( @_, 1022 1022 { 1023 type => SCALAR, 1024 }, 1025 ); 1026 1027 my $log = $self->log; 1028 my $sql = $self->sql; 1029 my $db =$self->db; 1030 1031 $log->debug( "entered - @_" ); 1023 type => SCALAR, 1024 callbacks => { 1025 'is valid object key' => sub { $self->_is_valid_object_key($_[0]) }, 1026 }, 1027 }, 1028 ); 1029 1030 my $log = $self->log; 1031 my $sql = $self->sql; 1032 my $db =$self->db; 1033 1034 $log->debug("entered - @_"); 1032 1035 1033 1036 my $stat; 1034 1037 eval { 1035 my $query = $db->prepare_cached( $sql-> get_object );1036 my $rows = $query->execute( $key);1037 1038 unless ( $rows == 1) {1039 $log->logdie( "no storage object found");1038 my $query = $db->prepare_cached( $sql->stat_object ); 1039 my $rows = $query->execute($key); 1040 1041 unless ($rows == 1) { 1042 $log->logdie("no storage object found"); 1040 1043 } 1041 1044 1042 1045 $stat = $query->fetchrow_arrayref; 1043 1046 $query->finish; 1044 1045 $db->commit;1046 1047 }; 1047 1048 if ( $@ ) { 1048 1049 $db->rollback; 1049 $log->logdie( "database error: $@");1050 } 1051 1052 $log->debug( "leaving");1050 $log->logdie("database error: $@"); 1051 } 1052 1053 $log->debug("leaving"); 1053 1054 1054 1055 return $stat; -
trunk/Nebulous/lib/Nebulous/Server/SQL.pm
r13177 r13180 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1.3 5 2007-05-03 01:49:55jhoblitt Exp $3 # $Id: SQL.pm,v 1.36 2007-05-03 03:21:28 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 53 53 get_object => qq{ 54 54 SELECT 55 s torage_object.so_id,55 so_id, 56 56 ext_id, 57 57 read_lock, … … 63 63 USING (so_id) 64 64 WHERE ext_id = ? 65 }, 66 stat_object => qq{ 67 SELECT 68 storage_object.so_id, 69 storage_object.ext_id, 70 read_lock, 71 write_lock, 72 storage_object_attr.epoch, 73 storage_object_attr.mtime, 74 COUNT(instance.so_id) as instances 75 FROM storage_object 76 JOIN storage_object_attr 77 USING (so_id) 78 JOIN instance 79 USING (so_id) 80 WHERE ext_id = ? 81 GROUP BY storage_object.so_id 65 82 }, 66 83 # Note: this sets an update lock
Note:
See TracChangeset
for help on using the changeset viewer.
