Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit aa2d6b1

Browse files
committed
pg_verifybackup: Move some declarations to new pg_verifybackup.h
This is in preparation for adding a second source file to this directory. Amul Sul, reviewed by Sravan Kumar and revised a bit by me. Discussion: http://postgr.es/m/CAAJ_b95mcGjkfAf1qduOR97CokW8-_i-dWLm3v6x1w2-OW9M+A@mail.gmail.com
1 parent af99d44 commit aa2d6b1

File tree

2 files changed

+107
-85
lines changed

2 files changed

+107
-85
lines changed

src/bin/pg_verifybackup/pg_verifybackup.c

Lines changed: 4 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
#include <sys/stat.h>
1919
#include <time.h>
2020

21-
#include "common/controldata_utils.h"
22-
#include "common/hashfn_unstable.h"
2321
#include "common/logging.h"
2422
#include "common/parse_manifest.h"
2523
#include "fe_utils/simple_list.h"
2624
#include "getopt_long.h"
25+
#include "pg_verifybackup.h"
2726
#include "pgtime.h"
2827

2928
/*
@@ -45,79 +44,6 @@
4544
*/
4645
#define READ_CHUNK_SIZE (128 * 1024)
4746

48-
/*
49-
* Each file described by the manifest file is parsed to produce an object
50-
* like this.
51-
*/
52-
typedef struct manifest_file
53-
{
54-
uint32 status; /* hash status */
55-
const char *pathname;
56-
size_t size;
57-
pg_checksum_type checksum_type;
58-
int checksum_length;
59-
uint8 *checksum_payload;
60-
bool matched;
61-
bool bad;
62-
} manifest_file;
63-
64-
#define should_verify_checksum(m) \
65-
(((m)->matched) && !((m)->bad) && (((m)->checksum_type) != CHECKSUM_TYPE_NONE))
66-
67-
/*
68-
* Define a hash table which we can use to store information about the files
69-
* mentioned in the backup manifest.
70-
*/
71-
#define SH_PREFIX manifest_files
72-
#define SH_ELEMENT_TYPE manifest_file
73-
#define SH_KEY_TYPE const char *
74-
#define SH_KEY pathname
75-
#define SH_HASH_KEY(tb, key) hash_string(key)
76-
#define SH_EQUAL(tb, a, b) (strcmp(a, b) == 0)
77-
#define SH_SCOPE static inline
78-
#define SH_RAW_ALLOCATOR pg_malloc0
79-
#define SH_DECLARE
80-
#define SH_DEFINE
81-
#include "lib/simplehash.h"
82-
83-
/*
84-
* Each WAL range described by the manifest file is parsed to produce an
85-
* object like this.
86-
*/
87-
typedef struct manifest_wal_range
88-
{
89-
TimeLineID tli;
90-
XLogRecPtr start_lsn;
91-
XLogRecPtr end_lsn;
92-
struct manifest_wal_range *next;
93-
struct manifest_wal_range *prev;
94-
} manifest_wal_range;
95-
96-
/*
97-
* All the data parsed from a backup_manifest file.
98-
*/
99-
typedef struct manifest_data
100-
{
101-
int version;
102-
uint64 system_identifier;
103-
manifest_files_hash *files;
104-
manifest_wal_range *first_wal_range;
105-
manifest_wal_range *last_wal_range;
106-
} manifest_data;
107-
108-
/*
109-
* All of the context information we need while checking a backup manifest.
110-
*/
111-
typedef struct verifier_context
112-
{
113-
manifest_data *manifest;
114-
char *backup_directory;
115-
SimpleStringList ignore_list;
116-
bool skip_checksums;
117-
bool exit_on_error;
118-
bool saw_any_error;
119-
} verifier_context;
120-
12147
static manifest_data *parse_manifest_file(char *manifest_path);
12248
static void verifybackup_version_cb(JsonManifestParseContext *context,
12349
int manifest_version);
@@ -151,13 +77,6 @@ static void parse_required_wal(verifier_context *context,
15177
char *pg_waldump_path,
15278
char *wal_directory);
15379

154-
static void report_backup_error(verifier_context *context,
155-
const char *pg_restrict fmt,...)
156-
pg_attribute_printf(2, 3);
157-
static void report_fatal_error(const char *pg_restrict fmt,...)
158-
pg_attribute_printf(1, 2) pg_attribute_noreturn();
159-
static bool should_ignore_relpath(verifier_context *context, const char *relpath);
160-
16180
static void progress_report(bool finished);
16281
static void usage(void);
16382

@@ -980,7 +899,7 @@ parse_required_wal(verifier_context *context, char *pg_waldump_path,
980899
* Update the context to indicate that we saw an error, and exit if the
981900
* context says we should.
982901
*/
983-
static void
902+
void
984903
report_backup_error(verifier_context *context, const char *pg_restrict fmt,...)
985904
{
986905
va_list ap;
@@ -997,7 +916,7 @@ report_backup_error(verifier_context *context, const char *pg_restrict fmt,...)
997916
/*
998917
* Report a fatal error and exit
999918
*/
1000-
static void
919+
void
1001920
report_fatal_error(const char *pg_restrict fmt,...)
1002921
{
1003922
va_list ap;
@@ -1016,7 +935,7 @@ report_fatal_error(const char *pg_restrict fmt,...)
1016935
* Note that by "prefix" we mean a parent directory; for this purpose,
1017936
* "aa/bb" is not a prefix of "aa/bbb", but it is a prefix of "aa/bb/cc".
1018937
*/
1019-
static bool
938+
bool
1020939
should_ignore_relpath(verifier_context *context, const char *relpath)
1021940
{
1022941
SimpleStringListCell *cell;
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* pg_verifybackup.h
4+
* Verify a backup against a backup manifest.
5+
*
6+
* Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7+
* Portions Copyright (c) 1994, Regents of the University of California
8+
*
9+
* src/bin/pg_verifybackup/pg_verifybackup.h
10+
*
11+
*-------------------------------------------------------------------------
12+
*/
13+
14+
#ifndef PG_VERIFYBACKUP_H
15+
#define PG_VERIFYBACKUP_H
16+
17+
#include "common/controldata_utils.h"
18+
#include "common/hashfn_unstable.h"
19+
#include "common/parse_manifest.h"
20+
#include "fe_utils/simple_list.h"
21+
22+
/*
23+
* Each file described by the manifest file is parsed to produce an object
24+
* like this.
25+
*/
26+
typedef struct manifest_file
27+
{
28+
uint32 status; /* hash status */
29+
const char *pathname;
30+
size_t size;
31+
pg_checksum_type checksum_type;
32+
int checksum_length;
33+
uint8 *checksum_payload;
34+
bool matched;
35+
bool bad;
36+
} manifest_file;
37+
38+
#define should_verify_checksum(m) \
39+
(((m)->matched) && !((m)->bad) && (((m)->checksum_type) != CHECKSUM_TYPE_NONE))
40+
41+
/*
42+
* Define a hash table which we can use to store information about the files
43+
* mentioned in the backup manifest.
44+
*/
45+
#define SH_PREFIX manifest_files
46+
#define SH_ELEMENT_TYPE manifest_file
47+
#define SH_KEY_TYPE const char *
48+
#define SH_KEY pathname
49+
#define SH_HASH_KEY(tb, key) hash_string(key)
50+
#define SH_EQUAL(tb, a, b) (strcmp(a, b) == 0)
51+
#define SH_SCOPE static inline
52+
#define SH_RAW_ALLOCATOR pg_malloc0
53+
#define SH_DECLARE
54+
#define SH_DEFINE
55+
#include "lib/simplehash.h"
56+
57+
/*
58+
* Each WAL range described by the manifest file is parsed to produce an
59+
* object like this.
60+
*/
61+
typedef struct manifest_wal_range
62+
{
63+
TimeLineID tli;
64+
XLogRecPtr start_lsn;
65+
XLogRecPtr end_lsn;
66+
struct manifest_wal_range *next;
67+
struct manifest_wal_range *prev;
68+
} manifest_wal_range;
69+
70+
/*
71+
* All the data parsed from a backup_manifest file.
72+
*/
73+
typedef struct manifest_data
74+
{
75+
int version;
76+
uint64 system_identifier;
77+
manifest_files_hash *files;
78+
manifest_wal_range *first_wal_range;
79+
manifest_wal_range *last_wal_range;
80+
} manifest_data;
81+
82+
/*
83+
* All of the context information we need while checking a backup manifest.
84+
*/
85+
typedef struct verifier_context
86+
{
87+
manifest_data *manifest;
88+
char *backup_directory;
89+
SimpleStringList ignore_list;
90+
bool skip_checksums;
91+
bool exit_on_error;
92+
bool saw_any_error;
93+
} verifier_context;
94+
95+
extern void report_backup_error(verifier_context *context,
96+
const char *pg_restrict fmt,...)
97+
pg_attribute_printf(2, 3);
98+
extern void report_fatal_error(const char *pg_restrict fmt,...)
99+
pg_attribute_printf(1, 2) pg_attribute_noreturn();
100+
extern bool should_ignore_relpath(verifier_context *context,
101+
const char *relpath);
102+
103+
#endif /* PG_VERIFYBACKUP_H */

0 commit comments

Comments
 (0)