Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop jobs hash #282

Merged
merged 2 commits into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Renamed `UntilTimeout` to `UntilExpired`
- Removed concurrency for now (a0cff5bc42edbe7190d6ede7e7f845074d2d7af6)
- Improved integration testing for locks
- Totally delete the hash that was growing out of proportion

## v5.1.0

Expand Down
5 changes: 3 additions & 2 deletions redis/delete.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ local exists_key = KEYS[1]
local grabbed_key = KEYS[2]
local available_key = KEYS[3]
local version_key = KEYS[4]
local unique_digest = KEYS[5] -- TODO: Legacy support (Remove in v6.1)
local unique_digest = KEYS[5] -- TODO: Legacy support (Remove in v6.1)

redis.call('DEL', exists_key)
redis.call('DEL', grabbed_key)
redis.call('DEL', available_key)
redis.call('DEL', version_key)
redis.call('DEL', unique_digest) -- TODO: Legacy support (Remove in v6.1)
redis.call('DEL', 'uniquejobs') -- TODO: Old job hash, just drop the darn thing
redis.call('DEL', unique_digest) -- TODO: Legacy support (Remove in v6.1)
2 changes: 1 addition & 1 deletion redis/release_lock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local stored_jid = redis.pcall('get', unique_key)
if stored_jid then
if stored_jid == job_id or stored_jid == '2' then
redis.pcall('del', unique_key)
redis.pcall('hdel', 'uniquejobs', job_id)
redis.pcall('HDEL', 'uniquejobs', job_id)
return 1
else
return 0
Expand Down
19 changes: 19 additions & 0 deletions spec/integration/sidekiq_unique_jobs/legacy_lock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@
let(:locksmith_two) { described_class.new(lock_item_two) }
let(:lock_item_two) { lock_item.merge('jid' => jid_two) }

context 'with a legacy uniquejobs hash' do
before do
SidekiqUniqueJobs.redis do |conn|
conn.multi do
conn.hset('uniquejobs', 'bogus', 'value')
conn.hset('uniquejobs', 'bogus', 'value 2')
end
end
end

it 'deletes the uniquejobs hash' do
expect(keys).to include('uniquejobs')
expect(hexists('uniquejobs', 'bogus')).to eq(true)
locksmith_one.delete
expect(keys).not_to include('uniquejobs')
expect(hexists('uniquejobs', 'bogus')).to eq(false)
end
end

context 'with a legacy lock' do
before do
result = SidekiqUniqueJobs::Scripts.call(
Expand Down
8 changes: 8 additions & 0 deletions spec/support/sidekiq_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ def zcount(queue, time)
redis { |conn| conn.zcount(queue, -1, time) }
end

def hexists(hash, key)
redis { |conn| conn.hexists(hash, key) }
end

def hlen(hash, key)
redis { |conn| conn.hlen(hash, key) }
end

def get_key(key)
redis { |conn| conn.get(key) }
end
Expand Down