Skip to content

Commit a742f2b

Browse files
committed
Stop backup if we can't connect by stream protocol with --stream option.
1 parent c8a6900 commit a742f2b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

backup.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ parray *backup_files_list;
4242
static volatile uint32 total_copy_files_increment;
4343
static uint32 total_files_num;
4444
static PGconn *start_stop_connect = NULL;
45+
static pthread_mutex_t check_stream_mut = PTHREAD_MUTEX_INITIALIZER;
4546

4647
typedef struct
4748
{
@@ -170,7 +171,12 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
170171
pgBackupGetPath(&current, path, lengthof(path), DATABASE_DIR);
171172
join_path_components(dst_backup_path, path, "pg_xlog");
172173
dir_create_dir(dst_backup_path, DIR_PERMISSION);
174+
pthread_mutex_lock(&check_stream_mut);
173175
pthread_create(&stream_thread, NULL, (void *(*)(void *)) StreamLog, dst_backup_path);
176+
pthread_mutex_lock(&check_stream_mut);
177+
if (conn == NULL)
178+
elog(ERROR, "I can't continue work because stream connect has failed.");
179+
pthread_mutex_unlock(&check_stream_mut);
174180
}
175181

176182
if(!from_replica)
@@ -1457,8 +1463,11 @@ StreamLog(void *arg)
14571463
if (conn == NULL)
14581464
conn = GetConnection();
14591465
if (!conn)
1466+
{
1467+
pthread_mutex_unlock(&check_stream_mut);
14601468
/* Error message already written in GetConnection() */
14611469
return;
1470+
}
14621471

14631472
if (!CheckServerVersionForStreaming(conn))
14641473
{
@@ -1478,6 +1487,8 @@ StreamLog(void *arg)
14781487
if (!RunIdentifySystem(conn, NULL, &starttli, &startpos, NULL))
14791488
disconnect_and_exit(1);
14801489

1490+
/* Ok we have normal stream connect and main process can work again */
1491+
pthread_mutex_unlock(&check_stream_mut);
14811492
/*
14821493
* We must use startpos as start_lsn from start_backup
14831494
*/

0 commit comments

Comments
 (0)