Change DatabaseBase => IDatabase in /db where possible
[lhc/web/wiklou.git] / includes / db / DatabaseMysqlBase.php
index d1ebe62..af80d24 100644 (file)
  */
 abstract class DatabaseMysqlBase extends Database {
        /** @var MysqlMasterPos */
-       protected $lastKnownSlavePos;
-       /** @var string Method to detect slave lag */
+       protected $lastKnownReplicaPos;
+       /** @var string Method to detect replica DB lag */
        protected $lagDetectionMethod;
-       /** @var array Method to detect slave lag */
+       /** @var array Method to detect replica DB lag */
        protected $lagDetectionOptions = [];
        /** @var bool bool Whether to use GTID methods */
        protected $useGTIDs = false;
-
+       /** @var string|null */
+       protected $sslKeyPath;
+       /** @var string|null */
+       protected $sslCertPath;
+       /** @var string|null */
+       protected $sslCAPath;
+       /** @var string[]|null */
+       protected $sslCiphers;
        /** @var string|null */
        private $serverVersion = null;
 
@@ -53,6 +60,10 @@ abstract class DatabaseMysqlBase extends Database {
         *       ID of this server's master will be used. Set the "conds" field to
         *       override the query conditions, e.g. ['shard' => 's1'].
         *   - useGTIDs : use GTID methods like MASTER_GTID_WAIT() when possible.
+        *   - sslKeyPath : path to key file [default: null]
+        *   - sslCertPath : path to certificate file [default: null]
+        *   - sslCAPath : parth to certificate authority PEM files [default: null]
+        *   - sslCiphers : array list of allowable ciphers [default: null]
         * @param array $params
         */
        function __construct( array $params ) {
@@ -65,6 +76,12 @@ abstract class DatabaseMysqlBase extends Database {
                        ? $params['lagDetectionOptions']
                        : [];
                $this->useGTIDs = !empty( $params['useGTIDs' ] );
+               foreach ( [ 'KeyPath', 'CertPath', 'CAPath', 'Ciphers' ] as $name ) {
+                       $var = "ssl{$name}";
+                       if ( isset( $params[$var] ) ) {
+                               $this->$var = $params[$var];
+                       }
+               }
        }
 
        /**
@@ -599,15 +616,6 @@ abstract class DatabaseMysqlBase extends Database {
                return strlen( $name ) && $name[0] == '`' && substr( $name, -1, 1 ) == '`';
        }
 
-       function reconnect() {
-               $this->closeConnection();
-               $this->mOpened = false;
-               $this->mConn = false;
-               $this->open( $this->mServer, $this->mUser, $this->mPassword, $this->mDBname );
-
-               return true;
-       }
-
        function getLag() {
                if ( $this->getLagDetectionMethod() === 'pt-heartbeat' ) {
                        return $this->getLagFromPtHeartbeat();
@@ -687,7 +695,7 @@ abstract class DatabaseMysqlBase extends Database {
                $key = $cache->makeGlobalKey(
                        'mysql',
                        'master-info',
-                       // Using one key for all cluster slaves is preferable
+                       // Using one key for all cluster replica DBs is preferable
                        $this->getLBInfo( 'clusterMasterHost' ) ?: $this->getServer()
                );
 
@@ -763,7 +771,7 @@ abstract class DatabaseMysqlBase extends Database {
 
                if ( $this->getLBInfo( 'is static' ) === true ) {
                        return 0; // this is a copy of a read-only dataset with no master DB
-               } elseif ( $this->lastKnownSlavePos && $this->lastKnownSlavePos->hasReached( $pos ) ) {
+               } elseif ( $this->lastKnownReplicaPos && $this->lastKnownReplicaPos->hasReached( $pos ) ) {
                        return 0; // already reached this point for sure
                }
 
@@ -789,16 +797,16 @@ abstract class DatabaseMysqlBase extends Database {
                if ( $status === null ) {
                        // T126436: jobs programmed to wait on master positions might be referencing binlogs
                        // with an old master hostname. Such calls make MASTER_POS_WAIT() return null. Try
-                       // to detect this and treat the slave as having reached the position; a proper master
+                       // to detect this and treat the replica DB as having reached the position; a proper master
                        // switchover already requires that the new master be caught up before the switch.
-                       $slavePos = $this->getSlavePos();
-                       if ( $slavePos && !$slavePos->channelsMatch( $pos ) ) {
-                               $this->lastKnownSlavePos = $slavePos;
+                       $replicationPos = $this->getSlavePos();
+                       if ( $replicationPos && !$replicationPos->channelsMatch( $pos ) ) {
+                               $this->lastKnownReplicaPos = $replicationPos;
                                $status = 0;
                        }
                } elseif ( $status >= 0 ) {
                        // Remember that this position was reached to save queries next time
-                       $this->lastKnownSlavePos = $pos;
+                       $this->lastKnownReplicaPos = $pos;
                }
 
                return $status;
@@ -872,6 +880,14 @@ abstract class DatabaseMysqlBase extends Database {
                return "FORCE INDEX (" . $this->indexName( $index ) . ")";
        }
 
+       /**
+        * @param string $index
+        * @return string
+        */
+       function ignoreIndexClause( $index ) {
+               return "IGNORE INDEX (" . $this->indexName( $index ) . ")";
+       }
+
        /**
         * @return string
         */
@@ -1082,7 +1098,7 @@ abstract class DatabaseMysqlBase extends Database {
         */
        function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = __METHOD__ ) {
                if ( !$conds ) {
-                       throw new DBUnexpectedError( $this, 'DatabaseBase::deleteJoin() called with empty $conds' );
+                       throw new DBUnexpectedError( $this, __METHOD__ . ' called with empty $conds' );
                }
 
                $delTable = $this->tableName( $delTable );