Commit 834a2476 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Introduced new state, sync_idle, to really solve the sync problems.

parent 31409830
/*
* $Id: simple-cache.c,v 0.32 1993/08/05 01:06:12 ceder Exp $
* $Id: simple-cache.c,v 0.33 1993/08/13 14:17:29 ceder Exp $
* Copyright (C) 1991 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -33,7 +33,7 @@
* New save algorithm by ceder.
*/
static char *rcsid = "$Id: simple-cache.c,v 0.32 1993/08/05 01:06:12 ceder Exp $";
static char *rcsid = "$Id: simple-cache.c,v 0.33 1993/08/13 14:17:29 ceder Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -112,6 +112,7 @@ static FILE *file_b = NULL; /* File under construction. */
* Four state variables for the background save.
*/
static enum {
sync_idle,
sync_save_conf,
sync_save_pers,
sync_save_text,
......@@ -120,6 +121,21 @@ static enum {
sync_ready
} sync_state;
/* The state machine sync_state works like this:
*
* Old state action new state
* none sync_part called sync_idle
* for the first time
* sync_idle SYNC_INTERVAL sync_save_conf
* sync_save_conf all confs saved sync_save_pers
* sync_save_pers all persons saved sync_save_text
* sync_save_text all texts saved sync_ready
* sync_ready sync_part called sync_idle
* any error occurs sync_error
* sync_error sync_part called sync_wait
* sync_wait SYNC_RETRY_INTERVAL sync_save_conf
*/
static long sync_next;
static Conf_no highest_conf_no;
......@@ -1773,7 +1789,7 @@ sync_part(void)
if ( last_sync_start == NO_TIME )
{
last_sync_start = time(NULL);
sync_state = sync_ready;
sync_state = sync_idle;
}
#ifdef LOGACCESSES
......@@ -1795,14 +1811,10 @@ sync_part(void)
break;
case sync_ready:
#if 0
/* This doesn't work. It causes the server to enter an
infinite loop when it is exiting if it takes more than
SYNC_INTERVAL minutes to save the text. The fix below is
not perfect; if it takes more than SYNC_INTERVAL minutes to
save the data base the server will pause for TIMEOUT ms
instead of SYNCTIMEOUT ms once. A real event queue should
be implemented to fix this. +++ */
sync_state = sync_idle;
return TRUE;
case sync_idle:
if ( difftime(time(NULL), last_sync_start) < 60 * SYNC_INTERVAL )
{
#ifdef LOGACCESSES
......@@ -1814,12 +1826,6 @@ sync_part(void)
last_sync_start = time(NULL);
pre_sync();
#else /* This works, but it might take too long a pause. */
#ifdef LOGACCESSES
syncing_or_saving = 0;
#endif
return TRUE;
#endif /* 1 */
break;
case sync_wait:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment