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"
14#include "access/xlogdefs.h"
15
16/* these enum values are sorted in the order we want actions to be processed */
17typedef 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 */
30
31typedef enum
32{
34
39
40typedef enum
41{
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 */
57typedef struct file_entry_t
58{
59 uint32 status; /* hash status */
60
61 const char *path;
63
64 /*
65 * Status of the file in the target.
66 */
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 */
77
78 /*
79 * Status of the file in the source.
80 */
84 char *source_link_target; /* for a symlink */
85
86 /*
87 * What will we do to the file?
88 */
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 */
97typedef 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 */
106
107/* Functions for populating the filemap */
108extern void filehash_init(void);
109extern void process_source_file(const char *path, file_type_t type,
110 size_t size, const char *link_target);
111extern void process_target_file(const char *path, file_type_t type,
112 size_t size, const char *link_target);
114 RelFileLocator rlocator,
115 BlockNumber blkno);
116
117extern filemap_t *decide_file_actions(XLogSegNo last_common_segno);
118extern void calculate_totals(filemap_t *filemap);
119extern void print_filemap(filemap_t *filemap);
120
121extern void keepwal_init(void);
122extern void keepwal_add_entry(const char *path);
123
124#endif /* FILEMAP_H */
uint32 BlockNumber
Definition: block.h:31
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:475
uint64_t uint64
Definition: c.h:544
uint32_t uint32
Definition: c.h:543
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
void process_target_wal_block_change(ForkNumber forknum, RelFileLocator rlocator, BlockNumber blkno)
Definition: filemap.c:353
file_content_type_t
Definition: filemap.h:41
@ FILE_CONTENT_TYPE_OTHER
Definition: filemap.h:42
@ FILE_CONTENT_TYPE_RELATION
Definition: filemap.h:43
@ FILE_CONTENT_TYPE_WAL
Definition: filemap.h:44
void keepwal_add_entry(const char *path)
Definition: filemap.c:251
file_action_t
Definition: filemap.h:18
@ FILE_ACTION_REMOVE
Definition: filemap.h:28
@ FILE_ACTION_COPY
Definition: filemap.h:22
@ FILE_ACTION_NONE
Definition: filemap.h:25
@ FILE_ACTION_COPY_TAIL
Definition: filemap.h:23
@ FILE_ACTION_UNDECIDED
Definition: filemap.h:19
@ FILE_ACTION_TRUNCATE
Definition: filemap.h:27
@ FILE_ACTION_CREATE
Definition: filemap.h:21
struct file_entry_t file_entry_t
void calculate_totals(filemap_t *filemap)
Definition: filemap.c:500
filemap_t * decide_file_actions(XLogSegNo last_common_segno)
Definition: filemap.c:924
file_type_t
Definition: filemap.h:32
@ FILE_TYPE_UNDEFINED
Definition: filemap.h:33
@ FILE_TYPE_REGULAR
Definition: filemap.h:35
@ FILE_TYPE_SYMLINK
Definition: filemap.h:37
@ FILE_TYPE_DIRECTORY
Definition: filemap.h:36
struct filemap_t filemap_t
ForkNumber
Definition: relpath.h:56
Definition: filemap.h:58
datapagemap_t target_pages_to_overwrite
Definition: filemap.h:76
const char * path
Definition: filemap.h:61
size_t source_size
Definition: filemap.h:83
bool source_exists
Definition: filemap.h:81
bool target_exists
Definition: filemap.h:67
char * source_link_target
Definition: filemap.h:84
uint32 status
Definition: filemap.h:59
file_content_type_t content_type
Definition: filemap.h:62
file_type_t source_type
Definition: filemap.h:82
char * target_link_target
Definition: filemap.h:70
size_t target_size
Definition: filemap.h:69
file_action_t action
Definition: filemap.h:89
file_type_t target_type
Definition: filemap.h:68
file_entry_t * entries[FLEXIBLE_ARRAY_MEMBER]
Definition: filemap.h:104
int nentries
Definition: filemap.h:103
uint64 total_size
Definition: filemap.h:100
uint64 fetch_size
Definition: filemap.h:101
const char * type
uint64 XLogSegNo
Definition: xlogdefs.h:52