*/
protected function mergeViaCas( $key, $callback, $exptime = 0, $attempts = 10 ) {
do {
+ $this->clearLastError();
$casToken = null; // passed by reference
$currentValue = $this->get( $key, $casToken );
+ if ( $this->getLastError() ) {
+ return false; // don't spam retries (retry only on races)
+ }
+
// Derive the new value from the old value
$value = call_user_func( $callback, $this, $key, $currentValue );
+ $this->clearLastError();
if ( $value === false ) {
$success = true; // do nothing
} elseif ( $currentValue === false ) {
// Try to update the key, failing if it gets changed in the meantime
$success = $this->cas( $casToken, $key, $value, $exptime );
}
+ if ( $this->getLastError() ) {
+ return false; // IO error; don't spam retries
+ }
} while ( !$success && --$attempts );
return $success;
return false;
}
+ $this->clearLastError();
$currentValue = $this->get( $key );
- // Derive the new value from the old value
- $value = call_user_func( $callback, $this, $key, $currentValue );
+ if ( !$this->getLastError() ) {
+ // Derive the new value from the old value
+ $value = call_user_func( $callback, $this, $key, $currentValue );
- if ( $value === false ) {
- $success = true; // do nothing
- } else {
- $success = $this->set( $key, $value, $exptime ); // set the new value
+ if ( $value === false ) {
+ $success = true; // do nothing
+ } else {
+ $success = $this->set( $key, $value, $exptime ); // set the new value
+ }
}
if ( !$this->unlock( $key ) ) {