Skip to content

Commit

Permalink
Clearer metrics Without LKK Delete (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
tstone authored Jul 12, 2021
1 parent 5f79169 commit bb18a80
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
8 changes: 3 additions & 5 deletions lib/atomic_cache/atomic_cache_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,11 @@ def last_known_value(keyspace, options, tags)
return lkv
end

# if the value of the last known key is nil, we can infer that it's
# most likely expired, thus remove it so other processes don't waste
# time trying to read it
@storage.delete(lkk)
metrics(:increment, 'last-known-value.nil', tags: tags)
else
metrics(:increment, 'last-known-value.not-present', tags: tags)
end

metrics(:increment, 'last-known-value.not-present', tags: tags)
nil
end

Expand Down
7 changes: 7 additions & 0 deletions lib/atomic_cache/key/last_mod_time_key_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ def lock(keyspace, ttl, options={})
@storage.add(keyspace.lock_key, LOCK_VALUE, ttl, options)
end

# check if the keyspace is locked
#
# @param keyspace [AtomicCache::Keyspace] keyspace to lock
def lock_present?(keyspace)
@storage.read(keyspace.lock_key) == LOCK_VALUE
end

# remove existing lock to allow other processes to update keyspace
#
# @param keyspace [AtomicCache::Keyspace] keyspace to lock
Expand Down
2 changes: 1 addition & 1 deletion lib/atomic_cache/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module AtomicCache
VERSION = "0.5.0.rc1"
VERSION = "0.5.1.rc1"
end
7 changes: 0 additions & 7 deletions spec/atomic_cache/atomic_cache_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,6 @@
result = subject.fetch(keyspace, backoff_duration_ms: 5) { 'value from generate' }
expect(result).to eq(nil)
end

it 'deletes the last known key' do
key_storage.set(keyspace.last_known_key_key, :oldkey)
cache_storage.set(:oldkey, nil)
subject.fetch(keyspace, backoff_duration_ms: 5) { 'value from generate' }
expect(cache_storage.store).to_not have_key(:oldkey)
end
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/atomic_cache/key/last_mod_time_key_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@
expect(storage.store).to_not have_key(:'ns:lock')
end

it 'checks if the lock is present' do
subject.lock(req_keyspace, 100)
expect(subject.lock_present?(req_keyspace)).to eq(true)
end

it 'checks if the lock is not present' do
expect(subject.lock_present?(req_keyspace)).to eq(false)
end

it 'promotes a timestamp and last known key' do
subject.promote(req_keyspace, last_known_key: 'asdf', timestamp: timestamp)
expect(storage.read(:'ns:lkk')).to eq('asdf')
Expand Down

0 comments on commit bb18a80

Please sign in to comment.