Ejemplo n.º 1
0
 /**
  * @param array $params An associative array with one member:
  *   - connection: An IDatabase connection object
  */
 public function __construct(array $params)
 {
     if (!isset($params['connection'])) {
         throw new InvalidArgumentException("Missing 'connection' argument.");
     }
     $this->db = $params['connection'];
     parent::__construct(['servers' => [['type' => $this->db->getType(), 'host' => $this->db->getServer(), 'dbname' => $this->db->getDBname(), 'load' => 1]], 'trxProfiler' => isset($params['trxProfiler']) ? $params['trxProfiler'] : null, 'srvCache' => isset($params['srvCache']) ? $params['srvCache'] : null, 'wanCache' => isset($params['wanCache']) ? $params['wanCache'] : null]);
     if (isset($params['readOnlyReason'])) {
         $this->db->setLBInfo('readOnlyReason', $params['readOnlyReason']);
     }
 }
Ejemplo n.º 2
0
 /**
  * Wait for a slave DB to reach a specified master position
  *
  * This will connect to the master to get an accurate position if $pos is not given
  *
  * @param IDatabase $conn Slave DB
  * @param DBMasterPos|bool $pos Master position; default: current position
  * @param integer $timeout Timeout in seconds
  * @return bool Success
  * @since 1.27
  */
 public function safeWaitForMasterPos(IDatabase $conn, $pos = false, $timeout = 10)
 {
     if ($this->getServerCount() == 1 || !$conn->getLBInfo('slave')) {
         return true;
         // server is not a slave DB
     }
     $pos = $pos ?: $this->getConnection(DB_MASTER)->getMasterPos();
     if (!$pos) {
         return false;
         // something is misconfigured
     }
     $result = $conn->masterPosWait($pos, $timeout);
     if ($result == -1 || is_null($result)) {
         $msg = __METHOD__ . ": Timed out waiting on {$conn->getServer()} pos {$pos}";
         wfDebugLog('replication', "{$msg}\n");
         wfDebugLog('DBPerformance', "{$msg}:\n" . wfBacktrace(true));
         $ok = false;
     } else {
         wfDebugLog('replication', __METHOD__ . ": Done\n");
         $ok = true;
     }
     return $ok;
 }
Ejemplo n.º 3
0
 public function safeWaitForMasterPos(IDatabase $conn, $pos = false, $timeout = 10)
 {
     if ($this->getServerCount() <= 1 || !$conn->getLBInfo('replica')) {
         return true;
         // server is not a replica DB
     }
     if (!$pos) {
         // Get the current master position, opening a connection if needed
         $masterConn = $this->getAnyOpenConnection($this->getWriterIndex());
         if ($masterConn) {
             $pos = $masterConn->getMasterPos();
         } else {
             $masterConn = $this->openConnection($this->getWriterIndex(), self::DOMAIN_ANY);
             $pos = $masterConn->getMasterPos();
             $this->closeConnection($masterConn);
         }
     }
     if ($pos instanceof DBMasterPos) {
         $result = $conn->masterPosWait($pos, $timeout);
         if ($result == -1 || is_null($result)) {
             $msg = __METHOD__ . ": Timed out waiting on {$conn->getServer()} pos {$pos}";
             $this->replLogger->warning("{$msg}");
             $ok = false;
         } else {
             $this->replLogger->info(__METHOD__ . ": Done");
             $ok = true;
         }
     } else {
         $ok = false;
         // something is misconfigured
         $this->replLogger->error("Could not get master pos for {$conn->getServer()}.");
     }
     return $ok;
 }