-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chore: use BackedArguments for memcache_parser #6176
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
Conversation
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.
Review completed. 1 suggestions posted.
Comment augment review to trigger a new review at any time.
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.
Pull request overview
This PR refactors the memcache parser to use BackedArguments for storing command keys, replacing the previous custom memory management approach with a more consistent, reusable pattern already used elsewhere in the codebase. This simplifies MemcacheParser::Command by removing the key and keys_ext members, as well as the internal blob storage member, in favor of inheriting from BackedArguments.
Key changes:
MemcacheParser::Commandnow inherits fromBackedArgumentsfor key storage- Added iterator support to
BackedArgumentsto enable range-based operations - Simplified
MCPipelineMessageby storing value asstd::stringinstead of managing separate backing storage
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/common/backed_args.h | Added iterator support and empty() method to BackedArguments to support memcache command iteration |
| src/facade/memcache_parser.h | Refactored Command struct to inherit from BackedArguments; replaced key and keys_ext with BackedArguments storage; added key() accessor method |
| src/facade/memcache_parser.cc | Updated parsing logic to use tmp_args_ temporary storage and MaterializeArgs helper; introduced critical bug in base64 decoding with dangling reference |
| src/facade/memcache_parser_test.cc | Updated tests to use cmd_.key() accessor and new ToArgs() helper; fixed test logic to check all keys starting from index 0 |
| src/facade/dragonfly_connection.h | Simplified MCPipelineMessage to store value as std::string instead of managing custom backing storage |
| src/facade/dragonfly_connection.cc | Simplified MCPipelineMessage constructor; updated memory tracking to use BackedArguments::HeapMemory() |
| src/server/main_service.cc | Updated DispatchMC to work with BackedArguments iterator interface and new key() accessor |
| src/server/test_utils.cc | Updated test utilities to use BackedArguments::Assign() for constructing memcache commands |
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.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
|
|
||
| class MCParserTest : public testing::Test { | ||
| protected: | ||
| MemcacheParser::Result Parse(string_view input) { |
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.
Despite many changes, the tests here are left intact. most changes are around Parse called being replaced with this auxillary function.
| size_t index_; | ||
| size_t offset_ = 0; |
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.
As I understand, offset we can get from index, so I don't see any point in storing it 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.
you need O(N) to compute offset from lens
offset = Sum{len_[k] | k <= index }
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.
just for curiosity if instead of len we will store offset directly and calculate len like next - prev. It should solve the complexity
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.
interesting idea, let me think about it.
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.
for 3 elements with len 5 4 3 you will have the next offset array [5, 9, 12] to get len return id > 0 ? offset[id] - offset[id-1] : offset[0];
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.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
a45c532 to
a1c1010
Compare
739f3ff to
0f55bc7
Compare
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.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Signed-off-by: Roman Gershman <roman@dragonflydb.io>
|
augment review |
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.
Review completed. 1 suggestion posted.
Comment augment review to trigger a new review at any time.
| cmd->clear(); | ||
|
|
||
| if (cmd->type <= CAS) { // Store command | ||
| if (tokens_view.size() < 4 || tokens[0].size() > 250) { // key length limit |
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 key length check uses tokens[0], which is the command name, not the key; consider checking tokens_view[0] so the 250-char key limit is actually enforced.
🤖 Was this useful? React with 👍 or 👎
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.
will double check in the next PR.
|
|
||
| if (res->type >= MP::DELETE) { // write commands | ||
| if (!res->keys_ext.empty() && res->keys_ext.back() == "noreply") { | ||
| if (args->size() > 1 && args->back() == "noreply") { |
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.
should this comparison be case insensitive? args->back() == "noreply"
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.
- it's not a regression
- based on https://github.com/memcached/memcached/blob/master/doc/protocol.txt#L209 it should be lowcase.
Change BackedArguments to keep prefix sums of all lengths of its items Based on the idea from #6176 (comment) Signed-off-by: Roman Gershman <roman@dragonflydb.io>
Change BackedArguments to keep prefix sums of all lengths of its items Based on the idea from #6176 (comment) Signed-off-by: Roman Gershman <roman@dragonflydb.io>
Change BackedArguments to keep prefix sums of all lengths of its items Based on the idea from #6176 (comment) Signed-off-by: Roman Gershman <roman@dragonflydb.io>
Following #6171 and #6169 we implement Memcache::Command using BackedArguments.