Changeset 25121
- Timestamp:
- Aug 18, 2009, 5:02:45 PM (17 years ago)
- Location:
- trunk/Nebulous
- Files:
-
- 4 edited
-
bin/neb-cull (modified) (3 diffs)
-
lib/Nebulous/Client.pm (modified) (3 diffs)
-
t/53_client_cull.t (modified) (2 diffs)
-
t/72_neb-cull.t (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous/bin/neb-cull
r24996 r25121 16 16 use Pod::Usage qw( pod2usage ); 17 17 18 my ($ server, $volume, $one_only);18 my ($min_copies, $server, $volume, $one_only); 19 19 20 20 $server = $ENV{'NEB_SERVER'} unless $server; 21 21 22 22 GetOptions( 23 'min_copies|m=i'=> \$min_copies, 23 24 'server|s=s' => \$server, 24 25 'volume|v=s' => \$volume, … … 41 42 unless defined $neb; 42 43 44 $volume ||= "any"; 45 $min_copies ||= 2; 46 43 47 my @cull_args; 44 48 push @cull_args, $key; 45 if (defined $volume) { 46 push @cull_args, $volume; 47 } 49 push @cull_args, $volume; 48 50 49 51 if ($one_only) { … … 58 60 } 59 61 } else { 62 push @cull_args, $min_copies; 60 63 unless (defined $neb->cull(@cull_args)) { 61 64 die "failed to cull Nebulous key: $key - " . $neb->err; -
trunk/Nebulous/lib/Nebulous/Client.pm
r24996 r25121 275 275 my $self = shift; 276 276 277 my ($key, $vol_name ) = validate_pos(@_,277 my ($key, $vol_name, $min_copies) = validate_pos(@_, 278 278 { 279 279 type => SCALAR, … … 284 284 optional => 1, 285 285 }, 286 ); 287 288 $log->debug( "entered - @_" ); 289 290 my $locations; 286 { 287 # min copies 288 type => SCALAR, 289 optional => 1, 290 }, 291 ); 292 293 $min_copies ||= 1; 294 295 $log->debug( "entered - @_" ); 296 297 my $stats = $self->stat($key); 298 my $instances = $stats->[6]; 299 if ((not defined $instances) or ($instances == 0)) { 300 $self->set_err("can not cull - no instances"); 301 $log->debug("leaving"); 302 return; 303 } 304 if ($instances < $min_copies) { 305 $self->set_err("can not cull - not enough instances"); 306 $log->debug("leaving"); 307 308 return; 309 } 310 291 311 # if vol_name is specified we need to stat the file to find out how many 292 312 # instances there are on all volumes. Otherwise we wouldn't know if it's 293 313 # safe to remove the last instance on the specified volume. 294 314 # XXX We need some way to determine which is the best instance to remove 315 my $locations; 295 316 if (defined $vol_name) { 296 my @stats = $self->stat($key);297 my $instances = $stats[6];298 if (defined $instances and $instances < 2) {299 $self->set_err("can not cull - not enough instances");300 $log->debug("leaving");301 302 return;303 }304 305 317 $locations = $self->find_instances($key, $vol_name); 306 unless (defined $locations) {307 $self->set_err( "no instances" );308 $log->debug( "leaving" );309 310 return;311 }312 318 } else { 313 319 $locations = $self->find_instances($key); 314 unless ($locations) { 315 $self->set_err( "no instances" ); 316 $log->debug("leaving"); 317 318 return; 319 } 320 321 if (scalar @{ $locations } < 2) { 322 $self->set_err("can not cull - not enough instances"); 323 $log->debug("leaving"); 324 325 return; 326 } 320 } 321 322 unless (defined $locations) { 323 $self->set_err( "no instances" ); 324 $log->debug( "leaving" ); 325 326 return; 327 327 } 328 328 … … 393 393 } 394 394 for (my $i = 1; $i < $stats->[6]; $i++) { 395 $self->cull($key );395 $self->cull($key, "any", 1); 396 396 $removed++; 397 397 } -
trunk/Nebulous/t/53_client_cull.t
r13180 r25121 114 114 $neb->cull(); 115 115 }; 116 like( $@, qr/1 - 2were expected/, "no params" );116 like( $@, qr/1 - 3 were expected/, "no params" ); 117 117 118 118 Test::Nebulous->setup; … … 122 122 proxy => "http://$hostport/nebulous", 123 123 ); 124 $neb->cull( 1, 2, 3 );124 $neb->cull( 1, 2, 3, 4 ); 125 125 }; 126 like( $@, qr/1 - 2were expected/, "too many params" );126 like( $@, qr/1 - 3 were expected/, "too many params" ); 127 127 128 128 Test::Nebulous->cleanup; -
trunk/Nebulous/t/72_neb-cull.t
r24996 r25121 17 17 18 18 use Apache::Test qw( -withtestmore ); 19 plan tests => 29;19 plan tests => 41; 20 20 21 21 use lib qw( ./lib ./t ); … … 71 71 is($? >> 8, 255, "exit code"); 72 72 like($test->stdout, qr/^$/, "stdout"); 73 like($test->stderr, qr/failed to cull Nebulous key/, "stderr"); 74 } 75 76 Test::Nebulous->setup; 77 78 { 79 my $key = 'foo'; 80 81 my $neb = Nebulous::Client->new( 82 proxy => $neb_url, 83 ); 84 $neb->create($key); 85 $neb->replicate($key); 86 87 $test->run(args => $key); 88 89 is($neb->stat($key)->[6], 1, "correct # of instances"); 90 is($? >> 8, 0, "exit code"); 91 like($test->stdout, qr/^$/, "stdout"); 92 like($test->stderr, qr/^$/, "stderr"); 93 } 94 95 Test::Nebulous->setup; 96 97 { 98 my $key = 'foo'; 99 100 my $neb = Nebulous::Client->new( 101 proxy => $neb_url, 102 ); 103 $neb->create($key); 104 $neb->replicate($key); 105 $neb->replicate($key); 106 107 $test->run(args => $key); 108 109 is($neb->stat($key)->[6], 2, "correct # of instances"); 110 is($? >> 8, 0, "exit code"); 111 like($test->stdout, qr/^$/, "stdout"); 112 like($test->stderr, qr/^$/, "stderr"); 113 } 114 115 Test::Nebulous->setup; 116 117 { 118 my $key = 'foo'; 119 120 my $neb = Nebulous::Client->new( 121 proxy => $neb_url, 122 ); 123 $neb->create($key); 124 125 $test->run(args => "--one_only " . $key); 126 127 is($neb->stat($key)->[6], 1, "correct # of instances"); 128 is($? >> 8, 255, "exit code"); 129 like($test->stdout, qr/^$/, "stdout"); 73 130 like($test->stderr, qr/not enough instances/, "stderr"); 74 131 } … … 85 142 $neb->replicate($key); 86 143 87 $test->run(args => $key);88 89 is($neb->stat($key)->[6], 1, "correct # of instances");90 is($? >> 8, 0, "exit code");91 like($test->stdout, qr/^$/, "stdout");92 like($test->stderr, qr/^$/, "stderr");93 }94 95 Test::Nebulous->setup;96 97 {98 my $key = 'foo';99 100 my $neb = Nebulous::Client->new(101 proxy => $neb_url,102 );103 $neb->create($key);104 $neb->replicate($key);105 $neb->replicate($key);106 107 $test->run(args => $key);108 109 is($neb->stat($key)->[6], 2, "correct # of instances");110 is($? >> 8, 0, "exit code");111 like($test->stdout, qr/^$/, "stdout");112 like($test->stderr, qr/^$/, "stderr");113 }114 115 Test::Nebulous->setup;116 117 {118 my $key = 'foo';119 120 my $neb = Nebulous::Client->new(121 proxy => $neb_url,122 );123 $neb->create($key);124 125 144 $test->run(args => "--one_only " . $key); 126 145 127 146 is($neb->stat($key)->[6], 1, "correct # of instances"); 128 is($? >> 8, 255, "exit code"); 147 is($? >> 8, 0, "exit code"); 148 like($test->stdout, qr/^$/, "stdout"); 149 like($test->stderr, qr/^$/, "stderr"); 150 } 151 152 Test::Nebulous->setup; 153 154 { 155 my $key = 'foo'; 156 157 my $neb = Nebulous::Client->new( 158 proxy => $neb_url, 159 ); 160 $neb->create($key); 161 $neb->replicate($key); 162 $neb->replicate($key); 163 164 $test->run(args => "--one_only " . $key); 165 166 is($neb->stat($key)->[6], 1, "correct # of instances"); 167 is($? >> 8, 0, "exit code"); 168 like($test->stdout, qr/^$/, "stdout"); 169 like($test->stderr, qr/^$/, "stderr"); 170 } 171 172 Test::Nebulous->setup; 173 174 { 175 my $key = 'foo'; 176 177 my $neb = Nebulous::Client->new( 178 proxy => $neb_url, 179 ); 180 $neb->create($key); 181 $neb->replicate($key); 182 183 $test->run(args => "--min_copies 1 " . $key); 184 185 is($neb->stat($key)->[6], 1, "correct # of instances"); 186 is($? >> 8, 0, "exit code"); 187 like($test->stdout, qr/^$/, "stdout"); 188 like($test->stderr, qr/^$/, "stderr"); 189 } 190 191 Test::Nebulous->setup; 192 193 { 194 my $key = 'foo'; 195 196 my $neb = Nebulous::Client->new( 197 proxy => $neb_url, 198 ); 199 $neb->create($key); 200 201 $test->run(args => "--min_copies 1 " . $key); 202 203 is($neb->stat($key)->[6], 1, "correct # of instances"); 204 is($? >> 8, 0, "exit code"); 129 205 like($test->stdout, qr/^$/, "stdout"); 130 206 like($test->stderr, qr/not enough instances/, "stderr"); … … 141 217 $neb->create($key); 142 218 $neb->replicate($key); 143 144 $test->run(args => "--one_only " . $key); 145 146 is($neb->stat($key)->[6], 1, "correct # of instances"); 147 is($? >> 8, 0, "exit code"); 148 like($test->stdout, qr/^$/, "stdout"); 149 like($test->stderr, qr/^$/, "stderr"); 150 } 151 152 Test::Nebulous->setup; 153 154 { 155 my $key = 'foo'; 156 157 my $neb = Nebulous::Client->new( 158 proxy => $neb_url, 159 ); 160 $neb->create($key); 161 $neb->replicate($key); 162 $neb->replicate($key); 163 164 $test->run(args => "--one_only " . $key); 219 $neb->replicate($key); 220 221 $test->run(args => "--min_copies 2 " . $key); 165 222 166 223 is($neb->stat($key)->[6], 1, "correct # of instances");
Note:
See TracChangeset
for help on using the changeset viewer.
