IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23854


Ignore:
Timestamp:
Apr 14, 2009, 11:12:04 AM (17 years ago)
Author:
jhoblitt
Message:

change 'log_level' param to 'trace'
refactor ->find_objects() functionality

Location:
branches/neb_distrib_20081210/Nebulous-Server
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/neb_distrib_20081210/Nebulous-Server/Changes

    r23852 r23854  
    1414    - create a pseduo directory structure on key creation
    1515    - Nebulous::Key parsing and testing improvements
     16    - change 'log_level' param to 'trace'
     17    - refactor ->find_objects() functionality
    1618     
    17190.16
  • branches/neb_distrib_20081210/Nebulous-Server/lib/Nebulous/Server.pm

    r23772 r23854  
    1919use File::Path;
    2020use File::Spec;
    21 use Log::Log4perl;
     21use Log::Log4perl qw( :levels );
    2222use Nebulous::Key qw( parse_neb_key parse_neb_volume );
    2323use Nebulous::Server::Config;
     
    5050    Nebulous::Server::Log->init($config);
    5151    my $log = Log::Log4perl::get_logger( "Nebulous::Server" );
     52    $log->level($config->trace);
    5253
    5354    my $sql = Nebulous::Server::SQL->new;
     
    310311                default     => undef,
    311312            },
     313            # return dir_id instead of parent_id
     314            dir_id  => {
     315                type        => BOOLEAN,
     316                optional    => 1,
     317                default     => undef,
     318            },
    312319        }
    313320    );
     
    318325    my $sql = $self->sql;
    319326    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 '';
    320332
    321333    # resolve parent directory
     
    324336    # File::Spec->splitpath was causing ->splitdir to always an extra dir
    325337    # 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    }
    327343    # dirname returns "." if there is no dir component to the path, we have
    328344    # to filter this out
    329345    @dirs = grep(!/^\.$/, @dirs);
    330346
     347    $log->debug("looking for dirs - ", join(" : ", @dirs), "\n");
     348
    331349    # start at the root dir; '/' == 1
    332350    my $parent_id = 1;
     351    my $dir_id;
    333352TRANS: while (1) {
    334353        eval {
    335354            foreach my $dir (@dirs) {
    336                 my $dir_id;
     355                $dir_id = undef;
    337356                {
    338357                    my $query = $db->prepare_cached($sql->get_directory);
     
    340359                    if ($query->rows) {
    341360                        $dir_id = $query->fetchrow_hashref->{'dir_id'};
     361                        $log->debug("resolved $dir to dir_id: $dir_id");
    342362                    }
    343363                    $query->finish;
     
    392412    }
    393413
    394     return $parent_id;
     414    $log->debug("leaving");
     415
     416    return $p{dir_id} ? $dir_id : $parent_id;
    395417}
    396418
     
    12301252    my $db  = $self->_db_for_index($index);
    12311253
     1254    $log->debug( "entered - @_" );
     1255
    12321256    # first check to see if the key is an exact match
     1257    my @keys;
    12331258    eval {
     1259        $log->debug("trying for an exact key match with $key");
    12341260        my $query = $db->prepare_cached( $sql->find_object_by_ext_id );
    1235         $query->execute( $key );
     1261        $query->execute( $key->path );
    12361262        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;
    12421270    };
    12431271    if ($@) {
     
    12461274    }
    12471275
     1276    if (scalar @keys) {
     1277        # it was an exact match, so stop here
     1278        $log->debug("leaving");
     1279
     1280        return \@keys;
     1281    }
     1282
    12481283    # 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
    12511289    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 );
    12541293
    12551294        while ( my $row = $query->fetchrow_hashref ) {
    12561295            my $key = $row->{ 'ext_id' };
    12571296            push @keys, $key if $key;
     1297            $log->debug( "matched $key" ) if $key;
    12581298        }
    12591299    };
    12601300    $log->logdie("database error: $@") if $@;
     1301
     1302    $log->debug( "leaving" );
    12611303
    12621304    return \@keys;
     
    17351777        my $mode = [_retry(sub { stat($storage_path) } )]->[2] & 07777;
    17361778        unless ($mode == 0775) {
    1737             $log->error("$storage_path has the wrong permissions of: %04o", $mode);
     1779            $log->error("$storage_path has the wrong permissions of: %04x", $mode);
    17381780            _retry(sub { chmod(0775, $storage_path) }) or die "can't chmod $storage_path: $!";
    17391781        }
  • branches/neb_distrib_20081210/Nebulous-Server/lib/Nebulous/Server/Config.pm

    r23537 r23854  
    3636
    3737my $new_validate = {
    38     log_level   => {
     38    trace       => {
    3939        type        => SCALAR,
    4040        optional    => 1,
    41         default     => 'all',
     41        default     => 'fatal',
    4242        callbacks   => {
    4343            'is valid level' => sub {
     
    6161
    6262    # normalize log levels to lower-case
    63     my $self ={ log_level => lc $p{ log_level } };
     63    my $self = { trace => $LEVELS{lc($p{trace})} };
    6464
    6565    bless $self, $class || ref $class;
  • branches/neb_distrib_20081210/Nebulous-Server/lib/Nebulous/Server/SQL.pm

    r23772 r23854  
    314314        WHERE ext_id = ?
    315315    },
     316    find_object_by_dir_id => qq{
     317        SELECT ext_id, ext_id_basename
     318        FROM storage_object
     319        WHERE dir_id = ?
     320    },
    316321    rename_object => qq{
    317322        UPDATE storage_object
  • branches/neb_distrib_20081210/Nebulous-Server/t/02_server_setup.t

    r23537 r23854  
    2323# ->new()
    2424{
    25     my $neb = Nebulous::Server->new( log_level => 'off' );
     25    my $neb = Nebulous::Server->new( trace => 'off' );
    2626
    2727    ok($neb, "set log level");
  • branches/neb_distrib_20081210/Nebulous-Server/t/12_server_find_objects.t

    r17717 r23854  
    88use warnings FATAL => qw( all );
    99
    10 use Test::More tests => 6;
     10use Test::More tests => 15;
    1111
    1212use lib qw( ./t ./lib );
     
    2525# search for a regex of '' should match nothing
    2626eval {
    27     # key
    28     my $uri = $neb->create_object("foo");
     27    $neb->create_object("foo");
    2928
    3029    my $keys = $neb->find_objects();
     
    3534
    3635{
    37     # key
    38     my $uri = $neb->create_object("foo");
     36    $neb->create_object("foo");
    3937
    4038    my $keys = $neb->find_objects("foo");
     
    4846{
    4947    # 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");
    5250
    5351    my $keys = $neb->find_objects("foo");
     
    5553    is(scalar @$keys, 1, 'number of keys found');
    5654    is($keys->[0], "foo", "key name");
     55}
     56
     57# test recursive dir searching
     58Test::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
     69Test::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
     82Test::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
     94Test::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");
    57104}
    58105
Note: See TracChangeset for help on using the changeset viewer.