* The provided URL is in the form of DB://cluster/id
* or DB://cluster/id/itemid for concatened storage.
*
+ * @param string $url
+ * @return string|bool False if missing
* @see ExternalStoreMedium::fetchFromURL()
*/
public function fetchFromURL( $url ) {
* are not represented.
*/
public function batchFetchFromURLs( array $urls ) {
- $batched = $inverseUrlMap = array();
+ $batched = $inverseUrlMap = [];
foreach ( $urls as $url ) {
list( $cluster, $id, $itemID ) = $this->parseURL( $url );
$batched[$cluster][$id][] = $itemID;
// since we do === from the $itemID in $batched
$inverseUrlMap[$cluster][$id][$itemID] = $url;
}
- $ret = array();
+ $ret = [];
foreach ( $batched as $cluster => $batchByCluster ) {
$res = $this->batchFetchBlobs( $cluster, $batchByCluster );
/** @var HistoryBlob $blob */
return $ret;
}
- /**
- * @see ExternalStoreMedium::store()
- */
- public function store( $cluster, $data ) {
- $dbw = $this->getMaster( $cluster );
+ public function store( $location, $data ) {
+ $dbw = $this->getMaster( $location );
$id = $dbw->nextSequenceValue( 'blob_blob_id_seq' );
$dbw->insert( $this->getTable( $dbw ),
- array( 'blob_id' => $id, 'blob_text' => $data ),
+ [ 'blob_id' => $id, 'blob_text' => $data ],
__METHOD__ );
$id = $dbw->insertId();
if ( !$id ) {
throw new MWException( __METHOD__ . ': no insert ID' );
}
- return "DB://$cluster/$id";
+ return "DB://$location/$id";
}
/**
}
/**
- * Get a slave database connection for the specified cluster
+ * Get a replica DB connection for the specified cluster
*
* @param string $cluster Cluster name
* @return IDatabase
wfDebug( "writable external store\n" );
}
- $db = $lb->getConnection( DB_SLAVE, array(), $wiki );
+ $db = $lb->getConnection( DB_SLAVE, [], $wiki );
$db->clearFlag( DBO_TRX ); // sanity
return $db;
$wiki = isset( $this->params['wiki'] ) ? $this->params['wiki'] : false;
$lb = $this->getLoadBalancer( $cluster );
- $db = $lb->getConnection( DB_MASTER, array(), $wiki );
+ $db = $lb->getConnection( DB_MASTER, [], $wiki );
$db->clearFlag( DBO_TRX ); // sanity
return $db;
* @param string $cluster
* @param string $id
* @param string $itemID
- * @return mixed
+ * @return HistoryBlob|bool Returns false if missing
* @private
*/
function fetchBlob( $cluster, $id, $itemID ) {
* the same blob. By keeping the last-used one open, we avoid
* redundant unserialization and decompression overhead.
*/
- static $externalBlobCache = array();
+ static $externalBlobCache = [];
$cacheID = ( $itemID === false ) ? "$cluster/$id" : "$cluster/$id/";
if ( isset( $externalBlobCache[$cacheID] ) ) {
$dbr = $this->getSlave( $cluster );
$ret = $dbr->selectField( $this->getTable( $dbr ),
- 'blob_text', array( 'blob_id' => $id ), __METHOD__ );
+ 'blob_text', [ 'blob_id' => $id ], __METHOD__ );
if ( $ret === false ) {
wfDebugLog( 'ExternalStoreDB',
"ExternalStoreDB::fetchBlob master fallback on $cacheID" );
// Try the master
$dbw = $this->getMaster( $cluster );
$ret = $dbw->selectField( $this->getTable( $dbw ),
- 'blob_text', array( 'blob_id' => $id ), __METHOD__ );
+ 'blob_text', [ 'blob_id' => $id ], __METHOD__ );
if ( $ret === false ) {
wfDebugLog( 'ExternalStoreDB',
"ExternalStoreDB::fetchBlob master failed to find $cacheID" );
$ret = unserialize( $ret );
}
- $externalBlobCache = array( $cacheID => $ret );
+ $externalBlobCache = [ $cacheID => $ret ];
return $ret;
}
function batchFetchBlobs( $cluster, array $ids ) {
$dbr = $this->getSlave( $cluster );
$res = $dbr->select( $this->getTable( $dbr ),
- array( 'blob_id', 'blob_text' ), array( 'blob_id' => array_keys( $ids ) ), __METHOD__ );
- $ret = array();
+ [ 'blob_id', 'blob_text' ], [ 'blob_id' => array_keys( $ids ) ], __METHOD__ );
+ $ret = [];
if ( $res !== false ) {
$this->mergeBatchResult( $ret, $ids, $res );
}
// Try the master
$dbw = $this->getMaster( $cluster );
$res = $dbw->select( $this->getTable( $dbr ),
- array( 'blob_id', 'blob_text' ),
- array( 'blob_id' => array_keys( $ids ) ),
+ [ 'blob_id', 'blob_text' ],
+ [ 'blob_id' => array_keys( $ids ) ],
__METHOD__ );
if ( $res === false ) {
wfDebugLog( __CLASS__, __METHOD__ . " master failed on '$cluster'" );
}
/**
- * Helper function for self::batchFetchBlobs for merging master/slave results
+ * Helper function for self::batchFetchBlobs for merging master/replica DB results
* @param array &$ret Current self::batchFetchBlobs return value
* @param array &$ids Map from blob_id to requested itemIDs
* @param mixed $res DB result from Database::select
protected function parseURL( $url ) {
$path = explode( '/', $url );
- return array(
+ return [
$path[2], // cluster
$path[3], // id
isset( $path[4] ) ? $path[4] : false // itemID
- );
+ ];
}
}