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

MTG-1110 Add request time out for DB query #349

Closed
Closed
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
1 change: 1 addition & 0 deletions integrity_verification/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ async fn main() {
&config.database_url.clone().unwrap(),
100,
500,
Some(120),
config.base_dump_path.clone(),
metrics.red_metrics,
)
Expand Down
1 change: 1 addition & 0 deletions nft_ingester/src/bin/api/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub async fn main() -> Result<(), IngesterError> {
&args.pg_database_url,
args.pg_min_db_connections,
args.pg_max_db_connections,
Some(args.pg_max_lifetime_sec),
None,
red_metrics.clone(),
)
Expand Down
3 changes: 2 additions & 1 deletion nft_ingester/src/bin/ingester/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ pub async fn main() -> Result<(), IngesterError> {
let index_pg_storage = Arc::new(
init_index_storage_with_migration(
&args.pg_database_url,
args.pg_max_db_connections.clone(),
args.pg_max_db_connections,
Some(args.pg_max_lifetime_sec),
metrics_state.red_metrics.clone(),
DEFAULT_MIN_POSTGRES_CONNECTIONS,
PG_MIGRATIONS_PATH,
Expand Down
1 change: 1 addition & 0 deletions nft_ingester/src/bin/migrator/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub async fn main() -> Result<(), IngesterError> {
&args.pg_database_url,
args.pg_min_db_connections,
args.pg_max_db_connections,
Some(args.pg_max_lifetime_sec),
None,
metrics_state.red_metrics.clone(),
)
Expand Down
8 changes: 6 additions & 2 deletions nft_ingester/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ pub struct IngesterClapArgs {

#[clap(long, default_value = "100")]
pub pg_max_db_connections: u32,
#[clap(long, default_value = "120")]
pub pg_max_lifetime_sec: u64,

#[clap(short('r'), long, default_value="{redis_connection_str=\"redis://127.0.0.1:6379/0\"}", value_parser = parse_json_to_dict)]
pub redis_connection_config: Dict,

#[clap(long, default_value = "20")]
pub redis_accounts_parsing_workers: u32,

#[clap(long, default_value = "20")]
pub redis_transactions_parsing_workers: u32,

Expand Down Expand Up @@ -299,6 +299,8 @@ pub struct MigratorClapArgs {
pub pg_min_db_connections: u32,
#[clap(long, default_value = "250")]
pub pg_max_db_connections: u32,
#[clap(long, default_value = "120")]
pub pg_max_lifetime_sec: u64,

#[clap(long, help = "Metrics port")]
pub metrics_port: Option<u16>,
Expand All @@ -325,6 +327,8 @@ pub struct ApiClapArgs {
pub pg_min_db_connections: u32,
#[clap(long, default_value = "250")]
pub pg_max_db_connections: u32,
#[clap(long, default_value = "120")]
pub pg_max_lifetime_sec: u64,

#[clap(
short('m'),
Expand Down
2 changes: 2 additions & 0 deletions nft_ingester/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const MALLOC_CONF_ENV: &str = "MALLOC_CONF";
pub async fn init_index_storage_with_migration(
url: &str,
max_pg_connections: u32,
max_lifetime_sec: Option<u64>,
red_metrics: Arc<RequestErrorDurationMetrics>,
min_pg_connections: u32,
pg_migrations_path: &str,
Expand All @@ -34,6 +35,7 @@ pub async fn init_index_storage_with_migration(
url,
min_pg_connections,
max_pg_connections,
max_lifetime_sec,
base_dump_path,
red_metrics,
)
Expand Down
2 changes: 2 additions & 0 deletions postgre-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl PgClient {
url: &str,
min_connections: u32,
max_connections: u32,
max_lifetime_sec: Option<u64>,
base_dump_path: Option<PathBuf>,
metrics: Arc<RequestErrorDurationMetrics>,
) -> Result<Self, Error> {
Expand All @@ -67,6 +68,7 @@ impl PgClient {
let pool = PgPoolOptions::new()
.min_connections(min_connections)
.max_connections(max_connections)
.max_lifetime(max_lifetime_sec.map(Duration::from_secs))
// 1 hour of a timeout, this is set specifically due to synchronizer needing up to 200 connections to do a full sync load
.acquire_timeout(Duration::from_secs(3600))
.connect_with(options)
Expand Down