You've already forked pg_probackup
mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2026-06-21 01:34:15 +02:00
code cleanup for catchup.c: pg_start_backup() refactoring
This commit is contained in:
+18
-18
@@ -49,8 +49,6 @@ static void *backup_files(void *arg);
|
||||
|
||||
static void do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool backup_logs);
|
||||
|
||||
static void pg_start_backup(const char *label, bool smooth, pgBackup *backup,
|
||||
PGNodeInfo *nodeInfo, PGconn *conn);
|
||||
static void pg_switch_wal(PGconn *conn);
|
||||
static void pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn, PGNodeInfo *nodeInfo);
|
||||
|
||||
@@ -138,7 +136,19 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
|
||||
strlen(" with pg_probackup"));
|
||||
|
||||
/* Call pg_start_backup function in PostgreSQL connect */
|
||||
pg_start_backup(label, smooth_checkpoint, ¤t, nodeInfo, backup_conn);
|
||||
current.start_lsn = pg_start_backup(label, smooth_checkpoint, backup_conn);
|
||||
|
||||
if ((!stream_wal || current.backup_mode == BACKUP_MODE_DIFF_PAGE) &&
|
||||
!current.from_replica &&
|
||||
!(nodeInfo->server_version < 90600 &&
|
||||
!nodeInfo->is_superuser))
|
||||
/*
|
||||
* Switch to a new WAL segment. It is necessary to get archived WAL
|
||||
* segment, which includes start LSN of current backup.
|
||||
* Don`t do this for replica backups and for PG 9.5 if pguser is not superuser
|
||||
* (because in 9.5 only superuser can switch WAL)
|
||||
*/
|
||||
pg_switch_wal(conn);
|
||||
|
||||
/* Obtain current timeline */
|
||||
#if PG_VERSION_NUM >= 90600
|
||||
@@ -1030,14 +1040,14 @@ confirm_block_size(PGconn *conn, const char *name, int blcksz)
|
||||
/*
|
||||
* Notify start of backup to PostgreSQL server.
|
||||
*/
|
||||
static void
|
||||
pg_start_backup(const char *label, bool smooth, pgBackup *backup,
|
||||
PGNodeInfo *nodeInfo, PGconn *conn)
|
||||
XLogRecPtr
|
||||
pg_start_backup(const char *label, bool smooth, PGconn *conn)
|
||||
{
|
||||
PGresult *res;
|
||||
const char *params[2];
|
||||
uint32 lsn_hi;
|
||||
uint32 lsn_lo;
|
||||
XLogRecPtr start_lsn;
|
||||
|
||||
params[0] = label;
|
||||
|
||||
@@ -1064,21 +1074,11 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup,
|
||||
/* Extract timeline and LSN from results of pg_start_backup() */
|
||||
XLogDataFromLSN(PQgetvalue(res, 0, 0), &lsn_hi, &lsn_lo);
|
||||
/* Calculate LSN */
|
||||
backup->start_lsn = ((uint64) lsn_hi )<< 32 | lsn_lo;
|
||||
start_lsn = ((uint64) lsn_hi )<< 32 | lsn_lo;
|
||||
|
||||
PQclear(res);
|
||||
|
||||
if ((!stream_wal || current.backup_mode == BACKUP_MODE_DIFF_PAGE) &&
|
||||
!backup->from_replica &&
|
||||
!(nodeInfo->server_version < 90600 &&
|
||||
!nodeInfo->is_superuser))
|
||||
/*
|
||||
* Switch to a new WAL segment. It is necessary to get archived WAL
|
||||
* segment, which includes start LSN of current backup.
|
||||
* Don`t do this for replica backups and for PG 9.5 if pguser is not superuser
|
||||
* (because in 9.5 only superuser can switch WAL)
|
||||
*/
|
||||
pg_switch_wal(conn);
|
||||
return start_lsn;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+15
-60
@@ -2,8 +2,7 @@
|
||||
*
|
||||
* catchup.c: sync DB cluster
|
||||
*
|
||||
* Portions Copyright (c) 2009-2013, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
|
||||
* Portions Copyright (c) 2015-2020, Postgres Professional
|
||||
* Copyright (c) 2020-2021, Postgres Professional
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -46,8 +45,6 @@ static void *catchup_files(void *arg);
|
||||
|
||||
static void do_catchup_instance(char *source_pgdata, char *dest_pgdata, PGconn *backup_conn, PGNodeInfo *nodeInfo, BackupMode backup_mode, bool no_sync, bool backup_logs);
|
||||
|
||||
static void catchup_pg_start_backup(char *label, bool smooth, BackupMode backup_mode, XLogRecPtr *start_lsn, PGNodeInfo *nodeInfo, PGconn *conn);
|
||||
|
||||
static void pg_switch_wal(PGconn *conn);
|
||||
static void catchup_pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn, PGNodeInfo *nodeInfo, char *dest_pgdata);
|
||||
|
||||
@@ -124,7 +121,20 @@ do_catchup_instance(char *source_pgdata, char *dest_pgdata, PGconn *backup_conn,
|
||||
strlen(" with pg_probackup"));
|
||||
|
||||
/* Call pg_start_backup function in PostgreSQL connect */
|
||||
catchup_pg_start_backup(label, smooth_checkpoint, backup_mode, &start_lsn, nodeInfo, backup_conn);
|
||||
start_lsn = pg_start_backup(label, smooth_checkpoint, backup_conn);
|
||||
|
||||
/* TODO !!! */
|
||||
if ((!stream_wal || backup_mode == BACKUP_MODE_DIFF_PAGE) &&
|
||||
/* !backup->from_replica && */
|
||||
!(nodeInfo->server_version < 90600 &&
|
||||
!nodeInfo->is_superuser))
|
||||
/*
|
||||
* Switch to a new WAL segment. It is necessary to get archived WAL
|
||||
* segment, which includes start LSN of current backup.
|
||||
* Don`t do this for replica backups and for PG 9.5 if pguser is not superuser
|
||||
* (because in 9.5 only superuser can switch WAL)
|
||||
*/
|
||||
pg_switch_wal(conn);
|
||||
|
||||
/* Obtain current timeline */
|
||||
#if PG_VERSION_NUM >= 90600
|
||||
@@ -732,61 +742,6 @@ do_catchup(char *source_pgdata, char *dest_pgdata, BackupMode backup_mode, Conne
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Notify start of backup to PostgreSQL server.
|
||||
*/
|
||||
static void
|
||||
catchup_pg_start_backup(char *label, bool smooth, BackupMode backup_mode, XLogRecPtr *start_lsn,
|
||||
PGNodeInfo *nodeInfo, PGconn *conn)
|
||||
{
|
||||
PGresult *res;
|
||||
const char *params[2];
|
||||
uint32 lsn_hi;
|
||||
uint32 lsn_lo;
|
||||
|
||||
params[0] = label;
|
||||
|
||||
/* 2nd argument is 'fast'*/
|
||||
params[1] = smooth ? "false" : "true";
|
||||
if (!exclusive_backup)
|
||||
res = pgut_execute(conn,
|
||||
"SELECT pg_catalog.pg_start_backup($1, $2, false)",
|
||||
2,
|
||||
params);
|
||||
else
|
||||
res = pgut_execute(conn,
|
||||
"SELECT pg_catalog.pg_start_backup($1, $2)",
|
||||
2,
|
||||
params);
|
||||
|
||||
/*
|
||||
* Set flag that pg_start_backup() was called. If an error will happen it
|
||||
* is necessary to call pg_stop_backup() in backup_cleanup().
|
||||
*/
|
||||
backup_in_progress = true;
|
||||
pgut_atexit_push(backup_stopbackup_callback, conn);
|
||||
|
||||
/* Extract timeline and LSN from results of pg_start_backup() */
|
||||
XLogDataFromLSN(PQgetvalue(res, 0, 0), &lsn_hi, &lsn_lo);
|
||||
/* Calculate LSN */
|
||||
*start_lsn = ((uint64) lsn_hi )<< 32 | lsn_lo;
|
||||
|
||||
PQclear(res);
|
||||
|
||||
/* TODO !!! */
|
||||
if ((!stream_wal || backup_mode == BACKUP_MODE_DIFF_PAGE) &&
|
||||
/* !backup->from_replica && */
|
||||
!(nodeInfo->server_version < 90600 &&
|
||||
!nodeInfo->is_superuser))
|
||||
/*
|
||||
* Switch to a new WAL segment. It is necessary to get archived WAL
|
||||
* segment, which includes start LSN of current backup.
|
||||
* Don`t do this for replica backups and for PG 9.5 if pguser is not superuser
|
||||
* (because in 9.5 only superuser can switch WAL)
|
||||
*/
|
||||
pg_switch_wal(conn);
|
||||
}
|
||||
|
||||
/*
|
||||
* Switch to a new WAL segment. It should be called only for master.
|
||||
* For PG 9.5 it should be called only if pguser is superuser.
|
||||
|
||||
@@ -821,6 +821,9 @@ extern char *pg_ptrack_get_block(ConnectionArgs *arguments,
|
||||
BlockNumber blknum, size_t *result_size,
|
||||
int ptrack_version_num, const char *ptrack_schema);
|
||||
|
||||
extern XLogRecPtr pg_start_backup(const char *label, bool smooth, PGconn *conn);
|
||||
|
||||
|
||||
/* in catchup.c */
|
||||
extern int do_catchup(char *source_pgdata, char *dest_pgdata, BackupMode backup_mode, ConnectionOptions conn_opt, bool stream_wal, int num_threads);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user