@@ -421,6 +421,8 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
421421 int partial_try_count = 0 ;
422422 int partial_file_size = 0 ;
423423 bool partial_is_stale = true;
424+ /* remote agent error message */
425+ char * errmsg = NULL ;
424426
425427 /* from path */
426428 join_path_components (from_fullpath , pg_xlog_dir , wal_file_name );
@@ -579,7 +581,7 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
579581 from_fullpath , strerror (errno ));
580582 }
581583
582- if (read_len > 0 && fio_write (out , buf , read_len ) != read_len )
584+ if (read_len > 0 && fio_write_async (out , buf , read_len ) != read_len )
583585 {
584586 fio_unlink (to_fullpath_part , FIO_BACKUP_HOST );
585587 elog (ERROR , "Cannot write to destination temp file \"%s\": %s" ,
@@ -593,6 +595,14 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
593595 /* close source file */
594596 fclose (in );
595597
598+ /* Writing is asynchronous in case of push in remote mode, so check agent status */
599+ if (fio_check_error_fd (out , & errmsg ))
600+ {
601+ fio_unlink (to_fullpath_part , FIO_BACKUP_HOST );
602+ elog (ERROR , "Cannot write to the remote file \"%s\": %s" ,
603+ to_fullpath_part , errmsg );
604+ }
605+
596606 /* close temp file */
597607 if (fio_close (out ) != 0 )
598608 {
@@ -652,6 +662,8 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
652662 int partial_try_count = 0 ;
653663 int partial_file_size = 0 ;
654664 bool partial_is_stale = true;
665+ /* remote agent errormsg */
666+ char * errmsg = NULL ;
655667
656668 /* from path */
657669 join_path_components (from_fullpath , pg_xlog_dir , wal_file_name );
@@ -804,6 +816,7 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
804816 }
805817
806818 /* copy content */
819+ /* TODO: move to separate function */
807820 for (;;)
808821 {
809822 size_t read_len = 0 ;
@@ -831,7 +844,15 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
831844 /* close source file */
832845 fclose (in );
833846
834- /* close temp file */
847+ /* Writing is asynchronous in case of push in remote mode, so check agent status */
848+ if (fio_check_error_fd_gz (out , & errmsg ))
849+ {
850+ fio_unlink (to_fullpath_gz_part , FIO_BACKUP_HOST );
851+ elog (ERROR , "Cannot write to the remote compressed file \"%s\": %s" ,
852+ to_fullpath_gz_part , errmsg );
853+ }
854+
855+ /* close temp file, TODO: make it synchronous */
835856 if (fio_gzclose (out ) != 0 )
836857 {
837858 fio_unlink (to_fullpath_gz_part , FIO_BACKUP_HOST );
0 commit comments