Skip to content

Commit 3a6fd07

Browse files
authored
Merge pull request #94 from doyoubi/fix/SlowlogErrCmd
Ignore command with error result in slowlog. Fix some bugs.
2 parents 22b32ca + 0d2522f commit 3a6fd07

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/command.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,6 @@ void cmd_mark_fail(struct command *cmd, const char *reason)
11181118
void cmd_stats(struct command *cmd, int64_t end_time)
11191119
{
11201120
struct context *ctx = cmd->ctx;
1121-
struct command *last, *first;
11221121
long long latency;
11231122

11241123
ATOMIC_INC(ctx->stats.completed_commands, 1);
@@ -1128,20 +1127,14 @@ void cmd_stats(struct command *cmd, int64_t end_time)
11281127
ATOMIC_INC(ctx->stats.total_latency, latency);
11291128
ATOMIC_SET(ctx->last_command_latency, latency);
11301129

1131-
if (!STAILQ_EMPTY(&cmd->sub_cmds)) {
1132-
first = STAILQ_FIRST(&cmd->sub_cmds);
1133-
last = STAILQ_LAST(&cmd->sub_cmds, command, sub_cmd_next);
1134-
latency = last->rep_time[1] - first->rep_time[0];
1135-
} else {
1136-
latency = cmd->rep_time[1] - cmd->rep_time[0];
1137-
}
1130+
latency = cmd->rep_time[1] - cmd->rep_time[0];
11381131

11391132
if (slowlog_need_log(cmd, latency)) {
11401133
if (slowlog_statsd_enabled()) {
11411134
slowlog_add_count(cmd);
11421135
}
11431136
if (slowlog_cmd_enabled()) {
1144-
struct slowlog_entry *entry = slowlog_create_entry(cmd, latency);
1137+
struct slowlog_entry *entry = slowlog_create_entry(cmd, latency / 1000);
11451138
slowlog_set(&cmd->ctx->slowlog, entry);
11461139
}
11471140
}

src/server.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ void server_make_iov(struct conn_info *info)
6464
cmd_iov_add(&info->iov, (void*)req_ask, strlen(req_ask), NULL);
6565
}
6666
cmd->rep_time[0] = t;
67+
if (cmd->parent) {
68+
int64_t parent_rep_start_time = cmd->parent->rep_time[0];
69+
if (parent_rep_start_time == 0 || parent_rep_start_time > t)
70+
cmd->parent->rep_time[0] = t;
71+
}
6772

6873
if (cmd->prefix != NULL) {
6974
cmd_iov_add(&info->iov, (void*)cmd->prefix, strlen(cmd->prefix), NULL);
@@ -234,6 +239,11 @@ int server_read(struct connection *server)
234239
status = server_read_reply(server, cmd);
235240

236241
cmd->rep_time[1] = now;
242+
if (cmd->parent) {
243+
int64_t parent_rep_end_time = cmd->parent->rep_time[1];
244+
if (parent_rep_end_time == 0 || parent_rep_end_time < now)
245+
cmd->parent->rep_time[1] = now;
246+
}
237247

238248
switch (status) {
239249
case CORVUS_ASKING:

src/slowlog.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ bool slowlog_statsd_enabled()
164164
bool slowlog_type_need_log(struct command *cmd)
165165
{
166166
return cmd->request_type != CMD_EXTRA
167-
&& cmd->request_type != CMD_UNIMPL;
167+
&& cmd->request_type != CMD_UNIMPL
168+
&& cmd->reply_type != REP_ERROR;
168169
}
169170

170171
bool slowlog_need_log(struct command *cmd, long long latency)

0 commit comments

Comments
 (0)