diff --git a/include/MySQL_Logger.hpp b/include/MySQL_Logger.hpp index 30ba475c6..49db93247 100644 --- a/include/MySQL_Logger.hpp +++ b/include/MySQL_Logger.hpp @@ -17,6 +17,7 @@ class MySQL_Logger { MySQL_Logger(); ~MySQL_Logger(); void flush_log(); + void flush_log_unlocked(); unsigned int find_next_id(); void set_datadir(char *); void log_request(MySQL_Session *); diff --git a/lib/MySQL_Logger.cpp b/lib/MySQL_Logger.cpp index 503934637..228ca5e4c 100644 --- a/lib/MySQL_Logger.cpp +++ b/lib/MySQL_Logger.cpp @@ -14,6 +14,8 @@ MySQL_Logger::MySQL_Logger() { base_filename=(char *)"mysql-log"; spinlock_rwlock_init(&rwlock); logfile=NULL; + log_file_id=0; + max_log_file_size=1024*1024; }; MySQL_Logger::~MySQL_Logger() { @@ -32,13 +34,21 @@ void MySQL_Logger::wrunlock() { void MySQL_Logger::flush_log() { wrlock(); + flush_log_unlocked(); + wrunlock(); +} +void MySQL_Logger::flush_log_unlocked() { if (logfile) { logfile->flush(); logfile->close(); delete logfile; logfile=NULL; } - log_file_id=find_next_id()+1; + if (log_file_id==0) { + log_file_id=find_next_id()+1; + } else { + log_file_id++; + } char *filen=(char *)malloc(strlen(datadir)+strlen(base_filename)+10); sprintf(filen,"%s/%s.%06d",datadir,base_filename,log_file_id); logfile=new std::fstream(); @@ -55,7 +65,6 @@ void MySQL_Logger::flush_log() { //int fd=open(filen, O_WRONLY | O_APPEND | O_CREAT , S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); free(filen); //close(fd); - wrunlock(); }; void MySQL_Logger::set_datadir(char *s) { @@ -78,6 +87,10 @@ void MySQL_Logger::log_request(MySQL_Session *sess) { ev.set_client(""); wrlock(); ev.SerializeToOstream(logfile); + unsigned long curpos=logfile->tellp(); + if (curpos > max_log_file_size) { + flush_log_unlocked(); + } //*logfile << t << std::endl << id << std::endl << std::endl ; wrunlock(); }