IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18400


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

Location:
trunk/Nebulous-Server
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/Changes

    r18387 r18400  
    22
    330.13
     4    - add "smart" storage volume selection when ->replicate_object() is invoked without a target volume name
    45    - add volume.host field
    56    - add --host option to neb-initdb
  • 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{
  • trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm

    r18388 r18400  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SQL.pm,v 1.59 2008-06-30 23:26:16 jhoblitt Exp $
     3# $Id: SQL.pm,v 1.60 2008-07-02 03:40:10 jhoblitt Exp $
    44
    55package Nebulous::Server::SQL;
     
    211211            AND available = ?
    212212            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 = ?
    213253        ORDER BY free DESC
    214254        LIMIT 1
  • trunk/Nebulous-Server/t/07_server_find_instances.t

    r17753 r18400  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 07_server_find_instances.t,v 1.12 2008-05-20 01:47:08 jhoblitt Exp $
     5# $Id: 07_server_find_instances.t,v 1.13 2008-07-02 03:40:10 jhoblitt Exp $
    66
    77use strict;
     
    9191    my $uri2 = $neb->replicate_object("foo");
    9292
    93     my $locations = $neb->find_instances("foo", "node01");
     93    my $locations = $neb->find_instances("foo", ":any");
    9494
    9595    uri_scheme_ok($locations->[0], 'file');
Note: See TracChangeset for help on using the changeset viewer.