@@ -94,31 +94,28 @@ typedef struct manifest_wal_range
94
94
} manifest_wal_range ;
95
95
96
96
/*
97
- * Details we need in callbacks that occur while parsing a backup manifest .
97
+ * All the data parsed from a backup_manifest file .
98
98
*/
99
- typedef struct parser_context
99
+ typedef struct manifest_data
100
100
{
101
- manifest_files_hash * ht ;
101
+ manifest_files_hash * files ;
102
102
manifest_wal_range * first_wal_range ;
103
103
manifest_wal_range * last_wal_range ;
104
- } parser_context ;
104
+ } manifest_data ;
105
105
106
106
/*
107
107
* All of the context information we need while checking a backup manifest.
108
108
*/
109
109
typedef struct verifier_context
110
110
{
111
- manifest_files_hash * ht ;
111
+ manifest_data * manifest ;
112
112
char * backup_directory ;
113
113
SimpleStringList ignore_list ;
114
114
bool exit_on_error ;
115
115
bool saw_any_error ;
116
116
} verifier_context ;
117
117
118
- static void parse_manifest_file (char * manifest_path ,
119
- manifest_files_hash * * ht_p ,
120
- manifest_wal_range * * first_wal_range_p );
121
-
118
+ static manifest_data * parse_manifest_file (char * manifest_path );
122
119
static void verifybackup_per_file_cb (JsonManifestParseContext * context ,
123
120
char * pathname , size_t size ,
124
121
pg_checksum_type checksum_type ,
@@ -142,8 +139,7 @@ static void verify_file_checksum(verifier_context *context,
142
139
manifest_file * m , char * fullpath );
143
140
static void parse_required_wal (verifier_context * context ,
144
141
char * pg_waldump_path ,
145
- char * wal_directory ,
146
- manifest_wal_range * first_wal_range );
142
+ char * wal_directory );
147
143
148
144
static void report_backup_error (verifier_context * context ,
149
145
const char * pg_restrict fmt ,...)
@@ -185,7 +181,6 @@ main(int argc, char **argv)
185
181
186
182
int c ;
187
183
verifier_context context ;
188
- manifest_wal_range * first_wal_range ;
189
184
char * manifest_path = NULL ;
190
185
bool no_parse_wal = false;
191
186
bool quiet = false;
@@ -338,7 +333,7 @@ main(int argc, char **argv)
338
333
* the manifest as fatal; there doesn't seem to be much point in trying to
339
334
* verify the backup directory against a corrupted manifest.
340
335
*/
341
- parse_manifest_file ( manifest_path , & context .ht , & first_wal_range );
336
+ context .manifest = parse_manifest_file ( manifest_path );
342
337
343
338
/*
344
339
* Now scan the files in the backup directory. At this stage, we verify
@@ -367,8 +362,7 @@ main(int argc, char **argv)
367
362
* not to do so.
368
363
*/
369
364
if (!no_parse_wal )
370
- parse_required_wal (& context , pg_waldump_path ,
371
- wal_directory , first_wal_range );
365
+ parse_required_wal (& context , pg_waldump_path , wal_directory );
372
366
373
367
/*
374
368
* If everything looks OK, tell the user this, unless we were asked to
@@ -385,9 +379,8 @@ main(int argc, char **argv)
385
379
* all the files it mentions, and a linked list of all the WAL ranges it
386
380
* mentions.
387
381
*/
388
- static void
389
- parse_manifest_file (char * manifest_path , manifest_files_hash * * ht_p ,
390
- manifest_wal_range * * first_wal_range_p )
382
+ static manifest_data *
383
+ parse_manifest_file (char * manifest_path )
391
384
{
392
385
int fd ;
393
386
struct stat statbuf ;
@@ -396,8 +389,8 @@ parse_manifest_file(char *manifest_path, manifest_files_hash **ht_p,
396
389
manifest_files_hash * ht ;
397
390
char * buffer ;
398
391
int rc ;
399
- parser_context private_context ;
400
392
JsonManifestParseContext context ;
393
+ manifest_data * result ;
401
394
402
395
/* Open the manifest file. */
403
396
if ((fd = open (manifest_path , O_RDONLY | PG_BINARY , 0 )) < 0 )
@@ -436,10 +429,9 @@ parse_manifest_file(char *manifest_path, manifest_files_hash **ht_p,
436
429
close (fd );
437
430
438
431
/* Parse the manifest. */
439
- private_context .ht = ht ;
440
- private_context .first_wal_range = NULL ;
441
- private_context .last_wal_range = NULL ;
442
- context .private_data = & private_context ;
432
+ result = pg_malloc0 (sizeof (manifest_data ));
433
+ result -> files = ht ;
434
+ context .private_data = result ;
443
435
context .per_file_cb = verifybackup_per_file_cb ;
444
436
context .per_wal_range_cb = verifybackup_per_wal_range_cb ;
445
437
context .error_cb = report_manifest_error ;
@@ -448,9 +440,7 @@ parse_manifest_file(char *manifest_path, manifest_files_hash **ht_p,
448
440
/* Done with the buffer. */
449
441
pfree (buffer );
450
442
451
- /* Return the file hash table and WAL range list we constructed. */
452
- * ht_p = ht ;
453
- * first_wal_range_p = private_context .first_wal_range ;
443
+ return result ;
454
444
}
455
445
456
446
/*
@@ -480,8 +470,8 @@ verifybackup_per_file_cb(JsonManifestParseContext *context,
480
470
pg_checksum_type checksum_type ,
481
471
int checksum_length , uint8 * checksum_payload )
482
472
{
483
- parser_context * pcxt = context -> private_data ;
484
- manifest_files_hash * ht = pcxt -> ht ;
473
+ manifest_data * manifest = context -> private_data ;
474
+ manifest_files_hash * ht = manifest -> files ;
485
475
manifest_file * m ;
486
476
bool found ;
487
477
@@ -508,23 +498,23 @@ verifybackup_per_wal_range_cb(JsonManifestParseContext *context,
508
498
TimeLineID tli ,
509
499
XLogRecPtr start_lsn , XLogRecPtr end_lsn )
510
500
{
511
- parser_context * pcxt = context -> private_data ;
501
+ manifest_data * manifest = context -> private_data ;
512
502
manifest_wal_range * range ;
513
503
514
504
/* Allocate and initialize a struct describing this WAL range. */
515
505
range = palloc (sizeof (manifest_wal_range ));
516
506
range -> tli = tli ;
517
507
range -> start_lsn = start_lsn ;
518
508
range -> end_lsn = end_lsn ;
519
- range -> prev = pcxt -> last_wal_range ;
509
+ range -> prev = manifest -> last_wal_range ;
520
510
range -> next = NULL ;
521
511
522
512
/* Add it to the end of the list. */
523
- if (pcxt -> first_wal_range == NULL )
524
- pcxt -> first_wal_range = range ;
513
+ if (manifest -> first_wal_range == NULL )
514
+ manifest -> first_wal_range = range ;
525
515
else
526
- pcxt -> last_wal_range -> next = range ;
527
- pcxt -> last_wal_range = range ;
516
+ manifest -> last_wal_range -> next = range ;
517
+ manifest -> last_wal_range = range ;
528
518
}
529
519
530
520
/*
@@ -639,7 +629,7 @@ verify_backup_file(verifier_context *context, char *relpath, char *fullpath)
639
629
}
640
630
641
631
/* Check whether there's an entry in the manifest hash. */
642
- m = manifest_files_lookup (context -> ht , relpath );
632
+ m = manifest_files_lookup (context -> manifest -> files , relpath );
643
633
if (m == NULL )
644
634
{
645
635
report_backup_error (context ,
@@ -679,11 +669,12 @@ verify_backup_file(verifier_context *context, char *relpath, char *fullpath)
679
669
static void
680
670
report_extra_backup_files (verifier_context * context )
681
671
{
672
+ manifest_data * manifest = context -> manifest ;
682
673
manifest_files_iterator it ;
683
674
manifest_file * m ;
684
675
685
- manifest_files_start_iterate (context -> ht , & it );
686
- while ((m = manifest_files_iterate (context -> ht , & it )) != NULL )
676
+ manifest_files_start_iterate (manifest -> files , & it );
677
+ while ((m = manifest_files_iterate (manifest -> files , & it )) != NULL )
687
678
if (!m -> matched && !should_ignore_relpath (context , m -> pathname ))
688
679
report_backup_error (context ,
689
680
"\"%s\" is present in the manifest but not on disk" ,
@@ -698,13 +689,14 @@ report_extra_backup_files(verifier_context *context)
698
689
static void
699
690
verify_backup_checksums (verifier_context * context )
700
691
{
692
+ manifest_data * manifest = context -> manifest ;
701
693
manifest_files_iterator it ;
702
694
manifest_file * m ;
703
695
704
696
progress_report (false);
705
697
706
- manifest_files_start_iterate (context -> ht , & it );
707
- while ((m = manifest_files_iterate (context -> ht , & it )) != NULL )
698
+ manifest_files_start_iterate (manifest -> files , & it );
699
+ while ((m = manifest_files_iterate (manifest -> files , & it )) != NULL )
708
700
{
709
701
if (should_verify_checksum (m ) &&
710
702
!should_ignore_relpath (context , m -> pathname ))
@@ -833,9 +825,10 @@ verify_file_checksum(verifier_context *context, manifest_file *m,
833
825
*/
834
826
static void
835
827
parse_required_wal (verifier_context * context , char * pg_waldump_path ,
836
- char * wal_directory , manifest_wal_range * first_wal_range )
828
+ char * wal_directory )
837
829
{
838
- manifest_wal_range * this_wal_range = first_wal_range ;
830
+ manifest_data * manifest = context -> manifest ;
831
+ manifest_wal_range * this_wal_range = manifest -> first_wal_range ;
839
832
840
833
while (this_wal_range != NULL )
841
834
{
0 commit comments