Skip to content

Commit 37e8eba

Browse files
committed
WIP: libpq-based client
depends on neondatabase/rust-postgres#25
1 parent f45882e commit 37e8eba

File tree

7 files changed

+373
-14
lines changed

7 files changed

+373
-14
lines changed

Cargo.lock

Lines changed: 24 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ env_logger = "0.10"
163163
log = "0.4"
164164

165165
## Libraries from neondatabase/ git forks, ideally with changes to be upstreamed
166-
postgres = { git = "https://github.com/neondatabase/rust-postgres.git", rev="ce7260db5998fe27167da42503905a12e7ad9048" }
167-
postgres-native-tls = { git = "https://github.com/neondatabase/rust-postgres.git", rev="ce7260db5998fe27167da42503905a12e7ad9048" }
168-
postgres-protocol = { git = "https://github.com/neondatabase/rust-postgres.git", rev="ce7260db5998fe27167da42503905a12e7ad9048" }
169-
postgres-types = { git = "https://github.com/neondatabase/rust-postgres.git", rev="ce7260db5998fe27167da42503905a12e7ad9048" }
170-
tokio-postgres = { git = "https://github.com/neondatabase/rust-postgres.git", rev="ce7260db5998fe27167da42503905a12e7ad9048" }
166+
postgres = { git = "https://github.com/neondatabase/rust-postgres.git", branch="neon" }
167+
postgres-native-tls = { git = "https://github.com/neondatabase/rust-postgres.git", branch="neon" }
168+
postgres-protocol = { git = "https://github.com/neondatabase/rust-postgres.git", branch="neon" }
169+
postgres-types = { git = "https://github.com/neondatabase/rust-postgres.git", branch="neon" }
170+
tokio-postgres = { git = "https://github.com/neondatabase/rust-postgres.git", branch="neon" }
171171

172172
## Other git libraries
173173
heapless = { default-features=false, features=[], git = "https://github.com/japaric/heapless.git", rev = "644653bf3b831c6bb4963be2de24804acf5e5001" } # upstream release pending
@@ -204,7 +204,7 @@ tonic-build = "0.9"
204204

205205
# This is only needed for proxy's tests.
206206
# TODO: we should probably fork `tokio-postgres-rustls` instead.
207-
tokio-postgres = { git = "https://github.com/neondatabase/rust-postgres.git", rev="ce7260db5998fe27167da42503905a12e7ad9048" }
207+
tokio-postgres = { git = "https://github.com/neondatabase/rust-postgres.git", branch="neon" }
208208

209209
################# Binary contents sections
210210

libs/pageserver_api/src/models.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use utils::{
1818

1919
use crate::reltag::RelTag;
2020
use anyhow::bail;
21-
use bytes::{BufMut, Bytes, BytesMut};
21+
use bytes::{Buf, BufMut, Bytes, BytesMut};
2222

2323
/// The state of a tenant in this pageserver.
2424
///
@@ -767,6 +767,36 @@ impl PagestreamBeMessage {
767767

768768
bytes.into()
769769
}
770+
771+
pub fn deserialize(buf: Bytes) -> anyhow::Result<Self> {
772+
let mut buf = buf.reader();
773+
let msg_tag = buf.read_u8()?;
774+
match msg_tag {
775+
100 => todo!(),
776+
101 => todo!(),
777+
102 => {
778+
let buf = buf.get_ref();
779+
/* TODO use constant */
780+
if buf.len() == 8192 {
781+
Ok(PagestreamBeMessage::GetPage(PagestreamGetPageResponse {
782+
page: buf.clone(),
783+
}))
784+
} else {
785+
anyhow::bail!("invalid page size: {}", buf.len());
786+
}
787+
}
788+
103 => {
789+
let buf = buf.get_ref();
790+
let cstr = std::ffi::CStr::from_bytes_until_nul(buf)?;
791+
let rust_str = cstr.to_str()?;
792+
Ok(PagestreamBeMessage::Error(PagestreamErrorResponse {
793+
message: rust_str.to_owned(),
794+
}))
795+
}
796+
104 => todo!(),
797+
_ => bail!("unknown tag: {:?}", msg_tag),
798+
}
799+
}
770800
}
771801

772802
#[cfg(test)]

pageserver/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ enum-map.workspace = true
8282
enumset.workspace = true
8383
strum.workspace = true
8484
strum_macros.workspace = true
85+
tokio-stream.workspace = true
86+
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
8587

8688
[dev-dependencies]
8789
criterion.workspace = true

0 commit comments

Comments
 (0)