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 7a4fb9d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lqdetect.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ 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) {
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 {
Expand All @@ -115,7 +115,6 @@ static bool do_command_dupcheck(char *key, enum lq_detect_command cmd, struct lq
}
}
}
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 7a4fb9d

Please sign in to comment.