PostgreSQL Source Code
git master
filemap.h
Go to the documentation of this file.
1
/*-------------------------------------------------------------------------
2
*
3
* filemap.h
4
*
5
* Copyright (c) 2013-2025, 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
#include "
access/xlogdefs.h
"
15
16
/* these enum values are sorted in the order we want actions to be processed */
17
typedef
enum
18
{
19
FILE_ACTION_UNDECIDED
= 0,
/* not decided yet */
20
21
FILE_ACTION_CREATE
,
/* create local directory or symbolic link */
22
FILE_ACTION_COPY
,
/* copy whole file, overwriting if exists */
23
FILE_ACTION_COPY_TAIL
,
/* copy tail from 'source_size' to
24
* 'target_size' */
25
FILE_ACTION_NONE
,
/* no action (we might still copy modified
26
* blocks based on the parsed WAL) */
27
FILE_ACTION_TRUNCATE
,
/* truncate local file to 'newsize' bytes */
28
FILE_ACTION_REMOVE
,
/* remove local file / directory / symlink */
29
}
file_action_t
;
30
31
typedef
enum
32
{
33
FILE_TYPE_UNDEFINED
= 0,
34
35
FILE_TYPE_REGULAR
,
36
FILE_TYPE_DIRECTORY
,
37
FILE_TYPE_SYMLINK
,
38
}
file_type_t
;
39
40
typedef
enum
41
{
42
FILE_CONTENT_TYPE_OTHER
= 0,
43
FILE_CONTENT_TYPE_RELATION
,
44
FILE_CONTENT_TYPE_WAL
45
}
file_content_type_t
;
46
47
/*
48
* For every file found in the local or remote system, we have a file entry
49
* that contains information about the file on both systems. For relation
50
* files, there is also a page map that marks pages in the file that were
51
* changed in the target after the last common checkpoint.
52
*
53
* When gathering information, these are kept in a hash table, private to
54
* filemap.c. decide_file_actions() fills in the 'action' field, sorts all
55
* the entries, and returns them in an array, ready for executing the actions.
56
*/
57
typedef
struct
file_entry_t
58
{
59
uint32
status
;
/* hash status */
60
61
const
char
*
path
;
62
file_content_type_t
content_type
;
63
64
/*
65
* Status of the file in the target.
66
*/
67
bool
target_exists
;
68
file_type_t
target_type
;
69
size_t
target_size
;
/* for a regular file */
70
char
*
target_link_target
;
/* for a symlink */
71
72
/*
73
* Pages that were modified in the target and need to be replaced from the
74
* source.
75
*/
76
datapagemap_t
target_pages_to_overwrite
;
77
78
/*
79
* Status of the file in the source.
80
*/
81
bool
source_exists
;
82
file_type_t
source_type
;
83
size_t
source_size
;
84
char
*
source_link_target
;
/* for a symlink */
85
86
/*
87
* What will we do to the file?
88
*/
89
file_action_t
action
;
90
}
file_entry_t
;
91
92
/*
93
* This contains the final decisions on what to do with each file.
94
* 'entries' array contains an entry for each file, sorted in the order
95
* that their actions should executed.
96
*/
97
typedef
struct
filemap_t
98
{
99
/* Summary information, filled by calculate_totals() */
100
uint64
total_size
;
/* total size of the source cluster */
101
uint64
fetch_size
;
/* number of bytes that needs to be copied */
102
103
int
nentries
;
/* size of 'entries' array */
104
file_entry_t
*
entries
[
FLEXIBLE_ARRAY_MEMBER
];
105
}
filemap_t
;
106
107
/* Functions for populating the filemap */
108
extern
void
filehash_init
(
void
);
109
extern
void
process_source_file
(
const
char
*path,
file_type_t
type
,
110
size_t
size,
const
char
*link_target);
111
extern
void
process_target_file
(
const
char
*path,
file_type_t
type
,
112
size_t
size,
const
char
*link_target);
113
extern
void
process_target_wal_block_change
(
ForkNumber
forknum,
114
RelFileLocator
rlocator,
115
BlockNumber
blkno);
116
117
extern
filemap_t
*
decide_file_actions
(
XLogSegNo
last_common_segno);
118
extern
void
calculate_totals
(
filemap_t
*filemap);
119
extern
void
print_filemap
(
filemap_t
*filemap);
120
121
extern
void
keepwal_init
(
void
);
122
extern
void
keepwal_add_entry
(
const
char
*path);
123
124
#endif
/* FILEMAP_H */
block.h
BlockNumber
uint32 BlockNumber
Definition:
block.h:31
FLEXIBLE_ARRAY_MEMBER
#define FLEXIBLE_ARRAY_MEMBER
Definition:
c.h:475
uint64
uint64_t uint64
Definition:
c.h:544
uint32
uint32_t uint32
Definition:
c.h:543
datapagemap.h
filehash_init
void filehash_init(void)
Definition:
filemap.c:197
process_source_file
void process_source_file(const char *path, file_type_t type, size_t size, const char *link_target)
Definition:
filemap.c:280
print_filemap
void print_filemap(filemap_t *filemap)
Definition:
filemap.c:541
keepwal_init
void keepwal_init(void)
Definition:
filemap.c:243
process_target_file
void process_target_file(const char *path, file_type_t type, size_t size, const char *link_target)
Definition:
filemap.c:316
process_target_wal_block_change
void process_target_wal_block_change(ForkNumber forknum, RelFileLocator rlocator, BlockNumber blkno)
Definition:
filemap.c:353
file_content_type_t
file_content_type_t
Definition:
filemap.h:41
FILE_CONTENT_TYPE_OTHER
@ FILE_CONTENT_TYPE_OTHER
Definition:
filemap.h:42
FILE_CONTENT_TYPE_RELATION
@ FILE_CONTENT_TYPE_RELATION
Definition:
filemap.h:43
FILE_CONTENT_TYPE_WAL
@ FILE_CONTENT_TYPE_WAL
Definition:
filemap.h:44
keepwal_add_entry
void keepwal_add_entry(const char *path)
Definition:
filemap.c:251
file_action_t
file_action_t
Definition:
filemap.h:18
FILE_ACTION_REMOVE
@ FILE_ACTION_REMOVE
Definition:
filemap.h:28
FILE_ACTION_COPY
@ FILE_ACTION_COPY
Definition:
filemap.h:22
FILE_ACTION_NONE
@ FILE_ACTION_NONE
Definition:
filemap.h:25
FILE_ACTION_COPY_TAIL
@ FILE_ACTION_COPY_TAIL
Definition:
filemap.h:23
FILE_ACTION_UNDECIDED
@ FILE_ACTION_UNDECIDED
Definition:
filemap.h:19
FILE_ACTION_TRUNCATE
@ FILE_ACTION_TRUNCATE
Definition:
filemap.h:27
FILE_ACTION_CREATE
@ FILE_ACTION_CREATE
Definition:
filemap.h:21
file_entry_t
struct file_entry_t file_entry_t
calculate_totals
void calculate_totals(filemap_t *filemap)
Definition:
filemap.c:500
decide_file_actions
filemap_t * decide_file_actions(XLogSegNo last_common_segno)
Definition:
filemap.c:924
file_type_t
file_type_t
Definition:
filemap.h:32
FILE_TYPE_UNDEFINED
@ FILE_TYPE_UNDEFINED
Definition:
filemap.h:33
FILE_TYPE_REGULAR
@ FILE_TYPE_REGULAR
Definition:
filemap.h:35
FILE_TYPE_SYMLINK
@ FILE_TYPE_SYMLINK
Definition:
filemap.h:37
FILE_TYPE_DIRECTORY
@ FILE_TYPE_DIRECTORY
Definition:
filemap.h:36
filemap_t
struct filemap_t filemap_t
relfilelocator.h
ForkNumber
ForkNumber
Definition:
relpath.h:56
RelFileLocator
Definition:
relfilelocator.h:59
datapagemap
Definition:
datapagemap.h:15
file_entry_t
Definition:
filemap.h:58
file_entry_t::target_pages_to_overwrite
datapagemap_t target_pages_to_overwrite
Definition:
filemap.h:76
file_entry_t::path
const char * path
Definition:
filemap.h:61
file_entry_t::source_size
size_t source_size
Definition:
filemap.h:83
file_entry_t::source_exists
bool source_exists
Definition:
filemap.h:81
file_entry_t::target_exists
bool target_exists
Definition:
filemap.h:67
file_entry_t::source_link_target
char * source_link_target
Definition:
filemap.h:84
file_entry_t::status
uint32 status
Definition:
filemap.h:59
file_entry_t::content_type
file_content_type_t content_type
Definition:
filemap.h:62
file_entry_t::source_type
file_type_t source_type
Definition:
filemap.h:82
file_entry_t::target_link_target
char * target_link_target
Definition:
filemap.h:70
file_entry_t::target_size
size_t target_size
Definition:
filemap.h:69
file_entry_t::action
file_action_t action
Definition:
filemap.h:89
file_entry_t::target_type
file_type_t target_type
Definition:
filemap.h:68
filemap_t
Definition:
filemap.h:98
filemap_t::entries
file_entry_t * entries[FLEXIBLE_ARRAY_MEMBER]
Definition:
filemap.h:104
filemap_t::nentries
int nentries
Definition:
filemap.h:103
filemap_t::total_size
uint64 total_size
Definition:
filemap.h:100
filemap_t::fetch_size
uint64 fetch_size
Definition:
filemap.h:101
type
const char * type
Definition:
wait_event_funcs.c:27
xlogdefs.h
XLogSegNo
uint64 XLogSegNo
Definition:
xlogdefs.h:52
src
bin
pg_rewind
filemap.h
Generated on Fri Nov 21 2025 00:13:16 for PostgreSQL Source Code by
1.9.4