PostgreSQL Source Code  git master
reinit.h File Reference
#include "common/relpath.h"
Include dependency graph for reinit.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define UNLOGGED_RELATION_CLEANUP   0x0001
 
#define UNLOGGED_RELATION_INIT   0x0002
 

Functions

void ResetUnloggedRelations (int op)
 
bool parse_filename_for_nontemp_relation (const char *name, int *relnumchars, ForkNumber *fork)
 

Macro Definition Documentation

◆ UNLOGGED_RELATION_CLEANUP

#define UNLOGGED_RELATION_CLEANUP   0x0001

Definition at line 26 of file reinit.h.

◆ UNLOGGED_RELATION_INIT

#define UNLOGGED_RELATION_INIT   0x0002

Definition at line 27 of file reinit.h.

Function Documentation

◆ parse_filename_for_nontemp_relation()

bool parse_filename_for_nontemp_relation ( const char *  name,
int *  relnumchars,
ForkNumber fork 
)

Definition at line 381 of file reinit.c.

383 {
384  int pos;
385 
386  /* Look for a non-empty string of digits (that isn't too long). */
387  for (pos = 0; isdigit((unsigned char) name[pos]); ++pos)
388  ;
389  if (pos == 0 || pos > OIDCHARS)
390  return false;
391  *relnumchars = pos;
392 
393  /* Check for a fork name. */
394  if (name[pos] != '_')
395  *fork = MAIN_FORKNUM;
396  else
397  {
398  int forkchar;
399 
400  forkchar = forkname_chars(&name[pos + 1], fork);
401  if (forkchar <= 0)
402  return false;
403  pos += forkchar + 1;
404  }
405 
406  /* Check for a segment number. */
407  if (name[pos] == '.')
408  {
409  int segchar;
410 
411  for (segchar = 1; isdigit((unsigned char) name[pos + segchar]); ++segchar)
412  ;
413  if (segchar <= 1)
414  return false;
415  pos += segchar;
416  }
417 
418  /* Now we should be at the end. */
419  if (name[pos] != '\0')
420  return false;
421  return true;
422 }
const char * name
Definition: encode.c:571
int forkname_chars(const char *str, ForkNumber *fork)
Definition: relpath.c:81
@ MAIN_FORKNUM
Definition: relpath.h:50
#define OIDCHARS
Definition: relpath.h:37

References forkname_chars(), MAIN_FORKNUM, name, and OIDCHARS.

Referenced by ResetUnloggedRelationsInDbspaceDir(), and sendDir().

◆ ResetUnloggedRelations()

void ResetUnloggedRelations ( int  op)

Definition at line 47 of file reinit.c.

48 {
49  char temp_path[MAXPGPATH + 10 + sizeof(TABLESPACE_VERSION_DIRECTORY)];
50  DIR *spc_dir;
51  struct dirent *spc_de;
52  MemoryContext tmpctx,
53  oldctx;
54 
55  /* Log it. */
56  elog(DEBUG1, "resetting unlogged relations: cleanup %d init %d",
57  (op & UNLOGGED_RELATION_CLEANUP) != 0,
58  (op & UNLOGGED_RELATION_INIT) != 0);
59 
60  /*
61  * Just to be sure we don't leak any memory, let's create a temporary
62  * memory context for this operation.
63  */
65  "ResetUnloggedRelations",
67  oldctx = MemoryContextSwitchTo(tmpctx);
68 
69  /* Prepare to report progress resetting unlogged relations. */
71 
72  /*
73  * First process unlogged files in pg_default ($PGDATA/base)
74  */
76 
77  /*
78  * Cycle through directories for all non-default tablespaces.
79  */
80  spc_dir = AllocateDir("pg_tblspc");
81 
82  while ((spc_de = ReadDir(spc_dir, "pg_tblspc")) != NULL)
83  {
84  if (strcmp(spc_de->d_name, ".") == 0 ||
85  strcmp(spc_de->d_name, "..") == 0)
86  continue;
87 
88  snprintf(temp_path, sizeof(temp_path), "pg_tblspc/%s/%s",
91  }
92 
93  FreeDir(spc_dir);
94 
95  /*
96  * Restore memory context.
97  */
98  MemoryContextSwitchTo(oldctx);
99  MemoryContextDelete(tmpctx);
100 }
void begin_startup_progress_phase(void)
Definition: startup.c:352
#define DEBUG1
Definition: elog.h:30
struct dirent * ReadDir(DIR *dir, const char *dirname)
Definition: fd.c:2806
int FreeDir(DIR *dir)
Definition: fd.c:2858
DIR * AllocateDir(const char *dirname)
Definition: fd.c:2740
MemoryContext CurrentMemoryContext
Definition: mcxt.c:135
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:403
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:153
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
#define MAXPGPATH
#define snprintf
Definition: port.h:238
static void ResetUnloggedRelationsInTablespaceDir(const char *tsdirname, int op)
Definition: reinit.c:106
#define UNLOGGED_RELATION_INIT
Definition: reinit.h:27
#define UNLOGGED_RELATION_CLEANUP
Definition: reinit.h:26
#define TABLESPACE_VERSION_DIRECTORY
Definition: relpath.h:33
Definition: dirent.c:26
Definition: dirent.h:10
char d_name[MAX_PATH]
Definition: dirent.h:15

References AllocateDir(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, begin_startup_progress_phase(), CurrentMemoryContext, dirent::d_name, DEBUG1, elog(), FreeDir(), MAXPGPATH, MemoryContextDelete(), MemoryContextSwitchTo(), ReadDir(), ResetUnloggedRelationsInTablespaceDir(), snprintf, TABLESPACE_VERSION_DIRECTORY, UNLOGGED_RELATION_CLEANUP, and UNLOGGED_RELATION_INIT.

Referenced by StartupXLOG().