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

fix(cache): address in-memory cache invalidation using global tenant as key_prefix #6976

Merged
merged 2 commits into from
Jan 3, 2025

Conversation

Chethan-rao
Copy link
Contributor

@Chethan-rao Chethan-rao commented Jan 2, 2025

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

This PR fixes an inconsistency in the redis key_prefix that was used when invalidating the cache entries which affected all the cache types (configs, accounts, routing, etc).
The delete_key redis call during cache invalidation was using global as the key_prefix (key like global:test_key was being deleted in redis) while each of the tenants were reading using their corresponding key_prefix (key like public:test_key was being set/read in redis).

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

How did you test it?

PUT/GET/UPDATE/DELETE on configs table as configs has cache usage

  1. PUT
curl --location 'http://localhost:8080/configs/' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-tenant-id: public' \
--header 'api-key: test_admin' \
--data '{
    "key": "test_key_1",
    "value": "test_val_1"
}'
  1. GET
curl --location 'http://localhost:8080/configs/test_key_1' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-tenant-id: public' \
--header 'api-key: test_admin' \
--data ''

image

  1. UPDATE
curl --location 'http://localhost:8080/configs/test_key_1' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-tenant-id: public' \
--header 'api-key: test_admin' \
--data '{
    "value": "test_val_2"
}'
  1. GET
curl --location 'http://localhost:8080/configs/test_key_1' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-tenant-id: public' \
--header 'api-key: test_admin' \
--data ''

image

  1. DELETE
curl --location --request DELETE 'http://localhost:8080/configs/test_key_1' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-tenant-id: public' \
--header 'api-key: test_admin' \
--data ''
  1. GET
curl --location 'http://localhost:8080/configs/test_key_1' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-tenant-id: public' \
--header 'api-key: test_admin' \
--data ''

image

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@Chethan-rao Chethan-rao added A-framework Area: Framework C-bug Category: Bug S-waiting-on-review Status: This PR has been implemented and needs to be reviewed labels Jan 2, 2025
@Chethan-rao Chethan-rao self-assigned this Jan 2, 2025
@Chethan-rao Chethan-rao requested review from a team as code owners January 2, 2025 14:17
Copy link

semanticdiff-com bot commented Jan 2, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/redis_interface/src/commands.rs  55% smaller
  crates/router/src/db/configs.rs  33% smaller
  crates/storage_impl/src/redis/cache.rs  3% smaller
  crates/router/src/core/admin.rs  0% smaller
  crates/router/src/core/cache.rs  0% smaller
  crates/router/src/core/routing.rs  0% smaller
  crates/router/src/core/routing/helpers.rs  0% smaller
  crates/router/src/db/merchant_account.rs  0% smaller
  crates/storage_impl/src/redis/pub_sub.rs  0% smaller

@Chethan-rao Chethan-rao changed the title fix(cache): address imc invalidation using global tenant as key_prefix fix(cache): address in-memory cache invalidation using global tenant as key_prefix Jan 2, 2025
@@ -343,48 +363,37 @@ where
}

#[instrument(skip_all)]
pub async fn redact_cache<T, F, Fut>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this function because its not being used anywhere. moreover its not meant to be used in public

@likhinbopanna likhinbopanna added this pull request to the merge queue Jan 3, 2025
Merged via the queue into main with commit fce5ffa Jan 3, 2025
29 of 31 checks passed
@likhinbopanna likhinbopanna deleted the fix-cache-issue branch January 3, 2025 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-framework Area: Framework C-bug Category: Bug S-waiting-on-review Status: This PR has been implemented and needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants