Add ClusterCache for cache migration to Redis Cluster
What does this MR do and why?
This MR introduces the ClusterCache
singleton to enable GitLab SaaS to migrate cache workload to a Redis Cluster.
In broad strokes, this MR does:
- Introduce
ClusterCache
because we need to migrate fromredis-cluster-cache
toredis-cache
. - Update
Cache
to use aMultiStore
for migration - Updates
redis.yml.example
, settingClusterCache
to connect to a Redis Cluster in CI. This mirrors whatpre/gstg/gprd
will be. - Update
lib/gitlab/patch/redis_cache_store.rb
to runmget
only if thedefault_store
is a standalone Redis. This is to avoid performance regressions when the MultiStore is still reading from the standalone Redis. - Fix specs that tests for strict conditions like number of Redis commands being used (in multistore, we make extra calls)
Note that this MR is only ready after feature-flag gets migrated out of redis-cache.
See gitlab-com/gl-infra/scalability#2016
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
Set GDK to run a Redis Cluster (https://gitlab.com/gitlab-org/gitlab-development-kit/-/blob/main/data/announcements/0004_redis_cluster_support.yml)
- Update
redis.yml
development:
cluster_cache:
cluster:
- redis://localhost:6001
- Restart the rails-web
gdk restart rails
- Enable
use_primary_and_secondary_stores_for_cache
and wait for ~1 minute for the in-memory feature flag cache to expire.
Feature.enable(:use_primary_store_as_default_for_cache)
Clicking around on gdk.test:3000
with the performance bar would show ClusterCache
with set
commands. Running the following line in terminal should show a bunch of keys in the Redis Cluster
for i in 0 1 2; do redis-cli -p 600$i keys '*'; done
- Enable
use_primary_store_as_default_for_cache
and wait for ~1 minute for the in-memory feature flag cache to expire.
Feature.enable(:use_primary_store_as_default_for_cache)
Clicking around on gdk.test:3000
with the performance bar would show ClusterCache
forming most of the reads and Cache
to be used for writes.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.