Skip to content

Conversation

@romange
Copy link
Collaborator

@romange romange commented Dec 8, 2025

Following #6171 and #6169 we implement Memcache::Command using BackedArguments.

Copilot AI review requested due to automatic review settings December 8, 2025 08:34
Copy link

@augmentcode augmentcode bot left a 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.

Copy link
Contributor

Copilot AI left a 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::Command now inherits from BackedArguments for key storage
  • Added iterator support to BackedArguments to enable range-based operations
  • Simplified MCPipelineMessage by storing value as std::string instead 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

Copy link
Contributor

Copilot AI left a 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.

Following #6171 and #6169 we implement Memcache::Command using BackedArguments.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>

class MCParserTest : public testing::Test {
protected:
MemcacheParser::Result Parse(string_view input) {
Copy link
Collaborator Author

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.

Comment on lines +46 to +47
size_t index_;
size_t offset_ = 0;
Copy link
Contributor

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

Copy link
Collaborator Author

@romange romange Dec 8, 2025

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 }

Copy link
Contributor

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

Copy link
Collaborator Author

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.

Copy link
Contributor

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];

BorysTheDev
BorysTheDev previously approved these changes Dec 8, 2025
Copilot AI review requested due to automatic review settings December 8, 2025 16:29
Copy link
Contributor

Copilot AI left a 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.

@romange romange force-pushed the MC1 branch 2 times, most recently from a45c532 to a1c1010 Compare December 8, 2025 16:35
Copilot AI review requested due to automatic review settings December 8, 2025 16:35
@romange romange force-pushed the MC1 branch 3 times, most recently from 739f3ff to 0f55bc7 Compare December 8, 2025 17:17
Copy link
Contributor

Copilot AI left a 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>
@romange
Copy link
Collaborator Author

romange commented Dec 9, 2025

augment review

Copy link

@augmentcode augmentcode bot left a 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
Copy link

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 👎

Copy link
Collaborator Author

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") {
Copy link
Contributor

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"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  1. it's not a regression
  2. based on https://github.com/memcached/memcached/blob/master/doc/protocol.txt#L209 it should be lowcase.

@romange romange merged commit 555e23c into main Dec 9, 2025
10 checks passed
@romange romange deleted the MC1 branch December 9, 2025 10:04
romange added a commit that referenced this pull request Dec 9, 2025
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>
romange added a commit that referenced this pull request Dec 9, 2025
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>
romange added a commit that referenced this pull request Dec 9, 2025
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>
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.

3 participants