@@ -164,7 +164,7 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
164
164
control_file [MAXPGPATH ];
165
165
parray * files ,
166
166
* to_files ;
167
- pthread_t * threads ;
167
+ pthread_t * threads = NULL ;
168
168
merge_files_arg * threads_args ;
169
169
int i ;
170
170
bool merge_isok = true;
@@ -193,19 +193,6 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
193
193
if (from_backup -> status == BACKUP_STATUS_CORRUPT )
194
194
elog (ERROR , "Interrupt merging" );
195
195
196
- /*
197
- * Previous merging was interrupted during deleting source backup. It is
198
- * safe just to delete it again.
199
- */
200
- if (from_backup -> status == BACKUP_STATUS_DELETING )
201
- goto delete_source_backup ;
202
-
203
- to_backup -> status = BACKUP_STATUS_MERGING ;
204
- write_backup_status (to_backup );
205
-
206
- from_backup -> status = BACKUP_STATUS_MERGING ;
207
- write_backup_status (from_backup );
208
-
209
196
/*
210
197
* Make backup paths.
211
198
*/
@@ -216,8 +203,6 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
216
203
pgBackupGetPath (from_backup , from_database_path , lengthof (from_database_path ),
217
204
DATABASE_DIR );
218
205
219
- create_data_directories (to_database_path , from_backup_path , false);
220
-
221
206
/*
222
207
* Get list of files which will be modified or removed.
223
208
*/
@@ -238,6 +223,21 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
238
223
/* sort by size for load balancing */
239
224
parray_qsort (files , pgFileCompareSize );
240
225
226
+ /*
227
+ * Previous merging was interrupted during deleting source backup. It is
228
+ * safe just to delete it again.
229
+ */
230
+ if (from_backup -> status == BACKUP_STATUS_DELETING )
231
+ goto delete_source_backup ;
232
+
233
+ to_backup -> status = BACKUP_STATUS_MERGING ;
234
+ write_backup_status (to_backup );
235
+
236
+ from_backup -> status = BACKUP_STATUS_MERGING ;
237
+ write_backup_status (from_backup );
238
+
239
+ create_data_directories (to_database_path , from_backup_path , false);
240
+
241
241
threads = (pthread_t * ) palloc (sizeof (pthread_t ) * num_threads );
242
242
threads_args = (merge_files_arg * ) palloc (sizeof (merge_files_arg ) * num_threads );
243
243
@@ -344,8 +344,11 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
344
344
write_backup (to_backup );
345
345
346
346
/* Cleanup */
347
- pfree (threads_args );
348
- pfree (threads );
347
+ if (threads )
348
+ {
349
+ pfree (threads_args );
350
+ pfree (threads );
351
+ }
349
352
350
353
parray_walk (to_files , pgFileFree );
351
354
parray_free (to_files );
0 commit comments