PostgreSQL Source Code  git master
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 95 of file fileset.c.

96 {
97  char path[MAXPGPATH];
98  File file;
99 
100  FilePath(path, fileset, name);
101  file = PathNameCreateTemporaryFile(path, false);
102 
103  /* If we failed, see if we need to create the directory on demand. */
104  if (file <= 0)
105  {
106  char tempdirpath[MAXPGPATH];
107  char filesetpath[MAXPGPATH];
108  Oid tablespace = ChooseTablespace(fileset, name);
109 
110  TempTablespacePath(tempdirpath, tablespace);
111  FileSetPath(filesetpath, fileset, tablespace);
112  PathNameCreateTemporaryDir(tempdirpath, filesetpath);
113  file = PathNameCreateTemporaryFile(path, true);
114  }
115 
116  return file;
117 }
File PathNameCreateTemporaryFile(const char *path, bool error_on_failure)
Definition: fd.c:1813
void PathNameCreateTemporaryDir(const char *basedir, const char *directory)
Definition: fd.c:1612
void TempTablespacePath(char *path, Oid tablespace)
Definition: fd.c:1731
int File
Definition: fd.h:49
static void FilePath(char *path, FileSet *fileset, const char *name)
Definition: fileset.c:200
static void FileSetPath(char *path, FileSet *fileset, Oid tablespace)
Definition: fileset.c:175
static Oid ChooseTablespace(const FileSet *fileset, const char *name)
Definition: fileset.c:189
#define MAXPGPATH
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 139 of file fileset.c.

141 {
142  char path[MAXPGPATH];
143 
144  FilePath(path, fileset, name);
145 
146  return PathNameDeleteTemporaryFile(path, error_on_failure);
147 }
bool PathNameDeleteTemporaryFile(const char *path, bool error_on_failure)
Definition: fd.c:1884

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

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

◆ FileSetDeleteAll()

void FileSetDeleteAll ( FileSet fileset)

Definition at line 153 of file fileset.c.

154 {
155  char dirpath[MAXPGPATH];
156  int i;
157 
158  /*
159  * Delete the directory we created in each tablespace. Doesn't fail
160  * because we use this in error cleanup paths, but can generate LOG
161  * message on IO error.
162  */
163  for (i = 0; i < fileset->ntablespaces; ++i)
164  {
165  FileSetPath(dirpath, fileset, fileset->tablespaces[i]);
167  }
168 }
void PathNameDeleteTemporaryDir(const char *dirname)
Definition: fd.c:1643
int i
Definition: isn.c:73
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 55 of file fileset.c.

56 {
57  static uint32 counter = 0;
58 
59  fileset->creator_pid = MyProcPid;
60  fileset->number = counter;
61  counter = (counter + 1) % INT_MAX;
62 
63  /* Capture the tablespace OIDs so that all backends agree on them. */
65  fileset->ntablespaces =
66  GetTempTablespaces(&fileset->tablespaces[0],
67  lengthof(fileset->tablespaces));
68  if (fileset->ntablespaces == 0)
69  {
70  /* If the GUC is empty, use current database's default tablespace */
71  fileset->tablespaces[0] = MyDatabaseTableSpace;
72  fileset->ntablespaces = 1;
73  }
74  else
75  {
76  int i;
77 
78  /*
79  * An entry of InvalidOid means use the default tablespace for the
80  * current database. Replace that now, to be sure that all users of
81  * the FileSet agree on what to do.
82  */
83  for (i = 0; i < fileset->ntablespaces; i++)
84  {
85  if (fileset->tablespaces[i] == InvalidOid)
87  }
88  }
89 }
void PrepareTempTablespaces(void)
Definition: tablespace.c:1337
unsigned int uint32
Definition: c.h:495
#define lengthof(array)
Definition: c.h:777
int GetTempTablespaces(Oid *tableSpaces, int numSpaces)
Definition: fd.c:3038
int MyProcPid
Definition: globals.c:44
Oid MyDatabaseTableSpace
Definition: globals.c:91
#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 122 of file fileset.c.

123 {
124  char path[MAXPGPATH];
125  File file;
126 
127  FilePath(path, fileset, name);
128  file = PathNameOpenTemporaryFile(path, mode);
129 
130  return file;
131 }
File PathNameOpenTemporaryFile(const char *path, int mode)
Definition: fd.c:1853
static PgChecksumMode mode
Definition: pg_checksums.c:56

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

Referenced by BufFileOpenFileSet().