r102482 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102481‎ | r102482 | r102483 >
Date:02:40, 9 November 2011
Author:tstarling
Status:resolved
Tags:
Comment:
Added an external locking layer around Subversion access to the repository. Intended as a stopgap measure to address bug 27228. Committing for test on server.
Modified paths:
  • /trunk/extensions/ExtensionDistributor/cron.php (added) (history)
  • /trunk/extensions/ExtensionDistributor/svn-invoker.conf.sample (modified) (history)
  • /trunk/extensions/ExtensionDistributor/svn-invoker.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ExtensionDistributor/svn-invoker.conf.sample
@@ -1,4 +1,4 @@
22 <?php
33
44 $wgExtDistWorkingCopy = '/path/to/mw-working-copy';
5 -
 5+$wgExtDistLockFile = '/path/to/lock-file';
Index: trunk/extensions/ExtensionDistributor/cron.php
@@ -0,0 +1,52 @@
 2+<?php
 3+
 4+/**
 5+ * Script to be run from cron, to update the svn working copies (especially new extensions)
 6+ */
 7+
 8+if ( php_sapi_name() !== 'cli' ) {
 9+ echo "This script can only be run from the command line\n";
 10+ exit( 1 );
 11+}
 12+
 13+$wgExtDistWorkingCopy = false;
 14+$wgExtDistLockFile = false;
 15+$confFile = dirname( __FILE__ ) . '/svn-invoker.conf';
 16+if ( !file_exists( $confFile ) ) {
 17+ echo "Error: please create svn-invoker.conf based on svn-invoker.conf.sample\n";
 18+ exit( 1 );
 19+}
 20+require( $confFile );
 21+
 22+cronExecute();
 23+
 24+function cronExecute() {
 25+ global $wgExtDistLockFile;
 26+ if ( $wgExtDistLockFile ) {
 27+ $lockFile = fopen( $wgExtDistLockFile, 'r+' );
 28+ if ( !$lockFile ) {
 29+ echo "Error opening lock file\n";
 30+ exit( 1 );
 31+ }
 32+ if ( !flock( $lockFile, LOCK_EX | LOCK_NB ) ) {
 33+ echo "Error obtaining lock\n";
 34+ exit( 1 );
 35+ }
 36+ }
 37+
 38+ // Update the files
 39+ svnUpdate( "$wgExtDistWorkingCopy/trunk" );
 40+ for ( glob( "$wgExtDistWorkingCopy/branches/*", GLOB_ONLYDIR ) as $branch ) {
 41+ svnUpdate( $branch );
 42+ }
 43+}
 44+
 45+function svnUpdate( $path ) {
 46+ $cmd = "svn up --non-interactive " . escapeshellarg( $path );
 47+ $retval = 1;
 48+ system( $cmd, $retval );
 49+ if ( $retval ) {
 50+ echo "Error executing command: $cmd\n";
 51+ exit( 1 );
 52+ }
 53+}
Property changes on: trunk/extensions/ExtensionDistributor/cron.php
___________________________________________________________________
Added: svn:eol-style
154 + native
Index: trunk/extensions/ExtensionDistributor/svn-invoker.php
@@ -9,6 +9,8 @@
1010 exit( 1 );
1111 }
1212
 13+$wgExtDistWorkingCopy = false;
 14+$wgExtDistLockFile = false;
1315 $confFile = dirname( __FILE__ ) . '/svn-invoker.conf';
1416 if ( !file_exists( $confFile ) ) {
1517 echo "Error: please create svn-invoker.conf based on svn-invoker.conf.sample\n";
@@ -39,7 +41,7 @@
4042 }
4143
4244 function svnExecute() {
43 - global $wgExtDistWorkingCopy;
 45+ global $wgExtDistWorkingCopy, $wgExtDistLockFile;
4446
4547 $encCommand = '';
4648 $done = false;
@@ -57,6 +59,30 @@
5860 return;
5961 }
6062
 63+ if ( $wgExtDistLockFile ) {
 64+ $lockFile = fopen( $wgExtDistLockFile, 'r+' );
 65+ if ( !$lockFile ) {
 66+ svnError( 'extdist-remote-error', "Unable to open lock file." );
 67+ return;
 68+ }
 69+ $timeout = 20;
 70+ for ( $i = 0; $i < $timeout; $i++ ) {
 71+ $wouldBlock = false;
 72+ if ( flock( $lockFile, LOCK_EX | LOCK_NB ) ) {
 73+ break;
 74+ }
 75+ if ( !$wouldBlock ) {
 76+ svnError( 'extdist-remote-error', "Error attempting to obtain lock." );
 77+ return;
 78+ }
 79+ sleep( 1 );
 80+ }
 81+ if ( $i == $timeout ) {
 82+ svnError( 'extdist-remote-error', "Lock wait timeout." );
 83+ return;
 84+ }
 85+ }
 86+
6187 $command = json_decode( $encCommand );
6288 if ( !isset( $command->version ) || !isset( $command->extension ) ) {
6389 svnError( 'extdist-remote-error', "Missing version or extension parameter." );

Follow-up revisions

RevisionCommit summaryAuthorDate
r102483MFT r102482tstarling02:44, 9 November 2011
r102502More fixes for r102482: the $wouldBlock check doesn't appear to work, also do...tstarling09:59, 9 November 2011

Status & tagging log