IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13180


Ignore:
Timestamp:
May 2, 2007, 5:21:28 PM (19 years ago)
Author:
jhoblitt
Message:

overhaul Nebulous::Client->cull()
add the number of instances to ->stat_object()

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/lib/Nebulous/Server.pm

    r13173 r13180  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.32 2007-05-03 01:44:23 jhoblitt Exp $
     3# $Id: Server.pm,v 1.33 2007-05-03 03:21:28 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    10211021    my ( $key ) = validate_pos( @_,
    10221022        {
    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 - @_");
    10321035
    10331036    my $stat;
    10341037    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");
    10401043        }
    10411044
    10421045        $stat = $query->fetchrow_arrayref;
    10431046        $query->finish;
    1044 
    1045         $db->commit;
    10461047    };
    10471048    if ( $@ ) {
    10481049        $db->rollback;
    1049         $log->logdie( "database error: $@" );
    1050     }
    1051 
    1052     $log->debug( "leaving" );
     1050        $log->logdie("database error: $@");
     1051    }
     1052
     1053    $log->debug("leaving");
    10531054
    10541055    return $stat;
  • trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm

    r13177 r13180  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SQL.pm,v 1.35 2007-05-03 01:49:55 jhoblitt Exp $
     3# $Id: SQL.pm,v 1.36 2007-05-03 03:21:28 jhoblitt Exp $
    44
    55package Nebulous::Server::SQL;
     
    5353    get_object          => qq{
    5454        SELECT
    55             storage_object.so_id,
     55            so_id,
    5656            ext_id,
    5757            read_lock,
     
    6363        USING (so_id)
    6464        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
    6582    },
    6683    # Note: this sets an update lock
  • trunk/Nebulous-Server/t/09_server_stat_object.t

    r13092 r13180  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 09_server_stat_object.t,v 1.10 2007-05-01 02:52:04 jhoblitt Exp $
     5# $Id: 09_server_stat_object.t,v 1.11 2007-05-03 03:21:28 jhoblitt Exp $
    66
    77use strict;
    88use warnings FATAL => qw( all );
    99
    10 use Test::More tests => 11;
     10use Test::More tests => 12;
    1111
    1212use lib qw( ./t ./lib );
     
    2323
    2424Test::Nebulous->setup;
    25 
    2625{
    27     my $uri = $neb->create_object("foo");
     26    $neb->create_object("foo");
    2827
    2928    my $info = $neb->stat_object("foo");
    3029
    31     is(scalar @$info, 6, "number of columns");
     30    is(scalar @$info, 7, "number of columns");
    3231}
    3332
     
    3534
    3635{
    37     my $uri = $neb->create_object("foo", "node01");
     36    $neb->create_object("foo", "node01");
    3837
    3938    my $info = $neb->stat_object("foo");
    4039
    41     is(scalar @$info, 6,                       "number of columns");
     40    is(scalar @$info, 7,                       "number of columns");
    4241    is(@$info[0], 1,                           "so_id");
    4342    is(@$info[1], "foo",                       "ext_id");
     
    4645    like(@$info[4], qr/....-..-.. ..:..:../,   "epoch");
    4746    like(@$info[5], qr/....-..-.. ..:..:../,   "mtime");
     47    is(@$info[6], 1,                           "instances");
    4848}
    4949
     
    5353    $neb->stat_object("foo");
    5454};
    55 like($@, qr/no storage object found/, "object does not exist");
     55like($@, qr/is valid object key/, "object does not exist");
    5656
    5757Test::Nebulous->setup;
     
    6565
    6666eval {
     67    $neb->create_object("foo");
    6768    $neb->stat_object("foo", 2);
    6869};
  • trunk/Nebulous/lib/Nebulous/Client.pm

    r13092 r13180  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Client.pm,v 1.29 2007-05-01 02:52:04 jhoblitt Exp $
     3# $Id: Client.pm,v 1.30 2007-05-03 03:21:28 jhoblitt Exp $
    44
    55package Nebulous::Client;
     
    227227    my $self = shift;
    228228
    229     my ( $key, @params ) = validate_pos( @_,
     229    my ($key, $vol_name) = validate_pos(@_,
    230230        {
    231231            type => SCALAR,
     
    240240    $log->debug( "entered - @_" );
    241241
    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 }) {
    245259            $log->debug( "no instances" );
    246260            $log->debug( "leaving" );
    247261
    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");
    261284
    262285    return $uri;
     
    638661    my $self = shift;
    639662
    640     my ( $uri ) = validate_pos( @_,
     663    my ($uri) = validate_pos(@_,
    641664        {
    642665            type => SCALAR,
  • trunk/Nebulous/lib/Nebulous/Server.pm

    r13173 r13180  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.32 2007-05-03 01:44:23 jhoblitt Exp $
     3# $Id: Server.pm,v 1.33 2007-05-03 03:21:28 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    10211021    my ( $key ) = validate_pos( @_,
    10221022        {
    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 - @_");
    10321035
    10331036    my $stat;
    10341037    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");
    10401043        }
    10411044
    10421045        $stat = $query->fetchrow_arrayref;
    10431046        $query->finish;
    1044 
    1045         $db->commit;
    10461047    };
    10471048    if ( $@ ) {
    10481049        $db->rollback;
    1049         $log->logdie( "database error: $@" );
    1050     }
    1051 
    1052     $log->debug( "leaving" );
     1050        $log->logdie("database error: $@");
     1051    }
     1052
     1053    $log->debug("leaving");
    10531054
    10541055    return $stat;
  • trunk/Nebulous/lib/Nebulous/Server/SQL.pm

    r13177 r13180  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SQL.pm,v 1.35 2007-05-03 01:49:55 jhoblitt Exp $
     3# $Id: SQL.pm,v 1.36 2007-05-03 03:21:28 jhoblitt Exp $
    44
    55package Nebulous::Server::SQL;
     
    5353    get_object          => qq{
    5454        SELECT
    55             storage_object.so_id,
     55            so_id,
    5656            ext_id,
    5757            read_lock,
     
    6363        USING (so_id)
    6464        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
    6582    },
    6683    # Note: this sets an update lock
  • trunk/Nebulous/t/09_server_stat_object.t

    r13092 r13180  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 09_server_stat_object.t,v 1.10 2007-05-01 02:52:04 jhoblitt Exp $
     5# $Id: 09_server_stat_object.t,v 1.11 2007-05-03 03:21:28 jhoblitt Exp $
    66
    77use strict;
    88use warnings FATAL => qw( all );
    99
    10 use Test::More tests => 11;
     10use Test::More tests => 12;
    1111
    1212use lib qw( ./t ./lib );
     
    2323
    2424Test::Nebulous->setup;
    25 
    2625{
    27     my $uri = $neb->create_object("foo");
     26    $neb->create_object("foo");
    2827
    2928    my $info = $neb->stat_object("foo");
    3029
    31     is(scalar @$info, 6, "number of columns");
     30    is(scalar @$info, 7, "number of columns");
    3231}
    3332
     
    3534
    3635{
    37     my $uri = $neb->create_object("foo", "node01");
     36    $neb->create_object("foo", "node01");
    3837
    3938    my $info = $neb->stat_object("foo");
    4039
    41     is(scalar @$info, 6,                       "number of columns");
     40    is(scalar @$info, 7,                       "number of columns");
    4241    is(@$info[0], 1,                           "so_id");
    4342    is(@$info[1], "foo",                       "ext_id");
     
    4645    like(@$info[4], qr/....-..-.. ..:..:../,   "epoch");
    4746    like(@$info[5], qr/....-..-.. ..:..:../,   "mtime");
     47    is(@$info[6], 1,                           "instances");
    4848}
    4949
     
    5353    $neb->stat_object("foo");
    5454};
    55 like($@, qr/no storage object found/, "object does not exist");
     55like($@, qr/is valid object key/, "object does not exist");
    5656
    5757Test::Nebulous->setup;
     
    6565
    6666eval {
     67    $neb->create_object("foo");
    6768    $neb->stat_object("foo", 2);
    6869};
  • trunk/Nebulous/t/53_client_cull.t

    r13178 r13180  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 53_client_cull.t,v 1.4 2007-05-03 01:53:20 jhoblitt Exp $
     5# $Id: 53_client_cull.t,v 1.5 2007-05-03 03:21:28 jhoblitt Exp $
    66
    77use strict;
     
    1414use lib qw( ./t ./lib );
    1515
    16 use Nebulous::Client trace => 'debug';
     16use Nebulous::Client;
    1717use Nebulous::Util qw( :standard );
    1818use Test::Nebulous;
     
    2727        proxy => "http://$hostport/nebulous",
    2828    );
    29     $neb->create( "foo" );
    30     $neb->replicate( "foo" );
     29    $neb->create("foo");
     30    $neb->replicate("foo");
    3131
    32     my $uri = $neb->cull( "foo" );
     32    my $uri = $neb->cull("foo");
    3333
    34     ok( $uri, "good cull" );
    35     ok( ! -e _get_file_path( $uri ), "file doesn't exist" );
     34    ok($uri, "good cull");
     35    ok(! -e _get_file_path($uri), "file doesn't exist");
    3636}
    3737
     
    3939
    4040{
    41 
    4241    # key, $volume
    4342    my $neb = Nebulous::Client->new(
    4443        proxy => "http://$hostport/nebulous",
    4544    );
    46     $neb->create( "foo" );
    47     $neb->replicate( "foo", "node01" );
     45    $neb->create("foo");
     46    $neb->replicate("foo", "node01");
    4847
    49     my $uri = $neb->cull( "foo", "node01" );
     48    my $uri = $neb->cull("foo", "node01");
    5049
    51     ok( $uri, "good cull" );
    52     ok( ! -e _get_file_path( $uri ), "file exists" );
     50    ok($uri, "good cull");
     51    ok(! -e _get_file_path($uri), "file exists");
    5352}
    5453
     
    6059        proxy => "http://$hostport/nebulous",
    6160    );
    62     $neb->create( "foo" );
     61    $neb->create("foo");
    6362
    64     $neb->replicate( "foo", "node01" );
    65     $neb->replicate( "foo", "node02" );
     63    $neb->replicate("foo", "node01");
     64    $neb->replicate("foo", "node02");
    6665
    67     my $uri1 = $neb->cull( "foo" );
    68     my $uri2 = $neb->cull( "foo" );
     66    my $uri1 = $neb->cull("foo");
     67    my $uri2 = $neb->cull("foo");
    6968
    70     ok( $uri1, "good cull" );
    71     ok( $uri2, "good cull" );
    72     ok( ! -e _get_file_path( $uri1 ), "file exists" );
    73     ok( ! -e _get_file_path( $uri2 ), "file exists" );
     69    ok($uri1, "good cull");
     70    ok($uri2, "good cull");
     71    ok(! -e _get_file_path($uri1), "file exists");
     72    ok(! -e _get_file_path($uri2), "file exists");
    7473}
    7574
Note: See TracChangeset for help on using the changeset viewer.