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 */
28
}
file_action_t
;
29
30
typedef
enum
31
{
32
FILE_TYPE_UNDEFINED
= 0,
33
34
FILE_TYPE_REGULAR
,
35
FILE_TYPE_DIRECTORY
,
36
FILE_TYPE_SYMLINK
,
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
*/
59
bool
target_exists
;
60
file_type_t
target_type
;
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
*/
68
datapagemap_t
target_pages_to_overwrite
;
69
70
/*
71
* Status of the file in the source.
72
*/
73
bool
source_exists
;
74
file_type_t
source_type
;
75
size_t
source_size
;
76
char
*
source_link_target
;
/* for a symlink */
77
78
/*
79
* What will we do to the file?
80
*/
81
file_action_t
action
;
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 */
96
file_entry_t
*
entries
[
FLEXIBLE_ARRAY_MEMBER
];
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
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 */
block.h
BlockNumber
uint32 BlockNumber
Definition:
block.h:31
uint32
unsigned int uint32
Definition:
c.h:492
FLEXIBLE_ARRAY_MEMBER
#define FLEXIBLE_ARRAY_MEMBER
Definition:
c.h:413
datapagemap.h
filehash_init
void filehash_init(void)
Definition:
filemap.c:196
process_source_file
void process_source_file(const char *path, file_type_t type, size_t size, const char *link_target)
Definition:
filemap.c:279
print_filemap
void print_filemap(filemap_t *filemap)
Definition:
filemap.c:540
keepwal_init
void keepwal_init(void)
Definition:
filemap.c:242
process_target_file
void process_target_file(const char *path, file_type_t type, size_t size, const char *link_target)
Definition:
filemap.c:315
process_target_wal_block_change
void process_target_wal_block_change(ForkNumber forknum, RelFileLocator rlocator, BlockNumber blkno)
Definition:
filemap.c:352
decide_file_actions
filemap_t * decide_file_actions(void)
Definition:
filemap.c:861
keepwal_add_entry
void keepwal_add_entry(const char *path)
Definition:
filemap.c:250
file_action_t
file_action_t
Definition:
filemap.h:17
FILE_ACTION_REMOVE
@ FILE_ACTION_REMOVE
Definition:
filemap.h:27
FILE_ACTION_COPY
@ FILE_ACTION_COPY
Definition:
filemap.h:21
FILE_ACTION_NONE
@ FILE_ACTION_NONE
Definition:
filemap.h:24
FILE_ACTION_COPY_TAIL
@ FILE_ACTION_COPY_TAIL
Definition:
filemap.h:22
FILE_ACTION_UNDECIDED
@ FILE_ACTION_UNDECIDED
Definition:
filemap.h:18
FILE_ACTION_TRUNCATE
@ FILE_ACTION_TRUNCATE
Definition:
filemap.h:26
FILE_ACTION_CREATE
@ FILE_ACTION_CREATE
Definition:
filemap.h:20
file_entry_t
struct file_entry_t file_entry_t
calculate_totals
void calculate_totals(filemap_t *filemap)
Definition:
filemap.c:499
file_type_t
file_type_t
Definition:
filemap.h:31
FILE_TYPE_UNDEFINED
@ FILE_TYPE_UNDEFINED
Definition:
filemap.h:32
FILE_TYPE_REGULAR
@ FILE_TYPE_REGULAR
Definition:
filemap.h:34
FILE_TYPE_SYMLINK
@ FILE_TYPE_SYMLINK
Definition:
filemap.h:36
FILE_TYPE_DIRECTORY
@ FILE_TYPE_DIRECTORY
Definition:
filemap.h:35
filemap_t
struct filemap_t filemap_t
relfilelocator.h
ForkNumber
ForkNumber
Definition:
relpath.h:56
size
static pg_noinline void Size size
Definition:
slab.c:607
RelFileLocator
Definition:
relfilelocator.h:59
datapagemap
Definition:
datapagemap.h:15
file_entry_t
Definition:
filemap.h:50
file_entry_t::target_pages_to_overwrite
datapagemap_t target_pages_to_overwrite
Definition:
filemap.h:68
file_entry_t::path
const char * path
Definition:
filemap.h:53
file_entry_t::source_size
size_t source_size
Definition:
filemap.h:75
file_entry_t::source_exists
bool source_exists
Definition:
filemap.h:73
file_entry_t::target_exists
bool target_exists
Definition:
filemap.h:59
file_entry_t::source_link_target
char * source_link_target
Definition:
filemap.h:76
file_entry_t::status
uint32 status
Definition:
filemap.h:51
file_entry_t::source_type
file_type_t source_type
Definition:
filemap.h:74
file_entry_t::target_link_target
char * target_link_target
Definition:
filemap.h:62
file_entry_t::target_size
size_t target_size
Definition:
filemap.h:61
file_entry_t::action
file_action_t action
Definition:
filemap.h:81
file_entry_t::target_type
file_type_t target_type
Definition:
filemap.h:60
file_entry_t::isrelfile
bool isrelfile
Definition:
filemap.h:54
filemap_t
Definition:
filemap.h:90
filemap_t::entries
file_entry_t * entries[FLEXIBLE_ARRAY_MEMBER]
Definition:
filemap.h:96
filemap_t::nentries
int nentries
Definition:
filemap.h:95
filemap_t::total_size
uint64 total_size
Definition:
filemap.h:92
filemap_t::fetch_size
uint64 fetch_size
Definition:
filemap.h:93
type
const char * type
Definition:
wait_event_funcs.c:27
src
bin
pg_rewind
filemap.h
Generated on Tue Dec 3 2024 00:13:23 for PostgreSQL Source Code by
1.9.1