41 list( $cluster, $id, $itemID ) = $this->
parseURL( $url );
44 if ( $itemID !==
false &&
$ret !==
false ) {
45 return $ret->getItem( $itemID );
61 $batched = $inverseUrlMap = [];
62 foreach ( $urls
as $url ) {
63 list( $cluster, $id, $itemID ) = $this->
parseURL( $url );
64 $batched[$cluster][$id][] = $itemID;
67 $inverseUrlMap[$cluster][$id][$itemID] = $url;
70 foreach ( $batched
as $cluster => $batchByCluster ) {
74 foreach ( $batchByCluster[$id]
as $itemID ) {
75 $url = $inverseUrlMap[$cluster][$id][$itemID];
76 if ( $itemID ===
false ) {
88 public function store( $location, $data ) {
90 $id = $dbw->nextSequenceValue(
'blob_blob_id_seq' );
91 $dbw->insert( $this->
getTable( $dbw ),
92 [
'blob_id' => $id,
'blob_text' => $data ],
94 $id = $dbw->insertId();
96 throw new MWException( __METHOD__ .
': no insert ID' );
99 return "DB://$location/$id";
109 $wiki = isset( $this->params[
'wiki'] ) ? $this->params[
'wiki'] :
false;
123 $wiki = isset( $this->params[
'wiki'] ) ? $this->params[
'wiki'] :
false;
126 if ( !in_array(
"DB://" . $cluster, (
array)$wgDefaultExternalStore ) ) {
127 wfDebug(
"read only external store\n" );
128 $lb->allowLagged(
true );
130 wfDebug(
"writable external store\n" );
133 $db = $lb->getConnectionRef(
DB_REPLICA, [], $wiki );
146 $wiki = isset( $this->params[
'wiki'] ) ? $this->params[
'wiki'] :
false;
149 $db = $lb->getConnectionRef(
DB_MASTER, [], $wiki );
162 $table = $db->getLBInfo(
'blobs table' );
163 if ( is_null( $table ) ) {
187 static $externalBlobCache = [];
189 $cacheID = ( $itemID ===
false ) ?
"$cluster/$id" :
"$cluster/$id/";
190 if ( isset( $externalBlobCache[$cacheID] ) ) {
192 "ExternalStoreDB::fetchBlob cache hit on $cacheID" );
194 return $externalBlobCache[$cacheID];
198 "ExternalStoreDB::fetchBlob cache miss on $cacheID" );
202 'blob_text', [
'blob_id' => $id ], __METHOD__ );
203 if (
$ret ===
false ) {
205 "ExternalStoreDB::fetchBlob master fallback on $cacheID" );
209 'blob_text', [
'blob_id' => $id ], __METHOD__ );
210 if (
$ret ===
false ) {
212 "ExternalStoreDB::fetchBlob master failed to find $cacheID" );
215 if ( $itemID !==
false &&
$ret !==
false ) {
220 $externalBlobCache = [ $cacheID =>
$ret ];
236 [
'blob_id',
'blob_text' ], [
'blob_id' => array_keys( $ids ) ], __METHOD__ );
238 if (
$res !==
false ) {
243 " master fallback on '$cluster' for: " .
244 implode(
',', array_keys( $ids ) ) );
248 [
'blob_id',
'blob_text' ],
249 [
'blob_id' => array_keys( $ids ) ],
251 if (
$res ===
false ) {
252 wfDebugLog( __CLASS__, __METHOD__ .
" master failed on '$cluster'" );
259 " master on '$cluster' failed locating items: " .
260 implode(
',', array_keys( $ids ) ) );
273 foreach (
$res as $row ) {
275 $itemIDs = $ids[$id];
277 if ( count( $itemIDs ) === 1 && reset( $itemIDs ) ===
false ) {
279 $ret[$id] = $row->blob_text;
292 $path = explode(
'/', $url );
297 isset( $path[4] ) ? $path[4] :
false
fetchBlob($cluster, $id, $itemID)
Fetch a blob item out of the database; a cache of the last-loaded blob will be kept so that multiple ...
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
fetchFromURL($url)
The provided URL is in the form of DB://cluster/id or DB://cluster/id/itemid for concatened storage...
the array() calling protocol came about after MediaWiki 1.4rc1.
array $wgDefaultExternalStore
The place to put new revisions, false to put them in the local text table.
Accessable external objects in a particular storage medium.
processing should stop and the error should be shown to the user * false
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
when a variable name is used in a it is silently declared as a new local masking the global
batchFetchFromURLs(array $urls)
Fetch data from given external store URLs.
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfDebugLog($logGroup, $text, $dest= 'all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not...
mergeBatchResult(array &$ret, array &$ids, $res)
Helper function for self::batchFetchBlobs for merging master/replica DB results.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
getTable($db)
Get the 'blobs' table name for this database.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
wfGetLBFactory()
Get the load balancer factory object.
batchFetchBlobs($cluster, array $ids)
Fetch multiple blob items out of the database.
getSlave($cluster)
Get a replica DB connection for the specified cluster.
DB accessable external objects.
getLoadBalancer($cluster)
Get a LoadBalancer for the specified cluster.
getMaster($cluster)
Get a master database connection for the specified cluster.