@@ -457,8 +457,11 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
457457 * It is important that we do this after(!) validation so
458458 * database_map can be trusted.
459459 * NOTE: database_map could be missing for legal reasons, e.g. missing
460- * permissions on pg_database during `backup` and, as long as user do not request
461- * partial restore, it`s OK
460+ * permissions on pg_database during `backup` and, as long as user
461+ * do not request partial restore, it`s OK.
462+ *
463+ * If partial restore is requested and database map doesn't exist,
464+ * throw an error.
462465 */
463466 if (datname_list )
464467 dbOid_exclude_list = get_dbOid_exclude_list (dest_backup , dest_files , datname_list ,
@@ -709,19 +712,22 @@ restore_files(void *arg)
709712 i + 1 , (unsigned long ) parray_num (arguments -> files ),
710713 file -> rel_path );
711714
712- /* only files from pgdata can be skipped by partial restore */
713- if (arguments -> dbOid_exclude_list &&
714- file -> external_dir_num == 0 )
715+ /* Only files from pgdata can be skipped by partial restore */
716+ if (arguments -> dbOid_exclude_list && file -> external_dir_num == 0 )
715717 {
716- /* exclude map is not empty */
718+ /* Check if the file belongs to the database we exclude */
717719 if (parray_bsearch (arguments -> dbOid_exclude_list ,
718720 & file -> dbOid , pgCompareOid ))
719721 {
720- /* got a match, destination file will truncated */
722+ /*
723+ * We cannot simply skip the file, because it may lead to
724+ * failure during WAL redo; hence, create empty file.
725+ */
721726 create_empty_file (FIO_BACKUP_HOST ,
722727 instance_config .pgdata , FIO_DB_HOST , file );
723728
724- elog (VERBOSE , "Exclude file due to partial restore: \"%s\"" , file -> rel_path );
729+ elog (VERBOSE , "Exclude file due to partial restore: \"%s\"" ,
730+ file -> rel_path );
725731 continue ;
726732 }
727733 }
@@ -1176,7 +1182,8 @@ parseRecoveryTargetOptions(const char *target_time,
11761182 return rt ;
11771183}
11781184
1179- /* Return array of dbOids of databases that should not be restored
1185+ /*
1186+ * Return array of dbOids of databases that should not be restored
11801187 * Regardless of what option user used, db-include or db-exclude,
11811188 * we always convert it into exclude_list.
11821189 */
@@ -1191,6 +1198,7 @@ get_dbOid_exclude_list(pgBackup *backup, parray *files,
11911198 bool found_database_map = false;
11921199
11931200 /* make sure that database_map is in backup_content.control */
1201+ // TODO can't we use parray_bsearch here?
11941202 for (i = 0 ; i < parray_num (files ); i ++ )
11951203 {
11961204 pgFile * file = (pgFile * ) parray_get (files , i );
@@ -1203,6 +1211,7 @@ get_dbOid_exclude_list(pgBackup *backup, parray *files,
12031211 }
12041212 }
12051213
1214+ // TODO rephrase error message
12061215 if (!found_database_map )
12071216 elog (ERROR , "Backup %s has missing database_map, partial restore is impossible." ,
12081217 base36enc (backup -> start_time ));
@@ -1215,7 +1224,8 @@ get_dbOid_exclude_list(pgBackup *backup, parray *files,
12151224 elog (ERROR , "Backup %s has empty or mangled database_map, partial restore is impossible." ,
12161225 base36enc (backup -> start_time ));
12171226
1218- /* So we have list of datnames and database_map for it.
1227+ /*
1228+ * So we have a list of datnames and database_map for it.
12191229 * We must construct a list of dbOids to exclude.
12201230 */
12211231 if (partial_restore_type )
@@ -1284,7 +1294,7 @@ get_dbOid_exclude_list(pgBackup *backup, parray *files,
12841294 }
12851295 }
12861296
1287- /* extra sanity, we must be totally sure that list is not empty */
1297+ /* extra sanity: ensure that list is not empty */
12881298 if (!dbOid_exclude_list || parray_num (dbOid_exclude_list ) < 1 )
12891299 elog (ERROR , "Failed to find a match in database_map of backup %s for partial restore" ,
12901300 base36enc (backup -> start_time ));
@@ -1296,6 +1306,8 @@ get_dbOid_exclude_list(pgBackup *backup, parray *files,
12961306}
12971307
12981308/* Compare two Oids */
1309+ // TODO is it overflow safe?
1310+ // TODO move it to dir.c like other compare functions
12991311int
13001312pgCompareOid (const void * f1 , const void * f2 )
13011313{
0 commit comments