IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 1, 2008, 5:40:10 PM (18 years ago)
Author:
jhoblitt
Message:

add "smart" storage volume selection when ->replicate_object() is invoked without a target volume name

File:
1 edited

Legend:

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

    r18389 r18400  
    11# Copyright (c) 2004-2008  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.78 2008-07-01 00:28:06 jhoblitt Exp $
     3# $Id: Server.pm,v 1.79 2008-07-02 03:40:10 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    320320            type        => SCALAR,
    321321            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]) },
    323324            },
    324325        },
     
    336337    );
    337338
     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
    338347    my $log = $self->log;
    339348    my $sql = $self->sql;
     
    353362    }
    354363       
    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    }
    356372
    357373    my $uri;
     
    359375        my $so_id;
    360376        {
     377            # verify that at least one instance is currently available
    361378            my $query = $db->prepare_cached( $sql->get_object_instances );
    362379            my $rows = $query->execute($key, 1);
     
    382399            ($ins_id) = $query->fetchrow_array;
    383400            # 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 next
     401            # get a warning about the stmt handling still being active the next
    385402            # time LAST_INSERT_ID() is invoked
    386403            $query->finish;
     
    11971214
    11981215
     1216sub _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
    11991265sub _is_valid_object_key
    12001266{
Note: See TracChangeset for help on using the changeset viewer.