summaryrefslogtreecommitdiff
path: root/lib/tasks/cache.rake
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-04 00:11:19 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-04 00:11:19 +0000
commitb3930fc34f7ed725bb79fc0ec563602ed20d879b (patch)
tree086bd7237ad86cf778c773cfa512763bc5dd8567 /lib/tasks/cache.rake
parent63b3a14f15ee5c202d78b7bd72030f4f437ef982 (diff)
downloadgitlab-ce-b3930fc34f7ed725bb79fc0ec563602ed20d879b.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/tasks/cache.rake')
-rw-r--r--lib/tasks/cache.rake32
1 files changed, 21 insertions, 11 deletions
diff --git a/lib/tasks/cache.rake b/lib/tasks/cache.rake
index 46d940255de..4d698e56444 100644
--- a/lib/tasks/cache.rake
+++ b/lib/tasks/cache.rake
@@ -2,22 +2,32 @@
namespace :cache do
namespace :clear do
+ REDIS_CLEAR_BATCH_SIZE = 1000 # There seems to be no speedup when pushing beyond 1,000
+ REDIS_SCAN_START_STOP = '0'.freeze # Magic value, see http://redis.io/commands/scan
+
desc "GitLab | Cache | Clear redis cache"
task redis: :environment do
- cache_key_patterns = %W[
- #{Gitlab::Redis::Cache::CACHE_NAMESPACE}*
- #{Gitlab::Cache::Ci::ProjectPipelineStatus::ALL_PIPELINES_STATUS_PATTERN}
- ]
+ Gitlab::Redis::Cache.with do |redis|
+ cache_key_pattern = %W[#{Gitlab::Redis::Cache::CACHE_NAMESPACE}*
+ projects/*/pipeline_status]
- ::Gitlab::Cleanup::Redis::BatchDeleteByPattern.new(cache_key_patterns).execute
- end
+ cache_key_pattern.each do |match|
+ cursor = REDIS_SCAN_START_STOP
+ loop do
+ cursor, keys = redis.scan(
+ cursor,
+ match: match,
+ count: REDIS_CLEAR_BATCH_SIZE
+ )
- desc "GitLab | Cache | Clear description templates redis cache"
- task description_templates: :environment do
- project_ids = Array(ENV['project_ids']&.split(',')).map!(&:squish)
+ Gitlab::Instrumentation::RedisClusterValidator.allow_cross_slot_commands do
+ redis.del(*keys) if keys.any?
+ end
- cache_key_patterns = ::Gitlab::Cleanup::Redis::DescriptionTemplatesCacheKeysPatternBuilder.new(project_ids).execute
- ::Gitlab::Cleanup::Redis::BatchDeleteByPattern.new(cache_key_patterns).execute
+ break if cursor == REDIS_SCAN_START_STOP
+ end
+ end
+ end
end
task all: [:redis]