Changeset 342
- Timestamp:
- 08/11/06 03:20:15 (2 years ago)
- Files:
-
- branches/server-newrepl/lib/MogileFS/Worker/Monitor.pm (modified) (2 diffs)
- branches/server-newrepl/lib/MogileFS/Worker/Query.pm (modified) (1 diff)
- branches/server-newrepl/lib/MogileFS/Worker/Replicate.pm (modified) (7 diffs)
- branches/server-newrepl/t/00-startup.t (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/server-newrepl/lib/MogileFS/Worker/Monitor.pm
r338 r342 1 1 package MogileFS::Worker::Monitor; 2 # deletes files3 2 4 3 use strict; … … 28 27 every(2.5, sub { 29 28 $self->parent_ping; 30 $self->read_from_parent;31 29 32 30 # get db and note we're starting a run branches/server-newrepl/lib/MogileFS/Worker/Query.pm
r338 r342 325 325 $fid, $dmid, $key, $size, $trow->{classid}); 326 326 return $self->err_line("db_error") unless $rv; 327 328 # mark it as needing replicating: 329 $dbh->do("INSERT IGNORE INTO file_to_replicate ". 330 "SET fid=?, fromdevid=?, nexttry=0", undef, $fid, $devid); 331 return $self->err_line("db_error") if $dbh->err; 327 332 328 333 $dbh->do("DELETE FROM tempfile WHERE fid=?", undef, $fid); branches/server-newrepl/lib/MogileFS/Worker/Replicate.pm
r338 r342 95 95 } @$to_repl; 96 96 97 98 97 foreach my $todo (@$to_repl) { 99 98 my $fid = $todo->{fid}; 99 warn "to repl (new): $fid\n"; 100 100 101 101 my $errcode; 102 102 103 if (my $status = replicate($dbh, $fid, undef, \$errcode)) { 103 my ($status, $unlock) = replicate($dbh, $fid, errref => \$errcode, no_unlock => 1); 104 if ($status) { 104 105 # $status is either 0 (failure, handled below), 1 (success, we actually 105 106 # replicated this file), or 2 (success, but someone else replicated it). 107 106 108 # so if it's 2, we just want to go to the next fid. this file is done. 109 # somebody else presumably took care of the file_to_replicate maintenance 110 if ($status == 2) { 111 $unlock->() if $unlock; 112 next; 113 } 114 115 # replicate was a success, so cleanup table, then unlock 107 116 warn " new repl: $fid status = $status\n"; 108 next if $status == 2; 117 $dbh->do("DELETE FROM file_to_replicate WHERE fid=?", undef, $fid); 118 $unlock->(); 119 109 120 } else { 110 121 warn " new repl: $fid status = 0\n"; 111 122 error("ERROR CODE: $errcode"); 123 $unlock->() if $unlock; 112 124 } 113 125 } … … 170 182 $self->read_from_parent; 171 183 172 if (my $status = replicate($dbh, $fid, $mclass)) {184 if (my $status = replicate($dbh, $fid, class => $mclass)) { 173 185 # $status is either 0 (failure, handled below), 1 (success, we actually 174 186 # replicated this file), or 2 (success, but someone else replicated it). … … 205 217 # $policy_class is optional (perl classname representing replication policy). if present, used. if not, looked up based on $fid. 206 218 sub replicate { 207 my ($dbh, $fid, $mclass, $errref) = @_; 219 my ($dbh, $fid, %opts) = @_; 220 my $errref = delete $opts{'errref'}; 221 my $mclass = delete $opts{'class'}; 222 my $no_unlock = delete $opts{'no_unlock'}; 223 die if %opts; 224 208 225 $mclass ||= MogileFS::Class->of_fid($fid); 209 226 … … 213 230 return error("Failed to load policy class: $policy_class: $@"); 214 231 } 232 233 # hashref of devid -> $device_row_href (where devid is alive) 234 my $devs = Mgd::get_device_summary(); 235 return error("Device information from get_device_summary is empty") 236 unless $devs && %$devs; 215 237 216 238 my $lockname = "mgfs:fid:$fid:replicate"; … … 219 241 return error("Unable to obtain lock $lockname") 220 242 unless $lock; 221 222 # hashref of devid -> $device_row_href (where devid is alive)223 my $devs = Mgd::get_device_summary();224 return error("Device information from get_device_summary is empty")225 unless $devs && %$devs;226 243 227 244 # learn what devices this file is already on … … 245 262 } 246 263 264 my $unlock = sub { 265 $dbh->selectrow_array("SELECT RELEASE_LOCK(?)", undef, $lockname); 266 }; 267 247 268 my $retunlock = sub { 248 269 my $rv = shift; … … 254 275 } 255 276 $$errref = $errcode if $errref; 256 $dbh->selectrow_array("SELECT RELEASE_LOCK(?)", undef, $lockname); 257 return $rv ? $rv : error($errmsg); 277 278 my $ret = $rv ? $rv : error($errmsg); 279 if ($no_unlock) { 280 return ($ret, $unlock); 281 } else { 282 $unlock->(); 283 return $ret; 284 } 258 285 }; 259 286 branches/server-newrepl/t/00-startup.t
r341 r342 24 24 my $tempdb = create_temp_db(); 25 25 isa_ok $tempdb, "DBHandle"; 26 my $dbh = $tempdb->dbh; 26 27 27 28 my $rv; … … 97 98 my $tries = 1; 98 99 my @urls; 99 while ($tries < 10 && (@urls = $mogc->get_paths("file1")) < 2) {100 while ($tries++ < 10 && (@urls = $mogc->get_paths("file1")) < 2) { 100 101 sleep 1; 101 102 } … … 112 113 ok(unlink($path1), "deleted path $path1"); 113 114 my $dead_url = $urls[0]; 114 for (1.. 20) {115 for (1..10) { 115 116 @urls = $mogc->get_paths("file1"); 116 isnt($urls[0], $dead_url, "didn't return dead url first ");117 isnt($urls[0], $dead_url, "didn't return dead url first (try $_)"); 117 118 } 118 119 120 my $to_repl_rows = $dbh->selectrow_array("SELECT COUNT(*) FROM file_to_replicate"); 121 is($to_repl_rows, 0, "no more files to replicate"); 119 122 120 123 121
