r10527 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r10526‎ | r10527 | r10528 >
Date:13:22, 15 August 2005
Author:midom
Status:old
Tags:
Comment:
Merge down Tim's HEAD changes
Modified paths:
  • /branches/REL1_5/phase3/includes/ExternalStoreDB.php (modified) (history)

Diff [purge]

Index: branches/REL1_5/phase3/includes/ExternalStoreDB.php
@@ -10,31 +10,74 @@
1111
1212
1313 /** @package MediaWiki */
 14+
1415 class ExternalStoreDB {
 16+ var $loadBalancers = array();
 17+
1518 /**
1619 * Fetch data from given URL
1720 * @param string $url An url
1821 */
 22+
 23+ function &getLoadBalancer( $cluster ) {
 24+ global $wgExternalServers;
 25+ if ( !array_key_exists( $cluster, $this->loadBalancers ) ) {
 26+ $this->loadBalancers[$cluster] = LoadBalancer::newFromParams( $wgExternalServers[$cluster] );
 27+ }
 28+ return $this->loadBalancers[$cluster];
 29+ }
 30+
 31+ function &getSlave( $cluster ) {
 32+ $lb =& $this->getLoadBalancer( $cluster );
 33+ return $lb->getConnection( DB_SLAVE );
 34+ }
 35+
 36+ function &getMaster( $cluster ) {
 37+ $lb =& $this->getLoadBalancer( $cluster );
 38+ return $lb->getConnection( DB_MASTER );
 39+ }
 40+
1941 function fetchFromURL($url) {
2042 global $wgExternalServers;
2143 #
22 - # URLs have the form DB://cluster/id, e.g.
23 - # DB://cluster1/3298247
 44+ # URLs have the form DB://cluster/id or DB://cluster/id/itemid for concatenated storage
2445 #
2546 $path = explode( '/', $url );
2647 $cluster = $path[2];
2748 $id = $path[3];
 49+ if ( isset( $path[4] ) ) {
 50+ $itemID = $path[4];
 51+ } else {
 52+ $itemID = false;
 53+ }
2854
29 - $lb = LoadBalancer::NewFromParams( $wgExternalServers[$cluster] );
30 - $db = $lb->getConnection( DB_SLAVE );
 55+ $dbr =& $this->getSlave( $cluster );
 56+ $ret = $dbr->selectField( 'blobs', 'blob_text', array( 'blob_id' => $id ) );
3157
32 - $ret = $db->selectField( 'blobs', 'blob_text', array( 'blob_id' => $id ) );
33 -
 58+ if ( $itemID !== false ) {
 59+ # Unserialise object and get item
 60+ $obj = unserialize( $ret );
 61+ $ret = $obj->getItem( $itemID );
 62+ }
3463 return $ret;
3564 }
3665
37 - /* @fixme XXX: may require other methods, for store, delete,
38 - * whatever, for initial ext storage
 66+ /**
 67+ * Insert a data item into a given cluster
 68+ *
 69+ * @param string $cluster The cluster name
 70+ * @param string $data The data item
 71+ * @return string URL
3972 */
 73+ function store( $cluster, $data ) {
 74+ global $wgExternalServers;
 75+ $fname = 'ExternalStoreDB::store';
 76+
 77+ $dbw =& $this->getMaster( $cluster );
 78+
 79+ $id = $dbw->nextSequenceValue( 'blob_blob_id_seq' );
 80+ $dbw->insert( 'blobs', array( 'blob_id' => $id, 'blob_text' => $data ), $fname );
 81+ return "DB://$cluster/" . $dbw->insertId();
 82+ }
4083 }
4184 ?>

Status & tagging log