@@ -15,6 +15,9 @@ use super::{BinlogDumpFlags, ComBinlogDump, ComBinlogDumpGtid, Sid};
1515/// Binlog request representation. Please consult MySql documentation.
1616///
1717/// This struct is a helper builder for [`ComBinlogDump`] and [`ComBinlogDumpGtid`].
18+ ///
19+ /// `server_id`, `host`, `port` are inspectable Source server side with:
20+ /// `SHOW SLAVE HOSTS` mysql 5.7 or `SHOW REPLICAS` on mysql 8.x.
1821#[ derive( Debug , Clone , Eq , PartialEq , Hash ) ]
1922pub struct BinlogRequest < ' a > {
2023 /// Server id of a slave.
@@ -25,6 +28,14 @@ pub struct BinlogRequest<'a> {
2528 flags : BinlogDumpFlags ,
2629 /// Filename of the binlog on the master.
2730 filename : Cow < ' a , [ u8 ] > ,
31+ /// Replicat/Slave hostname
32+ ///
33+ /// Defaults to the Empty string.
34+ hostname : Cow < ' a , [ u8 ] > ,
35+ /// Replicat/Slave port
36+ ///
37+ /// Defaults to 0.
38+ port : u16 ,
2839 /// Position in the binlog-file to start the stream with.
2940 ///
3041 /// If `use_gtid` is `false`, then the value will be truncated to u32.
@@ -43,6 +54,8 @@ impl<'a> BinlogRequest<'a> {
4354 filename : Default :: default ( ) ,
4455 pos : 4 ,
4556 sids : vec ! [ ] ,
57+ hostname : Default :: default ( ) ,
58+ port : 0 ,
4659 }
4760 }
4861
@@ -56,6 +69,23 @@ impl<'a> BinlogRequest<'a> {
5669 self . use_gtid
5770 }
5871
72+ /// Returns the hostname to report to the Source server used for replication.
73+ ///
74+ /// Purely informative it's not an information used for connection.
75+ /// Be sure to set something meaningful.
76+ pub fn hostname_raw ( & ' a self ) -> & ' a [ u8 ] {
77+ self . hostname . as_ref ( )
78+ }
79+
80+ /// Returns the hostname to report to the Source server used for replication,
81+ /// as a UTF-8 string (lossy converted).
82+ ///
83+ /// Purely informative it's not an information used for connection.
84+ /// Be sure to set something meaningful.
85+ pub fn hostname ( & ' a self ) -> Cow < ' a , str > {
86+ String :: from_utf8_lossy ( self . hostname . as_ref ( ) )
87+ }
88+
5989 /// If `use_gtid` is `false`, then all flags except `BINLOG_DUMP_NON_BLOCK` will be truncated
6090 /// (defaults to empty).
6191 pub fn flags ( & self ) -> BinlogDumpFlags {
@@ -80,6 +110,13 @@ impl<'a> BinlogRequest<'a> {
80110 self . pos
81111 }
82112
113+ /// Port to report to the Source used for Replication.
114+ ///
115+ /// Purely informative be sure to define the same as the one used for connection.
116+ pub fn port ( & self ) -> u16 {
117+ self . port
118+ }
119+
83120 /// If `use_gtid` is `false`, then this value will be ignored (defaults to an empty vector).
84121 pub fn sids ( & self ) -> & [ Sid < ' _ > ] {
85122 & self . sids
@@ -91,6 +128,25 @@ impl<'a> BinlogRequest<'a> {
91128 self
92129 }
93130
131+ /// Returns modified `self` with the given `host` value,
132+ ///
133+ /// The host value is purely informative and used in mysql replica inspection statements.
134+ pub fn with_hostname ( mut self , hostname : impl Into < Cow < ' a , [ u8 ] > > ) -> Self {
135+ self . hostname = hostname. into ( ) ;
136+ self
137+ }
138+
139+ /// Returns modified `self` with the given `port` value to show in
140+ ///
141+ /// ## Warning
142+ ///
143+ /// Setting a reporting port different of the real port used to stream
144+ /// the binlog will lead replica inspections sql statement to show the port setted here!
145+ pub fn with_port ( mut self , port : u16 ) -> Self {
146+ self . port = port;
147+ self
148+ }
149+
94150 /// Returns modified `self` with the given value of the `use_gtid` field.
95151 pub fn with_use_gtid ( mut self , use_gtid : bool ) -> Self {
96152 self . use_gtid = use_gtid;
0 commit comments