Changeset 23854
- Timestamp:
- Apr 14, 2009, 11:12:04 AM (17 years ago)
- Location:
- branches/neb_distrib_20081210/Nebulous-Server
- Files:
-
- 6 edited
-
Changes (modified) (1 diff)
-
lib/Nebulous/Server.pm (modified) (10 diffs)
-
lib/Nebulous/Server/Config.pm (modified) (2 diffs)
-
lib/Nebulous/Server/SQL.pm (modified) (1 diff)
-
t/02_server_setup.t (modified) (1 diff)
-
t/12_server_find_objects.t (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/neb_distrib_20081210/Nebulous-Server/Changes
r23852 r23854 14 14 - create a pseduo directory structure on key creation 15 15 - Nebulous::Key parsing and testing improvements 16 - change 'log_level' param to 'trace' 17 - refactor ->find_objects() functionality 16 18 17 19 0.16 -
branches/neb_distrib_20081210/Nebulous-Server/lib/Nebulous/Server.pm
r23772 r23854 19 19 use File::Path; 20 20 use File::Spec; 21 use Log::Log4perl ;21 use Log::Log4perl qw( :levels ); 22 22 use Nebulous::Key qw( parse_neb_key parse_neb_volume ); 23 23 use Nebulous::Server::Config; … … 50 50 Nebulous::Server::Log->init($config); 51 51 my $log = Log::Log4perl::get_logger( "Nebulous::Server" ); 52 $log->level($config->trace); 52 53 53 54 my $sql = Nebulous::Server::SQL->new; … … 310 311 default => undef, 311 312 }, 313 # return dir_id instead of parent_id 314 dir_id => { 315 type => BOOLEAN, 316 optional => 1, 317 default => undef, 318 }, 312 319 } 313 320 ); … … 318 325 my $sql = $self->sql; 319 326 my $db = $self->db($key); 327 328 $log->debug( "entered - @_" ); 329 330 # no path means '/', which has a dir_id & parent_id of 1 331 return 1 if $key->path eq ''; 320 332 321 333 # resolve parent directory … … 324 336 # File::Spec->splitpath was causing ->splitdir to always an extra dir 325 337 # named "" because of a trailing / 326 @dirs = File::Spec->splitdir(dirname($key->path)); 338 unless ($p{dir_id}) { 339 @dirs = File::Spec->splitdir(dirname($key->path)); 340 } else { 341 @dirs = File::Spec->splitdir($key->path); 342 } 327 343 # dirname returns "." if there is no dir component to the path, we have 328 344 # to filter this out 329 345 @dirs = grep(!/^\.$/, @dirs); 330 346 347 $log->debug("looking for dirs - ", join(" : ", @dirs), "\n"); 348 331 349 # start at the root dir; '/' == 1 332 350 my $parent_id = 1; 351 my $dir_id; 333 352 TRANS: while (1) { 334 353 eval { 335 354 foreach my $dir (@dirs) { 336 my $dir_id;355 $dir_id = undef; 337 356 { 338 357 my $query = $db->prepare_cached($sql->get_directory); … … 340 359 if ($query->rows) { 341 360 $dir_id = $query->fetchrow_hashref->{'dir_id'}; 361 $log->debug("resolved $dir to dir_id: $dir_id"); 342 362 } 343 363 $query->finish; … … 392 412 } 393 413 394 return $parent_id; 414 $log->debug("leaving"); 415 416 return $p{dir_id} ? $dir_id : $parent_id; 395 417 } 396 418 … … 1230 1252 my $db = $self->_db_for_index($index); 1231 1253 1254 $log->debug( "entered - @_" ); 1255 1232 1256 # first check to see if the key is an exact match 1257 my @keys; 1233 1258 eval { 1259 $log->debug("trying for an exact key match with $key"); 1234 1260 my $query = $db->prepare_cached( $sql->find_object_by_ext_id ); 1235 $query->execute( $key );1261 $query->execute( $key->path ); 1236 1262 if ($query->rows) { 1237 return [$query->fetchrow_hashref->{'ext_id'}]; 1238 } 1239 1240 my $parent_id = $self->_resolve_dir_parent_id(key => $key); 1241 1263 my $ext_id = $query->fetchrow_hashref->{'ext_id'}; 1264 $log->debug( "pattern has an exact match" ); 1265 push @keys, $ext_id; 1266 } else { 1267 $log->debug("no exact match for key"); 1268 } 1269 $query->finish; 1242 1270 }; 1243 1271 if ($@) { … … 1246 1274 } 1247 1275 1276 if (scalar @keys) { 1277 # it was an exact match, so stop here 1278 $log->debug("leaving"); 1279 1280 return \@keys; 1281 } 1282 1248 1283 # else, assume it's a directory 1249 1250 my @keys; 1284 my $dir_id = $self->_resolve_dir_parent_id(key => $key, dir_id => 1); 1285 unless (defined $dir_id) { 1286 $log->logdie("pattern $key does not match any key or directory"); 1287 } 1288 1251 1289 eval { 1252 my $query = $db->prepare_cached( $sql->find_object_by_ext_id ); 1253 $query->execute( $key ); 1290 $log->debug("trying for a directory match under dir: $dir_id"); 1291 my $query = $db->prepare_cached( $sql->find_object_by_dir_id ); 1292 $query->execute( $dir_id ); 1254 1293 1255 1294 while ( my $row = $query->fetchrow_hashref ) { 1256 1295 my $key = $row->{ 'ext_id' }; 1257 1296 push @keys, $key if $key; 1297 $log->debug( "matched $key" ) if $key; 1258 1298 } 1259 1299 }; 1260 1300 $log->logdie("database error: $@") if $@; 1301 1302 $log->debug( "leaving" ); 1261 1303 1262 1304 return \@keys; … … 1735 1777 my $mode = [_retry(sub { stat($storage_path) } )]->[2] & 07777; 1736 1778 unless ($mode == 0775) { 1737 $log->error("$storage_path has the wrong permissions of: %04 o", $mode);1779 $log->error("$storage_path has the wrong permissions of: %04x", $mode); 1738 1780 _retry(sub { chmod(0775, $storage_path) }) or die "can't chmod $storage_path: $!"; 1739 1781 } -
branches/neb_distrib_20081210/Nebulous-Server/lib/Nebulous/Server/Config.pm
r23537 r23854 36 36 37 37 my $new_validate = { 38 log_level=> {38 trace => { 39 39 type => SCALAR, 40 40 optional => 1, 41 default => ' all',41 default => 'fatal', 42 42 callbacks => { 43 43 'is valid level' => sub { … … 61 61 62 62 # normalize log levels to lower-case 63 my $self = { log_level => lc $p{ log_level} };63 my $self = { trace => $LEVELS{lc($p{trace})} }; 64 64 65 65 bless $self, $class || ref $class; -
branches/neb_distrib_20081210/Nebulous-Server/lib/Nebulous/Server/SQL.pm
r23772 r23854 314 314 WHERE ext_id = ? 315 315 }, 316 find_object_by_dir_id => qq{ 317 SELECT ext_id, ext_id_basename 318 FROM storage_object 319 WHERE dir_id = ? 320 }, 316 321 rename_object => qq{ 317 322 UPDATE storage_object -
branches/neb_distrib_20081210/Nebulous-Server/t/02_server_setup.t
r23537 r23854 23 23 # ->new() 24 24 { 25 my $neb = Nebulous::Server->new( log_level=> 'off' );25 my $neb = Nebulous::Server->new( trace => 'off' ); 26 26 27 27 ok($neb, "set log level"); -
branches/neb_distrib_20081210/Nebulous-Server/t/12_server_find_objects.t
r17717 r23854 8 8 use warnings FATAL => qw( all ); 9 9 10 use Test::More tests => 6;10 use Test::More tests => 15; 11 11 12 12 use lib qw( ./t ./lib ); … … 25 25 # search for a regex of '' should match nothing 26 26 eval { 27 # key 28 my $uri = $neb->create_object("foo"); 27 $neb->create_object("foo"); 29 28 30 29 my $keys = $neb->find_objects(); … … 35 34 36 35 { 37 # key 38 my $uri = $neb->create_object("foo"); 36 $neb->create_object("foo"); 39 37 40 38 my $keys = $neb->find_objects("foo"); … … 48 46 { 49 47 # key 50 my $uri1 =$neb->create_object("foo");51 my $uri2 =$neb->replicate_object("foo");48 $neb->create_object("foo"); 49 $neb->replicate_object("foo"); 52 50 53 51 my $keys = $neb->find_objects("foo"); … … 55 53 is(scalar @$keys, 1, 'number of keys found'); 56 54 is($keys->[0], "foo", "key name"); 55 } 56 57 # test recursive dir searching 58 Test::Nebulous->setup; 59 60 { 61 $neb->create_object("a/foo"); 62 63 my $keys = $neb->find_objects("a"); 64 65 is(scalar @$keys, 1, 'number of keys found'); 66 is($keys->[0], "a/foo", "key name"); 67 } 68 69 Test::Nebulous->setup; 70 71 { 72 $neb->create_object("a/foo"); 73 $neb->create_object("a/bar"); 74 75 my $keys = $neb->find_objects("a"); 76 77 is(scalar @$keys, 2, 'number of keys found'); 78 is($keys->[0], "a/foo", "key name"); 79 is($keys->[1], "a/bar", "key name"); 80 } 81 82 Test::Nebulous->setup; 83 84 { 85 $neb->create_object("a/foo"); 86 $neb->create_object("bar"); 87 88 my $keys = $neb->find_objects("a"); 89 90 is(scalar @$keys, 1, 'number of keys found'); 91 is($keys->[0], "a/foo", "key name"); 92 } 93 94 Test::Nebulous->setup; 95 96 { 97 $neb->create_object("a/foo"); 98 $neb->create_object("bar"); 99 100 my $keys = $neb->find_objects(".."); 101 102 is(scalar @$keys, 1, 'number of keys found'); 103 is($keys->[0], "bar", "key name"); 57 104 } 58 105
Note:
See TracChangeset
for help on using the changeset viewer.
