PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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"
14
15/* these enum values are sorted in the order we want actions to be processed */
16typedef 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
30typedef enum
31{
33
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 */
49typedef 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 */
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 */
89typedef 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 */
100extern void filehash_init(void);
101extern void process_source_file(const char *path, file_type_t type,
102 size_t size, const char *link_target);
103extern void process_target_file(const char *path, file_type_t type,
104 size_t size, const char *link_target);
106 RelFileLocator rlocator,
107 BlockNumber blkno);
108
109extern filemap_t *decide_file_actions(void);
110extern void calculate_totals(filemap_t *filemap);
111extern void print_filemap(filemap_t *filemap);
112
113extern void keepwal_init(void);
114extern void keepwal_add_entry(const char *path);
115
116#endif /* FILEMAP_H */
uint32 BlockNumber
Definition: block.h:31
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:434
uint64_t uint64
Definition: c.h:503
uint32_t uint32
Definition: c.h:502
void filehash_init(void)
Definition: filemap.c:197
void process_source_file(const char *path, file_type_t type, size_t size, const char *link_target)
Definition: filemap.c:280
void print_filemap(filemap_t *filemap)
Definition: filemap.c:541
void keepwal_init(void)
Definition: filemap.c:243
void process_target_file(const char *path, file_type_t type, size_t size, const char *link_target)
Definition: filemap.c:316
filemap_t * decide_file_actions(void)
Definition: filemap.c:861
void process_target_wal_block_change(ForkNumber forknum, RelFileLocator rlocator, BlockNumber blkno)
Definition: filemap.c:353
void keepwal_add_entry(const char *path)
Definition: filemap.c:251
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:500
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
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