| 123 | | error("ERROR CODE for fid $fid: $errcode"); |
|---|
| | 125 | # bail if we failed getting the lock, that means someone else probably |
|---|
| | 126 | # already did it, so we should just move on |
|---|
| | 127 | if ($errcode eq 'failed_getting_lock') { |
|---|
| | 128 | $unlock->() if $unlock; |
|---|
| | 129 | next; |
|---|
| | 130 | } |
|---|
| | 131 | |
|---|
| | 132 | # logic for setting the next try time appropriately |
|---|
| | 133 | my $update_nexttry = sub { |
|---|
| | 134 | my ($type, $delay) = @_; |
|---|
| | 135 | error("update_nexttry( $type, $delay ) for $fid"); |
|---|
| | 136 | if ($type eq 'end_of_time') { |
|---|
| | 137 | # special; update to a time that won't happen again, as we've encountered a scenario |
|---|
| | 138 | # in which case we're really hosed |
|---|
| | 139 | $dbh->do("UPDATE file_to_replicate SET nexttry = 2147483647, failcount = failcount + 1 WHERE fid = ?", |
|---|
| | 140 | undef, $fid); |
|---|
| | 141 | } else { |
|---|
| | 142 | my $extra = $type eq 'offset' ? 'UNIX_TIMESTAMP() +' : ''; |
|---|
| | 143 | $dbh->do("UPDATE file_to_replicate SET nexttry = $extra ?, failcount = failcount + 1 WHERE fid = ?", |
|---|
| | 144 | undef, $delay+0, $fid); |
|---|
| | 145 | } |
|---|
| | 146 | error("Failed setting nexttry of fid $fid to $type $delay: " . $dbh->errstr) |
|---|
| | 147 | if $dbh->err; |
|---|
| | 148 | }; |
|---|
| | 149 | |
|---|
| | 150 | # now let's handle any error we want to consider a total failure; do not |
|---|
| | 151 | # retry at any point. push this file off to the end so someone has to come |
|---|
| | 152 | # along and figure out what went wrong. |
|---|
| | 153 | if ($errcode eq 'no_source' || $errcode eq 'no_devices') { |
|---|
| | 154 | $update_nexttry->( end_of_time => 1 ); |
|---|
| | 155 | $unlock->() if $unlock; |
|---|
| | 156 | next; |
|---|
| | 157 | } |
|---|
| | 158 | |
|---|
| | 159 | # at this point, the rest of the errors require exponential backoff. define what this means |
|---|
| | 160 | # as far as failcount -> delay to next try. |
|---|
| | 161 | # 15s, 1m, 5m, 30m, 1h, 2h, 4h, 8h, 24h, 24h, 24h, 24h, ... |
|---|
| | 162 | my @backoff = qw( 15 60 300 1800 3600 7200 14400 28800 ); |
|---|
| | 163 | $update_nexttry->( offset => $backoff[$todo->{failcount}] || 86400 ); |
|---|
| | 164 | $unlock->() if $unlock; |
|---|
| | 165 | |
|---|
| | 166 | #error("ERROR CODE for fid $fid: $errcode"); |
|---|