PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
fileset.h File Reference
#include "storage/fd.h"
Include dependency graph for fileset.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  FileSet
 

Typedefs

typedef struct FileSet FileSet
 

Functions

void FileSetInit (FileSet *fileset)
 
File FileSetCreate (FileSet *fileset, const char *name)
 
File FileSetOpen (FileSet *fileset, const char *name, int mode)
 
bool FileSetDelete (FileSet *fileset, const char *name, bool error_on_failure)
 
void FileSetDeleteAll (FileSet *fileset)
 

Typedef Documentation

◆ FileSet

typedef struct FileSet FileSet

Function Documentation

◆ FileSetCreate()

File FileSetCreate ( FileSet fileset,
const char *  name 
)

Definition at line 92 of file fileset.c.

93{
94 char path[MAXPGPATH];
95 File file;
96
97 FilePath(path, fileset, name);
98 file = PathNameCreateTemporaryFile(path, false);
99
100 /* If we failed, see if we need to create the directory on demand. */
101 if (file <= 0)
102 {
103 char tempdirpath[MAXPGPATH];
104 char filesetpath[MAXPGPATH];
106
107 TempTablespacePath(tempdirpath, tablespace);
108 FileSetPath(filesetpath, fileset, tablespace);
109 PathNameCreateTemporaryDir(tempdirpath, filesetpath);
110 file = PathNameCreateTemporaryFile(path, true);
111 }
112
113 return file;
114}
File PathNameCreateTemporaryFile(const char *path, bool error_on_failure)
Definition: fd.c:1860
void PathNameCreateTemporaryDir(const char *basedir, const char *directory)
Definition: fd.c:1659
void TempTablespacePath(char *path, Oid tablespace)
Definition: fd.c:1778
int File
Definition: fd.h:51
static void FilePath(char *path, FileSet *fileset, const char *name)
Definition: fileset.c:197
static void FileSetPath(char *path, FileSet *fileset, Oid tablespace)
Definition: fileset.c:172
static Oid ChooseTablespace(const FileSet *fileset, const char *name)
Definition: fileset.c:186
#define MAXPGPATH
static char * tablespace
Definition: pgbench.c:216
unsigned int Oid
Definition: postgres_ext.h:31
const char * name

References ChooseTablespace(), FilePath(), FileSetPath(), MAXPGPATH, name, PathNameCreateTemporaryDir(), PathNameCreateTemporaryFile(), tablespace, and TempTablespacePath().

Referenced by MakeNewFileSetSegment().

◆ FileSetDelete()

bool FileSetDelete ( FileSet fileset,
const char *  name,
bool  error_on_failure 
)

Definition at line 136 of file fileset.c.

138{
139 char path[MAXPGPATH];
140
141 FilePath(path, fileset, name);
142
143 return PathNameDeleteTemporaryFile(path, error_on_failure);
144}
bool PathNameDeleteTemporaryFile(const char *path, bool error_on_failure)
Definition: fd.c:1931

References FilePath(), MAXPGPATH, name, and PathNameDeleteTemporaryFile().

Referenced by BufFileDeleteFileSet(), BufFileTruncateFileSet(), and MakeNewFileSetSegment().

◆ FileSetDeleteAll()

void FileSetDeleteAll ( FileSet fileset)

Definition at line 150 of file fileset.c.

151{
152 char dirpath[MAXPGPATH];
153 int i;
154
155 /*
156 * Delete the directory we created in each tablespace. Doesn't fail
157 * because we use this in error cleanup paths, but can generate LOG
158 * message on IO error.
159 */
160 for (i = 0; i < fileset->ntablespaces; ++i)
161 {
162 FileSetPath(dirpath, fileset, fileset->tablespaces[i]);
164 }
165}
void PathNameDeleteTemporaryDir(const char *dirname)
Definition: fd.c:1690
int i
Definition: isn.c:72
Oid tablespaces[8]
Definition: fileset.h:27
int ntablespaces
Definition: fileset.h:26

References FileSetPath(), i, MAXPGPATH, FileSet::ntablespaces, PathNameDeleteTemporaryDir(), and FileSet::tablespaces.

Referenced by logicalrep_worker_onexit(), SharedFileSetDeleteAll(), and SharedFileSetOnDetach().

◆ FileSetInit()

void FileSetInit ( FileSet fileset)

Definition at line 52 of file fileset.c.

53{
54 static uint32 counter = 0;
55
56 fileset->creator_pid = MyProcPid;
57 fileset->number = counter;
58 counter = (counter + 1) % INT_MAX;
59
60 /* Capture the tablespace OIDs so that all backends agree on them. */
62 fileset->ntablespaces =
64 lengthof(fileset->tablespaces));
65 if (fileset->ntablespaces == 0)
66 {
67 /* If the GUC is empty, use current database's default tablespace */
69 fileset->ntablespaces = 1;
70 }
71 else
72 {
73 int i;
74
75 /*
76 * An entry of InvalidOid means use the default tablespace for the
77 * current database. Replace that now, to be sure that all users of
78 * the FileSet agree on what to do.
79 */
80 for (i = 0; i < fileset->ntablespaces; i++)
81 {
82 if (fileset->tablespaces[i] == InvalidOid)
84 }
85 }
86}
void PrepareTempTablespaces(void)
Definition: tablespace.c:1331
uint32_t uint32
Definition: c.h:485
#define lengthof(array)
Definition: c.h:742
int GetTempTablespaces(Oid *tableSpaces, int numSpaces)
Definition: fd.c:3115
int MyProcPid
Definition: globals.c:46
Oid MyDatabaseTableSpace
Definition: globals.c:95
#define InvalidOid
Definition: postgres_ext.h:36
pid_t creator_pid
Definition: fileset.h:24
uint32 number
Definition: fileset.h:25

References FileSet::creator_pid, GetTempTablespaces(), i, InvalidOid, lengthof, MyDatabaseTableSpace, MyProcPid, FileSet::ntablespaces, FileSet::number, PrepareTempTablespaces(), and FileSet::tablespaces.

Referenced by SharedFileSetInit(), and stream_start_internal().

◆ FileSetOpen()

File FileSetOpen ( FileSet fileset,
const char *  name,
int  mode 
)

Definition at line 119 of file fileset.c.

120{
121 char path[MAXPGPATH];
122 File file;
123
124 FilePath(path, fileset, name);
125 file = PathNameOpenTemporaryFile(path, mode);
126
127 return file;
128}
File PathNameOpenTemporaryFile(const char *path, int mode)
Definition: fd.c:1900
static PgChecksumMode mode
Definition: pg_checksums.c:55

References FilePath(), MAXPGPATH, mode, name, and PathNameOpenTemporaryFile().

Referenced by BufFileOpenFileSet().