diff --git a/config/config.example.toml b/config/config.example.toml index db562ffe7e66..943ff3cf6aa0 100644 --- a/config/config.example.toml +++ b/config/config.example.toml @@ -436,4 +436,9 @@ apple_pay_merchant_cert_key = "APPLE_PAY_MERCHNAT_CERTIFICATE_KEY" #Private [payment_link] -sdk_url = "http://localhost:9090/dist/HyperLoader.js" \ No newline at end of file +sdk_url = "http://localhost:9090/dist/HyperLoader.js" + +# Config for KV setup +[kv_config] +# TTL for KV in seconds +ttl = 900 diff --git a/config/development.toml b/config/development.toml index 701805ffe0ad..918be3478de6 100644 --- a/config/development.toml +++ b/config/development.toml @@ -449,4 +449,7 @@ sdk_url = "http://localhost:9090/dist/HyperLoader.js" [lock_settings] redis_lock_expiry_seconds = 180 # 3 * 60 seconds -delay_between_retries_in_milliseconds = 500 \ No newline at end of file +delay_between_retries_in_milliseconds = 500 + +[kv_config] +ttl = 900 # 15 * 60 seconds diff --git a/config/docker_compose.toml b/config/docker_compose.toml index de984597d055..d2da9180a655 100644 --- a/config/docker_compose.toml +++ b/config/docker_compose.toml @@ -316,4 +316,7 @@ supported_connectors = "braintree" [lock_settings] redis_lock_expiry_seconds = 180 # 3 * 60 seconds -delay_between_retries_in_milliseconds = 500 \ No newline at end of file +delay_between_retries_in_milliseconds = 500 + +[kv_config] +ttl = 900 # 15 * 60 seconds diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.toml index 8cbded8f5368..28129ab98677 100644 --- a/crates/router/Cargo.toml +++ b/crates/router/Cargo.toml @@ -14,7 +14,7 @@ s3 = ["dep:aws-sdk-s3", "dep:aws-config"] kms = ["external_services/kms", "dep:aws-config"] email = ["external_services/email", "dep:aws-config"] stripe = ["dep:serde_qs"] -release = ["kms", "stripe", "s3", "email","accounts_cache"] +release = ["kms", "stripe", "s3", "email","accounts_cache","kv_store"] olap = ["data_models/olap", "storage_impl/olap", "scheduler/olap"] oltp = ["data_models/oltp", "storage_impl/oltp"] kv_store = ["scheduler/kv_store"] diff --git a/crates/router/src/configs/defaults.rs b/crates/router/src/configs/defaults.rs index c2e60bacb63e..2f418ce6f188 100644 --- a/crates/router/src/configs/defaults.rs +++ b/crates/router/src/configs/defaults.rs @@ -104,6 +104,13 @@ impl Default for super::settings::DrainerSettings { } } +#[cfg(feature = "kv_store")] +impl Default for super::settings::KvConfig { + fn default() -> Self { + Self { ttl: 900 } + } +} + use super::settings::{ Mandates, SupportedConnectorsForMandate, SupportedPaymentMethodTypesForMandate, SupportedPaymentMethodsForMandate, diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs index ec1ea7d77e1f..8691e48180c2 100644 --- a/crates/router/src/configs/settings.rs +++ b/crates/router/src/configs/settings.rs @@ -102,6 +102,13 @@ pub struct Settings { pub lock_settings: LockSettings, pub temp_locker_enable_config: TempLockerEnableConfig, pub payment_link: PaymentLink, + #[cfg(feature = "kv_store")] + pub kv_config: KvConfig, +} + +#[derive(Debug, Deserialize, Clone)] +pub struct KvConfig { + pub ttl: u32, } #[derive(Debug, Deserialize, Clone, Default)] diff --git a/crates/router/src/services.rs b/crates/router/src/services.rs index d216d6164276..631e9a5c189d 100644 --- a/crates/router/src/services.rs +++ b/crates/router/src/services.rs @@ -90,6 +90,7 @@ pub async fn get_store( store, config.drainer.stream_name.clone(), config.drainer.num_partitions, + config.kv_config.ttl, ); Ok(store) diff --git a/crates/storage_impl/src/consts.rs b/crates/storage_impl/src/consts.rs deleted file mode 100644 index 04eab6176f94..000000000000 --- a/crates/storage_impl/src/consts.rs +++ /dev/null @@ -1,2 +0,0 @@ -// TTL for KV setup -pub(crate) const KV_TTL: u32 = 300; diff --git a/crates/storage_impl/src/lib.rs b/crates/storage_impl/src/lib.rs index dd8d71fc701e..17d432c7932b 100644 --- a/crates/storage_impl/src/lib.rs +++ b/crates/storage_impl/src/lib.rs @@ -9,7 +9,6 @@ mod address; pub mod config; pub mod connection; mod connector_response; -mod consts; pub mod database; pub mod errors; mod lookup; @@ -138,6 +137,7 @@ pub struct KVRouterStore { router_store: RouterStore, drainer_stream_name: String, drainer_num_partitions: u8, + ttl_for_kv: u32, } #[async_trait::async_trait] @@ -146,13 +146,14 @@ where RouterStore: DatabaseStore, T: DatabaseStore, { - type Config = (RouterStore, String, u8); + type Config = (RouterStore, String, u8, u32); async fn new(config: Self::Config, _test_transaction: bool) -> StorageResult { - let (router_store, drainer_stream_name, drainer_num_partitions) = config; + let (router_store, drainer_stream_name, drainer_num_partitions, ttl_for_kv) = config; Ok(Self::from_store( router_store, drainer_stream_name, drainer_num_partitions, + ttl_for_kv, )) } fn get_master_pool(&self) -> &PgPool { @@ -176,11 +177,13 @@ impl KVRouterStore { store: RouterStore, drainer_stream_name: String, drainer_num_partitions: u8, + ttl_for_kv: u32, ) -> Self { Self { router_store: store, drainer_stream_name, drainer_num_partitions, + ttl_for_kv, } } diff --git a/crates/storage_impl/src/redis/kv_store.rs b/crates/storage_impl/src/redis/kv_store.rs index 32fe21f758a3..507c65eefc82 100644 --- a/crates/storage_impl/src/redis/kv_store.rs +++ b/crates/storage_impl/src/redis/kv_store.rs @@ -6,7 +6,7 @@ use router_derive::TryGetEnumVariant; use router_env::logger; use serde::de; -use crate::{consts, metrics, store::kv::TypedSql, KVRouterStore}; +use crate::{metrics, store::kv::TypedSql, KVRouterStore}; pub trait KvStorePartition { fn partition_number(key: PartitionKey<'_>, num_partitions: u8) -> u32 { @@ -102,6 +102,8 @@ where let type_name = std::any::type_name::(); let operation = op.to_string(); + let ttl = store.ttl_for_kv; + let partition_key = PartitionKey::MerchantIdPaymentIdCombination { combination: key }; let result = async { @@ -109,9 +111,7 @@ where KvOperation::Hset(value, sql) => { logger::debug!("Operation: {operation} value: {value:?}"); - redis_conn - .set_hash_fields(key, value, Some(consts::KV_TTL)) - .await?; + redis_conn.set_hash_fields(key, value, Some(ttl)).await?; store .push_to_drainer_stream::(sql, partition_key) @@ -136,12 +136,7 @@ where logger::debug!("Operation: {operation} value: {value:?}"); let result = redis_conn - .serialize_and_set_hash_field_if_not_exist( - key, - field, - value, - Some(consts::KV_TTL), - ) + .serialize_and_set_hash_field_if_not_exist(key, field, value, Some(ttl)) .await?; if matches!(result, redis_interface::HsetnxReply::KeySet) { @@ -156,7 +151,7 @@ where logger::debug!("Operation: {operation} value: {value:?}"); let result = redis_conn - .serialize_and_set_key_if_not_exist(key, value, Some(consts::KV_TTL.into())) + .serialize_and_set_key_if_not_exist(key, value, Some(ttl.into())) .await?; if matches!(result, redis_interface::SetnxReply::KeySet) { diff --git a/loadtest/config/development.toml b/loadtest/config/development.toml index 47235601cb0e..1eff861f643d 100644 --- a/loadtest/config/development.toml +++ b/loadtest/config/development.toml @@ -235,3 +235,6 @@ card.debit = {connector_list = "stripe,adyen,authorizedotnet,globalpay,worldpay, bank_debit.ach = { connector_list = "gocardless"} bank_debit.becs = { connector_list = "gocardless"} bank_debit.sepa = { connector_list = "gocardless"} + +[kv_config] +ttl = 300 # 5 * 60 seconds