Commit 9622020c authored by Yorick Peterse's avatar Yorick Peterse

Remove support for sticking to old and new keys

In https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67773 we added
support for multiple databases in the load balancer. This was released
in 14.4. As part of these changes, we added support for reading/writing
to both the old and new Redis keys, making it easier to switch between
the old and new version of the code.

In this commit we remove the use of the old key format, as it's no
longer needed.

This fixes https://gitlab.com/gitlab-org/gitlab/-/issues/345208

Changelog: changed
parent eea4e622
......@@ -123,21 +123,18 @@ module Gitlab
def unstick(namespace, id)
Gitlab::Redis::SharedState.with do |redis|
redis.del(redis_key_for(namespace, id))
redis.del(old_redis_key_for(namespace, id))
end
end
def set_write_location_for(namespace, id, location)
Gitlab::Redis::SharedState.with do |redis|
redis.set(redis_key_for(namespace, id), location, ex: EXPIRATION)
redis.set(old_redis_key_for(namespace, id), location, ex: EXPIRATION)
end
end
def last_write_location_for(namespace, id)
Gitlab::Redis::SharedState.with do |redis|
redis.get(redis_key_for(namespace, id)) ||
redis.get(old_redis_key_for(namespace, id))
redis.get(redis_key_for(namespace, id))
end
end
......@@ -146,10 +143,6 @@ module Gitlab
"database-load-balancing/write-location/#{name}/#{namespace}/#{id}"
end
def old_redis_key_for(namespace, id)
"database-load-balancing/write-location/#{namespace}/#{id}"
end
end
end
end
......
......@@ -256,15 +256,6 @@ RSpec.describe Gitlab::Database::LoadBalancing::Sticking, :redis do
expect(sticking.last_write_location_for(:user, 4)).to be_nil
end
it 'removes the old key' do
Gitlab::Redis::SharedState.with do |redis|
redis.set(sticking.send(:old_redis_key_for, :user, 4), 'foo', ex: 30)
end
sticking.unstick(:user, 4)
expect(sticking.last_write_location_for(:user, 4)).to be_nil
end
end
describe '#last_write_location_for' do
......@@ -273,14 +264,6 @@ RSpec.describe Gitlab::Database::LoadBalancing::Sticking, :redis do
expect(sticking.last_write_location_for(:user, 4)).to eq('foo')
end
it 'falls back to reading the old key' do
Gitlab::Redis::SharedState.with do |redis|
redis.set(sticking.send(:old_redis_key_for, :user, 4), 'foo', ex: 30)
end
expect(sticking.last_write_location_for(:user, 4)).to eq('foo')
end
end
describe '#redis_key_for' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment