Skip to content

Commit 3013a78

Browse files
authored
Release 2 5 pg stop backup decomposition2 (#387)
* Rename pg_checksum_enable() to pg_is_checksum_enabled * Remove unused instanceState from pg_start_backup() * Refactor wait_wal_lsn(): remove unused pgBackup * parameter and replace InstanceState * with simple directory string * Refactor pg_stop_backup(): remove useless conn variable * Make some functions and variables (from backup.c) accessible from other compilation units * Remove some references to global stream_wal variable * Remove unused variable externaldir * Yet another split of pg_stop_backup(): separate verification of stop_lsn into wait_wal_and_calculate_stop_lsn() * Create pfilearray_clear_locks() helper function
1 parent 151d499 commit 3013a78

File tree

8 files changed

+257
-250
lines changed

8 files changed

+257
-250
lines changed

src/backup.c

+191-234
Large diffs are not rendered by default.

src/checkdb.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -455,14 +455,15 @@ get_index_list(const char *dbname, bool first_db_with_amcheck,
455455
ind->heapallindexed_is_supported = heapallindexed_is_supported;
456456
ind->amcheck_nspname = pgut_malloc(strlen(amcheck_nspname) + 1);
457457
strcpy(ind->amcheck_nspname, amcheck_nspname);
458-
pg_atomic_clear_flag(&ind->lock);
459458

460459
if (index_list == NULL)
461460
index_list = parray_new();
462461

463462
parray_append(index_list, ind);
464463
}
465464

465+
pfilearray_clear_locks(index_list);
466+
466467
PQclear(res);
467468

468469
return index_list;

src/dir.c

+16
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ pgFileInit(const char *rel_path)
222222
/* Number of blocks backed up during backup */
223223
file->n_headers = 0;
224224

225+
// May be add?
226+
// pg_atomic_clear_flag(file->lock);
225227
return file;
226228
}
227229

@@ -1859,3 +1861,17 @@ cleanup_tablespace(const char *path)
18591861
parray_walk(files, pgFileFree);
18601862
parray_free(files);
18611863
}
1864+
1865+
/*
1866+
* Clear the synchronisation locks in a parray of (pgFile *)'s
1867+
*/
1868+
void
1869+
pfilearray_clear_locks(parray *file_list)
1870+
{
1871+
int i;
1872+
for (i = 0; i < parray_num(file_list); i++)
1873+
{
1874+
pgFile *file = (pgFile *) parray_get(file_list, i);
1875+
pg_atomic_clear_flag(&file->lock);
1876+
}
1877+
}

src/pg_probackup.c

-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ static char *backup_path = NULL;
6868
static CatalogState *catalogState = NULL;
6969
/* ================ catalogState (END) =========== */
7070

71-
/* colon separated external directories list ("/path1:/path2") */
72-
char *externaldir = NULL;
7371
/* common options */
7472
int num_threads = 1;
7573
bool stream_wal = false;

src/pg_probackup.h

+42-3
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,6 @@ typedef struct
600600
int ret;
601601
} backup_files_arg;
602602

603-
604603
typedef struct timelineInfo timelineInfo;
605604

606605
/* struct to collect info about timelines in WAL archive */
@@ -679,10 +678,11 @@ typedef struct BackupPageHeader2
679678
uint16 checksum;
680679
} BackupPageHeader2;
681680

682-
typedef struct StopBackupCallbackState {
681+
typedef struct StopBackupCallbackParams
682+
{
683683
PGconn *conn;
684684
int server_version;
685-
} StopBackupCallbackState;
685+
} StopBackupCallbackParams;
686686

687687
/* Special value for compressed_size field */
688688
#define PageIsOk 0
@@ -1061,6 +1061,7 @@ extern int pgFileCompareRelPathWithExternalDesc(const void *f1, const void *f2);
10611061
extern int pgFileCompareLinked(const void *f1, const void *f2);
10621062
extern int pgFileCompareSize(const void *f1, const void *f2);
10631063
extern int pgCompareOid(const void *f1, const void *f2);
1064+
extern void pfilearray_clear_locks(parray *file_list);
10641065

10651066
/* in data.c */
10661067
extern bool check_data_file(ConnectionArgs *arguments, pgFile *file,
@@ -1259,4 +1260,42 @@ extern void start_WAL_streaming(PGconn *backup_conn, char *stream_dst_path,
12591260
ConnectionOptions *conn_opt,
12601261
XLogRecPtr startpos, TimeLineID starttli);
12611262
extern int wait_WAL_streaming_end(parray *backup_files_list);
1263+
1264+
/* external variables and functions, implemented in backup.c */
1265+
typedef struct PGStopBackupResult
1266+
{
1267+
/*
1268+
* We will use values of snapshot_xid and invocation_time if there are
1269+
* no transactions between start_lsn and stop_lsn.
1270+
*/
1271+
TransactionId snapshot_xid;
1272+
time_t invocation_time;
1273+
/*
1274+
* Fields that store pg_catalog.pg_stop_backup() result
1275+
*/
1276+
XLogRecPtr lsn;
1277+
size_t backup_label_content_len;
1278+
char *backup_label_content;
1279+
size_t tablespace_map_content_len;
1280+
char *tablespace_map_content;
1281+
} PGStopBackupResult;
1282+
1283+
extern bool backup_in_progress;
1284+
extern parray *backup_files_list;
1285+
1286+
extern void pg_start_backup(const char *label, bool smooth, pgBackup *backup,
1287+
PGNodeInfo *nodeInfo, PGconn *conn);
1288+
extern void pg_silent_client_messages(PGconn *conn);
1289+
extern void pg_create_restore_point(PGconn *conn, time_t backup_start_time);
1290+
extern void pg_stop_backup_send(PGconn *conn, int server_version, bool is_started_on_replica, bool is_exclusive, char **query_text);
1291+
extern void pg_stop_backup_consume(PGconn *conn, int server_version,
1292+
bool is_exclusive, uint32 timeout, const char *query_text,
1293+
PGStopBackupResult *result);
1294+
extern void pg_stop_backup_write_file_helper(const char *path, const char *filename, const char *error_msg_filename,
1295+
const void *data, size_t len, parray *file_list);
1296+
extern XLogRecPtr wait_wal_lsn(const char *wal_segment_dir, XLogRecPtr lsn, bool is_start_lsn, TimeLineID tli,
1297+
bool in_prev_segment, bool segment_only,
1298+
int timeout_elevel, bool in_stream_dir);
1299+
extern void wait_wal_and_calculate_stop_lsn(const char *xlog_path, XLogRecPtr stop_lsn, pgBackup *backup);
1300+
12621301
#endif /* PG_PROBACKUP_H */

src/restore.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ restore_chain(pgBackup *dest_backup, parray *parent_chain,
824824
}
825825

826826
/*
827-
* Setup directory structure for external directories and file locks
827+
* Setup directory structure for external directories
828828
*/
829829
for (i = 0; i < parray_num(dest_files); i++)
830830
{
@@ -848,11 +848,11 @@ restore_chain(pgBackup *dest_backup, parray *parent_chain,
848848
elog(VERBOSE, "Create external directory \"%s\"", dirpath);
849849
fio_mkdir(dirpath, file->mode, FIO_DB_HOST);
850850
}
851-
852-
/* setup threads */
853-
pg_atomic_clear_flag(&file->lock);
854851
}
855852

853+
/* setup threads */
854+
pfilearray_clear_locks(dest_files);
855+
856856
/* Get list of files in destination directory and remove redundant files */
857857
if (params->incremental_mode != INCR_NONE || cleanup_pgdata)
858858
{

src/utils/parray.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ parray_rm(parray *array, const void *key, int(*compare)(const void *, const void
175175
size_t
176176
parray_num(const parray *array)
177177
{
178-
return array->used;
178+
return array!= NULL ? array->used : (size_t) 0;
179179
}
180180

181181
void

src/validate.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,7 @@ pgBackupValidate(pgBackup *backup, pgRestoreParams *params)
130130
// params->partial_restore_type);
131131

132132
/* setup threads */
133-
for (i = 0; i < parray_num(files); i++)
134-
{
135-
pgFile *file = (pgFile *) parray_get(files, i);
136-
pg_atomic_clear_flag(&file->lock);
137-
}
133+
pfilearray_clear_locks(files);
138134

139135
/* init thread args with own file lists */
140136
threads = (pthread_t *) palloc(sizeof(pthread_t) * num_threads);

0 commit comments

Comments
 (0)