Fix genbki.pl and Gen_fmgrtab.pl to use PID-specific temp file names,

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.
This commit is contained in:
Tom Lane 2010-01-05 20:23:32 +00:00
parent 1658f6bf58
commit 72559b49c0
3 changed files with 39 additions and 24 deletions

View File

@ -7,7 +7,7 @@
# Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group # Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California # Portions Copyright (c) 1994, Regents of the University of California
# #
# $PostgreSQL: pgsql/src/backend/catalog/Catalog.pm,v 1.2 2010/01/05 02:34:03 tgl Exp $ # $PostgreSQL: pgsql/src/backend/catalog/Catalog.pm,v 1.3 2010/01/05 20:23:32 tgl Exp $
# #
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@ -170,11 +170,14 @@ sub Catalogs
} }
# Rename temporary files to final names. # 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 sub RenameTempFile
{ {
my $final_name = shift; my $final_name = shift;
my $temp_name = $final_name . '.tmp'; my $extension = shift;
my $temp_name = $final_name . $extension;
print "Writing $final_name\n"; print "Writing $final_name\n";
rename($temp_name, $final_name) || die "rename: $temp_name: $!"; rename($temp_name, $final_name) || die "rename: $temp_name: $!";
} }

View File

@ -10,7 +10,7 @@
# Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group # Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California # Portions Copyright (c) 1994, Regents of the University of California
# #
# $PostgreSQL: pgsql/src/backend/catalog/genbki.pl,v 1.3 2010/01/05 06:41:44 tgl Exp $ # $PostgreSQL: pgsql/src/backend/catalog/genbki.pl,v 1.4 2010/01/05 20:23:32 tgl Exp $
# #
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@ -62,14 +62,19 @@ if ($output_path ne '' && substr($output_path, -1) ne '/')
} }
# Open temp files # Open temp files
open BKI, '>', $output_path . 'postgres.bki.tmp' my $tmpext = ".tmp$$";
|| die "can't open postgres.bki.tmp: $!"; my $bkifile = $output_path . 'postgres.bki';
open SCHEMAPG, '>', $output_path . 'schemapg.h.tmp' open BKI, '>', $bkifile . $tmpext
|| die "can't open 'schemapg.h.tmp: $!"; or die "can't open $bkifile$tmpext: $!";
open DESCR, '>', $output_path . 'postgres.description.tmp' my $schemafile = $output_path . 'schemapg.h';
|| die "can't open postgres.description.tmp: $!"; open SCHEMAPG, '>', $schemafile . $tmpext
open SHDESCR, '>', $output_path . 'postgres.shdescription.tmp' or die "can't open $schemafile$tmpext: $!";
|| die "can't open postgres.shdescription.tmp: $!"; 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. # 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! # 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 # We're done emitting data
close BKI; close BKI;
close SCHEMAPG;
close DESCR; close DESCR;
close SHDESCR; close SHDESCR;
close SCHEMAPG;
# Finally, rename the completed files into place. # Finally, rename the completed files into place.
Catalog::RenameTempFile($output_path . 'postgres.bki'); Catalog::RenameTempFile($bkifile, $tmpext);
Catalog::RenameTempFile($output_path . 'postgres.description'); Catalog::RenameTempFile($schemafile, $tmpext);
Catalog::RenameTempFile($output_path . 'postgres.shdescription'); Catalog::RenameTempFile($descrfile, $tmpext);
Catalog::RenameTempFile($output_path . 'schemapg.h'); Catalog::RenameTempFile($shdescrfile, $tmpext);
exit 0; exit 0;

View File

@ -9,7 +9,7 @@
# #
# #
# IDENTIFICATION # IDENTIFICATION
# $PostgreSQL: pgsql/src/backend/utils/Gen_fmgrtab.pl,v 1.4 2010/01/05 01:06:56 tgl Exp $ # $PostgreSQL: pgsql/src/backend/utils/Gen_fmgrtab.pl,v 1.5 2010/01/05 20:23:32 tgl Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -58,7 +58,6 @@ foreach my $column ( @{ $catalogs->{pg_proc}->{columns} } )
my $data = $catalogs->{pg_proc}->{data}; my $data = $catalogs->{pg_proc}->{data};
foreach my $row (@$data) foreach my $row (@$data)
{ {
# To construct fmgroids.h and fmgrtab.c, we need to inspect some # To construct fmgroids.h and fmgrtab.c, we need to inspect some
# of the individual data fields. Just splitting on whitespace # of the individual data fields. Just splitting on whitespace
# won't work, because some quoted fields might contain internal # won't work, because some quoted fields might contain internal
@ -81,10 +80,19 @@ foreach my $row (@$data)
nargs => $row->{pronargs}, nargs => $row->{pronargs},
prosrc => $row->{prosrc}, prosrc => $row->{prosrc},
}; };
# Hack to work around memory leak in some versions of Perl
$row = undef;
} }
# Emit headers for both files # 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 print H
qq|/*------------------------------------------------------------------------- qq|/*-------------------------------------------------------------------------
* *
@ -123,7 +131,6 @@ qq|/*-------------------------------------------------------------------------
*/ */
|; |;
open T, '>', $output_path . 'fmgrtab.c.tmp' || die "Could not open fmgrtab.c.tmp: $!";
print T print T
qq|/*------------------------------------------------------------------------- qq|/*-------------------------------------------------------------------------
* *
@ -174,7 +181,6 @@ foreach my $s (sort {$a->{oid} <=> $b->{oid}} @fmgr)
# And add the file footers. # And add the file footers.
print H "\n#endif /* FMGROIDS_H */\n"; print H "\n#endif /* FMGROIDS_H */\n";
close(H);
print T print T
qq| /* dummy entry is easier than getting rid of comma after last real one */ 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; const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)) - 1;
|; |;
close(H);
close(T); close(T);
# Finally, rename the completed files into place. # Finally, rename the completed files into place.
Catalog::RenameTempFile($output_path . 'fmgroids.h'); Catalog::RenameTempFile($oidsfile, $tmpext);
Catalog::RenameTempFile($output_path . 'fmgrtab.c'); Catalog::RenameTempFile($tabfile, $tmpext);
sub usage sub usage
{ {