summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Starling <tstarling@wikimedia.org>2022-01-13 12:49:29 +1100
committerTim Starling <tstarling@wikimedia.org>2022-01-13 02:08:40 +0000
commite0160e2352c5c0336ad08c38e8fb7fd744a36d6e (patch)
tree26b8246f9742d0919f5cde0a122816d85f700ab0
parent5b4a658ccd69d652577e346cee186f8cba99158d (diff)
maintenance: Add --batch-size to sql.php
Wait for replication after each batch of queries in sql.php, instead of only at the end. Bug: T299095 Change-Id: Ie077e9cec66cb35e2339982638151aa8edd06dc4
-rw-r--r--maintenance/sql.php6
1 files changed, 6 insertions, 0 deletions
diff --git a/maintenance/sql.php b/maintenance/sql.php
index 6d1fcfa3dfd8..4ee9792eb3e1 100644
--- a/maintenance/sql.php
+++ b/maintenance/sql.php
@@ -49,6 +49,7 @@ class MwSql extends Maintenance {
'The database wiki ID to use if not the current one', false, true );
$this->addOption( 'replicadb',
'Replica DB server to use instead of the primary DB (can be "any")', false, true );
+ $this->setBatchSize( 100 );
}
public function execute() {
@@ -132,6 +133,7 @@ class MwSql extends Maintenance {
$prompt = $newPrompt;
$doDie = !Maintenance::posix_isatty( 0 );
$res = 1;
+ $batchCount = 0;
while ( ( $line = Maintenance::readconsole( $prompt ) ) !== false ) {
if ( !$line ) {
# User simply pressed return key
@@ -154,6 +156,10 @@ class MwSql extends Maintenance {
}
// @phan-suppress-next-line SecurityCheck-SQLInjection
$res = $this->sqlDoQuery( $db, $wholeLine, $doDie );
+ if ( $this->getBatchSize() && ++$batchCount >= $this->getBatchSize() ) {
+ $batchCount = 0;
+ $lbFactory->waitForReplication();
+ }
$prompt = $newPrompt;
$wholeLine = '';
}