Changeset 18400
- Timestamp:
- Jul 1, 2008, 5:40:10 PM (18 years ago)
- Location:
- trunk/Nebulous-Server
- Files:
-
- 4 edited
-
Changes (modified) (1 diff)
-
lib/Nebulous/Server.pm (modified) (7 diffs)
-
lib/Nebulous/Server/SQL.pm (modified) (2 diffs)
-
t/07_server_find_instances.t (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/Changes
r18387 r18400 2 2 3 3 0.13 4 - add "smart" storage volume selection when ->replicate_object() is invoked without a target volume name 4 5 - add volume.host field 5 6 - add --host option to neb-initdb -
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 { -
trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
r18388 r18400 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1. 59 2008-06-30 23:26:16jhoblitt Exp $3 # $Id: SQL.pm,v 1.60 2008-07-02 03:40:10 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 211 211 AND available = ? 212 212 AND allocate = ? 213 ORDER BY free DESC 214 LIMIT 1 215 }, 216 get_replication_volume_for_ext_id => qq{ 217 SELECT 218 vol_id, 219 host, 220 path, 221 xattr, 222 total - used as free 223 FROM ( 224 -- This query works but is slow... 225 -- SELECT 226 -- mountedvol.* 227 -- FROM mountedvol 228 -- WHERE 229 -- vol_id NOT IN( 230 -- SELECT vol_id 231 -- FROM storage_object 232 -- JOIN instance 233 -- USING(so_id) 234 -- WHERE ext_id = -- 235 -- ) 236 SELECT 237 m.* 238 FROM mountedvol AS m 239 LEFT JOIN instance AS i 240 ON m.vol_id = i.vol_id 241 AND i.so_id = ( 242 SELECT so_id 243 FROM storage_object 244 WHERE ext_id = ? 245 ) 246 WHERE 247 i.vol_id IS NULL 248 ) as Foo 249 WHERE 250 used / total < ? 251 AND available = ? 252 AND allocate = ? 213 253 ORDER BY free DESC 214 254 LIMIT 1 -
trunk/Nebulous-Server/t/07_server_find_instances.t
r17753 r18400 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 07_server_find_instances.t,v 1.1 2 2008-05-20 01:47:08jhoblitt Exp $5 # $Id: 07_server_find_instances.t,v 1.13 2008-07-02 03:40:10 jhoblitt Exp $ 6 6 7 7 use strict; … … 91 91 my $uri2 = $neb->replicate_object("foo"); 92 92 93 my $locations = $neb->find_instances("foo", " node01");93 my $locations = $neb->find_instances("foo", ":any"); 94 94 95 95 uri_scheme_ok($locations->[0], 'file');
Note:
See TracChangeset
for help on using the changeset viewer.
