PostgreSQL Source Code  git master
filemap.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * filemap.h
4  *
5  * Copyright (c) 2013-2024, 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/relfilelocator.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  */
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 */
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  RelFileLocator rlocator,
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 extern void keepwal_init(void);
114 extern void keepwal_add_entry(const char *path);
115 
116 #endif /* FILEMAP_H */
uint32 BlockNumber
Definition: block.h:31
unsigned int uint32
Definition: c.h:492
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:413
void filehash_init(void)
Definition: filemap.c:196
void process_source_file(const char *path, file_type_t type, size_t size, const char *link_target)
Definition: filemap.c:279
void print_filemap(filemap_t *filemap)
Definition: filemap.c:540
void keepwal_init(void)
Definition: filemap.c:242
void process_target_file(const char *path, file_type_t type, size_t size, const char *link_target)
Definition: filemap.c:315
void process_target_wal_block_change(ForkNumber forknum, RelFileLocator rlocator, BlockNumber blkno)
Definition: filemap.c:352
filemap_t * decide_file_actions(void)
Definition: filemap.c:861
void keepwal_add_entry(const char *path)
Definition: filemap.c:250
file_action_t
Definition: filemap.h:17
@ FILE_ACTION_REMOVE
Definition: filemap.h:27
@ FILE_ACTION_COPY
Definition: filemap.h:21
@ FILE_ACTION_NONE
Definition: filemap.h:24
@ FILE_ACTION_COPY_TAIL
Definition: filemap.h:22
@ FILE_ACTION_UNDECIDED
Definition: filemap.h:18
@ FILE_ACTION_TRUNCATE
Definition: filemap.h:26
@ FILE_ACTION_CREATE
Definition: filemap.h:20
struct file_entry_t file_entry_t
void calculate_totals(filemap_t *filemap)
Definition: filemap.c:499
file_type_t
Definition: filemap.h:31
@ FILE_TYPE_UNDEFINED
Definition: filemap.h:32
@ FILE_TYPE_REGULAR
Definition: filemap.h:34
@ FILE_TYPE_SYMLINK
Definition: filemap.h:36
@ FILE_TYPE_DIRECTORY
Definition: filemap.h:35
struct filemap_t filemap_t
ForkNumber
Definition: relpath.h:56
static pg_noinline void Size size
Definition: slab.c:607
Definition: filemap.h:50
datapagemap_t target_pages_to_overwrite
Definition: filemap.h:68
const char * path
Definition: filemap.h:53
size_t source_size
Definition: filemap.h:75
bool source_exists
Definition: filemap.h:73
bool target_exists
Definition: filemap.h:59
char * source_link_target
Definition: filemap.h:76
uint32 status
Definition: filemap.h:51
file_type_t source_type
Definition: filemap.h:74
char * target_link_target
Definition: filemap.h:62
size_t target_size
Definition: filemap.h:61
file_action_t action
Definition: filemap.h:81
file_type_t target_type
Definition: filemap.h:60
bool isrelfile
Definition: filemap.h:54
file_entry_t * entries[FLEXIBLE_ARRAY_MEMBER]
Definition: filemap.h:96
int nentries
Definition: filemap.h:95
uint64 total_size
Definition: filemap.h:92
uint64 fetch_size
Definition: filemap.h:93
const char * type