Experiment with DB->compact() to reduce the size of database files on disk when possible.
authorArt Cancro <ajc@citadel.org>
Sun, 2 Jul 2017 04:46:53 +0000 (00:46 -0400)
committerArt Cancro <ajc@citadel.org>
Sun, 2 Jul 2017 04:46:53 +0000 (00:46 -0400)
Commented out while we test it.

citadel/database.c
citadel/database.h
citadel/modules/expire/serv_expire.c

index fcb82d2e5eecadbb6a155edfc258f4aac42a701a..4bd685d66f6d6d752c531f73eb31a815f5f4c132 100644 (file)
@@ -861,6 +861,25 @@ void cdb_trunc(int cdb)
 }
 
 
+/*
+ * compact (defragment) the database , possibly returning space back to the underlying filesystem
+ */
+void cdb_compact(void)
+{
+       int ret;
+       int i;
+
+       syslog(LOG_DEBUG, "db: cdb_compact() started");
+       for (i = 0; i < MAXCDB; i++) {
+               syslog(LOG_DEBUG, "db: compacting database %d", i);
+               ret = dbp[i]->compact(dbp[i], NULL, NULL, NULL, NULL, DB_FREE_SPACE, NULL);
+               if (ret) {
+                       syslog(LOG_ERR, "db: compact: %s", db_strerror(ret));
+               }
+       }
+       syslog(LOG_DEBUG, "db: cdb_compact() finished");
+}
+
 
 // Has an item already been seen (is it in the CDB_USETABLE) ?
 // Returns 0 if it hasn't, 1 if it has
index cfaa1bd600c3093ac5620be073494e477088a39f..b9b76b715918992912c6ffab9937f52e1372ea53 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1987-2012 by the citadel.org team
+ * Copyright (c) 1987-2017 by the citadel.org team
  *
  *  This program is open source software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 3.
@@ -34,6 +34,7 @@ void cdb_chmod_data(void);
 void cdb_checkpoint(void);
 void check_handles(void *arg);
 void cdb_cull_logs(void);
+void cdb_compact(void);
 
 
 /*
index 5fce934737d97e68d9ff0f5ef80573b07e5f0fb6..7fd28e6b4a699217d90d094fc8f8ee6ac9866ee1 100644 (file)
@@ -905,6 +905,13 @@ void purge_databases(void)
                syslog(LOG_NOTICE, "Processed %d message reference count adjustments.", retval);
        }
 
+       // Enable this after we've tested it and make it a site-configurable option.
+       // This will allow the database files to shrink when they can.
+       // if (!server_shutting_down)
+       // {
+               // cdb_compact();
+       // }
+
        if (!server_shutting_down)
        {
                syslog(LOG_INFO, "Auto-purger: finished.");