/** * Construct a database error * @param $db DatabaseBase object which threw the error * @param $error String A simple error message to be used for debugging */ function __construct(DatabaseBase &$db, $error) { global $wgDBcluster; $this->db = $db; parent::__construct($error); $isMaster = !is_null($db->getLBInfo('master')); // Wikia change - @author macbre - MAIN-2304 \Wikia\Logger\WikiaLogger::instance()->error('DBError', ['name' => $db->getDBname(), 'cluster' => $wgDBcluster, 'server' => $db->getServer(), 'server_role' => $isMaster ? 'master' : 'slave', 'errno' => $db->lastErrno(), 'err' => $db->lastError(), 'exception' => $this]); }
/** * Mark a foreign connection as being available for reuse under a different * DB name or prefix. This mechanism is reference-counted, and must be called * the same number of times as getConnection() to work. * * @param DatabaseBase $conn * @throws MWException */ public function reuseConnection($conn) { $serverIndex = $conn->getLBInfo('serverIndex'); $refCount = $conn->getLBInfo('foreignPoolRefCount'); if ($serverIndex === null || $refCount === null) { wfDebug(__METHOD__ . ": this connection was not opened as a foreign connection\n"); /** * This can happen in code like: * foreach ( $dbs as $db ) { * $conn = $lb->getConnection( DB_SLAVE, array(), $db ); * ... * $lb->reuseConnection( $conn ); * } * When a connection to the local DB is opened in this way, reuseConnection() * should be ignored */ return; } $dbName = $conn->getDBname(); $prefix = $conn->tablePrefix(); if (strval($prefix) !== '') { $wiki = "{$dbName}-{$prefix}"; } else { $wiki = $dbName; } if ($this->mConns['foreignUsed'][$serverIndex][$wiki] !== $conn) { throw new MWException(__METHOD__ . ": connection not found, has " . "the connection been freed already?"); } $conn->setLBInfo('foreignPoolRefCount', --$refCount); if ($refCount <= 0) { $this->mConns['foreignFree'][$serverIndex][$wiki] = $conn; unset($this->mConns['foreignUsed'][$serverIndex][$wiki]); wfDebug(__METHOD__ . ": freed connection {$serverIndex}/{$wiki}\n"); } else { wfDebug(__METHOD__ . ": reference count for {$serverIndex}/{$wiki} reduced to {$refCount}\n"); } }
/** * Get the 'blobs' table name for this database * * @param DatabaseBase $db * @return string Table name ('blobs' by default) */ function getTable($db) { $table = $db->getLBInfo('blobs table'); if (is_null($table)) { $table = 'blobs'; } return $table; }