Skip to content

Commit 1101529

Browse files
darnuriaAxel Viala
authored andcommitted
Expose replica/slave host/port for reporting
Followup of blackbeam/rust_mysql_common#96 it's possible to inspect them with show slave hosts/ show replicas
1 parent ddee16e commit 1101529

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/conn/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,12 +1169,19 @@ impl Conn {
11691169
Ok(self)
11701170
}
11711171

1172-
async fn register_as_slave(&mut self, server_id: u32) -> Result<()> {
1172+
async fn register_as_slave<'a>(
1173+
&mut self,
1174+
server_id: u32,
1175+
hostname: impl Into<Cow<'a, [u8]>>,
1176+
port: u16,
1177+
) -> Result<()> {
11731178
use mysql_common::packets::ComRegisterSlave;
11741179

1180+
let cmd_register_slave = ComRegisterSlave::new(server_id)
1181+
.with_hostname(hostname)
1182+
.with_port(port);
11751183
self.query_drop("SET @master_binlog_checksum='ALL'").await?;
1176-
self.write_command(&ComRegisterSlave::new(server_id))
1177-
.await?;
1184+
self.write_command(&cmd_register_slave).await?;
11781185

11791186
// Server will respond with OK.
11801187
self.read_packet().await?;
@@ -1183,7 +1190,8 @@ impl Conn {
11831190
}
11841191

11851192
async fn request_binlog(&mut self, request: BinlogRequest<'_>) -> Result<()> {
1186-
self.register_as_slave(request.server_id()).await?;
1193+
self.register_as_slave(request.server_id(), request.hostname_raw(), request.port())
1194+
.await?;
11871195
self.write_command(&request.as_cmd()).await?;
11881196
Ok(())
11891197
}

0 commit comments

Comments
 (0)