Add 'temporary file' facility to fd.c, and arrange for temp
files to be closed automatically at transaction abort or commit, should they still be open. Also close any still-open stdio files allocated with AllocateFile at abort/commit. This should eliminate problems with leakage of file descriptors after an error. Also, put in some primitive buffered-IO support so that psort.c can use virtual files without severe performance penalties.
This commit is contained in:
parent
b0f1880a8e
commit
c1167a08ca
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.33 1999/03/28 20:31:59 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.34 1999/05/09 00:52:08 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Transaction aborts can now occur two ways:
|
||||
@ -148,6 +148,7 @@
|
||||
#include <utils/inval.h>
|
||||
#include <utils/portal.h>
|
||||
#include <access/transam.h>
|
||||
#include <storage/fd.h>
|
||||
#include <storage/proc.h>
|
||||
#include <utils/mcxt.h>
|
||||
#include <catalog/heap.h>
|
||||
@ -920,6 +921,7 @@ CommitTransaction()
|
||||
AtCommit_Cache();
|
||||
AtCommit_Locks();
|
||||
AtCommit_Memory();
|
||||
AtEOXact_Files();
|
||||
|
||||
/* ----------------
|
||||
* done with commit processing, set current transaction
|
||||
@ -990,6 +992,7 @@ AbortTransaction()
|
||||
AtAbort_Cache();
|
||||
AtAbort_Locks();
|
||||
AtAbort_Memory();
|
||||
AtEOXact_Files();
|
||||
|
||||
/* ----------------
|
||||
* done with abort processing, set current transaction
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: fd.h,v 1.12 1999/02/13 23:22:05 momjian Exp $
|
||||
* $Id: fd.h,v 1.13 1999/05/09 00:52:06 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -17,19 +17,23 @@
|
||||
* {File Name Open, Allocate, Free} File
|
||||
*
|
||||
* These are NOT JUST RENAMINGS OF THE UNIX ROUTINES.
|
||||
* use them for all file activity...
|
||||
* Use them for all file activity...
|
||||
*
|
||||
* fd = FilePathOpenFile("foo", O_RDONLY);
|
||||
* File fd;
|
||||
*
|
||||
* use AllocateFile if you need a file descriptor in some other context.
|
||||
* it will make sure that there is a file descriptor free
|
||||
*
|
||||
* use FreeFile to let the virtual file descriptor package know that
|
||||
* there is now a free fd (when you are done with it)
|
||||
* fd = FilePathOpenFile("foo", O_RDONLY);
|
||||
*
|
||||
* AllocateFile();
|
||||
* FreeFile();
|
||||
*
|
||||
* Use AllocateFile, not fopen, if you need a stdio file (FILE*); then
|
||||
* use FreeFile, not fclose, to close it. AVOID using stdio for files
|
||||
* that you intend to hold open for any length of time, since there is
|
||||
* no way for them to share kernel file descriptors with other files.
|
||||
*
|
||||
* The BufFile routines provide a partial replacement for stdio. Currently
|
||||
* they only support buffered access to a virtual file, without any of
|
||||
* stdio's formatting features. That's enough for immediate needs, but
|
||||
* the set of facilities could be expanded if necessary.
|
||||
*/
|
||||
#ifndef FD_H
|
||||
#define FD_H
|
||||
@ -44,7 +48,11 @@ typedef char *FileName;
|
||||
|
||||
typedef int File;
|
||||
|
||||
/* originally in libpq-fs.h */
|
||||
/* BufFile is an opaque type whose details are not known outside fd.c. */
|
||||
|
||||
typedef struct BufFile BufFile;
|
||||
|
||||
/* why is this here? fd.c doesn't want it ... */
|
||||
struct pgstat
|
||||
{ /* just the fields we need from stat
|
||||
* structure */
|
||||
@ -62,8 +70,11 @@ struct pgstat
|
||||
/*
|
||||
* prototypes for functions in fd.c
|
||||
*/
|
||||
|
||||
/* Operations on virtual Files --- equivalent to Unix kernel file ops */
|
||||
extern File FileNameOpenFile(FileName fileName, int fileFlags, int fileMode);
|
||||
extern File PathNameOpenFile(FileName fileName, int fileFlags, int fileMode);
|
||||
extern File OpenTemporaryFile(void);
|
||||
extern void FileClose(File file);
|
||||
extern void FileUnlink(File file);
|
||||
extern int FileRead(File file, char *buffer, int amount);
|
||||
@ -71,10 +82,25 @@ extern int FileWrite(File file, char *buffer, int amount);
|
||||
extern long FileSeek(File file, long offset, int whence);
|
||||
extern int FileTruncate(File file, int offset);
|
||||
extern int FileSync(File file);
|
||||
extern int FileNameUnlink(char *filename);
|
||||
|
||||
/* Operations that allow use of regular stdio --- USE WITH CAUTION */
|
||||
extern FILE *AllocateFile(char *name, char *mode);
|
||||
extern void FreeFile(FILE *);
|
||||
|
||||
/* Operations on BufFiles --- a very incomplete emulation of stdio
|
||||
* atop virtual Files...
|
||||
*/
|
||||
extern BufFile *BufFileCreate(File file);
|
||||
extern void BufFileClose(BufFile *file);
|
||||
extern size_t BufFileRead(BufFile *file, void *ptr, size_t size);
|
||||
extern size_t BufFileWrite(BufFile *file, void *ptr, size_t size);
|
||||
extern int BufFileFlush(BufFile *file);
|
||||
extern long BufFileSeek(BufFile *file, long offset, int whence);
|
||||
|
||||
/* Miscellaneous support routines */
|
||||
extern int FileNameUnlink(char *filename);
|
||||
extern void closeAllVfds(void);
|
||||
extern void AtEOXact_Files(void);
|
||||
extern int pg_fsync(int fd);
|
||||
|
||||
#endif /* FD_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user