Skip to content

Commit

Permalink
document the neon options as ephemeral or not
Browse files Browse the repository at this point in the history
  • Loading branch information
conradludgate committed Dec 4, 2024
1 parent 1fad360 commit 765be4b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
6 changes: 3 additions & 3 deletions libs/proxy/postgres-protocol2/src/message/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,12 @@ pub struct StartupMessageParams {
impl StartupMessageParams {
/// Set parameter's value by its name.
pub fn insert(&mut self, name: &str, value: &str) {
if name.contains('\0') | value.contains('\0') {
if name.contains('\0') || value.contains('\0') {
panic!("startup parameter name or value contained a null")
}
self.params.put(name.as_bytes());
self.params.put_slice(name.as_bytes());
self.params.put_u8(0);
self.params.put(value.as_bytes());
self.params.put_slice(value.as_bytes());
self.params.put_u8(0);
}
}
Expand Down
33 changes: 23 additions & 10 deletions proxy/src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ pub(crate) async fn handle_client<S: AsyncRead + AsyncWrite + Unpin>(

let params_compat = match &user_info {
auth::Backend::ControlPlane(_, info) => {
info.info.options.get("proxy_params_compat").is_some()
info.info.options.get(NeonOptions::PARAMS_COMPAT).is_some()
}
auth::Backend::Local(_) => false,
};
Expand Down Expand Up @@ -417,6 +417,19 @@ pub(crate) async fn prepare_client_connection<P>(
pub(crate) struct NeonOptions(Vec<(SmolStr, SmolStr)>);

impl NeonOptions {
// proxy options:

/// `PARAMS_COMPAT` allows opting in to forwarding all startup parameters from client to compute.
const PARAMS_COMPAT: &str = "proxy_params_compat";

// cplane options:

/// `LSN` allows provisioning an ephemeral compute with time-travel to the provided LSN.
const LSN: &str = "lsn";

/// `ENDPOINT_TYPE` allows configuring an ephemeral compute to be read_only or read_write.
const ENDPOINT_TYPE: &str = "endpoint_type";

pub(crate) fn parse_params(params: &StartupMessageParams) -> Self {
params
.options_raw()
Expand All @@ -436,15 +449,15 @@ impl NeonOptions {
}

pub(crate) fn is_ephemeral(&self) -> bool {
fn parameter_is_not_ephemeral(p: &str) -> bool {
p == "proxy_params_compat"
}

self.0
.iter()
.filter(|(k, _)| !parameter_is_not_ephemeral(k))
.count()
> 0
self.0.iter().any(|(k, _)| match &**k {
// This is not a cplane option, we know it does not create ephemeral computes.
Self::PARAMS_COMPAT => false,
Self::LSN => true,
Self::ENDPOINT_TYPE => true,
// err on the side of caution. any cplane options we don't know about
// might lead to ephemeral computes.
_ => true,
})
}

fn parse_from_iter<'a>(options: impl Iterator<Item = &'a str>) -> Self {
Expand Down

0 comments on commit 765be4b

Please sign in to comment.