Migrate Redis BufferedCounter to Redis SharedState
What does this MR do and why?
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).
References
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.
MR acceptance checklist
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 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
- Setup Redis Cluster https://gitlab.com/gitlab-org/gitlab-development-kit/-/blob/main/doc/howto/redis_cluster.md
- Configure
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
- Enable dual write FF:
Feature.enable(:use_primary_and_secondary_stores_for_buffered_counter)
- Increment some counter:
ProjectStatistics.increment_statistic(Project.find(1), :build_artifacts_size, Gitlab::Counters::Increment.new(amount: 10))
- Check that the keys exist in both Redises:
# 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"
- Flush counters by running
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"
Merge request reports
Activity
assigned to @marcogreg
added pipelinetier-1 label
added backend label
- Resolved by Brian Williams
1 Message CHANGELOG missing: If this merge request needs a changelog entry, add the
Changelog
trailer to the commit message you want to add to the changelog.If this merge request doesn't need a CHANGELOG entry, feel free to ignore this message.
Reviewer roulette
Category Reviewer Maintainer backend @daniel-prause
(UTC+1, 7 hours behind author)
@bwill
(UTC-6, 14 hours behind author)
Please refer to documentation page for guidance on how you can benefit from the Reviewer Roulette, or use the GitLab Review Workload Dashboard to find other available reviewers.
If needed, you can retry the
danger-review
job that generated this comment.Generated by
DangerEdited by ****
- Resolved by 🤖 GitLab Bot 🤖
Proper labels assigned to this merge request. Please ignore me.
@marcogreg
- please see the following guidance and update this merge request.1 Error Please add typebug typefeature, or typemaintenance label to this merge request. Edited by 🤖 GitLab Bot 🤖
added typemaintenance label
changed milestone to %17.10
added 1 commit
- 8d20b60f - Migrate Redis BufferedCounter to Redis SharedState
added 1 commit
- 57a70062 - Migrate Redis BufferedCounter to Redis SharedState
added feature flag groupdurability labels
added devopsdata_access sectioninfrastructure platforms labels
requested review from @daniel-prause