From 31083c21a8e384b70817ff1b32ae4f2007b19e60 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 24 Jun 1999 15:19:06 +0000 Subject: [PATCH] * added server command line option "-f" to defrag databases on startup * control.c: better performance and reliability in [get|put]_control() --- citadel/ChangeLog | 4 ++++ citadel/citserver.c | 4 ++++ citadel/citserver.h | 2 ++ citadel/control.c | 20 ++++++++++---------- citadel/database.c | 5 ----- citadel/install.txt | 6 +++++- citadel/room_ops.c | 4 +++- citadel/sysdep.c | 10 +++++++--- 8 files changed, 35 insertions(+), 20 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 53864121d..45bedcc12 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,3 +1,7 @@ +Thu Jun 24 11:13:23 EDT 1999 Art Cancro + * added server command line option "-f" to defrag databases on startup + * control.c: better performance and reliability in [get|put]_control() + Mon Jun 21 00:04:15 EDT 1999 Art Cancro * netproc.c: started writing a vortex checker. Not finished. diff --git a/citadel/citserver.c b/citadel/citserver.c index 693357e3d..e79fc29db 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -40,6 +40,7 @@ struct CitContext *ContextList = NULL; int ScheduledShutdown = 0; +int do_defrag = 0; /* * Various things that need to be initialized at startup @@ -48,6 +49,9 @@ void master_startup(void) { lprintf(7, "Opening databases\n"); open_databases(); + if (do_defrag) + defrag_databases(); + lprintf(7, "Checking floor reference counts\n"); check_ref_counts(); diff --git a/citadel/citserver.h b/citadel/citserver.h index 04e1458bf..0db931cb8 100644 --- a/citadel/citserver.h +++ b/citadel/citserver.h @@ -27,3 +27,5 @@ void deallocate_user_data(struct CitContext *con); void *CtdlGetUserData(unsigned long requested_sym); void CtdlAllocUserData(unsigned long requested_sym, size_t num_bytes); int CtdlGetDynamicSymbol(void); + +extern int do_defrag; diff --git a/citadel/control.c b/citadel/control.c index 297c365ac..c4868210a 100644 --- a/citadel/control.c +++ b/citadel/control.c @@ -34,35 +34,35 @@ struct CitControl CitControl; struct config config; +FILE *control_fp = NULL; /* * get_control - read the control record into memory. */ void get_control(void) { - FILE *fp; /* Zero it out. If the control record on disk is missing or short, * the system functions with all control record fields initialized * to zero. */ memset(&CitControl, 0, sizeof(struct CitControl)); - fp = fopen("citadel.control", "rb"); - if (fp == NULL) return; + if (control_fp == NULL) + control_fp = fopen("citadel.control", "rb+"); + if (control_fp == NULL) return; - fread(&CitControl, sizeof(struct CitControl), 1, fp); - fclose(fp); + rewind(control_fp); + fread(&CitControl, sizeof(struct CitControl), 1, control_fp); } /* * put_control - write the control record to disk. */ void put_control(void) { - FILE *fp; - fp = fopen("citadel.control", "wb"); - if (fp != NULL) { - fwrite(&CitControl, sizeof(struct CitControl), 1, fp); - fclose(fp); + if (control_fp != NULL) { + rewind(control_fp); + fwrite(&CitControl, sizeof(struct CitControl), 1, control_fp); + fflush(control_fp); } } diff --git a/citadel/database.c b/citadel/database.c index ee2e2422f..d14ab2bc0 100644 --- a/citadel/database.c +++ b/citadel/database.c @@ -177,11 +177,6 @@ void open_databases(void) { void close_databases(void) { int a; - /* Hmm... we should decide when would be a good time to defrag. - * Server shutdowns might be an opportune time. - defrag_databases(); - */ - begin_critical_section(S_DATABASE); for (a=0; aQRname, newmsgid); cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long)); if (cdbfr == NULL) { msglist = NULL; @@ -369,6 +370,7 @@ long AddMessageToRoom(struct quickroom *whichroom, long newmsgid) { } else { msglist = mallok(cdbfr->len); + if (msglist==NULL) lprintf(3, "ERROR malloc msglist!\n"); num_msgs = cdbfr->len / sizeof(long); memcpy(msglist, cdbfr->ptr, cdbfr->len); cdb_free(cdbfr); diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 43d635573..4b82115f8 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -825,6 +825,10 @@ int main(int argc, char **argv) home_specified = 1; } + else if (!strncmp(argv[a], "-f", 2)) { + do_defrag = 1; + } + /* -r tells the server not to drop root permissions. don't use * this unless you know what you're doing. this should be * removed in the next release if it proves unnecessary. */ @@ -833,9 +837,9 @@ int main(int argc, char **argv) /* any other parameter makes it crash and burn */ else { - lprintf(1, "citserver: usage: "); - lprintf(1, "citserver [-tTraceFile]"); - lprintf(1, " [-d] [-xLogLevel] [-hHomeDir]\n"); + lprintf(1, "citserver: usage: " + "citserver [-tTraceFile] [-d] [-f]" + " [-xLogLevel] [-hHomeDir]\n"); exit(1); } -- 2.30.2