Teach cache register to support redis cluster hash tags
fixes AE-655 Change-Id: Ib3c5b1516516cb7a85bb1776fd15873efdbad421 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/333088 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Cody Cutrer <cody@instructure.com> QA-Review: Jacob Burroughs <jburroughs@instructure.com> Product-Review: Jacob Burroughs <jburroughs@instructure.com>
This commit is contained in:
parent
dd69a65cb0
commit
1622650415
|
@ -74,7 +74,7 @@ module ActiveRecord
|
|||
|
||||
if key_types.any?
|
||||
base_keys.group_by { |key| Canvas::CacheRegister.redis(key, ::Shard.current) }.each do |redis, node_base_keys|
|
||||
node_base_keys.map { |k| key_types.map { |type| "#{k}/#{type}" } }.flatten.each_slice(1000) do |slice|
|
||||
node_base_keys.map { |k| key_types.map { |type| "{#{k}}/#{type}" } }.flatten.each_slice(1000) do |slice|
|
||||
redis.del(*slice)
|
||||
end
|
||||
rescue Redis::BaseConnectionError
|
||||
|
@ -84,7 +84,7 @@ module ActiveRecord
|
|||
if multi_key_types.any?
|
||||
base_keys.each do |base_key|
|
||||
multi_key_types.each do |type|
|
||||
MultiCache.delete("#{base_key}/#{type}", { unprefixed_key: true })
|
||||
MultiCache.delete("{#{base_key}}/#{type}", { unprefixed_key: true })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -109,7 +109,7 @@ module ActiveRecord
|
|||
|
||||
prefer_multi_cache = prefer_multi_cache_for_key_type?(key_type)
|
||||
redis = Canvas::CacheRegister.redis(base_key, ::Shard.shard_for(global_id), prefer_multi_cache:)
|
||||
full_key = "#{base_key}/#{key_type}"
|
||||
full_key = "{#{base_key}}/#{key_type}"
|
||||
|
||||
RequestCache.cache(full_key) do
|
||||
# try to get the timestamp for the type, set it to now if it doesn't exist
|
||||
|
|
|
@ -75,7 +75,7 @@ module ActiveSupport
|
|||
redis = Canvas::CacheRegister.redis(base_obj_key, batch_object.shard)
|
||||
|
||||
instrument(:read, name, options) do |payload|
|
||||
keys_to_batch = batched_keys.map { |type| "#{base_obj_key}/#{type}" }
|
||||
keys_to_batch = batched_keys.map { |type| "{#{base_obj_key}}/#{type}" }
|
||||
now = Time.now.utc.to_fs(batch_object.cache_timestamp_format)
|
||||
# pass in the base key, followed by the intermediate keys (that the script will pull and append to the base)
|
||||
keys = [key] + keys_to_batch
|
||||
|
|
|
@ -423,7 +423,7 @@ describe Canvas::CacheRegister do
|
|||
end
|
||||
|
||||
it "uses multi-cache delete when clearing a configured key" do
|
||||
key = Account.base_cache_register_key_for(Account.default) + "/feature_flags"
|
||||
key = "{#{Account.base_cache_register_key_for(Account.default)}}/feature_flags"
|
||||
allow(Canvas::CacheRegister).to receive(:can_use_multi_cache_redis?).and_return(true)
|
||||
expect(Canvas::CacheRegister).to_not receive(:redis)
|
||||
expect(MultiCache).to receive(:delete).with(key, { unprefixed_key: true })
|
||||
|
|
|
@ -144,11 +144,11 @@ describe ActiveSupport::Cache::HaStore do
|
|||
Timecop.freeze do
|
||||
now = Time.now.utc.to_s(Account.cache_timestamp_format)
|
||||
base_key = Account.base_cache_register_key_for(Account.site_admin)
|
||||
full_key = base_key + "/feature_flags"
|
||||
full_key = "{#{base_key}}/feature_flags"
|
||||
expect(Canvas::CacheRegister.lua).to receive(:run).with(:get_key, [full_key], [now], store.redis).and_return("cool beans")
|
||||
expect(Account.site_admin.cache_key(:feature_flags)).to eq("accounts/#{Account.site_admin.global_id}-cool beans")
|
||||
# doesn't use it for other key types
|
||||
expect(Canvas::CacheRegister.lua).to receive(:run).with(:get_key, [base_key + "/global_navigation"], [now], Canvas.redis).and_return(now)
|
||||
expect(Canvas::CacheRegister.lua).to receive(:run).with(:get_key, ["{#{base_key}}/global_navigation"], [now], Canvas.redis).and_return(now)
|
||||
expect(Account.site_admin.cache_key(:global_navigation)).to eq("accounts/#{Account.site_admin.global_id}-#{now}")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue