mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 04:04:43 +08:00
feat: Soft kill kv (#4582)
Co-authored-by: Akshay S <akshay.s@Akshay-Subramanian-D66TQ6D97K.local> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -31,7 +31,7 @@ use crate::{
|
||||
diesel_error_to_data_error,
|
||||
errors::RedisErrorExt,
|
||||
lookup::ReverseLookupInterface,
|
||||
redis::kv_store::{kv_wrapper, KvOperation, PartitionKey},
|
||||
redis::kv_store::{decide_storage_scheme, kv_wrapper, KvOperation, Op, PartitionKey},
|
||||
utils::{pg_connection_read, pg_connection_write, try_redis_get_else_try_database_get},
|
||||
DataModelExt, DatabaseStore, KVRouterStore, RouterStore,
|
||||
};
|
||||
@ -333,6 +333,9 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
|
||||
payment_attempt: PaymentAttemptNew,
|
||||
storage_scheme: MerchantStorageScheme,
|
||||
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
|
||||
let storage_scheme =
|
||||
decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Insert)
|
||||
.await;
|
||||
match storage_scheme {
|
||||
MerchantStorageScheme::PostgresOnly => {
|
||||
self.router_store
|
||||
@ -470,6 +473,17 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
|
||||
payment_attempt: PaymentAttemptUpdate,
|
||||
storage_scheme: MerchantStorageScheme,
|
||||
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
|
||||
let key = PartitionKey::MerchantIdPaymentId {
|
||||
merchant_id: &this.merchant_id,
|
||||
payment_id: &this.payment_id,
|
||||
};
|
||||
let field = format!("pa_{}", this.attempt_id);
|
||||
let storage_scheme = decide_storage_scheme::<_, DieselPaymentAttempt>(
|
||||
self,
|
||||
storage_scheme,
|
||||
Op::Update(key.clone(), &field, Some(&this.updated_by)),
|
||||
)
|
||||
.await;
|
||||
match storage_scheme {
|
||||
MerchantStorageScheme::PostgresOnly => {
|
||||
self.router_store
|
||||
@ -477,10 +491,6 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
|
||||
.await
|
||||
}
|
||||
MerchantStorageScheme::RedisKv => {
|
||||
let key = PartitionKey::MerchantIdPaymentId {
|
||||
merchant_id: &this.merchant_id,
|
||||
payment_id: &this.payment_id,
|
||||
};
|
||||
let key_str = key.to_string();
|
||||
let old_connector_transaction_id = &this.connector_transaction_id;
|
||||
let old_preprocessing_id = &this.preprocessing_step_id;
|
||||
@ -493,7 +503,6 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
|
||||
// Check for database presence as well Maybe use a read replica here ?
|
||||
let redis_value = serde_json::to_string(&updated_attempt)
|
||||
.change_context(errors::StorageError::KVError)?;
|
||||
let field = format!("pa_{}", updated_attempt.attempt_id);
|
||||
|
||||
let redis_entry = kv::TypedSql {
|
||||
op: kv::DBOperation::Update {
|
||||
@ -588,6 +597,8 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
|
||||
merchant_id: &str,
|
||||
storage_scheme: MerchantStorageScheme,
|
||||
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
|
||||
let storage_scheme =
|
||||
decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await;
|
||||
match storage_scheme {
|
||||
MerchantStorageScheme::PostgresOnly => {
|
||||
self.router_store
|
||||
@ -645,6 +656,8 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
|
||||
storage_scheme,
|
||||
)
|
||||
};
|
||||
let storage_scheme =
|
||||
decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await;
|
||||
match storage_scheme {
|
||||
MerchantStorageScheme::PostgresOnly => database_call().await,
|
||||
MerchantStorageScheme::RedisKv => {
|
||||
@ -697,6 +710,8 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
|
||||
storage_scheme,
|
||||
)
|
||||
};
|
||||
let storage_scheme =
|
||||
decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await;
|
||||
match storage_scheme {
|
||||
MerchantStorageScheme::PostgresOnly => database_call().await,
|
||||
MerchantStorageScheme::RedisKv => {
|
||||
@ -744,6 +759,8 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
|
||||
connector_txn_id: &str,
|
||||
storage_scheme: MerchantStorageScheme,
|
||||
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
|
||||
let storage_scheme =
|
||||
decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await;
|
||||
match storage_scheme {
|
||||
MerchantStorageScheme::PostgresOnly => {
|
||||
self.router_store
|
||||
@ -804,6 +821,8 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
|
||||
attempt_id: &str,
|
||||
storage_scheme: MerchantStorageScheme,
|
||||
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
|
||||
let storage_scheme =
|
||||
decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await;
|
||||
match storage_scheme {
|
||||
MerchantStorageScheme::PostgresOnly => {
|
||||
self.router_store
|
||||
@ -850,6 +869,8 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
|
||||
merchant_id: &str,
|
||||
storage_scheme: MerchantStorageScheme,
|
||||
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
|
||||
let storage_scheme =
|
||||
decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await;
|
||||
match storage_scheme {
|
||||
MerchantStorageScheme::PostgresOnly => {
|
||||
self.router_store
|
||||
@ -909,6 +930,8 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
|
||||
merchant_id: &str,
|
||||
storage_scheme: MerchantStorageScheme,
|
||||
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
|
||||
let storage_scheme =
|
||||
decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await;
|
||||
match storage_scheme {
|
||||
MerchantStorageScheme::PostgresOnly => {
|
||||
self.router_store
|
||||
@ -968,6 +991,8 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
|
||||
payment_id: &str,
|
||||
storage_scheme: MerchantStorageScheme,
|
||||
) -> error_stack::Result<Vec<PaymentAttempt>, errors::StorageError> {
|
||||
let storage_scheme =
|
||||
decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await;
|
||||
match storage_scheme {
|
||||
MerchantStorageScheme::PostgresOnly => {
|
||||
self.router_store
|
||||
|
||||
@ -43,7 +43,7 @@ use crate::connection;
|
||||
use crate::{
|
||||
diesel_error_to_data_error,
|
||||
errors::RedisErrorExt,
|
||||
redis::kv_store::{kv_wrapper, KvOperation, PartitionKey},
|
||||
redis::kv_store::{decide_storage_scheme, kv_wrapper, KvOperation, Op, PartitionKey},
|
||||
utils::{self, pg_connection_read, pg_connection_write},
|
||||
DataModelExt, DatabaseStore, KVRouterStore,
|
||||
};
|
||||
@ -55,6 +55,15 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
|
||||
new: PaymentIntentNew,
|
||||
storage_scheme: MerchantStorageScheme,
|
||||
) -> error_stack::Result<PaymentIntent, StorageError> {
|
||||
let merchant_id = new.merchant_id.clone();
|
||||
let payment_id = new.payment_id.clone();
|
||||
let field = format!("pi_{}", new.payment_id);
|
||||
let key = PartitionKey::MerchantIdPaymentId {
|
||||
merchant_id: &merchant_id,
|
||||
payment_id: &payment_id,
|
||||
};
|
||||
let storage_scheme =
|
||||
decide_storage_scheme::<_, DieselPaymentIntent>(self, storage_scheme, Op::Insert).await;
|
||||
match storage_scheme {
|
||||
MerchantStorageScheme::PostgresOnly => {
|
||||
self.router_store
|
||||
@ -63,14 +72,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
|
||||
}
|
||||
|
||||
MerchantStorageScheme::RedisKv => {
|
||||
let merchant_id = new.merchant_id.clone();
|
||||
let payment_id = new.payment_id.clone();
|
||||
let key = PartitionKey::MerchantIdPaymentId {
|
||||
merchant_id: &merchant_id,
|
||||
payment_id: &payment_id,
|
||||
};
|
||||
let key_str = key.to_string();
|
||||
let field = format!("pi_{}", new.payment_id);
|
||||
let created_intent = PaymentIntent {
|
||||
id: 0i32,
|
||||
payment_id: new.payment_id.clone(),
|
||||
@ -155,6 +157,19 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
|
||||
payment_intent_update: PaymentIntentUpdate,
|
||||
storage_scheme: MerchantStorageScheme,
|
||||
) -> error_stack::Result<PaymentIntent, StorageError> {
|
||||
let merchant_id = this.merchant_id.clone();
|
||||
let payment_id = this.payment_id.clone();
|
||||
let key = PartitionKey::MerchantIdPaymentId {
|
||||
merchant_id: &merchant_id,
|
||||
payment_id: &payment_id,
|
||||
};
|
||||
let field = format!("pi_{}", this.payment_id);
|
||||
let storage_scheme = decide_storage_scheme::<_, DieselPaymentIntent>(
|
||||
self,
|
||||
storage_scheme,
|
||||
Op::Update(key.clone(), &field, Some(&this.updated_by)),
|
||||
)
|
||||
.await;
|
||||
match storage_scheme {
|
||||
MerchantStorageScheme::PostgresOnly => {
|
||||
self.router_store
|
||||
@ -162,14 +177,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
|
||||
.await
|
||||
}
|
||||
MerchantStorageScheme::RedisKv => {
|
||||
let merchant_id = this.merchant_id.clone();
|
||||
let payment_id = this.payment_id.clone();
|
||||
let key = PartitionKey::MerchantIdPaymentId {
|
||||
merchant_id: &merchant_id,
|
||||
payment_id: &payment_id,
|
||||
};
|
||||
let key_str = key.to_string();
|
||||
let field = format!("pi_{}", this.payment_id);
|
||||
|
||||
let diesel_intent_update = payment_intent_update.to_storage_model();
|
||||
let origin_diesel_intent = this.to_storage_model();
|
||||
@ -225,6 +233,8 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
|
||||
er.change_context(new_err)
|
||||
})
|
||||
};
|
||||
let storage_scheme =
|
||||
decide_storage_scheme::<_, DieselPaymentIntent>(self, storage_scheme, Op::Find).await;
|
||||
match storage_scheme {
|
||||
MerchantStorageScheme::PostgresOnly => database_call().await,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user