diff --git a/log_manager/log_manager.cc b/log_manager/log_manager.cc index d27976f71..099e7489c 100644 --- a/log_manager/log_manager.cc +++ b/log_manager/log_manager.cc @@ -3073,3 +3073,57 @@ static int find_last_seqno( return seqno; } + +/** + * Flush all log files synchronously + * @return 1 if log flushing was successful, 0 in case an error occurred. + */ +int skygw_log_force_flush_all() +{ + int rval = 0, i; + logfile_t* lf; + + for (i = LOGFILE_FIRST; i <= LOGFILE_LAST; i <<= 1) + { + +#ifdef SS_DEBUG + char debugstr[512]; + + switch(i){ + case LOGFILE_ERROR: + sprintf(debugstr,"ERROR"); + break; + case LOGFILE_MESSAGE: + sprintf(debugstr,"MESSAGE"); + break; + case LOGFILE_TRACE: + sprintf(debugstr,"TRACE"); + break; + case LOGFILE_DEBUG: + sprintf(debugstr,"DEBUG"); + break; + } + skygw_log_write((logfile_id_t)i,"Force flushing LOG_%s",debugstr); +#endif + + bool nflushed = true; + lf = &lm->lm_logfile[(logfile_id_t)i]; + acquire_lock(&lf->lf_spinlock); + lf->lf_flushflag = true; + release_lock(&lf->lf_spinlock); + skygw_message_send(lf->lf_logmes); + + while(nflushed){ + acquire_lock(&lf->lf_spinlock); + nflushed = lf->lf_flushflag; + release_lock(&lf->lf_spinlock); + } + +#ifdef SS_DEBUG + fprintf(stderr,"Logfile %s flushed.\n",debugstr); +#endif + + } + + return rval; +} diff --git a/log_manager/log_manager.h b/log_manager/log_manager.h index af11d3a86..de70fb01b 100644 --- a/log_manager/log_manager.h +++ b/log_manager/log_manager.h @@ -113,6 +113,7 @@ void skygw_logmanager_exit(void); void skygw_log_done(void); int skygw_log_write(logfile_id_t id, const char* format, ...); int skygw_log_flush(logfile_id_t id); +int skygw_log_force_flush_all(); int skygw_log_rotate(logfile_id_t id); int skygw_log_write_flush(logfile_id_t id, const char* format, ...); int skygw_log_enable(logfile_id_t id);