Changeset 25027 for branches/pap/Nebulous/lib
- Timestamp:
- Aug 7, 2009, 4:08:25 PM (17 years ago)
- Location:
- branches/pap
- Files:
-
- 5 edited
-
. (modified) (1 prop)
-
Nebulous (modified) (1 prop)
-
Nebulous/lib (modified) (1 prop)
-
Nebulous/lib/Nebulous/Client.pm (modified) (12 diffs)
-
Nebulous/lib/Nebulous/Client.pod (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap
- Property svn:mergeinfo changed
-
branches/pap/Nebulous
- Property svn:mergeinfo deleted
-
branches/pap/Nebulous/lib
- Property svn:mergeinfo deleted
-
branches/pap/Nebulous/lib/Nebulous/Client.pm
r23934 r25027 9 9 no warnings qw( uninitialized ); 10 10 11 our $VERSION = '0. 09';11 our $VERSION = '0.17'; 12 12 13 13 use Digest::MD5; … … 16 16 use Nebulous::Client::Log; 17 17 use Nebulous::Util qw( :standard ); 18 use Params::Validate qw( validate validate_pos SCALAR UNDEF );18 use Params::Validate qw( validate validate_pos SCALAR UNDEF BOOLEAN ); 19 19 #use SOAP::Lite +trace => [qw( debug )]; 20 20 use SOAP::Lite; … … 297 297 my $instances = $stats[6]; 298 298 if (defined $instances and $instances < 2) { 299 $ log->debug("can not cull - not enough instances");299 $self->set_err("can not cull - not enough instances"); 300 300 $log->debug("leaving"); 301 301 … … 305 305 $locations = $self->find_instances($key, $vol_name); 306 306 unless (defined $locations) { 307 $ log->debug( "no instances" );307 $self->set_err( "no instances" ); 308 308 $log->debug( "leaving" ); 309 309 … … 313 313 $locations = $self->find_instances($key); 314 314 unless ($locations) { 315 $ log->debug("no instances");315 $self->set_err( "no instances" ); 316 316 $log->debug("leaving"); 317 317 … … 320 320 321 321 if (scalar @{ $locations } < 2) { 322 $ log->debug("can not cull - not enough instances");322 $self->set_err("can not cull - not enough instances"); 323 323 $log->debug("leaving"); 324 324 … … 329 329 my $uri = $self->delete_instance($key, @$locations[0]); 330 330 331 eval { 332 _nuke_file(_get_file_path(@$locations[0])); 333 }; 334 if ($@) { 335 $log->logdie($@); 336 } 337 331 338 $log->debug("leaving"); 332 339 333 340 return $uri; 341 } 342 343 344 sub there_can_be_only_one 345 { 346 my $self = shift; 347 348 my ($key, $vol_name) = validate_pos(@_, 349 { 350 type => SCALAR, 351 }, 352 { 353 # volume 354 type => SCALAR, 355 optional => 1, 356 }, 357 ); 358 359 $log->debug( "entered - @_" ); 360 361 my $locations; 362 my $removed = 0; 363 eval { 364 # first - strip off any inaccesible instances 365 if (not defined $self->prune($key)) { 366 # use the prune() method to also determine if $key is valid 367 die "invalid key: $key"; 368 } 369 370 # check to see if there is an instance on $vol_name that should be the 371 # sole survivor 372 if (defined $vol_name) { 373 $locations = $self->find_instances($key, $vol_name); 374 } 375 376 if (defined $locations) { 377 my $instances = $self->find_instances($key); 378 if (scalar @$instances < 2) { 379 die "not enough instances"; 380 } 381 foreach my $victim (@$instances) { 382 next if $victim eq $locations->[0]; 383 $self->delete_instance($key, $victim); 384 $removed++; 385 } 386 } else { 387 # nuke whatever 388 my $stats = $self->stat($key); 389 # start at one so cull() is called one less time then the # of 390 # instances 391 if ($stats->[6] < 2) { 392 die "not enough instances"; 393 } 394 for (my $i = 1; $i < $stats->[6]; $i++) { 395 $self->cull($key); 396 $removed++; 397 } 398 } 399 400 }; 401 if ($@) { 402 if ($@ =~ qr/invalid key/) { 403 $self->set_err($@); 404 return; 405 } 406 $log->logdie($@); 407 } 408 409 $log->debug("leaving"); 410 411 return $removed; 334 412 } 335 413 … … 803 881 my $self = shift; 804 882 805 my ( $key ) = validate_pos( @_, 806 { 807 type => SCALAR, 883 my ($key, $force) = validate_pos( @_, 884 { 885 type => SCALAR, 886 }, 887 { 888 type => BOOLEAN, 889 optional => 1, 890 default => undef, 891 callbacks => { 892 'is boolean' => sub { 893 $_[0] == 0 or $_[0] == 1 or $_[0] == undef; 894 }, 895 }, 808 896 }, 809 897 ); … … 817 905 # a lock is implicitly removed when the last storage object is deleted 818 906 foreach my $uri ( @$locations ) { 907 # it is being assumed here that it is better to have files on disk and 908 # not in the database then the inverse. 909 my $path; 910 eval { 911 $path = _get_file_path( $uri ); 912 }; 913 if ($@) { 914 if ($force) { 915 $log->warn($@); 916 $log->warn("exception ignored because force is in effect"); 917 } else { 918 $log->logdie($@); 919 } 920 } 921 819 922 $self->delete_instance($key, $uri) or return undef; 923 924 eval { 925 _nuke_file( $path ); 926 }; 927 if ($@) { 928 if ($force) { 929 $log->warn($@); 930 $log->warn("exception ignored because force is in effect"); 931 } else { 932 $log->logdie($@); 933 } 934 } 820 935 } 821 936 … … 959 1074 $log->debug( "entered - @_" ); 960 1075 961 # it is being assumed here that it is better to have files on disk and not in962 # the database then the inverse.963 964 my $path;965 eval {966 $path = _get_file_path( $uri );967 };968 $log->logdie( $@ ) if $@;969 970 1076 my $response = $self->{ 'server' }->delete_instance($key, $uri); 971 1077 if ( $response->fault ) { … … 982 1088 $log->debug( "server deleted instance" ); 983 1089 984 eval {985 _nuke_file( $path );986 };987 $log->logdie( $@ ) if $@;988 989 1090 $log->debug( "leaving" ); 990 1091 … … 1045 1146 1046 1147 return $stats; 1148 } 1149 1150 1151 sub chmod 1152 { 1153 my $self = shift; 1154 1155 my ($key, $mode) = validate_pos( @_, 1156 { 1157 type => SCALAR, 1158 }, 1159 { 1160 type => SCALAR, 1161 regex => qr/\d{3,4}/, 1162 }, 1163 ); 1164 1165 $log->debug( "entered - @_" ); 1166 1167 my $response = $self->{ 'server' }->chmod_object($key, $mode); 1168 if ( $response->fault ) { 1169 $self->set_err($response->faultstring); 1170 if ($response->faultstring =~ /is valid object key/) { 1171 $log->debug( "leaving" ); 1172 return; 1173 } 1174 if ($response->faultstring =~ /is allowable mode/) { 1175 $log->debug( "leaving" ); 1176 return; 1177 } 1178 1179 $log->logdie("unhandled fault - ", $self->err); 1180 } 1181 1182 my $response_mode = $response->result; 1183 1184 $log->debug( "leaving" ); 1185 1186 return $response_mode; 1187 } 1188 1189 1190 sub prune 1191 { 1192 my $self = shift; 1193 1194 my ( $key ) = validate_pos( @_, 1195 { 1196 type => SCALAR, 1197 }, 1198 ); 1199 1200 $log->debug( "entered - @_" ); 1201 1202 my $response = $self->{ 'server' }->prune_object( $key ); 1203 if ( $response->fault ) { 1204 $self->set_err($response->faultstring); 1205 if ($response->faultstring =~ /is valid object key/) { 1206 $log->debug( "leaving" ); 1207 return; 1208 } 1209 1210 $log->logdie("unhandled fault - ", $self->err); 1211 } 1212 1213 $log->debug( "server returned a stat" ); 1214 1215 my $n_removed = $response->result; 1216 1217 $log->debug( "leaving" ); 1218 1219 return $n_removed; 1047 1220 } 1048 1221 -
branches/pap/Nebulous/lib/Nebulous/Client.pod
r20094 r25027 13 13 ); 14 14 15 my $uri = $neb->create( "key", "node01");16 my $fh = $neb->open_create( "key", "node01");17 $neb->replicate( "key", "node01");18 $neb->cull( "key", "node01");19 $neb->lock( "key", 'write' );20 $neb->unlock( "key", 'write' );15 my $uri = $neb->create( $key, $vol ); 16 my $fh = $neb->open_create( $key, $vol ); 17 $neb->replicate( $key, $vol ); 18 $neb->cull( $key, $vol ); 19 $neb->lock( $key, 'write' ); 20 $neb->unlock( $key, 'write' ); 21 21 $neb->setxattr( $key, $name, $value, $flags ); 22 22 $neb->getxattr( $key, $name ); … … 24 24 $neb->removexattr( $key, $name ); 25 25 my $uris = $neb->find_objects( $pattern ); 26 my $uris = $neb->find_instances( "key", "node01");27 my $path = $neb->find( "key");28 my $fh = $neb->open( "key", 'read' );29 $neb->delete( "key");30 $neb->copy( "key", "new_key", "node01");31 $neb->move( "key", "new_key");32 $neb->swap( "key1", "key2");26 my $uris = $neb->find_instances( $key, $vol ); 27 my $path = $neb->find( $key ); 28 my $fh = $neb->open( $key, 'read' ); 29 $neb->delete( $key ); 30 $neb->copy( $key, $new_key, $vol ); 31 $neb->move( $key, $new_key ); 32 $neb->swap( $key1, $key2 ); 33 33 $neb->delete_instance( $uri ); 34 my $stats = $neb->stat( "key");34 my $stats = $neb->stat( $key ); 35 35 my $mounts = $neb->mounts(); 36 my $mode = $neb->chmod( $key, $mode ); 37 my $n_dead = $neb->prune( $key ); 38 my $n_dead = $neb->there_can_be_only_one( $key, $vol ); 36 39 37 40 =head1 DESCRIPTION … … 404 407 405 408 Returns an arrayref of scalars. 409 410 =item * prune($key) 411 412 Removes all of the inaccessible instances from an object. 413 414 =over 4 415 416 =item * key 417 418 The storage object key (name). 419 420 =back 421 422 The number of instances removed. 423 424 =item * there_can_be_only_one($key, $vol) 425 426 Removes all but one instance of an object and automatically removes any 427 inaccessible instances. 428 429 =over 4 430 431 =item * key 432 433 The storage object key (name). 434 435 =item * vol 436 437 If specified, the only remaining instance will be left on this volume (if an 438 instance already exists there). 439 440 =back 441 442 The number of avaiable instances removed. 406 443 407 444 =item * mounts() … … 425 462 ] 426 463 464 =item * chmod( $key, $mode ); 465 466 Accepts 2 parameters, both mandatory. C<$key> is the nebulous key to operate 467 on and C<$mode> are the POSIX like file permissions to set on all instances of 468 C<$key>. C<$mode> must be specified in oct. Returns C<$mode> or sucess or an 469 exception on failure. 470 427 471 =back 428 472 … … 456 500 =head1 COPYRIGHT 457 501 458 Copyright (C) 2004-200 8Joshua Hoblitt. All rights reserved.502 Copyright (C) 2004-2009 Joshua Hoblitt. All rights reserved. 459 503 460 504 This program is free software; you can redistribute it and/or modify it under
Note:
See TracChangeset
for help on using the changeset viewer.
