Delay rhizome open database using an alarm, close on config change

This commit is contained in:
Jeremy Lakeman 2014-06-06 13:39:50 +09:30
parent 3d537f9645
commit 0b0e4cc8b4
6 changed files with 46 additions and 10 deletions

View File

@ -112,12 +112,6 @@ int overlayServerMode()
}
overlay_queue_init();
if (is_rhizome_enabled()){
rhizome_opendb();
if (config.rhizome.clean_on_start && !config.rhizome.clean_on_open)
rhizome_cleanup(NULL);
}
time_ms_t now = gettime_ms();
// Periodically check for server shut down

View File

@ -461,8 +461,7 @@ sqlite3_stmt *_sqlite_prepare(struct __sourceloc __whence, int log_level, sqlite
{
IN();
sqlite3_stmt *statement = NULL;
if (!rhizome_db && rhizome_opendb() == -1)
RETURN(NULL);
assert(rhizome_db);
while (1) {
switch (sqlite3_prepare_v2(rhizome_db, sqltext, -1, &statement, NULL)) {
case SQLITE_OK:

View File

@ -515,6 +515,7 @@ int app_rhizome_direct_sync(const struct cli_parsed *parsed, struct cli_context
if (!strcasecmp(modeName,"push")) mode=1; /* push only */
if (!strcasecmp(modeName,"pull")) mode=2; /* pull only */
DEBUGF("sync direction = %d",mode);
rhizome_opendb();
if (parsed->args[3]) {
struct config_rhizome_peer peer;
const struct config_rhizome_peer *peers[1] = { &peer };

View File

@ -482,7 +482,7 @@ void rhizome_sync_announce(struct sched_ent *alarm)
int overlay_mdp_service_rhizome_sync(struct internal_mdp_header *header, struct overlay_buffer *payload)
{
if (!config.rhizome.enable)
if (!config.rhizome.enable || !rhizome_db)
return 0;
struct rhizome_sync *state = header->source->sync_state;
if (!state){

View File

@ -270,6 +270,16 @@ void server_watchdog(struct sched_ent *alarm)
}
}
DEFINE_ALARM(rhizome_open_db);
void rhizome_open_db(struct sched_ent *UNUSED(alarm))
{
if (config.rhizome.enable && !rhizome_db){
rhizome_opendb();
if (config.rhizome.clean_on_start && !config.rhizome.clean_on_open)
rhizome_cleanup(NULL);
}
}
void cf_on_config_change()
{
if (!serverMode)
@ -299,6 +309,12 @@ void cf_on_config_change()
now+config.server.config_reload_interval_ms,
TIME_MS_NEVER_WILL,
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);
}else if(rhizome_db){
rhizome_close_db();
}
}
/* Called periodically by the server process in its main loop.
@ -319,7 +335,7 @@ void server_shutdown_check(struct sched_ent *alarm)
}
}
if (alarm){
RESCHEDULE(alarm, now+1000, now+30000, now+5000);
RESCHEDULE(alarm, now+1000, now+30000, now+1100);
}
}

View File

@ -503,6 +503,32 @@ test_MissingPayload() {
executeOk $servald rhizome extract file $BID file1a
}
doc_ConnectOnEnable="Enable and disable rhizome while fetching"
setup_ConnectOnEnable(){
setup_common
set_instance +A
dd if=/dev/urandom of=file1 bs=1k count=1k 2>&1
echo x >>file1
rhizome_add_file file1
foreach_instance +A +B \
executeOk_servald config \
set rhizome.enable off
start_servald_instances +A +B
}
test_ConnectOnEnable(){
# TODO try to force disabling rhizome mid transfer
foreach_instance +A +B \
executeOk_servald config \
set rhizome.enable on \
sync
sleep 2
foreach_instance +A +B \
executeOk_servald config \
set rhizome.enable off \
sync
sleep 3
}
doc_HttpFetchRange="Fetch a file range using HTTP GET"
setup_HttpFetchRange() {
setup_curl 7