Changeset 12961
- Timestamp:
- Apr 23, 2007, 10:45:08 AM (19 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
-
Nebulous-Server/lib/Nebulous/Server.pm (modified) (12 diffs)
-
Nebulous-Server/lib/Nebulous/Server/SQL.pm (modified) (4 diffs)
-
Nebulous/lib/Nebulous/Client.pm (modified) (5 diffs)
-
Nebulous/lib/Nebulous/Server.pm (modified) (12 diffs)
-
Nebulous/lib/Nebulous/Server/SQL.pm (modified) (4 diffs)
-
Nebulous/lib/Nebulous/Util.pm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/lib/Nebulous/Server.pm
r10627 r12961 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1.2 2 2006-12-12 00:02:53jhoblitt Exp $3 # $Id: Server.pm,v 1.23 2007-04-23 20:45:08 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 13 13 14 14 use DBI; 15 use Nebulous::Util qw( :standard );15 use Log::Log4perl; 16 16 use Nebulous::Server::Config; 17 17 use Nebulous::Server::Log; 18 18 use Nebulous::Server::SQL; 19 use Log::Log4perl; 20 use Params::Validate qw( validate_pos SCALAR ); 19 use Nebulous::Util qw( :standard ); 20 use Params::Validate qw( validate_pos SCALAR SCALARREF ); 21 use URI::file; 21 22 22 23 __PACKAGE__->mk_accessors(qw( log sql config )); … … 159 160 $log->debug( "entered - @_" ); 160 161 161 # TODO do some intelligent volume allocated162 # add hooks to make this decision based on avaiable space163 162 $volume = $self->_get_storage_volume( $volume ); 164 163 165 my $uri;166 164 my $object_id; 167 165 my $ins_id; … … 210 208 } 211 209 212 $uri = "$volume/$key.$ins_id";210 my $uri = URI::file->new("$volume/$key.$ins_id"); 213 211 214 212 $log->debug( "generated uri $uri"); 215 213 216 my $path = _get_file_path( $uri );217 218 214 # TODO add some stuff here to retry if unsucessful 219 215 eval { 220 _create_empty_file( $path);216 _create_empty_file($uri->file); 221 217 }; 222 218 if ( $@ ) { … … 237 233 $log->debug( "leaving" ); 238 234 239 return $uri;235 return "$uri"; 240 236 } 241 237 … … 297 293 298 294 { 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"); 301 297 302 298 my $query = $db->prepare_cached( $sql->update_instance_uri ); … … 311 307 312 308 eval { 313 $path = _get_file_path( $uri ); 314 $path = _create_empty_file( $path ); 309 _create_empty_file($uri->file); 315 310 }; 316 311 if ( $@ ) { … … 323 318 $log->debug( "leaving" ); 324 319 325 return $uri;320 return "$uri"; 326 321 } 327 322 … … 620 615 my ( $uri ) = validate_pos( @_, 621 616 { 622 type => SCALAR ,617 type => SCALAR|SCALARREF, 623 618 }, 624 619 ); … … 731 726 } 732 727 728 # select *, total - used as free, (used / total) * 100 as perused from mount; 729 733 730 sub _get_storage_volume { 734 731 my $self = shift; … … 751 748 if ( $name ) { 752 749 $query = $db->prepare_cached( $sql->get_storage_volume_byname ); 753 $rows = $query->execute( $name);750 $rows = $query->execute(0.95, $name); 754 751 } else { 755 752 $query = $db->prepare_cached( $sql->get_storage_volume ); 756 $rows = $query->execute ;753 $rows = $query->execute(0.95); 757 754 } 758 755 … … 762 759 } 763 760 764 $volume = $query->fetchrow_hashref->{ ' uri' };761 $volume = $query->fetchrow_hashref->{ 'mountpoint' }; 765 762 766 763 $query->finish; -
trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
r12007 r12961 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1.2 3 2007-02-23 01:23:45jhoblitt Exp $3 # $Id: SQL.pm,v 1.24 2007-04-23 20:45:08 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 115 115 }, 116 116 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 118 128 }, 119 129 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 121 140 }, 122 141 new_volume => qq{ 123 INSERT INTO volume (name, uri)142 INSERT INTO volume (name, path) 124 143 VALUES (?, ?) 125 144 }, … … 130 149 }, 131 150 get_volume_by_name => qq{ 132 SELECT vol_id, name, uri151 SELECT vol_id, name, path 133 152 FROM volume 134 153 WHERE name = ? … … 156 175 DROP TABLE IF EXISTS lock_record; 157 176 DROP TABLE IF EXISTS volume; 177 DROP TABLE IF EXISTS mount; 158 178 DROP TABLE IF EXISTS class; 159 179 DROP TABLE IF EXISTS log -
trunk/Nebulous/lib/Nebulous/Client.pm
r5670 r12961 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Client.pm,v 1.2 3 2005-12-03 03:19:43jhoblitt Exp $3 # $Id: Client.pm,v 1.24 2007-04-23 20:45:08 jhoblitt Exp $ 4 4 5 5 package Nebulous::Client; … … 123 123 } 124 124 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; 135 130 $log->debug( "local filename is $filename" ); 136 131 137 132 $log->debug( "leaving" ); 138 133 139 return $ filename;134 return $uri; 140 135 } 141 136 … … 176 171 } 177 172 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" ); 181 179 182 180 my $fh; … … 215 213 } 216 214 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 217 222 my $fh = $self->open( $key, 'read' ); 218 223 unless ( $fh ) { … … 222 227 return undef; 223 228 } 224 225 $log->debug( "server allocated new instance" );226 227 my $uri = $response->result;228 229 229 230 my $new_fh; -
trunk/Nebulous/lib/Nebulous/Server.pm
r10627 r12961 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1.2 2 2006-12-12 00:02:53jhoblitt Exp $3 # $Id: Server.pm,v 1.23 2007-04-23 20:45:08 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 13 13 14 14 use DBI; 15 use Nebulous::Util qw( :standard );15 use Log::Log4perl; 16 16 use Nebulous::Server::Config; 17 17 use Nebulous::Server::Log; 18 18 use Nebulous::Server::SQL; 19 use Log::Log4perl; 20 use Params::Validate qw( validate_pos SCALAR ); 19 use Nebulous::Util qw( :standard ); 20 use Params::Validate qw( validate_pos SCALAR SCALARREF ); 21 use URI::file; 21 22 22 23 __PACKAGE__->mk_accessors(qw( log sql config )); … … 159 160 $log->debug( "entered - @_" ); 160 161 161 # TODO do some intelligent volume allocated162 # add hooks to make this decision based on avaiable space163 162 $volume = $self->_get_storage_volume( $volume ); 164 163 165 my $uri;166 164 my $object_id; 167 165 my $ins_id; … … 210 208 } 211 209 212 $uri = "$volume/$key.$ins_id";210 my $uri = URI::file->new("$volume/$key.$ins_id"); 213 211 214 212 $log->debug( "generated uri $uri"); 215 213 216 my $path = _get_file_path( $uri );217 218 214 # TODO add some stuff here to retry if unsucessful 219 215 eval { 220 _create_empty_file( $path);216 _create_empty_file($uri->file); 221 217 }; 222 218 if ( $@ ) { … … 237 233 $log->debug( "leaving" ); 238 234 239 return $uri;235 return "$uri"; 240 236 } 241 237 … … 297 293 298 294 { 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"); 301 297 302 298 my $query = $db->prepare_cached( $sql->update_instance_uri ); … … 311 307 312 308 eval { 313 $path = _get_file_path( $uri ); 314 $path = _create_empty_file( $path ); 309 _create_empty_file($uri->file); 315 310 }; 316 311 if ( $@ ) { … … 323 318 $log->debug( "leaving" ); 324 319 325 return $uri;320 return "$uri"; 326 321 } 327 322 … … 620 615 my ( $uri ) = validate_pos( @_, 621 616 { 622 type => SCALAR ,617 type => SCALAR|SCALARREF, 623 618 }, 624 619 ); … … 731 726 } 732 727 728 # select *, total - used as free, (used / total) * 100 as perused from mount; 729 733 730 sub _get_storage_volume { 734 731 my $self = shift; … … 751 748 if ( $name ) { 752 749 $query = $db->prepare_cached( $sql->get_storage_volume_byname ); 753 $rows = $query->execute( $name);750 $rows = $query->execute(0.95, $name); 754 751 } else { 755 752 $query = $db->prepare_cached( $sql->get_storage_volume ); 756 $rows = $query->execute ;753 $rows = $query->execute(0.95); 757 754 } 758 755 … … 762 759 } 763 760 764 $volume = $query->fetchrow_hashref->{ ' uri' };761 $volume = $query->fetchrow_hashref->{ 'mountpoint' }; 765 762 766 763 $query->finish; -
trunk/Nebulous/lib/Nebulous/Server/SQL.pm
r12007 r12961 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1.2 3 2007-02-23 01:23:45jhoblitt Exp $3 # $Id: SQL.pm,v 1.24 2007-04-23 20:45:08 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 115 115 }, 116 116 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 118 128 }, 119 129 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 121 140 }, 122 141 new_volume => qq{ 123 INSERT INTO volume (name, uri)142 INSERT INTO volume (name, path) 124 143 VALUES (?, ?) 125 144 }, … … 130 149 }, 131 150 get_volume_by_name => qq{ 132 SELECT vol_id, name, uri151 SELECT vol_id, name, path 133 152 FROM volume 134 153 WHERE name = ? … … 156 175 DROP TABLE IF EXISTS lock_record; 157 176 DROP TABLE IF EXISTS volume; 177 DROP TABLE IF EXISTS mount; 158 178 DROP TABLE IF EXISTS class; 159 179 DROP TABLE IF EXISTS log -
trunk/Nebulous/lib/Nebulous/Util.pm
r4440 r12961 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Util.pm,v 1. 3 2005-06-30 02:35:06jhoblitt Exp $3 # $Id: Util.pm,v 1.4 2007-04-23 20:45:08 jhoblitt Exp $ 4 4 5 5 package Nebulous::Util; … … 14 14 use Log::Log4perl qw( :levels ); 15 15 use URI; 16 use URI::file; 16 17 17 18 my @symbols = qw( … … 71 72 my ( $uri , $flags ) = @_; 72 73 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); 75 77 76 78 return $fh;
Note:
See TracChangeset
for help on using the changeset viewer.
