Commit e30734dc authored by David Byers's avatar David Byers
Browse files

Bug fixes to aux items.

Some initial (nonworking) code for a one-pass sync.
parent ff7ebeaa
# #
# Generated from: Makefile.src,v 1.29 1996/08/25 19:53:59 ceder Exp # Generated from: Makefile.src,v 1.30 1997/09/13 15:31:45 byers Exp
# Copyright (C) 1991, 1993, 1994, 1995, 1996 Lysator Academic Computer Association. # Copyright (C) 1991, 1993, 1994, 1995, 1996 Lysator Academic Computer Association.
# #
# This file is part of the LysKOM server. # This file is part of the LysKOM server.
......
/* /*
* $Id: aux-items.c,v 1.1 1997/09/13 15:31:55 byers Exp $ * $Id: aux-items.c,v 1.2 1997/10/23 12:37:20 byers Exp $
* Copyright (C) 1994, 1995, 1996 Lysator Academic Computer Association. * Copyright (C) 1994, 1995, 1996 Lysator Academic Computer Association.
* *
* This file is part of the LysKOM server. * This file is part of the LysKOM server.
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "manipulate.h" #include "manipulate.h"
#include "aux-items.h" #include "aux-items.h"
#include "kom-errno.h" #include "kom-errno.h"
#include "kom-memory.h"
#include "async.h" #include "async.h"
#include "com.h" #include "com.h"
#include "connections.h" #include "connections.h"
...@@ -531,7 +532,7 @@ aux_inherit_items(Aux_item_list *target, ...@@ -531,7 +532,7 @@ aux_inherit_items(Aux_item_list *target,
)) ))
continue; continue;
item = copy_aux_item(parent->items[i]); copy_aux_item(&item, &parent->items[i]);
prepare_aux_item(&item, parent->items[i].creator, def); prepare_aux_item(&item, parent->items[i].creator, def);
if (item.inherit_limit != 0) if (item.inherit_limit != 0)
item.inherit_limit -= 1; item.inherit_limit -= 1;
...@@ -541,25 +542,6 @@ aux_inherit_items(Aux_item_list *target, ...@@ -541,25 +542,6 @@ aux_inherit_items(Aux_item_list *target,
} }
} }
/*
* copy_aux_item
*
* Create a copy of an aux item by duplicating duplicable fields
* and duplicating all dynamically allocated memory
*/
Aux_item copy_aux_item(Aux_item item)
{
Aux_item new;
new = item;
new.data = EMPTY_STRING;
s_strcpy(&new.data, item.data);
return new;
}
/* /*
* filter_aux_item_list * filter_aux_item_list
* *
...@@ -815,8 +797,9 @@ void text_stat_add_aux_item_list(Text_stat *text_s, ...@@ -815,8 +797,9 @@ void text_stat_add_aux_item_list(Text_stat *text_s,
item_list->items[i].aux_no = text_s->highest_aux; item_list->items[i].aux_no = text_s->highest_aux;
item_list->items[i].creator = item_creator; item_list->items[i].creator = item_creator;
item_list->items[i].sent_at = time(NULL); item_list->items[i].sent_at = time(NULL);
text_s->aux_item_list.items[text_s->aux_item_list.length] copy_aux_item(
= copy_aux_item(item_list->items[i]); &text_s->aux_item_list.items[text_s->aux_item_list.length],
&item_list->items[i]);
text_s->aux_item_list.length += 1; text_s->aux_item_list.length += 1;
} }
} }
...@@ -897,8 +880,8 @@ conf_stat_add_aux_item_list(Conference *conf, ...@@ -897,8 +880,8 @@ conf_stat_add_aux_item_list(Conference *conf,
item_list->items[i].aux_no = conf->highest_aux; item_list->items[i].aux_no = conf->highest_aux;
item_list->items[i].creator = item_creator; item_list->items[i].creator = item_creator;
item_list->items[i].sent_at = time(NULL); item_list->items[i].sent_at = time(NULL);
conf->aux_item_list.items[conf->aux_item_list.length] copy_aux_item(&conf->aux_item_list.items[conf->aux_item_list.length],
= copy_aux_item(item_list->items[i]); &item_list->items[i]);
conf->aux_item_list.length += 1; conf->aux_item_list.length += 1;
} }
} }
...@@ -965,8 +948,8 @@ system_add_aux_item_list(Info *info, ...@@ -965,8 +948,8 @@ system_add_aux_item_list(Info *info,
item_list->items[i].aux_no = info->highest_aux_no; item_list->items[i].aux_no = info->highest_aux_no;
item_list->items[i].creator = item_creator; item_list->items[i].creator = item_creator;
item_list->items[i].sent_at = time(NULL); item_list->items[i].sent_at = time(NULL);
info->aux_item_list.items[info->aux_item_list.length] copy_aux_item(&info->aux_item_list.items[info->aux_item_list.length],
= copy_aux_item(item_list->items[i]); &item_list->items[i]);
info->aux_item_list.length += 1; info->aux_item_list.length += 1;
} }
} }
......
/* /*
* $Id: aux-items.h,v 1.1 1997/09/13 15:31:56 byers Exp $ * $Id: aux-items.h,v 1.2 1997/10/23 12:37:21 byers Exp $
* Copyright (C) 1994, 1995, 1996 Lysator Academic Computer Association. * Copyright (C) 1994, 1995, 1996 Lysator Academic Computer Association.
* *
* This file is part of the LysKOM server. * This file is part of the LysKOM server.
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
(list).items = \ (list).items = \
srealloc((list).items, \ srealloc((list).items, \
((list).length + 1) * sizeof(Aux_item)); \ ((list).length + 1) * sizeof(Aux_item)); \
(list).items[(list).length] = copy_aux_item(item); \ copy_aux_item(&(list).items[(list).length], &item); \
(counter) += 1; \ (counter) += 1; \
(list).items[(list).length].aux_no = (counter); \ (list).items[(list).length].aux_no = (counter); \
(list).length += 1; \ (list).length += 1; \
...@@ -88,12 +88,6 @@ extern Aux_item_definition empty_aux_item_definition; ...@@ -88,12 +88,6 @@ extern Aux_item_definition empty_aux_item_definition;
/* Return a copy of item. If you think you need to
* call this, think again. */
Aux_item copy_aux_item(Aux_item item);
/* Inerit items from parent to target. counter is a pointer to /* Inerit items from parent to target. counter is a pointer to
* highest_aux_item or equivalent. target_creator is the creator * highest_aux_item or equivalent. target_creator is the creator
......
/* /*
* $Id: cache-node.h,v 0.10 1995/11/02 21:48:24 ceder Exp $ * $Id: cache-node.h,v 0.11 1997/10/23 12:37:22 byers Exp $
* Copyright (C) 1991, 1993, 1994, 1995 Lysator Academic Computer Association. * Copyright (C) 1991, 1993, 1994, 1995 Lysator Academic Computer Association.
* *
* This file is part of the LysKOM server. * This file is part of the LysKOM server.
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
* Please mail bug reports to bug-lyskom@lysator.liu.se. * Please mail bug reports to bug-lyskom@lysator.liu.se.
*/ */
/* /*
* $Id: cache-node.h,v 0.10 1995/11/02 21:48:24 ceder Exp $ * $Id: cache-node.h,v 0.11 1997/10/23 12:37:22 byers Exp $
* *
* cache-node.h * cache-node.h
*/ */
...@@ -31,15 +31,22 @@ ...@@ -31,15 +31,22 @@
typedef struct cache_node { typedef struct cache_node {
struct { struct {
unsigned int exists : 1; unsigned int exists : 1;
unsigned int dirty : 1; /* Is *ptr modified? */ unsigned int dirty : 1; /* Is *ptr modified? */
unsigned int snapshot : 1; /* We have a valid snapshot */
unsigned int saved_sirty : 1; /* Saved a dirty copy */
} s; } s;
void *snap_shot; /* Dirty data to be written to file B. */ void *snap_shot; /* Dirty data to be written to file B. */
/* (Dirty relative to file A). */ /* (Dirty relative to file A). */
void *ptr; /* In-core data. */ void *ptr; /* In-core data. */
long pos; /* Position to element in file A. */ long pos; /* Position to element in file A. */
long size; /* Size on disk. */ long size; /* Size on disk. */
#ifdef FASTSAVE
long saved_pos; /* Position saved in case of recover */
long saved_size; /* Size saved in case of recover */
#else
long pos_b; /* Position to element in file B. */ long pos_b; /* Position to element in file B. */
long size_b; /* Size in file B. */ long size_b; /* Size in file B. */
#endif
struct cache_node *prev; /* Points towards most recently used. */ struct cache_node *prev; /* Points towards most recently used. */
struct cache_node *next; /* Points towards least recently used. */ struct cache_node *next; /* Points towards least recently used. */
int lock_cnt; int lock_cnt;
......
/* /*
* $Id: kom-memory.h,v 1.6 1997/09/13 15:32:09 byers Exp $ * $Id: kom-memory.h,v 1.7 1997/10/23 12:37:23 byers Exp $
* Copyright (C) 1991, 1993, 1994, 1996 Lysator Academic Computer Association. * Copyright (C) 1991, 1993, 1994, 1996 Lysator Academic Computer Association.
* *
* This file is part of the LysKOM server. * This file is part of the LysKOM server.
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
* Please mail bug reports to bug-lyskom@lysator.liu.se. * Please mail bug reports to bug-lyskom@lysator.liu.se.
*/ */
/* /*
* $Id: kom-memory.h,v 1.6 1997/09/13 15:32:09 byers Exp $ * $Id: kom-memory.h,v 1.7 1997/10/23 12:37:23 byers Exp $
* *
* The time has come to get some order into this mess. * The time has come to get some order into this mess.
* *
...@@ -116,6 +116,10 @@ extern void init_who_info_old (Who_info_old *w); ...@@ -116,6 +116,10 @@ extern void init_who_info_old (Who_info_old *w);
/* Aux_item_list */ /* Aux_item_list */
extern void free_aux_item_list (Aux_item_list *list); extern void free_aux_item_list (Aux_item_list *list);
extern void copy_aux_item_list (Aux_item_list *dest, Aux_item_list *src);
extern void init_aux_item_list (Aux_item_list *list);
extern void copy_aux_item (Aux_item *dest, Aux_item *src);
/* /*
* Other kind of functions * Other kind of functions
......
/* /*
* $Id: memory.c,v 0.20 1997/09/13 15:32:13 byers Exp $ * $Id: memory.c,v 0.21 1997/10/23 12:37:25 byers Exp $
* Copyright (C) 1991, 1992, 1993, 1994, 1996 Lysator Academic Computer Association. * Copyright (C) 1991, 1992, 1993, 1994, 1996 Lysator Academic Computer Association.
* *
* This file is part of the LysKOM server. * This file is part of the LysKOM server.
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
* These functions should be used instead of smalloc/srealloc. * These functions should be used instead of smalloc/srealloc.
*/ */
static char *rcsid = "$Id: memory.c,v 0.20 1997/09/13 15:32:13 byers Exp $"; static char *rcsid = "$Id: memory.c,v 0.21 1997/10/23 12:37:25 byers Exp $";
#include "rcs.h" #include "rcs.h"
USE(rcsid); USE(rcsid);
...@@ -109,6 +109,7 @@ clear_conference(Conference *confp) ...@@ -109,6 +109,7 @@ clear_conference(Conference *confp)
s_clear(&confp->name); s_clear(&confp->name);
clear_member_list(&confp->members); clear_member_list(&confp->members);
clear_text_list(&confp->texts); clear_text_list(&confp->texts);
free_aux_item_list(&confp->aux_item_list);
init_conference(confp); init_conference(confp);
} }
...@@ -123,6 +124,8 @@ copy_conference (Conference *o) ...@@ -123,6 +124,8 @@ copy_conference (Conference *o)
s_strcpy(&c->name, o->name); s_strcpy(&c->name, o->name);
c->members = copy_member_list(o->members); c->members = copy_member_list(o->members);
c->texts = copy_text_list(o->texts); c->texts = copy_text_list(o->texts);
copy_aux_item_list(&c->aux_item_list,
&o->aux_item_list);
return c; return c;
} }
...@@ -142,6 +145,7 @@ init_conference (Conference *c) ...@@ -142,6 +145,7 @@ init_conference (Conference *c)
c->name = EMPTY_STRING; c->name = EMPTY_STRING;
init_member_list(&c->members); init_member_list(&c->members);
init_text_list(&c->texts); init_text_list(&c->texts);
init_aux_item_list(&c->aux_item_list);
} }
/* Dynamic_session_info */ /* Dynamic_session_info */
...@@ -553,13 +557,8 @@ clear_text_stat(Text_stat *t) ...@@ -553,13 +557,8 @@ clear_text_stat(Text_stat *t)
} }
} }
for (i = 0; i < t->aux_item_list.length; i++)
{
s_clear(&t->aux_item_list.items[i].data);
}
sfree(t->aux_item_list.items);
sfree(t->misc_items); sfree(t->misc_items);
free_aux_item_list(&t->aux_item_list);
init_text_stat(t); init_text_stat(t);
} }
...@@ -572,11 +571,8 @@ copy_text_stat(Text_stat *t) ...@@ -572,11 +571,8 @@ copy_text_stat(Text_stat *t)
*c = *t; *c = *t;
c->misc_items = smalloc(c->no_of_misc * sizeof(Misc_info)); c->misc_items = smalloc(c->no_of_misc * sizeof(Misc_info));
memcpy(c->misc_items, t->misc_items, c->no_of_misc * sizeof(Misc_info)); memcpy(c->misc_items, t->misc_items, c->no_of_misc * sizeof(Misc_info));
c->aux_item_list.items = copy_aux_item_list(&c->aux_item_list,
smalloc(c->aux_item_list.length * sizeof(Aux_item)); &t->aux_item_list);
memcpy(c->aux_item_list.items,
t->aux_item_list.items,
c->aux_item_list.length * sizeof(Aux_item));
return c; return c;
} }
...@@ -592,8 +588,7 @@ init_text_stat (Text_stat *t) ...@@ -592,8 +588,7 @@ init_text_stat (Text_stat *t)
t->no_of_misc = 0; t->no_of_misc = 0;
t->highest_aux = 0; t->highest_aux = 0;
t->misc_items = NULL; t->misc_items = NULL;
t->aux_item_list.length = 0; init_aux_item_list(&t->aux_item_list);
t->aux_item_list.items = NULL;
} }
/* struct tm */ /* struct tm */
...@@ -665,6 +660,35 @@ free_aux_item_list(Aux_item_list *list) ...@@ -665,6 +660,35 @@ free_aux_item_list(Aux_item_list *list)
list->items = NULL; list->items = NULL;
} }
void
copy_aux_item_list(Aux_item_list *dest, Aux_item_list *src)
{
unsigned long i;
*dest = *src;
dest->items = smalloc(sizeof(Aux_item) * src->length);
for (i = 0; i < src->length; i++)
{
copy_aux_item(&dest->items[i], &src->items[i]);
}
}
void
init_aux_item_list(Aux_item_list *list)
{
list->length = 0;
list->items = NULL;
}
void
copy_aux_item(Aux_item *dest, Aux_item *src)
{
*dest = *src;
dest->data = EMPTY_STRING;
s_strcpy(&dest->data, src->data);
}
/* /*
* Other kind of functions * Other kind of functions
*/ */
......
/* /*
* $Id: simple-cache.c,v 0.63 1997/09/13 15:32:40 byers Exp $ * $Id: simple-cache.c,v 0.64 1997/10/23 12:37:26 byers Exp $
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996 Lysator Academic Computer Association. * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996 Lysator Academic Computer Association.
* *
* This file is part of the LysKOM server. * This file is part of the LysKOM server.
...@@ -31,9 +31,10 @@ ...@@ -31,9 +31,10 @@
* New database format with texts in their own file by Inge Wallin. * New database format with texts in their own file by Inge Wallin.
* *
* New save algorithm by ceder. * New save algorithm by ceder.
* Attempt at newer algorithm by byers (FASTSAVE)
*/ */
static char *rcsid = "$Id: simple-cache.c,v 0.63 1997/09/13 15:32:40 byers Exp $"; static char *rcsid = "$Id: simple-cache.c,v 0.64 1997/10/23 12:37:26 byers Exp $";
#include "rcs.h" #include "rcs.h"
USE(rcsid); USE(rcsid);
...@@ -117,6 +118,9 @@ EXPORT Conf_no *conf_table = NULL; /* Used in conference.c. */ ...@@ -117,6 +118,9 @@ EXPORT Conf_no *conf_table = NULL; /* Used in conference.c. */
static FILE *text_file= NULL; static FILE *text_file= NULL;
static FILE *file_a = NULL; /* Current file. */ static FILE *file_a = NULL; /* Current file. */
static FILE *file_b = NULL; /* File under construction. */ static FILE *file_b = NULL; /* File under construction. */
#ifdef FASTSAVE
static FILE *file_b_r = NULL; /* Read from file under construction */
#endif
/* /*
* Four state variables for the background save. * Four state variables for the background save.
...@@ -146,7 +150,9 @@ static enum { ...@@ -146,7 +150,9 @@ static enum {
* sync_wait SYNC_RETRY_INTERVAL sync_save_conf * sync_wait SYNC_RETRY_INTERVAL sync_save_conf
*/ */
#ifndef FASTSAVE
static long sync_next; static long sync_next;
#endif
static Conf_no highest_conf_no; static Conf_no highest_conf_no;
static Text_no highest_text_no; static Text_no highest_text_no;
...@@ -1372,8 +1378,11 @@ is_clean(const char *fn) ...@@ -1372,8 +1378,11 @@ is_clean(const char *fn)
if ( (fp = fopen(fn, "rb")) == NULL ) if ( (fp = fopen(fn, "rb")) == NULL )
return FALSE; return FALSE;
if ( getc(fp) == 'C' && getc(fp) == 'L' && getc(fp) == 'E' if ( getc(fp) == 'C' &&
&& getc(fp) == 'A' && getc(fp) == 'N' ) getc(fp) == 'L' &&
getc(fp) == 'E' &&
getc(fp) == 'A' &&
getc(fp) == 'N' )
{ {
fclose(fp); fclose(fp);
return TRUE; return TRUE;
...@@ -1422,6 +1431,7 @@ pre_sync(void) ...@@ -1422,6 +1431,7 @@ pre_sync(void)
highest_text_no = next_text_num; highest_text_no = next_text_num;
highest_conf_no = next_free_num; highest_conf_no = next_free_num;
#ifndef FASTSAVE
for ( i = 1; i < highest_conf_no; i++ ) for ( i = 1; i < highest_conf_no; i++ )
{ {
node = get_conf_node(i); node = get_conf_node(i);
...@@ -1517,6 +1527,7 @@ pre_sync(void) ...@@ -1517,6 +1527,7 @@ pre_sync(void)
} }
} }
} }
#endif
/* All marking is done. Now open file B. */ /* All marking is done. Now open file B. */
...@@ -1532,9 +1543,12 @@ pre_sync(void) ...@@ -1532,9 +1543,12 @@ pre_sync(void)
{ {
log("pre_sync: Save in progress aborted.\n"); log("pre_sync: Save in progress aborted.\n");
fclose(file_b); fclose(file_b);
#ifdef FASTSAVE
file_b = NULL;
#endif
} }
if ( (file_b=fopen(param.datafile_name, "wb") ) == NULL ) if ( (file_b = fopen(param.datafile_name, "wb") ) == NULL )
{ {
log("WARNING: pre_sync: can't open file to save in.\n"); log("WARNING: pre_sync: can't open file to save in.\n");
sync_state = sync_wait; sync_state = sync_wait;
...@@ -1542,6 +1556,18 @@ pre_sync(void) ...@@ -1542,6 +1556,18 @@ pre_sync(void)
return; return;
} }
#ifdef FASTSAVE
if ( (file_b_r = fopen(param.datafile_name, "rb") ) == NULL )
{
fclose(file_b);
file_b = NULL;
log("WARNING: pre_sync: can't open file to save in for reading.\n");
sync_state = sync_wait;
return;
}
#endif
fprintf(file_b, "DIRTY:%05ld\n", 2L); /* DIRTY-FLAG and VERSION*/ fprintf(file_b, "DIRTY:%05ld\n", 2L); /* DIRTY-FLAG and VERSION*/
...@@ -1551,7 +1577,12 @@ pre_sync(void) ...@@ -1551,7 +1577,12 @@ pre_sync(void)
foutput_info(file_b, &kom_info); foutput_info(file_b, &kom_info);
fprintf(file_b, "\n"); fprintf(file_b, "\n");
sync_state = sync_save_conf; sync_state = sync_save_conf;
#ifdef FASTSAVE
next_text_to_sync = 1;
next_conf_to_sync = 1;
#else
sync_next = 1; sync_next = 1;
#endif
} }
static void static void
...@@ -1608,23 +1639,34 @@ save_one_conf(void) ...@@ -1608,23 +1639,34 @@ save_one_conf(void)
{ {
Cache_node *cn; Cache_node *cn;
#ifdef FASTSAVE
if (next_conf_to_sync < highest_conf_no)
#else
if (sync_next < highest_conf_no) if (sync_next < highest_conf_no)
#endif
{ {
cn = get_conf_node (sync_next); cn = get_conf_node (sync_next);
if ( cn == NULL ) if ( cn == NULL )
{ {
/* putc('@', file_b);
putc('\n', file_b); */
} }
else else
{ {
#ifdef FASTSAVE
cn->saved_pos = cn->pos;
cn->pos = ftell(file_b);
cn->s.saved_dirty = cn->s.dirty;
#else
cn->pos_b = ftell(file_b); cn->pos_b = ftell(file_b);
#endif
if ( cn->snap_shot != NULL ) if ( cn->snap_shot != NULL )
{ {
fprintf(file_b, "C %ld ", sync_next); fprintf(file_b, "C %ld ", sync_next);
foutput_conference(file_b, cn->snap_shot); foutput_conference(file_b, cn->snap_shot);
#ifdef FASTSAVE
free_conference( cn->snap_shot );
#endif
} }
else if ( cn->s.dirty == 0 && cn->ptr != NULL ) else if ( cn->s.dirty == 0 && cn->ptr != NULL )
{ {
...@@ -1637,14 +1679,28 @@ save_one_conf(void) ...@@ -1637,14 +1679,28 @@ save_one_conf(void)
} }