@@ -22,8 +22,8 @@ typedef enum cmd_in_second_state{
2222}state ;
2323
2424typedef 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
6666static 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
0 commit comments