/** * @param string $domain Domain ID, or false for the current domain * @param IDatabase|null DB master connectionl used to avoid loops [optional] * @return bool */ private function masterRunningReadOnly($domain, IDatabase $conn = null) { $cache = $this->wanCache; $masterServer = $this->getServerName($this->getWriterIndex()); return (bool) $cache->getWithSetCallback($cache->makeGlobalKey(__CLASS__, 'server-read-only', $masterServer), self::TTL_CACHE_READONLY, function () use($domain, $conn) { $old = $this->trxProfiler->setSilenced(true); try { $dbw = $conn ?: $this->getConnection(self::DB_MASTER, [], $domain); $readOnly = (int) $dbw->serverIsReadOnly(); if (!$conn) { $this->reuseConnection($dbw); } } catch (DBError $e) { $readOnly = 0; } $this->trxProfiler->setSilenced($old); return $readOnly; }, ['pcTTL' => $cache::TTL_PROC_LONG, 'busyValue' => 0]); }
public final function rollback($fname = __METHOD__, $flush = '') { if ($flush === self::FLUSHING_INTERNAL || $flush === self::FLUSHING_ALL_PEERS) { if (!$this->mTrxLevel) { return; // nothing to do } } else { if (!$this->mTrxLevel) { $this->queryLogger->error("{$fname}: No transaction to rollback, something got out of sync."); return; // nothing to do } elseif ($this->getFlag(self::DBO_TRX)) { throw new DBUnexpectedError($this, "{$fname}: Expected mass rollback of all peer databases (DBO_TRX set)."); } } // Avoid fatals if close() was called $this->assertOpen(); $this->doRollback($fname); $this->mTrxAtomicLevels = []; if ($this->mTrxDoneWrites) { $this->trxProfiler->transactionWritingOut($this->mServer, $this->mDBname, $this->mTrxShortId); } $this->mTrxIdleCallbacks = []; // clear $this->mTrxPreCommitCallbacks = []; // clear $this->runOnTransactionIdleCallbacks(self::TRIGGER_ROLLBACK); $this->runTransactionListenerCallbacks(self::TRIGGER_ROLLBACK); }
/** * Mark a DB as no longer in a transaction * * This will check if locks are possibly held for longer than * needed and log any affected transactions to a special DB log. * Note that there can be multiple connections to a single DB. * * @param string $server DB server * @param string $db DB name * @param string $id Resource ID string of connection */ public function transactionWritingOut($server, $db, $id = '') { $this->trxProfiler->transactionWritingOut($server, $db, $id); }