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 42d796a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 16 deletions.
19 changes: 13 additions & 6 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, expected_write_length) != expected_write_length) {
mc_logger->log(EXTENSION_LOG_WARNING, NULL, "write length is difference to expectation.");
}

close(fd);

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

timertype *timer = &this.timer;

logtype log = { {0}, {0} };
logtype log = {"", "", 0};
snprintf(log.client_ip, IP_LENGTH, "%s", client_ip);
snprintf(log.key, KEY_LENGTH, "%s", key);

Expand Down
2 changes: 1 addition & 1 deletion cmd_in_second.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
#define CMD_IN_SECOND_NO_MEM 2

int32_t cmd_in_second_start(const char* collection_name, const char* cmd, const int32_t bulk_limit);
bool cmd_in_second_write(const char*collection_name, const char* cmd, const char* key, const char* client_ip);
bool cmd_in_second_write(const char* collection_name, const char* cmd, const char* key, const char* client_ip);
51 changes: 42 additions & 9 deletions t/bulk.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,52 @@ sub request_log{
mem_cmd_is($sock, "cmd_in_second $whole_cmd $cnt", "", $rst);
}

sub do_bulk_insert {
sub do_bulk_coll_insert {

my ($collection, $cmd, $count) = @_;
my ($collection, $count) = @_;
my $start_time = time;

my $cmd = "insert";
my $key = "mykey";

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

my $whole_cmd = "$collection $cmd $key $vleng";
my $whole_cmd;

if ($collection eq "bop") {
if ($collection eq "sop") {
$whole_cmd = "$collection $cmd $key $vleng";
}

elsif ($collection eq "bop" or $collection eq "lop") {
$whole_cmd = "$collection $cmd $key $index $vleng";
}

elsif ($collection eq "mop") {
my $field = "f$index";
$whole_cmd = "$collection $cmd $key $field $vleng";
}


my $rst = "STORED";

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

$whole_cmd = "$collection $cmd $key $vleng $create";
if ($collection eq "sop") {
$whole_cmd = "$collection $cmd $key $vleng $create";
}

if($collection eq "bop") {
elsif ($collection eq "bop" or $collection eq "lop") {
$whole_cmd = "$collection $cmd $key $index $vleng $create";
}

elsif ($collection eq "mop") {
my $field = "f$index";
$whole_cmd = "$collection $cmd $key $field $vleng $create";
}

$rst = "CREATED_STORED";
}

Expand All @@ -62,9 +80,24 @@ sub do_bulk_insert {
}

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

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

sleep(1);
mem_cmd_is($sock, "bop insert mykey 1000 9", "datum1000", "STORED");
=pod
unlink "../cmd_in_second.log";
request_log("mop insert", 10);
do_bulk_coll_insert("mop", 11);
open(my $file_handle, "cmd_in_second.log") or die "log file not exist\n";
open($file_handle, "cmd_in_second.log") or die "log file not exist\n";
close($file_handle);
=cut

release_memcached($engine, $server);

0 comments on commit 42d796a

Please sign in to comment.