PostgreSQL Source Code  git master
filemap.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * filemap.h
4  *
5  * Copyright (c) 2013-2020, PostgreSQL Global Development Group
6  *-------------------------------------------------------------------------
7  */
8 #ifndef FILEMAP_H
9 #define FILEMAP_H
10 
11 #include "datapagemap.h"
12 #include "storage/block.h"
13 #include "storage/relfilenode.h"
14 
15 /*
16  * For every file found in the local or remote system, we have a file entry
17  * which says what we are going to do with the file. For relation files,
18  * there is also a page map, marking pages in the file that were changed
19  * locally.
20  *
21  * The enum values are sorted in the order we want actions to be processed.
22  */
23 typedef enum
24 {
25  FILE_ACTION_CREATE, /* create local directory or symbolic link */
26  FILE_ACTION_COPY, /* copy whole file, overwriting if exists */
27  FILE_ACTION_COPY_TAIL, /* copy tail from 'oldsize' to 'newsize' */
28  FILE_ACTION_NONE, /* no action (we might still copy modified
29  * blocks based on the parsed WAL) */
30  FILE_ACTION_TRUNCATE, /* truncate local file to 'newsize' bytes */
31  FILE_ACTION_REMOVE /* remove local file / directory / symlink */
33 
34 typedef enum
35 {
39 } file_type_t;
40 
41 typedef struct file_entry_t
42 {
43  char *path;
45 
47 
48  /* for a regular file */
49  size_t oldsize;
50  size_t newsize;
51  bool isrelfile; /* is it a relation data file? */
52 
54 
55  /* for a symlink */
56  char *link_target;
57 
58  struct file_entry_t *next;
59 } file_entry_t;
60 
61 typedef struct filemap_t
62 {
63  /*
64  * New entries are accumulated to a linked list, in process_source_file
65  * and process_target_file.
66  */
69  int nlist; /* number of entries currently in list */
70 
71  /*
72  * After processing all the remote files, the entries in the linked list
73  * are moved to this array. After processing local files, too, all the
74  * local entries are added to the array by filemap_finalize, and sorted in
75  * the final order. After filemap_finalize, all the entries are in the
76  * array, and the linked list is empty.
77  */
79  int narray; /* current length of array */
80 
81  /*
82  * Summary information. total_size is the total size of the source
83  * cluster, and fetch_size is the number of bytes that needs to be copied.
84  */
85  uint64 total_size;
86  uint64 fetch_size;
87 } filemap_t;
88 
89 extern filemap_t *filemap;
90 
91 extern void filemap_create(void);
92 extern void calculate_totals(void);
93 extern void print_filemap(void);
94 
95 /* Functions for populating the filemap */
96 extern void process_source_file(const char *path, file_type_t type,
97  size_t newsize, const char *link_target);
98 extern void process_target_file(const char *path, file_type_t type,
99  size_t newsize, const char *link_target);
100 extern void process_block_change(ForkNumber forknum, RelFileNode rnode,
101  BlockNumber blkno);
102 extern void filemap_finalize(void);
103 
104 #endif /* FILEMAP_H */
void calculate_totals(void)
Definition: filemap.c:633
filemap_t * filemap
Definition: filemap.c:23
file_entry_t * first
Definition: filemap.h:67
file_entry_t ** array
Definition: filemap.h:78
void filemap_finalize(void)
Definition: filemap.c:597
size_t newsize
Definition: filemap.h:50
void filemap_create(void)
Definition: filemap.c:135
uint32 BlockNumber
Definition: block.h:31
datapagemap_t pagemap
Definition: filemap.h:53
int narray
Definition: filemap.h:79
uint64 fetch_size
Definition: filemap.h:86
file_type_t type
Definition: filemap.h:44
bool isrelfile
Definition: filemap.h:51
void process_target_file(const char *path, file_type_t type, size_t newsize, const char *link_target)
Definition: filemap.c:348
int nlist
Definition: filemap.h:69
file_action_t action
Definition: filemap.h:46
char * link_target
Definition: filemap.h:56
struct file_entry_t * next
Definition: filemap.h:58
size_t oldsize
Definition: filemap.h:49
uint64 total_size
Definition: filemap.h:85
void process_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno)
Definition: filemap.c:439
ForkNumber
Definition: relpath.h:40
void print_filemap(void)
Definition: filemap.c:675
file_action_t
Definition: filemap.h:23
char * path
Definition: filemap.h:43
struct filemap_t filemap_t
file_entry_t * last
Definition: filemap.h:68
void process_source_file(const char *path, file_type_t type, size_t newsize, const char *link_target)
Definition: filemap.c:157
Definition: filemap.h:41
struct file_entry_t file_entry_t
file_type_t
Definition: filemap.h:34