Skip to content

Commit 3f6eeac

Browse files
committed
WIP: libpq-based client
depends on neondatabase/rust-postgres#25
1 parent b061542 commit 3f6eeac

File tree

6 files changed

+372
-13
lines changed

6 files changed

+372
-13
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
@@ -161,11 +161,11 @@ env_logger = "0.10"
161161
log = "0.4"
162162

163163
## Libraries from neondatabase/ git forks, ideally with changes to be upstreamed
164-
postgres = { git = "https://github.com/neondatabase/rust-postgres.git", rev="7434d9388965a17a6d113e5dfc0e65666a03b4c2" }
165-
postgres-native-tls = { git = "https://github.com/neondatabase/rust-postgres.git", rev="7434d9388965a17a6d113e5dfc0e65666a03b4c2" }
166-
postgres-protocol = { git = "https://github.com/neondatabase/rust-postgres.git", rev="7434d9388965a17a6d113e5dfc0e65666a03b4c2" }
167-
postgres-types = { git = "https://github.com/neondatabase/rust-postgres.git", rev="7434d9388965a17a6d113e5dfc0e65666a03b4c2" }
168-
tokio-postgres = { git = "https://github.com/neondatabase/rust-postgres.git", rev="7434d9388965a17a6d113e5dfc0e65666a03b4c2" }
164+
postgres = { git = "https://github.com/neondatabase/rust-postgres.git", branch="problame/copy-both-duplex-public" }
165+
postgres-native-tls = { git = "https://github.com/neondatabase/rust-postgres.git", branch="problame/copy-both-duplex-public" }
166+
postgres-protocol = { git = "https://github.com/neondatabase/rust-postgres.git", branch="problame/copy-both-duplex-public" }
167+
postgres-types = { git = "https://github.com/neondatabase/rust-postgres.git", branch="problame/copy-both-duplex-public" }
168+
tokio-postgres = { git = "https://github.com/neondatabase/rust-postgres.git", branch="problame/copy-both-duplex-public" }
169169

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

203203
# This is only needed for proxy's tests.
204204
# TODO: we should probably fork `tokio-postgres-rustls` instead.
205-
tokio-postgres = { git = "https://github.com/neondatabase/rust-postgres.git", rev="7434d9388965a17a6d113e5dfc0e65666a03b4c2" }
205+
tokio-postgres = { git = "https://github.com/neondatabase/rust-postgres.git", branch="problame/copy-both-duplex-public" }
206206

207207
################# Binary contents sections
208208

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
///
@@ -807,6 +807,36 @@ impl PagestreamBeMessage {
807807

808808
bytes.into()
809809
}
810+
811+
pub fn deserialize(buf: Bytes) -> anyhow::Result<Self> {
812+
let mut buf = buf.reader();
813+
let msg_tag = buf.read_u8()?;
814+
match msg_tag {
815+
100 => todo!(),
816+
101 => todo!(),
817+
102 => {
818+
let buf = buf.get_ref();
819+
/* TODO use constant */
820+
if buf.len() == 8192 {
821+
Ok(PagestreamBeMessage::GetPage(PagestreamGetPageResponse {
822+
page: buf.clone(),
823+
}))
824+
} else {
825+
anyhow::bail!("invalid page size: {}", buf.len());
826+
}
827+
}
828+
103 => {
829+
let buf = buf.get_ref();
830+
let cstr = std::ffi::CStr::from_bytes_until_nul(&buf)?;
831+
let rust_str = cstr.to_str()?;
832+
Ok(PagestreamBeMessage::Error(PagestreamErrorResponse {
833+
message: rust_str.to_owned(),
834+
}))
835+
}
836+
104 => todo!(),
837+
_ => bail!("unknown tag: {:?}", msg_tag),
838+
}
839+
}
810840
}
811841

812842
#[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)