Skip to content
代码片段 群组 项目
未验证 提交 5540a84a 编辑于 作者: Sylvester Chin's avatar Sylvester Chin 提交者: GitLab
浏览文件

Revert "Use multistore pool for RepositoryCache.cache_store"

This reverts commit d0c26297.
上级 7b8ee285
No related branches found
No related tags found
无相关合并请求
# frozen_string_literal: true
module Gitlab
module Redis
class MultiStoreConnectionPool < ::ConnectionPool
# We intercept the returned connection and borrow the connections
# before yielding the block.
def with
super do |conn|
next yield conn unless conn.is_a?(Gitlab::Redis::MultiStore)
conn.with_borrowed_connection do
yield conn
end
end
end
end
end
end
...@@ -4,16 +4,15 @@ module Gitlab ...@@ -4,16 +4,15 @@ module Gitlab
module Redis module Redis
class MultiStoreWrapper < Wrapper class MultiStoreWrapper < Wrapper
class << self class << self
# overrides Wrapper's pool to use the multistore connection pool
def with def with
multistore_pool.with do |multistore| multistore_pool.with do |multistore|
multistore.with_borrowed_connection do yield multistore
yield multistore
end
end end
end end
def multistore_pool def multistore_pool
@multistore_pool ||= ConnectionPool.new(size: pool_size, name: pool_name) { multistore } @multistore_pool ||= MultiStoreConnectionPool.new(size: pool_size, name: pool_name) { multistore }
end end
def pool_name def pool_name
......
...@@ -14,7 +14,7 @@ def config_fallback ...@@ -14,7 +14,7 @@ def config_fallback
def cache_store def cache_store
@cache_store ||= RepositoryCacheStore.new( @cache_store ||= RepositoryCacheStore.new(
redis: pool, redis: multistore_pool,
pool: false, pool: false,
compress: Gitlab::Utils.to_boolean(ENV.fetch('ENABLE_REDIS_CACHE_COMPRESSION', '1')), compress: Gitlab::Utils.to_boolean(ENV.fetch('ENABLE_REDIS_CACHE_COMPRESSION', '1')),
namespace: Cache::CACHE_NAMESPACE, namespace: Cache::CACHE_NAMESPACE,
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Redis::MultiStoreConnectionPool, feature_category: :scalability do
describe '#with' do
let(:conn_a) { Redis.new(url: 'redis://localhost:6379') }
let(:conn_b) { Redis.new(url: 'redis://localhost:6380') }
let(:pool_a) { ConnectionPool.new(size: 2) { conn_a } }
let(:pool_b) { ConnectionPool.new(size: 2) { conn_b } }
let(:multistore) { Gitlab::Redis::MultiStore.new(pool_a, pool_b, 'test') }
let(:multistore_pool) { described_class.new(size: 2) { multistore } }
before do
skip_default_enabled_yaml_check
end
it 'extends ConnectionPool' do
expect(multistore_pool.is_a?(::ConnectionPool)).to eq(true)
end
shared_examples 'handles connection borrowing' do
it 'yields a multistore with already borrowed connections' do
multistore_pool.with do |ms|
expect(ms).to be_an_instance_of(Gitlab::Redis::MultiStore)
expect(ms.primary_store).to eq(conn_a)
expect(ms.secondary_store).to eq(conn_b)
end
end
end
context 'with both feature flags enabled' do
before do
stub_feature_flags(use_primary_store_as_default_for_test: true,
use_primary_and_secondary_stores_for_test: true)
end
it_behaves_like 'handles connection borrowing'
end
context 'with use_primary_and_secondary_stores_for_test disabled' do
before do
stub_feature_flags(use_primary_store_as_default_for_test: true,
use_primary_and_secondary_stores_for_test: false)
end
it_behaves_like 'handles connection borrowing'
end
context 'with use_primary_store_as_default_for_test disabled' do
before do
stub_feature_flags(use_primary_store_as_default_for_test: false,
use_primary_and_secondary_stores_for_test: true)
end
it_behaves_like 'handles connection borrowing'
end
context 'with feature flags disabled' do
before do
stub_feature_flags(use_primary_store_as_default_for_test: false,
use_primary_and_secondary_stores_for_test: false)
end
it_behaves_like 'handles connection borrowing'
end
context 'when non-MultiStore is provided' do
let(:multistore) { conn_a }
it 'passes connection through without errors' do
multistore_pool.with do |c|
expect(c).to eq(conn_a)
end
end
end
end
end
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
it 'has a default ttl of 8 hours' do it 'has a default ttl of 8 hours' do
expect(described_class.cache_store.options[:expires_in]).to eq(8.hours) expect(described_class.cache_store.options[:expires_in]).to eq(8.hours)
end end
it 'uses a pool of multistore connections' do
expect(described_class.cache_store.redis.checkout).to be_an_instance_of(Gitlab::Redis::MultiStore)
end
end end
it 'migrates from self to ClusterRepositoryCache' do it 'migrates from self to ClusterRepositoryCache' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册