@@ -14,6 +14,7 @@ using json = nlohmann::json;
14
14
#endif /* DEBUG */
15
15
#define PROXYSQL_MYSQL_LOGGER_VERSION " 2.0.0714" DEB
16
16
17
+ extern MySQL_Logger *GloMyLogger;
17
18
18
19
static uint8_t mysql_encode_length (uint64_t len, unsigned char *hd) {
19
20
if (len < 251 ) return 1 ;
@@ -225,6 +226,9 @@ void MySQL_Event::write_auth(std::fstream *f, MySQL_Session *sess) {
225
226
}
226
227
j[" ssl" ] = sess->client_myds ->encrypted ;
227
228
}
229
+ // for performance reason, we are moving the write lock
230
+ // right before the write to disk
231
+ GloMyLogger->wrlock ();
228
232
*f << j.dump () << std::endl;
229
233
}
230
234
@@ -253,6 +257,10 @@ uint64_t MySQL_Event::write_query_format_1(std::fstream *f) {
253
257
254
258
total_bytes+=mysql_encode_length (query_len,NULL )+query_len;
255
259
260
+ // for performance reason, we are moving the write lock
261
+ // right before the write to disk
262
+ GloMyLogger->wrlock ();
263
+
256
264
// write total length , fixed size
257
265
f->write ((const char *)&total_bytes,sizeof (uint64_t ));
258
266
// char prefix;
@@ -389,6 +397,11 @@ uint64_t MySQL_Event::write_query_format_2_json(std::fstream *f) {
389
397
char digest_hex[20 ];
390
398
sprintf (digest_hex," 0x%016llX" , (long long unsigned int )query_digest);
391
399
j[" digest" ] = digest_hex;
400
+
401
+ // for performance reason, we are moving the write lock
402
+ // right before the write to disk
403
+ GloMyLogger->wrlock ();
404
+
392
405
*f << j.dump () << std::endl;
393
406
return total_bytes; // always 0
394
407
}
@@ -690,7 +703,9 @@ void MySQL_Logger::log_request(MySQL_Session *sess, MySQL_Data_Stream *myds) {
690
703
me.set_server (hid,sa,sl);
691
704
}
692
705
693
- wrlock ();
706
+ // for performance reason, we are moving the write lock
707
+ // right before the write to disk
708
+ // wrlock();
694
709
695
710
me.write (events.logfile , sess);
696
711
@@ -840,7 +855,9 @@ void MySQL_Logger::log_audit_entry(log_event_type _et, MySQL_Session *sess, MySQ
840
855
me.set_extra_info (xi);
841
856
}
842
857
843
- wrlock ();
858
+ // for performance reason, we are moving the write lock
859
+ // right before the write to disk
860
+ // wrlock();
844
861
845
862
me.write (audit.logfile , sess);
846
863
0 commit comments