Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure DB ID is set if namespaces are enabled #766

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions bottomless/src/replicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,19 @@ impl Options {
pub fn from_env() -> Result<Self> {
fn env_var(key: &str) -> Result<String> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I preemptively acked, but before we merge -- should all env_var callsites disallow empty vars?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avinassh can you double-check before I queue this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@psarna hey, let me double check all of the vars if we are using empty vars anywhere

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@psarna I have double checked all, we don't expect empty variables to be set anywhere in bottomless

match std::env::var(key) {
Ok(res) => Ok(res),
Ok(res) => {
let res = res.trim().to_string();
if res.is_empty() {
bail!("{} environment variable is empty", key)
} else {
Ok(res)
}
}
Comment on lines +158 to +165
Copy link
Member Author

@avinassh avinassh Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't trim, then it lets us slip in values containing just spaces or export LIBSQL_BOTTOMLESS_DATABASE_ID=''. I don't think we ever want env variables to have spaces, trimming seems like a must.

Err(_) => bail!("{} environment variable not set", key),
}
}
fn env_var_or<S: ToString>(key: &str, default_value: S) -> String {
match std::env::var(key) {
match env_var(key) {
Ok(res) => res,
Err(_) => default_value.to_string(),
}
Expand Down
11 changes: 10 additions & 1 deletion libsql-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ where
db_is_dirty: self.db_is_dirty,
max_log_duration: self.db_config.max_log_duration.map(Duration::from_secs_f32),
snapshot_callback: self.snapshot_callback,
bottomless_replication: self.db_config.bottomless_replication,
bottomless_replication: self.db_config.bottomless_replication.clone(),
extensions: self.extensions,
stats_sender: self.stats_sender.clone(),
max_response_size: self.db_config.max_response_size,
Expand All @@ -530,6 +530,15 @@ where
.await?;
}

// if namespaces are enabled, then bottomless must have set DB ID
if !self.disable_namespaces {
if let Some(bottomless) = &self.db_config.bottomless_replication {
if bottomless.db_id.is_none() {
anyhow::bail!("bottomless replication with namespaces requires a DB ID");
}
}
}

if let Some(config) = self.rpc_config.take() {
let proxy_service =
ProxyService::new(namespaces.clone(), None, self.disable_namespaces);
Expand Down
Loading