Log huge write queries in CLI scripts
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 8 Apr 2015 01:11:29 +0000 (18:11 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 8 Apr 2015 07:06:03 +0000 (07:06 +0000)
* This is already done for web scripts, but with lower limits

Bug: T95382
Change-Id: I0fe14bcdaebc3568b0cb7af8084b7bfefeb82826

maintenance/Maintenance.php

index a0ffcb2..a8dbd5f 100644 (file)
@@ -38,6 +38,8 @@ define( 'DO_MAINTENANCE', RUN_MAINTENANCE_IF_MAIN ); // original name, harmless
 
 $maintClass = false;
 
+use MediaWiki\Logger\LoggerFactory;
+
 /**
  * Abstract maintenance class for quickly writing and churning out
  * maintenance scripts with minimal effort. All that _must_ be defined
@@ -612,6 +614,11 @@ abstract class Maintenance {
                        $profiler->setTemplated( true );
                        Profiler::replaceStubInstance( $profiler );
                }
+
+               $trxProfiler = Profiler::instance()->getTransactionProfiler();
+               $trxProfiler->setLogger( LoggerFactory::getInstance( 'DBPerformance' ) );
+               # Catch huge single updates that lead to slave lag
+               $trxProfiler->setExpectation( 'maxAffected', 1000, __METHOD__ );
        }
 
        /**