Skip to content

Commit

Permalink
refactor: Added min idle and max lifetime for database config (#2900)
Browse files Browse the repository at this point in the history
Co-authored-by: akshay.s <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Gnanasundari24 <[email protected]>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
5 people authored Nov 28, 2023
1 parent bd889c8 commit b3c51e6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/development.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ port = 5432
dbname = "hyperswitch_db"
pool_size = 5
connection_timeout = 10
min_idle = 2

[replica_database]
username = "db_user"
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/configs/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ impl Default for super::settings::Database {
pool_size: 5,
connection_timeout: 10,
queue_strategy: Default::default(),
min_idle: None,
max_lifetime: None,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/configs/kms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ impl KmsDecrypt for settings::Database {
pool_size: self.pool_size,
connection_timeout: self.connection_timeout,
queue_strategy: self.queue_strategy.into(),
min_idle: self.min_idle,
max_lifetime: self.max_lifetime,
})
}
}
4 changes: 4 additions & 0 deletions crates/router/src/configs/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ pub struct Database {
pub pool_size: u32,
pub connection_timeout: u64,
pub queue_strategy: QueueStrategy,
pub min_idle: Option<u32>,
pub max_lifetime: Option<u64>,
}

#[derive(Debug, Deserialize, Clone, Default)]
Expand Down Expand Up @@ -548,6 +550,8 @@ impl From<Database> for storage_impl::config::Database {
pool_size: val.pool_size,
connection_timeout: val.connection_timeout,
queue_strategy: val.queue_strategy.into(),
min_idle: val.min_idle,
max_lifetime: val.max_lifetime,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/storage_impl/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ pub struct Database {
pub pool_size: u32,
pub connection_timeout: u64,
pub queue_strategy: bb8::QueueStrategy,
pub min_idle: Option<u32>,
pub max_lifetime: Option<u64>,
}
4 changes: 3 additions & 1 deletion crates/storage_impl/src/database/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ pub async fn diesel_make_pg_pool(
let manager = async_bb8_diesel::ConnectionManager::<PgConnection>::new(database_url);
let mut pool = bb8::Pool::builder()
.max_size(database.pool_size)
.min_idle(database.min_idle)
.queue_strategy(database.queue_strategy)
.connection_timeout(std::time::Duration::from_secs(database.connection_timeout));
.connection_timeout(std::time::Duration::from_secs(database.connection_timeout))
.max_lifetime(database.max_lifetime.map(std::time::Duration::from_secs));

if test_transaction {
pool = pool.connection_customizer(Box::new(TestTransaction));
Expand Down

0 comments on commit b3c51e6

Please sign in to comment.