Skip to content

Commit bb18a80

Browse files
authored
Clearer metrics Without LKK Delete (#33)
1 parent 5f79169 commit bb18a80

5 files changed

Lines changed: 20 additions & 13 deletions

File tree

lib/atomic_cache/atomic_cache_client.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,11 @@ def last_known_value(keyspace, options, tags)
119119
return lkv
120120
end
121121

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

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

lib/atomic_cache/key/last_mod_time_key_manager.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ def lock(keyspace, ttl, options={})
5959
@storage.add(keyspace.lock_key, LOCK_VALUE, ttl, options)
6060
end
6161

62+
# check if the keyspace is locked
63+
#
64+
# @param keyspace [AtomicCache::Keyspace] keyspace to lock
65+
def lock_present?(keyspace)
66+
@storage.read(keyspace.lock_key) == LOCK_VALUE
67+
end
68+
6269
# remove existing lock to allow other processes to update keyspace
6370
#
6471
# @param keyspace [AtomicCache::Keyspace] keyspace to lock

lib/atomic_cache/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module AtomicCache
4-
VERSION = "0.5.0.rc1"
4+
VERSION = "0.5.1.rc1"
55
end

spec/atomic_cache/atomic_cache_client_spec.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,6 @@
168168
result = subject.fetch(keyspace, backoff_duration_ms: 5) { 'value from generate' }
169169
expect(result).to eq(nil)
170170
end
171-
172-
it 'deletes the last known key' do
173-
key_storage.set(keyspace.last_known_key_key, :oldkey)
174-
cache_storage.set(:oldkey, nil)
175-
subject.fetch(keyspace, backoff_duration_ms: 5) { 'value from generate' }
176-
expect(cache_storage.store).to_not have_key(:oldkey)
177-
end
178171
end
179172
end
180173
end

spec/atomic_cache/key/last_mod_time_key_manager_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@
4040
expect(storage.store).to_not have_key(:'ns:lock')
4141
end
4242

43+
it 'checks if the lock is present' do
44+
subject.lock(req_keyspace, 100)
45+
expect(subject.lock_present?(req_keyspace)).to eq(true)
46+
end
47+
48+
it 'checks if the lock is not present' do
49+
expect(subject.lock_present?(req_keyspace)).to eq(false)
50+
end
51+
4352
it 'promotes a timestamp and last known key' do
4453
subject.promote(req_keyspace, last_known_key: 'asdf', timestamp: timestamp)
4554
expect(storage.read(:'ns:lkk')).to eq('asdf')

0 commit comments

Comments
 (0)