28
28
#include "postmaster/syslogger.h"
29
29
#include "replication/basebackup.h"
30
30
#include "replication/basebackup_sink.h"
31
+ #include "replication/basebackup_target.h"
31
32
#include "replication/backup_manifest.h"
32
33
#include "replication/walsender.h"
33
34
#include "replication/walsender_private.h"
53
54
*/
54
55
#define SINK_BUFFER_LENGTH Max(32768, BLCKSZ)
55
56
56
- typedef enum
57
- {
58
- BACKUP_TARGET_BLACKHOLE ,
59
- BACKUP_TARGET_CLIENT ,
60
- BACKUP_TARGET_SERVER
61
- } backup_target_type ;
62
-
63
57
typedef enum
64
58
{
65
59
BACKUP_COMPRESSION_NONE ,
@@ -77,8 +71,9 @@ typedef struct
77
71
bool includewal ;
78
72
uint32 maxrate ;
79
73
bool sendtblspcmapfile ;
80
- backup_target_type target ;
81
- char * target_detail ;
74
+ bool send_to_client ;
75
+ bool use_copytblspc ;
76
+ BaseBackupTargetHandle * target_handle ;
82
77
backup_manifest_option manifest ;
83
78
basebackup_compression_type compression ;
84
79
int compression_level ;
@@ -715,12 +710,12 @@ parse_basebackup_options(List *options, basebackup_options *opt)
715
710
bool o_manifest_checksums = false;
716
711
bool o_target = false;
717
712
bool o_target_detail = false;
718
- char * target_str = "compat" ; /* placate compiler */
713
+ char * target_str = NULL ;
714
+ char * target_detail_str = NULL ;
719
715
bool o_compression = false;
720
716
bool o_compression_level = false;
721
717
722
718
MemSet (opt , 0 , sizeof (* opt ));
723
- opt -> target = BACKUP_TARGET_CLIENT ;
724
719
opt -> manifest = MANIFEST_OPTION_NO ;
725
720
opt -> manifest_checksum_type = CHECKSUM_TYPE_CRC32C ;
726
721
opt -> compression = BACKUP_COMPRESSION_NONE ;
@@ -864,22 +859,11 @@ parse_basebackup_options(List *options, basebackup_options *opt)
864
859
}
865
860
else if (strcmp (defel -> defname , "target" ) == 0 )
866
861
{
867
- target_str = defGetString (defel );
868
-
869
862
if (o_target )
870
863
ereport (ERROR ,
871
864
(errcode (ERRCODE_SYNTAX_ERROR ),
872
865
errmsg ("duplicate option \"%s\"" , defel -> defname )));
873
- if (strcmp (target_str , "blackhole" ) == 0 )
874
- opt -> target = BACKUP_TARGET_BLACKHOLE ;
875
- else if (strcmp (target_str , "client" ) == 0 )
876
- opt -> target = BACKUP_TARGET_CLIENT ;
877
- else if (strcmp (target_str , "server" ) == 0 )
878
- opt -> target = BACKUP_TARGET_SERVER ;
879
- else
880
- ereport (ERROR ,
881
- (errcode (ERRCODE_SYNTAX_ERROR ),
882
- errmsg ("unrecognized target: \"%s\"" , target_str )));
866
+ target_str = defGetString (defel );
883
867
o_target = true;
884
868
}
885
869
else if (strcmp (defel -> defname , "target_detail" ) == 0 )
@@ -890,7 +874,7 @@ parse_basebackup_options(List *options, basebackup_options *opt)
890
874
ereport (ERROR ,
891
875
(errcode (ERRCODE_SYNTAX_ERROR ),
892
876
errmsg ("duplicate option \"%s\"" , defel -> defname )));
893
- opt -> target_detail = optval ;
877
+ target_detail_str = optval ;
894
878
o_target_detail = true;
895
879
}
896
880
else if (strcmp (defel -> defname , "compression" ) == 0 )
@@ -942,22 +926,28 @@ parse_basebackup_options(List *options, basebackup_options *opt)
942
926
errmsg ("manifest checksums require a backup manifest" )));
943
927
opt -> manifest_checksum_type = CHECKSUM_TYPE_NONE ;
944
928
}
945
- if (opt -> target == BACKUP_TARGET_SERVER )
929
+
930
+ if (target_str == NULL )
946
931
{
947
- if (opt -> target_detail = = NULL )
932
+ if (target_detail_str ! = NULL )
948
933
ereport (ERROR ,
949
934
(errcode (ERRCODE_SYNTAX_ERROR ),
950
- errmsg ("target '%s' requires a target detail" ,
951
- target_str )));
935
+ errmsg ("target detail cannot be used without target" )));
936
+ opt -> use_copytblspc = true;
937
+ opt -> send_to_client = true;
952
938
}
953
- else
939
+ else if ( strcmp ( target_str , "client" ) == 0 )
954
940
{
955
- if (opt -> target_detail != NULL )
941
+ if (target_detail_str != NULL )
956
942
ereport (ERROR ,
957
943
(errcode (ERRCODE_SYNTAX_ERROR ),
958
944
errmsg ("target '%s' does not accept a target detail" ,
959
945
target_str )));
946
+ opt -> send_to_client = true;
960
947
}
948
+ else
949
+ opt -> target_handle =
950
+ BaseBackupGetTargetHandle (target_str , target_detail_str );
961
951
962
952
if (o_compression_level && !o_compression )
963
953
ereport (ERROR ,
@@ -993,32 +983,14 @@ SendBaseBackup(BaseBackupCmd *cmd)
993
983
}
994
984
995
985
/*
996
- * If the TARGET option was specified, then we can use the new copy-stream
997
- * protocol. If the target is specifically 'client' then set up to stream
998
- * the backup to the client; otherwise, it's being sent someplace else and
999
- * should not be sent to the client.
1000
- */
1001
- if (opt .target == BACKUP_TARGET_CLIENT )
1002
- sink = bbsink_copystream_new (true);
1003
- else
1004
- sink = bbsink_copystream_new (false);
1005
-
1006
- /*
1007
- * If a non-default backup target is in use, arrange to send the data
1008
- * wherever it needs to go.
986
+ * If the target is specifically 'client' then set up to stream the backup
987
+ * to the client; otherwise, it's being sent someplace else and should not
988
+ * be sent to the client. BaseBackupGetSink has the job of setting up a
989
+ * sink to send the backup data wherever it needs to go.
1009
990
*/
1010
- switch (opt .target )
1011
- {
1012
- case BACKUP_TARGET_BLACKHOLE :
1013
- /* Nothing to do, just discard data. */
1014
- break ;
1015
- case BACKUP_TARGET_CLIENT :
1016
- /* Nothing to do, handling above is sufficient. */
1017
- break ;
1018
- case BACKUP_TARGET_SERVER :
1019
- sink = bbsink_server_new (sink , opt .target_detail );
1020
- break ;
1021
- }
991
+ sink = bbsink_copystream_new (opt .send_to_client );
992
+ if (opt .target_handle != NULL )
993
+ sink = BaseBackupGetSink (opt .target_handle , sink );
1022
994
1023
995
/* Set up network throttling, if client requested it */
1024
996
if (opt .maxrate > 0 )
0 commit comments