aboutsummaryrefslogtreecommitdiff
path: root/src/stasis/anastasis-dbinit.c
diff options
context:
space:
mode:
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;
34static int reset_db; 34static int reset_db;
35 35
36/** 36/**
37 * -g option: do garbate collection
38 */
39static int gc_db;
40
41/**
37 * Main function that will be run. 42 * Main function that will be run.
38 * 43 *
39 * @param cls closure 44 * @param cls closure
@@ -54,21 +59,49 @@ run (void *cls,
54 { 59 {
55 fprintf (stderr, 60 fprintf (stderr,
56 "Failed to initialize database plugin.\n"); 61 "Failed to initialize database plugin.\n");
57 global_ret = EXIT_FAILURE; 62 global_ret = EXIT_NOTINSTALLED;
58 return; 63 return;
59 } 64 }
60 if (reset_db) 65 if (reset_db)
61 { 66 {
62 (void) plugin->drop_tables (plugin->cls); 67 if (GNUNET_OK != plugin->drop_tables (plugin->cls))
63 ANASTASIS_DB_plugin_unload (plugin); 68 {
64 plugin = ANASTASIS_DB_plugin_load (cfg); 69 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
70 "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");
71 }
65 } 72 }
66 if (GNUNET_OK != 73 if (GNUNET_OK !=
67 plugin->create_tables (plugin->cls)) 74 plugin->create_tables (plugin->cls))
68 { 75 {
69 global_ret = EXIT_FAILURE; 76 global_ret = EXIT_FAILURE;
77 ANASTASIS_DB_plugin_unload (plugin);
70 return; 78 return;
71 } 79 }
80 if (gc_db)
81 {
82 struct GNUNET_TIME_Absolute expire_backups;
83 struct GNUNET_TIME_Absolute expire_payments;
84 struct GNUNET_TIME_Absolute now;
85
86 now = GNUNET_TIME_absolute_get ();
87 expire_backups = GNUNET_TIME_absolute_subtract (
88 now,
89 GNUNET_TIME_relative_multiply (
90 GNUNET_TIME_UNIT_MONTHS,
91 6));
92 expire_payments = GNUNET_TIME_absolute_subtract (
93 now,
94 GNUNET_TIME_relative_multiply (
95 GNUNET_TIME_UNIT_YEARS,
96 10));
97 if (0 > plugin->gc (plugin->cls,
98 expire_backups,
99 expire_payments))
100 {
101 fprintf (stderr,
102 "Garbage collection failed!\n");
103 }
104 }
72 ANASTASIS_DB_plugin_unload (plugin); 105 ANASTASIS_DB_plugin_unload (plugin);
73} 106}
74 107
@@ -86,7 +119,10 @@ main (int argc,
86 char *const *argv) 119 char *const *argv)
87{ 120{
88 struct GNUNET_GETOPT_CommandLineOption options[] = { 121 struct GNUNET_GETOPT_CommandLineOption options[] = {
89 122 GNUNET_GETOPT_option_flag ('g',
123 "garbagecollect",
124 "remove state data from database",
125 &gc_db),
90 GNUNET_GETOPT_option_flag ('r', 126 GNUNET_GETOPT_option_flag ('r',
91 "reset", 127 "reset",
92 "reset database (DANGEROUS: all existing data is lost!)", 128 "reset database (DANGEROUS: all existing data is lost!)",