33 * archive.c: - pg_probackup specific archive commands for archive backups.
44 *
55 *
6- * Portions Copyright (c) 2018-2019 , Postgres Professional
6+ * Portions Copyright (c) 2018-2021 , Postgres Professional
77 *
88 *-------------------------------------------------------------------------
99 */
@@ -113,15 +113,13 @@ static parray *setup_push_filelist(const char *archive_status_dir,
113113 * Where archlog_path is $BACKUP_PATH/wal/instance_name
114114 */
115115void
116- do_archive_push (InstanceState * instanceState ,InstanceConfig * instance ,char * wal_file_path ,
116+ do_archive_push (InstanceState * instanceState ,InstanceConfig * instance ,char * pg_xlog_dir ,
117117char * wal_file_name ,int batch_size ,bool overwrite ,
118118bool no_sync ,bool no_ready_rename )
119119{
120120uint64 i ;
121- char current_dir [MAXPGPATH ];
122- char pg_xlog_dir [MAXPGPATH ];
123- char archive_status_dir [MAXPGPATH ];
124- uint64 system_id ;
121+ /* usually instance pgdata/pg_wal/archive_status, empty if no_ready_rename or batch_size == 1 */
122+ char archive_status_dir [MAXPGPATH ]= "" ;
125123bool is_compress = false;
126124
127125/* arrays with meta info for multi threaded backup */
@@ -141,31 +139,8 @@ do_archive_push(InstanceState *instanceState, InstanceConfig *instance, char *wa
141139parray * batch_files = NULL ;
142140int n_threads ;
143141
144- if (wal_file_name == NULL )
145- elog (ERROR ,"Required parameter is not specified: --wal-file-name %%f" );
146-
147- if (!getcwd (current_dir ,sizeof (current_dir )))
148- elog (ERROR ,"getcwd() error" );
149-
150- /* verify that archive-push --instance parameter is valid */
151- system_id = get_system_identifier (current_dir ,FIO_DB_HOST );
152-
153- if (instance -> pgdata == NULL )
154- elog (ERROR ,"Cannot read pg_probackup.conf for this instance" );
155-
156- if (system_id != instance -> system_identifier )
157- elog (ERROR ,"Refuse to push WAL segment %s into archive. Instance parameters mismatch."
158- "Instance '%s' should have SYSTEM_ID = " UINT64_FORMAT " instead of " UINT64_FORMAT ,
159- wal_file_name ,instanceState -> instance_name ,instance -> system_identifier ,system_id );
160-
161- if (instance -> compress_alg == PGLZ_COMPRESS )
162- elog (ERROR ,"Cannot use pglz for WAL compression" );
163-
164- join_path_components (pg_xlog_dir ,current_dir ,XLOGDIR );
165- join_path_components (archive_status_dir ,pg_xlog_dir ,"archive_status" );
166-
167- /* Create 'archlog_path' directory. Do nothing if it already exists. */
168- //fio_mkdir(instanceState->instance_wal_subdir_path, DIR_PERMISSION, FIO_BACKUP_HOST);
142+ if (!no_ready_rename || batch_size > 1 )
143+ join_path_components (archive_status_dir ,pg_xlog_dir ,"archive_status" );
169144
170145#ifdef HAVE_LIBZ
171146if (instance -> compress_alg == ZLIB_COMPRESS )
@@ -204,12 +179,13 @@ do_archive_push(InstanceState *instanceState, InstanceConfig *instance, char *wa
204179{
205180int rc ;
206181WALSegno * xlogfile = (WALSegno * )parray_get (batch_files ,i );
182+ bool first_wal = strcmp (xlogfile -> name ,wal_file_name )== 0 ;
207183
208- rc = push_file (xlogfile ,archive_status_dir ,
184+ rc = push_file (xlogfile ,first_wal ? NULL : archive_status_dir ,
209185pg_xlog_dir ,instanceState -> instance_wal_subdir_path ,
210186overwrite ,no_sync ,
211187instance -> archive_timeout ,
212- no_ready_rename || ( strcmp ( xlogfile -> name , wal_file_name ) == 0 ) ? true : false ,
188+ no_ready_rename || first_wal ,
213189is_compress && IsXLogFileName (xlogfile -> name ) ? true : false,
214190instance -> compress_level );
215191if (rc == 0 )
@@ -233,7 +209,7 @@ do_archive_push(InstanceState *instanceState, InstanceConfig *instance, char *wa
233209arg -> first_filename = wal_file_name ;
234210arg -> archive_dir = instanceState -> instance_wal_subdir_path ;
235211arg -> pg_xlog_dir = pg_xlog_dir ;
236- arg -> archive_status_dir = archive_status_dir ;
212+ arg -> archive_status_dir = (! no_ready_rename || batch_size > 1 ) ? archive_status_dir : NULL ;
237213arg -> overwrite = overwrite ;
238214arg -> compress = is_compress ;
239215arg -> no_sync = no_sync ;
@@ -276,7 +252,7 @@ do_archive_push(InstanceState *instanceState, InstanceConfig *instance, char *wa
276252
277253/* Note, that we are leaking memory here,
278254 * because pushing into archive is a very
279- * time-sensetive operation, so we skip freeing stuff.
255+ * time-sensitive operation, so we skip freeing stuff.
280256 */
281257
282258push_done :
@@ -356,9 +332,6 @@ push_file(WALSegno *xlogfile, const char *archive_status_dir,
356332int compress_level )
357333{
358334int rc ;
359- char wal_file_dummy [MAXPGPATH ];
360-
361- join_path_components (wal_file_dummy ,archive_status_dir ,xlogfile -> name );
362335
363336elog (LOG ,"pushing file \"%s\"" ,xlogfile -> name );
364337
@@ -375,11 +348,13 @@ push_file(WALSegno *xlogfile, const char *archive_status_dir,
375348#endif
376349
377350/* take '--no-ready-rename' flag into account */
378- if (!no_ready_rename )
351+ if (!no_ready_rename && archive_status_dir != NULL )
379352{
353+ char wal_file_dummy [MAXPGPATH ];
380354char wal_file_ready [MAXPGPATH ];
381355char wal_file_done [MAXPGPATH ];
382356
357+ join_path_components (wal_file_dummy ,archive_status_dir ,xlogfile -> name );
383358snprintf (wal_file_ready ,MAXPGPATH ,"%s.%s" ,wal_file_dummy ,"ready" );
384359snprintf (wal_file_done ,MAXPGPATH ,"%s.%s" ,wal_file_dummy ,"done" );
385360