summaryrefslogtreecommitdiff
path: root/src/stasis/anastasis-dbinit.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-09-17 00:34:52 +0200
committerChristian Grothoff <christian@grothoff.org>2021-09-17 00:35:05 +0200
commit75b3065db390c1c631accd03b68f162953597733 (patch)
treeff5a5adb1c28a315c66e9898721bfdc5c4440e23 /src/stasis/anastasis-dbinit.c
parente5e27b880b6df3c4263bca3177050cb6a5ae23a9 (diff)
downloadanastasis-75b3065db390c1c631accd03b68f162953597733.tar.gz
anastasis-75b3065db390c1c631accd03b68f162953597733.tar.bz2
anastasis-75b3065db390c1c631accd03b68f162953597733.zip
expose DB garbage collection, ROLLBACK instead of committing if preflight check fails
Diffstat (limited to 'src/stasis/anastasis-dbinit.c')
-rw-r--r--src/stasis/anastasis-dbinit.c46
1 files changed, 41 insertions, 5 deletions
diff --git a/src/stasis/anastasis-dbinit.c b/src/stasis/anastasis-dbinit.c
index 17b3c56..a0e17db 100644
--- a/src/stasis/anastasis-dbinit.c
+++ b/src/stasis/anastasis-dbinit.c
@@ -34,6 +34,11 @@ static int global_ret;
static int reset_db;
/**
+ * -g option: do garbate collection
+ */
+static int gc_db;
+
+/**
* Main function that will be run.
*
* @param cls closure
@@ -54,21 +59,49 @@ run (void *cls,
{
fprintf (stderr,
"Failed to initialize database plugin.\n");
- global_ret = EXIT_FAILURE;
+ global_ret = EXIT_NOTINSTALLED;
return;
}
if (reset_db)
{
- (void) plugin->drop_tables (plugin->cls);
- ANASTASIS_DB_plugin_unload (plugin);
- plugin = ANASTASIS_DB_plugin_load (cfg);
+ if (GNUNET_OK != plugin->drop_tables (plugin->cls))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not drop tables as requested. Either database was not yet initialized, or permission denied. Consult the logs. Will still try to create new tables.\n");
+ }
}
if (GNUNET_OK !=
plugin->create_tables (plugin->cls))
{
global_ret = EXIT_FAILURE;
+ ANASTASIS_DB_plugin_unload (plugin);
return;
}
+ if (gc_db)
+ {
+ struct GNUNET_TIME_Absolute expire_backups;
+ struct GNUNET_TIME_Absolute expire_payments;
+ struct GNUNET_TIME_Absolute now;
+
+ now = GNUNET_TIME_absolute_get ();
+ expire_backups = GNUNET_TIME_absolute_subtract (
+ now,
+ GNUNET_TIME_relative_multiply (
+ GNUNET_TIME_UNIT_MONTHS,
+ 6));
+ expire_payments = GNUNET_TIME_absolute_subtract (
+ now,
+ GNUNET_TIME_relative_multiply (
+ GNUNET_TIME_UNIT_YEARS,
+ 10));
+ if (0 > plugin->gc (plugin->cls,
+ expire_backups,
+ expire_payments))
+ {
+ fprintf (stderr,
+ "Garbage collection failed!\n");
+ }
+ }
ANASTASIS_DB_plugin_unload (plugin);
}
@@ -86,7 +119,10 @@ main (int argc,
char *const *argv)
{
struct GNUNET_GETOPT_CommandLineOption options[] = {
-
+ GNUNET_GETOPT_option_flag ('g',
+ "garbagecollect",
+ "remove state data from database",
+ &gc_db),
GNUNET_GETOPT_option_flag ('r',
"reset",
"reset database (DANGEROUS: all existing data is lost!)",