-
Notifications
You must be signed in to change notification settings - Fork 280
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
StateDB Cache #350
StateDB Cache #350
Conversation
Test FAILed. |
jenkins test this please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good. It doesn't look like you ever evict things from the cache. Is that intentional?
std::string redis_key = generate_redis_key(key); | ||
const std::vector<std::string> cmd_vec{"GET", redis_key}; | ||
auto result = | ||
redis::send_cmd_with_reply<std::string>(redis_connection_, cmd_vec); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you fetch the value from Redis, you should cache it here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
auto entry_search = cache_.find(key); | ||
bool new_entry = (entry_search == cache_.end()); | ||
if (!new_entry) { | ||
std::lock_guard<std::mutex> lock(entry_search->second->entry_mtx_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of this lock? It will be released once it goes out of scope, so it won't be held after the if-statement.
// This method is being invoked as part of the 'add application' | ||
// procedure in the query frontend. Because any subsequent feedback | ||
// updates to the StateDB depend on the completion of 'add application', | ||
// it's safe to add a new cache entry immediately |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm will this always be true? This seems like a complicated behavior to rely on for safety. What if another code path ends up putting things in the StateDB? Will that break this code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh I understand your comment now. Can you clarify in the comment that if we are creating a new entry, it means that the method is being invoked as part of adding an application?
But my previous question still remains, this seems like tricky behavior to rely on for safety.
Test PASSed. |
@dcrankshaw A couple questions regarding performance vs consistency tradeoffs:
|
@dcrankshaw I redesigned the
This design no longer makes any assumptions about the origin of the first |
Test FAILed. |
Test FAILed. |
jenkins test this please |
Test FAILed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Will merge once tests pass.
Test FAILed. |
Test FAILed. |
Test PASSed. |
Fixes #329