return $value;
}
- public function delete( $key ) {
+ public function delete( $key, $flags = 0 ) {
apc_delete( $key . self::KEY_SUFFIX );
return true;
return true;
}
- public function delete( $key ) {
+ public function delete( $key, $flags = 0 ) {
apcu_delete( $key . self::KEY_SUFFIX );
return true;
*
* @param string $key
* @return bool True if the item was deleted or not found, false on failure
+ * @param int $flags Bitfield of BagOStuff::WRITE_* constants
*/
- abstract public function delete( $key );
+ abstract public function delete( $key, $flags = 0 );
/**
* Merge changes into the existing cache value (possibly creating a new one)
}
public function delete( $key, $flags = 0 ) {
- parent::delete( $key );
+ parent::delete( $key, $flags );
if ( !( $flags & self::WRITE_CACHE_ONLY ) ) {
$this->backend->delete( $key );
}
return true;
}
- public function delete( $key ) {
+ public function delete( $key, $flags = 0 ) {
return true;
}
return true;
}
- public function delete( $key ) {
+ public function delete( $key, $flags = 0 ) {
unset( $this->bag[$key] );
return true;
$value, $this->fixExpiry( $exptime ) );
}
- public function delete( $key ) {
+ public function delete( $key, $flags = 0 ) {
return $this->client->delete( $this->validateKeyEncoding( $key ) );
}
return $this->checkResult( $key, parent::cas( $casToken, $key, $value, $exptime ) );
}
- public function delete( $key ) {
+ public function delete( $key, $flags = 0 ) {
$this->debugLog( "delete($key)" );
$result = parent::delete( $key );
if ( $result === false && $this->client->getResultCode() === Memcached::RES_NOTFOUND ) {
return $this->doWrite( $this->cacheIndexes, $asyncWrites, 'set', $key, $value, $exptime );
}
- public function delete( $key ) {
+ public function delete( $key, $flags = 0 ) {
return $this->doWrite( $this->cacheIndexes, $this->asyncWrites, 'delete', $key );
}
return false;
}
- /**
- * Set an item
- *
- * @param string $key
- * @param mixed $value
- * @param int $exptime Either an interval in seconds or a unix timestamp for expiry
- * @param int $flags Bitfield of BagOStuff::WRITE_* constants
- * @return bool Success
- */
public function set( $key, $value, $exptime = 0, $flags = 0 ) {
+ // @TODO: respect WRITE_SYNC (e.g. EACH_QUORUM)
$req = [
'method' => 'PUT',
'url' => $this->url . rawurlencode( $key ),
return $this->handleError( "Failed to store $key", $rcode, $rerr );
}
- /**
- * Delete an item.
- *
- * @param string $key
- * @return bool True if the item was deleted or not found, false on failure
- */
- public function delete( $key ) {
+ public function delete( $key, $flags = 0 ) {
+ // @TODO: respect WRITE_SYNC (e.g. EACH_QUORUM)
$req = [
'method' => 'DELETE',
'url' => $this->url . rawurlencode( $key ),
return $result;
}
- public function delete( $key ) {
+ public function delete( $key, $flags = 0 ) {
list( $server, $conn ) = $this->getConnection( $key );
if ( !$conn ) {
return false;
return $this->writeStore->set( $key, $value, $exptime, $flags );
}
- public function delete( $key ) {
- return $this->writeStore->delete( $key );
+ public function delete( $key, $flags = 0 ) {
+ return $this->writeStore->delete( $key, $flags );
}
public function add( $key, $value, $exptime = 0 ) {
return ( is_array( $result ) && $result === [] ) || $result;
}
- public function delete( $key ) {
+ public function delete( $key, $flags = 0 ) {
wincache_ucache_delete( $key );
return true;
return (bool)$db->affectedRows();
}
- public function delete( $key ) {
+ public function delete( $key, $flags = 0 ) {
+ $ok = true;
+
list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
$db = null;
$silenceScope = $this->silenceTransactionProfiler();
__METHOD__ );
} catch ( DBError $e ) {
$this->handleWriteError( $e, $db, $serverIndex );
- return false;
+ $ok = false;
+ }
+ if ( ( $flags & self::WRITE_SYNC ) == self::WRITE_SYNC ) {
+ $ok = $this->waitForReplication() && $ok;
}
- return true;
+ return $ok;
}
public function incr( $key, $step = 1 ) {
if ( $exception instanceof DBConnectionError ) {
$this->markServerDown( $exception, $serverIndex );
}
- $this->logger->error( "DBError: {$exception->getMessage()}" );
- if ( $exception instanceof DBConnectionError ) {
- $this->setLastError( BagOStuff::ERR_UNREACHABLE );
- $this->logger->debug( __METHOD__ . ": ignoring connection error" );
- } else {
- $this->setLastError( BagOStuff::ERR_UNEXPECTED );
- $this->logger->debug( __METHOD__ . ": ignoring query error" );
- }
+
+ $this->setAndLogDBError( $exception );
}
/**
$this->markServerDown( $exception, $serverIndex );
}
+ $this->setAndLogDBError( $exception );
+ }
+
+ /**
+ * @param DBError $exception
+ */
+ private function setAndLogDBError( DBError $exception ) {
$this->logger->error( "DBError: {$exception->getMessage()}" );
if ( $exception instanceof DBConnectionError ) {
$this->setLastError( BagOStuff::ERR_UNREACHABLE );
}
// Main LB is used; wait for any replica DBs to catch up
- $masterPos = $lb->getMasterPos();
- if ( !$masterPos ) {
- return true; // not applicable
- }
+ try {
+ $masterPos = $lb->getMasterPos();
+ if ( !$masterPos ) {
+ return true; // not applicable
+ }
- $loop = new WaitConditionLoop(
- function () use ( $lb, $masterPos ) {
- return $lb->waitForAll( $masterPos, 1 );
- },
- $this->syncTimeout,
- $this->busyCallbacks
- );
+ $loop = new WaitConditionLoop(
+ function () use ( $lb, $masterPos ) {
+ return $lb->waitForAll( $masterPos, 1 );
+ },
+ $this->syncTimeout,
+ $this->busyCallbacks
+ );
- return ( $loop->invoke() === $loop::CONDITION_REACHED );
+ return ( $loop->invoke() === $loop::CONDITION_REACHED );
+ } catch ( DBError $e ) {
+ $this->setAndLogDBError( $e );
+
+ return false;
+ }
}
/**