@@ -42,8 +42,8 @@ typedef struct cmd_in_second_timer {
4242} timertype ;
4343
4444struct cmd_in_second {
45- char cmd [ 20 ] ;
46- char collection_name [ 10 ];
45+ int cmd ;
46+ char cmd_str [ 50 ];
4747 struct cmd_in_second_buffer buffer ;
4848 timertype timer ;
4949 int32_t bulk_limit ;
@@ -71,15 +71,6 @@ static bool is_bulk_cmd()
7171 return last_time -> tv_sec - front_time -> tv_sec <= 1 ;
7272}
7373
74- static void get_whole_cmd (char * whole_cmd )
75- {
76- if (strlen (this .collection_name )) {
77- snprintf (whole_cmd , 20 , "%s %s" , this .collection_name , this .cmd );
78- return ;
79- }
80- snprintf (whole_cmd , 15 , "%s" , this .cmd );
81- }
82-
8374static bool buffer_empty ()
8475{
8576 return this .buffer .front == this .buffer .rear ;
@@ -104,10 +95,7 @@ static void* buffer_flush_thread()
10495 return NULL ;
10596 }
10697
107- char whole_cmd [20 ] = "" ;
108- get_whole_cmd (whole_cmd );
109-
110- const size_t whole_cmd_len = strlen (whole_cmd );
98+ const size_t cmd_len = strlen (this .cmd_str );
11199 const int32_t whitespaces = 3 ;
112100
113101 size_t expected_write_length = 0 ;
@@ -138,10 +126,10 @@ static void* buffer_flush_thread()
138126 }
139127
140128 char log [LOG_LENGTH ] = "" ;
141- snprintf (log , LOG_LENGTH , "%s%s %s %s\n" , time_str , whole_cmd , front .key , front .client_ip );
129+ snprintf (log , LOG_LENGTH , "%s%s %s %s\n" , time_str , this . cmd_str , front .key , front .client_ip );
142130 strncat (log_str , log , LOG_LENGTH );
143131
144- expected_write_length += whole_cmd_len + strlen (front .key ) + strlen (front .client_ip ) + whitespaces ;
132+ expected_write_length += cmd_len + strlen (front .key ) + strlen (front .client_ip ) + whitespaces ;
145133 circular_log_counter = (circular_log_counter + 1 ) % this .log_per_timer ;
146134 }
147135
@@ -228,8 +216,7 @@ static bool is_cmd_to_log(const char* collection_name, const char* cmd)
228216 strcmp (this .cmd , cmd ) == 0 ;
229217}
230218
231- bool cmd_in_second_write (const char * collection_name , const char * cmd ,
232- const char * key , const char * client_ip )
219+ bool cmd_in_second_write (const int cmd , const char * key , const char * client_ip )
233220{
234221 pthread_mutex_lock (& this .lock );
235222 if (this .cur_state != ON_LOGGING || !is_cmd_to_log (collection_name , cmd )) {
@@ -252,9 +239,9 @@ bool cmd_in_second_write(const char* collection_name, const char* cmd,
252239 return true;
253240}
254241
242+ /* TODO mc_logger */
255243void cmd_in_second_init ()
256244{
257- assert ("test" );
258245 this .cur_state = NOT_STARTED ;
259246 pthread_mutex_init (& this .lock , NULL );
260247
@@ -270,8 +257,7 @@ void cmd_in_second_init()
270257 this .timer .ring = NULL ;
271258}
272259
273- int32_t cmd_in_second_start (const char * collection_name , const char * cmd ,
274- const int32_t bulk_limit )
260+ int cmd_in_second_start (const int cmd , const int bulk_limit )
275261{
276262
277263 pthread_mutex_lock (& this .lock );
@@ -281,6 +267,7 @@ int32_t cmd_in_second_start(const char* collection_name, const char* cmd,
281267 return CMD_IN_SECOND_STARTED_ALREADY ;
282268 }
283269
270+ this .cmd = cmd ;
284271 this .bulk_limit = bulk_limit ;
285272
286273 this .buffer .capacity = bulk_limit + 1 ;
@@ -302,9 +289,6 @@ int32_t cmd_in_second_start(const char* collection_name, const char* cmd,
302289 return CMD_IN_SECOND_NO_MEM ;
303290 }
304291
305- snprintf (this .collection_name , 5 , "%s" , collection_name );
306- snprintf (this .cmd , 15 , "%s" , cmd );
307-
308292 this .cur_state = ON_LOGGING ;
309293
310294 pthread_mutex_unlock (& this .lock );
0 commit comments