Actually connect

This commit is contained in:
Bojan Serafimov
2022-09-13 15:29:36 -04:00
parent ecbda94790
commit cd8c96233f
3 changed files with 46 additions and 18 deletions

View File

@@ -5,10 +5,13 @@ use std::{
path::PathBuf,
str::FromStr,
};
use tokio::net::TcpStream;
use tokio::{io::AsyncWriteExt, net::TcpStream};
use clap::{App, Arg};
use utils::zid::{ZTenantId, ZTimelineId};
use utils::{
pq_proto::FeMessage,
zid::{ZTenantId, ZTimelineId},
};
// TODO put this in library, dedup with stuff in control_plane
/// Client for the pageserver's pagestream API
@@ -16,18 +19,18 @@ struct PagestreamApi {
stream: TcpStream,
}
/// Good enough implementation for these tests
impl PagestreamApi {
async fn connect(
connstr: &str,
tenant: &ZTenantId,
timeline: &ZTimelineId,
) -> anyhow::Result<PagestreamApi> {
let mut stream = TcpStream::connect("localhost:15000").await?;
// Connect to pageserver
println!("connecting to: {}", connstr);
// Parse connstr
let config = tokio_postgres::Config::from_str(connstr).expect("bad connstr");
let tcp_addr = format!("localhost:{}", config.get_ports()[0]);
// Connect
let mut stream = TcpStream::connect(tcp_addr).await?;
let (client, conn) = config
.connect_raw(&mut stream, tokio_postgres::NoTls)
.await?;
@@ -39,13 +42,15 @@ impl PagestreamApi {
_ = client.query(init_query.as_str(), &[]) => (),
};
println!("connected");
Ok(PagestreamApi { stream })
}
async fn make_request(&mut self) -> anyhow::Result<()> {
// TODO implement
async fn make_request(&mut self, msg: PagestreamFeMessage) -> anyhow::Result<()> {
let msg_bytes = msg.serialize();
self.stream.write_all(&msg_bytes).await?;
let _response = FeMessage::read_fut(&mut self.stream).await?;
Ok(())
}
}
@@ -56,7 +61,7 @@ async fn replay_trace<R: std::io::Read>(
) -> anyhow::Result<()> {
while let Ok(msg) = PagestreamFeMessage::parse(reader) {
println!("Parsed message {:?}", msg);
pagestream.make_request().await?;
// pagestream.make_request(msg).await?;
}
Ok(())
@@ -97,10 +102,14 @@ async fn main() -> anyhow::Result<()> {
let path = entry.path();
let _conn_id = ZTimelineId::from_str(path.file_name().unwrap().to_str().unwrap())?;
// TODO The pageserver deletes existing traces?
// LOL yes because I use tenant ID as trace id
let pagestream = PagestreamApi::connect(connstr, &tenant_id, &timeline_id).await?;
let file = File::open(path)?;
let file = File::open(path.clone())?;
let mut reader = BufReader::new(file);
// let len = file.metadata().unwrap().len();
// println!("replaying {:?} trace {} bytes", path, len);
replay_trace(&mut reader, pagestream).await?;
}
}

View File

@@ -499,7 +499,9 @@ impl PageServerHandler {
// Make request tracer if needed
let repo = tenant_mgr::get_repository_for_tenant(tenant_id)?;
let mut tracer = if repo.get_trace_read_requests() {
let path = repo.conf.trace_path(&tenant_id, &timeline_id, &timeline_id);
let path = repo
.conf
.trace_path(&tenant_id, &timeline_id, &ZTimelineId::generate());
Some(Tracer::new(path))
} else {
None