Migrate Redis BufferedCounter to Redis SharedState
All threads resolved!
All threads resolved!
Compare changes
Use MultiStore
to migrate keys from Gitlab::Redis::BufferedCounter
to Gitlab::Redis::SharedState
. Migration is done by wrapping the BufferedCounter
class with Multistore, which handles dual writes and switchover read to both stores via FF toggles.
As described in gitlab-com/gl-infra/data-access/durability/team#71, we are able to sync up the buffered counters with MultiStore only because FlushCounterIncrementsWorker
isn't enabled. Without this, we'd have to implement a more complicated approach as in !140630 (closed).
Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
config/redis.yml
: buffered_counter:
url: unix:/Users/gregoriusmarco/gdk/redis/redis.socket?db=5 # change to your respective gdk path
shared_state:
cluster:
- redis://localhost:6001
Feature.enable(:use_primary_and_secondary_stores_for_buffered_counter)
ProjectStatistics.increment_statistic(Project.find(1), :build_artifacts_size, Gitlab::Counters::Increment.new(amount: 10))
# on redis buffered_counter
$ gdk redis-cli -n 5
redis /Users/gregoriusmarco/gdk/redis/redis.socket[5]> keys *
1) "project:{1}:counters:ProjectStatistics:1:build_artifacts_size"
redis /Users/gregoriusmarco/gdk/redis/redis.socket[5]> get project:{1}:counters:ProjectStatistics:1:build_artifacts_size
"10"
# on redis cluster shared_state
$ redis-cli -p 6001
127.0.0.1:6001> get project:{1}:counters:ProjectStatistics:1:build_artifacts_size
"10"
FlushCounterIncrementsWorker
:[16] pry(main)> project = Project.first
=> #<Project id:1 toolbox/gitlab-smoke-tests>>
[17] pry(main)> FlushCounterIncrementsWorker.new.perform(project.statistics.class.name, project.statistics.id, :build_artifacts_size)
# check redis
redis /Users/gregoriusmarco/gdk/redis/redis.socket[5]> keys *
(empty array)
127.0.0.1:6001> keys *
1) "gitlab:exclusive_lease:namespace:namespaces_root_statistics:61"