Skip to content

Commit

Permalink
FIX: Fix do_command_dupcheck method that didn't show 0 at same key
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesecrust committed Oct 28, 2024
1 parent 63c8a8d commit 046d88c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
9 changes: 4 additions & 5 deletions lqdetect.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,16 @@ static bool do_command_dupcheck(char *key, enum lq_detect_command cmd, struct lq
if (arg->count == 0) {
uint32_t offset = lqdetect.buffer[cmd].keypos[ii];
uint32_t cmplen = lqdetect.buffer[cmd].keylen[ii];
if (cmplen == strlen(key) &&
memcmp(lqdetect.buffer[cmd].data+offset, key, cmplen) == 0) {
return true;
}
if (cmplen == strlen(key) && memcmp(lqdetect.buffer[cmd].data+offset, key, cmplen) == 0
&& strcmp(lqdetect.arg[cmd][ii].query, arg->query) == 0) {
return true;
}
} else {
if (strcmp(lqdetect.arg[cmd][ii].query, arg->query) == 0) {
return true;
}
}
}
break;
}
return false;
}
Expand Down
37 changes: 36 additions & 1 deletion t/long_query_detect_issue.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/perl

use strict;
use Test::More tests => 107;
use Test::More tests => 120;
use FindBin qw($Bin);
use lib "$Bin/lib";
use MemcachedTest;
Expand Down Expand Up @@ -116,5 +116,40 @@ $line = scalar <$sock>;
$line = scalar <$sock>;
mem_cmd_is($sock, "delete $key", "", "DELETED");

my $idx;
my $substring;
mem_cmd_is($sock, "sop insert skey1 5 create 0 0 5", "datum", "CREATED_STORED");
mem_cmd_is($sock, "sop insert skey2 5 create 0 0 5", "datum", "CREATED_STORED");
$rst = "long query detection started";
print $sock "lqdetect start 1\r\n";
$line = scalar <$sock>;
like($line, qr/$rst/, "lqdetect show");
$line = scalar <$sock>;
$rst = "VALUE 0 1\n"
. "5 datum\n"
. "END";
for ($idx = 1; $idx < 3; $idx += 1) {
mem_cmd_is($sock, "sop get skey1 $idx", "", $rst);
}
mem_cmd_is($sock, "sop get skey1 0", "", $rst);
for ($idx = 0; $idx < 3; $idx += 1) {
mem_cmd_is($sock, "sop get skey2 $idx", "", $rst);
}
print $sock "lqdetect show\r\n";
$line = scalar <$sock>;
for ($idx = 1; $idx < 3; $idx += 1) {
$line = scalar <$sock>;
$substring = "sop get skey1 $idx";
like($line, qr/$substring/, "lqdetect show $substring");
}
$line = scalar <$sock>;
$substring = "sop get skey1 0";
like($line, qr/$substring/, "lqdetect show $substring");
$line = scalar <$sock>;
$substring = "sop get skey2 0";
like($line, qr/$substring/, "lqdetect show $substring");
print $sock "lqdetect stop\r\n";
$line = scalar <$sock>;
$line = scalar <$sock>;
# after test
release_memcached($engine, $server);

0 comments on commit 046d88c

Please sign in to comment.