IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16565


Ignore:
Timestamp:
Feb 21, 2008, 1:20:39 PM (18 years ago)
Author:
jhoblitt
Message:

add support for storing instances in multi-tier 'hashed' directories

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/Build.PL

    r16264 r16565  
    8484        'DBD::mysql'            => '3.0007',
    8585        'DBI'                   => '1.53',
     86        'Digest::SHA1'          => 0,
    8687        'File::ExtAttr'         => '1.03',
     88        'File::Path'            => '1.08',
     89        'File::Spec'            => 0,
    8790        'File::Spec::Functions' => 0,
    8891        'Log::Log4perl'         => '0.48',
  • trunk/Nebulous-Server/Changes

    r16354 r16565  
    22
    330.07
     4    - add support for storing instances in multi-tier 'hashed' directories
    45    - pickup test DB settings from the env.
    56    - add neb-ls -l|-1 option
  • trunk/Nebulous-Server/lib/Nebulous/Server.pm

    r16354 r16565  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.52 2008-02-07 22:18:51 jhoblitt Exp $
     3# $Id: Server.pm,v 1.53 2008-02-21 23:20:39 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    1313
    1414use DBI;
     15use Digest::SHA1 qw( sha1_hex );
    1516use File::ExtAttr qw( setfattr );
     17use File::Path;
     18use File::Spec;
    1619use Log::Log4perl;
    1720use Nebulous::Server::Config;
     
    2326
    2427__PACKAGE__->mk_accessors(qw( log sql config ));
     28
     29use constant SUBPATH_DEPTH => 3;
    2530
    2631sub new {
     
    12291234    my $log = $self->log;
    12301235    my $sql = $self->sql;
    1231     my $db  =$self->db;
    1232 
    1233     my ($storage_filename);
    1234     my ($uri);
    1235     eval {
    1236         $storage_filename = $self->_generate_storage_filename($key, $ins_id);
    1237         # XXX put a hook for directory hashing here
    1238         $uri = URI::file->new("$vol_path/$storage_filename");
     1236    my $db  = $self->db;
     1237
     1238    my $uri;
     1239    eval {
     1240        my $storage_path = $self->_generate_storage_path($key, $vol_path);
     1241        my $storage_filename = $self->_generate_storage_filename($key, $ins_id);
     1242        unless (-d $storage_path) {
     1243            mkpath($storage_path)
     1244                or die "can't create storage path: $storage_path";
     1245        }
     1246        my $fqpn = File::Spec->catfile($storage_path, $storage_filename);
     1247        $uri = URI::file->new($fqpn);
    12391248        $log->debug("generated uri $uri");
    12401249        $self->_create_empty_file($uri->file);
     
    12911300
    12921301
     1302sub _generate_storage_path
     1303{
     1304    my $self = shift;
     1305
     1306    my ($key, $vol_path) = @_;
     1307
     1308    # taken and modified from Cache::File::cache_file_path()
     1309    # Copyright (C) 2003-2006 Chris Leishman.  All Rights Reserved.
     1310    my $shakey = sha1_hex($key);
     1311    my (@path) = unpack('A2' x SUBPATH_DEPTH, $shakey);
     1312
     1313    return File::Spec->catdir($vol_path, @path);
     1314}
     1315
     1316
    12931317sub DESTROY
    12941318{
  • trunk/Nebulous/Build.PL

    r16264 r16565  
    8484        'DBD::mysql'            => '3.0007',
    8585        'DBI'                   => '1.53',
     86        'Digest::SHA1'          => 0,
    8687        'File::ExtAttr'         => '1.03',
     88        'File::Path'            => '1.08',
     89        'File::Spec'            => 0,
    8790        'File::Spec::Functions' => 0,
    8891        'Log::Log4perl'         => '0.48',
  • trunk/Nebulous/Changes

    r16354 r16565  
    22
    330.07
     4    - add support for storing instances in multi-tier 'hashed' directories
    45    - pickup test DB settings from the env.
    56    - add neb-ls -l|-1 option
  • trunk/Nebulous/lib/Nebulous/Server.pm

    r16354 r16565  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.52 2008-02-07 22:18:51 jhoblitt Exp $
     3# $Id: Server.pm,v 1.53 2008-02-21 23:20:39 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    1313
    1414use DBI;
     15use Digest::SHA1 qw( sha1_hex );
    1516use File::ExtAttr qw( setfattr );
     17use File::Path;
     18use File::Spec;
    1619use Log::Log4perl;
    1720use Nebulous::Server::Config;
     
    2326
    2427__PACKAGE__->mk_accessors(qw( log sql config ));
     28
     29use constant SUBPATH_DEPTH => 3;
    2530
    2631sub new {
     
    12291234    my $log = $self->log;
    12301235    my $sql = $self->sql;
    1231     my $db  =$self->db;
    1232 
    1233     my ($storage_filename);
    1234     my ($uri);
    1235     eval {
    1236         $storage_filename = $self->_generate_storage_filename($key, $ins_id);
    1237         # XXX put a hook for directory hashing here
    1238         $uri = URI::file->new("$vol_path/$storage_filename");
     1236    my $db  = $self->db;
     1237
     1238    my $uri;
     1239    eval {
     1240        my $storage_path = $self->_generate_storage_path($key, $vol_path);
     1241        my $storage_filename = $self->_generate_storage_filename($key, $ins_id);
     1242        unless (-d $storage_path) {
     1243            mkpath($storage_path)
     1244                or die "can't create storage path: $storage_path";
     1245        }
     1246        my $fqpn = File::Spec->catfile($storage_path, $storage_filename);
     1247        $uri = URI::file->new($fqpn);
    12391248        $log->debug("generated uri $uri");
    12401249        $self->_create_empty_file($uri->file);
     
    12911300
    12921301
     1302sub _generate_storage_path
     1303{
     1304    my $self = shift;
     1305
     1306    my ($key, $vol_path) = @_;
     1307
     1308    # taken and modified from Cache::File::cache_file_path()
     1309    # Copyright (C) 2003-2006 Chris Leishman.  All Rights Reserved.
     1310    my $shakey = sha1_hex($key);
     1311    my (@path) = unpack('A2' x SUBPATH_DEPTH, $shakey);
     1312
     1313    return File::Spec->catdir($vol_path, @path);
     1314}
     1315
     1316
    12931317sub DESTROY
    12941318{
Note: See TracChangeset for help on using the changeset viewer.