* added server command line option "-f" to defrag databases on startup
authorArt Cancro <ajc@citadel.org>
Thu, 24 Jun 1999 15:19:06 +0000 (15:19 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 24 Jun 1999 15:19:06 +0000 (15:19 +0000)
        * control.c: better performance and reliability in [get|put]_control()

citadel/ChangeLog
citadel/citserver.c
citadel/citserver.h
citadel/control.c
citadel/database.c
citadel/install.txt
citadel/room_ops.c
citadel/sysdep.c

index 53864121d92b438bdc727eb6511efb36b2bc6817..45bedcc1208f2d77d64f3426ece4229cd99d4594 100644 (file)
@@ -1,3 +1,7 @@
+Thu Jun 24 11:13:23 EDT 1999 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
+       * 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 <ajc@uncnsrd.mt-kisco.ny.us>
        * netproc.c: started writing a vortex checker.  Not finished.
 
index 693357e3da999aca497d7309044ef92fde13e9d7..e79fc29dbfae7b8de124e2b0815a921071076903 100644 (file)
@@ -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();
 
index 04e1458bf066facccafeb101eaf46c86101c0a15..0db931cb89f6bed47a6338e99c31b533e30d2707 100644 (file)
@@ -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;
index 297c365ac2ccfc9185033deb9d2aabf41b191038..c4868210a01ab6559352b01b6f916d2c69dfac3f 100644 (file)
 
 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);
                }
        }
 
index ee2e2422fe4e43662c31bbc81dfbcac0da32a1d5..d14ab2bc036095dd3ba5889822c8a27133861a61 100644 (file)
@@ -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; a<MAXCDB; ++a) {
                lprintf(7, "Closing database %d\n", a);
index e289d19f0c522b81885a92b0abaf16a4c38690e0..9c5e32e83458b2b03e8433477eb68358554cfc2f 100644 (file)
@@ -207,7 +207,7 @@ port for each one.
 program is the main Citadel server.  Before we cover the recommended method of
 starting the server, let's examine its usage options:
  
- citserver [-hHomeDir] [-xDebugLevel] [-tTraceFile] [-d]
+ citserver [-hHomeDir] [-xDebugLevel] [-tTraceFile] [-d] [-f]
  
  The options are as follows:
  
@@ -234,6 +234,10 @@ starting the Citadel server, for example, from an rc.local script (which is
 not recommended, because this won't allow the server to automatically restart
 when it is shut down).
  
+ -f            - Defragment all the databases upon startup.  This isn't
+normally necessary due to the nature of the data stored in Citadel, but the
+option is provided in case you need it.
  
    The preferred method of starting the Citadel server is to place an entry in
 your /etc/inittab file.  This will conveniently bring the server up when your 
index 60359b4703d061a59d057e05936fa3303b1cced7..3bca3a7c211cb8b0aba861f93c1977a089ecc204 100644 (file)
@@ -361,7 +361,8 @@ long AddMessageToRoom(struct quickroom *whichroom, long newmsgid) {
        int num_msgs;
        long *msglist;
        long highest_msg = 0L;
-       
+
+       lprintf(9, "AddMessageToRoom(%s, %ld)\n", whichroom->QRname, 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);
index 43d6355735da7eef6cf45e1b5bb3eff5a473d522..4b82115f85c20bf26d748726018075ffed863483 100644 (file)
@@ -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);
                        }