Skip to content

Commit 42d796a

Browse files
fix warning
1 parent 499bc4b commit 42d796a

File tree

3 files changed

+56
-16
lines changed

3 files changed

+56
-16
lines changed

cmd_in_second.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ typedef enum cmd_in_second_state{
2222
}state;
2323

2424
typedef struct cmd_in_second_log{
25-
char key[256];
26-
char client_ip[16];
25+
char key[KEY_LENGTH];
26+
char client_ip[IP_LENGTH];
2727
int32_t timer_idx;
2828
}logtype;
2929

@@ -65,7 +65,7 @@ static bool is_bulk_cmd()
6565

6666
static void get_whole_cmd(char* whole_cmd)
6767
{
68-
if (this.collection_name) {
68+
if (strlen(this.collection_name)) {
6969
sprintf(whole_cmd, "%s %s", this.collection_name, this.cmd);
7070
return;
7171
}
@@ -87,7 +87,7 @@ static void* buffer_flush_thread()
8787
return NULL;
8888
}
8989

90-
char whole_cmd[20] = {0};
90+
char whole_cmd[20] = "";
9191
get_whole_cmd(whole_cmd);
9292

9393
buffertype* buffer = &this.buffer;
@@ -102,6 +102,8 @@ static void* buffer_flush_thread()
102102
return NULL;
103103
}
104104

105+
int32_t expected_write_length = 0;
106+
105107
while (!buffer_empty()) {
106108

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

116118
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);
117119
timer_idx = front.timer_idx;
120+
121+
expected_write_length += 27;
118122
}
119123
char log[LOG_LENGTH] = "";
120124
sprintf(log, "%s%s %s %s\n", time_str, whole_cmd, front.key, front.client_ip);
121125
strncat(log_str, log, LOG_LENGTH);
122126

127+
expected_write_length += LOG_LENGTH;
123128
}
124129

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

127134
close(fd);
128135

@@ -191,7 +198,7 @@ bool cmd_in_second_write(const char* collection_name, const char* cmd, const cha
191198

192199
timertype *timer = &this.timer;
193200

194-
logtype log = { {0}, {0} };
201+
logtype log = {"", "", 0};
195202
snprintf(log.client_ip, IP_LENGTH, "%s", client_ip);
196203
snprintf(log.key, KEY_LENGTH, "%s", key);
197204

cmd_in_second.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
#define CMD_IN_SECOND_NO_MEM 2
1212

1313
int32_t cmd_in_second_start(const char* collection_name, const char* cmd, const int32_t bulk_limit);
14-
bool cmd_in_second_write(const char*collection_name, const char* cmd, const char* key, const char* client_ip);
14+
bool cmd_in_second_write(const char* collection_name, const char* cmd, const char* key, const char* client_ip);

t/bulk.t

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,52 @@ sub request_log{
1919
mem_cmd_is($sock, "cmd_in_second $whole_cmd $cnt", "", $rst);
2020
}
2121

22-
sub do_bulk_insert {
22+
sub do_bulk_coll_insert {
2323

24-
my ($collection, $cmd, $count) = @_;
24+
my ($collection, $count) = @_;
2525
my $start_time = time;
2626

27+
my $cmd = "insert";
2728
my $key = "mykey";
2829

2930
for (my $index=0; $index < $count; $index++) {
3031
my $val = "datum$index";
3132
my $vleng = length($val);
3233

33-
my $whole_cmd = "$collection $cmd $key $vleng";
34+
my $whole_cmd;
3435

35-
if ($collection eq "bop") {
36+
if ($collection eq "sop") {
37+
$whole_cmd = "$collection $cmd $key $vleng";
38+
}
39+
40+
elsif ($collection eq "bop" or $collection eq "lop") {
3641
$whole_cmd = "$collection $cmd $key $index $vleng";
3742
}
3843

44+
elsif ($collection eq "mop") {
45+
my $field = "f$index";
46+
$whole_cmd = "$collection $cmd $key $field $vleng";
47+
}
48+
49+
3950
my $rst = "STORED";
4051

4152
if ($index == 0) {
4253
my $create = "create 13 0 0";
4354

44-
$whole_cmd = "$collection $cmd $key $vleng $create";
55+
if ($collection eq "sop") {
56+
$whole_cmd = "$collection $cmd $key $vleng $create";
57+
}
4558

46-
if($collection eq "bop") {
59+
elsif ($collection eq "bop" or $collection eq "lop") {
4760
$whole_cmd = "$collection $cmd $key $index $vleng $create";
4861
}
4962

63+
elsif ($collection eq "mop") {
64+
my $field = "f$index";
65+
$whole_cmd = "$collection $cmd $key $field $vleng $create";
66+
}
67+
5068
$rst = "CREATED_STORED";
5169
}
5270

@@ -62,9 +80,24 @@ sub do_bulk_insert {
6280
}
6381

6482
unlink "../cmd_in_second.log";
65-
request_log("bop insert", 2000);
66-
do_bulk_bop_insert("bop", "insert", 2100);
83+
request_log("bop insert", 50);
84+
do_bulk_coll_insert("bop", 51);
85+
86+
my $file_handle;
87+
open($file_handle, "cmd_in_second.log") or die "log file not exist\n";
88+
close($file_handle);
89+
90+
sleep(1);
91+
mem_cmd_is($sock, "bop insert mykey 1000 9", "datum1000", "STORED");
92+
=pod
93+
94+
unlink "../cmd_in_second.log";
95+
request_log("mop insert", 10);
96+
do_bulk_coll_insert("mop", 11);
6797
68-
open(my $file_handle, "cmd_in_second.log") or die "log file not exist\n";
98+
open($file_handle, "cmd_in_second.log") or die "log file not exist\n";
99+
close($file_handle);
100+
=cut
69101

70102
release_memcached($engine, $server);
103+

0 commit comments

Comments
 (0)