PostgreSQL Source Code  git master
filemap.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * filemap.c
4  * A data structure for keeping track of files that have changed.
5  *
6  * Copyright (c) 2013-2018, PostgreSQL Global Development Group
7  *
8  *-------------------------------------------------------------------------
9  */
10 
11 #include "postgres_fe.h"
12 
13 #include <sys/stat.h>
14 #include <unistd.h>
15 
16 #include "datapagemap.h"
17 #include "filemap.h"
18 #include "logging.h"
19 #include "pg_rewind.h"
20 
21 #include "common/string.h"
22 #include "catalog/pg_tablespace_d.h"
23 #include "storage/fd.h"
24 
26 
27 static bool isRelDataFile(const char *path);
28 static char *datasegpath(RelFileNode rnode, ForkNumber forknum,
29  BlockNumber segno);
30 static int path_cmp(const void *a, const void *b);
31 static int final_filemap_cmp(const void *a, const void *b);
32 static void filemap_list_to_array(filemap_t *map);
33 static bool check_file_excluded(const char *path, const char *type);
34 
35 /*
36  * The contents of these directories are removed or recreated during server
37  * start so they are not included in data processed by pg_rewind.
38  *
39  * Note: those lists should be kept in sync with what basebackup.c provides.
40  * Some of the values, contrary to what basebackup.c uses, are hardcoded as
41  * they are defined in backend-only headers. So this list is maintained
42  * with a best effort in mind.
43  */
44 static const char *excludeDirContents[] =
45 {
46  /*
47  * Skip temporary statistics files. PG_STAT_TMP_DIR must be skipped even
48  * when stats_temp_directory is set because PGSS_TEXT_FILE is always
49  * created there.
50  */
51  "pg_stat_tmp", /* defined as PG_STAT_TMP_DIR */
52 
53  /*
54  * It is generally not useful to backup the contents of this directory
55  * even if the intention is to restore to another master. See backup.sgml
56  * for a more detailed description.
57  */
58  "pg_replslot",
59 
60  /* Contents removed on startup, see dsm_cleanup_for_mmap(). */
61  "pg_dynshmem", /* defined as PG_DYNSHMEM_DIR */
62 
63  /* Contents removed on startup, see AsyncShmemInit(). */
64  "pg_notify",
65 
66  /*
67  * Old contents are loaded for possible debugging but are not required for
68  * normal operation, see OldSerXidInit().
69  */
70  "pg_serial",
71 
72  /* Contents removed on startup, see DeleteAllExportedSnapshotFiles(). */
73  "pg_snapshots",
74 
75  /* Contents zeroed on startup, see StartupSUBTRANS(). */
76  "pg_subtrans",
77 
78  /* end of list */
79  NULL
80 };
81 
82 /*
83  * List of files excluded from filemap processing.
84  */
85 static const char *excludeFiles[] =
86 {
87  /* Skip auto conf temporary file. */
88  "postgresql.auto.conf.tmp", /* defined as PG_AUTOCONF_FILENAME */
89 
90  /* Skip current log file temporary file */
91  "current_logfiles.tmp", /* defined as LOG_METAINFO_DATAFILE_TMP */
92 
93  /* Skip relation cache because it is rebuilt on startup */
94  "pg_internal.init", /* defined as RELCACHE_INIT_FILENAME */
95 
96  /*
97  * If there's a backup_label or tablespace_map file, it belongs to a
98  * backup started by the user with pg_start_backup(). It is *not* correct
99  * for this backup. Our backup_label is written later on separately.
100  */
101  "backup_label", /* defined as BACKUP_LABEL_FILE */
102  "tablespace_map", /* defined as TABLESPACE_MAP */
103 
104  "postmaster.pid",
105  "postmaster.opts",
106 
107  /* end of list */
108  NULL
109 };
110 
111 /*
112  * Create a new file map (stored in the global pointer "filemap").
113  */
114 void
116 {
117  filemap_t *map;
118 
119  map = pg_malloc(sizeof(filemap_t));
120  map->first = map->last = NULL;
121  map->nlist = 0;
122  map->array = NULL;
123  map->narray = 0;
124 
125  Assert(filemap == NULL);
126  filemap = map;
127 }
128 
129 /*
130  * Callback for processing source file list.
131  *
132  * This is called once for every file in the source server. We decide what
133  * action needs to be taken for the file, depending on whether the file
134  * exists in the target and whether the size matches.
135  */
136 void
137 process_source_file(const char *path, file_type_t type, size_t newsize,
138  const char *link_target)
139 {
140  bool exists;
141  char localpath[MAXPGPATH];
142  struct stat statbuf;
143  filemap_t *map = filemap;
145  size_t oldsize = 0;
146  file_entry_t *entry;
147 
148  Assert(map->array == NULL);
149 
150  /* ignore any path matching the exclusion filters */
151  if (check_file_excluded(path, "source"))
152  return;
153 
154  /*
155  * Pretend that pg_wal is a directory, even if it's really a symlink. We
156  * don't want to mess with the symlink itself, nor complain if it's a
157  * symlink in source but not in target or vice versa.
158  */
159  if (strcmp(path, "pg_wal") == 0 && type == FILE_TYPE_SYMLINK)
160  type = FILE_TYPE_DIRECTORY;
161 
162  /*
163  * Skip temporary files, .../pgsql_tmp/... and .../pgsql_tmp.* in source.
164  * This has the effect that all temporary files in the destination will be
165  * removed.
166  */
167  if (strstr(path, "/" PG_TEMP_FILE_PREFIX) != NULL)
168  return;
169  if (strstr(path, "/" PG_TEMP_FILES_DIR "/") != NULL)
170  return;
171 
172  /*
173  * sanity check: a filename that looks like a data file better be a
174  * regular file
175  */
176  if (type != FILE_TYPE_REGULAR && isRelDataFile(path))
177  pg_fatal("data file \"%s\" in source is not a regular file\n", path);
178 
179  snprintf(localpath, sizeof(localpath), "%s/%s", datadir_target, path);
180 
181  /* Does the corresponding file exist in the target data dir? */
182  if (lstat(localpath, &statbuf) < 0)
183  {
184  if (errno != ENOENT)
185  pg_fatal("could not stat file \"%s\": %s\n",
186  localpath, strerror(errno));
187 
188  exists = false;
189  }
190  else
191  exists = true;
192 
193  switch (type)
194  {
195  case FILE_TYPE_DIRECTORY:
196  if (exists && !S_ISDIR(statbuf.st_mode) && strcmp(path, "pg_wal") != 0)
197  {
198  /* it's a directory in source, but not in target. Strange.. */
199  pg_fatal("\"%s\" is not a directory\n", localpath);
200  }
201 
202  if (!exists)
203  action = FILE_ACTION_CREATE;
204  else
205  action = FILE_ACTION_NONE;
206  oldsize = 0;
207  break;
208 
209  case FILE_TYPE_SYMLINK:
210  if (exists &&
211 #ifndef WIN32
212  !S_ISLNK(statbuf.st_mode)
213 #else
214  !pgwin32_is_junction(localpath)
215 #endif
216  )
217  {
218  /*
219  * It's a symbolic link in source, but not in target.
220  * Strange..
221  */
222  pg_fatal("\"%s\" is not a symbolic link\n", localpath);
223  }
224 
225  if (!exists)
226  action = FILE_ACTION_CREATE;
227  else
228  action = FILE_ACTION_NONE;
229  oldsize = 0;
230  break;
231 
232  case FILE_TYPE_REGULAR:
233  if (exists && !S_ISREG(statbuf.st_mode))
234  pg_fatal("\"%s\" is not a regular file\n", localpath);
235 
236  if (!exists || !isRelDataFile(path))
237  {
238  /*
239  * File exists in source, but not in target. Or it's a
240  * non-data file that we have no special processing for. Copy
241  * it in toto.
242  *
243  * An exception: PG_VERSIONs should be identical, but avoid
244  * overwriting it for paranoia.
245  */
246  if (pg_str_endswith(path, "PG_VERSION"))
247  {
248  action = FILE_ACTION_NONE;
249  oldsize = statbuf.st_size;
250  }
251  else
252  {
253  action = FILE_ACTION_COPY;
254  oldsize = 0;
255  }
256  }
257  else
258  {
259  /*
260  * It's a data file that exists in both.
261  *
262  * If it's larger in target, we can truncate it. There will
263  * also be a WAL record of the truncation in the source
264  * system, so WAL replay would eventually truncate the target
265  * too, but we might as well do it now.
266  *
267  * If it's smaller in the target, it means that it has been
268  * truncated in the target, or enlarged in the source, or
269  * both. If it was truncated in the target, we need to copy
270  * the missing tail from the source system. If it was enlarged
271  * in the source system, there will be WAL records in the
272  * source system for the new blocks, so we wouldn't need to
273  * copy them here. But we don't know which scenario we're
274  * dealing with, and there's no harm in copying the missing
275  * blocks now, so do it now.
276  *
277  * If it's the same size, do nothing here. Any blocks modified
278  * in the target will be copied based on parsing the target
279  * system's WAL, and any blocks modified in the source will be
280  * updated after rewinding, when the source system's WAL is
281  * replayed.
282  */
283  oldsize = statbuf.st_size;
284  if (oldsize < newsize)
285  action = FILE_ACTION_COPY_TAIL;
286  else if (oldsize > newsize)
287  action = FILE_ACTION_TRUNCATE;
288  else
289  action = FILE_ACTION_NONE;
290  }
291  break;
292  }
293 
294  /* Create a new entry for this file */
295  entry = pg_malloc(sizeof(file_entry_t));
296  entry->path = pg_strdup(path);
297  entry->type = type;
298  entry->action = action;
299  entry->oldsize = oldsize;
300  entry->newsize = newsize;
301  entry->link_target = link_target ? pg_strdup(link_target) : NULL;
302  entry->next = NULL;
303  entry->pagemap.bitmap = NULL;
304  entry->pagemap.bitmapsize = 0;
305  entry->isrelfile = isRelDataFile(path);
306 
307  if (map->last)
308  {
309  map->last->next = entry;
310  map->last = entry;
311  }
312  else
313  map->first = map->last = entry;
314  map->nlist++;
315 }
316 
317 /*
318  * Callback for processing target file list.
319  *
320  * All source files must be already processed before calling this. This only
321  * marks target data directory's files that didn't exist in the source for
322  * deletion.
323  */
324 void
325 process_target_file(const char *path, file_type_t type, size_t oldsize,
326  const char *link_target)
327 {
328  bool exists;
329  char localpath[MAXPGPATH];
330  struct stat statbuf;
331  file_entry_t key;
332  file_entry_t *key_ptr;
333  filemap_t *map = filemap;
334  file_entry_t *entry;
335 
336  /*
337  * Ignore any path matching the exclusion filters. This is not actually
338  * mandatory for target files, but this does not hurt and let's be
339  * consistent with the source processing.
340  */
341  if (check_file_excluded(path, "target"))
342  return;
343 
344  snprintf(localpath, sizeof(localpath), "%s/%s", datadir_target, path);
345  if (lstat(localpath, &statbuf) < 0)
346  {
347  if (errno != ENOENT)
348  pg_fatal("could not stat file \"%s\": %s\n",
349  localpath, strerror(errno));
350 
351  exists = false;
352  }
353 
354  if (map->array == NULL)
355  {
356  /* on first call, initialize lookup array */
357  if (map->nlist == 0)
358  {
359  /* should not happen */
360  pg_fatal("source file list is empty\n");
361  }
362 
364 
365  Assert(map->array != NULL);
366 
367  qsort(map->array, map->narray, sizeof(file_entry_t *), path_cmp);
368  }
369 
370  /*
371  * Like in process_source_file, pretend that xlog is always a directory.
372  */
373  if (strcmp(path, "pg_wal") == 0 && type == FILE_TYPE_SYMLINK)
374  type = FILE_TYPE_DIRECTORY;
375 
376  key.path = (char *) path;
377  key_ptr = &key;
378  exists = (bsearch(&key_ptr, map->array, map->narray, sizeof(file_entry_t *),
379  path_cmp) != NULL);
380 
381  /* Remove any file or folder that doesn't exist in the source system. */
382  if (!exists)
383  {
384  entry = pg_malloc(sizeof(file_entry_t));
385  entry->path = pg_strdup(path);
386  entry->type = type;
387  entry->action = FILE_ACTION_REMOVE;
388  entry->oldsize = oldsize;
389  entry->newsize = 0;
390  entry->link_target = link_target ? pg_strdup(link_target) : NULL;
391  entry->next = NULL;
392  entry->pagemap.bitmap = NULL;
393  entry->pagemap.bitmapsize = 0;
394  entry->isrelfile = isRelDataFile(path);
395 
396  if (map->last == NULL)
397  map->first = entry;
398  else
399  map->last->next = entry;
400  map->last = entry;
401  map->nlist++;
402  }
403  else
404  {
405  /*
406  * We already handled all files that exist in the source system in
407  * process_source_file().
408  */
409  }
410 }
411 
412 /*
413  * This callback gets called while we read the WAL in the target, for every
414  * block that have changed in the target system. It makes note of all the
415  * changed blocks in the pagemap of the file.
416  */
417 void
419 {
420  char *path;
421  file_entry_t key;
422  file_entry_t *key_ptr;
423  file_entry_t *entry;
424  BlockNumber blkno_inseg;
425  int segno;
426  filemap_t *map = filemap;
427  file_entry_t **e;
428 
429  Assert(map->array);
430 
431  segno = blkno / RELSEG_SIZE;
432  blkno_inseg = blkno % RELSEG_SIZE;
433 
434  path = datasegpath(rnode, forknum, segno);
435 
436  key.path = (char *) path;
437  key_ptr = &key;
438 
439  e = bsearch(&key_ptr, map->array, map->narray, sizeof(file_entry_t *),
440  path_cmp);
441  if (e)
442  entry = *e;
443  else
444  entry = NULL;
445  pfree(path);
446 
447  if (entry)
448  {
449  Assert(entry->isrelfile);
450 
451  switch (entry->action)
452  {
453  case FILE_ACTION_NONE:
455  /* skip if we're truncating away the modified block anyway */
456  if ((blkno_inseg + 1) * BLCKSZ <= entry->newsize)
457  datapagemap_add(&entry->pagemap, blkno_inseg);
458  break;
459 
461 
462  /*
463  * skip the modified block if it is part of the "tail" that
464  * we're copying anyway.
465  */
466  if ((blkno_inseg + 1) * BLCKSZ <= entry->oldsize)
467  datapagemap_add(&entry->pagemap, blkno_inseg);
468  break;
469 
470  case FILE_ACTION_COPY:
471  case FILE_ACTION_REMOVE:
472  break;
473 
474  case FILE_ACTION_CREATE:
475  pg_fatal("unexpected page modification for directory or symbolic link \"%s\"\n", entry->path);
476  }
477  }
478  else
479  {
480  /*
481  * If we don't have any record of this file in the file map, it means
482  * that it's a relation that doesn't exist in the source system, and
483  * it was subsequently removed in the target system, too. We can
484  * safely ignore it.
485  */
486  }
487 }
488 
489 /*
490  * Is this the path of file that pg_rewind can skip copying?
491  */
492 static bool
493 check_file_excluded(const char *path, const char *type)
494 {
495  char localpath[MAXPGPATH];
496  int excludeIdx;
497  const char *filename;
498 
499  /* check individual files... */
500  for (excludeIdx = 0; excludeFiles[excludeIdx] != NULL; excludeIdx++)
501  {
502  filename = last_dir_separator(path);
503  if (filename == NULL)
504  filename = path;
505  else
506  filename++;
507  if (strcmp(filename, excludeFiles[excludeIdx]) == 0)
508  {
509  pg_log(PG_DEBUG, "entry \"%s\" excluded from %s file list\n",
510  path, type);
511  return true;
512  }
513  }
514 
515  /*
516  * ... And check some directories. Note that this includes any contents
517  * within the directories themselves.
518  */
519  for (excludeIdx = 0; excludeDirContents[excludeIdx] != NULL; excludeIdx++)
520  {
521  snprintf(localpath, sizeof(localpath), "%s/",
522  excludeDirContents[excludeIdx]);
523  if (strstr(path, localpath) == path)
524  {
525  pg_log(PG_DEBUG, "entry \"%s\" excluded from %s file list\n",
526  path, type);
527  return true;
528  }
529  }
530 
531  return false;
532 }
533 
534 /*
535  * Convert the linked list of entries in map->first/last to the array,
536  * map->array.
537  */
538 static void
540 {
541  int narray;
542  file_entry_t *entry,
543  *next;
544 
545  map->array = (file_entry_t **)
546  pg_realloc(map->array,
547  (map->nlist + map->narray) * sizeof(file_entry_t *));
548 
549  narray = map->narray;
550  for (entry = map->first; entry != NULL; entry = next)
551  {
552  map->array[narray++] = entry;
553  next = entry->next;
554  entry->next = NULL;
555  }
556  Assert(narray == map->nlist + map->narray);
557  map->narray = narray;
558  map->nlist = 0;
559  map->first = map->last = NULL;
560 }
561 
562 void
564 {
565  filemap_t *map = filemap;
566 
568  qsort(map->array, map->narray, sizeof(file_entry_t *),
570 }
571 
572 static const char *
574 {
575  switch (action)
576  {
577  case FILE_ACTION_NONE:
578  return "NONE";
579  case FILE_ACTION_COPY:
580  return "COPY";
582  return "TRUNCATE";
584  return "COPY_TAIL";
585  case FILE_ACTION_CREATE:
586  return "CREATE";
587  case FILE_ACTION_REMOVE:
588  return "REMOVE";
589 
590  default:
591  return "unknown";
592  }
593 }
594 
595 /*
596  * Calculate the totals needed for progress reports.
597  */
598 void
600 {
601  file_entry_t *entry;
602  int i;
603  filemap_t *map = filemap;
604 
605  map->total_size = 0;
606  map->fetch_size = 0;
607 
608  for (i = 0; i < map->narray; i++)
609  {
610  entry = map->array[i];
611 
612  if (entry->type != FILE_TYPE_REGULAR)
613  continue;
614 
615  map->total_size += entry->newsize;
616 
617  if (entry->action == FILE_ACTION_COPY)
618  {
619  map->fetch_size += entry->newsize;
620  continue;
621  }
622 
623  if (entry->action == FILE_ACTION_COPY_TAIL)
624  map->fetch_size += (entry->newsize - entry->oldsize);
625 
626  if (entry->pagemap.bitmapsize > 0)
627  {
629  BlockNumber blk;
630 
631  iter = datapagemap_iterate(&entry->pagemap);
632  while (datapagemap_next(iter, &blk))
633  map->fetch_size += BLCKSZ;
634 
635  pg_free(iter);
636  }
637  }
638 }
639 
640 void
642 {
643  filemap_t *map = filemap;
644  file_entry_t *entry;
645  int i;
646 
647  for (i = 0; i < map->narray; i++)
648  {
649  entry = map->array[i];
650  if (entry->action != FILE_ACTION_NONE ||
651  entry->pagemap.bitmapsize > 0)
652  {
654  /*------
655  translator: first %s is a file path, second is a keyword such as COPY */
656  "%s (%s)\n", entry->path,
657  action_to_str(entry->action));
658 
659  if (entry->pagemap.bitmapsize > 0)
660  datapagemap_print(&entry->pagemap);
661  }
662  }
663  fflush(stdout);
664 }
665 
666 /*
667  * Does it look like a relation data file?
668  *
669  * For our purposes, only files belonging to the main fork are considered
670  * relation files. Other forks are always copied in toto, because we cannot
671  * reliably track changes to them, because WAL only contains block references
672  * for the main fork.
673  */
674 static bool
675 isRelDataFile(const char *path)
676 {
677  RelFileNode rnode;
678  unsigned int segNo;
679  int nmatch;
680  bool matched;
681 
682  /*----
683  * Relation data files can be in one of the following directories:
684  *
685  * global/
686  * shared relations
687  *
688  * base/<db oid>/
689  * regular relations, default tablespace
690  *
691  * pg_tblspc/<tblspc oid>/<tblspc version>/
692  * within a non-default tablespace (the name of the directory
693  * depends on version)
694  *
695  * And the relation data files themselves have a filename like:
696  *
697  * <oid>.<segment number>
698  *
699  *----
700  */
701  rnode.spcNode = InvalidOid;
702  rnode.dbNode = InvalidOid;
703  rnode.relNode = InvalidOid;
704  segNo = 0;
705  matched = false;
706 
707  nmatch = sscanf(path, "global/%u.%u", &rnode.relNode, &segNo);
708  if (nmatch == 1 || nmatch == 2)
709  {
710  rnode.spcNode = GLOBALTABLESPACE_OID;
711  rnode.dbNode = 0;
712  matched = true;
713  }
714  else
715  {
716  nmatch = sscanf(path, "base/%u/%u.%u",
717  &rnode.dbNode, &rnode.relNode, &segNo);
718  if (nmatch == 2 || nmatch == 3)
719  {
720  rnode.spcNode = DEFAULTTABLESPACE_OID;
721  matched = true;
722  }
723  else
724  {
725  nmatch = sscanf(path, "pg_tblspc/%u/" TABLESPACE_VERSION_DIRECTORY "/%u/%u.%u",
726  &rnode.spcNode, &rnode.dbNode, &rnode.relNode,
727  &segNo);
728  if (nmatch == 3 || nmatch == 4)
729  matched = true;
730  }
731  }
732 
733  /*
734  * The sscanf tests above can match files that have extra characters at
735  * the end. To eliminate such cases, cross-check that GetRelationPath
736  * creates the exact same filename, when passed the RelFileNode
737  * information we extracted from the filename.
738  */
739  if (matched)
740  {
741  char *check_path = datasegpath(rnode, MAIN_FORKNUM, segNo);
742 
743  if (strcmp(check_path, path) != 0)
744  matched = false;
745 
746  pfree(check_path);
747  }
748 
749  return matched;
750 }
751 
752 /*
753  * A helper function to create the path of a relation file and segment.
754  *
755  * The returned path is palloc'd
756  */
757 static char *
759 {
760  char *path;
761  char *segpath;
762 
763  path = relpathperm(rnode, forknum);
764  if (segno > 0)
765  {
766  segpath = psprintf("%s.%u", path, segno);
767  pfree(path);
768  return segpath;
769  }
770  else
771  return path;
772 }
773 
774 static int
775 path_cmp(const void *a, const void *b)
776 {
777  file_entry_t *fa = *((file_entry_t **) a);
778  file_entry_t *fb = *((file_entry_t **) b);
779 
780  return strcmp(fa->path, fb->path);
781 }
782 
783 /*
784  * In the final stage, the filemap is sorted so that removals come last.
785  * From disk space usage point of view, it would be better to do removals
786  * first, but for now, safety first. If a whole directory is deleted, all
787  * files and subdirectories inside it need to removed first. On creation,
788  * parent directory needs to be created before files and directories inside
789  * it. To achieve that, the file_action_t enum is ordered so that we can
790  * just sort on that first. Furthermore, sort REMOVE entries in reverse
791  * path order, so that "foo/bar" subdirectory is removed before "foo".
792  */
793 static int
794 final_filemap_cmp(const void *a, const void *b)
795 {
796  file_entry_t *fa = *((file_entry_t **) a);
797  file_entry_t *fb = *((file_entry_t **) b);
798 
799  if (fa->action > fb->action)
800  return 1;
801  if (fa->action < fb->action)
802  return -1;
803 
804  if (fa->action == FILE_ACTION_REMOVE)
805  return -strcmp(fa->path, fb->path);
806  else
807  return strcmp(fa->path, fb->path);
808 }
void datapagemap_add(datapagemap_t *map, BlockNumber blkno)
Definition: datapagemap.c:32
void calculate_totals(void)
Definition: filemap.c:599
static int final_filemap_cmp(const void *a, const void *b)
Definition: filemap.c:794
char * datadir_target
Definition: pg_rewind.c:51
#define relpathperm(rnode, forknum)
Definition: relpath.h:83
static int fa(void)
Definition: preproc-init.c:85
static int32 next
Definition: blutils.c:211
file_entry_t * first
Definition: filemap.h:68
bool pg_str_endswith(const char *str, const char *end)
Definition: string.c:31
file_entry_t ** array
Definition: filemap.h:79
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void process_target_file(const char *path, file_type_t type, size_t oldsize, const char *link_target)
Definition: filemap.c:325
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
size_t newsize
Definition: filemap.h:51
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define PG_TEMP_FILE_PREFIX
Definition: fd.h:144
char * bitmap
Definition: datapagemap.h:18
uint32 BlockNumber
Definition: block.h:31
void pg_fatal(const char *fmt,...)
Definition: logging.c:83
void filemap_create(void)
Definition: filemap.c:115
static int fb(int x)
Definition: preproc-init.c:92
datapagemap_t pagemap
Definition: filemap.h:54
int narray
Definition: filemap.h:80
void filemap_finalize(void)
Definition: filemap.c:563
uint64 fetch_size
Definition: filemap.h:87
void process_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno)
Definition: filemap.c:418
file_type_t type
Definition: filemap.h:45
static char * datasegpath(RelFileNode rnode, ForkNumber forknum, BlockNumber segno)
Definition: filemap.c:758
bool isrelfile
Definition: filemap.h:52
void pfree(void *pointer)
Definition: mcxt.c:1031
int nlist
Definition: filemap.h:70
bool datapagemap_next(datapagemap_iterator_t *iter, BlockNumber *blkno)
Definition: datapagemap.c:87
#define MAXPGPATH
file_action_t action
Definition: filemap.h:47
char * link_target
Definition: filemap.h:57
#define TABLESPACE_VERSION_DIRECTORY
Definition: relpath.h:26
struct file_entry_t * next
Definition: filemap.h:59
filemap_t * filemap
Definition: filemap.c:25
static const char * action_to_str(file_action_t action)
Definition: filemap.c:573
size_t oldsize
Definition: filemap.h:50
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
uint64 total_size
Definition: filemap.h:86
void pg_log(eLogType type, const char *fmt,...)
Definition: logging.c:69
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
void print_filemap(void)
Definition: filemap.c:641
static const char * excludeFiles[]
Definition: filemap.c:85
ForkNumber
Definition: relpath.h:40
#define S_ISREG(m)
Definition: win32_port.h:310
#define stat(a, b)
Definition: win32_port.h:266
char * last_dir_separator(const char *filename)
Definition: path.c:138
void datapagemap_print(datapagemap_t *map)
Definition: datapagemap.c:117
int bitmapsize
Definition: datapagemap.h:19
#define InvalidOid
Definition: postgres_ext.h:36
#define PG_TEMP_FILES_DIR
Definition: fd.h:143
#define Assert(condition)
Definition: c.h:699
file_action_t
Definition: filemap.h:24
static bool isRelDataFile(const char *path)
Definition: filemap.c:675
datapagemap_iterator_t * datapagemap_iterate(datapagemap_t *map)
Definition: datapagemap.c:75
char * path
Definition: filemap.h:44
void pg_free(void *ptr)
Definition: fe_memutils.c:105
void process_source_file(const char *path, file_type_t type, size_t newsize, const char *link_target)
Definition: filemap.c:137
static void filemap_list_to_array(filemap_t *map)
Definition: filemap.c:539
#define S_ISDIR(m)
Definition: win32_port.h:307
#define lstat(path, sb)
Definition: win32_port.h:255
file_entry_t * last
Definition: filemap.h:69
static char * filename
Definition: pg_dumpall.c:87
e
Definition: preproc-init.c:82
int i
const char * strerror(int errnum)
Definition: strerror.c:19
Definition: filemap.h:42
static int path_cmp(const void *a, const void *b)
Definition: filemap.c:775
static bool check_file_excluded(const char *path, const char *type)
Definition: filemap.c:493
#define qsort(a, b, c, d)
Definition: port.h:421
file_type_t
Definition: filemap.h:35
static const char * excludeDirContents[]
Definition: filemap.c:44
bool pgwin32_is_junction(const char *path)