diff --git a/src/backup.c b/src/backup.c index 2317bee9..380dc1c0 100644 --- a/src/backup.c +++ b/src/backup.c @@ -22,6 +22,7 @@ #include #include "utils/thread.h" +#include #define PG_STOP_BACKUP_TIMEOUT 300 @@ -474,6 +475,7 @@ do_backup_instance(void) pgBackup *prev_backup = NULL; parray *prev_backup_filelist = NULL; + parray *backup_list = NULL; pgFile *pg_control = NULL; @@ -515,7 +517,6 @@ do_backup_instance(void) current.backup_mode == BACKUP_MODE_DIFF_PTRACK || current.backup_mode == BACKUP_MODE_DIFF_DELTA) { - parray *backup_list; char prev_backup_filelist_path[MAXPGPATH]; /* get list of backups already taken */ @@ -525,7 +526,6 @@ do_backup_instance(void) if (prev_backup == NULL) elog(ERROR, "Valid backup on current timeline is not found. " "Create new FULL backup before an incremental one."); - parray_free(backup_list); pgBackupGetPath(prev_backup, prev_backup_filelist_path, lengthof(prev_backup_filelist_path), DATABASE_FILE_LIST); @@ -832,6 +832,13 @@ do_backup_instance(void) current.data_bytes += file->write_size; } + /* Cleanup */ + if (backup_list) + { + parray_walk(backup_list, pgBackupFree); + parray_free(backup_list); + } + parray_walk(backup_files_list, pgFileFree); parray_free(backup_files_list); backup_files_list = NULL; diff --git a/src/parsexlog.c b/src/parsexlog.c index ee7b5076..ed73f70c 100644 --- a/src/parsexlog.c +++ b/src/parsexlog.c @@ -22,6 +22,7 @@ #endif #include "utils/thread.h" +#include /* * RmgrNames is an array of resource manager names, to make error messages diff --git a/src/pg_probackup.c b/src/pg_probackup.c index 00b0fc42..e8240e19 100644 --- a/src/pg_probackup.c +++ b/src/pg_probackup.c @@ -16,6 +16,7 @@ #include #include "utils/thread.h" +#include const char *PROGRAM_VERSION = "2.0.24"; const char *PROGRAM_URL = "https://github.com/postgrespro/pg_probackup"; diff --git a/src/pg_probackup.h b/src/pg_probackup.h index ca45d604..0fad6d70 100644 --- a/src/pg_probackup.h +++ b/src/pg_probackup.h @@ -418,7 +418,6 @@ extern int do_restore_or_validate(time_t target_backup_id, extern bool satisfy_timeline(const parray *timelines, const pgBackup *backup); extern bool satisfy_recovery_target(const pgBackup *backup, const pgRecoveryTarget *rt); -extern parray * readTimeLineHistory_probackup(TimeLineID targetTLI); extern pgRecoveryTarget *parseRecoveryTargetOptions( const char *target_time, const char *target_xid, const char *target_inclusive, TimeLineID target_tli, const char* target_lsn, diff --git a/src/restore.c b/src/restore.c index 439f3c4e..9cf33515 100644 --- a/src/restore.c +++ b/src/restore.c @@ -33,6 +33,7 @@ static void restore_backup(pgBackup *backup); static void create_recovery_conf(time_t backup_id, pgRecoveryTarget *rt, pgBackup *backup); +static parray *read_timeline_history(TimeLineID targetTLI); static void *restore_files(void *arg); static void remove_deleted_files(pgBackup *backup); @@ -138,7 +139,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt, elog(LOG, "target timeline ID = %u", rt->recovery_target_tli); /* Read timeline history files from archives */ - timelines = readTimeLineHistory_probackup(rt->recovery_target_tli); + timelines = read_timeline_history(rt->recovery_target_tli); if (!satisfy_timeline(timelines, current_backup)) { @@ -149,6 +150,9 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt, /* Try to find another backup that satisfies target timeline */ continue; } + + parray_walk(timelines, pfree); + parray_free(timelines); } if (!satisfy_recovery_target(current_backup, rt)) @@ -731,7 +735,7 @@ create_recovery_conf(time_t backup_id, * based on readTimeLineHistory() in timeline.c */ parray * -readTimeLineHistory_probackup(TimeLineID targetTLI) +read_timeline_history(TimeLineID targetTLI) { parray *result; char path[MAXPGPATH]; @@ -820,8 +824,7 @@ readTimeLineHistory_probackup(TimeLineID targetTLI) entry = pgut_new(TimeLineHistoryEntry); entry->tli = targetTLI; /* LSN in target timeline is valid */ - /* TODO ensure that -1UL --> -1L fix is correct */ - entry->end = (uint32) (-1L << 32) | -1L; + entry->end = InvalidXLogRecPtr; parray_insert(result, 0, entry); return result; @@ -853,7 +856,8 @@ satisfy_timeline(const parray *timelines, const pgBackup *backup) timeline = (TimeLineHistoryEntry *) parray_get(timelines, i); if (backup->tli == timeline->tli && - backup->stop_lsn < timeline->end) + (XLogRecPtrIsInvalid(timeline->end) || + backup->stop_lsn < timeline->end)) return true; } return false; diff --git a/src/utils/logger.c b/src/utils/logger.c index 4cdbf721..05f6fc5b 100644 --- a/src/utils/logger.c +++ b/src/utils/logger.c @@ -14,6 +14,7 @@ #include "logger.h" #include "pgut.h" #include "thread.h" +#include /* Logger parameters */ diff --git a/src/utils/thread.c b/src/utils/thread.c index 82c23764..0999a0d5 100644 --- a/src/utils/thread.c +++ b/src/utils/thread.c @@ -9,8 +9,11 @@ #include "thread.h" +#ifdef WIN32 +DWORD main_tid = 0; +#else pthread_t main_tid = 0; - +#endif #ifdef WIN32 #include diff --git a/src/utils/thread.h b/src/utils/thread.h index 06460533..6b8349bf 100644 --- a/src/utils/thread.h +++ b/src/utils/thread.h @@ -28,7 +28,13 @@ extern int pthread_join(pthread_t th, void **thread_return); #include #endif +#ifdef WIN32 +extern DWORD main_tid; +#else extern pthread_t main_tid; +#endif + + extern int pthread_lock(pthread_mutex_t *mp);