From: Art Cancro Date: Sun, 2 Jul 2017 04:46:53 +0000 (-0400) Subject: Experiment with DB->compact() to reduce the size of database files on disk when possible. X-Git-Tag: v939~534 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=dbee11a35d5d217f356279fa400d7f9deab86cb0 Experiment with DB->compact() to reduce the size of database files on disk when possible. Commented out while we test it. --- diff --git a/citadel/database.c b/citadel/database.c index fcb82d2e5..4bd685d66 100644 --- a/citadel/database.c +++ b/citadel/database.c @@ -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 diff --git a/citadel/database.h b/citadel/database.h index cfaa1bd60..b9b76b715 100644 --- a/citadel/database.h +++ b/citadel/database.h @@ -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); /* diff --git a/citadel/modules/expire/serv_expire.c b/citadel/modules/expire/serv_expire.c index 5fce93473..7fd28e6b4 100644 --- a/citadel/modules/expire/serv_expire.c +++ b/citadel/modules/expire/serv_expire.c @@ -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.");