Skip to content
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
2 changes: 2 additions & 0 deletions lib/bolt/config/src/ns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ pub struct Turnstile {
pub struct Service {
pub count: usize,
pub resources: ServiceResources,
pub crdb_min_connections: Option<u64>,
pub crdb_max_connections: Option<u64>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
Expand Down
21 changes: 0 additions & 21 deletions lib/bolt/config/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ pub struct ServiceConfig {

#[serde(default)]
pub resources: ServiceResourcesMap,

#[serde(default)]
pub cockroachdb: CockroachDB,
}

#[derive(Deserialize, Clone, Debug)]
Expand Down Expand Up @@ -240,24 +237,6 @@ impl Default for ServiceResourcesMap {
}
}

#[derive(Deserialize, Clone, Debug)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
pub struct CockroachDB {
// Sets a minimum number of connections to the database. This is important to ensure that
// the initial queries are not delayed by a large surge of TCP connections immediately
// after startup.
//
// To figure out a healthy number for this value, see the `rivet_crdb_pool_conn_size`
// metric to see how many connections are being used for a given service.
pub min_connections: usize,
}

impl Default for CockroachDB {
fn default() -> Self {
Self { min_connections: 1 }
}
}

mod defaults {
pub fn singleton() -> bool {
false
Expand Down
14 changes: 10 additions & 4 deletions lib/bolt/core/src/context/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,10 +923,12 @@ impl ServiceContextData {
);
}

env.insert(
"CRDB_MIN_CONNECTIONS".into(),
self.config().cockroachdb.min_connections.to_string(),
);
if let Some(x) = ns_service_config.crdb_min_connections {
env.insert("CRDB_MIN_CONNECTIONS".into(), x.to_string());
}
if let Some(x) = ns_service_config.crdb_max_connections {
env.insert("CRDB_MAX_CONNECTIONS".into(), x.to_string());
}

if project_ctx.ns().prometheus.is_some() && self.depends_on_prometheus_api() {
env.insert(
Expand Down Expand Up @@ -1374,10 +1376,14 @@ impl ServiceContextData {
config::ns::ClusterKind::SingleNode { .. } => config::ns::Service {
count: 1,
resources: self.config().resources.single_node.clone(),
crdb_min_connections: None,
crdb_max_connections: None,
},
config::ns::ClusterKind::Distributed { .. } => config::ns::Service {
count: 2,
resources: self.config().resources.distributed.clone(),
crdb_min_connections: None,
crdb_max_connections: None,
},
});

Expand Down
Loading