Skip to content

Commit

Permalink
Provide better errors for deletion scenarios. bug3
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin authored and Trond Norbye committed Oct 29, 2009
1 parent 47ab3b0 commit dd599c0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
10 changes: 8 additions & 2 deletions memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -2288,7 +2288,7 @@ static void write_and_free(conn *c, char *buf, int bytes) {
}
}

static inline void set_noreply_maybe(conn *c, token_t *tokens, size_t ntokens)
static inline bool set_noreply_maybe(conn *c, token_t *tokens, size_t ntokens)
{
int noreply_index = ntokens - 2;

Expand All @@ -2303,6 +2303,7 @@ static inline void set_noreply_maybe(conn *c, token_t *tokens, size_t ntokens)
&& strcmp(tokens[noreply_index].value, "noreply") == 0) {
c->noreply = true;
}
return c->noreply;
}

void append_stat(const char *name, ADD_STAT add_stats, conn *c,
Expand Down Expand Up @@ -2870,7 +2871,12 @@ static void process_delete_command(conn *c, token_t *tokens, const size_t ntoken

assert(c != NULL);

set_noreply_maybe(c, tokens, ntokens);
if (ntokens == 4) {
if (!set_noreply_maybe(c, tokens, ntokens)) {
out_string(c, "CLIENT_ERROR bad command line format");
return;
}
}

key = tokens[KEY_TOKEN].value;
nkey = tokens[KEY_TOKEN].length;
Expand Down
39 changes: 39 additions & 0 deletions t/issue_3.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/perl

use strict;
use Test::More tests => 7;
use FindBin qw($Bin);
use lib "$Bin/lib";
use MemcachedTest;

my $server = new_memcached();
my $sock = $server->sock;
my $key = "del_key";

print $sock "delete $key\r\n";
is (scalar <$sock>, "NOT_FOUND\r\n", "not found on delete");

print $sock "delete $key 10\r\n";
is (scalar <$sock>, "CLIENT_ERROR bad command line format\r\n", "invalid delete");

print $sock "delete $key 10 noreply\r\n";
is (scalar <$sock>, "ERROR\r\n", "Even more invalid delete");

print $sock "delete $key noreply\r\n";
# Will not reply, so let's do a set and check that.

print $sock "set $key 0 0 1\r\nx\r\n";
is (scalar <$sock>, "STORED\r\n", "Stored a key");

print $sock "delete $key\r\n";
is (scalar <$sock>, "DELETED\r\n", "Properly deleted");

print $sock "set $key 0 0 1\r\nx\r\n";
is (scalar <$sock>, "STORED\r\n", "Stored a key");

print $sock "delete $key noreply\r\n";
# will not reply, but a subsequent add will succeed

print $sock "add $key 0 0 1\r\nx\r\n";
is (scalar <$sock>, "STORED\r\n", "Add succeeded after deletion.");

2 changes: 1 addition & 1 deletion t/stats-detail.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ print $sock "stats detail dump\r\n";
is(scalar <$sock>, "PREFIX foo get 2 hit 1 set 1 del 0\r\n", "details after get without hit");
is(scalar <$sock>, "END\r\n", "end of details");

print $sock "delete foo:125 0\r\n";
print $sock "delete foo:125\r\n";
is(scalar <$sock>, "NOT_FOUND\r\n", "sent delete command");

print $sock "stats detail dump\r\n";
Expand Down
6 changes: 3 additions & 3 deletions t/udp.t
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ for my $prot (::IS_ASCII,::IS_BINARY) {
udp_get_test($prot,45,"404$prot","1",::ENTRY_MISSING);
udp_incr_decr_test($prot,45,"aval$prot","1","incr",1);
udp_incr_decr_test($prot,45,"aval$prot","1","decr",2);
udp_delete_test($prot,45,"aval$prot","0");
udp_delete_test($prot,45,"aval$prot");
}

sub udp_set_test {
Expand Down Expand Up @@ -123,12 +123,12 @@ sub udp_get_test {
}

sub udp_delete_test {
my ($protocol, $req_id, $key, $time) = @_;
my ($protocol, $req_id, $key) = @_;
my $req = "";
my $key_len = length($key);

if ($protocol == ::IS_ASCII) {
$req = "delete $key $time\r\n";
$req = "delete $key\r\n";
} elsif ($protocol == ::IS_BINARY) {
$req = pack(::REQ_PKT_FMT, ::BIN_REQ_MAGIC, ::CMD_DELETE, $key_len, 0, 0, 0, $key_len, 0, 0, 0);
$req .= $key;
Expand Down

0 comments on commit dd599c0

Please sign in to comment.