Skip to content

Conversation

abhijat
Copy link
Contributor

@abhijat abhijat commented Mar 10, 2025

The usages of WrapSds are removed from zset_family calls.

In most cases it is a straightforward change to use string_view or string_view.data(), string_view.size().

In one case a wrapper had to be introduced.

fixes #4639

@abhijat abhijat changed the title chore(zset_family/score_map): Remove usages of sds [wip] chore(zset_family/score_map): Remove usages of sds Mar 10, 2025
@abhijat abhijat changed the title [wip] chore(zset_family/score_map): Remove usages of sds [wip] chore(zset_family/score_map): Replace sds arguments with string_view Mar 10, 2025
@abhijat
Copy link
Contributor Author

abhijat commented Mar 24, 2025

test failure seems related to this change:

src/redis/listpack.c:886]: assert((p) >= (lp)+LP_HDR_SIZE && (p)+(replaced_len) < (lp)+lpGetTotalBytes((lp))) failed!

passing in an empty string view ends up being treated as nullptr of zero size, which is different from the behavior for sds

@abhijat
Copy link
Contributor Author

abhijat commented Mar 24, 2025

passing in an empty string view ends up being treated as nullptr of zero size, which is different from the behavior for sds

reproducible by adding an empty field in unit test for zadd.

THe usages of WrapSds are removed from zset_family calls.

In most cases it is a straightforward change to use string_view or
string_view.data(), string_view.size(). In one case a wrapper had to be
introduced.

Signed-off-by: Abhijat Malviya <[email protected]>
@abhijat abhijat force-pushed the abhijat/chore/cleanup_sds_in_sorted_map branch from db97e4f to 24b3723 Compare March 25, 2025 10:44
@abhijat abhijat changed the title [wip] chore(zset_family/score_map): Replace sds arguments with string_view chore(zset_family/score_map): Replace sds arguments with string_view Mar 25, 2025
@abhijat abhijat requested review from romange and kostasrim March 25, 2025 14:52
@@ -108,7 +108,8 @@ constexpr unsigned kConvFlags = DoubleToStringConverter::UNIQUE_ZERO;
DoubleToStringConverter score_conv(kConvFlags, "inf", "nan", 'e', -6, 21, 6, 0);

// Copied from redis code but uses double_conversion to encode double values.
unsigned char* zzlInsertAt(unsigned char* zl, unsigned char* eptr, sds ele, double score) {
unsigned char* zzlInsertAt(unsigned char* zl, unsigned char* eptr, const unsigned char* ele,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would use const char* ele to avoid multiple castings on the caller side.
Maybe even better: it's now in our c++ code base, so you could even keep string_view ele here and make the safe conversion to ""sv in this function.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, to signify it's ours - please rename it to ZzlInsertAt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed name and signature

Signed-off-by: Abhijat Malviya <[email protected]>
@abhijat abhijat requested a review from romange March 27, 2025 10:22
Copy link
Contributor

@kostasrim kostasrim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comment, LGTM

// results in the replace operation being applied on the listpack. In addition to being wrong, it
// also causes assertion failures. To circumvent this corner case we pass here a string view
// pointing to an empty string on the stack, which has a non-null data field.
if (ele.data() == nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we patch lpAppend ? Or if we want to enforce a contract, why not simply introduce a wrapper that does this check for us here and use it. That way, we save this "hack"?

Not that it matters that much, it's a few lines

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do not change code under redis directory and this function is the wrapper

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right you want to keep the diffs clean

Copy link
Collaborator

@romange romange left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work!

@abhijat abhijat merged commit 90e9ecb into main Mar 27, 2025
10 checks passed
@abhijat abhijat deleted the abhijat/chore/cleanup_sds_in_sorted_map branch March 27, 2025 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

get rid of sds arguments in SortedMap
3 participants