Merge "rdbms: add "maxReadRows" limit to TransactionProfiler"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 13 Aug 2018 23:26:37 +0000 (23:26 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 13 Aug 2018 23:26:37 +0000 (23:26 +0000)
autoload.php
includes/externalstore/ExternalStoreDB.php
includes/libs/rdbms/loadbalancer/ILoadBalancer.php
maintenance/benchmarks/Benchmarker.php
maintenance/benchmarks/australia-untidy.html.gz [deleted file]
maintenance/benchmarks/benchmarkCSSMin.php
maintenance/benchmarks/benchmarkJavaScriptMinifier.php [new file with mode: 0644]
maintenance/benchmarks/benchmarkTidy.php
maintenance/benchmarks/jsmin/jquery-3.2.1.js.gz [new file with mode: 0644]
maintenance/benchmarks/tidy/australia-untidy.html.gz [new file with mode: 0644]

index d3ab3af..1c1eeef 100644 (file)
@@ -195,6 +195,7 @@ $wgAutoloadLocalClasses = [
        'BenchmarkDeleteTruncate' => __DIR__ . '/maintenance/benchmarks/bench_delete_truncate.php',
        'BenchmarkHooks' => __DIR__ . '/maintenance/benchmarks/benchmarkHooks.php',
        'BenchmarkJSMinPlus' => __DIR__ . '/maintenance/benchmarks/benchmarkJSMinPlus.php',
+       'BenchmarkJavaScriptMinifier' => __DIR__ . '/maintenance/benchmarks/benchmarkJavaScriptMinifier.php',
        'BenchmarkLruHash' => __DIR__ . '/maintenance/benchmarks/benchmarkLruHash.php',
        'BenchmarkParse' => __DIR__ . '/maintenance/benchmarks/benchmarkParse.php',
        'BenchmarkPurge' => __DIR__ . '/maintenance/benchmarks/benchmarkPurge.php',
index 422e1fb..5a77e89 100644 (file)
  */
 
 use MediaWiki\MediaWikiServices;
-use Wikimedia\Rdbms\LoadBalancer;
+use Wikimedia\Rdbms\ILoadBalancer;
 use Wikimedia\Rdbms\IDatabase;
 use Wikimedia\Rdbms\DBConnRef;
 use Wikimedia\Rdbms\MaintainableDBConnRef;
+use Wikimedia\Rdbms\DatabaseDomain;
 
 /**
  * DB accessible external objects.
@@ -112,7 +113,7 @@ class ExternalStoreDB extends ExternalStoreMedium {
         * Get a LoadBalancer for the specified cluster
         *
         * @param string $cluster Cluster name
-        * @return LoadBalancer
+        * @return ILoadBalancer
         */
        private function getLoadBalancer( $cluster ) {
                $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
@@ -128,8 +129,8 @@ class ExternalStoreDB extends ExternalStoreMedium {
        public function getSlave( $cluster ) {
                global $wgDefaultExternalStore;
 
-               $wiki = $this->params['wiki'] ?? false;
                $lb = $this->getLoadBalancer( $cluster );
+               $domainId = $this->getDomainId( $lb->getServerInfo( $lb->getWriterIndex() ) );
 
                if ( !in_array( "DB://" . $cluster, (array)$wgDefaultExternalStore ) ) {
                        wfDebug( "read only external store\n" );
@@ -138,7 +139,7 @@ class ExternalStoreDB extends ExternalStoreMedium {
                        wfDebug( "writable external store\n" );
                }
 
-               $db = $lb->getConnectionRef( DB_REPLICA, [], $wiki );
+               $db = $lb->getConnectionRef( DB_REPLICA, [], $domainId );
                $db->clearFlag( DBO_TRX ); // sanity
 
                return $db;
@@ -151,15 +152,38 @@ class ExternalStoreDB extends ExternalStoreMedium {
         * @return MaintainableDBConnRef
         */
        public function getMaster( $cluster ) {
-               $wiki = $this->params['wiki'] ?? false;
                $lb = $this->getLoadBalancer( $cluster );
+               $domainId = $this->getDomainId( $lb->getServerInfo( $lb->getWriterIndex() ) );
 
-               $db = $lb->getMaintenanceConnectionRef( DB_MASTER, [], $wiki );
+               $db = $lb->getMaintenanceConnectionRef( DB_MASTER, [], $domainId );
                $db->clearFlag( DBO_TRX ); // sanity
 
                return $db;
        }
 
+       /**
+        * @param array $server Master DB server configuration array for LoadBalancer
+        * @return string|bool Database domain ID or false
+        */
+       private function getDomainId( array $server ) {
+               if ( isset( $server['dbname'] ) ) {
+                       // T200471: for b/c, treat any "dbname" field as forcing which database to use.
+                       // MediaWiki/LoadBalancer previously did not enforce any concept of a local DB
+                       // domain, but rather assumed that the LB server configuration matched $wgDBname.
+                       // This check is useful when the external storage DB for this cluster does not use
+                       // the same name as the corresponding "main" DB(s) for wikis.
+                       $domain = new DatabaseDomain(
+                               $server['dbname'],
+                               $server['schema'] ?? null,
+                               $server['tablePrefix'] ?? ''
+                       );
+
+                       return $domain->getId();
+               }
+
+               return $this->params['wiki'] ?? false; // local domain unless explictly given
+       }
+
        /**
         * Get the 'blobs' table name for this database
         *
index 83ebd51..9f7d050 100644 (file)
@@ -356,6 +356,7 @@ interface ILoadBalancer {
         * Return the server info structure for a given index, or false if the index is invalid.
         * @param int $i
         * @return array|bool
+        * @since 1.31
         */
        public function getServerInfo( $i );
 
index e1eef07..04aee80 100644 (file)
@@ -162,4 +162,18 @@ abstract class Benchmarker extends Maintenance {
                        $this->lang->formatSize( memory_get_peak_usage( true ) )
                ) );
        }
+
+       /**
+        * @since 1.32
+        * @param string $file Path to file (maybe compressed with gzip)
+        * @return string Contents of file
+        */
+       protected function loadFile( $file ) {
+               $content = file_get_contents( $file );
+               // Detect GZIP compression header
+               if ( substr( $content, 0, 2 ) === "\037\213" ) {
+                       $content = gzdecode( $content );
+               }
+               return $content;
+       }
 }
diff --git a/maintenance/benchmarks/australia-untidy.html.gz b/maintenance/benchmarks/australia-untidy.html.gz
deleted file mode 100644 (file)
index 148481d..0000000
Binary files a/maintenance/benchmarks/australia-untidy.html.gz and /dev/null differ
index a7d998d..8e2acb2 100644 (file)
@@ -61,15 +61,6 @@ class BenchmarkCSSMin extends Benchmarker {
                        ],
                ] );
        }
-
-       private function loadFile( $file ) {
-               $css = file_get_contents( $file );
-               // Detect GZIP compression header
-               if ( substr( $css, 0, 2 ) === "\037\213" ) {
-                       $css = gzdecode( $css );
-               }
-               return $css;
-       }
 }
 
 $maintClass = BenchmarkCSSMin::class;
diff --git a/maintenance/benchmarks/benchmarkJavaScriptMinifier.php b/maintenance/benchmarks/benchmarkJavaScriptMinifier.php
new file mode 100644 (file)
index 0000000..bb75660
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Benchmark
+ * @author Timo Tijhof
+ */
+
+require_once __DIR__ . '/Benchmarker.php';
+
+/**
+ * Maintenance script that benchmarks JavaScriptMinifier.
+ *
+ * @ingroup Benchmark
+ */
+class BenchmarkJavaScriptMinifier extends Benchmarker {
+       protected $defaultCount = 10;
+
+       public function __construct() {
+               parent::__construct();
+               $this->addDescription( 'Benchmark for JavaScriptMinifier.' );
+               $this->addOption( 'file', 'Path to JavaScript file (may be gzipped)', false, true );
+       }
+
+       public function execute() {
+               $file = $this->getOption( 'file', __DIR__ . '/jsmin/jquery-3.2.1.js.gz' );
+               $filename = basename( $file );
+               $content = $this->loadFile( $file );
+               if ( $content === false ) {
+                       $this->fatalError( 'Unable to open input file' );
+               }
+
+               $this->bench( [
+                       "minify ($filename)" => [
+                               'function' => [ JavaScriptMinifier::class, 'minify' ],
+                               'args' => [ $content ],
+                       ],
+               ] );
+       }
+}
+
+$maintClass = BenchmarkJavaScriptMinifier::class;
+require_once RUN_MAINTENANCE_IF_MAIN;
index 5a432fb..e9a30f9 100644 (file)
@@ -2,12 +2,12 @@
 
 use MediaWiki\MediaWikiServices;
 
-require __DIR__ . '/../Maintenance.php';
+require __DIR__ . '/Benchmarker.php';
 
-class BenchmarkTidy extends Maintenance {
+class BenchmarkTidy extends Benchmarker {
        public function __construct() {
                parent::__construct();
-               $this->addOption( 'file', 'A filename which contains the input text', true, true );
+               $this->addOption( 'file', 'Path to file containing the input text', false, true );
                $this->addOption( 'driver', 'The Tidy driver name, or false to use the configured instance',
                        false,  true );
                $this->addOption( 'tidy-config', 'JSON encoded value for the tidy configuration array',
@@ -15,7 +15,8 @@ class BenchmarkTidy extends Maintenance {
        }
 
        public function execute() {
-               $html = file_get_contents( $this->getOption( 'file' ) );
+               $file = $this->getOption( 'file', __DIR__ . '/tidy/australia-untidy.html.gz' );
+               $html = $this->loadFile( $file );
                if ( $html === false ) {
                        $this->fatalError( "Unable to open input file" );
                }
diff --git a/maintenance/benchmarks/jsmin/jquery-3.2.1.js.gz b/maintenance/benchmarks/jsmin/jquery-3.2.1.js.gz
new file mode 100644 (file)
index 0000000..2e8e9b2
Binary files /dev/null and b/maintenance/benchmarks/jsmin/jquery-3.2.1.js.gz differ
diff --git a/maintenance/benchmarks/tidy/australia-untidy.html.gz b/maintenance/benchmarks/tidy/australia-untidy.html.gz
new file mode 100644 (file)
index 0000000..148481d
Binary files /dev/null and b/maintenance/benchmarks/tidy/australia-untidy.html.gz differ