From ca8f651b8d6b6a6208a5ef5dce810cfdd541f0f3 Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Mon, 23 Jun 2014 13:49:37 +0930 Subject: [PATCH] Cleanup the rhizome database every 30 minutes or so --- conf_schema.h | 1 - server.c | 20 ++++++++++++++------ tests/rhizomeops | 1 - 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/conf_schema.h b/conf_schema.h index 5f8662ab..f0cb51a4 100644 --- a/conf_schema.h +++ b/conf_schema.h @@ -427,7 +427,6 @@ STRUCT(rhizome) ATOM(bool_t, enable, 1, boolean,, "If true, server opens Rhizome database when starting") ATOM(bool_t, fetch, 1, boolean,, "If false, no new bundles will be fetched from peers") ATOM(bool_t, clean_on_open, 0, boolean,, "If true, Rhizome database is cleaned at start of every command") -ATOM(bool_t, clean_on_start, 1, boolean,, "If true, Rhizome database is cleaned at start of daemon") STRING(256, datastore_path, "", str_nonempty,, "Path of rhizome storage directory, absolute or relative to instance directory") ATOM(uint64_t, database_size, UINT64_MAX, uint64_scaled,, "Maximum size of database in bytes") ATOM(uint64_t, min_free_space, 100*1024*1024, uint64_scaled,, "Minimum free space to preserve on the disk") diff --git a/server.c b/server.c index 8b31eb85..23d64c1d 100644 --- a/server.c +++ b/server.c @@ -348,13 +348,21 @@ void server_watchdog(struct sched_ent *alarm) } } -DEFINE_ALARM(rhizome_open_db); -void rhizome_open_db(struct sched_ent *UNUSED(alarm)) +DEFINE_ALARM(rhizome_clean_db); +void rhizome_clean_db(struct sched_ent *alarm) { - if (config.rhizome.enable && !rhizome_db){ + if (!config.rhizome.enable) + return; + + time_ms_t now = gettime_ms(); + if (!rhizome_db){ rhizome_opendb(); - if (config.rhizome.clean_on_start && !config.rhizome.clean_on_open) - rhizome_cleanup(NULL); + // first clean up 5 minutes after opening + RESCHEDULE(alarm, now + 5*60*1000, TIME_MS_NEVER_WILL, TIME_MS_NEVER_WILL); + }else{ + rhizome_cleanup(NULL); + // clean up every 30 minutes or so + RESCHEDULE(alarm, now + 30*60*1000, TIME_MS_NEVER_WILL, TIME_MS_NEVER_WILL); } } @@ -389,7 +397,7 @@ void cf_on_config_change() now+config.server.config_reload_interval_ms+100); if (config.rhizome.enable){ - RESCHEDULE(&ALARM_STRUCT(rhizome_open_db), now+100, now+100, TIME_MS_NEVER_WILL); + RESCHEDULE(&ALARM_STRUCT(rhizome_clean_db), now+100, now+100, TIME_MS_NEVER_WILL); }else if(rhizome_db){ rhizome_close_db(); } diff --git a/tests/rhizomeops b/tests/rhizomeops index 4386c84d..6f1e98b5 100755 --- a/tests/rhizomeops +++ b/tests/rhizomeops @@ -910,7 +910,6 @@ setup_MeshMSAddGrow() { setup_rhizome executeOk_servald config set rhizome.clean_on_open on export SERVALD_ORPHAN_PAYLOAD_PERSIST_MS=0 - export SERVALD_INVALID_PAYLOAD_PERSIST_MS=0 echo "Message1" >file1 echo -e "service=MeshMS1\nsender=$SIDB1\nrecipient=$SIDB2" >file1.manifest }