示例#1
0
	/**
	 * Wait for the slave to catch up to a given master position.
	 * @TODO: return values for this and base class are rubbish
	 *
	 * @param $pos DBMasterPos object
	 * @param $timeout Integer: the maximum number of seconds to wait for synchronisation
	 * @return bool|string
	 */
	function masterPosWait( DBMasterPos $pos, $timeout ) {
		if ( $this->lastKnownSlavePos && $this->lastKnownSlavePos->hasReached( $pos ) ) {
			return '0'; // http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html
		}

		wfProfileIn( __METHOD__ );
		# Commit any open transactions
		$this->commit( __METHOD__, 'flush' );

		if ( !is_null( $this->mFakeSlaveLag ) ) {
			$status = parent::masterPosWait( $pos, $timeout );
			wfProfileOut( __METHOD__ );
			return $status;
		}

		# Call doQuery() directly, to avoid opening a transaction if DBO_TRX is set
		$encFile = $this->addQuotes( $pos->file );
		$encPos = intval( $pos->pos );
		$sql = "SELECT MASTER_POS_WAIT($encFile, $encPos, $timeout)";
		$res = $this->doQuery( $sql );

		$status = false;
		if ( $res && $row = $this->fetchRow( $res ) ) {
			$status = $row[0]; // can be NULL, -1, or 0+ per the MySQL manual
			if ( ctype_digit( $status ) ) { // success
				$this->lastKnownSlavePos = $pos;
			}
		}

		wfProfileOut( __METHOD__ );
		return $status;
	}
示例#2
0
 /**
  * Wait for the slave to catch up to a given master position.
  *
  * @param $pos DBMasterPos object
  * @param $timeout Integer: the maximum number of seconds to wait for synchronisation
  */
 function masterPosWait(DBMasterPos $pos, $timeout)
 {
     $fname = 'DatabaseBase::masterPosWait';
     wfProfileIn($fname);
     # Commit any open transactions
     if ($this->mTrxLevel) {
         $this->commit();
     }
     if (!is_null($this->mFakeSlaveLag)) {
         $status = parent::masterPosWait($pos, $timeout);
         wfProfileOut($fname);
         return $status;
     }
     # Call doQuery() directly, to avoid opening a transaction if DBO_TRX is set
     $encFile = $this->addQuotes($pos->file);
     $encPos = intval($pos->pos);
     $sql = "SELECT MASTER_POS_WAIT({$encFile}, {$encPos}, {$timeout})";
     $res = $this->doQuery($sql);
     if ($res && ($row = $this->fetchRow($res))) {
         wfProfileOut($fname);
         return $row[0];
     } else {
         wfProfileOut($fname);
         return false;
     }
 }