Skip to content

Commit 8f6fb52

Browse files
committed
Merge branch 'pgpro-533'
2 parents efc0c8c + 9cd12fb commit 8f6fb52

24 files changed

+1064
-332
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ OBJS = src/backup.o src/catalog.o src/configure.o src/data.o \
44
src/pg_probackup.o src/restore.o src/show.o src/status.o \
55
src/util.o src/validate.o src/datapagemap.o src/parsexlog.o \
66
src/xlogreader.o src/streamutil.o src/receivelog.o \
7-
src/archive.o src/utils/parray.o src/utils/pgut.o src/utils/logger.o
7+
src/archive.o src/utils/parray.o src/utils/pgut.o src/utils/logger.o \
8+
src/utils/json.o
89

910
EXTRA_CLEAN = src/datapagemap.c src/datapagemap.h src/xlogreader.c \
1011
src/receivelog.c src/receivelog.h src/streamutil.c src/streamutil.h src/logging.h

src/backup.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ do_backup_instance(void)
633633
* For backup from master wait for previous segment.
634634
* For backup from replica wait for current segment.
635635
*/
636-
!from_replica, backup_files_list);
636+
!current.from_replica, backup_files_list);
637637
}
638638

639639
if (current.backup_mode == BACKUP_MODE_DIFF_PTRACK)
@@ -815,11 +815,15 @@ do_backup(time_t start_time)
815815
pgut_atexit_push(backup_disconnect, NULL);
816816

817817
current.primary_conninfo = pgut_get_conninfo_string(backup_conn);
818+
819+
current.compress_alg = compress_alg;
820+
current.compress_level = compress_level;
821+
818822
/* Confirm data block size and xlog block size are compatible */
819823
confirm_block_size("block_size", BLCKSZ);
820824
confirm_block_size("wal_block_size", XLOG_BLCKSZ);
821825

822-
from_replica = pg_is_in_recovery();
826+
current.from_replica = pg_is_in_recovery();
823827

824828
/* Confirm that this server version is supported */
825829
check_server_version();
@@ -859,7 +863,7 @@ do_backup(time_t start_time)
859863
}
860864
}
861865

862-
if (from_replica)
866+
if (current.from_replica)
863867
{
864868
/* Check master connection options */
865869
if (master_host == NULL)
@@ -956,7 +960,7 @@ check_server_version(void)
956960
"server version is %s, must be %s or higher",
957961
server_version_str, "9.5");
958962

959-
if (from_replica && server_version < 90600)
963+
if (current.from_replica && server_version < 90600)
960964
elog(ERROR,
961965
"server version is %s, must be %s or higher for backup from replica",
962966
server_version_str, "9.6");
@@ -1061,7 +1065,7 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
10611065
params[0] = label;
10621066

10631067
/* For replica we call pg_start_backup() on master */
1064-
conn = (from_replica) ? master_conn : backup_conn;
1068+
conn = (backup->from_replica) ? master_conn : backup_conn;
10651069

10661070
/* 2nd argument is 'fast'*/
10671071
params[1] = smooth ? "false" : "true";
@@ -1112,7 +1116,7 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
11121116
}
11131117

11141118
/* Wait for start_lsn to be replayed by replica */
1115-
if (from_replica)
1119+
if (backup->from_replica)
11161120
wait_replica_wal_lsn(backup->start_lsn, true);
11171121
}
11181122

@@ -1555,8 +1559,6 @@ wait_replica_wal_lsn(XLogRecPtr lsn, bool is_start_backup)
15551559
{
15561560
uint32 try_count = 0;
15571561

1558-
Assert(from_replica);
1559-
15601562
while (true)
15611563
{
15621564
PGresult *res;
@@ -1651,7 +1653,7 @@ pg_stop_backup(pgBackup *backup)
16511653
elog(FATAL, "backup is not in progress");
16521654

16531655
/* For replica we call pg_stop_backup() on master */
1654-
conn = (from_replica) ? master_conn : backup_conn;
1656+
conn = (current.from_replica) ? master_conn : backup_conn;
16551657

16561658
/* Remove annoying NOTICE messages generated by backend */
16571659
res = pgut_execute(conn, "SET client_min_messages = warning;",
@@ -1664,7 +1666,7 @@ pg_stop_backup(pgBackup *backup)
16641666
const char *params[1];
16651667
char name[1024];
16661668

1667-
if (!from_replica)
1669+
if (!current.from_replica)
16681670
snprintf(name, lengthof(name), "pg_probackup, backup_id %s",
16691671
base36enc(backup->start_time));
16701672
else
@@ -1892,7 +1894,7 @@ pg_stop_backup(pgBackup *backup)
18921894
stream_xlog_path[MAXPGPATH];
18931895

18941896
/* Wait for stop_lsn to be received by replica */
1895-
if (from_replica)
1897+
if (backup->from_replica)
18961898
wait_replica_wal_lsn(stop_backup_lsn, false);
18971899
/*
18981900
* Wait for stop_lsn to be archived or streamed.

src/catalog.c

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -385,15 +385,17 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
385385

386386
fprintf(out, "#Configuration\n");
387387
fprintf(out, "backup-mode = %s\n", pgBackupGetBackupMode(backup));
388-
fprintf(out, "stream = %s\n", backup->stream?"true":"false");
389-
fprintf(out, "compress-alg = %s\n", deparse_compress_alg(compress_alg));
390-
fprintf(out, "compress-level = %d\n", compress_level);
391-
fprintf(out, "from-replica = %s\n", from_replica?"true":"false");
388+
fprintf(out, "stream = %s\n", backup->stream ? "true" : "false");
389+
fprintf(out, "compress-alg = %s\n",
390+
deparse_compress_alg(backup->compress_alg));
391+
fprintf(out, "compress-level = %d\n", backup->compress_level);
392+
fprintf(out, "from-replica = %s\n", backup->from_replica ? "true" : "false");
392393

393394
fprintf(out, "\n#Compatibility\n");
394395
fprintf(out, "block-size = %u\n", backup->block_size);
395396
fprintf(out, "xlog-block-size = %u\n", backup->wal_block_size);
396397
fprintf(out, "checksum-version = %u\n", backup->checksum_version);
398+
fprintf(out, "program-version = %s\n", PROGRAM_VERSION);
397399
if (backup->server_version[0] != '\0')
398400
fprintf(out, "server-version = %s\n", backup->server_version);
399401

@@ -429,7 +431,7 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
429431
if (backup->data_bytes != BYTES_INVALID)
430432
fprintf(out, "data-bytes = " INT64_FORMAT "\n", backup->data_bytes);
431433

432-
if (backup->data_bytes != BYTES_INVALID)
434+
if (backup->wal_bytes != BYTES_INVALID)
433435
fprintf(out, "wal-bytes = " INT64_FORMAT "\n", backup->wal_bytes);
434436

435437
fprintf(out, "status = %s\n", status2str(backup->status));
@@ -475,10 +477,9 @@ readBackupControlFile(const char *path)
475477
char *stop_lsn = NULL;
476478
char *status = NULL;
477479
char *parent_backup = NULL;
478-
char *compress_alg = NULL;
480+
char *program_version = NULL;
479481
char *server_version = NULL;
480-
int *compress_level;
481-
bool *from_replica;
482+
char *compress_alg = NULL;
482483

483484
pgut_option options[] =
484485
{
@@ -495,13 +496,14 @@ readBackupControlFile(const char *path)
495496
{'u', 0, "block-size", &backup->block_size, SOURCE_FILE_STRICT},
496497
{'u', 0, "xlog-block-size", &backup->wal_block_size, SOURCE_FILE_STRICT},
497498
{'u', 0, "checksum-version", &backup->checksum_version, SOURCE_FILE_STRICT},
499+
{'s', 0, "program-version", &program_version, SOURCE_FILE_STRICT},
498500
{'s', 0, "server-version", &server_version, SOURCE_FILE_STRICT},
499501
{'b', 0, "stream", &backup->stream, SOURCE_FILE_STRICT},
500502
{'s', 0, "status", &status, SOURCE_FILE_STRICT},
501503
{'s', 0, "parent-backup-id", &parent_backup, SOURCE_FILE_STRICT},
502504
{'s', 0, "compress-alg", &compress_alg, SOURCE_FILE_STRICT},
503-
{'u', 0, "compress-level", &compress_level, SOURCE_FILE_STRICT},
504-
{'b', 0, "from-replica", &from_replica, SOURCE_FILE_STRICT},
505+
{'u', 0, "compress-level", &backup->compress_level, SOURCE_FILE_STRICT},
506+
{'b', 0, "from-replica", &backup->from_replica, SOURCE_FILE_STRICT},
505507
{'s', 0, "primary-conninfo", &backup->primary_conninfo, SOURCE_FILE_STRICT},
506508
{0}
507509
};
@@ -571,13 +573,23 @@ readBackupControlFile(const char *path)
571573
free(parent_backup);
572574
}
573575

576+
if (program_version)
577+
{
578+
StrNCpy(backup->program_version, program_version,
579+
sizeof(backup->program_version));
580+
pfree(program_version);
581+
}
582+
574583
if (server_version)
575584
{
576585
StrNCpy(backup->server_version, server_version,
577586
sizeof(backup->server_version));
578587
pfree(server_version);
579588
}
580589

590+
if (compress_alg)
591+
backup->compress_alg = parse_compress_alg(compress_alg);
592+
581593
return backup;
582594
}
583595

@@ -626,6 +638,48 @@ deparse_backup_mode(BackupMode mode)
626638
return NULL;
627639
}
628640

641+
CompressAlg
642+
parse_compress_alg(const char *arg)
643+
{
644+
size_t len;
645+
646+
/* Skip all spaces detected */
647+
while (isspace((unsigned char)*arg))
648+
arg++;
649+
len = strlen(arg);
650+
651+
if (len == 0)
652+
elog(ERROR, "compress algrorithm is empty");
653+
654+
if (pg_strncasecmp("zlib", arg, len) == 0)
655+
return ZLIB_COMPRESS;
656+
else if (pg_strncasecmp("pglz", arg, len) == 0)
657+
return PGLZ_COMPRESS;
658+
else if (pg_strncasecmp("none", arg, len) == 0)
659+
return NONE_COMPRESS;
660+
else
661+
elog(ERROR, "invalid compress algorithm value \"%s\"", arg);
662+
663+
return NOT_DEFINED_COMPRESS;
664+
}
665+
666+
const char*
667+
deparse_compress_alg(int alg)
668+
{
669+
switch (alg)
670+
{
671+
case NONE_COMPRESS:
672+
case NOT_DEFINED_COMPRESS:
673+
return "none";
674+
case ZLIB_COMPRESS:
675+
return "zlib";
676+
case PGLZ_COMPRESS:
677+
return "pglz";
678+
}
679+
680+
return NULL;
681+
}
682+
629683
/* free pgBackup object */
630684
void
631685
pgBackupFree(void *backup)

0 commit comments

Comments
 (0)