Anomie has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/393928 )

Change subject: Migrate ar_text to modern storage
......................................................................

Migrate ar_text to modern storage

This really should have been done a very long time ago.

This adds a maintenance script to migrate rows with ar_text_id null to
modern storage, either the text table or ExternalStore.

Bug: T36925
Change-Id: I5608c6b6d3ecad516b785e13d668427c1b762e41
---
M autoload.php
M includes/installer/DatabaseUpdater.php
M includes/installer/MssqlUpdater.php
M includes/installer/MysqlUpdater.php
M includes/installer/OracleUpdater.php
M includes/installer/PostgresUpdater.php
M includes/installer/SqliteUpdater.php
A maintenance/migrateArchiveText.php
8 files changed, 158 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/28/393928/1

diff --git a/autoload.php b/autoload.php
index 51daced..7cf20a0 100644
--- a/autoload.php
+++ b/autoload.php
@@ -1001,6 +1001,7 @@
        'MessageContent' => __DIR__ . '/includes/content/MessageContent.php',
        'MessageLocalizer' => __DIR__ . '/languages/MessageLocalizer.php',
        'MessageSpecifier' => __DIR__ . '/includes/libs/MessageSpecifier.php',
+       'MigrateArchiveText' => __DIR__ . '/maintenance/migrateArchiveText.php',
        'MigrateComments' => __DIR__ . '/maintenance/migrateComments.php',
        'MigrateFileRepoLayout' => __DIR__ . 
'/maintenance/migrateFileRepoLayout.php',
        'MigrateUserGroup' => __DIR__ . '/maintenance/migrateUserGroup.php',
diff --git a/includes/installer/DatabaseUpdater.php 
b/includes/installer/DatabaseUpdater.php
index 54ff712..6639fc8 100644
--- a/includes/installer/DatabaseUpdater.php
+++ b/includes/installer/DatabaseUpdater.php
@@ -1230,4 +1230,15 @@
                }
        }
 
+       /**
+        * Migrate ar_text to modern storage
+        * @since 1.31
+        */
+       protected function migrateArchiveText() {
+               $this->output( "Migrating archive ar_text to modern storage.\n" 
);
+               $task = $this->maintenance->runChild( 'MigrateArchiveText', 
'migrateArchiveText.php' );
+               $task->execute();
+               $this->output( "done.\n" );
+       }
+
 }
diff --git a/includes/installer/MssqlUpdater.php 
b/includes/installer/MssqlUpdater.php
index 411d2c8..cb5e59e 100644
--- a/includes/installer/MssqlUpdater.php
+++ b/includes/installer/MssqlUpdater.php
@@ -105,6 +105,9 @@
                        // 1.30
                        [ 'modifyField', 'image', 'img_media_type', 
'patch-add-3d.sql' ],
                        [ 'addIndex', 'site_stats', 'PRIMARY', 
'patch-site_stats-pk.sql' ],
+
+                       // 1.31
+                       [ 'migrateArchiveText' ],
                ];
        }
 
diff --git a/includes/installer/MysqlUpdater.php 
b/includes/installer/MysqlUpdater.php
index 466ad0f..572a73b 100644
--- a/includes/installer/MysqlUpdater.php
+++ b/includes/installer/MysqlUpdater.php
@@ -329,6 +329,9 @@
                        [ 'renameIndex', 'l10n_cache', 'lc_lang_key', 
'PRIMARY', false,
                                'patch-l10n_cache-primary-key.sql' ],
                        [ 'doUnsignedSyncronisation' ],
+
+                       // 1.31
+                       [ 'migrateArchiveText' ],
                ];
        }
 
diff --git a/includes/installer/OracleUpdater.php 
b/includes/installer/OracleUpdater.php
index 040b54a..73f37af 100644
--- a/includes/installer/OracleUpdater.php
+++ b/includes/installer/OracleUpdater.php
@@ -127,6 +127,9 @@
                        [ 'doAutoIncrementTriggers' ],
                        [ 'addIndex', 'site_stats', 'PRIMARY', 
'patch-site_stats-pk.sql' ],
 
+                       // 1.31
+                       [ 'migrateArchiveText' ],
+
                        // KEEP THIS AT THE BOTTOM!!
                        [ 'doRebuildDuplicateFunction' ],
 
diff --git a/includes/installer/PostgresUpdater.php 
b/includes/installer/PostgresUpdater.php
index 91f569f..77d25d4 100644
--- a/includes/installer/PostgresUpdater.php
+++ b/includes/installer/PostgresUpdater.php
@@ -482,6 +482,9 @@
                        [ 'addPgField', 'protected_titles', 'pt_reason_id', 
'INTEGER NOT NULL DEFAULT 0' ],
                        [ 'addTable', 'comment', 'patch-comment-table.sql' ],
                        [ 'addIndex', 'site_stats', 'site_stats_pkey', 
'patch-site_stats-pk.sql' ],
+
+                       // 1.31
+                       [ 'migrateArchiveText' ],
                ];
        }
 
diff --git a/includes/installer/SqliteUpdater.php 
b/includes/installer/SqliteUpdater.php
index 9f71001..48cb991 100644
--- a/includes/installer/SqliteUpdater.php
+++ b/includes/installer/SqliteUpdater.php
@@ -193,6 +193,9 @@
                        [ 'migrateComments' ],
                        [ 'renameIndex', 'l10n_cache', 'lc_lang_key', 
'PRIMARY', false,
                                'patch-l10n_cache-primary-key.sql' ],
+
+                       // 1.31
+                       [ 'migrateArchiveText' ],
                ];
        }
 
diff --git a/maintenance/migrateArchiveText.php 
b/maintenance/migrateArchiveText.php
new file mode 100644
index 0000000..96f5dbf
--- /dev/null
+++ b/maintenance/migrateArchiveText.php
@@ -0,0 +1,131 @@
+<?php
+/**
+ * Migrate archive.ar_text and ar_flags to modern storage
+ *
+ * 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 Maintenance
+ */
+
+use Wikimedia\Rdbms\IDatabase;
+
+require_once __DIR__ . '/Maintenance.php';
+
+/**
+ * Maintenance script that migrates archive.ar_text and ar_flags to modern 
storage
+ *
+ * @ingroup Maintenance
+ * @since 1.31
+ */
+class MigrateArchiveText extends LoggedUpdateMaintenance {
+       public function __construct() {
+               parent::__construct();
+               $this->addDescription(
+                       'Migrates comments from pre-1.5 ar_text and ar_flags 
columns to modern storage'
+               );
+       }
+
+       protected function getUpdateKey() {
+               return __CLASS__;
+       }
+
+       protected function doDBUpdates() {
+               global $wgDefaultExternalStore;
+
+               $batchSize = $this->getBatchSize();
+
+               $this->output( "Migrating ar_text to modern storage...\n" );
+               $dbr = $this->getDB( DB_REPLICA, [ 'vslow' ] );
+               $dbw = $this->getDB( DB_MASTER );
+               $start = 0;
+               $count = 0;
+               $errors = 0;
+               while ( true ) {
+                       $res = $dbr->select(
+                               'archive',
+                               [ 'ar_id', 'ar_text', 'ar_flags' ],
+                               [
+                                       'ar_text_id' => null,
+                                       "ar_id > $start",
+                               ],
+                               __METHOD__,
+                               [ 'LIMIT' => $batchSize, 'ORDER BY' => [ 
'ar_id' ] ]
+                       );
+                       $numRows = $res->numRows();
+
+                       foreach ( $res as $row ) {
+                               $start = $row->ar_id;
+
+                               // Recompress the text (and store in external 
storage, if
+                               // applicable) if it's not already in external 
storage.
+                               if ( !in_array( 'external', explode( ',', 
$row->ar_flags ), true ) ) {
+                                       $data = Revision::getRevisionText( 
$row, 'ar_' );
+                                       if ( $data === false ) {
+                                               $this->error( "No blob for row 
ar_id=$row->ar_id" );
+                                               $errors++;
+                                               continue;
+                                       }
+                                       $flags = 
Revision::compressRevisionText( $data );
+
+                                       if ( $wgDefaultExternalStore ) {
+                                               $data = 
ExternalStore::insertToDefault( $data );
+                                               if ( !$data ) {
+                                                       throw new MWException( 
"Unable to store text to external storage" );
+                                               }
+                                               if ( $flags ) {
+                                                       $flags .= ',';
+                                               }
+                                               $flags .= 'external';
+                                       }
+                               } else {
+                                       $flags = $row->ar_flags;
+                                       $data = $row->ar_text;
+                               }
+
+                               $this->beginTransaction( $dbw, __METHOD__ );
+                               $dbw->insert(
+                                       'text',
+                                       [ 'old_text' => $data, 'old_flags' => 
$flags ],
+                                       __METHOD__
+                               );
+                               $id = $dbw->insertId();
+                               $dbw->update(
+                                       'archive',
+                                       [ 'ar_text_id' => $id, 'ar_text' => '', 
'ar_flags' => '' ],
+                                       [ 'ar_id' => $row->ar_id, 'ar_text_id' 
=> null ],
+                                       __METHOD__
+                               );
+                               $count += $dbw->affectedRows();
+                               $this->commitTransaction( $dbw, __METHOD__ );
+                       }
+
+                       if ( $numRows < $batchSize ) {
+                               // We must have reached the end
+                               break;
+                       }
+
+                       $this->output( "... $start\n" );
+               }
+
+               $this->output( "Completed ar_text migration, $count rows 
updated.\n" );
+
+               return $errors === 0;
+       }
+}
+
+$maintClass = "MigrateArchiveText";
+require_once RUN_MAINTENANCE_IF_MAIN;

-- 
To view, visit https://gerrit.wikimedia.org/r/393928
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5608c6b6d3ecad516b785e13d668427c1b762e41
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to