Don't clean the database for every command line operation by default

This commit is contained in:
Jeremy Lakeman 2013-08-27 13:42:56 +09:30
parent ceb7f9d4c9
commit 44ab51e2ab
4 changed files with 31 additions and 21 deletions

View File

@ -397,7 +397,8 @@ END_STRUCT
STRUCT(rhizome) 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, 1, 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, "", absolute_path,, "Path of rhizome storage directory, absolute or relative to instance directory") STRING(256, datastore_path, "", absolute_path,, "Path of rhizome storage directory, absolute or relative to instance directory")
ATOM(uint64_t, database_size, 1000000, uint64_scaled,, "Size of database in bytes") ATOM(uint64_t, database_size, 1000000, uint64_scaled,, "Size of database in bytes")
ATOM(bool_t, external_blobs, 0, boolean,, "Store rhizome bundles as separate files.") ATOM(bool_t, external_blobs, 0, boolean,, "Store rhizome bundles as separate files.")

View File

@ -128,8 +128,11 @@ schedule(&_sched_##X); }
/* Get rhizome server started BEFORE populating fd list so that /* Get rhizome server started BEFORE populating fd list so that
the server's listen socket is in the list for poll() */ the server's listen socket is in the list for poll() */
if (is_rhizome_enabled()) if (is_rhizome_enabled()){
rhizome_opendb(); rhizome_opendb();
if (config.rhizome.clean_on_start && !config.rhizome.clean_on_open)
rhizome_cleanup(NULL);
}
/* Rhizome http server needs to know which callback to attach /* Rhizome http server needs to know which callback to attach
to client sockets, so provide it here, along with the name to to client sockets, so provide it here, along with the name to

View File

@ -727,38 +727,43 @@ static int rhizome_delete_external(const char *fileid)
return unlink(blob_path); return unlink(blob_path);
} }
static int rhizome_cleanup_external(sqlite_retry_state *retry, sqlite3_stmt *statement){
int ret=0;
while (sqlite_step_retry(retry, statement) == SQLITE_ROW) {
const char *id = (const char *) sqlite3_column_text(statement, 0);
if (rhizome_delete_external(id)==0)
ret++;
}
return ret;
}
int rhizome_cleanup(struct rhizome_cleanup_report *report) int rhizome_cleanup(struct rhizome_cleanup_report *report)
{ {
IN(); IN();
sqlite_retry_state retry = SQLITE_RETRY_STATE_DEFAULT; sqlite_retry_state retry = SQLITE_RETRY_STATE_DEFAULT;
// cleanup external blobs for unreferenced files // cleanup external blobs for unreferenced files
int externals_removed=0;
int candidates=0;
sqlite3_stmt *statement = sqlite_prepare(&retry, "SELECT id FROM FILES WHERE inserttime < %lld AND datavalid=0;", gettime_ms() - 300000); sqlite3_stmt *statement = sqlite_prepare(&retry, "SELECT id FROM FILES WHERE inserttime < %lld AND datavalid=0;", gettime_ms() - 300000);
int externals_removed=rhizome_cleanup_external(&retry, statement); while (sqlite_step_retry(&retry, statement) == SQLITE_ROW) {
candidates++;
const char *id = (const char *) sqlite3_column_text(statement, 0);
if (rhizome_delete_external(id)==0)
externals_removed++;
}
sqlite3_finalize(statement); sqlite3_finalize(statement);
statement = sqlite_prepare(&retry, "SELECT id FROM FILES WHERE inserttime < %lld AND datavalid=1 AND NOT EXISTS( SELECT 1 FROM MANIFESTS WHERE MANIFESTS.filehash = FILES.id);", gettime_ms() - 1000); statement = sqlite_prepare(&retry, "SELECT id FROM FILES WHERE inserttime < %lld AND datavalid=1 AND NOT EXISTS( SELECT 1 FROM MANIFESTS WHERE MANIFESTS.filehash = FILES.id);", gettime_ms() - 1000);
externals_removed+=rhizome_cleanup_external(&retry, statement); while (sqlite_step_retry(&retry, statement) == SQLITE_ROW) {
candidates++;
const char *id = (const char *) sqlite3_column_text(statement, 0);
if (rhizome_delete_external(id)==0)
externals_removed++;
}
sqlite3_finalize(statement); sqlite3_finalize(statement);
// clean out unreferenced files
int ret; int ret;
ret = sqlite_exec_void_loglevel(LOG_LEVEL_WARN, "DELETE FROM FILES WHERE inserttime < %lld AND datavalid=0;", gettime_ms() - 300000); if (candidates){
if (report) // clean out unreferenced files
report->deleted_stale_incoming_files = ret; ret = sqlite_exec_void_loglevel(LOG_LEVEL_WARN, "DELETE FROM FILES WHERE inserttime < %lld AND datavalid=0;", gettime_ms() - 300000);
ret = sqlite_exec_void_loglevel(LOG_LEVEL_WARN, "DELETE FROM FILES WHERE inserttime < %lld AND datavalid=1 AND NOT EXISTS( SELECT 1 FROM MANIFESTS WHERE MANIFESTS.filehash = FILES.id);", gettime_ms() - 1000); if (report)
if (report) report->deleted_stale_incoming_files = ret;
report->deleted_orphan_files = ret; ret = sqlite_exec_void_loglevel(LOG_LEVEL_WARN, "DELETE FROM FILES WHERE inserttime < %lld AND datavalid=1 AND NOT EXISTS( SELECT 1 FROM MANIFESTS WHERE MANIFESTS.filehash = FILES.id);", gettime_ms() - 1000);
if (report)
report->deleted_orphan_files = ret;
}
ret = sqlite_exec_void_loglevel(LOG_LEVEL_WARN, "DELETE FROM FILEBLOBS WHERE NOT EXISTS ( SELECT 1 FROM FILES WHERE FILES.id = FILEBLOBS.id );"); ret = sqlite_exec_void_loglevel(LOG_LEVEL_WARN, "DELETE FROM FILEBLOBS WHERE NOT EXISTS ( SELECT 1 FROM FILES WHERE FILES.id = FILEBLOBS.id );");
if (report) if (report)

View File

@ -782,6 +782,7 @@ doc_MeshMSAddGrow="Subsequent add MeshMS updates manifest and removes old payloa
setup_MeshMSAddGrow() { setup_MeshMSAddGrow() {
setup_servald setup_servald
setup_rhizome setup_rhizome
executeOk_servald config set rhizome.clean_on_open on
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
} }