@@ -89,14 +89,11 @@ unlink_lock_atexit(void)
89
89
* If no backup matches, return NULL.
90
90
*/
91
91
pgBackup *
92
- read_backup (const char * instance_name , time_t timestamp )
92
+ read_backup (const char * root_dir )
93
93
{
94
- pgBackup tmp ;
95
94
char conf_path [MAXPGPATH ];
96
95
97
- tmp .start_time = timestamp ;
98
- pgBackupGetPathInInstance (instance_name , & tmp , conf_path ,
99
- lengthof (conf_path ), BACKUP_CONTROL_FILE , NULL );
96
+ join_path_components (conf_path , root_dir , BACKUP_CONTROL_FILE );
100
97
101
98
return readBackupControlFile (conf_path );
102
99
}
@@ -109,11 +106,11 @@ read_backup(const char *instance_name, time_t timestamp)
109
106
*/
110
107
void
111
108
write_backup_status (pgBackup * backup , BackupStatus status ,
112
- const char * instance_name )
109
+ const char * instance_name , bool strict )
113
110
{
114
111
pgBackup * tmp ;
115
112
116
- tmp = read_backup (instance_name , backup -> start_time );
113
+ tmp = read_backup (backup -> root_dir );
117
114
if (!tmp )
118
115
{
119
116
/*
@@ -125,7 +122,9 @@ write_backup_status(pgBackup *backup, BackupStatus status,
125
122
126
123
backup -> status = status ;
127
124
tmp -> status = backup -> status ;
128
- write_backup (tmp );
125
+ tmp -> root_dir = pgut_strdup (backup -> root_dir );
126
+
127
+ write_backup (tmp , strict );
129
128
130
129
pgBackupFree (tmp );
131
130
}
@@ -134,7 +133,7 @@ write_backup_status(pgBackup *backup, BackupStatus status,
134
133
* Create exclusive lockfile in the backup's directory.
135
134
*/
136
135
bool
137
- lock_backup (pgBackup * backup )
136
+ lock_backup (pgBackup * backup , bool strict )
138
137
{
139
138
char lock_file [MAXPGPATH ];
140
139
int fd ;
@@ -280,6 +279,14 @@ lock_backup(pgBackup *backup)
280
279
fio_unlink (lock_file , FIO_BACKUP_HOST );
281
280
/* if write didn't set errno, assume problem is no disk space */
282
281
errno = save_errno ? save_errno : ENOSPC ;
282
+
283
+ /* In lax mode if we failed to grab lock because of 'out of space error',
284
+ * then treat backup as locked.
285
+ * Only delete command should be run in lax mode.
286
+ */
287
+ if (!strict && errno == ENOSPC )
288
+ return true;
289
+
283
290
elog (ERROR , "Could not write lock file \"%s\": %s" ,
284
291
lock_file , strerror (errno ));
285
292
}
@@ -536,7 +543,7 @@ get_backup_filelist(pgBackup *backup)
536
543
parray * files = NULL ;
537
544
char backup_filelist_path [MAXPGPATH ];
538
545
539
- pgBackupGetPath ( backup , backup_filelist_path , lengthof ( backup_filelist_path ) , DATABASE_FILE_LIST );
546
+ join_path_components ( backup_filelist_path , backup -> root_dir , DATABASE_FILE_LIST );
540
547
files = dir_read_file_list (NULL , NULL , backup_filelist_path , FIO_BACKUP_HOST );
541
548
542
549
/* redundant sanity? */
@@ -550,7 +557,7 @@ get_backup_filelist(pgBackup *backup)
550
557
* Lock list of backups. Function goes in backward direction.
551
558
*/
552
559
void
553
- catalog_lock_backup_list (parray * backup_list , int from_idx , int to_idx )
560
+ catalog_lock_backup_list (parray * backup_list , int from_idx , int to_idx , bool strict )
554
561
{
555
562
int start_idx ,
556
563
end_idx ;
@@ -565,7 +572,7 @@ catalog_lock_backup_list(parray *backup_list, int from_idx, int to_idx)
565
572
for (i = start_idx ; i >= end_idx ; i -- )
566
573
{
567
574
pgBackup * backup = (pgBackup * ) parray_get (backup_list , i );
568
- if (!lock_backup (backup ))
575
+ if (!lock_backup (backup , strict ))
569
576
elog (ERROR , "Cannot lock backup %s directory" ,
570
577
base36enc (backup -> start_time ));
571
578
}
@@ -837,7 +844,7 @@ pgBackupCreateDir(pgBackup *backup)
837
844
/* create directories for actual backup files */
838
845
for (i = 0 ; i < parray_num (subdirs ); i ++ )
839
846
{
840
- pgBackupGetPath ( backup , path , lengthof ( path ) , parray_get (subdirs , i ));
847
+ join_path_components ( path , backup -> root_dir , parray_get (subdirs , i ));
841
848
fio_mkdir (path , DIR_PERMISSION , FIO_BACKUP_HOST );
842
849
}
843
850
@@ -1580,7 +1587,7 @@ pin_backup(pgBackup *target_backup, pgSetBackupParams *set_backup_params)
1580
1587
return ;
1581
1588
1582
1589
/* Update backup.control */
1583
- write_backup (target_backup );
1590
+ write_backup (target_backup , true );
1584
1591
1585
1592
if (set_backup_params -> ttl > 0 || set_backup_params -> expire_time > 0 )
1586
1593
{
@@ -1630,7 +1637,7 @@ add_note(pgBackup *target_backup, char *note)
1630
1637
}
1631
1638
1632
1639
/* Update backup.control */
1633
- write_backup (target_backup );
1640
+ write_backup (target_backup , true );
1634
1641
}
1635
1642
1636
1643
/*
@@ -1735,27 +1742,34 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
1735
1742
* Save the backup content into BACKUP_CONTROL_FILE.
1736
1743
*/
1737
1744
void
1738
- write_backup (pgBackup * backup )
1745
+ write_backup (pgBackup * backup , bool strict )
1739
1746
{
1740
- FILE * fp = NULL ;
1741
- char path [MAXPGPATH ];
1742
- char path_temp [MAXPGPATH ];
1743
- int errno_temp ;
1747
+ FILE * fp = NULL ;
1748
+ char path [MAXPGPATH ];
1749
+ char path_temp [MAXPGPATH ];
1750
+ int errno_temp ;
1751
+ char buf [4096 ];
1744
1752
1745
- pgBackupGetPath ( backup , path , lengthof ( path ) , BACKUP_CONTROL_FILE );
1753
+ join_path_components ( path , backup -> root_dir , BACKUP_CONTROL_FILE );
1746
1754
snprintf (path_temp , sizeof (path_temp ), "%s.tmp" , path );
1747
1755
1748
1756
fp = fio_fopen (path_temp , PG_BINARY_W , FIO_BACKUP_HOST );
1749
1757
if (fp == NULL )
1750
1758
elog (ERROR , "Cannot open configuration file \"%s\": %s" ,
1751
1759
path_temp , strerror (errno ));
1752
1760
1761
+ setvbuf (fp , buf , _IOFBF , sizeof (buf ));
1762
+
1753
1763
pgBackupWriteControl (fp , backup );
1754
1764
1755
- if (fio_fflush ( fp ) || fio_fclose (fp ))
1765
+ if (fio_fclose (fp ))
1756
1766
{
1757
1767
errno_temp = errno ;
1758
1768
fio_unlink (path_temp , FIO_BACKUP_HOST );
1769
+
1770
+ if (!strict && errno_temp == ENOSPC )
1771
+ return ;
1772
+
1759
1773
elog (ERROR , "Cannot write configuration file \"%s\": %s" ,
1760
1774
path_temp , strerror (errno_temp ));
1761
1775
}
@@ -1788,7 +1802,7 @@ write_backup_filelist(pgBackup *backup, parray *files, const char *root,
1788
1802
int64 uncompressed_size_on_disk = 0 ;
1789
1803
int64 wal_size_on_disk = 0 ;
1790
1804
1791
- pgBackupGetPath ( backup , path , lengthof ( path ) , DATABASE_FILE_LIST );
1805
+ join_path_components ( path , backup -> root_dir , DATABASE_FILE_LIST );
1792
1806
snprintf (path_temp , sizeof (path_temp ), "%s.tmp" , path );
1793
1807
1794
1808
out = fio_fopen (path_temp , PG_BINARY_W , FIO_BACKUP_HOST );
0 commit comments