IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12961


Ignore:
Timestamp:
Apr 23, 2007, 10:45:08 AM (19 years ago)
Author:
jhoblitt
Message:

change API to generally return true URIs instead of file paths
add support for some what intelligent volume allocations

Location:
trunk
Files:
6 edited

Legend:

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

    r10627 r12961  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.22 2006-12-12 00:02:53 jhoblitt Exp $
     3# $Id: Server.pm,v 1.23 2007-04-23 20:45:08 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    1313
    1414use DBI;
    15 use Nebulous::Util qw( :standard );
     15use Log::Log4perl;
    1616use Nebulous::Server::Config;
    1717use Nebulous::Server::Log;
    1818use Nebulous::Server::SQL;
    19 use Log::Log4perl;
    20 use Params::Validate qw( validate_pos SCALAR );
     19use Nebulous::Util qw( :standard );
     20use Params::Validate qw( validate_pos SCALAR SCALARREF );
     21use URI::file;
    2122
    2223__PACKAGE__->mk_accessors(qw( log sql config ));
     
    159160    $log->debug( "entered - @_" );
    160161
    161     # TODO do some intelligent volume allocated
    162     # add hooks to make this decision based on avaiable space
    163162    $volume = $self->_get_storage_volume( $volume );
    164163
    165     my $uri;
    166164    my $object_id;
    167165    my $ins_id;
     
    210208    }
    211209
    212     $uri = "$volume/$key.$ins_id";
     210    my $uri = URI::file->new("$volume/$key.$ins_id");
    213211
    214212    $log->debug( "generated uri $uri");
    215213
    216     my $path = _get_file_path( $uri );
    217 
    218214    # TODO add some stuff here to retry if unsucessful
    219215    eval {
    220         _create_empty_file( $path );
     216        _create_empty_file($uri->file);
    221217    };
    222218    if ( $@ ) {
     
    237233    $log->debug( "leaving" );
    238234
    239     return $uri;
     235    return "$uri";
    240236}
    241237
     
    297293
    298294        {
    299             $uri = "$volume/$key.$ins_id";
    300             $log->debug( "generated uri $uri");
     295            $uri = URI::file->new("$volume/$key.$ins_id");
     296            $log->debug("generated uri $uri");
    301297
    302298            my $query = $db->prepare_cached( $sql->update_instance_uri );
     
    311307
    312308    eval {
    313         $path = _get_file_path( $uri );
    314         $path = _create_empty_file( $path );
     309        _create_empty_file($uri->file);
    315310    };
    316311    if ( $@ ) {
     
    323318    $log->debug( "leaving" );
    324319
    325     return $uri;
     320    return "$uri";
    326321}
    327322
     
    620615    my ( $uri ) = validate_pos( @_,
    621616        {
    622             type => SCALAR,
     617            type => SCALAR|SCALARREF,
    623618        },
    624619    );
     
    731726}
    732727
     728#  select *, total - used as free, (used / total) * 100 as perused from mount;
     729
    733730sub _get_storage_volume {
    734731    my $self = shift;
     
    751748        if ( $name ) {
    752749            $query = $db->prepare_cached( $sql->get_storage_volume_byname );
    753             $rows = $query->execute( $name );
     750            $rows = $query->execute(0.95, $name);
    754751        } else {
    755752            $query = $db->prepare_cached( $sql->get_storage_volume );
    756             $rows = $query->execute;
     753            $rows = $query->execute(0.95);
    757754        }
    758755
     
    762759        }
    763760
    764         $volume = $query->fetchrow_hashref->{ 'uri' };
     761        $volume = $query->fetchrow_hashref->{ 'mountpoint' };
    765762
    766763        $query->finish;
  • trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm

    r12007 r12961  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SQL.pm,v 1.23 2007-02-23 01:23:45 jhoblitt Exp $
     3# $Id: SQL.pm,v 1.24 2007-04-23 20:45:08 jhoblitt Exp $
    44
    55package Nebulous::Server::SQL;
     
    115115    },
    116116    get_storage_volume_byname   => qq{
    117         SELECT uri FROM volume WHERE name = ? ORDER BY rand() LIMIT 1
     117        SELECT
     118            mountpoint,
     119            total - used as free
     120        FROM volume
     121        JOIN mount      -- join limits us to currently mounted volumes
     122            ON volume.path = mount.mountpoint
     123        WHERE
     124            used / total < ?
     125            AND name = ?
     126        ORDER BY free DESC
     127        LIMIT 1
    118128    },
    119129    get_storage_volume          => qq{
    120         SELECT uri FROM volume ORDER BY rand() LIMIT 1
     130        SELECT
     131            mountpoint,
     132            total - used as free
     133        FROM volume
     134        JOIN mount      -- join limits us to currently mounted volumes
     135            ON volume.path = mount.mountpoint
     136        WHERE
     137            used / total < ?
     138        ORDER BY free DESC
     139        LIMIT 1
    121140    },
    122141    new_volume          => qq{
    123         INSERT INTO volume (name, uri)
     142        INSERT INTO volume (name, path)
    124143        VALUES (?, ?)
    125144    },
     
    130149    },
    131150    get_volume_by_name => qq{
    132         SELECT vol_id, name, uri
     151        SELECT vol_id, name, path
    133152        FROM volume
    134153        WHERE name = ?
     
    156175DROP TABLE IF EXISTS lock_record;
    157176DROP TABLE IF EXISTS volume;
     177DROP TABLE IF EXISTS mount;
    158178DROP TABLE IF EXISTS class;
    159179DROP TABLE IF EXISTS log
  • trunk/Nebulous/lib/Nebulous/Client.pm

    r5670 r12961  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Client.pm,v 1.23 2005-12-03 03:19:43 jhoblitt Exp $
     3# $Id: Client.pm,v 1.24 2007-04-23 20:45:08 jhoblitt Exp $
    44
    55package Nebulous::Client;
     
    123123    }
    124124
    125     my $uri = $response->result;
    126 
    127     $log->debug( "server allocated $uri" );
    128 
    129     my $filename;
    130     eval {
    131         $filename = _get_file_path( $uri );
    132     };
    133     $log->logdie( $@ ) if $@;
    134 
     125    my $res = $response->result;
     126    $log->debug( "server respone $res" );
     127
     128    my $uri = URI->new($res);
     129    my $filename = $uri->file;
    135130    $log->debug( "local filename is $filename" );
    136131
    137132    $log->debug( "leaving" );
    138133
    139     return $filename;
     134    return $uri;
    140135}
    141136
     
    176171    }
    177172
    178     my $uri = $response->result;
    179 
    180     $log->debug( "server allocated $uri" );
     173    my $res = $response->result;
     174    $log->debug( "server response $res" );
     175
     176    my $uri = URI->new($res);
     177    my $filename = $uri->file;
     178    $log->debug( "local filename is $filename" );
    181179
    182180    my $fh;
     
    215213    }
    216214
     215    my $res = $response->result;
     216    $log->debug( "server respone $res" );
     217
     218    my $uri = URI->new($res);
     219    my $filename = $uri->file;
     220    $log->debug( "local filename is $filename" );
     221
    217222    my $fh  = $self->open( $key, 'read' );
    218223    unless ( $fh ) {
     
    222227        return undef;
    223228    }
    224 
    225     $log->debug( "server allocated new instance" );
    226 
    227     my $uri = $response->result;
    228229
    229230    my $new_fh;
  • trunk/Nebulous/lib/Nebulous/Server.pm

    r10627 r12961  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.22 2006-12-12 00:02:53 jhoblitt Exp $
     3# $Id: Server.pm,v 1.23 2007-04-23 20:45:08 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    1313
    1414use DBI;
    15 use Nebulous::Util qw( :standard );
     15use Log::Log4perl;
    1616use Nebulous::Server::Config;
    1717use Nebulous::Server::Log;
    1818use Nebulous::Server::SQL;
    19 use Log::Log4perl;
    20 use Params::Validate qw( validate_pos SCALAR );
     19use Nebulous::Util qw( :standard );
     20use Params::Validate qw( validate_pos SCALAR SCALARREF );
     21use URI::file;
    2122
    2223__PACKAGE__->mk_accessors(qw( log sql config ));
     
    159160    $log->debug( "entered - @_" );
    160161
    161     # TODO do some intelligent volume allocated
    162     # add hooks to make this decision based on avaiable space
    163162    $volume = $self->_get_storage_volume( $volume );
    164163
    165     my $uri;
    166164    my $object_id;
    167165    my $ins_id;
     
    210208    }
    211209
    212     $uri = "$volume/$key.$ins_id";
     210    my $uri = URI::file->new("$volume/$key.$ins_id");
    213211
    214212    $log->debug( "generated uri $uri");
    215213
    216     my $path = _get_file_path( $uri );
    217 
    218214    # TODO add some stuff here to retry if unsucessful
    219215    eval {
    220         _create_empty_file( $path );
     216        _create_empty_file($uri->file);
    221217    };
    222218    if ( $@ ) {
     
    237233    $log->debug( "leaving" );
    238234
    239     return $uri;
     235    return "$uri";
    240236}
    241237
     
    297293
    298294        {
    299             $uri = "$volume/$key.$ins_id";
    300             $log->debug( "generated uri $uri");
     295            $uri = URI::file->new("$volume/$key.$ins_id");
     296            $log->debug("generated uri $uri");
    301297
    302298            my $query = $db->prepare_cached( $sql->update_instance_uri );
     
    311307
    312308    eval {
    313         $path = _get_file_path( $uri );
    314         $path = _create_empty_file( $path );
     309        _create_empty_file($uri->file);
    315310    };
    316311    if ( $@ ) {
     
    323318    $log->debug( "leaving" );
    324319
    325     return $uri;
     320    return "$uri";
    326321}
    327322
     
    620615    my ( $uri ) = validate_pos( @_,
    621616        {
    622             type => SCALAR,
     617            type => SCALAR|SCALARREF,
    623618        },
    624619    );
     
    731726}
    732727
     728#  select *, total - used as free, (used / total) * 100 as perused from mount;
     729
    733730sub _get_storage_volume {
    734731    my $self = shift;
     
    751748        if ( $name ) {
    752749            $query = $db->prepare_cached( $sql->get_storage_volume_byname );
    753             $rows = $query->execute( $name );
     750            $rows = $query->execute(0.95, $name);
    754751        } else {
    755752            $query = $db->prepare_cached( $sql->get_storage_volume );
    756             $rows = $query->execute;
     753            $rows = $query->execute(0.95);
    757754        }
    758755
     
    762759        }
    763760
    764         $volume = $query->fetchrow_hashref->{ 'uri' };
     761        $volume = $query->fetchrow_hashref->{ 'mountpoint' };
    765762
    766763        $query->finish;
  • trunk/Nebulous/lib/Nebulous/Server/SQL.pm

    r12007 r12961  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SQL.pm,v 1.23 2007-02-23 01:23:45 jhoblitt Exp $
     3# $Id: SQL.pm,v 1.24 2007-04-23 20:45:08 jhoblitt Exp $
    44
    55package Nebulous::Server::SQL;
     
    115115    },
    116116    get_storage_volume_byname   => qq{
    117         SELECT uri FROM volume WHERE name = ? ORDER BY rand() LIMIT 1
     117        SELECT
     118            mountpoint,
     119            total - used as free
     120        FROM volume
     121        JOIN mount      -- join limits us to currently mounted volumes
     122            ON volume.path = mount.mountpoint
     123        WHERE
     124            used / total < ?
     125            AND name = ?
     126        ORDER BY free DESC
     127        LIMIT 1
    118128    },
    119129    get_storage_volume          => qq{
    120         SELECT uri FROM volume ORDER BY rand() LIMIT 1
     130        SELECT
     131            mountpoint,
     132            total - used as free
     133        FROM volume
     134        JOIN mount      -- join limits us to currently mounted volumes
     135            ON volume.path = mount.mountpoint
     136        WHERE
     137            used / total < ?
     138        ORDER BY free DESC
     139        LIMIT 1
    121140    },
    122141    new_volume          => qq{
    123         INSERT INTO volume (name, uri)
     142        INSERT INTO volume (name, path)
    124143        VALUES (?, ?)
    125144    },
     
    130149    },
    131150    get_volume_by_name => qq{
    132         SELECT vol_id, name, uri
     151        SELECT vol_id, name, path
    133152        FROM volume
    134153        WHERE name = ?
     
    156175DROP TABLE IF EXISTS lock_record;
    157176DROP TABLE IF EXISTS volume;
     177DROP TABLE IF EXISTS mount;
    158178DROP TABLE IF EXISTS class;
    159179DROP TABLE IF EXISTS log
  • trunk/Nebulous/lib/Nebulous/Util.pm

    r4440 r12961  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Util.pm,v 1.3 2005-06-30 02:35:06 jhoblitt Exp $
     3# $Id: Util.pm,v 1.4 2007-04-23 20:45:08 jhoblitt Exp $
    44
    55package Nebulous::Util;
     
    1414use Log::Log4perl qw( :levels );
    1515use URI;
     16use URI::file;
    1617
    1718my @symbols = qw(
     
    7172    my ( $uri , $flags ) = @_;
    7273
    73     my $path = _get_file_path( $uri );
    74     my $fh = _get_filehandle( $path, $flags );
     74    $uri = URI->new("$uri");
     75
     76    my $fh = _get_filehandle($uri->file, $flags);
    7577
    7678    return $fh;
Note: See TracChangeset for help on using the changeset viewer.