Commit c4e3f18f authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Added the -L swith (logging of all database accesses).

parent 1453ac80
Sun Nov 22 16:04:11 1992 Per Cederqvist (ceder@mauritz)
* config.h (LOGACCESSES): New symbol.
Sat Apr 4 19:08:51 1992 Per Cederqvist (ceder@lysator) Sat Apr 4 19:08:51 1992 Per Cederqvist (ceder@lysator)
* kom-types.h (Who_info_ident, Who_info_ident_list, * kom-types.h (Who_info_ident, Who_info_ident_list,
......
/* /*
* $Id: config.h,v 0.5 1992/03/31 20:52:09 ceder Exp $ * $Id: config.h,v 0.6 1992/11/22 15:14:15 ceder Exp $
* Copyright (C) 1991 Lysator Academic Computer Association. * Copyright (C) 1991 Lysator Academic Computer Association.
* *
* This file is part of the LysKOM server. * This file is part of the LysKOM server.
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include <m-config.h> #include <m-config.h>
#define DEBUG /* We're still debugging and want traces. */ #define DEBUG /* We're still debugging and want traces. */
#define LOGACCESSES /* Log all accesses to the data base. */
/* /*
* Add some checks that really shouldn't be necessary. * Add some checks that really shouldn't be necessary.
*/ */
......
Sun Nov 22 16:06:36 1992 Per Cederqvist (ceder@mauritz)
* version.incl: Version 1.2.7.
* Support for logging of all db accesses:
* ramkomd.c (main): Added -L option.
* cache.h (tell_cache_garb_text): New function.
* simple-cache.c: Do the logging.
* text-garb.c (garb_text): Inhibit the logging while garbing.
* cache.h: Removed unused stuff.
Mon Nov 2 19:18:08 1992 Per Cederqvist (ceder@mauritz)
* simple-cache.c (LOGFILE): Deleted the changes from Tue Oct 27.
* cache.h (MAX_CACHED_PERSONS, MAX_CACHED_WHATEVER,
cached_load_names, cached_add_name): was unused, is deleted.
Tue Oct 27 05:27:55 1992 Per Cederqvist (ceder@ruben) Tue Oct 27 05:27:55 1992 Per Cederqvist (ceder@ruben)
* version.incl: Version 1.2.6. * version.incl: Version 1.2.6.
......
/* /*
* $Id: cache.h,v 0.8 1991/11/10 19:02:48 linus Exp $ * $Id: cache.h,v 0.9 1992/11/22 15:14:37 ceder Exp $
* Copyright (C) 1991 Lysator Academic Computer Association. * Copyright (C) 1991 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.h,v 0.8 1991/11/10 19:02:48 linus Exp $ * $Id: cache.h,v 0.9 1992/11/22 15:14:37 ceder Exp $
* *
* This file contains the cached data that the server stores. * This file contains the cached data that the server stores.
* .h file created by ceder 1990-04-18 * .h file created by ceder 1990-04-18
...@@ -67,10 +67,6 @@ cache_sync(void); ...@@ -67,10 +67,6 @@ cache_sync(void);
/* S}d{r ja. Tack f|r mig. /ceder */ /* S}d{r ja. Tack f|r mig. /ceder */
#define MAX_CACHED_PERSONS 5 /* To be increased after debugging */
#define MAX_CACHED_WHATEVER /* To be added */
/* /*
* Name caching routines * Name caching routines
*/ */
...@@ -87,24 +83,6 @@ cached_change_name(Conf_no name_num, ...@@ -87,24 +83,6 @@ cached_change_name(Conf_no name_num,
String new_name ); String new_name );
/* add_name adds a name to the list of cached conference names. It is only
* used when a new conference is created.
*/
extern void
cached_add_name( char * new_name );
/* load all the conference names from disk and store them in memory */
extern void
cached_load_names( void );
#if 0
/* get one name (I want this call! /ceder) */
/* I no longer want it. */
extern String
cached_get_name( Conf_no conf_no ); /* Returns NULL if the conference */
/* doesn't exist. */
#endif
extern Bool extern Bool
cached_conf_exists( Conf_no conf_no ); cached_conf_exists( Conf_no conf_no );
...@@ -132,13 +110,6 @@ cached_get_highest_local_no (Conf_no conf_no); ...@@ -132,13 +110,6 @@ cached_get_highest_local_no (Conf_no conf_no);
/*
* Person caching routines
*/
#if 0
extern Person *
cached_read_person( Pers_no pers_no );
#endif
/* /*
* Various function calls to tell the cache that something is changed. * Various function calls to tell the cache that something is changed.
*/ */
...@@ -258,3 +229,10 @@ dump_cache_mem_usage(FILE *stat_file); ...@@ -258,3 +229,10 @@ dump_cache_mem_usage(FILE *stat_file);
*/ */
int int
query_next_text_num(void); query_next_text_num(void);
/*
* Tell the cache that a text garbage collection operation is in progress
* or is finished.
*/
void
tell_cache_garb_text(int running);
/* /*
* $Id: ramkomd.c,v 0.30 1992/06/10 01:37:39 ceder Exp $ * $Id: ramkomd.c,v 0.31 1992/11/22 15:14:41 ceder Exp $
* Copyright (C) 1991 Lysator Academic Computer Association. * Copyright (C) 1991 Lysator Academic Computer Association.
* *
* This file is part of the LysKOM server. * This file is part of the LysKOM server.
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
* It has grown! /ceder * It has grown! /ceder
*/ */
static char *rcsid = "$Id: ramkomd.c,v 0.30 1992/06/10 01:37:39 ceder Exp $"; static char *rcsid = "$Id: ramkomd.c,v 0.31 1992/11/22 15:14:41 ceder Exp $";
#include <m-config.h> #include <m-config.h>
...@@ -83,7 +83,9 @@ int buglevel = 0; ...@@ -83,7 +83,9 @@ int buglevel = 0;
Bool never_save = FALSE; Bool never_save = FALSE;
#endif #endif
#ifdef LOGACCESSES
char *logaccess_file = NULL;
#endif
EXPORT char datafilename[BUFSIZ]; /* Full pathname to the database file */ EXPORT char datafilename[BUFSIZ]; /* Full pathname to the database file */
EXPORT char backupfilename[BUFSIZ]; /* Full pathname to the backup file */ EXPORT char backupfilename[BUFSIZ]; /* Full pathname to the backup file */
...@@ -333,9 +335,19 @@ main (int argc, ...@@ -333,9 +335,19 @@ main (int argc,
send_async_messages = FALSE; send_async_messages = FALSE;
break; break;
#ifdef LOGACCESSES
case 'L':
logaccess_file = argv[i] + 2;
break;
#endif
default: default:
restart_kom("usage: %s [-d] [-q] [-Ddir] [-pport] [-Pmuxport]" restart_kom("usage: %s [-d] [-q] [-Ddir] [-pport] [-Pmuxport]"
" [-a]\n", argv[0]); " [-a]"
#ifdef LOGACCESSES
" [-Ldb_trace_file]"
#endif
"\n", argv[0]);
} }
if (i < argc) if (i < argc)
......
/* /*
* $Id: simple-cache.c,v 0.27 1992/11/02 18:46:31 ceder Exp $ * $Id: simple-cache.c,v 0.28 1992/11/22 15:14:47 ceder Exp $
* Copyright (C) 1991 Lysator Academic Computer Association. * Copyright (C) 1991 Lysator Academic Computer Association.
* *
* This file is part of the LysKOM server. * This file is part of the LysKOM server.
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
* New save algorithm by ceder. * New save algorithm by ceder.
*/ */
static char *rcsid = "$Id: simple-cache.c,v 0.27 1992/11/02 18:46:31 ceder Exp $"; static char *rcsid = "$Id: simple-cache.c,v 0.28 1992/11/22 15:14:47 ceder Exp $";
/* /*
...@@ -124,6 +123,59 @@ static Text_no highest_text_no; ...@@ -124,6 +123,59 @@ static Text_no highest_text_no;
BUGDECL; BUGDECL;
/* Define LOGACCESSES if you want to be able to log all accesses to
the data base. */
#ifdef LOGACCESSES
extern char *logaccess_file; /* From ramkomd.c */
typedef enum {
lt_restart,
lt_text_stat,
lt_text_mass,
lt_conf_stat,
lt_pers_stat,
lt_text_def,
lt_conf_def,
lt_pers_def,
lt_create_text,
lt_garb_text,
lt_delete_text,
lt_create_conf,
lt_delete_conf,
lt_create_pers,
lt_delete_pers,
lt_lock_conf,
lt_unlock_conf,
lt_lock_pers,
lt_unlock_pers,
lt_get_highest, /* Get highest Local_text_no for a conf. */
lt_get_conf_type
/* Note: mark_*_as_changed is not logged. */
} Log_type;
static FILE *logfile = NULL;
static int syncing_or_saving = 0;
static int garb_running = 0;
static void log_access(Log_type t,
int id)
{
if (garb_running + syncing_or_saving == 0)
{
putc(t, logfile);
putw(id, logfile);
}
}
#define LOGACC(a,b) {if (logfile) log_access(a, b);}
#else
#define LOGACC(a,b)
#endif
/* Macros */ /* Macros */
...@@ -286,6 +338,8 @@ cached_get_conf_type (Conf_no conf_no) ...@@ -286,6 +338,8 @@ cached_get_conf_type (Conf_no conf_no)
restart_kom("cached_get_conf_type(%d): conference does not exist.\n", restart_kom("cached_get_conf_type(%d): conference does not exist.\n",
conf_no); conf_no);
LOGACC(lt_get_conf_type, conf_no);
return small_conf_arr [ conf_no ]->type; return small_conf_arr [ conf_no ]->type;
} }
...@@ -400,6 +454,9 @@ cached_create_person( Pers_no person ) ...@@ -400,6 +454,9 @@ cached_create_person( Pers_no person )
node->s.dirty = 1; node->s.dirty = 1;
node->s.exists = 1; node->s.exists = 1;
pers_set_mru( person ); pers_set_mru( person );
LOGACC(lt_create_pers, person);
return OK; return OK;
} }
...@@ -431,6 +488,8 @@ cached_get_person_stat( Pers_no person ) ...@@ -431,6 +488,8 @@ cached_get_person_stat( Pers_no person )
return NULL; return NULL;
} }
LOGACC(lt_pers_stat, person);
if ( node->ptr != NULL ) if ( node->ptr != NULL )
{ {
pers_set_mru( person ); pers_set_mru( person );
...@@ -529,6 +588,8 @@ cached_create_conf (String name) ...@@ -529,6 +588,8 @@ cached_create_conf (String name)
TRACE2("Created conference number %d\n", conf_no); TRACE2("Created conference number %d\n", conf_no);
LOGACC(lt_create_conf, conf_no);
return conf_no; return conf_no;
} }
...@@ -566,6 +627,8 @@ cached_delete_conf( Conf_no conf ) ...@@ -566,6 +627,8 @@ cached_delete_conf( Conf_no conf )
node->ptr = NULL; node->ptr = NULL;
node->s.exists = 0; node->s.exists = 0;
LOGACC(lt_delete_conf, conf);
return OK; return OK;
} }
...@@ -602,6 +665,8 @@ cached_delete_person(Pers_no pers) ...@@ -602,6 +665,8 @@ cached_delete_person(Pers_no pers)
log("cached_delete_pers(%lu): lock_cnt === %lu\n", log("cached_delete_pers(%lu): lock_cnt === %lu\n",
(u_long)pers, (u_long)node->lock_cnt); (u_long)pers, (u_long)node->lock_cnt);
LOGACC(lt_delete_pers, pers);
free_person (node->ptr); free_person (node->ptr);
node->ptr = NULL; node->ptr = NULL;
node->s.exists = 0; node->s.exists = 0;
...@@ -639,6 +704,15 @@ cached_delete_text(Text_no text) ...@@ -639,6 +704,15 @@ cached_delete_text(Text_no text)
node->ptr = NULL; node->ptr = NULL;
node->s.exists = 0; node->s.exists = 0;
#ifdef LOGACCESSES
if (garb_running)
{
putc(t, lt_garb_text);
putw(id, text);
}
else
log_access(lt_delete_text, text);
#endif
return OK; return OK;
} }
...@@ -664,6 +738,8 @@ cached_get_conf_stat (Conf_no conf_no) ...@@ -664,6 +738,8 @@ cached_get_conf_stat (Conf_no conf_no)
return NULL; return NULL;
} }
LOGACC(lt_conf_stat, conf_no);
if ( node->ptr != NULL ) if ( node->ptr != NULL )
{ {
conf_set_mru (conf_no); conf_set_mru (conf_no);
...@@ -722,6 +798,7 @@ cached_get_text( Text_no text ) ...@@ -722,6 +798,7 @@ cached_get_text( Text_no text )
return EMPTY_STRING; return EMPTY_STRING;
else else
{ {
LOGACC(lt_text_mass, text);
the_string.string = tmp_alloc( t_stat->no_of_chars ); the_string.string = tmp_alloc( t_stat->no_of_chars );
the_string.len = t_stat->no_of_chars; the_string.len = t_stat->no_of_chars;
fseek(text_file, t_stat->file_pos, SEEK_SET); fseek(text_file, t_stat->file_pos, SEEK_SET);
...@@ -763,6 +840,8 @@ cached_get_text_stat( Text_no text ) ...@@ -763,6 +840,8 @@ cached_get_text_stat( Text_no text )
return NULL; return NULL;
} }
LOGACC(lt_text_stat, text);
if ( node->ptr != NULL ) if ( node->ptr != NULL )
{ {
TRACE1("Found in ptr.\n"); TRACE1("Found in ptr.\n");
...@@ -840,6 +919,7 @@ cached_create_text( String message) ...@@ -840,6 +919,7 @@ cached_create_text( String message)
fflush(text_file); fflush(text_file);
LOGACC(lt_create_text, tno);
TRACE2("cached_create_text -> %d\n", tno); TRACE2("cached_create_text -> %d\n", tno);
return tno; return tno;
...@@ -913,6 +993,8 @@ cached_get_garb_nice (Conf_no conf_no) ...@@ -913,6 +993,8 @@ cached_get_garb_nice (Conf_no conf_no)
extern Local_text_no extern Local_text_no
cached_get_highest_local_no (Conf_no conf_no) cached_get_highest_local_no (Conf_no conf_no)
{ {
LOGACC(lt_get_highest, conf_no);
return small_conf_arr[ conf_no ]->highest_local_no; return small_conf_arr[ conf_no ]->highest_local_no;
} }
...@@ -922,6 +1004,8 @@ cached_lock_person(Pers_no pers_no) ...@@ -922,6 +1004,8 @@ cached_lock_person(Pers_no pers_no)
{ {
Cache_node *node; Cache_node *node;
LOGACC(lt_lock_pers, pers_no);
node = get_pers_node(pers_no); node = get_pers_node(pers_no);
if ( node == NULL || node->s.exists == 0 ) if ( node == NULL || node->s.exists == 0 )
...@@ -952,6 +1036,8 @@ cached_unlock_person(Pers_no pers_no) ...@@ -952,6 +1036,8 @@ cached_unlock_person(Pers_no pers_no)
{ {
Cache_node *node; Cache_node *node;
LOGACC(lt_unlock_pers, pers_no);
node = get_pers_node (pers_no); node = get_pers_node (pers_no);
if ( node == NULL ) if ( node == NULL )
...@@ -983,6 +1069,8 @@ cached_lock_conf(Conf_no conf_no) ...@@ -983,6 +1069,8 @@ cached_lock_conf(Conf_no conf_no)
if ( node->s.exists == 0 ) if ( node->s.exists == 0 )
restart_kom("cached_lock_conf(%d): nonexistent.\n", conf_no); restart_kom("cached_lock_conf(%d): nonexistent.\n", conf_no);
LOGACC(lt_lock_conf, conf_no);
if ( node->ptr == NULL ) if ( node->ptr == NULL )
{ {
Conference *conference_ptr; Conference *conference_ptr;
...@@ -1008,6 +1096,8 @@ cached_unlock_conf(Conf_no conf_no) ...@@ -1008,6 +1096,8 @@ cached_unlock_conf(Conf_no conf_no)
{ {
Cache_node *node; Cache_node *node;
LOGACC(lt_unlock_conf, conf_no);
node = get_conf_node(conf_no); node = get_conf_node(conf_no);
if ( node == NULL ) if ( node == NULL )
restart_kom("cached_unlock_conf(): can't get node.\n"); restart_kom("cached_unlock_conf(): can't get node.\n");
...@@ -1668,6 +1758,10 @@ sync_part(void) ...@@ -1668,6 +1758,10 @@ sync_part(void)
sync_state = sync_ready; sync_state = sync_ready;
} }
#ifdef LOGACCESSES
syncing_or_saving = 1;
#endif
switch(sync_state) switch(sync_state)
{ {
case sync_save_conf: case sync_save_conf:
...@@ -1684,7 +1778,12 @@ sync_part(void) ...@@ -1684,7 +1778,12 @@ sync_part(void)
case sync_ready: case sync_ready:
if ( difftime(time(NULL), last_sync_start) < 60 * SYNC_INTERVAL ) if ( difftime(time(NULL), last_sync_start) < 60 * SYNC_INTERVAL )
{
#ifdef LOGACCESSES
syncing_or_saving = 0;
#endif
return TRUE; return TRUE;
}
last_sync_start = time(NULL); last_sync_start = time(NULL);
...@@ -1693,7 +1792,12 @@ sync_part(void) ...@@ -1693,7 +1792,12 @@ sync_part(void)
case sync_wait: case sync_wait:
if ( difftime(time(NULL), last_sync_start) < 60 * SYNC_RETRY_INTERVAL ) if ( difftime(time(NULL), last_sync_start) < 60 * SYNC_RETRY_INTERVAL )
{
#ifdef LOGACCESSES
syncing_or_saving = 0;
#endif
return TRUE; return TRUE;
}
last_sync_start = time(NULL); last_sync_start = time(NULL);
...@@ -1716,6 +1820,10 @@ sync_part(void) ...@@ -1716,6 +1820,10 @@ sync_part(void)
if ( file_b != NULL && ferror(file_b) != 0) if ( file_b != NULL && ferror(file_b) != 0)
sync_state = sync_error; sync_state = sync_error;
#ifdef LOGACCESSES
syncing_or_saving = 0;
#endif
return FALSE; return FALSE;
} }
...@@ -1748,7 +1856,16 @@ init_cache(void) ...@@ -1748,7 +1856,16 @@ init_cache(void)
conf_mcb = create_cache_node_mcb(100, MAX_CONF); conf_mcb = create_cache_node_mcb(100, MAX_CONF);
text_mcb = create_cache_node_mcb(100, MAX_TEXT); text_mcb = create_cache_node_mcb(100, MAX_TEXT);
#ifdef LOGACCESSES
if (logaccess_file)
logfile = fopen(logaccess_file, "a");
if (logfile)
log("Logging db accesses to %s.\n", logaccess_file);
else
log("Failed to open db log file %s. Ignoring -L option.\n",
logaccess_file);
#endif
LOGACC(lt_restart, time(NULL));
if ( (text_file = fopen(textfilename, "a+b")) == NULL ) if ( (text_file = fopen(textfilename, "a+b")) == NULL )
{ {
...@@ -1795,6 +1912,7 @@ init_cache(void) ...@@ -1795,6 +1912,7 @@ init_cache(void)
break; break;
case '+': case '+':
LOGACC(lt_conf_def, i);
create_cache_node(conf_mcb, i); create_cache_node(conf_mcb, i);
node = get_conf_node(i); node = get_conf_node(i);
node->s.exists = 1; node->s.exists = 1;
...@@ -1825,6 +1943,7 @@ init_cache(void) ...@@ -1825,6 +1943,7 @@ init_cache(void)
break; break;
case '+': case '+':
LOGACC(lt_pers_def, i);
create_cache_node(pers_mcb, i); create_cache_node(pers_mcb, i);
node = get_pers_node(i); node = get_pers_node(i);
node->s.exists = 1; node->s.exists = 1;
...@@ -1851,6 +1970,7 @@ init_cache(void) ...@@ -1851,6 +1970,7 @@ init_cache(void)
break; break;