From af47b8260c824f241919cad43dbf37b215586a30 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 29 Oct 2005 01:41:36 +0000 Subject: [PATCH] Ability to set the blobs table name for any server in an external cluster. This would allow, for example, the merging of all external storage for a large wikipedia dump into a single database, with "clusters" distinguished by table name. --- RELEASE-NOTES | 1 + includes/Database.php | 24 ++++++++++++++++++++++++ includes/DefaultSettings.php | 6 ++++++ includes/ExternalStoreDB.php | 12 ++++++++++-- includes/LoadBalancer.php | 4 +++- 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 65a4d88ace..69b517fa9a 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -190,6 +190,7 @@ fully support the editing toolbar, but was found to be too confusing. * (bug 3649) Remove obsolete, broken moveCustomMessages script * (bug 3291) 'last' diff link for last history line when not at end * Avoid numerous redundant latest-revision lookups in history +* Ability to set the table name for external storage servers === Caveats === diff --git a/includes/Database.php b/includes/Database.php index 3d2f5c0daa..a4a889c6d3 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -62,6 +62,7 @@ class Database { var $mFlags; var $mTrxLevel = 0; var $mErrorCount = 0; + var $mLBInfo = array(); /**#@-*/ #------------------------------------------------------------------------------ @@ -130,6 +131,29 @@ class Database { return wfSetVar( $this->mErrorCount, $count ); } + /** + * Properties passed down from the server info array of the load balancer + */ + function getLBInfo( $name = NULL ) { + if ( is_null( $name ) ) { + return $this->mLBInfo; + } else { + if ( array_key_exists( $name, $this->mLBInfo ) ) { + return $this->mLBInfo[$name]; + } else { + return NULL; + } + } + } + + function setLBInfo( $name, $value = NULL ) { + if ( is_null( $value ) ) { + $this->mLBInfo = $name; + } else { + $this->mLBInfo[$name] = $value; + } + } + /**#@+ * Get function */ diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index a2eab9c6ac..e395f987bc 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -446,6 +446,12 @@ $wgSharedDB = null; # DBO_IGNORE -- ignore errors (not useful in LocalSettings.php) # DBO_NOBUFFER -- turn off buffering (not useful in LocalSettings.php) # +# max lag: (optional) Maximum replication lag before a slave will taken out of rotation +# max threads: (optional) Maximum number of running threads +# +# These and any other user-defined properties will be assigned to the mLBInfo member +# variable of the Database object. +# # Leave at false to use the single-server variables above $wgDBservers = false; diff --git a/includes/ExternalStoreDB.php b/includes/ExternalStoreDB.php index d07e23b4d1..9623778350 100644 --- a/includes/ExternalStoreDB.php +++ b/includes/ExternalStoreDB.php @@ -54,6 +54,14 @@ class ExternalStoreDB { $lb =& $this->getLoadBalancer( $cluster ); return $lb->getConnection( DB_MASTER ); } + + function getTable( &$db ) { + $table = $db->getLBInfo( 'blobs table' ); + if ( is_null( $table ) ) { + $table = 'blobs'; + } + return $table; + } function fetchFromURL($url) { global $wgExternalServers; @@ -95,7 +103,7 @@ class ExternalStoreDB { wfDebug( "ExternalStoreDB::fetchBlob cache miss on $cacheID\n" ); $dbr =& $this->getSlave( $cluster ); - $ret = $dbr->selectField( 'blobs', 'blob_text', array( 'blob_id' => $id ) ); + $ret = $dbr->selectField( $this->getTable( $dbr ), 'blob_text', array( 'blob_id' => $id ) ); if( $itemID !== false ) { // Unserialise object; caller extracts item $ret = unserialize( $ret ); @@ -119,7 +127,7 @@ class ExternalStoreDB { $dbw =& $this->getMaster( $cluster ); $id = $dbw->nextSequenceValue( 'blob_blob_id_seq' ); - $dbw->insert( 'blobs', array( 'blob_id' => $id, 'blob_text' => $data ), $fname ); + $dbw->insert( $this->getTable( $dbw ), array( 'blob_id' => $id, 'blob_text' => $data ), $fname ); return "DB://$cluster/" . $dbw->insertId(); } } diff --git a/includes/LoadBalancer.php b/includes/LoadBalancer.php index aaa4d839da..edc1fad078 100644 --- a/includes/LoadBalancer.php +++ b/includes/LoadBalancer.php @@ -438,7 +438,9 @@ class LoadBalancer { } # Create object - return new $class( $host, $user, $password, $dbname, 1, $flags ); + $db = new $class( $host, $user, $password, $dbname, 1, $flags ); + $db->setLBInfo( $server ); + return $db; } function reportConnectionError( &$conn ) -- 2.20.1