Added a function that flushes all logfiles synchronously.

This commit is contained in:
Markus Makela
2014-11-25 14:43:43 +02:00
parent 75e9c30d49
commit 3d50d8f117
2 changed files with 55 additions and 0 deletions

View File

@ -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;
}