Skip to content

Commit

Permalink
Improve Cassandra new connection errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai committed Oct 6, 2022
1 parent 96a015c commit 5b04f38
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
11 changes: 9 additions & 2 deletions shotover-proxy/src/transforms/cassandra/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ impl CassandraConnection {
pushed_messages_tx: Option<mpsc::UnboundedSender<Messages>>,
) -> Result<Self> {
let tcp_stream = timeout(Duration::from_secs(3), TcpStream::connect(&host))
.await?
.await
.map_err(|_| {
anyhow!(
"Cassandra node at {:?} did not respond to connection attempt within 3 seconds",
host
)
})?
.map_err(|e| {
anyhow::Error::new(e).context(format!("Failed to connect to upstream: {:?}", host))
anyhow::Error::new(e)
.context(format!("Failed to connect to cassandra node: {:?}", host))
})?;

let (out_tx, out_rx) = mpsc::unbounded_channel::<Request>();
Expand Down
25 changes: 20 additions & 5 deletions shotover-proxy/src/transforms/cassandra/sink_cluster/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,33 @@ impl ConnectionFactory {
self.tls.clone(),
self.pushed_messages_tx.clone(),
)
.await?;
.await
.map_err(|e| e.context("Failed to create new connection"))?;

for handshake_message in &self.init_handshake {
let (return_chan_tx, return_chan_rx) = oneshot::channel();
outbound.send(handshake_message.clone(), return_chan_tx)?;
return_chan_rx.await?;
outbound
.send(handshake_message.clone(), return_chan_tx)
.map_err(|e| {
anyhow!(e)
.context("Failed to initialize new connection with handshake, rx failed")
})?;
return_chan_rx.await.map_err(|e| {
anyhow!(e).context("Failed to initialize new connection with handshake, rx failed")
})?;
}

if let Some(use_message) = &self.use_message {
let (return_chan_tx, return_chan_rx) = oneshot::channel();
outbound.send(use_message.clone(), return_chan_tx)?;
return_chan_rx.await?;
outbound
.send(use_message.clone(), return_chan_tx)
.map_err(|e| {
anyhow!(e)
.context("Failed to initialize new connection with use message, rx failed")
})?;
return_chan_rx.await.map_err(|e| {
anyhow!(e).context("Failed to initialize new connection with handshake, rx failed")
})?;
}

Ok(outbound)
Expand Down

0 comments on commit 5b04f38

Please sign in to comment.