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)
* 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.
*
* This file is part of the LysKOM server.
......@@ -34,7 +34,7 @@
#include <m-config.h>
#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.
*/
......
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)
* 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.
*
* This file is part of the LysKOM server.
......@@ -23,7 +23,7 @@
* 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.
* .h file created by ceder 1990-04-18
......@@ -67,10 +67,6 @@ cache_sync(void);
/* 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
*/
......@@ -87,24 +83,6 @@ cached_change_name(Conf_no name_num,
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
cached_conf_exists( 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.
*/
......@@ -258,3 +229,10 @@ dump_cache_mem_usage(FILE *stat_file);
*/
int
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.
*
* This file is part of the LysKOM server.
......@@ -31,7 +31,7 @@
* 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>
......@@ -83,7 +83,9 @@ int buglevel = 0;
Bool never_save = FALSE;
#endif
#ifdef LOGACCESSES
char *logaccess_file = NULL;
#endif
EXPORT char datafilename[BUFSIZ]; /* Full pathname to the database file */
EXPORT char backupfilename[BUFSIZ]; /* Full pathname to the backup file */
......@@ -333,9 +335,19 @@ main (int argc,
send_async_messages = FALSE;
break;
#ifdef LOGACCESSES
case 'L':
logaccess_file = argv[i] + 2;
break;
#endif
default:
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)
......
/*
* $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.
*
* This file is part of the LysKOM server.
......@@ -33,8 +33,7 @@
* 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;
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 */
......@@ -286,6 +338,8 @@ cached_get_conf_type (Conf_no conf_no)
restart_kom("cached_get_conf_type(%d): conference does not exist.\n",
conf_no);
LOGACC(lt_get_conf_type, conf_no);
return small_conf_arr [ conf_no ]->type;
}
......@@ -400,6 +454,9 @@ cached_create_person( Pers_no person )
node->s.dirty = 1;
node->s.exists = 1;
pers_set_mru( person );
LOGACC(lt_create_pers, person);
return OK;
}
......@@ -431,6 +488,8 @@ cached_get_person_stat( Pers_no person )
return NULL;
}
LOGACC(lt_pers_stat, person);
if ( node->ptr != NULL )
{
pers_set_mru( person );
......@@ -529,6 +588,8 @@ cached_create_conf (String name)
TRACE2("Created conference number %d\n", conf_no);
LOGACC(lt_create_conf, conf_no);
return conf_no;
}
......@@ -566,6 +627,8 @@ cached_delete_conf( Conf_no conf )
node->ptr = NULL;
node->s.exists = 0;
LOGACC(lt_delete_conf, conf);
return OK;
}
......@@ -602,6 +665,8 @@ cached_delete_person(Pers_no pers)
log("cached_delete_pers(%lu): lock_cnt === %lu\n",
(u_long)pers, (u_long)node->lock_cnt);
LOGACC(lt_delete_pers, pers);
free_person (node->ptr);
node->ptr = NULL;
node->s.exists = 0;
......@@ -639,6 +704,15 @@ cached_delete_text(Text_no text)
node->ptr = NULL;
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;
}
......@@ -664,6 +738,8 @@ cached_get_conf_stat (Conf_no conf_no)
return NULL;
}
LOGACC(lt_conf_stat, conf_no);
if ( node->ptr != NULL )
{
conf_set_mru (conf_no);
......@@ -722,6 +798,7 @@ cached_get_text( Text_no text )
return EMPTY_STRING;
else
{
LOGACC(lt_text_mass, text);
the_string.string = tmp_alloc( t_stat->no_of_chars );
the_string.len = t_stat->no_of_chars;
fseek(text_file, t_stat->file_pos, SEEK_SET);
......@@ -763,6 +840,8 @@ cached_get_text_stat( Text_no text )
return NULL;
}
LOGACC(lt_text_stat, text);
if ( node->ptr != NULL )
{
TRACE1("Found in ptr.\n");
......@@ -840,6 +919,7 @@ cached_create_text( String message)
fflush(text_file);
LOGACC(lt_create_text, tno);
TRACE2("cached_create_text -> %d\n", tno);
return tno;
......@@ -913,6 +993,8 @@ cached_get_garb_nice (Conf_no conf_no)
extern Local_text_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;
}
......@@ -922,6 +1004,8 @@ cached_lock_person(Pers_no pers_no)
{
Cache_node *node;
LOGACC(lt_lock_pers, pers_no);
node = get_pers_node(pers_no);
if ( node == NULL || node->s.exists == 0 )
......@@ -952,6 +1036,8 @@ cached_unlock_person(Pers_no pers_no)
{
Cache_node *node;
LOGACC(lt_unlock_pers, pers_no);
node = get_pers_node (pers_no);
if ( node == NULL )
......@@ -983,6 +1069,8 @@ cached_lock_conf(Conf_no conf_no)
if ( node->s.exists == 0 )
restart_kom("cached_lock_conf(%d): nonexistent.\n", conf_no);
LOGACC(lt_lock_conf, conf_no);
if ( node->ptr == NULL )
{
Conference *conference_ptr;
......@@ -1008,6 +1096,8 @@ cached_unlock_conf(Conf_no conf_no)
{
Cache_node *node;
LOGACC(lt_unlock_conf, conf_no);
node = get_conf_node(conf_no);
if ( node == NULL )
restart_kom("cached_unlock_conf(): can't get node.\n");
......@@ -1668,6 +1758,10 @@ sync_part(void)
sync_state = sync_ready;
}
#ifdef LOGACCESSES
syncing_or_saving = 1;
#endif
switch(sync_state)
{
case sync_save_conf:
......@@ -1684,7 +1778,12 @@ sync_part(void)
case sync_ready:
if ( difftime(time(NULL), last_sync_start) < 60 * SYNC_INTERVAL )
{
#ifdef LOGACCESSES
syncing_or_saving = 0;
#endif
return TRUE;
}
last_sync_start = time(NULL);
......@@ -1693,7 +1792,12 @@ sync_part(void)
case sync_wait:
if ( difftime(time(NULL), last_sync_start) < 60 * SYNC_RETRY_INTERVAL )
{
#ifdef LOGACCESSES
syncing_or_saving = 0;
#endif
return TRUE;
}
last_sync_start = time(NULL);
......@@ -1716,6 +1820,10 @@ sync_part(void)
if ( file_b != NULL && ferror(file_b) != 0)
sync_state = sync_error;
#ifdef LOGACCESSES
syncing_or_saving = 0;
#endif
return FALSE;
}
......@@ -1748,7 +1856,16 @@ init_cache(void)
conf_mcb = create_cache_node_mcb(100, MAX_CONF);
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 )
{
......@@ -1795,6 +1912,7 @@ init_cache(void)
break;
case '+':
LOGACC(lt_conf_def, i);
create_cache_node(conf_mcb, i);
node = get_conf_node(i);
node->s.exists = 1;
......@@ -1825,6 +1943,7 @@ init_cache(void)
break;
case '+':
LOGACC(lt_pers_def, i);
create_cache_node(pers_mcb, i);
node = get_pers_node(i);
node->s.exists = 1;
......@@ -1851,6 +1970,7 @@ init_cache(void)
break;
case '+':
LOGACC(lt_text_def, i);
create_cache_node(text_mcb, i);
node = get_text_node(i);
node->s.exists = 1;
......@@ -1894,6 +2014,11 @@ free_all_cache (void)
int i;
Cache_node *node;
#ifdef LOGACCESSES
if (logfile)
fclose(logfile);
#endif
for ( i = 0; i < next_free_num; i++ )
{
node = get_conf_node(i);
......@@ -2137,3 +2262,12 @@ query_next_text_num(void)
{
return next_text_num;
}
EXPORT void
tell_cache_garb_text(int running)
{
#ifdef LOGACCESSES
garb_running = running;
#endif
}
/*
* $Id: text-garb.c,v 0.7 1992/10/06 23:45:00 ceder Exp $
* $Id: text-garb.c,v 0.8 1992/11/22 15:14:52 ceder Exp $
* Copyright (C) 1991 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -28,7 +28,7 @@
* Author: Per Cederqvist.
*/
static char *rcsid = "$Id: text-garb.c,v 0.7 1992/10/06 23:45:00 ceder Exp $";
static char *rcsid = "$Id: text-garb.c,v 0.8 1992/11/22 15:14:52 ceder Exp $";
#include <time.h>
......@@ -43,7 +43,7 @@ static char *rcsid = "$Id: text-garb.c,v 0.7 1992/10/06 23:45:00 ceder Exp $";
/*
* This comment is a description of how this _could_ be done in a more
* efficient way. It is not yet implemented. Design by Inge Wallin
* and Per Cederqvist 1992-10-07.
* and Per Cederqvist 1992-10-07. +++FIXME.
*
* Today, all text statuses are read into the core during the garbage
* collection phase. Due to step 3 below we think that we can reduce
......@@ -107,18 +107,21 @@ garb_text(void)
time( &last_start );
}
tell_cache_garb_text(1);
last_checked = traverse_text( last_checked );
if ( last_checked == 0 )
{
log("MSG: garb ready. %lu texts deleted.\n", (u_long)deleted_texts);
deleted_texts = 0;
tell_cache_garb_text(0);
return FALSE;
}
if ( (text_s = cached_get_text_stat( last_checked )) == NULL )
{
log("ERROR: garb_text(): Can't get text-stat.\n");
tell_cache_garb_text(0);
return FALSE;
}
......@@ -126,6 +129,7 @@ garb_text(void)
if ( text_s->no_of_marks > 0 || age < 24 * 3600 )
{
tell_cache_garb_text(0);
return FALSE;
}
......@@ -141,8 +145,11 @@ garb_text(void)
limit = (24 * 3600 *
cached_get_garb_nice( misc->datum.recipient ));
if ( age < limit )
{
tell_cache_garb_text(0);
return FALSE;
}
}
break;
......@@ -152,8 +159,11 @@ garb_text(void)
limit = ( 24 * 3600
* cached_get_garb_nice( misc->datum.cc_recipient ));
if ( age < limit )
{
tell_cache_garb_text(0);
return FALSE;
}
}
break;
......@@ -173,6 +183,7 @@ garb_text(void)
if ( difftime ( time(NULL), misc->datum.sent_at )
< limit )
{
tell_cache_garb_text(0);
return FALSE;
}
......@@ -188,6 +199,7 @@ garb_text(void)
VBUG(("garb_text: deleting %d\n", last_checked));
do_delete_text ( last_checked, text_s );
deleted_texts++;
tell_cache_garb_text(0);
return FALSE;
}
/*
* $Id: version.incl,v 0.33 1992/10/27 04:43:02 ceder Exp $
* $Id: version.incl,v 0.34 1992/11/22 15:14:55 ceder Exp $
* Copyright (C) 1991 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -27,4 +27,4 @@
* The version number is encoded in a long. It shall be printed as
* in sed s/\(.*\)\(..\)\(..\)/\1.\2.\3/
*/
10206
10207
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