-
Notifications
You must be signed in to change notification settings - Fork 1k
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
fix(hset_family): Fix crash on scan after expiry set #4802
Conversation
When expiry is set on an hset its members are migrated to a string map. If a scan is performed on the hset, the code branch for string map accessed the value pointer directly by loading the 64 bit value from the object pointer. When creating a new entry in string map with TTL, we also set a bit on the stored pointer as metadata, this is set as 1 << 63. As a result when loading back the pointer we need to unset the same bit to get the correct address, this is done already in string map internals but the scan code did not do this, resulting in segfault. This change adds an AND operation to unset the TTL bit before dereferencing the pointer. Signed-off-by: Abhijat Malviya <[email protected]>
0d840f1
to
329ac6c
Compare
src/core/string_map.h
Outdated
@@ -147,6 +147,11 @@ class StringMap : public DenseSet { | |||
void RandomPairs(unsigned int count, std::vector<sds>& keys, std::vector<sds>& vals, | |||
bool with_value); | |||
|
|||
static constexpr uint64_t kValTtlBit = 1ULL << 63; |
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.
there is no need to move these constants here
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.
Fixed, I had originally used the constant directly in hset_family.cc
but now StringMap::GetValue
method is used, moved these back.
Signed-off-by: Abhijat Malviya <[email protected]>
Signed-off-by: Abhijat Malviya <[email protected]>
When expiry is set on an hset its members are migrated to a string map.
When creating a new entry in string map with TTL, we also set a bit on the stored pointer as metadata, this is set as 1 << 63. As a consequence when reading back the pointer, if expiry is set, we need to unset the same bit to get the correct address, this is done already in string map internals.
This change adds a similar AND operation in the scan code to unset the TTL bit before dereferencing the pointer.
fixes #4799