-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
63 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
shotover-proxy/src/transforms/cassandra/sink_cluster/node.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use crate::codec::cassandra::CassandraCodec; | ||
use crate::message::{Message, Messages}; | ||
use crate::tls::TlsConnector; | ||
use crate::transforms::cassandra::connection::CassandraConnection; | ||
use anyhow::Result; | ||
use std::net::IpAddr; | ||
use tokio::net::ToSocketAddrs; | ||
use tokio::sync::{mpsc, oneshot}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct CassandraNode { | ||
pub address: IpAddr, | ||
pub _rack: String, | ||
pub _tokens: Vec<String>, | ||
pub outbound: Option<CassandraConnection>, | ||
} | ||
|
||
impl CassandraNode { | ||
pub async fn get_connection( | ||
&mut self, | ||
handshake: &[Message], | ||
tls: &Option<TlsConnector>, | ||
pushed_messages_tx: &Option<mpsc::UnboundedSender<Messages>>, | ||
) -> Result<&mut CassandraConnection> { | ||
if self.outbound.is_none() { | ||
self.outbound = Some( | ||
new_connection((self.address, 9042), handshake, tls, pushed_messages_tx).await?, | ||
) | ||
} | ||
|
||
Ok(self.outbound.as_mut().unwrap()) | ||
} | ||
} | ||
|
||
pub async fn new_connection<A: ToSocketAddrs>( | ||
address: A, | ||
handshake: &[Message], | ||
tls: &Option<TlsConnector>, | ||
pushed_messages_tx: &Option<mpsc::UnboundedSender<Messages>>, | ||
) -> Result<CassandraConnection> { | ||
let outbound = CassandraConnection::new( | ||
address, | ||
CassandraCodec::new(), | ||
tls.clone(), | ||
pushed_messages_tx.clone(), | ||
) | ||
.await?; | ||
|
||
for handshake_message in handshake { | ||
let (return_chan_tx, return_chan_rx) = oneshot::channel(); | ||
outbound.send(handshake_message.clone(), return_chan_tx)?; | ||
return_chan_rx.await?; | ||
} | ||
|
||
Ok(outbound) | ||
} |