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, RelFileNumber *relnumber, ForkNumber *fork, unsigned *segno)
 

Macro Definition Documentation

◆ UNLOGGED_RELATION_CLEANUP

#define UNLOGGED_RELATION_CLEANUP   0x0001

Definition at line 27 of file reinit.h.

◆ UNLOGGED_RELATION_INIT

#define UNLOGGED_RELATION_INIT   0x0002

Definition at line 28 of file reinit.h.

Function Documentation

◆ parse_filename_for_nontemp_relation()

bool parse_filename_for_nontemp_relation ( const char *  name,
RelFileNumber relnumber,
ForkNumber fork,
unsigned *  segno 
)

Definition at line 380 of file reinit.c.

382 {
383  unsigned long n,
384  s;
385  ForkNumber f;
386  char *endp;
387 
388  *relnumber = InvalidRelFileNumber;
389  *fork = InvalidForkNumber;
390  *segno = 0;
391 
392  /*
393  * Relation filenames should begin with a digit that is not a zero. By
394  * rejecting cases involving leading zeroes, the caller can assume that
395  * there's only one possible string of characters that could have produced
396  * any given value for *relnumber.
397  *
398  * (To be clear, we don't expect files with names like 0017.3 to exist at
399  * all -- but if 0017.3 does exist, it's a non-relation file, not part of
400  * the main fork for relfilenode 17.)
401  */
402  if (name[0] < '1' || name[0] > '9')
403  return false;
404 
405  /*
406  * Parse the leading digit string. If the value is out of range, we
407  * conclude that this isn't a relation file at all.
408  */
409  errno = 0;
410  n = strtoul(name, &endp, 10);
411  if (errno || name == endp || n <= 0 || n > PG_UINT32_MAX)
412  return false;
413  name = endp;
414 
415  /* Check for a fork name. */
416  if (*name != '_')
417  f = MAIN_FORKNUM;
418  else
419  {
420  int forkchar;
421 
422  forkchar = forkname_chars(name + 1, &f);
423  if (forkchar <= 0)
424  return false;
425  name += forkchar + 1;
426  }
427 
428  /* Check for a segment number. */
429  if (*name != '.')
430  s = 0;
431  else
432  {
433  /* Reject leading zeroes, just like we do for RelFileNumber. */
434  if (name[1] < '1' || name[1] > '9')
435  return false;
436 
437  errno = 0;
438  s = strtoul(name + 1, &endp, 10);
439  if (errno || name + 1 == endp || s <= 0 || s > PG_UINT32_MAX)
440  return false;
441  name = endp;
442  }
443 
444  /* Now we should be at the end. */
445  if (*name != '\0')
446  return false;
447 
448  /* Set out parameters and return. */
449  *relnumber = (RelFileNumber) n;
450  *fork = f;
451  *segno = (unsigned) s;
452  return true;
453 }
#define PG_UINT32_MAX
Definition: c.h:544
int forkname_chars(const char *str, ForkNumber *fork)
Definition: relpath.c:81
Oid RelFileNumber
Definition: relpath.h:25
ForkNumber
Definition: relpath.h:56
@ MAIN_FORKNUM
Definition: relpath.h:58
@ InvalidForkNumber
Definition: relpath.h:57
#define InvalidRelFileNumber
Definition: relpath.h:26
const char * name

References forkname_chars(), InvalidForkNumber, InvalidRelFileNumber, MAIN_FORKNUM, name, and PG_UINT32_MAX.

Referenced by ResetUnloggedRelationsInDbspaceDir(), and sendDir().

◆ ResetUnloggedRelations()

void ResetUnloggedRelations ( int  op)

Definition at line 47 of file reinit.c.

48 {
49  char temp_path[MAXPGPATH + sizeof(PG_TBLSPC_DIR) + 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_DIR);
81 
82  while ((spc_de = ReadDir(spc_dir, PG_TBLSPC_DIR)) != 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), "%s/%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:343
#define DEBUG1
Definition: elog.h:30
#define elog(elevel,...)
Definition: elog.h:225
struct dirent * ReadDir(DIR *dir, const char *dirname)
Definition: fd.c:2931
int FreeDir(DIR *dir)
Definition: fd.c:2983
DIR * AllocateDir(const char *dirname)
Definition: fd.c:2865
MemoryContext CurrentMemoryContext
Definition: mcxt.c:143
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:454
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:160
#define MAXPGPATH
#define snprintf
Definition: port.h:238
MemoryContextSwitchTo(old_ctx)
static void ResetUnloggedRelationsInTablespaceDir(const char *tsdirname, int op)
Definition: reinit.c:106
#define UNLOGGED_RELATION_INIT
Definition: reinit.h:28
#define UNLOGGED_RELATION_CLEANUP
Definition: reinit.h:27
#define PG_TBLSPC_DIR
Definition: relpath.h:41
#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(), PG_TBLSPC_DIR, ReadDir(), ResetUnloggedRelationsInTablespaceDir(), snprintf, TABLESPACE_VERSION_DIRECTORY, UNLOGGED_RELATION_CLEANUP, and UNLOGGED_RELATION_INIT.

Referenced by StartupXLOG().