Skip to content

Commit

Permalink
INTERNAL: do_lqdetect_write method simple
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesecrust committed Oct 30, 2024
1 parent 45d1e99 commit b42f4c4
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions lqdetect.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static bool is_command_duplicated(char *key, int keylen, enum lq_detect_command
case LQCMD_BOP_COUNT:
case LQCMD_BOP_DELETE:
for (int ii = 0; ii < count; ii++) {
if (strcmp(lqdetect.arg[cmd][ii].query, arg->query) == 0) {
if (buf->keylen[ii] > 0 && strcmp(lqdetect.arg[cmd][ii].query, arg->query) == 0) {
return true;
}
}
Expand All @@ -103,7 +103,7 @@ static bool is_command_duplicated(char *key, int keylen, enum lq_detect_command
case LQCMD_MOP_GET:
case LQCMD_SOP_GET:
for (int ii = 0; ii < count; ii++) {
if (strcmp(lqdetect.arg[cmd][ii].query, arg->query) == 0) {
if (buf->keylen[ii] > 0 && strcmp(lqdetect.arg[cmd][ii].query, arg->query) == 0) {
if (arg->count > 0) return true;
if (buf->keylen[ii] == keylen &&
memcmp(buf->data + buf->keypos[ii], key, keylen) == 0) {
Expand All @@ -122,10 +122,8 @@ static void do_lqdetect_write(char *client_ip, char *key,
struct tm *ptm;
struct timeval val;
struct lq_detect_buffer *buffer = &lqdetect.buffer[cmd];
uint32_t offset = buffer->offset;
uint32_t nsaved = buffer->nsaved;
char *bufptr = buffer->data + buffer->offset;
uint32_t nwrite, length, keylen = strlen(key);
uint32_t length, keylen = strlen(key);
char keybuf[251];
char *keyptr = key;

Expand All @@ -140,21 +138,23 @@ static void do_lqdetect_write(char *client_ip, char *key,

gettimeofday(&val, NULL);
ptm = localtime(&val.tv_sec);
length = ((nsaved+1) * LQ_INPUT_SIZE) - offset - 1;
length = ((nsaved+1) * LQ_INPUT_SIZE);

snprintf(bufptr, length, "%02d:%02d:%02d.%06ld %s <%u> %s ",
ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (long)val.tv_usec, client_ip,
arg->overhead, command_str[cmd]);

nwrite = strlen(bufptr);
buffer->keypos[nsaved] = offset + nwrite;
buffer->offset += snprintf(buffer->data + buffer->offset, length - buffer->offset,
"%02d:%02d:%02d.%06ld %s <%u> %s ",
ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (long)val.tv_usec,
client_ip, arg->overhead, command_str[cmd]);
buffer->keypos[nsaved] = buffer->offset;
buffer->keylen[nsaved] = keylen;
length -= nwrite;
bufptr += nwrite;

snprintf(bufptr, length, "%s %s\n", keyptr, arg->query);
nwrite += strlen(bufptr);
buffer->offset += nwrite;
buffer->offset += snprintf(buffer->data + buffer->offset, (length - buffer->offset) > 0 ? (length - buffer->offset) : 0,
"%s %s\n", keyptr, arg->query);
if (buffer->offset >= length) {
buffer->offset = length - 1;
buffer->keypos[nsaved] = -1;
buffer->keylen[nsaved] = -1;
buffer->data[buffer->offset] = '\n';
}
lqdetect.arg[cmd][nsaved] = *arg;
buffer->nsaved += 1;
}
Expand Down

0 comments on commit b42f4c4

Please sign in to comment.