Cleanup the rhizome database every 30 minutes or so

This commit is contained in:
Jeremy Lakeman 2014-06-23 13:49:37 +09:30
parent 2ef73884a1
commit ca8f651b8d
3 changed files with 14 additions and 8 deletions

View File

@ -427,7 +427,6 @@ STRUCT(rhizome)
ATOM(bool_t, enable, 1, boolean,, "If true, server opens Rhizome database when starting") 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, 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_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") 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, 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") ATOM(uint64_t, min_free_space, 100*1024*1024, uint64_scaled,, "Minimum free space to preserve on the disk")

View File

@ -348,13 +348,21 @@ void server_watchdog(struct sched_ent *alarm)
} }
} }
DEFINE_ALARM(rhizome_open_db); DEFINE_ALARM(rhizome_clean_db);
void rhizome_open_db(struct sched_ent *UNUSED(alarm)) 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(); rhizome_opendb();
if (config.rhizome.clean_on_start && !config.rhizome.clean_on_open) // first clean up 5 minutes after opening
rhizome_cleanup(NULL); 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); now+config.server.config_reload_interval_ms+100);
if (config.rhizome.enable){ 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){ }else if(rhizome_db){
rhizome_close_db(); rhizome_close_db();
} }

View File

@ -910,7 +910,6 @@ setup_MeshMSAddGrow() {
setup_rhizome setup_rhizome
executeOk_servald config set rhizome.clean_on_open on executeOk_servald config set rhizome.clean_on_open on
export SERVALD_ORPHAN_PAYLOAD_PERSIST_MS=0 export SERVALD_ORPHAN_PAYLOAD_PERSIST_MS=0
export SERVALD_INVALID_PAYLOAD_PERSIST_MS=0
echo "Message1" >file1 echo "Message1" >file1
echo -e "service=MeshMS1\nsender=$SIDB1\nrecipient=$SIDB2" >file1.manifest echo -e "service=MeshMS1\nsender=$SIDB1\nrecipient=$SIDB2" >file1.manifest
} }