예제 #1
0
 function __call($name, array $arguments)
 {
     if ($this->conn === null) {
         list($db, $groups, $wiki) = $this->params;
         $this->conn = $this->lb->getConnection($db, $groups, $wiki);
     }
     return call_user_func_array(array($this->conn, $name), $arguments);
 }
예제 #2
0
 /**
  * Clears the list of sites stored in the database.
  *
  * @see SiteStore::clear()
  *
  * @return bool Success
  */
 public function clear()
 {
     $dbw = $this->dbLoadBalancer->getConnection(DB_MASTER);
     $dbw->startAtomic(__METHOD__);
     $ok = $dbw->delete('sites', '*', __METHOD__);
     $ok = $dbw->delete('site_identifiers', '*', __METHOD__) && $ok;
     $dbw->endAtomic(__METHOD__);
     $this->reset();
     return $ok;
 }
예제 #3
0
 /**
  * @return DatabaseBase
  */
 protected function getDB()
 {
     if (!isset($this->db)) {
         # If server connection info was given, use that
         if ($this->serverInfo) {
             $this->lb = new LoadBalancer(array('servers' => array($this->serverInfo)));
             $this->db = $this->lb->getConnection(DB_MASTER);
             $this->db->clearFlag(DBO_TRX);
         } else {
             # We must keep a separate connection to MySQL in order to avoid deadlocks
             # However, SQLite has an opposite behaviour.
             # @todo Investigate behaviour for other databases
             if (wfGetDB(DB_MASTER)->getType() == 'sqlite') {
                 $this->db = wfGetDB(DB_MASTER);
             } else {
                 $this->lb = wfGetLBFactory()->newMainLB();
                 $this->db = $this->lb->getConnection(DB_MASTER);
                 $this->db->clearFlag(DBO_TRX);
             }
         }
     }
     return $this->db;
 }
예제 #4
0
	/**
	 * Get a connection to the specified database
	 *
	 * @param $serverIndex integer
	 * @return DatabaseBase
	 */
	protected function getDB( $serverIndex ) {
		global $wgDebugDBTransactions;

		if ( !isset( $this->conns[$serverIndex] ) ) {
			if ( $serverIndex >= $this->numServers ) {
				throw new MWException( __METHOD__ . ": Invalid server index \"$serverIndex\"" );
			}

			# Don't keep timing out trying to connect for each call if the DB is down
			if ( isset( $this->connFailureErrors[$serverIndex] )
				&& ( time() - $this->connFailureTimes[$serverIndex] ) < 60 )
			{
				throw $this->connFailureErrors[$serverIndex];
			}

			# If server connection info was given, use that
			if ( $this->serverInfos ) {
				if ( $wgDebugDBTransactions ) {
					wfDebug( "Using provided serverInfo for SqlBagOStuff\n" );
				}
				$info = $this->serverInfos[$serverIndex];
				$type = isset( $info['type'] ) ? $info['type'] : 'mysql';
				$host = isset( $info['host'] ) ? $info['host'] : '[unknown]';
				wfDebug( __CLASS__ . ": connecting to $host\n" );
				$db = DatabaseBase::factory( $type, $info );
				$db->clearFlag( DBO_TRX );
			} else {
				/*
				 * We must keep a separate connection to MySQL in order to avoid deadlocks
				 * However, SQLite has an opposite behavior. And PostgreSQL needs to know
				 * if we are in transaction or no
				 */
				if ( wfGetDB( DB_MASTER )->getType() == 'mysql' ) {
					$this->lb = wfGetLBFactory()->newMainLB();
					$db = $this->lb->getConnection( DB_MASTER );
					$db->clearFlag( DBO_TRX ); // auto-commit mode
				} else {
					$db = wfGetDB( DB_MASTER );
				}
			}
			if ( $wgDebugDBTransactions ) {
				wfDebug( sprintf( "Connection %s will be used for SqlBagOStuff\n", $db ) );
			}
			$this->conns[$serverIndex] = $db;
		}

		return $this->conns[$serverIndex];
	}
예제 #5
0
 /**
  * Get a connection to the specified database
  *
  * @param int $serverIndex
  * @return IDatabase
  * @throws MWException
  */
 protected function getDB($serverIndex)
 {
     if (!isset($this->conns[$serverIndex])) {
         if ($serverIndex >= $this->numServers) {
             throw new MWException(__METHOD__ . ": Invalid server index \"{$serverIndex}\"");
         }
         # Don't keep timing out trying to connect for each call if the DB is down
         if (isset($this->connFailureErrors[$serverIndex]) && time() - $this->connFailureTimes[$serverIndex] < 60) {
             throw $this->connFailureErrors[$serverIndex];
         }
         # If server connection info was given, use that
         if ($this->serverInfos) {
             $info = $this->serverInfos[$serverIndex];
             $type = isset($info['type']) ? $info['type'] : 'mysql';
             $host = isset($info['host']) ? $info['host'] : '[unknown]';
             $this->logger->debug(__CLASS__ . ": connecting to {$host}");
             // Use a blank trx profiler to ignore expections as this is a cache
             $info['trxProfiler'] = new TransactionProfiler();
             $db = DatabaseBase::factory($type, $info);
             $db->clearFlag(DBO_TRX);
         } else {
             /*
              * We must keep a separate connection to MySQL in order to avoid deadlocks
              * However, SQLite has an opposite behavior. And PostgreSQL needs to know
              * if we are in transaction or no
              */
             $index = $this->slaveOnly ? DB_SLAVE : DB_MASTER;
             if (wfGetDB($index)->getType() == 'mysql') {
                 $this->lb = wfGetLBFactory()->newMainLB();
                 $db = $this->lb->getConnection($index);
                 $db->clearFlag(DBO_TRX);
                 // auto-commit mode
             } else {
                 $db = wfGetDB($index);
             }
         }
         $this->logger->debug(sprintf("Connection %s will be used for SqlBagOStuff", $db));
         $this->conns[$serverIndex] = $db;
     }
     return $this->conns[$serverIndex];
 }
예제 #6
0
 /**
  * @return DatabaseBase
  */
 protected function getDB()
 {
     global $wgDebugDBTransactions;
     # Don't keep timing out trying to connect for each call if the DB is down
     if ($this->connFailureError && time() - $this->connFailureTime < 60) {
         throw $this->connFailureError;
     }
     if (!isset($this->db)) {
         # If server connection info was given, use that
         if ($this->serverInfo) {
             if ($wgDebugDBTransactions) {
                 wfDebug(sprintf("Using provided serverInfo for SqlBagOStuff\n"));
             }
             $this->lb = new LoadBalancer(array('servers' => array($this->serverInfo)));
             $this->db = $this->lb->getConnection(DB_MASTER);
             $this->db->clearFlag(DBO_TRX);
         } else {
             /*
              * We must keep a separate connection to MySQL in order to avoid deadlocks
              * However, SQLite has an opposite behaviour. And PostgreSQL needs to know
              * if we are in transaction or no
              */
             if (wfGetDB(DB_MASTER)->getType() == 'mysql') {
                 $this->lb = wfGetLBFactory()->newMainLB();
                 $this->db = $this->lb->getConnection(DB_MASTER);
                 $this->db->clearFlag(DBO_TRX);
                 // auto-commit mode
             } else {
                 $this->db = wfGetDB(DB_MASTER);
             }
         }
         if ($wgDebugDBTransactions) {
             wfDebug(sprintf("Connection %s will be used for SqlBagOStuff\n", $this->db));
         }
     }
     return $this->db;
 }
예제 #7
0
 /**
  * @param int $slaveOrMaster DB_MASTER or DB_SLAVE
  *
  * @return DatabaseBase
  * @throws MWException
  */
 private function getConnection($slaveOrMaster)
 {
     return $this->loadBalancer->getConnection($slaveOrMaster, ['watchlist']);
 }