r98178 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98177‎ | r98178 | r98179 >
Date:21:35, 26 September 2011
Author:asher
Status:ok
Tags:
Comment:
update lt schema upgrade script to work on secondary db's
Modified paths:
  • /branches/wmf/1.18wmf1/maintenance/upgrade-1.18wmf1-2.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/maintenance/upgrade-1.18wmf1-2.php
@@ -1,96 +1,115 @@
22 <?php
33
4 -require( dirname( __FILE__ ) . '/commandLine.inc' );
 4+require_once( dirname( __FILE__ ) . '/Maintenance.php' );
55 require( dirname( __FILE__ ) . '/../../wmf-config/InitialiseSettings.php' );
66
7 -doAllSchemaChanges();
 7+class SchemaMigration extends Maintenance {
88
9 -function doAllSchemaChanges() {
10 - global $wgLBFactoryConf, $wgConf;
 9+ public function __construct() {
 10+ parent::__construct();
 11+ $this->mDescription = "Run Schema Migrations for branch against all wikis";
 12+ $this->addOption( 'secondary', 'Run on secondary / non-prod slaves', false, false );
 13+ }
1114
12 - $sectionLoads = $wgLBFactoryConf['sectionLoads'];
13 - $sectionsByDB = $wgLBFactoryConf['sectionsByDB'];
14 - $rootPass = trim( wfShellExec( '/home/wikipedia/bin/mysql_root_pass' ) );
 15+ function doAllSchemaChanges() {
 16+ global $wgLBFactoryConf, $wgConf;
1517
16 - // Compile wiki lists
17 - $wikisBySection = array();
18 - foreach ( $wgConf->getLocalDatabases() as $wiki ) {
19 - if ( isset( $sectionsByDB[$wiki] ) ) {
20 - $wikisBySection[$sectionsByDB[$wiki]][] = $wiki;
21 - } else {
22 - $wikisBySection['DEFAULT'][] = $wiki;
23 - }
24 - }
 18+ if ( $this->getOption( 'secondary' ) ) {
 19+ require( dirname( __FILE__ ) . '/../../wmf-config/db-secondary.php' );
 20+ }
2521
26 - // Do the upgrades
27 - foreach ( $sectionLoads as $section => $loads ) {
28 - $master = true;
29 - foreach ( $loads as $server => $load ) {
30 - if ( $master ) {
31 - echo "Skipping $section master $server\n";
32 - $master = false;
33 - continue;
34 - }
 22+ $sectionLoads = $wgLBFactoryConf['sectionLoads'];
 23+ $sectionsByDB = $wgLBFactoryConf['sectionsByDB'];
3524
36 - $db = new DatabaseMysql(
37 - $server,
38 - 'root',
39 - $rootPass,
40 - false, /* dbName */
41 - 0, /* flags, no transactions */
42 - '' /* prefix */
43 - );
 25+ $rootPass = trim( wfShellExec( '/home/wikipedia/bin/mysql_root_pass' ) );
4426
45 - foreach ( $wikisBySection[$section] as $wiki ) {
46 - $db->selectDB( $wiki );
47 - upgradeWiki( $db );
48 - while ( $db->getLag() > 10 ) {
49 - echo "Waiting for $server to catch up to master.\n";
50 - sleep( 60 );
51 - }
52 - }
53 - }
54 - }
 27+ // Compile wiki lists
 28+ $wikisBySection = array();
 29+ foreach ( $wgConf->getLocalDatabases() as $wiki ) {
 30+ if ( isset( $sectionsByDB[$wiki] ) ) {
 31+ $wikisBySection[$sectionsByDB[$wiki]][] = $wiki;
 32+ } else {
 33+ $wikisBySection['DEFAULT'][] = $wiki;
 34+ }
 35+ }
5536
56 - echo "All done (except masters).\n";
57 -}
 37+ // Do the upgrades
 38+ foreach ( $sectionLoads as $section => $loads ) {
 39+ $master = true;
 40+ foreach ( $loads as $server => $load ) {
 41+ if ( $master ) {
 42+ echo "Skipping $section master $server\n";
 43+ $master = false;
 44+ continue;
 45+ }
5846
59 -function upgradeWiki( $db ) {
60 - global $wgConf;
61 - $wiki = $db->getDBname();
62 - $server = $db->getServer();
 47+ $db = new DatabaseMysql(
 48+ $server,
 49+ 'root',
 50+ $rootPass,
 51+ false, /* dbName */
 52+ 0, /* flags, no transactions */
 53+ '' /* prefix */
 54+ );
6355
64 - $upgradeLogRow = $db->selectRow( 'updatelog',
65 - 'ul_key',
66 - array( 'ul_key' => '1.18wmf1-lt' ),
67 - __FUNCTION__ );
68 - if ( $upgradeLogRow ) {
69 - echo $db->getDBname() . ": already done\n";
70 - return;
71 - }
 56+ foreach ( $wikisBySection[$section] as $wiki ) {
 57+ $db->selectDB( $wiki );
 58+ $this->upgradeWiki( $db );
 59+ if ( !$this->getOption( 'secondary' ) ) {
 60+ while ( $db->getLag() > 10 ) {
 61+ echo "Waiting for $server to catch up to master.\n";
 62+ sleep( 60 );
 63+ }
 64+ }
 65+ }
 66+ }
 67+ }
7268
73 - echo "$server $wiki 1.18wmf1-lt";
74 -
75 - if ( $wgConf->get( 'wmgUseLiquidThreads', $wiki ) && $wiki != "test2wiki") {
76 - echo " liquidthreads";
77 - sourceUpgradeFile( $db, dirname( __FILE__ ) .'/ums_conversation.sql' );
78 - } else {
79 - echo " no-op";
80 - }
81 -
82 - $db->insert( 'updatelog',
83 - array( 'ul_key' => '1.18wmf1-lt' ),
84 - __FUNCTION__ );
85 - echo " ok\n";
 69+ echo "All done (except masters).\n";
 70+ }
8671
87 -}
 72+ function upgradeWiki( $db ) {
 73+ global $wgConf;
 74+ $wiki = $db->getDBname();
 75+ $server = $db->getServer();
8876
89 -function sourceUpgradeFile( $db, $file ) {
90 - if ( !file_exists( $file ) ) {
91 - echo "File missing: $file\n";
92 - exit( 1 );
93 - }
94 - $db->sourceFile( $file );
 77+ $upgradeLogRow = $db->selectRow( 'updatelog',
 78+ 'ul_key',
 79+ array( 'ul_key' => '1.18wmf1-lt' ),
 80+ __FUNCTION__ );
 81+ if ( $upgradeLogRow ) {
 82+ echo $db->getDBname() . ": already done\n";
 83+ return;
 84+ }
 85+
 86+ echo "$server $wiki 1.18wmf1-lt";
 87+
 88+ if ( $wgConf->get( 'wmgUseLiquidThreads', $wiki ) && $wiki != "test2wiki") {
 89+ echo " liquidthreads";
 90+ $this->sourceUpgradeFile( $db, dirname( __FILE__ ) .'/ums_conversation.sql' );
 91+ } else {
 92+ echo " no-op";
 93+ }
 94+
 95+ $db->insert( 'updatelog',
 96+ array( 'ul_key' => '1.18wmf1-lt' ),
 97+ __FUNCTION__ );
 98+ echo " ok\n";
 99+ }
 100+
 101+ function sourceUpgradeFile( $db, $file ) {
 102+ if ( !file_exists( $file ) ) {
 103+ echo "File missing: $file\n";
 104+ exit( 1 );
 105+ }
 106+ $db->sourceFile( $file );
 107+ }
 108+
 109+ function execute() {
 110+ $this->doAllSchemaChanges();
 111+ }
95112 }
96113
 114+$maintClass = "SchemaMigration";
 115+require_once( RUN_MAINTENANCE_IF_MAIN );
97116

Status & tagging log