PostgreSQL Source Code  git master
filemap.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * filemap.h
4  *
5  * Copyright (c) 2013-2021, 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 /* these enum values are sorted in the order we want actions to be processed */
16 typedef enum
17 {
18  FILE_ACTION_UNDECIDED = 0, /* not decided yet */
19 
20  FILE_ACTION_CREATE, /* create local directory or symbolic link */
21  FILE_ACTION_COPY, /* copy whole file, overwriting if exists */
22  FILE_ACTION_COPY_TAIL, /* copy tail from 'source_size' to
23  * 'target_size' */
24  FILE_ACTION_NONE, /* no action (we might still copy modified
25  * blocks based on the parsed WAL) */
26  FILE_ACTION_TRUNCATE, /* truncate local file to 'newsize' bytes */
27  FILE_ACTION_REMOVE /* remove local file / directory / symlink */
29 
30 typedef enum
31 {
33 
37 } file_type_t;
38 
39 /*
40  * For every file found in the local or remote system, we have a file entry
41  * that contains information about the file on both systems. For relation
42  * files, there is also a page map that marks pages in the file that were
43  * changed in the target after the last common checkpoint.
44  *
45  * When gathering information, these are kept in a hash table, private to
46  * filemap.c. decide_file_actions() fills in the 'action' field, sorts all
47  * the entries, and returns them in an array, ready for executing the actions.
48  */
49 typedef struct file_entry_t
50 {
51  uint32 status; /* hash status */
52 
53  const char *path;
54  bool isrelfile; /* is it a relation data file? */
55 
56  /*
57  * Status of the file in the target.
58  */
61  size_t target_size; /* for a regular file */
62  char *target_link_target; /* for a symlink */
63 
64  /*
65  * Pages that were modified in the target and need to be replaced from the
66  * source.
67  */
69 
70  /*
71  * Status of the file in the source.
72  */
75  size_t source_size;
76  char *source_link_target; /* for a symlink */
77 
78  /*
79  * What will we do to the file?
80  */
82 } file_entry_t;
83 
84 /*
85  * This contains the final decisions on what to do with each file.
86  * 'entries' array contains an entry for each file, sorted in the order
87  * that their actions should executed.
88  */
89 typedef struct filemap_t
90 {
91  /* Summary information, filled by calculate_totals() */
92  uint64 total_size; /* total size of the source cluster */
93  uint64 fetch_size; /* number of bytes that needs to be copied */
94 
95  int nentries; /* size of 'entries' array */
97 } filemap_t;
98 
99 /* Functions for populating the filemap */
100 extern void filehash_init(void);
101 extern void process_source_file(const char *path, file_type_t type,
102  size_t size, const char *link_target);
103 extern void process_target_file(const char *path, file_type_t type,
104  size_t size, const char *link_target);
105 extern void process_target_wal_block_change(ForkNumber forknum,
106  RelFileNode rnode,
107  BlockNumber blkno);
108 
109 extern filemap_t *decide_file_actions(void);
110 extern void calculate_totals(filemap_t *filemap);
111 extern void print_filemap(filemap_t *filemap);
112 
113 #endif /* FILEMAP_H */
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:350
uint32 BlockNumber
Definition: block.h:31
void process_target_wal_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno)
Definition: filemap.c:292
uint64 fetch_size
Definition: filemap.h:93
size_t target_size
Definition: filemap.h:61
bool isrelfile
Definition: filemap.h:54
char * source_link_target
Definition: filemap.h:76
file_type_t target_type
Definition: filemap.h:60
filemap_t * decide_file_actions(void)
Definition: filemap.c:789
file_action_t action
Definition: filemap.h:81
bool target_exists
Definition: filemap.h:59
file_type_t source_type
Definition: filemap.h:74
size_t source_size
Definition: filemap.h:75
uint64 total_size
Definition: filemap.h:92
unsigned int uint32
Definition: c.h:441
const char * path
Definition: filemap.h:53
ForkNumber
Definition: relpath.h:40
datapagemap_t target_pages_to_overwrite
Definition: filemap.h:68
uint32 status
Definition: filemap.h:51
void process_target_file(const char *path, file_type_t type, size_t size, const char *link_target)
Definition: filemap.c:255
char * target_link_target
Definition: filemap.h:62
file_action_t
Definition: filemap.h:16
struct filemap_t filemap_t
int nentries
Definition: filemap.h:95
void print_filemap(filemap_t *filemap)
Definition: filemap.c:480
Definition: filemap.h:49
struct file_entry_t file_entry_t
void filehash_init(void)
Definition: filemap.c:169
bool source_exists
Definition: filemap.h:73
void calculate_totals(filemap_t *filemap)
Definition: filemap.c:439
file_type_t
Definition: filemap.h:30
void process_source_file(const char *path, file_type_t type, size_t size, const char *link_target)
Definition: filemap.c:219