Skip to content

Commit

Permalink
fix warning
Browse files Browse the repository at this point in the history
  • Loading branch information
computerphilosopher committed Aug 1, 2019
1 parent 499bc4b commit f1e331b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions cmd_in_second.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ typedef enum cmd_in_second_state{
}state;

typedef struct cmd_in_second_log{
char key[256];
char client_ip[16];
char key[KEY_LENGTH];
char client_ip[IP_LENGTH];
int32_t timer_idx;
}logtype;

Expand Down Expand Up @@ -65,7 +65,7 @@ static bool is_bulk_cmd()

static void get_whole_cmd(char* whole_cmd)
{
if (this.collection_name) {
if (strlen(this.collection_name)) {
sprintf(whole_cmd, "%s %s", this.collection_name, this.cmd);
return;
}
Expand All @@ -87,7 +87,7 @@ static void* buffer_flush_thread()
return NULL;
}

char whole_cmd[20] = {0};
char whole_cmd[20] = "";
get_whole_cmd(whole_cmd);

buffertype* buffer = &this.buffer;
Expand All @@ -102,6 +102,8 @@ static void* buffer_flush_thread()
return NULL;
}

int32_t expected_write_length = 0;

while (!buffer_empty()) {

logtype front = buffer->ring[buffer->front++];
Expand All @@ -115,14 +117,19 @@ static void* buffer_flush_thread()

sprintf(time_str, "%04d-%02d-%02d %02d:%02d:%02d.%06d\n", lt ->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec, (int32_t)front_time->tv_usec);
timer_idx = front.timer_idx;

expected_write_length += 27;
}
char log[LOG_LENGTH] = "";
sprintf(log, "%s%s %s %s\n", time_str, whole_cmd, front.key, front.client_ip);
strncat(log_str, log, LOG_LENGTH);

expected_write_length += LOG_LENGTH;
}

write(fd, log_str, strlen(log_str));
if (write(fd, log_str, strlen(log_str)) != expected_write_length) {
mc_logger->log(EXTENSION_LOG_WARNING, NULL, "write length is difference to expectation.");
}

close(fd);

Expand Down
2 changes: 1 addition & 1 deletion t/bulk.t
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ sub do_bulk_insert {

unlink "../cmd_in_second.log";
request_log("bop insert", 2000);
do_bulk_bop_insert("bop", "insert", 2100);
do_bulk_insert("bop", "insert", 2100);

open(my $file_handle, "cmd_in_second.log") or die "log file not exist\n";

Expand Down

0 comments on commit f1e331b

Please sign in to comment.