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 a96d342
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
21 changes: 12 additions & 9 deletions lqdetect.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,24 @@ static bool do_command_dupcheck(char *key, enum lq_detect_command cmd, struct lq
case LQCMD_MOP_DELETE:
case LQCMD_MOP_GET:
case LQCMD_SOP_GET:
for (int ii = 0; ii < count; ii++) {
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 (arg->count != 0) {
for (int ii = 0; ii < count; ii++) {
if (strcmp(lqdetect.arg[cmd][ii].query, arg->query) == 0) {
return true;
}
} else {
if (strcmp(lqdetect.arg[cmd][ii].query, arg->query) == 0) {
}
} else {
char buf[16002];
int buflen = snprintf(buf, sizeof(buf), "%s %s", key, arg->query);
for (int ii = 0; ii < count; ii++) {
uint32_t offset = lqdetect.buffer[cmd].keypos[ii];
uint32_t cmplen = lqdetect.buffer[cmd].keylen[ii] + 2;
if (cmplen == buflen &&
memcmp(lqdetect.buffer[cmd].data+offset, buf, cmplen) == 0) {
return true;
}
}
}
break;
}
return false;
}
Expand Down
35 changes: 34 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,38 @@ $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";
mem_cmd_is($sock, "lqdetect start 1", "", $rst);
$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 a96d342

Please sign in to comment.