Skip to content
Snippets Groups Projects

Migrate Redis BufferedCounter to Redis SharedState

Merged Marco Gregorius requested to merge mg-migrate-buffered-counter-to-shared-state into master

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

  1. Setup Redis Cluster https://gitlab.com/gitlab-org/gitlab-development-kit/-/blob/main/doc/howto/redis_cluster.md
  2. 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
  1. Enable dual write FF:
Feature.enable(:use_primary_and_secondary_stores_for_buffered_counter)
  1. Increment some counter:
ProjectStatistics.increment_statistic(Project.find(1), :build_artifacts_size, Gitlab::Counters::Increment.new(amount: 10))
  1. 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"
  1. 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"
Edited by Marco Gregorius

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
Please register or sign in to reply
Loading