Skip to content

Draft: Patch ActiveSupport to disable multikey command options

Sylvester Chin requested to merge schin1-rails-cache-patch into master

What does this MR do and why?

Multi-key operations in Rails.cache will lead to cross-slot errors. To estimate the impact of breaking them into single-key commands (on both stage group apdex and redis-cache apdex), this MR uses a feature-flag to disable multi-key commands in ActiveSupport::Cache::RedisCacheStore.

See gitlab-com/gl-infra/scalability#2004 (closed)

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Using gdk rails c:

  1. Write data
Rails.cache.write_multi({'y'=>1242, 'z'=>98765, 'x'=>123})
  1. Disable feature flag and multi-key reads will fail
Feature.disable(:disable_activesupport_multi_key_commands)
[4] pry(main)> Rails.cache.read_multi('x', 'y', 'z')
Gitlab::Instrumentation::RedisClusterValidator::CrossSlotError: Redis command MGET arguments hash to different slots. See https://docs.gitlab.com/ee/development/redis.html#multi-key-commands
from /Users/sylvesterchin/work/gitlab-development-kit/gitlab/lib/gitlab/instrumentation/redis_cluster_validator.rb:65:in `validate!'
  1. Enable feature flag to allow multi-key reads
Feature.enable(:disable_activesupport_multi_key_commands)
[6] pry(main)> Rails.cache.read_multi('x', 'y', 'z')
=> {"x"=>123, "y"=>1242, "z"=>98765}

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Sylvester Chin

Merge request reports