Optional reduce write for debug
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
mod connected;
|
||||
mod connecting;
|
||||
|
||||
use super::conncmd::ConnCommand;
|
||||
@@ -7,6 +8,7 @@ use crate::ca::conn::CaConnOpts;
|
||||
use crate::ca::conn2::progpend::HaveProgressPending;
|
||||
use async_channel::Sender;
|
||||
use ca_proto::ca::proto;
|
||||
use connected::Connected;
|
||||
use connecting::Connecting;
|
||||
use dbpg::seriesbychannel::ChannelInfoQuery;
|
||||
use futures_util::Future;
|
||||
@@ -34,6 +36,10 @@ use std::time::Instant;
|
||||
use taskrun::tokio;
|
||||
use tokio::net::TcpStream;
|
||||
|
||||
macro_rules! conn_err {
|
||||
($($arg:expr),*) => { if true { info!($($arg),*); } };
|
||||
}
|
||||
|
||||
autoerr::create_error_v1!(
|
||||
name(Error, "Conn"),
|
||||
enum variants {
|
||||
@@ -104,7 +110,7 @@ impl CaConn {
|
||||
Self {
|
||||
opts,
|
||||
backend,
|
||||
state: CaConnState::Connecting(Connecting::dummy_new(remote_addr, tsnow)),
|
||||
state: CaConnState::Connecting(Connecting::new(remote_addr, tsnow)),
|
||||
iqdqs: InsertDeques::new(),
|
||||
ca_conn_event_out_queue: VecDeque::new(),
|
||||
ca_conn_event_out_queue_max: 2000,
|
||||
@@ -308,7 +314,25 @@ impl Stream for CaConn {
|
||||
// }
|
||||
|
||||
match &mut self.state {
|
||||
CaConnState::Connecting(st2) => handle_poll_res!(st2.poll_unpin(cx), hpp),
|
||||
CaConnState::Connecting(st2) => match st2.poll_unpin(cx) {
|
||||
Ready(x) => match x {
|
||||
Ok(Some(x)) => {
|
||||
hpp.have_progress();
|
||||
self.state = CaConnState::Connected(Connected::new(x));
|
||||
}
|
||||
Ok(None) => {
|
||||
// TODO
|
||||
// In this case, should probably be treated like error.
|
||||
}
|
||||
Err(e) => {
|
||||
// TODO handle or propagate the error, change state.
|
||||
conn_err!("{}", e);
|
||||
}
|
||||
},
|
||||
Pending => {
|
||||
hpp.have_pending();
|
||||
}
|
||||
},
|
||||
CaConnState::Connected(_) => todo!(),
|
||||
CaConnState::Shutdown(_) => {
|
||||
// TODO still attempt to flush queues.
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
use futures_util::FutureExt;
|
||||
use std::fmt;
|
||||
use std::future::Future;
|
||||
use std::net::SocketAddrV4;
|
||||
use std::pin::Pin;
|
||||
use std::task::Context;
|
||||
use std::task::Poll;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
use taskrun::tokio;
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::time::error::Elapsed;
|
||||
|
||||
autoerr::create_error_v1!(
|
||||
name(Error, "Connected"),
|
||||
enum variants {
|
||||
Timeout,
|
||||
IO(#[from] std::io::Error),
|
||||
},
|
||||
);
|
||||
|
||||
type PollType = ();
|
||||
|
||||
type ReturnType = Result<Result<TcpStream, std::io::Error>, Elapsed>;
|
||||
|
||||
// type ConnectingFut = Pin<Box<dyn Future<Output = ReturnType> + Send>>;
|
||||
|
||||
pub struct Connected {
|
||||
tsbeg: Instant,
|
||||
addr: SocketAddrV4,
|
||||
tcp: TcpStream,
|
||||
// fut: ConnectingFut,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Connected {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt.debug_struct("Connected")
|
||||
.field("tsbeg", &self.tsbeg)
|
||||
.field("addr", &self.addr)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Connected {
|
||||
pub fn new(tcp: TcpStream) -> Self {
|
||||
Self {
|
||||
tsbeg: tsnow,
|
||||
addr: remote_addr,
|
||||
tcp,
|
||||
// fut: Box::pin(fut),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<Option<PollType>, Error>> {
|
||||
use Poll::*;
|
||||
Pending
|
||||
}
|
||||
|
||||
pub fn poll_unpin(&mut self, cx: &mut Context) -> Poll<Result<Option<PollType>, Error>> {
|
||||
Pin::new(self).poll(cx)
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,29 @@
|
||||
use futures_util::FutureExt;
|
||||
use std::fmt;
|
||||
use std::future::Future;
|
||||
use std::net::SocketAddrV4;
|
||||
use std::pin::Pin;
|
||||
use std::task::Context;
|
||||
use std::task::Poll;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
use taskrun::tokio;
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::time::error::Elapsed;
|
||||
|
||||
autoerr::create_error_v1!(
|
||||
name(Error, "Connecting"),
|
||||
enum variants {
|
||||
Logic,
|
||||
Timeout,
|
||||
IO(#[from] std::io::Error),
|
||||
},
|
||||
);
|
||||
|
||||
type ConnectingFut =
|
||||
Pin<Box<dyn Future<Output = Result<Result<TcpStream, std::io::Error>, tokio::time::error::Elapsed>> + Send>>;
|
||||
type PollType = TcpStream;
|
||||
|
||||
type ReturnType = Result<Result<TcpStream, std::io::Error>, Elapsed>;
|
||||
|
||||
type ConnectingFut = Pin<Box<dyn Future<Output = ReturnType> + Send>>;
|
||||
|
||||
pub struct Connecting {
|
||||
tsbeg: Instant,
|
||||
@@ -24,25 +31,6 @@ pub struct Connecting {
|
||||
fut: ConnectingFut,
|
||||
}
|
||||
|
||||
impl Connecting {
|
||||
pub fn dummy_new(remote_addr: SocketAddrV4, tsnow: Instant) -> Self {
|
||||
Self {
|
||||
tsbeg: tsnow,
|
||||
addr: remote_addr,
|
||||
fut: err::todoval(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<Option<()>, Error>> {
|
||||
let x = Err(Error::Logic);
|
||||
x?
|
||||
}
|
||||
|
||||
pub fn poll_unpin(&mut self, cx: &mut Context) -> Poll<Result<Option<()>, Error>> {
|
||||
Pin::new(self).poll(cx)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Connecting {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt.debug_struct("Connecting")
|
||||
@@ -51,3 +39,30 @@ impl fmt::Debug for Connecting {
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Connecting {
|
||||
pub fn new(remote_addr: SocketAddrV4, tsnow: Instant) -> Self {
|
||||
let fut = tokio::time::timeout(Duration::from_millis(1800), tokio::net::TcpStream::connect(remote_addr));
|
||||
Self {
|
||||
tsbeg: tsnow,
|
||||
addr: remote_addr,
|
||||
fut: Box::pin(fut),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<Option<PollType>, Error>> {
|
||||
use Poll::*;
|
||||
match self.fut.poll_unpin(cx) {
|
||||
Ready(x) => match x {
|
||||
Ok(Ok(x)) => Ready(Ok(Some(x))),
|
||||
Ok(Err(e)) => Ready(Err(e.into())),
|
||||
Err(_) => Ready(Err(Error::Timeout)),
|
||||
},
|
||||
Pending => Pending,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn poll_unpin(&mut self, cx: &mut Context) -> Poll<Result<Option<PollType>, Error>> {
|
||||
Pin::new(self).poll(cx)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ pub struct CaIngestOpts {
|
||||
pub test_bsread_addr: Option<String>,
|
||||
#[serde(default)]
|
||||
scylla_disable: bool,
|
||||
scylla_ignore_writes: bool,
|
||||
}
|
||||
|
||||
impl CaIngestOpts {
|
||||
@@ -125,6 +126,10 @@ impl CaIngestOpts {
|
||||
pub fn scylla_disable(&self) -> bool {
|
||||
self.scylla_disable
|
||||
}
|
||||
|
||||
pub fn scylla_ignore_writes(&self) -> bool {
|
||||
self.scylla_ignore_writes
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user