X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FExternalStoreDB.php;h=6f2b33e1ff77d9d4190217fcf8083ac7bc7c20fe;hb=45bf4e80bf80d4d00a1a3f62115649fe6cd84914;hp=877277a2806c15318b7e40dfcfddd7c3e7c7a31e;hpb=4960bff13d90c8afd48077682bb0bbad49b85d6b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ExternalStoreDB.php b/includes/ExternalStoreDB.php index 877277a280..6f2b33e1ff 100644 --- a/includes/ExternalStoreDB.php +++ b/includes/ExternalStoreDB.php @@ -1,4 +1,24 @@ mParams['wiki']) ? $this->mParams['wiki'] : false; - + return wfGetLBFactory()->getExternalLB( $cluster, $wiki ); } @@ -29,8 +49,18 @@ class ExternalStoreDB { * @return DatabaseBase object */ function &getSlave( $cluster ) { + global $wgDefaultExternalStore; + $wiki = isset($this->mParams['wiki']) ? $this->mParams['wiki'] : false; $lb =& $this->getLoadBalancer( $cluster ); + + if ( !in_array( "DB://" . $cluster, (array)$wgDefaultExternalStore ) ) { + wfDebug( "read only external store" ); + $lb->allowLagged(true); + } else { + wfDebug( "writable external store" ); + } + return $lb->getConnection( DB_SLAVE, array(), $wiki ); } @@ -63,6 +93,7 @@ class ExternalStoreDB { /** * Fetch data from given URL * @param $url String: an url of the form DB://cluster/id or DB://cluster/id/itemid for concatened storage. + * @return mixed */ function fetchFromURL( $url ) { $path = explode( '/', $url ); @@ -110,12 +141,12 @@ class ExternalStoreDB { wfDebug( "ExternalStoreDB::fetchBlob cache miss on $cacheID\n" ); $dbr =& $this->getSlave( $cluster ); - $ret = $dbr->selectField( $this->getTable( $dbr ), 'blob_text', array( 'blob_id' => $id ) ); + $ret = $dbr->selectField( $this->getTable( $dbr ), 'blob_text', array( 'blob_id' => $id ), __METHOD__ ); if ( $ret === false ) { wfDebugLog( 'ExternalStoreDB', "ExternalStoreDB::fetchBlob master fallback on $cacheID\n" ); // Try the master $dbw =& $this->getMaster( $cluster ); - $ret = $dbw->selectField( $this->getTable( $dbw ), 'blob_text', array( 'blob_id' => $id ) ); + $ret = $dbw->selectField( $this->getTable( $dbw ), 'blob_text', array( 'blob_id' => $id ), __METHOD__ ); if( $ret === false) { wfDebugLog( 'ExternalStoreDB', "ExternalStoreDB::fetchBlob master failed to find $cacheID\n" ); } @@ -139,15 +170,15 @@ class ExternalStoreDB { function store( $cluster, $data ) { $dbw = $this->getMaster( $cluster ); $id = $dbw->nextSequenceValue( 'blob_blob_id_seq' ); - $dbw->insert( $this->getTable( $dbw ), - array( 'blob_id' => $id, 'blob_text' => $data ), + $dbw->insert( $this->getTable( $dbw ), + array( 'blob_id' => $id, 'blob_text' => $data ), __METHOD__ ); $id = $dbw->insertId(); if ( !$id ) { throw new MWException( __METHOD__.': no insert ID' ); } if ( $dbw->getFlag( DBO_TRX ) ) { - $dbw->commit(); + $dbw->commit( __METHOD__ ); } return "DB://$cluster/$id"; }