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 *oidchars, ForkNumber *fork)
 

Macro Definition Documentation

◆ UNLOGGED_RELATION_CLEANUP

#define UNLOGGED_RELATION_CLEANUP   0x0001

◆ UNLOGGED_RELATION_INIT

#define UNLOGGED_RELATION_INIT   0x0002

Function Documentation

◆ parse_filename_for_nontemp_relation()

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

Definition at line 374 of file reinit.c.

References forkname_chars(), MAIN_FORKNUM, and OIDCHARS.

Referenced by ResetUnloggedRelationsInDbspaceDir(), and sendDir().

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

◆ ResetUnloggedRelations()

void ResetUnloggedRelations ( int  op)

Definition at line 46 of file reinit.c.

References AllocateDir(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, 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().

47 {
48  char temp_path[MAXPGPATH + 10 + sizeof(TABLESPACE_VERSION_DIRECTORY)];
49  DIR *spc_dir;
50  struct dirent *spc_de;
51  MemoryContext tmpctx,
52  oldctx;
53 
54  /* Log it. */
55  elog(DEBUG1, "resetting unlogged relations: cleanup %d init %d",
56  (op & UNLOGGED_RELATION_CLEANUP) != 0,
57  (op & UNLOGGED_RELATION_INIT) != 0);
58 
59  /*
60  * Just to be sure we don't leak any memory, let's create a temporary
61  * memory context for this operation.
62  */
64  "ResetUnloggedRelations",
66  oldctx = MemoryContextSwitchTo(tmpctx);
67 
68  /*
69  * First process unlogged files in pg_default ($PGDATA/base)
70  */
72 
73  /*
74  * Cycle through directories for all non-default tablespaces.
75  */
76  spc_dir = AllocateDir("pg_tblspc");
77 
78  while ((spc_de = ReadDir(spc_dir, "pg_tblspc")) != NULL)
79  {
80  if (strcmp(spc_de->d_name, ".") == 0 ||
81  strcmp(spc_de->d_name, "..") == 0)
82  continue;
83 
84  snprintf(temp_path, sizeof(temp_path), "pg_tblspc/%s/%s",
87  }
88 
89  FreeDir(spc_dir);
90 
91  /*
92  * Restore memory context.
93  */
94  MemoryContextSwitchTo(oldctx);
95  MemoryContextDelete(tmpctx);
96 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:211
#define DEBUG1
Definition: elog.h:25
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
Definition: dirent.h:9
Definition: dirent.c:25
#define MAXPGPATH
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
#define TABLESPACE_VERSION_DIRECTORY
Definition: relpath.h:26
#define UNLOGGED_RELATION_INIT
Definition: reinit.h:26
DIR * AllocateDir(const char *dirname)
Definition: fd.c:2600
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
#define AllocSetContextCreate(parent, name, allocparams)
Definition: memutils.h:170
struct dirent * ReadDir(DIR *dir, const char *dirname)
Definition: fd.c:2666
#define UNLOGGED_RELATION_CLEANUP
Definition: reinit.h:25
static void ResetUnloggedRelationsInTablespaceDir(const char *tsdirname, int op)
Definition: reinit.c:102
char d_name[MAX_PATH]
Definition: dirent.h:14
#define elog
Definition: elog.h:219
int FreeDir(DIR *dir)
Definition: fd.c:2718