Skip to content

Commit

Permalink
meta: fix ms c flag reflecting s flag
Browse files Browse the repository at this point in the history
Fixes memcached#1045

The parser for allowing metaset to return flags is a bad hack requiring
re-writing flags into a buffer then re-parsing them later. The newer
proxy parser doesn't need to do this and is thus safer from these
non-obvious bugs.

Added basic test coverage as well. It looks like ms with c was never
explicitly tested before, so the existing tests didn't fail during
development.

Thanks to @zenbones for the report.
  • Loading branch information
dormando committed Jun 14, 2023
1 parent 4269308 commit 2315e0c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions proto_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,7 @@ static void process_mset_command(conn *c, token_t *tokens, const size_t ntokens)
case 'c':
// need to set the cas value post-assignment.
META_CHAR(p, 'c');
break;
case 's':
// get the final size post-fill
META_CHAR(p, 's');
Expand Down
32 changes: 27 additions & 5 deletions t/metaget.t
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,29 @@ my $sock = $server->sock;
}

{
diag "basic mset CAS";
note "ensure mset flag reflection doesn't bleed";
# mset return flags are internally implemented by stashing the flags in
# the write buffer then re-parsing them later (to preserve order...) so we
# need to check extra that I'm not being a dingus and forgetting a break
# statement.
print $sock "ms a 1\r\n1\r\n";
is(scalar <$sock>, "HD\r\n", "no flags");

print $sock "ms a 1 c\r\n1\r\n";
like(scalar <$sock>, qr/^HD c\d+\r\n/, "c flag");

print $sock "ms a 1 Otest\r\n1\r\n";
like(scalar <$sock>, qr/^HD Otest\r\n/, "O flag");

print $sock "ms a 1 s\r\n1\r\n";
like(scalar <$sock>, qr/^HD s1\r\n/, "s flag");

print $sock "ms a 1 k\r\n1\r\n";
like(scalar <$sock>, qr/^HD ka\r\n/, "k flag");
}

{
note "basic mset CAS";
my $key = "msetcas";
print $sock "ms $key 2\r\nbo\r\n";
like(scalar <$sock>, qr/^HD/, "set test key");
Expand All @@ -174,7 +196,7 @@ my $sock = $server->sock;
}

{
diag "mdelete with cas";
note "mdelete with cas";
my $key = "mdeltest";
print $sock "ms $key 2\r\nzo\r\n";
like(scalar <$sock>, qr/^HD/, "set test key");
Expand All @@ -191,7 +213,7 @@ my $sock = $server->sock;
}

{
diag "encoded binary keys";
note "encoded binary keys";
# 44OG44K544OI is "tesuto" in katakana
my $tesuto = "44OG44K544OI";
print $sock "ms $tesuto 2 b\r\npo\r\n";
Expand All @@ -208,7 +230,7 @@ my $sock = $server->sock;
}

{
diag "marithmetic tests";
note "marithmetic tests";
print $sock "ma mo\r\n";
like(scalar <$sock>, qr/^NF\r/, "incr miss");

Expand Down Expand Up @@ -276,7 +298,7 @@ my $sock = $server->sock;
# mset tests with mode switch flag (M)

{
diag "mset mode switch";
note "mset mode switch";
print $sock "ms modedefault 2 T120\r\naa\r\n";
like(scalar <$sock>, qr/^HD/, "default set mode");
mget_is({ sock => $sock,
Expand Down

0 comments on commit 2315e0c

Please sign in to comment.