Skip to content

Commit

Permalink
Expose replica/slave host/port for reporting
Browse files Browse the repository at this point in the history
Followup of blackbeam/rust_mysql_common#96
it's possible to inspect them with show slave hosts/ show replicas
  • Loading branch information
darnuria authored and Axel Viala committed Jul 20, 2023
1 parent ddee16e commit 1101529
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/conn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,12 +1169,19 @@ impl Conn {
Ok(self)
}

async fn register_as_slave(&mut self, server_id: u32) -> Result<()> {
async fn register_as_slave<'a>(
&mut self,
server_id: u32,
hostname: impl Into<Cow<'a, [u8]>>,
port: u16,
) -> Result<()> {
use mysql_common::packets::ComRegisterSlave;

let cmd_register_slave = ComRegisterSlave::new(server_id)
.with_hostname(hostname)
.with_port(port);
self.query_drop("SET @master_binlog_checksum='ALL'").await?;
self.write_command(&ComRegisterSlave::new(server_id))
.await?;
self.write_command(&cmd_register_slave).await?;

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

async fn request_binlog(&mut self, request: BinlogRequest<'_>) -> Result<()> {
self.register_as_slave(request.server_id()).await?;
self.register_as_slave(request.server_id(), request.hostname_raw(), request.port())
.await?;
self.write_command(&request.as_cmd()).await?;
Ok(())
}
Expand Down

0 comments on commit 1101529

Please sign in to comment.