]> granicus.if.org Git - postgresql/blob - src/bin/pg_rewind/filemap.h
57f0f92fb90dcc9a6db10286f9d2cd450bab39d9
[postgresql] / src / bin / pg_rewind / filemap.h
1 /*-------------------------------------------------------------------------
2  *
3  * filemap.h
4  *
5  * Copyright (c) 2013-2015, PostgreSQL Global Development Group
6  *-------------------------------------------------------------------------
7  */
8 #ifndef FILEMAP_H
9 #define FILEMAP_H
10
11 #include "storage/relfilenode.h"
12 #include "storage/block.h"
13
14 #include "datapagemap.h"
15
16 /*
17  * For every file found in the local or remote system, we have a file entry
18  * which says what we are going to do with the file. For relation files,
19  * there is also a page map, marking pages in the file that were changed
20  * locally.
21  *
22  * The enum values are sorted in the order we want actions to be processed.
23  */
24 typedef enum
25 {
26         FILE_ACTION_CREATE,             /* create local directory or symbolic link */
27         FILE_ACTION_COPY,               /* copy whole file, overwriting if exists */
28         FILE_ACTION_COPY_TAIL,  /* copy tail from 'oldsize' to 'newsize' */
29         FILE_ACTION_NONE,               /* no action (we might still copy modified blocks
30                                                          * based on the parsed WAL) */
31         FILE_ACTION_TRUNCATE,   /* truncate local file to 'newsize' bytes */
32         FILE_ACTION_REMOVE,             /* remove local file / directory / symlink */
33
34 } file_action_t;
35
36 typedef enum
37 {
38         FILE_TYPE_REGULAR,
39         FILE_TYPE_DIRECTORY,
40         FILE_TYPE_SYMLINK
41 } file_type_t;
42
43 struct file_entry_t
44 {
45         char       *path;
46         file_type_t type;
47
48         file_action_t action;
49
50         /* for a regular file */
51         size_t          oldsize;
52         size_t          newsize;
53         bool            isrelfile;              /* is it a relation data file? */
54
55         datapagemap_t   pagemap;
56
57         /* for a symlink */
58         char            *link_target;
59
60         struct file_entry_t *next;
61 };
62
63 typedef struct file_entry_t file_entry_t;
64
65 struct filemap_t
66 {
67         /*
68          * New entries are accumulated to a linked list, in process_remote_file
69          * and process_local_file.
70          */
71         file_entry_t *first;
72         file_entry_t *last;
73         int                     nlist;
74
75         /*
76          * After processing all the remote files, the entries in the linked list
77          * are moved to this array. After processing local files, too, all the
78          * local entries are added to the array by filemap_finalize, and sorted
79          * in the final order. After filemap_finalize, all the entries are in
80          * the array, and the linked list is empty.
81          */
82         file_entry_t **array;
83         int                     narray;
84
85         /*
86          * Summary information. total_size is the total size of the source cluster,
87          * and fetch_size is the number of bytes that needs to be copied.
88          */
89         uint64          total_size;
90         uint64          fetch_size;
91 };
92
93 typedef struct filemap_t filemap_t;
94
95 extern filemap_t * filemap;
96
97 extern filemap_t *filemap_create(void);
98
99 extern void calculate_totals(void);
100 extern void print_filemap(void);
101
102 /* Functions for populating the filemap */
103 extern void process_remote_file(const char *path, file_type_t type, size_t newsize, const char *link_target);
104 extern void process_local_file(const char *path, file_type_t type, size_t newsize, const char *link_target);
105 extern void process_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno);
106 extern void filemap_finalize(void);
107
108 #endif   /* FILEMAP_H */