r95604 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95603‎ | r95604 | r95605 >
Date:18:31, 27 August 2011
Author:ariel
Status:ok (Comments)
Tags:
Comment:
define and use closeAndRename() after last write of xml dump file; convert from popen (child inherits all open descriptors and there is no workaround) to proc_open (CLOEXEC set on all descriptors), needed so close and rename doesn't hang forever if a child (prefetcher) is forked
Modified paths:
  • /trunk/phase3/includes/Export.php (modified) (history)
  • /trunk/phase3/maintenance/dumpTextPass.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/dumpTextPass.php
@@ -308,7 +308,7 @@
309309 $fileinfo = pathinfo($filenameList[$i]);
310310 $newFilenames[] = $fileinfo{'dirname'} . '/' . $checkpointNameFilledIn;
311311 }
312 - $this->egress->rename( $newFilenames );
 312+ $this->egress->closeAndRename( $newFilenames );
313313 }
314314 }
315315 xml_parser_free( $parser );
Index: trunk/phase3/includes/Export.php
@@ -704,6 +704,10 @@
705705 return;
706706 }
707707
 708+ function closeAndRename( $newname ) {
 709+ return;
 710+ }
 711+
708712 function rename( $newname ) {
709713 return;
710714 }
@@ -752,6 +756,21 @@
753757 }
754758 }
755759
 760+ function closeAndRename( $newname ) {
 761+ if ( is_array($newname) ) {
 762+ if (count($newname) > 1) {
 763+ throw new MWException("Export closeRenameAndReopen: passed multiple argumnts for rename of single file\n");
 764+ }
 765+ else {
 766+ $newname = $newname[0];
 767+ }
 768+ }
 769+ if ( $newname ) {
 770+ fclose( $this->handle );
 771+ rename( $this->filename, $newname );
 772+ }
 773+ }
 774+
756775 function rename( $newname ) {
757776 if ( is_array($newname) ) {
758777 if (count($newname) > 1) {
@@ -784,11 +803,21 @@
785804 if ( !is_null( $file ) ) {
786805 $command .= " > " . wfEscapeShellArg( $file );
787806 }
788 - $this->handle = popen( $command, "w" );
 807+
 808+ $this->startCommand($command);
789809 $this->command = $command;
790810 $this->filename = $file;
791811 }
792812
 813+ function startCommand($command) {
 814+ $spec = array(
 815+ 0 => array( "pipe", "r" ),
 816+ );
 817+ $pipes = array();
 818+ $this->procOpenResource = proc_open( $command, $spec, $pipes );
 819+ $this->handle = $pipes[0];
 820+ }
 821+
793822 /**
794823 * Close the old file, move it to a specified name,
795824 * and reopen new file with the old name.
@@ -803,14 +832,32 @@
804833 }
805834 }
806835 if ( $newname ) {
807 - pclose( $this->handle );
 836+ fclose( $this->handle );
 837+ proc_close($this->procOpenResource);
808838 rename( $this->filename, $newname );
809839 $command = $this->command;
810840 $command .= " > " . wfEscapeShellArg( $this->filename );
811 - $this->handle = popen( $command, "w" );
 841+ $this->startCommand($command);
812842 }
813843 }
814844
 845+ function closeAndRename( $newname ) {
 846+ if ( is_array($newname) ) {
 847+ if (count($newname) > 1) {
 848+ throw new MWException("Export closeRenameAndReopen: passed multiple argumnts for rename of single file\n");
 849+ }
 850+ else {
 851+ $newname = $newname[0];
 852+ }
 853+ }
 854+ if ( $newname ) {
 855+# pclose( $this->handle );
 856+ fclose( $this->handle );
 857+ proc_close($this->procOpenResource);
 858+ rename( $this->filename, $newname );
 859+ }
 860+ }
 861+
815862 function rename( $newname ) {
816863 if ( is_array($newname) ) {
817864 if (count($newname) > 1) {
@@ -872,14 +919,31 @@
873920 }
874921 }
875922 if ( $newname ) {
876 - pclose( $this->handle );
 923+ fclose( $this->handle );
 924+ proc_close($this->procOpenResource);
877925 rename( $this->filename, $newname );
878926 $command = "7za a -bd -si " . wfEscapeShellArg( $file );
879927 $command .= ' >' . wfGetNull() . ' 2>&1';
880 - $this->handle = popen( $command, "w" );
 928+ $this->startCommand($command);
881929 }
882930 }
883931
 932+ function closeAndRename( $newname ) {
 933+ if ( is_array($newname) ) {
 934+ if (count($newname) > 1) {
 935+ throw new MWException("Export closeRenameAndReopen: passed multiple argumnts for rename of single file\n");
 936+ }
 937+ else {
 938+ $newname = $newname[0];
 939+ }
 940+ }
 941+ if ( $newname ) {
 942+ fclose( $this->handle );
 943+ proc_close($this->procOpenResource);
 944+ rename( $this->filename, $newname );
 945+ }
 946+ }
 947+
884948 function rename( $newname ) {
885949 if ( is_array($newname) ) {
886950 if (count($newname) > 1) {
@@ -944,6 +1008,10 @@
9451009 $this->sink->closeRenameAndReopen( $newname );
9461010 }
9471011
 1012+ function closeAndRename( $newname ) {
 1013+ $this->sink->closeAndRename( $newname );
 1014+ }
 1015+
9481016 function rename( $newname ) {
9491017 $this->sink->rename( $newname );
9501018 }
@@ -1106,6 +1174,11 @@
11071175 }
11081176 }
11091177
 1178+ function closeAndRename( $newname ) {
 1179+ for( $i = 0; $i < $this->count; $i++ ) {
 1180+ $this->sinks[$i]->closeAndRename( $newnames[$i] );
 1181+ }
 1182+ }
11101183 function rename( $newnames ) {
11111184 for( $i = 0; $i < $this->count; $i++ ) {
11121185 $this->sinks[$i]->rename( $newnames[$i] );

Follow-up revisions

RevisionCommit summaryAuthorDate
r96276Whitespace fixes for r95272, r95604catrope11:22, 5 September 2011
r96556MFT r95260, r95272, r95288, r95290, r95443, r95601, r95604, r95634, r95720, r...reedy12:28, 8 September 2011

Comments

#Comment by Catrope (talk | contribs)   11:40, 5 September 2011
+#			pclose( $this->handle );

Leftover debugging code or something?

Status & tagging log