return $values;
}
- public function setMulti( array $data, $expiry = 0 ) {
+ public function setMulti( array $data, $expiry = 0, $flags = 0 ) {
$keysByTable = [];
foreach ( $data as $key => $value ) {
list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
return $ok;
}
- protected function cas( $casToken, $key, $value, $exptime = 0 ) {
+ protected function cas( $casToken, $key, $value, $exptime = 0, $flags = 0 ) {
list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
$db = null;
$silenceScope = $this->silenceTransactionProfiler();
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 ) {
}
public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
- $ok = $this->mergeViaCas( $key, $callback, $exptime, $attempts );
+ $ok = $this->mergeViaCas( $key, $callback, $exptime, $attempts, $flags );
if ( ( $flags & self::WRITE_SYNC ) == self::WRITE_SYNC ) {
$ok = $this->waitForReplication() && $ok;
}
return $ok;
}
- public function changeTTL( $key, $expiry = 0 ) {
+ public function changeTTL( $key, $expiry = 0, $flags = 0 ) {
list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
$db = null;
$silenceScope = $this->silenceTransactionProfiler();
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;
+ }
}
/**