Fix genbki.pl and Gen_fmgrtab.pl to use PID-specific temp file names,
authorTom Lane <[email protected]>
Tue, 5 Jan 2010 20:23:32 +0000 (20:23 +0000)
committerTom Lane <[email protected]>
Tue, 5 Jan 2010 20:23:32 +0000 (20:23 +0000)
so that it's safe if a parallel make chooses to run two concurrent copies.
Also, work around a memory leak in some versions of Perl.

src/backend/catalog/Catalog.pm
src/backend/catalog/genbki.pl
src/backend/utils/Gen_fmgrtab.pl

index 241b252394c96c7bfded301f70bf5c7fa3d4c3c3..d3fe389b7b4c9d4ed3a4cddef246a3f36f3e472f 100644 (file)
@@ -170,11 +170,14 @@ sub Catalogs
 }
 
 # Rename temporary files to final names.
-# Call this function with the final file name --- we append .tmp automatically
+# Call this function with the final file name and the .tmp extension
+# Note: recommended extension is ".tmp$$", so that parallel make steps
+# can't use the same temp files
 sub RenameTempFile
 {
     my $final_name = shift;
-    my $temp_name = $final_name . '.tmp';
+    my $extension = shift;
+    my $temp_name = $final_name . $extension;
     print "Writing $final_name\n";
     rename($temp_name, $final_name) || die "rename: $temp_name: $!";
 }
index 7a51b09b0ddc145aae896be0dc3b60ba0fc3e70e..edd3aee5072d91b2517c40d40d5890bb5e252f2c 100644 (file)
@@ -62,14 +62,19 @@ if ($output_path ne '' && substr($output_path, -1) ne '/')
 }
 
 # Open temp files
-open BKI,      '>', $output_path . 'postgres.bki.tmp'
-  || die "can't open postgres.bki.tmp: $!";
-open SCHEMAPG, '>', $output_path . 'schemapg.h.tmp'
-  || die "can't open 'schemapg.h.tmp: $!";
-open DESCR,    '>', $output_path . 'postgres.description.tmp'
-  || die "can't open postgres.description.tmp: $!";
-open SHDESCR,  '>', $output_path . 'postgres.shdescription.tmp'
-  || die "can't open postgres.shdescription.tmp: $!";
+my $tmpext = ".tmp$$";
+my $bkifile = $output_path . 'postgres.bki';
+open BKI, '>', $bkifile . $tmpext
+  or die "can't open $bkifile$tmpext: $!";
+my $schemafile = $output_path . 'schemapg.h';
+open SCHEMAPG, '>', $schemafile . $tmpext
+  or die "can't open $schemafile$tmpext: $!";
+my $descrfile = $output_path . 'postgres.description';
+open DESCR, '>', $descrfile . $tmpext
+  or die "can't open $descrfile$tmpext: $!";
+my $shdescrfile = $output_path . 'postgres.shdescription';
+open SHDESCR, '>', $shdescrfile . $tmpext
+  or die "can't open $shdescrfile$tmpext: $!";
 
 # Fetch some special data that we will substitute into the output file.
 # CAUTION: be wary about what symbols you substitute into the .bki file here!
@@ -283,15 +288,15 @@ print SCHEMAPG "\n#endif /* SCHEMAPG_H */\n";
 
 # We're done emitting data
 close BKI;
+close SCHEMAPG;
 close DESCR;
 close SHDESCR;
-close SCHEMAPG;
 
 # Finally, rename the completed files into place.
-Catalog::RenameTempFile($output_path . 'postgres.bki');
-Catalog::RenameTempFile($output_path . 'postgres.description');
-Catalog::RenameTempFile($output_path . 'postgres.shdescription');
-Catalog::RenameTempFile($output_path . 'schemapg.h');
+Catalog::RenameTempFile($bkifile, $tmpext);
+Catalog::RenameTempFile($schemafile, $tmpext);
+Catalog::RenameTempFile($descrfile, $tmpext);
+Catalog::RenameTempFile($shdescrfile, $tmpext);
 
 exit 0;
 
index fe03c2736ba556d4761282d712e99acf7f3520d4..8de25d9ed8f2e3d73626cbbd92627703f637bb64 100644 (file)
@@ -58,7 +58,6 @@ foreach my $column ( @{ $catalogs->{pg_proc}->{columns} } )
 my $data = $catalogs->{pg_proc}->{data};
 foreach my $row (@$data)
 {
-
     # To construct fmgroids.h and fmgrtab.c, we need to inspect some
     # of the individual data fields.  Just splitting on whitespace
     # won't work, because some quoted fields might contain internal
@@ -81,10 +80,19 @@ foreach my $row (@$data)
         nargs  => $row->{pronargs},
         prosrc => $row->{prosrc},
       };
+
+    # Hack to work around memory leak in some versions of Perl
+    $row = undef;
 }
 
 # Emit headers for both files
-open H, '>', $output_path . 'fmgroids.h.tmp' || die "Could not open fmgroids.h.tmp: $!";
+my $tmpext = ".tmp$$";
+my $oidsfile = $output_path . 'fmgroids.h';
+my $tabfile = $output_path . 'fmgrtab.c';
+
+open H, '>', $oidsfile . $tmpext or die "Could not open $oidsfile$tmpext: $!";
+open T, '>', $tabfile . $tmpext or die "Could not open $tabfile$tmpext: $!";
+
 print H 
 qq|/*-------------------------------------------------------------------------
  *
@@ -123,7 +131,6 @@ qq|/*-------------------------------------------------------------------------
  */
 |;
 
-open T, '>', $output_path . 'fmgrtab.c.tmp' || die "Could not open fmgrtab.c.tmp: $!";
 print T
 qq|/*-------------------------------------------------------------------------
  *
@@ -174,7 +181,6 @@ foreach my $s (sort {$a->{oid} <=> $b->{oid}} @fmgr)
 
 # And add the file footers.
 print H "\n#endif /* FMGROIDS_H */\n";
-close(H);
 
 print T
 qq|  /* dummy entry is easier than getting rid of comma after last real one */
@@ -187,11 +193,12 @@ qq|  /* dummy entry is easier than getting rid of comma after last real one */
 const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)) - 1;
 |;
 
+close(H);
 close(T);
 
 # Finally, rename the completed files into place.
-Catalog::RenameTempFile($output_path . 'fmgroids.h');
-Catalog::RenameTempFile($output_path . 'fmgrtab.c');
+Catalog::RenameTempFile($oidsfile, $tmpext);
+Catalog::RenameTempFile($tabfile, $tmpext);
 
 sub usage
 {