Open
Conversation
puneet00
reviewed
Oct 24, 2025
key_server.rb
Outdated
| true | ||
| end | ||
|
|
||
| def free_up |
Collaborator
There was a problem hiding this comment.
cleanup is not consistent and takes O(n)
this means app will return expired keys
puneet00
reviewed
Oct 24, 2025
key_server.rb
Outdated
| return true | ||
| end | ||
|
|
||
| def delete_key(key) |
Collaborator
There was a problem hiding this comment.
race conditions in this code
Collaborator
There was a problem hiding this comment.
similar race conditions in other methods
puneet00
requested changes
Oct 24, 2025
key_server.rb
Outdated
| return true | ||
| end | ||
|
|
||
| def delete_key(key) |
Collaborator
There was a problem hiding this comment.
similar race conditions in other methods
puneet00
requested changes
Oct 28, 2025
key_server.rb
Outdated
|
|
||
| def keep_alive(key) | ||
| key = key.to_sym | ||
| @lock.synchronize { |
Collaborator
There was a problem hiding this comment.
free_up is O(n)
so every method using this lock is O(n)
current solution doesn't meet problem statement constraints
…s to be less than O(n)
puneet00
reviewed
Oct 30, 2025
key_server.rb
Outdated
| end | ||
| expired_free = @redis.zrangebyscore(FREE_ZSET, '-inf', now) | ||
| expired_free.each do |k| | ||
| @redis.multi do |r| |
Collaborator
There was a problem hiding this comment.
multi will cause race condition here
puneet00
approved these changes
Oct 31, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In this assignment, Sinatra is being used for the api endpoints.
The endpoints are:
-> POST /generateKeys => creates 5 unique new keys
-> GET /key => returns any available key
-> PUT /releasekey/:id => unblocks the key in use
-> DELETE /deletekey/:id => deletes the key if being used
-> PUT /keepalive/:id => Keeps the keys alive if called by the client.
At the start of the app.rb file, there is a logic to handle automatic cleaning of the keys, i.e., it unblocks the keys which are in use for more than 1 minute and deletes the keys with respect to a 5 minute expiration period.
The rest of the core methods which have been used are in the key_server.rb file.